From 00206c8dbdee0f9fcd5a9a33c250daf4833717eb Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Sun, 3 Feb 2008 04:50:45 +0000 Subject: [PATCH] o updating for the changes I just made to maven-artifact git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@617948 13f79535-47bb-0310-9956-ffa450edef68 --- .../project/DefaultMavenProjectHelper.java | 27 +---- .../apache/maven/project/MavenProject.java | 55 ++++----- .../artifact/ActiveProjectArtifact.java | 113 ------------------ .../project/artifact/AttachedArtifact.java | 8 +- .../project/artifact/MavenMetadataSource.java | 15 +-- .../resources/META-INF/plexus/components.xml | 19 +-- 6 files changed, 37 insertions(+), 200 deletions(-) diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectHelper.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectHelper.java index fd39c4f2b1..7394d55a56 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectHelper.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectHelper.java @@ -31,26 +31,9 @@ import java.util.List; public class DefaultMavenProjectHelper implements MavenProjectHelper { - - private ArtifactHandlerManager artifactHandlerManager; - public void attachArtifact( MavenProject project, String artifactType, String artifactClassifier, File artifactFile ) - { - String type = artifactType; - - ArtifactHandler handler = null; - - if ( type != null ) - { - handler = artifactHandlerManager.getArtifactHandler( artifactType ); - } - - if ( handler == null ) - { - handler = artifactHandlerManager.getArtifactHandler( "jar" ); - } - - Artifact artifact = new AttachedArtifact( project.getArtifact(), artifactType, artifactClassifier, handler ); + { + Artifact artifact = new AttachedArtifact( project.getArtifact(), artifactType, artifactClassifier ); artifact.setFile( artifactFile ); artifact.setResolved( true ); @@ -60,9 +43,7 @@ public class DefaultMavenProjectHelper public void attachArtifact( MavenProject project, String artifactType, File artifactFile ) { - ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( artifactType ); - - Artifact artifact = new AttachedArtifact( project.getArtifact(), artifactType, handler ); + Artifact artifact = new AttachedArtifact( project.getArtifact(), artifactType ); artifact.setFile( artifactFile ); artifact.setResolved( true ); @@ -74,7 +55,7 @@ public class DefaultMavenProjectHelper { Artifact projectArtifact = project.getArtifact(); - Artifact artifact = new AttachedArtifact( projectArtifact, projectArtifact.getType(), artifactClassifier, projectArtifact.getArtifactHandler() ); + Artifact artifact = new AttachedArtifact( projectArtifact, projectArtifact.getType(), artifactClassifier ); artifact.setFile( artifactFile ); artifact.setResolved( true ); diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java index 867131e401..3101172e5e 100644 --- a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java @@ -23,6 +23,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.versioning.ManagedVersionMap; @@ -152,6 +153,12 @@ public class MavenProject private Stack previousExecutionProjects = new Stack(); + // This should not be in here and neither should any of artifact listing methods that pick off artifacts + // based on their scope as that forces MavenProject to know about all scopes that are available which + // makes the addition of new scopes unscalable. Another component should take as input a MavenProject and + // spit out the list of artifacts based on scope. jvz. + private ArtifactHandlerManager artifactHandlerManager; + public MavenProject() { Model model = new Model(); @@ -168,6 +175,12 @@ public class MavenProject this.model = model; } + // This is temporary until we get the scope related elements out of here. jvz. + public void setArtifactHandlerManager( ArtifactHandlerManager artifactHandlerManager ) + { + this.artifactHandlerManager = artifactHandlerManager; + } + public MavenProject( MavenProject project ) { // disown the parent @@ -490,7 +503,7 @@ public class MavenProject { Artifact a = (Artifact) i.next(); - if ( a.getArtifactHandler().isAddedToClasspath() ) + if ( artifactHandlerManager.getArtifactHandler( a.getType() ).isAddedToClasspath() ) { // TODO: let the scope handler deal with this if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) || @@ -512,7 +525,7 @@ public class MavenProject Artifact a = (Artifact) i.next(); // TODO: classpath check doesn't belong here - that's the other method - if ( a.getArtifactHandler().isAddedToClasspath() ) + if ( artifactHandlerManager.getArtifactHandler( a.getType() ).isAddedToClasspath() ) { // TODO: let the scope handler deal with this if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) || @@ -572,7 +585,7 @@ public class MavenProject { Artifact a = (Artifact) i.next(); - if ( a.getArtifactHandler().isAddedToClasspath() ) + if ( artifactHandlerManager.getArtifactHandler( a.getType() ).isAddedToClasspath() ) { // TODO: let the scope handler deal with this // NOTE: [jc] scope == 'test' is the widest possible scope, so we don't really need to perform @@ -601,7 +614,7 @@ public class MavenProject Artifact a = (Artifact) i.next(); // TODO: classpath check doesn't belong here - that's the other method - if ( a.getArtifactHandler().isAddedToClasspath() ) + if ( artifactHandlerManager.getArtifactHandler( a.getType() ).isAddedToClasspath() ) { // TODO: let the scope handler deal with this // NOTE: [jc] scope == 'test' is the widest possible scope, so we don't really need to perform @@ -666,7 +679,7 @@ public class MavenProject { Artifact a = (Artifact) i.next(); - if ( a.getArtifactHandler().isAddedToClasspath() ) + if ( artifactHandlerManager.getArtifactHandler( a.getType() ).isAddedToClasspath() ) { // TODO: let the scope handler deal with this if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) ) @@ -692,7 +705,7 @@ public class MavenProject Artifact a = (Artifact) i.next(); // TODO: classpath check doesn't belong here - that's the other method - if ( a.getArtifactHandler().isAddedToClasspath() ) + if ( artifactHandlerManager.getArtifactHandler( a.getType() ).isAddedToClasspath() ) { // TODO: let the scope handler deal with this if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) ) @@ -748,7 +761,7 @@ public class MavenProject { Artifact a = (Artifact) i.next(); - if ( a.getArtifactHandler().isAddedToClasspath() ) + if ( artifactHandlerManager.getArtifactHandler( a.getType() ).isAddedToClasspath() ) { // TODO: let the scope handler deal with this if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) ) @@ -769,7 +782,7 @@ public class MavenProject Artifact a = (Artifact) i.next(); // TODO: classpath check doesn't belong here - that's the other method - if ( a.getArtifactHandler().isAddedToClasspath() ) + if ( artifactHandlerManager.getArtifactHandler( a.getType() ).isAddedToClasspath() ) { // TODO: let the scope handler deal with this if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) ) @@ -1750,30 +1763,4 @@ public class MavenProject { return (Plugin) getBuild().getPluginsAsMap().get( pluginKey ); } - /** - * Default toString - */ - public String toString() - { - StringBuffer sb = new StringBuffer(30); - sb.append( "MavenProject: " ); - sb.append( this.getGroupId() ); - sb.append( ":" ); - sb.append( this.getArtifactId() ); - sb.append( ":" ); - sb.append( this.getVersion() ); - sb.append( " @ " ); - - try - { - sb.append( this.getFile().getPath() ); - } - catch (NullPointerException e) - { - //don't log it. - } - - return sb.toString(); - } - } diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java b/maven-project/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java index 7e4f0bd926..dc5c390b53 100644 --- a/maven-project/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java +++ b/maven-project/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java @@ -58,345 +58,232 @@ public class ActiveProjectArtifact artifact.setResolved( true ); } - /** {@inheritDoc} */ public File getFile() { // we need to get the latest file for the project, not the artifact that was created at one point in time return project.getArtifact().getFile(); } - /** {@inheritDoc} */ public String getGroupId() { return artifact.getGroupId(); } - /** {@inheritDoc} */ public String getArtifactId() { return artifact.getArtifactId(); } - /** {@inheritDoc} */ public String getVersion() { return artifact.getVersion(); } - /** {@inheritDoc} */ public void setVersion( String version ) { artifact.setVersion( version ); } - /** {@inheritDoc} */ public String getScope() { return artifact.getScope(); } - /** {@inheritDoc} */ public String getType() { return artifact.getType(); } - /** {@inheritDoc} */ public String getClassifier() { return artifact.getClassifier(); } - /** {@inheritDoc} */ public boolean hasClassifier() { return artifact.hasClassifier(); } - /** {@inheritDoc} */ public void setFile( File destination ) { artifact.setFile( destination ); project.getArtifact().setFile( destination ); } - /** {@inheritDoc} */ public String getBaseVersion() { return artifact.getBaseVersion(); } - /** {@inheritDoc} */ public void setBaseVersion( String baseVersion ) { artifact.setBaseVersion( baseVersion ); } - /** {@inheritDoc} */ public String getId() { return artifact.getId(); } - /** {@inheritDoc} */ public String getDependencyConflictId() { return artifact.getDependencyConflictId(); } - /** {@inheritDoc} */ public void addMetadata( ArtifactMetadata metadata ) { artifact.addMetadata( metadata ); } - /** {@inheritDoc} */ public Collection getMetadataList() { return artifact.getMetadataList(); } - /** {@inheritDoc} */ public void setRepository( ArtifactRepository remoteRepository ) { artifact.setRepository( remoteRepository ); } - /** {@inheritDoc} */ public ArtifactRepository getRepository() { return artifact.getRepository(); } - /** {@inheritDoc} */ public void updateVersion( String version, ArtifactRepository localRepository ) { artifact.updateVersion( version, localRepository ); } - /** {@inheritDoc} */ public String getDownloadUrl() { return artifact.getDownloadUrl(); } - /** {@inheritDoc} */ public void setDownloadUrl( String downloadUrl ) { artifact.setDownloadUrl( downloadUrl ); } - /** {@inheritDoc} */ public ArtifactFilter getDependencyFilter() { return artifact.getDependencyFilter(); } - /** {@inheritDoc} */ public void setDependencyFilter( ArtifactFilter artifactFilter ) { artifact.setDependencyFilter( artifactFilter ); } - /** {@inheritDoc} */ - public ArtifactHandler getArtifactHandler() - { - return artifact.getArtifactHandler(); - } - - /** {@inheritDoc} */ public List getDependencyTrail() { return artifact.getDependencyTrail(); } - /** {@inheritDoc} */ public void setDependencyTrail( List dependencyTrail ) { artifact.setDependencyTrail( dependencyTrail ); } - /** {@inheritDoc} */ public void setScope( String scope ) { artifact.setScope( scope ); } - /** {@inheritDoc} */ public VersionRange getVersionRange() { return artifact.getVersionRange(); } - /** {@inheritDoc} */ public void setVersionRange( VersionRange newRange ) { artifact.setVersionRange( newRange ); } - /** {@inheritDoc} */ public void selectVersion( String version ) { artifact.selectVersion( version ); } - /** {@inheritDoc} */ public void setGroupId( String groupId ) { artifact.setGroupId( groupId ); } - /** {@inheritDoc} */ public void setArtifactId( String artifactId ) { artifact.setArtifactId( artifactId ); } - /** {@inheritDoc} */ public boolean isSnapshot() { return artifact.isSnapshot(); } - /** {@inheritDoc} */ public int compareTo( Object o ) { return artifact.compareTo( o ); } - /** {@inheritDoc} */ public void setResolved( boolean resolved ) { artifact.setResolved( resolved ); } - /** {@inheritDoc} */ public boolean isResolved() { return artifact.isResolved(); } - /** {@inheritDoc} */ public void setResolvedVersion( String version ) { artifact.setResolvedVersion( version ); } - /** {@inheritDoc} */ - public void setArtifactHandler( ArtifactHandler handler ) - { - artifact.setArtifactHandler( handler ); - } - - /** {@inheritDoc} */ public String toString() { return "active project artifact:\n\tartifact = " + artifact + ";\n\tproject: " + project; } - /** {@inheritDoc} */ public boolean isRelease() { return artifact.isRelease(); } - /** {@inheritDoc} */ public void setRelease( boolean release ) { artifact.setRelease( release ); } - /** {@inheritDoc} */ public List getAvailableVersions() { return artifact.getAvailableVersions(); } - /** {@inheritDoc} */ public void setAvailableVersions( List versions ) { artifact.setAvailableVersions( versions ); } - /** {@inheritDoc} */ public boolean isOptional() { return artifact.isOptional(); } - /** {@inheritDoc} */ public ArtifactVersion getSelectedVersion() throws OverConstrainedVersionException { return artifact.getSelectedVersion(); } - /** {@inheritDoc} */ public boolean isSelectedVersionKnown() throws OverConstrainedVersionException { return artifact.isSelectedVersionKnown(); } - /** {@inheritDoc} */ public void setOptional( boolean optional ) { artifact.setOptional( optional ); } - - /** {@inheritDoc} */ - public int hashCode() - { - int result = 17; - - result = 37 * result + getGroupId().hashCode(); - result = 37 * result + getArtifactId().hashCode(); - result = 37 * result + getType().hashCode(); - if ( getVersion() != null ) - { - result = 37 * result + getVersion().hashCode(); - } - result = 37 * result + ( getClassifier() != null ? getClassifier().hashCode() : 0 ); - - return result; - } - - /** {@inheritDoc} */ - public boolean equals( Object o ) - { - if ( o == this ) - { - return true; - } - - if ( !( o instanceof Artifact ) ) - { - return false; - } - - Artifact a = (Artifact) o; - - if ( !a.getGroupId().equals( getGroupId() ) ) - { - return false; - } - else if ( !a.getArtifactId().equals( getArtifactId() ) ) - { - return false; - } - else if ( !a.getVersion().equals( getVersion() ) ) - { - return false; - } - else if ( !a.getType().equals( getType() ) ) - { - return false; - } - else if ( a.getClassifier() == null ? getClassifier() != null : !a.getClassifier().equals( getClassifier() ) ) - { - return false; - } - - return true; - } } diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java b/maven-project/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java index b17378abb3..90245b9335 100644 --- a/maven-project/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java +++ b/maven-project/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java @@ -37,10 +37,10 @@ public class AttachedArtifact private final Artifact parent; - public AttachedArtifact( Artifact parent, String type, String classifier, ArtifactHandler artifactHandler ) + public AttachedArtifact( Artifact parent, String type, String classifier ) { super( parent.getGroupId(), parent.getArtifactId(), parent.getVersionRange(), parent.getScope(), type, - classifier, artifactHandler, parent.isOptional() ); + classifier, parent.isOptional() ); setDependencyTrail( Collections.singletonList( parent.getId() ) ); @@ -52,9 +52,9 @@ public class AttachedArtifact } } - public AttachedArtifact( Artifact parent, String type, ArtifactHandler artifactHandler ) + public AttachedArtifact( Artifact parent, String type ) { - this( parent, type, null, artifactHandler ); + this( parent, type, null ); } public void setArtifactId( String artifactId ) diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index 4148286eb5..615a0c8c00 100644 --- a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -21,6 +21,7 @@ package org.apache.maven.project.artifact; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.metadata.ResolutionGroup; @@ -84,6 +85,8 @@ public class MavenMetadataSource private PlexusContainer container; + private ArtifactHandlerManager artifactHandlerManager; + /** Unfortunately we have projects that are still sending us JARs without the accompanying POMs. */ private boolean strictlyEnforceThePresenceOfAValidMavenPOM = false; @@ -127,12 +130,6 @@ public class MavenMetadataSource } catch ( InvalidProjectModelException e ) { - if ( strictlyEnforceThePresenceOfAValidMavenPOM ) - { - throw new ArtifactMetadataRetrievalException( "Invalid POM file for artifact: '" + - artifact.getDependencyConflictId() + "' Reason: " + e.getMessage(), e, artifact ); - } - getLogger().warn( "POM for \'" + pomArtifact + "\' is invalid. It will be ignored for artifact resolution. Reason: " + e.getMessage() ); @@ -151,10 +148,6 @@ public class MavenMetadataSource } getLogger().debug( "\n" ); } - else - { - getLogger().debug( "", e ); - } } project = null; @@ -253,7 +246,7 @@ public class MavenMetadataSource else { Set artifacts = Collections.EMPTY_SET; - if ( !artifact.getArtifactHandler().isIncludesDependencies() ) + if ( !artifactHandlerManager.getArtifactHandler( artifact.getType() ).isIncludesDependencies() ) { // TODO: we could possibly use p.getDependencyArtifacts instead of this call, but they haven't been filtered // or used the inherited scope (should that be passed to the buildFromRepository method above?) diff --git a/maven-project/src/main/resources/META-INF/plexus/components.xml b/maven-project/src/main/resources/META-INF/plexus/components.xml index 51afcef40d..f5402783a9 100644 --- a/maven-project/src/main/resources/META-INF/plexus/components.xml +++ b/maven-project/src/main/resources/META-INF/plexus/components.xml @@ -256,22 +256,8 @@ under the License. org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager - - - - - org.apache.maven.artifact.metadata.ArtifactMetadataSource - maven-strict - org.apache.maven.project.artifact.MavenMetadataSource - - true - - - org.apache.maven.artifact.factory.ArtifactFactory - - - org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager + org.apache.maven.artifact.handler.manager.ArtifactHandlerManager @@ -287,6 +273,9 @@ under the License. org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager + + org.apache.maven.artifact.handler.manager.ArtifactHandlerManager +