You are viewing a plain text version of this content. The canonical link for it is here.
Posted to m2-dev@maven.apache.org by mi...@apache.org on 2004/07/03 15:05:50 UTC

cvs commit: maven-components/maven-core/src/main/java/org/apache/maven/artifact/deployer DefaultArtifactDeployer.java

michal      2004/07/03 06:05:50

  Modified:    maven-core/src/main/java/org/apache/maven/artifact/deployer
                        DefaultArtifactDeployer.java
  Log:
  getting ready to deploy artifacts and sites with scp-wagon
  
  Revision  Changes    Path
  1.8       +58 -27    maven-components/maven-core/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java
  
  Index: DefaultArtifactDeployer.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DefaultArtifactDeployer.java	27 Jun 2004 17:02:17 -0000	1.7
  +++ DefaultArtifactDeployer.java	3 Jul 2004 13:05:50 -0000	1.8
  @@ -27,6 +27,7 @@
   import org.apache.maven.wagon.ConnectionException;
   import org.apache.maven.wagon.WagonUtils;
   import org.apache.maven.wagon.observers.ChecksumObserver;
  +import org.apache.maven.wagon.observers.Debug;
   import org.apache.maven.wagon.repository.Repository;
   
   
  @@ -38,7 +39,7 @@
    * @version $Id$
    */
   public class DefaultArtifactDeployer
  -    implements ArtifactDeployer
  +        implements ArtifactDeployer
   {
       private MavenArtifactFactory artifactFactory;
   
  @@ -46,13 +47,13 @@
       private WagonManager wagonManager;
   
       public void deploy( File file, String type, MavenProject project )
  -        throws Exception
  +            throws Exception
       {
           Wagon wagon = null;
   
           try
           {
  -            DistributionManagement distributionManagement =  project.getDistributionManagement();
  +            DistributionManagement distributionManagement = project.getDistributionManagement();
   
               if ( distributionManagement == null )
               {
  @@ -65,7 +66,6 @@
               }
   
   
  -
               if ( distributionManagement.getRepository() == null )
               {
                   String msg = "distributionManagement/repository element is missing in the POM: "
  @@ -79,7 +79,7 @@
   
               String id = distributionManagement.getRepository().getId();
   
  -            if (  url == null )
  +            if ( url == null )
               {
                   String msg = "distributionManagement/repository/url element is missing in the POM: "
                           + project.getId();
  @@ -91,7 +91,10 @@
   
               Repository repository = new Repository( id, url );
   
  -            wagon = wagonManager.getWagon( repository.getUrl()  );
  +            //@todo dirty hack to make artifact uploading work
  +            repository.setAuthenticationInfo( WagonUtils.getAuthInfo() );
  +
  +            wagon = wagonManager.getWagon( repository.getProtocol() );
   
               wagon.connect( repository );
   
  @@ -99,27 +102,59 @@
   
               wagon.addTransferListener( md5ChecksumObserver );
   
  -            if ( project.getVersion().endsWith( "SNAPSHOT" ) )
  +            Debug debug = new Debug();
  +
  +            wagon.addTransferListener( debug );
  +
  +            wagon.addSessionListener( debug );
  +
  +            boolean isSnapshot = project.getVersion().endsWith( "SNAPSHOT" );
  +
  +            String timestamp = SnapshotUtils.getTimestamp();
  +
  +            if ( isSnapshot )
               {
  -                String timestamp = SnapshotUtils.getTimestamp();
  +                //we will deploy (an example for jar artiact):
  +                //
  +                // o foo-1.2-9456757578.jar
  +                // o foo-1.2-SNAPSHOT.jar.snapshot-version
  +                // o foo-1.2-SNAPSHOT.jar
  +                // o foo-1.2-9456757578.pom
  +                // o foo-1.2-SNAPSHOT.pom
  +                // o foo-1.2-SNAPSHOT.pom.snapshot-version
   
  -                MavenArtifact artifact = deployFile( wagon, file, type, timestamp, project );
   
  -                WagonUtils.fromString( artifact.getSnapshotVersionPath(), wagon , timestamp);
  +                MavenArtifact artifact = deployFile( wagon, file, type, timestamp, project );
   
                   // we don't want to install pom twice
                   if ( !type.equals( "pom" ) )
                   {
                       deployFile( wagon, project.getFile(), "pom", timestamp, project );
   
  -                    MavenArtifact pomArtifact = deployFile( wagon, file, type, timestamp, project );
  +                }
  +            }
  +
  +            // we will deploy:
  +            // foo-1.2.jar or foo-1.2-SNAPSHOT.jar
  +            MavenArtifact artifact = deployFile( wagon, file, type, project.getVersion(), project );
  +
  +            if ( isSnapshot )
  +            {
  +                WagonUtils.fromString( artifact.getSnapshotVersionPath().substring( 1 ), wagon, timestamp );
  +            }
   
  -                    WagonUtils.fromString( pomArtifact.getSnapshotVersionPath(), wagon , timestamp);
   
  +            // if we are not deploying pom artifact itself we will deploy it
  +            if ( !type.equals( "pom" ) )
  +            {
  +                MavenArtifact pomArtifact = deployFile( wagon, project.getFile(), "pom", project.getVersion(), project );
  +
  +                if ( isSnapshot )
  +                {
  +                    WagonUtils.fromString( pomArtifact.getSnapshotVersionPath().substring( 1 ), wagon, timestamp );
                   }
               }
   
  -            deployFile( wagon, file, type, project.getVersion(), project );
           }
           finally
           {
  @@ -139,22 +174,15 @@
                   }
                   catch ( Exception e )
                   {
  -                   //
  +                    //
                   }
               }
           }
  -
  -        if ( !type.equals( "pom" ) )
  -        {
  -            deployFile( wagon, project.getFile(), "pom", project.getVersion(), project );
  -        }
  -
  -
  -
       }
   
  +
       public MavenArtifact deployFile( Wagon wagon, File file, String type, String version, MavenProject project )
  -        throws Exception
  +            throws Exception
       {
   
           Dependency dependency = new Dependency();
  @@ -163,13 +191,16 @@
   
           dependency.setArtifactId( project.getArtifactId() );
   
  -        dependency.setVersion( project.getVersion() );
  +        dependency.setVersion( version );
   
           dependency.setType( type );
   
  -        MavenArtifact artifact = artifactFactory.createArtifact( dependency  );
  +        MavenArtifact artifact = artifactFactory.createArtifact( dependency );
  +
  +        //@todo substriing operation should not be required
  +        String resource = artifact.getPath().substring( 1 );
   
  -        String resource = artifact.getPath();
  +        System.out.println( "Deploying resource: " + resource + " (" + file.getPath() + ")" );
   
           wagon.put( file, resource );