maven-m2-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: maven-components/maven-artifact/src/test/java/org/apache/maven/artifact/deployer ArtifactDeployerTest.java
Date Thu, 24 Mar 2005 08:45:37 GMT
brett       2005/03/24 00:45:37

  Modified:    maven-plugins/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy
                        DeployMojo.java
               maven-plugins/maven-deploy-plugin pom.xml
               maven-core/src/main/java/org/apache/maven/cli
                        ConsoleDownloadMonitor.java
               maven-artifact/src/main/java/org/apache/maven/artifact/construction
                        ArtifactConstructionSupport.java
               maven-artifact/src/main/java/org/apache/maven/artifact/deployer
                        ArtifactDeployer.java DefaultArtifactDeployer.java
               maven-artifact/src/main/java/org/apache/maven/artifact/installer
                        ArtifactInstaller.java
                        DefaultArtifactInstaller.java
               maven-artifact/src/main/java/org/apache/maven/artifact/manager
                        DefaultWagonManager.java WagonManager.java
               maven-artifact/src/main/java/org/apache/maven/artifact/metadata
                        ArtifactMetadata.java SnapshotArtifactMetadata.java
               maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout
                        LegacyRepositoryLayout.java
               maven-artifact/src/main/java/org/apache/maven/artifact/resolver
                        DefaultArtifactResolver.java
               maven-artifact/src/main/java/org/apache/maven/artifact/transform
                        ArtifactTransformation.java
                        SnapshotTransformation.java
               maven-artifact/src/main/resources/META-INF/plexus
                        components.xml
               maven-artifact/src/test/java/org/apache/maven/artifact/deployer
                        ArtifactDeployerTest.java
  Log:
  transform deployment of SNAPSHOT.
  Currently, the POM and artifact are deployed separately, causing an inconsistent version
to be written out.
  
  Revision  Changes    Path
  1.6       +34 -35    maven-components/maven-plugins/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java
  
  Index: DeployMojo.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-plugins/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DeployMojo.java	22 Mar 2005 12:36:36 -0000	1.5
  +++ DeployMojo.java	24 Mar 2005 08:45:36 -0000	1.6
  @@ -28,36 +28,34 @@
   import java.io.File;
   
   /**
  - * @goal deploy
  - *
  - * @description deploys an artifact to remote repository
  - *
  - * @parameter
  - *  name="project"
  - *  type="org.apache.maven.project.MavenProject"
  - *  required="true"
  - *  validator=""
  - *  expression="#project"
  - *  description=""
  - *
  - * @parameter
  - *  name="deployer"
  - *  type="org.apache.maven.artifact.deployer.ArtifactDeployer"
  - *  required="true"
  - *  validator=""
  - *  expression="#component.org.apache.maven.artifact.deployer.ArtifactDeployer"
  - *  description=""
  - *
  - * @parameter
  - *  name="deploymentRepository"
  - *  type="org.apache.maven.artifact.repository.ArtifactRepository"
  - *  required="true"
  - *  validator=""
  - *  expression="#project.distributionManagementArtifactRepository"
  - *  description=""
  - *
    * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
    * @version $Id$
  + * @goal deploy
  + * @description deploys an artifact to remote repository
  + * @parameter name="project"
  + * type="org.apache.maven.project.MavenProject"
  + * required="true"
  + * validator=""
  + * expression="#project"
  + * description=""
  + * @parameter name="deployer"
  + * type="org.apache.maven.artifact.deployer.ArtifactDeployer"
  + * required="true"
  + * validator=""
  + * expression="#component.org.apache.maven.artifact.deployer.ArtifactDeployer"
  + * description=""
  + * @parameter name="deploymentRepository"
  + * type="org.apache.maven.artifact.repository.ArtifactRepository"
  + * required="true"
  + * validator=""
  + * expression="#project.distributionManagementArtifactRepository"
  + * description=""
  + * @parameter name="localRepository"
  + * type="org.apache.maven.artifact.repository.ArtifactRepository"
  + * required="true"
  + * validator=""
  + * expression="#localRepository"
  + * description=""
    */
   public class DeployMojo
       extends AbstractPlugin
  @@ -68,21 +66,22 @@
   
       private ArtifactRepository deploymentRepository;
   
  +    private ArtifactRepository localRepository;
  +
       public void execute()
           throws PluginExecutionException
       {
           if ( deploymentRepository == null )
           {
  -            String msg = "Deployment failed: repository element was not specified in the
pom inside"
  -                + " distributionManagement element";
  +            String msg = "Deployment failed: repository element was not specified in the
pom inside" +
  +                " distributionManagement element";
               throw new PluginExecutionException( msg );
           }
   
           if ( deploymentRepository.getAuthenticationInfo() == null )
           {
  -            getLog().warn(
  -                           "Deployment repository {id: \'" + deploymentRepository.getId()
  -                               + "\'} has no associated authentication info!" );
  +            getLog().warn( "Deployment repository {id: \'" + deploymentRepository.getId()
+
  +                           "\'} has no associated authentication info!" );
           }
   
           // Deploy the POM
  @@ -93,7 +92,7 @@
   
           try
           {
  -            deployer.deploy( pom, pomArtifact, deploymentRepository );
  +            deployer.deploy( pom, pomArtifact, deploymentRepository, localRepository );
   
               //Deploy artifact
               if ( !"pom".equals( project.getPackaging() ) )
  @@ -101,7 +100,7 @@
                   Artifact artifact = new DefaultArtifact( project.getGroupId(), project.getArtifactId(),
                                                            project.getVersion(), project.getPackaging()
);
   
  -                deployer.deploy( project.getBuild().getDirectory(), artifact, deploymentRepository
);
  +                deployer.deploy( project.getBuild().getDirectory(), artifact, deploymentRepository,
localRepository );
               }
           }
           catch ( ArtifactDeploymentException e )
  
  
  
  1.9       +7 -0      maven-components/maven-plugins/maven-deploy-plugin/pom.xml
  
  Index: pom.xml
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-plugins/maven-deploy-plugin/pom.xml,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- pom.xml	23 Mar 2005 06:52:54 -0000	1.8
  +++ pom.xml	24 Mar 2005 08:45:36 -0000	1.9
  @@ -48,6 +48,13 @@
       </dependency>
       <dependency>
         <groupId>maven</groupId>
  +      <artifactId>wagon-file</artifactId>
  +      <version>1.0-alpha-2-SNAPSHOT</version>
  +      <type>jar</type>
  +      <scope>runtime</scope>
  +    </dependency>
  +    <dependency>
  +      <groupId>maven</groupId>
         <artifactId>wagon-ssh</artifactId>
         <version>1.0-alpha-2-SNAPSHOT</version>
         <type>jar</type>
  
  
  
  1.3       +10 -4     maven-components/maven-core/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java
  
  Index: ConsoleDownloadMonitor.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ConsoleDownloadMonitor.java	19 Mar 2005 03:00:06 -0000	1.2
  +++ ConsoleDownloadMonitor.java	24 Mar 2005 08:45:36 -0000	1.3
  @@ -35,7 +35,11 @@
   
       public void transferInitiated( TransferEvent transferEvent )
       {
  -        System.out.println( "Downloading: " + transferEvent.getResource().getName() );
  +        String message = transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ?
"Uploading" : "Downloading";
  +
  +        // TODO: can't use getLogger() because this isn't currently instantiated as a component
  +        System.out.println( message + ": " + transferEvent.getResource().getName() );
  +
           complete = 0;
       }
   
  @@ -60,12 +64,14 @@
   
       public void transferError( TransferEvent transferEvent )
       {
  -        getLogger().error( transferEvent.getException().getMessage() );
  +        // TODO: can't use getLogger() because this isn't currently instantiated as a component
  +        transferEvent.getException().printStackTrace();
       }
   
       public void debug( String message )
       {
  -        getLogger().debug( message );
  +        // TODO: can't use getLogger() because this isn't currently instantiated as a component
  +//        getLogger().debug( message );
       }
   }
   
  
  
  
  1.4       +0 -1      maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/construction/ArtifactConstructionSupport.java
  
  Index: ArtifactConstructionSupport.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/construction/ArtifactConstructionSupport.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ArtifactConstructionSupport.java	23 Mar 2005 03:40:12 -0000	1.3
  +++ ArtifactConstructionSupport.java	24 Mar 2005 08:45:36 -0000	1.4
  @@ -41,7 +41,6 @@
               return null;
           }
   
  -        // TODO: localRepository not used (should be used here to resolve path?
           String desiredScope = Artifact.SCOPE_RUNTIME;
           if ( Artifact.SCOPE_COMPILE.equals( scope ) && inheritedScope == null )
           {
  
  
  
  1.4       +4 -2      maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/deployer/ArtifactDeployer.java
  
  Index: ArtifactDeployer.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/deployer/ArtifactDeployer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ArtifactDeployer.java	23 Mar 2005 03:40:12 -0000	1.3
  +++ ArtifactDeployer.java	24 Mar 2005 08:45:36 -0000	1.4
  @@ -25,9 +25,11 @@
   {
       String ROLE = ArtifactDeployer.class.getName();
   
  -    void deploy( String basedir, Artifact artifact, ArtifactRepository deploymentRepository
)
  +    void deploy( String basedir, Artifact artifact, ArtifactRepository deploymentRepository,
  +                 ArtifactRepository localRepository )
           throws ArtifactDeploymentException;
   
  -    void deploy( File source, Artifact artifact, ArtifactRepository deploymentRepository
)
  +    void deploy( File source, Artifact artifact, ArtifactRepository deploymentRepository,
  +                 ArtifactRepository localRepository )
           throws ArtifactDeploymentException;
   }
  
  
  
  1.6       +37 -6     maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java
  
  Index: DefaultArtifactDeployer.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultArtifactDeployer.java	24 Mar 2005 05:18:40 -0000	1.5
  +++ DefaultArtifactDeployer.java	24 Mar 2005 08:45:36 -0000	1.6
  @@ -20,9 +20,15 @@
   import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
   import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
   import org.apache.maven.artifact.manager.WagonManager;
  +import org.apache.maven.artifact.metadata.ArtifactMetadata;
  +import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
   import org.apache.maven.artifact.repository.ArtifactRepository;
  +import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
  +import org.apache.maven.artifact.transform.ArtifactTransformation;
  +import org.apache.maven.wagon.TransferFailedException;
   
   import java.io.File;
  +import java.util.Iterator;
   import java.util.List;
   
   public class DefaultArtifactDeployer
  @@ -34,7 +40,8 @@
   
       private List artifactTransformations;
   
  -    public void deploy( String basedir, Artifact artifact, ArtifactRepository deploymentRepository
)
  +    public void deploy( String basedir, Artifact artifact, ArtifactRepository deploymentRepository,
  +                        ArtifactRepository localRepository )
           throws ArtifactDeploymentException
       {
           File source = null;
  @@ -48,19 +55,43 @@
               throw new ArtifactDeploymentException( "Error deploying artifact: ", e );
           }
   
  -        deploy( source, artifact, deploymentRepository );
  +        deploy( source, artifact, deploymentRepository, localRepository );
       }
   
  -    public void deploy( File source, Artifact artifact, ArtifactRepository deploymentRepository
)
  +    public void deploy( File source, Artifact artifact, ArtifactRepository deploymentRepository,
  +                        ArtifactRepository localRepository )
           throws ArtifactDeploymentException
       {
  -        // TODO: perform transformations
  -
           try
           {
  +            // TODO: better to have a transform manager, or reuse the handler manager again
so we don't have these requirements duplicated all over?
  +            for ( Iterator i = artifactTransformations.iterator(); i.hasNext(); )
  +            {
  +                ArtifactTransformation transform = (ArtifactTransformation) i.next();
  +                artifact = transform.transformForDeployment( artifact, deploymentRepository
);
  +            }
  +
               wagonManager.putArtifact( source, artifact, deploymentRepository );
  +
  +            // must be after the artifact is installed
  +            for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
  +            {
  +                ArtifactMetadata metadata = (ArtifactMetadata) i.next();
  +                metadata.storeInLocalRepository( localRepository );
  +                // TODO: shouldn't need to calculate this
  +                File f = new File( localRepository.getBasedir(), localRepository.pathOfMetadata(
metadata ) );
  +                wagonManager.putArtifactMetadata( f, metadata, deploymentRepository );
  +            }
  +        }
  +        catch ( TransferFailedException e )
  +        {
  +            throw new ArtifactDeploymentException( "Error deploying artifact: ", e );
  +        }
  +        catch ( ArtifactMetadataRetrievalException e )
  +        {
  +            throw new ArtifactDeploymentException( "Error deploying artifact: ", e );
           }
  -        catch ( Exception e )
  +        catch ( ArtifactPathFormatException e )
           {
               throw new ArtifactDeploymentException( "Error deploying artifact: ", e );
           }
  
  
  
  1.4       +1 -1      maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/installer/ArtifactInstaller.java
  
  
  
  
  1.12      +6 -1      maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java
  
  Index: DefaultArtifactInstaller.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DefaultArtifactInstaller.java	24 Mar 2005 05:18:40 -0000	1.11
  +++ DefaultArtifactInstaller.java	24 Mar 2005 08:45:36 -0000	1.12
  @@ -20,6 +20,7 @@
   import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
   import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
   import org.apache.maven.artifact.metadata.ArtifactMetadata;
  +import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
   import org.apache.maven.artifact.repository.ArtifactRepository;
   import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
   import org.apache.maven.artifact.transform.ArtifactTransformation;
  @@ -65,7 +66,7 @@
               for ( Iterator i = artifactTransformations.iterator(); i.hasNext(); )
               {
                   ArtifactTransformation transform = (ArtifactTransformation) i.next();
  -                artifact = transform.transformLocalArtifact( artifact, localRepository
);
  +                artifact = transform.transformForInstall( artifact, localRepository );
               }
   
               String localPath = localRepository.pathOf( artifact );
  @@ -96,5 +97,9 @@
           {
               throw new ArtifactInstallationException( "Error installing artifact: ", e );
           }
  +        catch ( ArtifactMetadataRetrievalException e )
  +        {
  +            throw new ArtifactInstallationException( "Error installing artifact: ", e );
  +        }
       }
   }
  \ No newline at end of file
  
  
  
  1.22      +85 -14    maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
  
  Index: DefaultWagonManager.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- DefaultWagonManager.java	24 Mar 2005 05:18:40 -0000	1.21
  +++ DefaultWagonManager.java	24 Mar 2005 08:45:37 -0000	1.22
  @@ -77,25 +77,94 @@
       }
   
       // TODO: don't throw exception
  -    public void releaseWagon( Wagon wagon )
  +    private void releaseWagon( Wagon wagon )
           throws Exception
       {
           container.release( wagon );
       }
   
  -    // TODO: don't throw exception
       public void putArtifact( File source, Artifact artifact, ArtifactRepository repository
)
  -        throws Exception
  +        throws TransferFailedException
  +    {
  +        try
  +        {
  +            putRemoteFile( repository, source, repository.pathOf( artifact ) );
  +        }
  +        catch ( ArtifactPathFormatException e )
  +        {
  +            throw new TransferFailedException( "Path of artifact could not be determined:
", e );
  +        }
  +    }
  +
  +    public void putArtifactMetadata( File source, ArtifactMetadata artifactMetadata, ArtifactRepository
repository )
  +        throws TransferFailedException
       {
  -        Wagon wagon = getWagon( repository.getProtocol() );
  +        try
  +        {
  +            putRemoteFile( repository, source, repository.pathOfMetadata( artifactMetadata
) );
  +        }
  +        catch ( ArtifactPathFormatException e )
  +        {
  +            throw new TransferFailedException( "Path of artifact could not be determined:
", e );
  +        }
  +    }
   
  -        wagon.connect( repository, getProxy( repository.getProtocol() ) );
  +    private void putRemoteFile( ArtifactRepository repository, File source, String remotePath
)
  +        throws TransferFailedException
  +    {
  +        Wagon wagon = null;
  +        try
  +        {
  +            wagon = getWagon( repository.getProtocol() );
  +        }
  +        catch ( UnsupportedProtocolException e )
  +        {
  +            throw new TransferFailedException( "Unsupported Protocol: ", e );
  +        }
   
  -        wagon.put( source, repository.pathOf( artifact ) );
  +        // TODO: probably don't want this on metadata...
  +        // TODO: not working well on upload, commented out for now
  +//        if ( downloadMonitor != null )
  +//        {
  +//            wagon.addTransferListener( downloadMonitor );
  +//        }
   
  -        wagon.disconnect();
  +        try
  +        {
  +            wagon.connect( repository, getProxy( repository.getProtocol() ) );
   
  -        releaseWagon( wagon );
  +            wagon.put( source, remotePath );
  +
  +            // TODO [BP]: put all disconnects in finally
  +            wagon.disconnect();
  +        }
  +        catch ( ConnectionException e )
  +        {
  +            throw new TransferFailedException( "Connection failed: ", e );
  +        }
  +        catch ( AuthenticationException e )
  +        {
  +            throw new TransferFailedException( "Authentication failed: ", e );
  +        }
  +        catch ( AuthorizationException e )
  +        {
  +            throw new TransferFailedException( "Authorization failed: ", e );
  +        }
  +        catch ( ResourceDoesNotExistException e )
  +        {
  +            throw new TransferFailedException( "Resource to deploy not found: ", e );
  +        }
  +        finally
  +        {
  +            try
  +            {
  +                releaseWagon( wagon );
  +            }
  +            catch ( Exception e )
  +            {
  +                throw new TransferFailedException( "Unable to release wagon", e );
  +            }
  +        }
       }
   
       public void getArtifact( Artifact artifact, List remoteRepositories, File destination
)
  @@ -139,16 +208,13 @@
           }
       }
   
  -    public void getMetadata( ArtifactMetadata metadata, ArtifactRepository remoteRepository,
  -                             ArtifactRepository localRepository )
  +    public void getArtifactMetadata( ArtifactMetadata metadata, ArtifactRepository remoteRepository,
File destination )
           throws TransferFailedException, ResourceDoesNotExistException
       {
           String remotePath;
  -        String localPath;
           try
           {
               remotePath = remoteRepository.pathOfMetadata( metadata );
  -            localPath = localRepository.pathOfMetadata( metadata );
           }
           catch ( ArtifactPathFormatException e )
           {
  @@ -156,8 +222,7 @@
               throw new TransferFailedException( "Failed to determine path for artifact",
e );
           }
   
  -        File metadataFile = new File( localRepository.getBasedir(), localPath );
  -        getRemoteFile( remoteRepository, metadataFile, remotePath );
  +        getRemoteFile( remoteRepository, destination, remotePath );
       }
   
       private void getRemoteFile( ArtifactRepository repository, File destination, String
remotePath )
  @@ -184,6 +249,7 @@
   
           //wagon.addTransferListener( md5SumObserver );
   
  +        // TODO: probably don't want this on metadata...
           if ( downloadMonitor != null )
           {
               wagon.addTransferListener( downloadMonitor );
  @@ -231,6 +297,11 @@
               }
           }
   
  +        if ( !temp.exists() )
  +        {
  +            throw new TransferFailedException( "Downloaded file does not exist: " + temp
);
  +        }
  +
           // The temporary file is named destination + ".tmp" and is done this
           // way to ensure
           // that the temporary file is in the same file system as the
  
  
  
  1.10      +6 -9      maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/manager/WagonManager.java
  
  Index: WagonManager.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/manager/WagonManager.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- WagonManager.java	24 Mar 2005 05:01:05 -0000	1.9
  +++ WagonManager.java	24 Mar 2005 08:45:37 -0000	1.10
  @@ -39,19 +39,16 @@
       Wagon getWagon( String protocol )
           throws UnsupportedProtocolException;
   
  -    // TODO: don't throw exception
  -    void releaseWagon( Wagon wagon )
  -        throws Exception;
  -
       void getArtifact( Artifact artifact, List remoteRepositories, File destination )
           throws TransferFailedException;
   
  -    // TODO: don't throw exception
       void putArtifact( File source, Artifact artifact, ArtifactRepository deploymentRepository
)
  -        throws Exception;
  +        throws TransferFailedException;
  +
  +    public void putArtifactMetadata( File source, ArtifactMetadata artifactMetadata, ArtifactRepository
repository )
  +        throws TransferFailedException;
   
  -    void getMetadata( ArtifactMetadata metadata, ArtifactRepository remoteRepository,
  -                      ArtifactRepository localRepository )
  +    public void getArtifactMetadata( ArtifactMetadata metadata, ArtifactRepository remoteRepository,
File destination )
           throws TransferFailedException, ResourceDoesNotExistException;
   
       void setProxy( String protocol, String host, int port, String username, String password,
String nonProxyHosts );
  
  
  
  1.3       +9 -11     maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java
  
  Index: ArtifactMetadata.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ArtifactMetadata.java	24 Mar 2005 05:01:05 -0000	1.2
  +++ ArtifactMetadata.java	24 Mar 2005 08:45:37 -0000	1.3
  @@ -17,19 +17,17 @@
    */
   
   import org.apache.maven.artifact.Artifact;
  +import org.apache.maven.artifact.manager.WagonManager;
   import org.apache.maven.artifact.repository.ArtifactRepository;
  -import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
  -import org.apache.maven.artifact.resolver.ArtifactResolutionException;
  -
  -import java.io.IOException;
   
   /**
    * Contains metadata about an artifact, and methods to retrieve/store it from an artifact
repository.
    *
    * @author <a href="mailto:brett@apache.org">Brett Porter</a>
    * @version $Id$
  - * @todo naming is too close to ArtifactMetadataSource which refers to a POM. A POM is
sometimes an artifact itself,
  - * so that naming may no longer be appropriate.
  + * @todo merge with artifactmetadatasource
  + * @todo retrieval exception not appropriate for store
  + * @todo not happy about the store/retrieve methods - they use "this"
    */
   public interface ArtifactMetadata
   {
  @@ -39,16 +37,16 @@
        * @param localRepository the local repository
        */
       void storeInLocalRepository( ArtifactRepository localRepository )
  -        throws IOException, ArtifactPathFormatException;
  +        throws ArtifactMetadataRetrievalException;
   
       /**
        * Retrieve the metadata from the remote repository into the local repository.
        *
        * @param remoteRepository the remote repository
  -     * @param localRepository  the local repository
  +     * @param wagonManager     the wagon manager to use to retrieve the metadata
        */
  -    void retrieveFromRemoteRepository( ArtifactRepository remoteRepository, ArtifactRepository
localRepository )
  -        throws IOException, ArtifactResolutionException;
  +    public void retrieveFromRemoteRepository( ArtifactRepository remoteRepository, WagonManager
wagonManager )
  +        throws ArtifactMetadataRetrievalException;
   
       /**
        * Get the associated artifact.
  
  
  
  1.3       +81 -22    maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java
  
  Index: SnapshotArtifactMetadata.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SnapshotArtifactMetadata.java	24 Mar 2005 05:01:05 -0000	1.2
  +++ SnapshotArtifactMetadata.java	24 Mar 2005 08:45:37 -0000	1.3
  @@ -17,11 +17,15 @@
    */
   
   import org.apache.maven.artifact.Artifact;
  +import org.apache.maven.artifact.manager.WagonManager;
   import org.apache.maven.artifact.repository.ArtifactRepository;
   import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
  -import org.apache.maven.artifact.resolver.ArtifactResolutionException;
  +import org.apache.maven.wagon.ResourceDoesNotExistException;
  +import org.apache.maven.wagon.TransferFailedException;
   import org.codehaus.plexus.util.FileUtils;
  +import org.codehaus.plexus.util.StringUtils;
   
  +import java.io.File;
   import java.io.IOException;
   import java.text.DateFormat;
   import java.text.SimpleDateFormat;
  @@ -39,7 +43,7 @@
   {
       private String timestamp = null;
   
  -    private int buildNumber = 1;
  +    private int buildNumber = 0;
   
       private static final String SNAPSHOT_VERSION_LOCAL_FILE = "version-local.txt";
   
  @@ -59,40 +63,89 @@
           return new SnapshotArtifactMetadata( artifact, SNAPSHOT_VERSION_LOCAL_FILE );
       }
   
  -    public static ArtifactMetadata createRemoteSnapshotMetadata( Artifact artifact )
  +    public static SnapshotArtifactMetadata createRemoteSnapshotMetadata( Artifact artifact
)
       {
           return new SnapshotArtifactMetadata( artifact, SNAPSHOT_VERSION_FILE );
       }
   
       public void storeInLocalRepository( ArtifactRepository localRepository )
  -        throws IOException, ArtifactPathFormatException
  +        throws ArtifactMetadataRetrievalException
       {
  -        FileUtils.fileWrite( localRepository.getBasedir() + "/" + localRepository.pathOfMetadata(
this ),
  -                             getTimestamp() + "-" + buildNumber );
  +        try
  +        {
  +            if ( timestamp == null )
  +            {
  +                timestamp = getUtcDateFormatter().format( new Date() );
  +            }
  +            String path = new File( localRepository.getBasedir(), localRepository.pathOfMetadata(
this ) ).getPath();
  +            FileUtils.fileWrite( path, getVersion() );
  +        }
  +        catch ( IOException e )
  +        {
  +            throw new ArtifactMetadataRetrievalException( "Unable to retrieve metadata",
e );
  +        }
  +        catch ( ArtifactPathFormatException e )
  +        {
  +            throw new ArtifactMetadataRetrievalException( "Unable to retrieve metadata",
e );
  +        }
       }
   
  -    public void retrieveFromRemoteRepository( ArtifactRepository remoteRepository, ArtifactRepository
localRepository )
  -        throws IOException, ArtifactResolutionException
  +    public String getVersion()
       {
  -/*
  -// TODO: this is getting the artifact - needs to get the version.txt
  -        resolver.resolve( artifact, Collections.singletonList( remoteRepository ), localRepository
);
  -
  -        String version = FileUtils.fileRead( artifact.getPath() );
  +        String version = artifact.getVersion();
  +        if ( version != null )
  +        {
  +            version = StringUtils.replace( version, "SNAPSHOT", timestamp );
  +        }
  +        else
  +        {
  +            version = timestamp;
  +        }
  +        return version + "-" + buildNumber;
  +    }
   
  -        int index = UTC_TIMESTAMP_PATTERN.length();
  -        timestamp = version.substring( 0, index );
  +    public void retrieveFromRemoteRepository( ArtifactRepository remoteRepository, WagonManager
wagonManager )
  +        throws ArtifactMetadataRetrievalException
  +    {
  +        try
  +        {
  +            File destination = File.createTempFile( "maven-artifact", null );
  +            destination.deleteOnExit();
   
  -        buildNumber = Integer.valueOf( version.substring( index + 1 ) ).intValue();
  -*/
  +            try
  +            {
  +                wagonManager.getArtifactMetadata( this, remoteRepository, destination );
  +            }
  +            catch ( ResourceDoesNotExistException e )
  +            {
  +                // this just means that there is no snapshot version file, so we keep timestamp
= null, build = 0
  +                return;
  +            }
  +
  +            String version = FileUtils.fileRead( destination );
  +
  +            int index = version.lastIndexOf( "-" );
  +            timestamp = version.substring( 0, index );
  +            buildNumber = Integer.valueOf( version.substring( index + 1 ) ).intValue();
  +            index = version.indexOf( "-" );
  +            if ( index >= 0 )
  +            {
  +                // ignore starting version part, will be prepended later
  +                timestamp = timestamp.substring( index + 1 );
  +            }
  +        }
  +        catch ( TransferFailedException e )
  +        {
  +            throw new ArtifactMetadataRetrievalException( "Unable to retrieve metadata",
e );
  +        }
  +        catch ( IOException e )
  +        {
  +            throw new ArtifactMetadataRetrievalException( "Unable to retrieve metadata",
e );
  +        }
       }
   
       public String getTimestamp()
       {
  -        if ( timestamp == null )
  -        {
  -            timestamp = getUtcDateFormatter().format( new Date() );
  -        }
           return timestamp;
       }
   
  @@ -102,4 +155,10 @@
           utcDateFormatter.setTimeZone( UTC_TIME_ZONE );
           return utcDateFormatter;
       }
  +
  +    public void update()
  +    {
  +        this.buildNumber++;
  +        timestamp = getUtcDateFormatter().format( new Date() );
  +    }
   }
  
  
  
  1.4       +1 -1      maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java
  
  Index: LegacyRepositoryLayout.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LegacyRepositoryLayout.java	23 Mar 2005 14:55:15 -0000	1.3
  +++ LegacyRepositoryLayout.java	24 Mar 2005 08:45:37 -0000	1.4
  @@ -30,7 +30,7 @@
   
       protected String metadataLayoutPattern()
       {
  -        return "${groupPath}/${directory}/${artifactId}-${version}-${metadataFilename}";
  +        return "${groupPath}/poms/${artifactId}-${version}-${metadataFilename}";
       }
   
       protected String groupIdAsPath( String groupId )
  
  
  
  1.29      +5 -12     maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
  
  Index: DefaultArtifactResolver.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- DefaultArtifactResolver.java	24 Mar 2005 05:18:41 -0000	1.28
  +++ DefaultArtifactResolver.java	24 Mar 2005 08:45:37 -0000	1.29
  @@ -81,7 +81,7 @@
           for ( Iterator i = artifactTransformations.iterator(); i.hasNext(); )
           {
               ArtifactTransformation transform = (ArtifactTransformation) i.next();
  -            artifact = transform.transformLocalArtifact( artifact, localRepository );
  +            artifact = transform.transformForResolve( artifact );
           }
   
           String localPath;
  @@ -182,19 +182,12 @@
               throw new ArtifactResolutionException( "Error transitively resolving artifacts:
", e );
           }
   
  -        // TODO: this is unclean, but necessary as long as resolve may return a different
artifact
  -        Map collectedArtifacts = artifactResolutionResult.getArtifacts();
  -        Map resolvedArtifacts = new HashMap( collectedArtifacts.size() );
  -        for ( Iterator i = collectedArtifacts.keySet().iterator(); i.hasNext(); )
  -        {
  -            Object key = i.next();
  -            resolvedArtifacts.put( key, resolve( (Artifact) collectedArtifacts.get( key
), remoteRepositories,
  -                                                 localRepository ) );
  +        for ( Iterator i = artifactResolutionResult.getArtifacts().values().iterator();
i.hasNext(); )
  +        {
  +            // TODO: resolve may modify artifacts, do we need to get the new list?
  +            resolve( (Artifact) i.next(), remoteRepositories, localRepository );
           }
   
  -        collectedArtifacts.clear();
  -        collectedArtifacts.putAll( resolvedArtifacts );
  -
           return artifactResolutionResult;
       }
   
  
  
  
  1.5       +16 -5     maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/transform/ArtifactTransformation.java
  
  Index: ArtifactTransformation.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/transform/ArtifactTransformation.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ArtifactTransformation.java	24 Mar 2005 05:01:06 -0000	1.4
  +++ ArtifactTransformation.java	24 Mar 2005 08:45:37 -0000	1.5
  @@ -17,6 +17,7 @@
    */
   
   import org.apache.maven.artifact.Artifact;
  +import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
   import org.apache.maven.artifact.repository.ArtifactRepository;
   
   /**
  @@ -29,6 +30,15 @@
       static String ROLE = ArtifactTransformation.class.getName();
   
       /**
  +     * Take in a artifact and return the transformed artifact for locating in the remote
repository. If no
  +     * transformation has occured the original artifact is returned.
  +     *
  +     * @param artifact Artifact to be transformed.
  +     * @return The transformed Artifact
  +     */
  +    Artifact transformForResolve( Artifact artifact );
  +
  +    /**
        * Take in a artifact and return the transformed artifact for locating in the local
repository. If no
        * transformation has occured the original artifact is returned.
        *
  @@ -36,15 +46,16 @@
        * @param localRepository the local repository it will be stored in
        * @return The transformed Artifact
        */
  -    Artifact transformLocalArtifact( Artifact artifact, ArtifactRepository localRepository
);
  +    Artifact transformForInstall( Artifact artifact, ArtifactRepository localRepository
);
   
       /**
  -     * Take in a artifact and return the transformed artifact for locating in the remote
repository. If no
  +     * Take in a artifact and return the transformed artifact for distributing toa remote
repository. If no
        * transformation has occured the original artifact is returned.
        *
  -     * @param artifact Artifact to be transformed.
  +     * @param artifact         Artifact to be transformed.
  +     * @param remoteRepository the repository to deploy to
        * @return The transformed Artifact
  -     * @todo finish doco
        */
  -    Artifact transformRemoteArtifact( Artifact artifact, ArtifactRepository remoteRepository
);
  +    Artifact transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository
)
  +        throws ArtifactMetadataRetrievalException;
   }
  \ No newline at end of file
  
  
  
  1.6       +25 -13    maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java
  
  Index: SnapshotTransformation.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SnapshotTransformation.java	24 Mar 2005 05:01:06 -0000	1.5
  +++ SnapshotTransformation.java	24 Mar 2005 08:45:37 -0000	1.6
  @@ -17,7 +17,10 @@
    */
   
   import org.apache.maven.artifact.Artifact;
  +import org.apache.maven.artifact.DefaultArtifact;
  +import org.apache.maven.artifact.manager.WagonManager;
   import org.apache.maven.artifact.metadata.ArtifactMetadata;
  +import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
   import org.apache.maven.artifact.metadata.SnapshotArtifactMetadata;
   import org.apache.maven.artifact.repository.ArtifactRepository;
   
  @@ -30,6 +33,8 @@
   public class SnapshotTransformation
       implements ArtifactTransformation
   {
  +    private WagonManager wagonManager;
  +
   /* TODO: use and remove
       public Artifact transform( Artifact artifact, ArtifactRepository localRepository, List
repositories,
                                  Map parameters )
  @@ -185,9 +190,15 @@
           return retValue;
       }
       */
  -    public Artifact transformLocalArtifact( Artifact artifact, ArtifactRepository localRepository
)
  +    public Artifact transformForResolve( Artifact artifact )
  +    {
  +        // TODO: implement
  +        return artifact;
  +    }
  +
  +    public Artifact transformForInstall( Artifact artifact, ArtifactRepository localRepository
)
       {
  -        if ( shouldProcessArtifact( artifact ) )
  +        if ( isSnapshot( artifact ) )
           {
               // only store the version-local.txt file for POMs as every file has an associated
POM
               ArtifactMetadata metadata = SnapshotArtifactMetadata.createLocalSnapshotMetadata(
artifact );
  @@ -196,23 +207,24 @@
           return artifact;
       }
   
  -    public Artifact transformRemoteArtifact( Artifact artifact, ArtifactRepository remoteRepository
)
  +    public Artifact transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository
)
  +        throws ArtifactMetadataRetrievalException
       {
  -        if ( shouldProcessArtifact( artifact ) )
  +        if ( isSnapshot( artifact ) )
           {
  -            ArtifactMetadata metadata = SnapshotArtifactMetadata.createRemoteSnapshotMetadata(
artifact );
  -//            wagonManager.getMetadata( metadata, remoteRepository, localRepository );
  -
  -            // TODO: implement
  +            SnapshotArtifactMetadata metadata = SnapshotArtifactMetadata.createRemoteSnapshotMetadata(
artifact );
  +            metadata.retrieveFromRemoteRepository( remoteRepository, wagonManager );
  +            metadata.update();
  +
  +            // TODO: note, we could currently transform this in place, as it is only used
through the deploy mojo,
  +            //   which creates the artifact and then disposes of it
  +            artifact = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(),
metadata.getVersion(),
  +                                            artifact.getScope(), artifact.getType(), artifact.getClassifier()
);
  +            artifact.addMetadata( metadata );
           }
           return artifact;
       }
   
  -    private static boolean shouldProcessArtifact( Artifact artifact )
  -    {
  -        return isSnapshot( artifact ) && "pom".equals( artifact.getType() );
  -    }
  -
       private static boolean isSnapshot( Artifact artifact )
       {
           return artifact.getVersion().endsWith( "SNAPSHOT" );
  
  
  
  1.16      +20 -15    maven-components/maven-artifact/src/main/resources/META-INF/plexus/components.xml
  
  Index: components.xml
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/resources/META-INF/plexus/components.xml,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- components.xml	24 Mar 2005 05:18:41 -0000	1.15
  +++ components.xml	24 Mar 2005 08:45:37 -0000	1.16
  @@ -2,12 +2,32 @@
     <components>
       <!--
        |
  +     | WagonManager
  +     |
  +     -->
  +    <component>
  +      <role>org.apache.maven.artifact.manager.WagonManager</role>
  +      <implementation>org.apache.maven.artifact.manager.DefaultWagonManager</implementation>
  +      <requirements>
  +        <requirement>
  +          <role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
  +        </requirement>
  +      </requirements>
  +    </component>
  +
  +    <!--
  +     |
        | Transformations
        |
        -->
       <component>
         <role>org.apache.maven.artifact.transform.ArtifactTransformation</role>
         <implementation>org.apache.maven.artifact.transform.SnapshotTransformation</implementation>
  +      <requirements>
  +        <requirement>
  +          <role>org.apache.maven.artifact.manager.WagonManager</role>
  +        </requirement>
  +      </requirements>
       </component>
   
       <!--
  @@ -34,21 +54,6 @@
   
       <!--
        |
  -     | WagonManager
  -     |
  -     -->
  -    <component>
  -      <role>org.apache.maven.artifact.manager.WagonManager</role>
  -      <implementation>org.apache.maven.artifact.manager.DefaultWagonManager</implementation>
  -      <requirements>
  -        <requirement>
  -          <role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
  -        </requirement>
  -      </requirements>
  -    </component>
  -    
  -    <!--
  -     |
        | ArtifactInstaller
        |
        -->
  
  
  
  1.3       +2 -2      maven-components/maven-artifact/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java
  
  Index: ArtifactDeployerTest.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ArtifactDeployerTest.java	23 Oct 2004 13:33:59 -0000	1.2
  +++ ArtifactDeployerTest.java	24 Mar 2005 08:45:37 -0000	1.3
  @@ -50,7 +50,7 @@
   
           Artifact artifact = createArtifact( "artifact", "1.0" );
   
  -        artifactDeployer.deploy( artifactBasedir, artifact, remoteRepository() );
  +        artifactDeployer.deploy( artifactBasedir, artifact, remoteRepository(), localRepository()
);
   
           assertRemoteArtifactPresent( artifact );
       }
  
  
  

Mime
View raw message