Example usage for org.apache.maven RepositoryUtils toArtifact

List of usage examples for org.apache.maven RepositoryUtils toArtifact

Introduction

In this page you can find the example usage for org.apache.maven RepositoryUtils toArtifact.

Prototype

public static Artifact toArtifact(org.apache.maven.artifact.Artifact artifact) 

Source Link

Usage

From source file:com.coderplus.apacheutils.translators.resolvers.DefaultArtifactsResolver.java

License:Apache License

public Set<Artifact> resolve(Set<Artifact> artifacts, org.eclipse.aether.RepositorySystem repoSystem)
        throws MojoExecutionException {

    Set<Artifact> resolvedArtifacts = new HashSet<Artifact>();
    for (Artifact artifact : artifacts) {
        try {//  w ww  . j a  v  a 2 s  . c  om
            ArtifactRequest request = new ArtifactRequest(RepositoryUtils.toArtifact(artifact),
                    RepositoryUtils.toRepos(remoteRepositories), "");
            ArtifactResult result = repoSystem
                    .resolveArtifact(LegacyLocalRepositoryManager.overlay(local, null, null), request);
            if (result.getArtifact() != null) {
                resolvedArtifacts.add(RepositoryUtils.toArtifact(result.getArtifact()));
            } else {
                throw new Exception("No valid artifact resolved");
            }
        } catch (Exception ex) {
            // an error occurred during resolution, log it an continue
            if (stopOnFailure) {
                throw new MojoExecutionException("error resolving: " + artifact.getId(), ex);
            }
        }

    }
    return resolvedArtifacts;
}

From source file:com.peergreen.community.maven.ReleaseCommunityMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    // get direct dependencies of this pom
    List<Dependency> dependencies = project.getDependencies();
    if (dependencies.size() != 1) {
        // Invalid dependencies
        throw new MojoExecutionException("We should have only one dependency. Found '" + dependencies + "'.");
    }/*from   w w  w .  j a v  a 2 s.c om*/

    // only one dependency, get the first one
    Dependency dependency = dependencies.get(0);

    // Collect data of this dependency
    String groupId = dependency.getGroupId();
    String artifactId = dependency.getArtifactId();
    String classifier = dependency.getClassifier();
    String type = dependency.getType();
    String version = dependency.getVersion();

    // create artifact and ask to resolve the artifact in order to get the
    // local file
    final Artifact artifact = new DefaultArtifact(groupId, artifactId, classifier, type, version);
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(artifact);
    request.setRepositories(remoteRepos);
    ArtifactResult result;
    // resolve artifact
    try {
        result = repositorySystem.resolveArtifact(repoSession, request);
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    getLog().info("Resolved artifact " + artifact + " to " + result.getArtifact().getFile() + " from "
            + result.getRepository());

    // well try to read the artifact model but the result is limited to sub
    // parameters :-/
    // ArtifactDescriptorRequest artifactDescriptorRequest = new
    // ArtifactDescriptorRequest();
    // artifactDescriptorRequest.setArtifact(result.getArtifact());
    // ArtifactDescriptorResult artifactDescriptorResult;
    // try {
    // artifactDescriptorResult =
    // repositorySystem.readArtifactDescriptor(repoSession,
    // artifactDescriptorRequest);
    // } catch (ArtifactDescriptorException e) {
    // throw new MojoExecutionException(e.getMessage(), e);
    // }
    // DefaultArtifactDescriptorReader.loadPom

    // Now, we needs to deploy this artifact with another name in the public
    // community repository
    DeployRequest deployRequest = new DeployRequest();

    if (communityArtifactId == null) {
        communityArtifactId = artifactId;
    }

    Artifact deployArtifact = new DefaultArtifact(communityGroupId, communityArtifactId, type, version);
    deployArtifact = deployArtifact.setVersion(communityVersion).setFile(result.getArtifact().getFile());

    // Generate the pom file
    Artifact pomArtifact = generatePom(deployArtifact);

    // Add artifact and the associated pom
    deployRequest.addArtifact(deployArtifact);
    deployRequest.addArtifact(pomArtifact);

    // Build the Peergreen community repository
    RemoteRepository communityRepository = new RemoteRepository("peergreen.community", "default",
            nexusPublicInstance);
    communityRepository
            .setAuthentication(repoSession.getAuthenticationSelector().getAuthentication(communityRepository));
    communityRepository.setProxy(repoSession.getProxySelector().getProxy(communityRepository));
    deployRequest.setRepository(communityRepository);
    DeployResult deployResult;
    try {
        deployResult = repositorySystem.deploy(repoSession, deployRequest);
    } catch (DeploymentException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }

    // Change the project artifact to be the deployed artifact (and then
    // install it in the local repository too)
    project.setArtifact(RepositoryUtils.toArtifact(deployArtifact));
}

From source file:com.photon.maven.plugins.android.phase04processclasses.ProguardMojo.java

License:Apache License

private void skipArtifact(String groupId, String artifactId, boolean shiftToLibraries) {
    artifactBlacklist.add(RepositoryUtils.toArtifact(new DefaultArtifact(groupId, artifactId, null, null)));
    if (shiftToLibraries) {
        artifactsToShift.add(RepositoryUtils.toArtifact(new DefaultArtifact(groupId, artifactId, null, null)));
    }//  w  w  w .jav  a  2s  . c  om
}

From source file:io.takari.maven.workspace.GenerationsWorkspaceReader.java

License:Apache License

private Artifact findMatchingArtifact(MavenProject project, Artifact requestedArtifact) {
    String versionlessId = ArtifactIdUtils.toVersionlessId(requestedArtifact);
    Artifact mainArtifact = RepositoryUtils.toArtifact(project.getArtifact());
    if (versionlessId.equals(ArtifactIdUtils.toVersionlessId(mainArtifact))) {
        return mainArtifact;
    }// w  ww .j av a  2  s.  c o  m
    for (Artifact attachedArtifact : RepositoryUtils.toArtifacts(project.getAttachedArtifacts())) {
        if (attachedArtifactComparison(requestedArtifact, attachedArtifact)) {
            return attachedArtifact;
        }
    }
    return null;
}

From source file:net.sf.taverna.t2.maven.plugins.MavenOsgiUtils.java

License:Apache License

public Set<BundleArtifact> getBundleArtifacts(List<DependencyNode> nodes) {
    Set<BundleArtifact> bundleArtifacts = new HashSet<BundleArtifact>();
    for (DependencyNode node : nodes) {
        Artifact artifact = RepositoryUtils.toArtifact(node.getDependency().getArtifact());
        String symbolicName = getManifestAttribute(artifact, Constants.BUNDLE_SYMBOLICNAME);
        if (symbolicName != null) {
            String version = getManifestAttribute(artifact, Constants.BUNDLE_VERSION);
            bundleArtifacts.add(new BundleArtifact(artifact, symbolicName, version));
            bundleArtifacts.addAll(getBundleArtifacts(node.getChildren()));
        } else {/*w  w  w .j  a  va2  s .c om*/
            log.warn("Not an OSGi bundle : " + artifact.getId());
        }
    }
    return bundleArtifacts;
}

From source file:net.sf.taverna.t2.maven.plugins.MavenOsgiUtils.java

License:Apache License

public Set<Artifact> getAllArtifacts(List<DependencyNode> nodes) {
    Set<Artifact> artifacts = new HashSet<Artifact>();
    for (DependencyNode node : nodes) {
        Artifact artifact = RepositoryUtils.toArtifact(node.getDependency().getArtifact());
        if (isBundle(artifact)) {
            artifacts.add(artifact);//from   w w  w .ja va 2 s  .c  o m
            artifacts.addAll(getAllArtifacts(node.getChildren()));
        }
    }
    return artifacts;
}

From source file:net.sf.taverna.t2.maven.plugins.MavenOsgiUtils.java

License:Apache License

public Set<Artifact> getArtifacts(List<DependencyNode> nodes) {
    Set<Artifact> artifacts = new HashSet<Artifact>();
    for (DependencyNode node : nodes) {
        Artifact artifact = RepositoryUtils.toArtifact(node.getDependency().getArtifact());
        if (isBundle(artifact)) {
            artifacts.add(artifact);//from  w  ww . ja v  a 2s .c  o m
        }
    }
    return artifacts;
}

From source file:org.apache.commons.weaver.maven.AbstractCWMojo.java

License:Apache License

private List<String> createClasspath() throws DependencyResolutionException {
    final CollectRequest collect = new CollectRequest();
    collect.setRootArtifact(RepositoryUtils.toArtifact(project.getArtifact()));
    collect.setRequestContext("project");
    collect.setRepositories(project.getRemoteProjectRepositories());

    for (final Dependency dependency : project.getDependencies()) {
        // guard against case where best-effort resolution for invalid models is requested:
        if (StringUtils.isAnyBlank(dependency.getGroupId(), dependency.getArtifactId(),
                dependency.getVersion())) {
            continue;
        }//from  w  w w.  j a v a2  s.  co  m
        collect.addDependency(
                RepositoryUtils.toDependency(dependency, repositorySystemSession.getArtifactTypeRegistry()));
    }
    final DependencyResult dependencyResult = repositorySystem.resolveDependencies(repositorySystemSession,
            new DependencyRequest().setFilter(new ScopeDependencyFilter(getExcludeScopes()))
                    .setCollectRequest(collect));

    return dependencyResult.getArtifactResults().stream()
            .map(ar -> ar.getArtifact().getFile().getAbsolutePath()).distinct().collect(Collectors.toList());
}

From source file:org.apache.karaf.tooling.features.Dependency30Helper.java

License:Apache License

@Override
public void getDependencies(MavenProject project, boolean useTransitiveDependencies)
        throws MojoExecutionException {
    DependencyNode rootNode = getDependencyTree(RepositoryUtils.toArtifact(project.getArtifact()));
    Scanner scanner = new Scanner();
    scanner.scan(rootNode, useTransitiveDependencies);
    localDependencies = scanner.localDependencies;
    treeListing = scanner.getLog();/* w  ww  .j a v a2s . co  m*/
}

From source file:org.apache.karaf.tooling.features.Dependency30Helper.java

License:Apache License

@Override
public String artifactToMvn(org.apache.maven.artifact.Artifact artifact) {
    return this.artifactToMvn(RepositoryUtils.toArtifact(artifact));
}