Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHRINKRES-181 MavenArtifactInfo is missing <optional> info #73

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ public interface MavenArtifactInfo {
* @return the scope information of this artifact
*/
ScopeType getScope();

/**
* @return return true if artifact is optional.
*/
boolean isOptional();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,24 @@ public class MavenArtifactInfoImpl implements MavenArtifactInfo {
protected final boolean snapshotVersion;
protected final String extension;
protected final ScopeType scopeType;
protected final boolean optional;

protected final MavenArtifactInfo[] dependencies;

protected MavenArtifactInfoImpl(final MavenCoordinate mavenCoordinate, final String resolvedVersion,
final boolean snapshotVersion, final String extension, final ScopeType scopeType,
final MavenArtifactInfo[] dependencies) {
final MavenArtifactInfo[] dependencies, final boolean optional) {
this.mavenCoordinate = mavenCoordinate;
this.resolvedVersion = resolvedVersion;
this.snapshotVersion = snapshotVersion;
this.extension = extension;
this.scopeType = scopeType;
this.dependencies = dependencies.clone();
this.optional = optional;
}

protected MavenArtifactInfoImpl(final Artifact artifact, final ScopeType scopeType,
final List<DependencyNode> children) {
final List<DependencyNode> children, boolean optional) {

final PackagingType packaging = PackagingType.of(artifact.getProperty(ArtifactProperties.TYPE, artifact.getExtension()));
final String classifier = artifact.getClassifier().length() == 0 ? packaging.getClassifier() : artifact.getClassifier();
Expand All @@ -54,6 +56,7 @@ protected MavenArtifactInfoImpl(final Artifact artifact, final ScopeType scopeTy
this.extension = artifact.getExtension();
this.dependencies = parseDependencies(children);
this.scopeType = scopeType;
this.optional = optional;
}

/**
Expand All @@ -76,8 +79,8 @@ static MavenArtifactInfo fromDependencyNode(final DependencyNode dependencyNode)
log.log(Level.WARNING, "Invalid scope {0} of retrieved dependency {1} will be replaced by <scope>runtime</scope>",
new Object[] { dependencyNode.getDependency().getScope(), dependencyNode.getDependency().getArtifact() });
}

return new MavenArtifactInfoImpl(artifact, scopeType, children);
final boolean optional = dependencyNode.getDependency().isOptional();
return new MavenArtifactInfoImpl(artifact, scopeType, children, optional);
}

/**
Expand Down Expand Up @@ -150,6 +153,11 @@ public ScopeType getScope() {
return scopeType;
}

@Override
public boolean isOptional() {
return optional;
}

@Override
public String toString() {
return "MavenArtifactInfoImpl [mavenCoordinate=" + mavenCoordinate + ", resolvedVersion=" + resolvedVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public class MavenResolvedArtifactImpl extends MavenArtifactInfoImpl implements

private MavenResolvedArtifactImpl(MavenCoordinate mavenCoordinate, String resolvedVersion, boolean snapshotVersion,
String extension, File file, ScopeType scopeType, MavenArtifactInfo[] dependencies) {
super(mavenCoordinate, resolvedVersion, snapshotVersion, extension, scopeType, dependencies);
super(mavenCoordinate, resolvedVersion, snapshotVersion, extension, scopeType, dependencies, false);
this.file = file;
}

private MavenResolvedArtifactImpl(final Artifact artifact, final ScopeType scopeType,
final List<DependencyNode> children) {
super(artifact, scopeType, children);
final List<DependencyNode> children, boolean optional) {
super(artifact, scopeType, children, optional);
this.file = artifactToFile(artifact);
}

Expand All @@ -87,7 +87,8 @@ static MavenResolvedArtifact fromArtifactResult(final ArtifactResult artifactRes
}

final List<DependencyNode> children = root.getChildren();
return new MavenResolvedArtifactImpl(artifact, scopeType, children);
final boolean optional = root.getDependency().isOptional();
return new MavenResolvedArtifactImpl(artifact, scopeType, children, optional);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void asMavenResolvedArtifact() {
assertEquals("1.0.0", resolvedArtifactInfos[0].getResolvedVersion());
assertEquals(false, resolvedArtifactInfos[0].isSnapshotVersion());
assertEquals("jar", resolvedArtifactInfos[0].getExtension());
assertEquals(false, resolvedArtifactInfos[0].isOptional());
assertEquals(originalCoordinateA, resolvedArtifactInfos[0].getCoordinate());

new ValidationUtil("test-deps-b-1.0.0.jar").validate(resolvedArtifactInfos[1].as(File.class));
Expand All @@ -75,6 +76,7 @@ public void asMavenResolvedArtifact() {
assertEquals("1.0.0", resolvedArtifactInfos[1].getResolvedVersion());
assertEquals(false, resolvedArtifactInfos[1].isSnapshotVersion());
assertEquals("jar", resolvedArtifactInfos[1].getExtension());
assertEquals(false, resolvedArtifactInfos[1].isOptional());
assertEquals(originalCoordinateB, resolvedArtifactInfos[1].getCoordinate());
}

Expand All @@ -98,6 +100,7 @@ public void asSingleResolvedArtifactInfo() {
assertEquals("1.0.0", resolvedArtifact.getResolvedVersion());
assertEquals(false, resolvedArtifact.isSnapshotVersion());
assertEquals("jar", resolvedArtifact.getExtension());
assertEquals(false, resolvedArtifact.isOptional());
assertEquals(originalCoordinate, resolvedArtifact.getCoordinate());
}

Expand Down Expand Up @@ -154,13 +157,15 @@ public void resolvedArtifactInfoDependecies() {
assertEquals("1.0.0", resolvedArtifact.getResolvedVersion());
assertEquals(false, resolvedArtifact.isSnapshotVersion());
assertEquals("jar", resolvedArtifact.getExtension());
assertEquals(false, resolvedArtifact.isOptional());
assertEquals(originalCoordinate, resolvedArtifact.getCoordinate());

final MavenArtifactInfo child1 = resolvedArtifact.getDependencies()[0];
assertEquals("jar", child1.getExtension());
assertEquals("1.0.0", child1.getResolvedVersion());
assertEquals(false, child1.isSnapshotVersion());
assertEquals("jar", child1.getExtension());
assertEquals(false, child1.isOptional());
assertEquals(child1Coordinate, child1.getCoordinate());
assertEquals(ScopeType.COMPILE, child1.getScope());

Expand All @@ -169,6 +174,7 @@ public void resolvedArtifactInfoDependecies() {
assertEquals("1.0.0", child2.getResolvedVersion());
assertEquals(false, child2.isSnapshotVersion());
assertEquals("jar", child2.getExtension());
assertEquals(false, child2.isOptional());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to verify that true can be returned from isOptional under some circumstances? ;-)

assertEquals(child2Coordinate, child2.getCoordinate());
assertEquals(ScopeType.RUNTIME, child2.getScope());
}
Expand Down