Skip to content

Commit

Permalink
[SHRINKRES-27] dependencies info for MavenResolvedArtifact's
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatloka authored and ALRubinger committed Dec 4, 2012
1 parent 9d8a08d commit 5c43166
Show file tree
Hide file tree
Showing 10 changed files with 431 additions and 211 deletions.
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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,14 @@
package org.jboss.shrinkwrap.resolver.api.maven;

import org.jboss.shrinkwrap.resolver.api.ResolvedArtifact;
import org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate;

/**
* Encapsulation of a 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 MavenResolvedArtifact extends ResolvedArtifact<MavenResolvedArtifact> {

/**
* 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();
public interface MavenResolvedArtifact extends MavenArtifactInfo, ResolvedArtifact<MavenResolvedArtifact> {
/* empty */
}
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) + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,15 @@ public <RETURNTYPE> RETURNTYPE[] as(Class<RETURNTYPE> returnTypeClass) throws Il
UnsupportedOperationException {
Validate.notNull(returnTypeClass, "Return type class must not be null");

FormatProcessor<? super MavenResolvedArtifact, RETURNTYPE> processor = FormatProcessors.find(
final FormatProcessor<? super MavenResolvedArtifact, RETURNTYPE> processor = FormatProcessors.find(
MavenResolvedArtifact.class, returnTypeClass);

@SuppressWarnings("unchecked")
final RETURNTYPE[] array = (RETURNTYPE[]) Array.newInstance(returnTypeClass, artifacts.size());

int i = 0;
for (final MavenResolvedArtifact artifact : artifacts) {

array[i] = processor.process(artifact, returnTypeClass);
i++;
array[i++] = processor.process(artifact, returnTypeClass);
}
return array;
}
Expand Down

0 comments on commit 5c43166

Please sign in to comment.