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

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

Introduction

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

Prototype

public String getScope() 

Source Link

Usage

From source file:org.ebayopensource.turmeric.eclipse.mavenapi.impl.AbstractMavenApi.java

License:Open Source License

/**
 * Resolve an artifact using a particular maven implementation and repository.
 *
 * @param embedder the embedded version of maven to use
 * @param repoSystem the repository to resolve against
 * @param md the artifact metadata to search
 * @return the resolved artifact/*from   www  .j  av  a  2s  .c  om*/
 * @throws MavenEclipseApiException the maven eclipse api exception
 */
public Artifact resolveArtifact(MavenImpl embedder, RepositorySystem repoSystem, ArtifactMetadata md)
        throws MavenEclipseApiException {
    if (embedder == null)
        throw new MavenEclipseApiException();

    try {
        List<ArtifactRepository> repos = _getKnownRepositories(embedder, md.getType());
        if (repos == null || repos.size() < 1) {
            throw new MavenEclipseApiException(Messages.ERROR_NO_REPOSITORIES);
        }

        Artifact artifact = null;

        if (md.getClassifier() == null)
            artifact = repoSystem.createArtifact(md.getGroupId(), md.getArtifactId(), md.getVersion(),
                    md.getScope(), md.getType());
        else
            artifact = repoSystem.createArtifactWithClassifier(md.getGroupId(), md.getArtifactId(),
                    md.getVersion(), md.getType(), md.getClassifier());

        if (artifact == null) {
            throw new MavenEclipseApiException(Messages.ERROR_NULL_ARTIFACT);
        }

        // embedder.resolve(artifact, repos, embedder.getLocalRepository());
        MavenApiUtil.resolveArtifact(repoSystem, artifact, embedder.getLocalRepository(), repos);

        return artifact;
    } catch (Exception e) {
        e.printStackTrace();
        throw new MavenEclipseApiException(e);
    }
}

From source file:org.ebayopensource.turmeric.eclipse.mavenapi.impl.AbstractMavenEclipseApi.java

License:Open Source License

/**
 * Create an artifact given the metadata.  This populates it into the repository.
 *
 * @param metadata the artifact metadata to use.
 * @return the created artifact.//from w  w w .  j a va  2  s  . c  o m
 * @throws MavenEclipseApiException the maven eclipse api exception
 */
public Artifact createArtifact(final ArtifactMetadata metadata) throws MavenEclipseApiException {
    RepositorySystem res = MavenApiHelper.getRepositorySystem();
    if (metadata.getClassifier() == null)
        return res.createArtifact(metadata.getGroupId(), metadata.getArtifactId(), metadata.getVersion(),
                metadata.getScope(), metadata.getType());
    return res.createArtifactWithClassifier(metadata.getGroupId(), metadata.getArtifactId(),
            metadata.getVersion(), metadata.getType(), metadata.getClassifier());
}

From source file:org.ebayopensource.turmeric.eclipse.mavenapi.impl.MavenEclipseUtil.java

License:Open Source License

/**
 * Artifact.//from w  w w .ja  v  a2 s. c om
 *
 * @param metadata the metadata
 * @return the artifact
 * @throws MavenEclipseApiException the maven eclipse api exception
 */
public static Artifact artifact(final ArtifactMetadata metadata) throws MavenEclipseApiException {
    if (metadata == null)
        return null;
    if (isNotBlank(metadata.getScope()))
        return MavenApiHelper.getRepositorySystem().createArtifact(metadata.getGroupId(),
                metadata.getArtifactId(), metadata.getVersion(), metadata.getScope(), metadata.getType());
    return MavenApiHelper.getRepositorySystem().createArtifactWithClassifier(metadata.getGroupId(),
            metadata.getArtifactId(), metadata.getVersion(), metadata.getType(), metadata.getClassifier());
}

From source file:org.ebayopensource.turmeric.eclipse.mavenapi.impl.MavenEclipseUtil.java

License:Open Source License

/**
 * Dependency.//from  w ww.j av a  2s.c  o  m
 *
 * @param metadata the metadata
 * @return the dependency
 */
public static Dependency dependency(final ArtifactMetadata metadata) {
    final Dependency dependency = new Dependency();
    dependency.setGroupId(metadata.getGroupId());
    dependency.setArtifactId(metadata.getArtifactId());
    dependency.setVersion(metadata.getVersion());
    dependency.setClassifier(metadata.getClassifier());
    dependency.setType(metadata.getType());
    if (metadata.getScope() != null
            && ArtifactScopeEnum.DEFAULT_SCOPE.getScope().equals(metadata.getScope()) == false)
        dependency.setScope(metadata.getScope());
    return dependency;
}

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

License:Open Source License

/**
 * Tries to resolve the given {@code ArtifactMetadata}s in the given
 * local/remote repositories and returns the resolved {@code Artifact}s.
 *
 * @param embedder the embedder//from w w w  .j  a v  a2  s. c  o  m
 * @param mdCollection the md collection
 * @param localRepository the local repository
 * @param remoteRepositories the remote repositories
 * @return the list
 * @throws MavenEclipseApiException the maven eclipse api exception
 */
public static List<Artifact> resolveArtifacts(RepositorySystem embedder, List<ArtifactMetadata> mdCollection,
        ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories)
        throws MavenEclipseApiException {
    if (mdCollection == null || mdCollection.isEmpty()) {
        return null;
    }

    List<Artifact> res = new ArrayList<Artifact>(mdCollection.size());
    Artifact artifact = null;
    for (Iterator<ArtifactMetadata> i$ = mdCollection.iterator(); i$.hasNext(); res.add(artifact)) {
        ArtifactMetadata md = i$.next();
        artifact = embedder.createArtifact(md.getGroupId(), md.getArtifactId(), md.getVersion(), md.getScope(),
                md.getType() != null ? md.getType() : "jar");

        resolveArtifact(embedder, artifact, localRepository, remoteRepositories);
    }

    return res;
}

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 {/*  www . j  ava  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);
    }
}