From 3f0f786e67ec1603e8bee73db8626010e904f383 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Thu, 24 Mar 2005 08:45:37 +0000 Subject: [PATCH] transform deployment of SNAPSHOT. Currently, the POM and artifact are deployed separately, causing an inconsistent version to be written out. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163684 13f79535-47bb-0310-9956-ffa450edef68 --- .../ArtifactConstructionSupport.java | 1 - .../artifact/deployer/ArtifactDeployer.java | 6 +- .../deployer/DefaultArtifactDeployer.java | 43 ++++++-- .../installer/DefaultArtifactInstaller.java | 7 +- .../artifact/manager/DefaultWagonManager.java | 99 ++++++++++++++++--- .../maven/artifact/manager/WagonManager.java | 13 +-- .../artifact/metadata/ArtifactMetadata.java | 18 ++-- .../metadata/SnapshotArtifactMetadata.java | 99 +++++++++++++++---- .../layout/LegacyRepositoryLayout.java | 2 +- .../resolver/DefaultArtifactResolver.java | 15 +-- .../transform/ArtifactTransformation.java | 21 +++- .../transform/SnapshotTransformation.java | 36 ++++--- .../resources/META-INF/plexus/components.xml | 35 ++++--- .../deployer/ArtifactDeployerTest.java | 2 +- .../maven/cli/ConsoleDownloadMonitor.java | 12 ++- maven-plugins/maven-deploy-plugin/pom.xml | 7 ++ .../maven/plugin/deploy/DeployMojo.java | 69 +++++++------ 17 files changed, 340 insertions(+), 145 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/construction/ArtifactConstructionSupport.java b/maven-artifact/src/main/java/org/apache/maven/artifact/construction/ArtifactConstructionSupport.java index f8ea30e0cf..8b92c621e0 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/construction/ArtifactConstructionSupport.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/construction/ArtifactConstructionSupport.java @@ -41,7 +41,6 @@ public class ArtifactConstructionSupport 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 ) { diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/deployer/ArtifactDeployer.java b/maven-artifact/src/main/java/org/apache/maven/artifact/deployer/ArtifactDeployer.java index 2e8dffc4e1..d158166ae6 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/deployer/ArtifactDeployer.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/deployer/ArtifactDeployer.java @@ -25,9 +25,11 @@ public interface ArtifactDeployer { 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; } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java b/maven-artifact/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java index 4421de98fd..a333e43724 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java @@ -20,9 +20,15 @@ import org.apache.maven.artifact.Artifact; 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 @@ public class DefaultArtifactDeployer 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 @@ public class DefaultArtifactDeployer 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 ( Exception e ) + catch ( TransferFailedException e ) + { + throw new ArtifactDeploymentException( "Error deploying artifact: ", e ); + } + catch ( ArtifactMetadataRetrievalException e ) + { + throw new ArtifactDeploymentException( "Error deploying artifact: ", e ); + } + catch ( ArtifactPathFormatException e ) { throw new ArtifactDeploymentException( "Error deploying artifact: ", e ); } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java b/maven-artifact/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java index 531138c4c9..54a322db3d 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java @@ -20,6 +20,7 @@ import org.apache.maven.artifact.Artifact; 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 @@ public class DefaultArtifactInstaller 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 @@ public class DefaultArtifactInstaller { throw new ArtifactInstallationException( "Error installing artifact: ", e ); } + catch ( ArtifactMetadataRetrievalException e ) + { + throw new ArtifactInstallationException( "Error installing artifact: ", e ); + } } } \ No newline at end of file diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java b/maven-artifact/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java index f645e98d07..22a8ec30a0 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java @@ -77,25 +77,94 @@ public class DefaultWagonManager } // 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 { - Wagon wagon = getWagon( repository.getProtocol() ); + try + { + putRemoteFile( repository, source, repository.pathOf( artifact ) ); + } + catch ( ArtifactPathFormatException e ) + { + throw new TransferFailedException( "Path of artifact could not be determined: ", e ); + } + } - wagon.connect( repository, getProxy( repository.getProtocol() ) ); + public void putArtifactMetadata( File source, ArtifactMetadata artifactMetadata, ArtifactRepository repository ) + throws TransferFailedException + { + try + { + putRemoteFile( repository, source, repository.pathOfMetadata( artifactMetadata ) ); + } + catch ( ArtifactPathFormatException e ) + { + throw new TransferFailedException( "Path of artifact could not be determined: ", e ); + } + } - wagon.put( source, repository.pathOf( artifact ) ); + 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.disconnect(); + // TODO: probably don't want this on metadata... + // TODO: not working well on upload, commented out for now +// if ( downloadMonitor != null ) +// { +// wagon.addTransferListener( downloadMonitor ); +// } - releaseWagon( wagon ); + try + { + wagon.connect( repository, getProxy( repository.getProtocol() ) ); + + 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 class DefaultWagonManager } } - 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 @@ public class DefaultWagonManager 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 @@ public class DefaultWagonManager //wagon.addTransferListener( md5SumObserver ); + // TODO: probably don't want this on metadata... if ( downloadMonitor != null ) { wagon.addTransferListener( downloadMonitor ); @@ -231,6 +297,11 @@ public class DefaultWagonManager } } + 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 diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/manager/WagonManager.java b/maven-artifact/src/main/java/org/apache/maven/artifact/manager/WagonManager.java index 831532d24d..f637bd360d 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/manager/WagonManager.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/manager/WagonManager.java @@ -39,19 +39,16 @@ public interface WagonManager 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; - void getMetadata( ArtifactMetadata metadata, ArtifactRepository remoteRepository, - ArtifactRepository localRepository ) + public void putArtifactMetadata( File source, ArtifactMetadata artifactMetadata, ArtifactRepository repository ) + throws TransferFailedException; + + 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 ); diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java index 7cc3e54920..2551edb2e4 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java @@ -17,19 +17,17 @@ package org.apache.maven.artifact.metadata; */ 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 Brett Porter * @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 @@ public interface ArtifactMetadata * @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. diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java index 535a1e4d24..b362468e5c 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java @@ -17,11 +17,15 @@ package org.apache.maven.artifact.metadata; */ 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 @@ public class SnapshotArtifactMetadata { 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 @@ public class SnapshotArtifactMetadata 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 = artifact.getVersion(); + if ( version != null ) + { + version = StringUtils.replace( version, "SNAPSHOT", timestamp ); + } + else + { + version = timestamp; + } + return version + "-" + buildNumber; + } - String version = FileUtils.fileRead( artifact.getPath() ); + public void retrieveFromRemoteRepository( ArtifactRepository remoteRepository, WagonManager wagonManager ) + throws ArtifactMetadataRetrievalException + { + try + { + File destination = File.createTempFile( "maven-artifact", null ); + destination.deleteOnExit(); - int index = UTC_TIMESTAMP_PATTERN.length(); - timestamp = version.substring( 0, index ); + 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; + } - buildNumber = Integer.valueOf( version.substring( index + 1 ) ).intValue(); -*/ + 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 @@ public class SnapshotArtifactMetadata utcDateFormatter.setTimeZone( UTC_TIME_ZONE ); return utcDateFormatter; } + + public void update() + { + this.buildNumber++; + timestamp = getUtcDateFormatter().format( new Date() ); + } } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java index 7d0ff4a3cf..cbe9f7ad9e 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java @@ -30,7 +30,7 @@ public class LegacyRepositoryLayout protected String metadataLayoutPattern() { - return "${groupPath}/${directory}/${artifactId}-${version}-${metadataFilename}"; + return "${groupPath}/poms/${artifactId}-${version}-${metadataFilename}"; } protected String groupIdAsPath( String groupId ) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index 4b7dfc3138..3d249c5e0f 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -81,7 +81,7 @@ public class DefaultArtifactResolver 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 @@ public class DefaultArtifactResolver 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(); ) + for ( Iterator i = artifactResolutionResult.getArtifacts().values().iterator(); i.hasNext(); ) { - Object key = i.next(); - resolvedArtifacts.put( key, resolve( (Artifact) collectedArtifacts.get( key ), remoteRepositories, - localRepository ) ); + // 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; } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/transform/ArtifactTransformation.java b/maven-artifact/src/main/java/org/apache/maven/artifact/transform/ArtifactTransformation.java index 56d4d3d0ca..75ecfe792f 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/transform/ArtifactTransformation.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/transform/ArtifactTransformation.java @@ -17,6 +17,7 @@ package org.apache.maven.artifact.transform; */ import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.repository.ArtifactRepository; /** @@ -28,6 +29,15 @@ public interface ArtifactTransformation { 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 @@ public interface ArtifactTransformation * @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 diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java b/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java index b558ec61cc..1e72067a06 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java @@ -17,7 +17,10 @@ package org.apache.maven.artifact.transform; */ 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 @@ import org.apache.maven.artifact.repository.ArtifactRepository; 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 @@ public class SnapshotTransformation return retValue; } */ - public Artifact transformLocalArtifact( Artifact artifact, ArtifactRepository localRepository ) + public Artifact transformForResolve( Artifact artifact ) { - if ( shouldProcessArtifact( artifact ) ) + // TODO: implement + return artifact; + } + + public Artifact transformForInstall( Artifact artifact, ArtifactRepository localRepository ) + { + 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 @@ public class SnapshotTransformation 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 ); + SnapshotArtifactMetadata metadata = SnapshotArtifactMetadata.createRemoteSnapshotMetadata( artifact ); + metadata.retrieveFromRemoteRepository( remoteRepository, wagonManager ); + metadata.update(); - // TODO: implement + // 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" ); diff --git a/maven-artifact/src/main/resources/META-INF/plexus/components.xml b/maven-artifact/src/main/resources/META-INF/plexus/components.xml index e9dbda68d3..6e9dd90eb3 100644 --- a/maven-artifact/src/main/resources/META-INF/plexus/components.xml +++ b/maven-artifact/src/main/resources/META-INF/plexus/components.xml @@ -1,5 +1,20 @@ + + + org.apache.maven.artifact.manager.WagonManager + org.apache.maven.artifact.manager.DefaultWagonManager + + + org.apache.maven.artifact.handler.manager.ArtifactHandlerManager + + + + - - org.apache.maven.artifact.manager.WagonManager - org.apache.maven.artifact.manager.DefaultWagonManager - - - org.apache.maven.artifact.handler.manager.ArtifactHandlerManager - - - -