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 44447a0672..4421de98fd 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 @@ -23,10 +23,8 @@ import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.artifact.repository.ArtifactRepository; import java.io.File; +import java.util.List; -/** - * @todo snapshot notions need to be dealt with in one place. - */ public class DefaultArtifactDeployer implements ArtifactDeployer { @@ -34,6 +32,8 @@ public class DefaultArtifactDeployer private ArtifactHandlerManager artifactHandlerManager; + private List artifactTransformations; + public void deploy( String basedir, Artifact artifact, ArtifactRepository deploymentRepository ) throws ArtifactDeploymentException { @@ -54,6 +54,8 @@ public class DefaultArtifactDeployer public void deploy( File source, Artifact artifact, ArtifactRepository deploymentRepository ) throws ArtifactDeploymentException { + // TODO: perform transformations + try { wagonManager.putArtifact( source, artifact, deploymentRepository ); diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/handler/manager/ArtifactHandlerManager.java b/maven-artifact/src/main/java/org/apache/maven/artifact/handler/manager/ArtifactHandlerManager.java index e901e431aa..5d0697de9b 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/handler/manager/ArtifactHandlerManager.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/handler/manager/ArtifactHandlerManager.java @@ -16,10 +16,7 @@ package org.apache.maven.artifact.handler.manager; * limitations under the License. */ -import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException; /** * @author Jason van Zyl @@ -31,10 +28,4 @@ public interface ArtifactHandlerManager ArtifactHandler getArtifactHandler( String type ) throws ArtifactHandlerNotFoundException; - - String getLocalRepositoryArtifactPath( Artifact artifact, ArtifactRepository localRepository ) - throws ArtifactPathFormatException; - - String getRemoteRepositoryArtifactPath( Artifact artifact, ArtifactRepository remoteRepository ) - throws ArtifactPathFormatException; } \ No newline at end of file diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/handler/manager/DefaultArtifactHandlerManager.java b/maven-artifact/src/main/java/org/apache/maven/artifact/handler/manager/DefaultArtifactHandlerManager.java index bdb348fb7b..881280c78e 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/handler/manager/DefaultArtifactHandlerManager.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/handler/manager/DefaultArtifactHandlerManager.java @@ -16,15 +16,9 @@ package org.apache.maven.artifact.handler.manager; * limitations under the License. */ -import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.artifact.transform.ArtifactTransformation; -import java.util.Iterator; -import java.util.List; import java.util.Map; import java.util.Set; @@ -36,8 +30,6 @@ import java.util.Set; public class DefaultArtifactHandlerManager implements ArtifactHandlerManager { - private List artifactTransformations; - private Map artifactHandlers; private ArtifactRepositoryLayout artifactRepositoryLayout; @@ -59,31 +51,4 @@ public class DefaultArtifactHandlerManager { return artifactHandlers.keySet(); } - - public String getRemoteRepositoryArtifactPath( Artifact artifact, ArtifactRepository remoteRepository ) - throws ArtifactPathFormatException - { - // TODO: note that these are currrently assuming only PUT operations, not GET operations - // TODO: note also that these add metadata to the artifacts, so it is assumed this is only called once per artifact - needs to be fixed - - for ( Iterator i = artifactTransformations.iterator(); i.hasNext(); ) - { - ArtifactTransformation transform = (ArtifactTransformation) i.next(); - artifact = transform.transformRemoteArtifact( artifact, remoteRepository ); - } - - return remoteRepository.pathOf( artifact ); - } - - public String getLocalRepositoryArtifactPath( Artifact artifact, ArtifactRepository localRepository ) - throws ArtifactPathFormatException - { - for ( Iterator i = artifactTransformations.iterator(); i.hasNext(); ) - { - ArtifactTransformation transform = (ArtifactTransformation) i.next(); - artifact = transform.transformLocalArtifact( artifact, localRepository ); - } - - return localRepository.getBasedir() + "/" + localRepository.pathOf( artifact ); - } -} \ No newline at end of file +} 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 d162362b39..531138c4c9 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 @@ -22,12 +22,14 @@ import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundExceptio import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException; +import org.apache.maven.artifact.transform.ArtifactTransformation; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.FileUtils; import java.io.File; import java.io.IOException; import java.util.Iterator; +import java.util.List; public class DefaultArtifactInstaller extends AbstractLogEnabled @@ -35,6 +37,8 @@ public class DefaultArtifactInstaller { private ArtifactHandlerManager artifactHandlerManager; + private List artifactTransformations; + public void install( String basedir, Artifact artifact, ArtifactRepository localRepository ) throws ArtifactInstallationException { @@ -57,12 +61,19 @@ public class DefaultArtifactInstaller { try { - String localPath = artifactHandlerManager.getLocalRepositoryArtifactPath( artifact, localRepository ); + // 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.transformLocalArtifact( artifact, localRepository ); + } + + String localPath = localRepository.pathOf( artifact ); getLogger().info( "Installing " + source.getPath() + " to " + localPath ); // TODO: use a file: wagon and the wagon manager? - File destination = new File( localPath ); + File destination = new File( localRepository.getBasedir(), localPath ); if ( !destination.getParentFile().exists() ) { destination.getParentFile().mkdirs(); 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 8aae4d96c9..f645e98d07 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 @@ -91,7 +91,7 @@ public class DefaultWagonManager wagon.connect( repository, getProxy( repository.getProtocol() ) ); - wagon.put( source, artifactHandlerManager.getRemoteRepositoryArtifactPath( artifact, repository ) ); + wagon.put( source, repository.pathOf( artifact ) ); wagon.disconnect(); @@ -107,11 +107,10 @@ public class DefaultWagonManager { ArtifactRepository repository = (ArtifactRepository) iter.next(); - // TODO: should we avoid doing the transforms on this every time, and instead transform outside the loop? String remotePath = null; try { - remotePath = artifactHandlerManager.getRemoteRepositoryArtifactPath( artifact, repository ); + remotePath = repository.pathOf( artifact ); } catch ( ArtifactPathFormatException e ) { 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 7781b454b3..4b7dfc3138 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 @@ -25,6 +25,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.transform.ArtifactTransformation; import org.apache.maven.wagon.TransferFailedException; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.Logger; @@ -56,6 +57,8 @@ public class DefaultArtifactResolver private ArtifactHandlerManager artifactHandlerManager; + private List artifactTransformations; + // ---------------------------------------------------------------------- // Implementation // ---------------------------------------------------------------------- @@ -67,27 +70,32 @@ public class DefaultArtifactResolver // ---------------------------------------------------------------------- // Check for the existence of the artifact in the specified local // ArtifactRepository. If it is present then simply return as the - // request - // for resolution has been satisfied. + // request for resolution has been satisfied. // ---------------------------------------------------------------------- Logger logger = getLogger(); logger.debug( "Resolving: " + artifact.getId() + " from:\n" + "{localRepository: " + localRepository + "}\n" + "{remoteRepositories: " + remoteRepositories + "}" ); + // 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.transformLocalArtifact( artifact, localRepository ); + } + String localPath; try { - localPath = artifactHandlerManager.getLocalRepositoryArtifactPath( artifact, localRepository ); + localPath = localRepository.pathOf( artifact ); } catch ( ArtifactPathFormatException e ) { throw new ArtifactResolutionException( "Error resolving artifact: ", e ); } - // TODO: what if it were a snapshot that was transformed? - File destination = new File( localPath ); + File destination = new File( localRepository.getBasedir(), localPath ); artifact.setFile( destination ); if ( destination.exists() ) 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 397d2401e4..e9dbda68d3 100644 --- a/maven-artifact/src/main/resources/META-INF/plexus/components.xml +++ b/maven-artifact/src/main/resources/META-INF/plexus/components.xml @@ -25,6 +25,10 @@ org.apache.maven.artifact.handler.manager.ArtifactHandlerManager + + org.apache.maven.artifact.transform.ArtifactTransformation + artifactTransformations + @@ -55,6 +59,10 @@ org.apache.maven.artifact.handler.manager.ArtifactHandlerManager + + org.apache.maven.artifact.transform.ArtifactTransformation + artifactTransformations + @@ -73,6 +81,10 @@ org.apache.maven.artifact.handler.manager.ArtifactHandlerManager + + org.apache.maven.artifact.transform.ArtifactTransformation + artifactTransformations + @@ -111,10 +123,6 @@ org.apache.maven.artifact.handler.ArtifactHandler artifactHandlers - - org.apache.maven.artifact.transform.ArtifactTransformation - artifactTransformations -