From 590e952f0276f970117e505c58cc6b5d6b63928a Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Mon, 21 Mar 2005 08:18:34 +0000 Subject: [PATCH] CHANGES ------------------------ o Factored the layout for a repository into a separate set of components in o.a.m.a.repository.layout o Added new DefaultRepositoryLayout that uses the repo layout in http://docs.codehaus.org/pages/viewpage.action?pageId=22230 (it is not used by default until we get the repo1 conversion done) o Added command-line switches to force legacy local-repo or new format (-a/-A, I know, but try to find something that makes more sense!) o Added path formatting to the repository itself, which is now constructed with a ArtifactRepositoryLayout instance (since layout should be tied to the repository) o Removed path formatting altogether from the DefaultArtifactHandlerManager. o Changed the AbstractArtifactBasedComponent (or whatever it's called) to use the repository formatting in the path() and localPath() methods. o Moved the plugin repo construction (still intact as a hard-coded singleton list) into the DefaultMavenProjectBuilder, where it will eventually build from POM info. o Added a new method to build an artifact repository for a section, if possible. This reduced the strain on mojos to construct an ArtifactRepository on demand. o Refactored all *DeployMojo to use #project.distributionManagementArtifactRepository instead of the #settings, #component..ArtifactRepositoryFactory, ... that it used to require. This is a big simplifying step. o Removed remote artifact repository construction from DefaultMaven, and changed the MavenSession to delegate to MavenProject for remoteArtifactRepositories, just as it does for pluginRepositories. o Added remoteArtifactRepositories, pluginArtifactRepositories, distributionManagementArtifactRepository to MavenProject as a cache for the higher-level repos used throughout the system. This is project info, so it belongs here. o Fixed all the tests in maven-core and maven-artifact which I broke. :) o Dropped what is probably a big format-bomb, since the Eclipse formatter doesn't really handle 'throws Exception' wrapping the right way. o Added MavenProject to the MavenSession constructor, since there should always be a MavenProject associated with a build, even if it's just the super-pom. TODO: -------------------------- - Write an integration/unit test to ensure that the new repo format works with $classifier (was: $extra) and $groupId[0]/../$groupId[n]. This is a simple adaptation of the old layout, but still needs testing. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163638 13f79535-47bb-0310-9956-ffa450edef68 --- .../artifact/AbstractArtifactComponent.java | 15 +- .../org/apache/maven/artifact/Artifact.java | 9 +- .../maven/artifact/DefaultArtifact.java | 45 ++++- .../manager/ArtifactHandlerManager.java | 17 +- .../DefaultArtifactHandlerManager.java | 86 +++------- .../installer/DefaultArtifactInstaller.java | 5 +- .../artifact/manager/DefaultWagonManager.java | 6 +- .../repository/ArtifactRepository.java | 21 ++- .../AbstractArtifactRepositoryLayout.java | 78 +++++++++ .../layout/ArtifactPathFormatException.java | 32 ++++ .../layout/ArtifactRepositoryLayout.java | 32 ++++ .../layout/DefaultRepositoryLayout.java | 37 ++++ .../layout/LegacyRepositoryLayout.java | 37 ++++ .../resolver/DefaultArtifactResolver.java | 59 +++---- .../resources/META-INF/plexus/components.xml | 19 ++- .../artifact/ArtifactComponentTestCase.java | 71 +++++--- .../resolver/ArtifactResolverTest.java | 33 ++-- .../java/org/apache/maven/DefaultMaven.java | 46 ++--- .../repository/ArtifactRepositoryFactory.java | 4 +- .../DefaultArtifactRepositoryFactory.java | 14 +- .../java/org/apache/maven/cli/MavenCli.java | 134 +++++++++------ .../apache/maven/execution/MavenSession.java | 30 ++-- .../lifecycle/DefaultLifecycleExecutor.java | 25 +-- .../maven/plugin/DefaultPluginManager.java | 81 +++------ .../project/DefaultMavenProjectBuilder.java | 159 ++++++++++++++---- .../apache/maven/project/MavenProject.java | 65 +++++-- .../java/org/apache/maven/MavenTestCase.java | 20 ++- ...luginParameterExpressionEvaluatorTest.java | 48 +++--- .../ProjectClasspathArtifactResolver.java | 15 +- .../plugin/deploy/AbstractDeployMojo.java | 49 ++---- .../maven/plugin/deploy/DeployMojo.java | 16 +- .../org/apache/maven/plugin/ejb/EjbMojo.java | 22 ++- .../maven/plugin/jar/JarDeployMojo.java | 49 +++--- .../maven/plugin/pom/PomDeployMojo.java | 72 ++++---- 34 files changed, 904 insertions(+), 547 deletions(-) create mode 100644 maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java create mode 100644 maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactPathFormatException.java create mode 100644 maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout.java create mode 100644 maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java create mode 100644 maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/AbstractArtifactComponent.java b/maven-artifact/src/main/java/org/apache/maven/artifact/AbstractArtifactComponent.java index 74e12b0bb3..b8d8ebec00 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/AbstractArtifactComponent.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/AbstractArtifactComponent.java @@ -20,6 +20,7 @@ import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException; import org.codehaus.plexus.logging.AbstractLogEnabled; /** @@ -38,15 +39,21 @@ public class AbstractArtifactComponent return artifactHandlerManager.getArtifactHandler( type ); } - protected String path( Artifact artifact ) throws ArtifactHandlerNotFoundException + protected String path( Artifact artifact, ArtifactRepository remoteRepository ) throws ArtifactPathFormatException { - return artifactHandlerManager.path( artifact ); + return remoteRepository.pathOf( artifact ); + } + + protected String localPath( Artifact artifact, ArtifactRepository localRepository ) + throws ArtifactPathFormatException + { + return localRepository.getBasedir() + "/" + localRepository.pathOf( artifact ); } protected void setLocalRepositoryPath( Artifact artifact, ArtifactRepository localRepository ) - throws ArtifactHandlerNotFoundException + throws ArtifactPathFormatException { - String artifactPath = artifactHandlerManager.localRepositoryPath( artifact, localRepository ); + String artifactPath = localPath( artifact, localRepository ); artifact.setPath( artifactPath ); } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java b/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java index 2a738e307d..9c8d65b008 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java @@ -22,7 +22,9 @@ public interface Artifact { // TODO: into scope handler String SCOPE_COMPILE = "compile"; + String SCOPE_TEST = "test"; + String SCOPE_RUNTIME = "runtime"; String getGroupId(); @@ -35,6 +37,11 @@ public interface Artifact String getType(); + String getClassifier(); + + // only providing this since classifier is *very* optional... + boolean hasClassifier(); + String getExtension(); // ---------------------------------------------------------------------- @@ -56,4 +63,4 @@ public interface Artifact String getId(); String getConflictId(); -} +} \ No newline at end of file diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java b/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java index dc5f3894f4..72505a194d 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java @@ -16,6 +16,8 @@ package org.apache.maven.artifact; * limitations under the License. */ +import org.codehaus.plexus.util.StringUtils; + import java.io.File; /** @@ -25,7 +27,7 @@ import java.io.File; public class DefaultArtifact implements Artifact { - + // ---------------------------------------------------------------------- // These are the only things i need to specify // ---------------------------------------------------------------------- @@ -38,6 +40,8 @@ public class DefaultArtifact private String type; + private String classifier; + private String scope; private String extension; @@ -47,11 +51,22 @@ public class DefaultArtifact /** * @todo this should be replaced by type handler */ - public DefaultArtifact( String groupId, String artifactId, String version, String scope, String type, String extension ) + public DefaultArtifact( String groupId, String artifactId, String version, String scope, String type, + String extension ) { - if(type == null) + this( groupId, artifactId, version, scope, type, null, extension ); + } + + /** + * !!! WARNING !!! Never put in the POM. It is for mojo use + * only. Classifier is for specifying derived artifacts, like ejb-client. + */ + public DefaultArtifact( String groupId, String artifactId, String version, String scope, String type, + String classifier, String extension ) + { + if ( type == null ) { - throw new NullPointerException("Artifact type cannot be null."); + throw new NullPointerException( "Artifact type cannot be null." ); } this.groupId = groupId; @@ -64,12 +79,24 @@ public class DefaultArtifact this.scope = scope; + this.classifier = classifier; + this.extension = extension; } public DefaultArtifact( String groupId, String artifactId, String version, String type ) { - this( groupId, artifactId, version, null, type, type ); + this( groupId, artifactId, version, null, type, null, type ); + } + + public String getClassifier() + { + return classifier; + } + + public boolean hasClassifier() + { + return StringUtils.isNotEmpty( classifier ); } public String getScope() @@ -142,12 +169,13 @@ public class DefaultArtifact public String getId() { - return getGroupId() + ":" + getArtifactId() + ":" + getType() + ":" + getVersion(); + return getConflictId() + ":" + getVersion(); } public String getConflictId() { - return getGroupId() + ":" + getArtifactId() + ":" + getType(); + return getGroupId() + ":" + getArtifactId() + ":" + getType() + + ( hasClassifier() ? ( ":" + getClassifier() ) : "" ); } // ---------------------------------------------------------------------- @@ -168,7 +196,6 @@ public class DefaultArtifact { Artifact other = (Artifact) o; - return this.groupId.equals( other.getGroupId() ) && this.artifactId.equals( other.getArtifactId() ) && this.version.equals( - other.getVersion() ) && this.type.equals( other.getType() ); + return getId().equals( other.getId() ); } } \ No newline at end of file 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 5d236684ef..f104bf2370 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 @@ -1,8 +1,6 @@ package org.apache.maven.artifact.handler.manager; -import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.artifact.repository.ArtifactRepository; import java.util.Set; @@ -30,15 +28,14 @@ public interface ArtifactHandlerManager { String ROLE = ArtifactHandlerManager.class.getName(); - ArtifactHandler getArtifactHandler( String type ) - throws ArtifactHandlerNotFoundException; + ArtifactHandler getArtifactHandler( String type ) throws ArtifactHandlerNotFoundException; - String localRepositoryPath( Artifact artifact, ArtifactRepository localRepository ) - throws ArtifactHandlerNotFoundException; - - String path( Artifact artifact ) - throws ArtifactHandlerNotFoundException; + // String localRepositoryPath( Artifact artifact, ArtifactRepository localRepository ) + // throws ArtifactHandlerNotFoundException; + // + // String path( Artifact artifact ) + // throws ArtifactHandlerNotFoundException; Set getHandlerTypes(); -} +} \ 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 a2ba914149..9e49ec43ee 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,10 +16,8 @@ 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.codehaus.plexus.util.StringUtils; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import java.util.Map; import java.util.Set; @@ -34,8 +32,9 @@ public class DefaultArtifactHandlerManager { private Map artifactHandlers; - public ArtifactHandler getArtifactHandler( String type ) - throws ArtifactHandlerNotFoundException + private ArtifactRepositoryLayout artifactRepositoryLayout; + + public ArtifactHandler getArtifactHandler( String type ) throws ArtifactHandlerNotFoundException { ArtifactHandler handler = (ArtifactHandler) artifactHandlers.get( type ); @@ -56,58 +55,29 @@ public class DefaultArtifactHandlerManager // // ---------------------------------------------------------------------- - private String layout; + // public String localRepositoryPath( Artifact artifact, ArtifactRepository localRepository ) + // throws ArtifactHandlerNotFoundException + // { + // return localRepository.getBasedir() + "/" + path( artifact ); + // } + // + // public String artifactUrl( Artifact artifact, ArtifactRepository remoteRepository ) + // throws ArtifactHandlerNotFoundException + // { + // return remoteRepository.getUrl() + "/" + path( artifact ); + // } + // + // public String path( Artifact artifact ) + // throws ArtifactHandlerNotFoundException + // { + // if ( artifact.getType() == null ) + // { + // throw new ArtifactHandlerNotFoundException( "Artifact handler is null for artifact " + artifact ); + // } + // + // ArtifactHandler handler = getArtifactHandler( artifact.getType() ); + // + // return artifactRepositoryLayout.pathOf( artifact, handler ); + // } - public String getLayout() - { - if ( layout == null ) - { - return "${groupId}/${directory}/${artifactId}-${version}.${extension}"; - } - - return layout; - } - - public String localRepositoryPath( Artifact artifact, ArtifactRepository localRepository ) - throws ArtifactHandlerNotFoundException - { - return localRepository.getBasedir() + "/" + path( artifact ); - } - - public String artifactUrl( Artifact artifact, ArtifactRepository remoteRepository ) - throws ArtifactHandlerNotFoundException - { - return remoteRepository.getUrl() + "/" + path( artifact ); - } - - public String path( Artifact artifact ) - throws ArtifactHandlerNotFoundException - { - if ( artifact.getType() == null ) - { - throw new ArtifactHandlerNotFoundException( "Artifact handler is null for artifact " + artifact ); - } - - ArtifactHandler handler = getArtifactHandler( artifact.getType() ); - - return interpolateLayout( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), handler.directory(), handler.extension() ); - } - - private String interpolateLayout( String groupId, String artifactId, String version, String directory, - String extension ) - { - String layout = getLayout(); - - layout = StringUtils.replace( layout, "${groupId}", groupId ); - - layout = StringUtils.replace( layout, "${artifactId}", artifactId ); - - layout = StringUtils.replace( layout, "${directory}", directory ); - - layout = StringUtils.replace( layout, "${version}", version ); - - layout = StringUtils.replace( layout, "${extension}", extension ); - - return layout; - } } \ 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 92e6ccb25b..fc9b28c183 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.AbstractArtifactComponent; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException; import org.codehaus.plexus.util.FileUtils; import java.io.File; @@ -69,9 +70,9 @@ public class DefaultArtifactInstaller { throw new ArtifactInstallationException( "Error installing artifact: ", e ); } - catch ( ArtifactHandlerNotFoundException e ) + catch ( ArtifactPathFormatException 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 8374888c20..713b7b373e 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 @@ -80,7 +80,7 @@ public class DefaultWagonManager wagon.connect( repository, getProxy( repository.getProtocol() ) ); - wagon.put( source, path( artifact ) ); + wagon.put( source, path( artifact, repository ) ); wagon.disconnect(); @@ -148,7 +148,9 @@ public class DefaultWagonManager wagon.connect( repository, getProxy( repository.getProtocol() ) ); - wagon.get( path( artifact ), temp ); + String remotePath = path( artifact, repository ); + + wagon.get( remotePath, temp ); // TODO [BP]: put all disconnects in finally wagon.disconnect(); diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java index 1ac4dc070b..f3e18cc9b4 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java @@ -16,6 +16,9 @@ package org.apache.maven.artifact.repository; * limitations under the License. */ +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.wagon.authentication.AuthenticationInfo; import org.apache.maven.wagon.repository.Repository; @@ -29,14 +32,26 @@ import org.apache.maven.wagon.repository.Repository; public class ArtifactRepository extends Repository { - - public ArtifactRepository( String id, String url ) + + private final ArtifactRepositoryLayout layout; + + public ArtifactRepository( String id, String url, ArtifactRepositoryLayout layout ) { super( id, url ); + + this.layout = layout; } - public ArtifactRepository( String id, String url, AuthenticationInfo authInfo ) + public ArtifactRepository( String id, String url, AuthenticationInfo authInfo, ArtifactRepositoryLayout layout ) { super( id, url, authInfo ); + + this.layout = layout; } + + public String pathOf( Artifact artifact ) throws ArtifactPathFormatException + { + return layout.pathOf( artifact ); + } + } \ No newline at end of file diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java new file mode 100644 index 0000000000..5487609926 --- /dev/null +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java @@ -0,0 +1,78 @@ +package org.apache.maven.artifact.repository.layout; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; +import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException; +import org.codehaus.plexus.util.StringUtils; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +/** + * @author jdcasey + */ +public abstract class AbstractArtifactRepositoryLayout + implements ArtifactRepositoryLayout +{ + + private ArtifactHandlerManager artifactHandlerManager; + + protected abstract String layoutPattern(); + + protected abstract String groupIdAsPath( String groupId ); + + public String pathOf( Artifact artifact ) throws ArtifactPathFormatException + { + String path = layoutPattern(); + + String groupPath = groupIdAsPath( artifact.getGroupId() ); + + path = StringUtils.replace( path, "${groupPath}", groupPath ); + + path = StringUtils.replace( path, "${artifactId}", artifact.getArtifactId() ); + + path = StringUtils.replace( path, "${version}", artifact.getVersion() ); + + if ( artifact.hasClassifier() ) + { + path = StringUtils.replace( path, "${classifier}", artifact.getClassifier() ); + } + else + { + path = StringUtils.replace( path, "-${classifier}", "" ); + } + + ArtifactHandler artifactHandler = null; + try + { + artifactHandler = artifactHandlerManager.getArtifactHandler( artifact.getType() ); + } + catch ( ArtifactHandlerNotFoundException e ) + { + throw new ArtifactPathFormatException( "Cannot find ArtifactHandler for artifact: \'" + artifact.getId() + + "\'.", e ); + } + + path = StringUtils.replace( path, "${directory}", artifactHandler.directory() ); + + path = StringUtils.replace( path, "${extension}", artifact.getExtension() ); + + return path; + } + +} \ No newline at end of file diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactPathFormatException.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactPathFormatException.java new file mode 100644 index 0000000000..d2e502dbcd --- /dev/null +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactPathFormatException.java @@ -0,0 +1,32 @@ +package org.apache.maven.artifact.repository.layout; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +/** + * @author jdcasey + */ +public class ArtifactPathFormatException + extends Exception +{ + + public ArtifactPathFormatException( String message, Throwable cause ) + { + super( message, cause ); + } + +} \ No newline at end of file diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout.java new file mode 100644 index 0000000000..ca46d2dea5 --- /dev/null +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout.java @@ -0,0 +1,32 @@ +package org.apache.maven.artifact.repository.layout; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +import org.apache.maven.artifact.Artifact; + +/** + * @author jdcasey + */ +public interface ArtifactRepositoryLayout +{ + + String ROLE = ArtifactRepositoryLayout.class.getName(); + + String pathOf( Artifact artifact ) throws ArtifactPathFormatException; + +} \ No newline at end of file diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java new file mode 100644 index 0000000000..74386ef03d --- /dev/null +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java @@ -0,0 +1,37 @@ +package org.apache.maven.artifact.repository.layout; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +/** + * @author jdcasey + */ +public class DefaultRepositoryLayout + extends AbstractArtifactRepositoryLayout +{ + + protected String layoutPattern() + { + return "${groupId}/${artifactId}/${version}/${artifactId}-${version}-${classifier}.${extension}"; + } + + protected String groupIdAsPath( String groupId ) + { + return groupId.replace( '.', '/' ); + } + +} \ No newline at end of file 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 new file mode 100644 index 0000000000..c362858fec --- /dev/null +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java @@ -0,0 +1,37 @@ +package org.apache.maven.artifact.repository.layout; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +/** + * @author jdcasey + */ +public class LegacyRepositoryLayout + extends AbstractArtifactRepositoryLayout +{ + + protected String layoutPattern() + { + return "${groupPath}/${directory}/${artifactId}-${version}-${classifier}.${extension}"; + } + + protected String groupIdAsPath( String groupId ) + { + return groupId; + } + +} \ No newline at end of file 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 32a5c1b3ed..302dd0f15e 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 @@ -3,11 +3,11 @@ package org.apache.maven.artifact.resolver; import org.apache.maven.artifact.AbstractArtifactComponent; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.construction.ArtifactConstructionSupport; -import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException; import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; 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.resolver.transform.ArtifactRequestTransformation; import org.apache.maven.wagon.TransferFailedException; @@ -45,7 +45,7 @@ public class DefaultArtifactResolver // ---------------------------------------------------------------------- // Implementation // ---------------------------------------------------------------------- - + private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport(); public Artifact resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) @@ -65,8 +65,8 @@ public class DefaultArtifactResolver try { Logger logger = getLogger(); - logger.debug( "Resolving: " + artifact.getId() + " from:\n" + "{localRepository: " + localRepository + - "}\n" + "{remoteRepositories: " + remoteRepositories + "}" ); + logger.debug( "Resolving: " + artifact.getId() + " from:\n" + "{localRepository: " + localRepository + + "}\n" + "{remoteRepositories: " + remoteRepositories + "}" ); setLocalRepositoryPath( artifact, localRepository ); @@ -77,14 +77,14 @@ public class DefaultArtifactResolver wagonManager.get( artifact, remoteRepositories, localRepository ); } - catch ( ArtifactHandlerNotFoundException e ) - { - throw new ArtifactResolutionException( "Error resolving artifact: ", e ); - } catch ( TransferFailedException e ) { throw new ArtifactResolutionException( artifactNotFound( artifact, remoteRepositories ), e ); } + catch ( ArtifactPathFormatException e ) + { + throw new ArtifactResolutionException( "Error resolving artifact: ", e ); + } return artifact; } @@ -95,8 +95,9 @@ public class DefaultArtifactResolver { StringBuffer sb = new StringBuffer(); - sb.append( "The artifact is not present locally as:" ).append( LS ).append( LS ).append( artifact.getPath() ).append( - LS ).append( LS ).append( "or in any of the specified remote repositories:" ).append( LS ).append( LS ); + sb.append( "The artifact is not present locally as:" ).append( LS ).append( LS ).append( artifact.getPath() ) + .append( LS ).append( LS ).append( "or in any of the specified remote repositories:" ).append( LS ) + .append( LS ); for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); ) { @@ -134,8 +135,8 @@ public class DefaultArtifactResolver // ---------------------------------------------------------------------- public ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories, - ArtifactRepository localRepository, - ArtifactMetadataSource source, ArtifactFilter filter ) + ArtifactRepository localRepository, + ArtifactMetadataSource source, ArtifactFilter filter ) throws ArtifactResolutionException { ArtifactResolutionResult artifactResolutionResult; @@ -158,16 +159,16 @@ public class DefaultArtifactResolver } public ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories, - ArtifactRepository localRepository, - ArtifactMetadataSource source ) + ArtifactRepository localRepository, + ArtifactMetadataSource source ) throws ArtifactResolutionException { return resolveTransitively( artifacts, remoteRepositories, localRepository, source, null ); } public ArtifactResolutionResult resolveTransitively( Artifact artifact, List remoteRepositories, - ArtifactRepository localRepository, - ArtifactMetadataSource source ) + ArtifactRepository localRepository, + ArtifactMetadataSource source ) throws ArtifactResolutionException { return resolveTransitively( Collections.singleton( artifact ), remoteRepositories, localRepository, source ); @@ -178,9 +179,8 @@ public class DefaultArtifactResolver // ---------------------------------------------------------------------- private ArtifactResolutionResult collect( Set artifacts, ArtifactRepository localRepository, - List remoteRepositories, ArtifactMetadataSource source, - ArtifactFilter filter ) - throws TransitiveArtifactResolutionException + List remoteRepositories, ArtifactMetadataSource source, + ArtifactFilter filter ) throws TransitiveArtifactResolutionException { ArtifactResolutionResult result = new ArtifactResolutionResult(); @@ -215,14 +215,14 @@ public class DefaultArtifactResolver // TODO: scope handler boolean updateScope = false; - if ( Artifact.SCOPE_RUNTIME.equals( newArtifact.getScope() ) && - Artifact.SCOPE_TEST.equals( knownArtifact.getScope() ) ) + if ( Artifact.SCOPE_RUNTIME.equals( newArtifact.getScope() ) + && Artifact.SCOPE_TEST.equals( knownArtifact.getScope() ) ) { updateScope = true; } - if ( Artifact.SCOPE_COMPILE.equals( newArtifact.getScope() ) && - !Artifact.SCOPE_COMPILE.equals( knownArtifact.getScope() ) ) + if ( Artifact.SCOPE_COMPILE.equals( newArtifact.getScope() ) + && !Artifact.SCOPE_COMPILE.equals( knownArtifact.getScope() ) ) { updateScope = true; } @@ -231,9 +231,10 @@ public class DefaultArtifactResolver { // TODO: Artifact factory? // TODO: [jc] Is this a better way to centralize artifact construction here? - Artifact artifact = artifactConstructionSupport.createArtifact( knownArtifact.getGroupId(), - knownArtifact.getArtifactId(), - knownVersion, newArtifact.getScope(), + Artifact artifact = artifactConstructionSupport.createArtifact( knownArtifact.getGroupId(), + knownArtifact.getArtifactId(), + knownVersion, + newArtifact.getScope(), knownArtifact.getType(), knownArtifact.getExtension() ); resolvedArtifacts.put( artifact.getConflictId(), artifact ); @@ -260,8 +261,8 @@ public class DefaultArtifactResolver } catch ( ArtifactMetadataRetrievalException e ) { - throw new TransitiveArtifactResolutionException( "Error retrieving metadata [" + newArtifact + - "] : ", e ); + throw new TransitiveArtifactResolutionException( "Error retrieving metadata [" + newArtifact + + "] : ", e ); } // the pom for given dependency exisit we will add it to the @@ -287,7 +288,7 @@ public class DefaultArtifactResolver { setLocalRepositoryPath( artifact, localRepository ); } - catch ( ArtifactHandlerNotFoundException e ) + catch ( ArtifactPathFormatException e ) { throw new TransitiveArtifactResolutionException( "Error collecting artifact: ", e ); } 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 f2a046536e..bd4748ce7b 100644 --- a/maven-artifact/src/main/resources/META-INF/plexus/components.xml +++ b/maven-artifact/src/main/resources/META-INF/plexus/components.xml @@ -67,6 +67,23 @@ + + org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout + default + org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout + + + + org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout + legacy + org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout + + + org.apache.maven.artifact.handler.manager.ArtifactHandlerManager + + + +