From 5b427cf0768e0f85b36f3b9406c21c8fdf68af2d Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Tue, 6 Dec 2005 20:50:41 +0000 Subject: [PATCH] PR: MNG-1630 Submitted By: Edwin Punzalan Reviewed By: John Casey Applied patches, with minor changes. These patches will ensure that the optional flag is passed on and inherited correctly when dealing with managed dependencies. I changed the patches, in that I added a new createDependencyArtifact(..) method on ArtifactFactory, which will eliminate the need to call an older variant of the method by passing in a null value for the inheritedScope parameter. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@354544 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/java/org/apache/maven/artifact/Artifact.java | 2 ++ .../java/org/apache/maven/artifact/DefaultArtifact.java | 5 +++++ .../org/apache/maven/artifact/factory/ArtifactFactory.java | 3 +++ .../maven/artifact/factory/DefaultArtifactFactory.java | 6 ++++++ .../apache/maven/project/DefaultMavenProjectBuilder.java | 3 ++- .../maven/project/artifact/ActiveProjectArtifact.java | 5 +++++ 6 files changed, 23 insertions(+), 1 deletion(-) 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 13325d4ca0..9194859bde 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 @@ -156,6 +156,8 @@ public interface Artifact void setAvailableVersions( List versions ); boolean isOptional(); + + void setOptional( boolean optional ); ArtifactVersion getSelectedVersion() throws OverConstrainedVersionException; 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 0e45e3296c..27c82e7a54 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 @@ -541,4 +541,9 @@ public class DefaultArtifact { return versionRange.isSelectedVersionKnown( this ); } + + public void setOptional( boolean optional ) + { + this.optional = optional; + } } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java b/maven-artifact/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java index 1b6b831b90..d740801dbb 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java @@ -32,6 +32,9 @@ public interface ArtifactFactory Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, String classifier, String scope ); + Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, + String classifier, String scope, boolean optional ); + Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, String classifier, String scope, String inheritedScope ); diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java b/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java index 74f5a740e9..194d7aedfb 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java @@ -49,6 +49,12 @@ public class DefaultArtifactFactory return createArtifact( groupId, artifactId, versionRange, type, classifier, null, null ); } + public Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, + String classifier, String scope, boolean optional ) + { + return createArtifact( groupId, artifactId, versionRange, type, classifier, scope, null, optional ); + } + public Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, String classifier, String scope, String inheritedScope ) { diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index a2ad5223e5..78cf3a30ef 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -249,7 +249,8 @@ public class DefaultMavenProjectBuilder VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() ); Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), versionRange, d.getType(), - d.getClassifier(), d.getScope() ); + d.getClassifier(), d.getScope(), + d.isOptional() ); map.put( d.getManagementKey(), artifact ); } catch ( InvalidVersionSpecificationException e ) 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 eb0f70cf1f..bc3833830a 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 @@ -288,4 +288,9 @@ public class ActiveProjectArtifact { return artifact.isSelectedVersionKnown(); } + + public void setOptional( boolean optional ) + { + artifact.setOptional( optional ); + } }