Example usage for org.apache.maven.repository.metadata ArtifactMetadata ArtifactMetadata

List of usage examples for org.apache.maven.repository.metadata ArtifactMetadata ArtifactMetadata

Introduction

In this page you can find the example usage for org.apache.maven.repository.metadata ArtifactMetadata ArtifactMetadata.

Prototype

public ArtifactMetadata(String groupId, String name, String version, String type,
            ArtifactScopeEnum artifactScope) 

Source Link

Usage

From source file:org.ebayopensource.turmeric.eclipse.mavenapi.internal.util.MavenApiUtil.java

License:Open Source License

private static MetadataTreeNode resolveMetadataTree(RepositorySystem embedder, ArtifactMetadata query,
        MetadataTreeNode parent, ArtifactRepository localRepository, List remoteRepositories)
        throws MavenEclipseApiException {
    try {//from www.j  a  v  a  2  s. c  o m
        Artifact pomArtifact = embedder.createArtifact(query.getGroupId(), query.getArtifactId(),
                query.getVersion(), query.getScope(), query.getType() != null ? query.getType() : "jar");
        //Artifact art = MavenApiHelper.getMavenEmbedder().resolve(groupId, artifactId, version, type, classifier, remoteRepositories, monitor);

        ArtifactResolutionResult result = resolveArtifact(embedder, pomArtifact, localRepository,
                remoteRepositories, false);

        if (pomArtifact.isResolved()) {
            MetadataTreeNode node = new MetadataTreeNode(query, parent, true, query.getScopeAsEnum());
            Set<Artifact> artifacts = result.getArtifacts();
            if (artifacts.size() > 1) {
                List<Artifact> dependencies = new ArrayList<Artifact>(artifacts);
                // remove the first one, which is the source artifact itself
                dependencies.remove(0);

                int nKids = dependencies.size();
                node.setNChildren(nKids);
                int kidNo = 0;
                MetadataTreeNode kidNode;
                for (Artifact artifact : dependencies) {
                    ArtifactMetadata amd = new ArtifactMetadata(artifact.getGroupId(), artifact.getArtifactId(),
                            artifact.getVersion(), artifact.getType(),
                            ArtifactScopeEnum.valueOf(artifact.getScope()));
                    // 20100514#emac: no need to resolve dependencies
                    // recursively
                    // kidNode = resolveMetadataTree(embedder, amd, node,
                    // localRepository, remoteRepositories);
                    kidNode = new MetadataTreeNode(amd, node, artifact.isResolved(), amd.getScopeAsEnum());
                    node.addChild(kidNo++, kidNode);
                }
            }

            return node;
        }

        return new MetadataTreeNode(pomArtifact, parent, false, query.getArtifactScope());
    } catch (Exception anyEx) {
        throw new MavenEclipseApiException(anyEx);
    }
}