-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SHRINKRES-27] dependencies info for MavenResolvedArtifact's
- Loading branch information
1 parent
9d8a08d
commit 5c43166
Showing
10 changed files
with
431 additions
and
211 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/MavenArtifactInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.jboss.shrinkwrap.resolver.api.maven; | ||
|
||
import org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate; | ||
|
||
/** | ||
* Resolved Maven-based artifact's metadata | ||
* | ||
* @author <a href="mailto:alr@jboss.org">Andrew Lee Rubinger</a> | ||
* @author <a href="mailto:kpiwko@redhat.com">Karel Piwko</a> | ||
* @author <a href="mailto:mmatloka@gmail.com">Michal Matloka</a> | ||
*/ | ||
public interface MavenArtifactInfo { | ||
|
||
/** | ||
* Returns the defined coordinate (i.e. address) of this resolved artifact. | ||
* | ||
* @return | ||
*/ | ||
MavenCoordinate getCoordinate(); | ||
|
||
/** | ||
* Returns the resolved "version" portion of this artifact's coordinates; SNAPSHOTs may declare a version field (as | ||
* represented by {@link VersionedMavenCoordinate#getVersion()}, which must resolve to a versioned snapshot version | ||
* number. That resolved version number is reflected by this field. In the case of true versions (ie. | ||
* non-SNAPSHOTs), this call will be equal to {@link VersionedMavenCoordinate#getVersion()}. | ||
* | ||
* @return | ||
*/ | ||
String getResolvedVersion(); | ||
|
||
/** | ||
* Returns whether or not this artifact is using a SNAPSHOT version. | ||
* | ||
* @return | ||
*/ | ||
boolean isSnapshotVersion(); | ||
|
||
/** | ||
* Returns the file extension of this artifact, ie. ("jar") | ||
* | ||
* @return The file extension, which is never null | ||
*/ | ||
String getExtension(); | ||
|
||
/** | ||
* Returns artifacts dependencies. | ||
* | ||
* @return | ||
*/ | ||
MavenArtifactInfo[] getDependencies(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/MavenArtifactInfoImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package org.jboss.shrinkwrap.resolver.impl.maven; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.jboss.shrinkwrap.resolver.api.maven.MavenArtifactInfo; | ||
import org.jboss.shrinkwrap.resolver.api.maven.PackagingType; | ||
import org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate; | ||
import org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinates; | ||
import org.sonatype.aether.artifact.Artifact; | ||
import org.sonatype.aether.graph.DependencyNode; | ||
|
||
/** | ||
* Immutable implementation of {@link MavenArtifactInfo}. | ||
* | ||
* @author <a href="mailto:mmatloka@gmail.com">Michal Matloka</a> | ||
*/ | ||
public class MavenArtifactInfoImpl implements MavenArtifactInfo { | ||
|
||
protected final MavenCoordinate mavenCoordinate; | ||
protected final String resolvedVersion; | ||
protected final boolean snapshotVersion; | ||
protected final String extension; | ||
|
||
protected final MavenArtifactInfo[] dependencies; | ||
|
||
protected MavenArtifactInfoImpl(final MavenCoordinate mavenCoordinate, final String resolvedVersion, | ||
final boolean snapshotVersion, final String extension, final MavenArtifactInfo[] dependencies) { | ||
this.mavenCoordinate = mavenCoordinate; | ||
this.resolvedVersion = resolvedVersion; | ||
this.snapshotVersion = snapshotVersion; | ||
this.extension = extension; | ||
this.dependencies = dependencies.clone(); | ||
} | ||
|
||
protected MavenArtifactInfoImpl(final Artifact artifact, final List<DependencyNode> children) { | ||
this.mavenCoordinate = MavenCoordinates.createCoordinate(artifact.getGroupId(), artifact.getArtifactId(), | ||
artifact.getBaseVersion(), PackagingType.of(artifact.getExtension()), | ||
artifact.getClassifier()); | ||
this.resolvedVersion = artifact.getVersion(); | ||
this.snapshotVersion = artifact.isSnapshot(); | ||
this.extension = artifact.getExtension(); | ||
this.dependencies = parseDependencies(children); | ||
} | ||
|
||
/** | ||
* Creates MavenArtifactInfo based on DependencyNode. | ||
* | ||
* @param dependencyNode | ||
* dependencyNode | ||
* @return | ||
*/ | ||
static MavenArtifactInfo fromDependencyNode(final DependencyNode dependencyNode) { | ||
final Artifact artifact = dependencyNode.getDependency().getArtifact(); | ||
final List<DependencyNode> children = dependencyNode.getChildren(); | ||
return new MavenArtifactInfoImpl(artifact, children); | ||
} | ||
|
||
/** | ||
* Produces MavenArtifactInfo array from List of DependencyNode's. | ||
* | ||
* @param children | ||
* @return | ||
*/ | ||
protected MavenArtifactInfo[] parseDependencies(final List<DependencyNode> children) { | ||
final MavenArtifactInfo[] dependecies = new MavenArtifactInfo[children.size()]; | ||
int i = 0; | ||
for (final DependencyNode child : children) { | ||
dependecies[i++] = MavenArtifactInfoImpl.fromDependencyNode(child); | ||
} | ||
return dependecies; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifactImpl#getCoordinate() | ||
*/ | ||
@Override | ||
public MavenCoordinate getCoordinate() { | ||
return mavenCoordinate; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact#getResolvedVersion() | ||
*/ | ||
@Override | ||
public String getResolvedVersion() { | ||
return resolvedVersion; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact#isSnapshotVersion() | ||
*/ | ||
@Override | ||
public boolean isSnapshotVersion() { | ||
return snapshotVersion; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact#getExtension() | ||
*/ | ||
@Override | ||
public String getExtension() { | ||
return extension; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact#getDependencies() | ||
*/ | ||
@Override | ||
public MavenArtifactInfo[] getDependencies() { | ||
return dependencies; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "MavenArtifactInfoImpl [mavenCoordinate=" + mavenCoordinate + ", resolvedVersion=" + resolvedVersion | ||
+ ", snapshotVersion=" + snapshotVersion + ", extension=" + extension + ", dependencies=" | ||
+ Arrays.toString(dependencies) + "]"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.