Search in sources :

Example 76 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project atlasmap by atlasmap.

the class AbstractAtlasMapMojo method resolveClasspath.

/**
 * Resolves the classpath.
 * @param artifacts artifacts
 * @return resolved
 * @throws MojoFailureException unexpected error
 */
protected List<URL> resolveClasspath(List<String> artifacts) throws MojoFailureException {
    final List<URL> urls = new ArrayList<>();
    try {
        for (String gav : artifacts) {
            Artifact artifact = new DefaultArtifact(gav);
            getLog().debug("Resolving dependencies for artifact: " + artifact);
            CollectRequest collectRequest = new CollectRequest();
            collectRequest.setRoot(new Dependency(artifact, ""));
            collectRequest.setRepositories(getRemoteRepos());
            DependencyRequest dependencyRequest = new DependencyRequest();
            dependencyRequest.setCollectRequest(collectRequest);
            DependencyResult dependencyResult = getSystem().resolveDependencies(getRepoSession(), dependencyRequest);
            PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
            dependencyResult.getRoot().accept(nlg);
            Iterator<DependencyNode> it = nlg.getNodes().iterator();
            while (it.hasNext()) {
                DependencyNode node = it.next();
                if (node.getDependency() != null) {
                    Artifact x = node.getDependency().getArtifact();
                    if (x.getFile() != null) {
                        getLog().debug("Found dependency: " + x + " for artifact: " + artifact);
                        urls.add(x.getFile().toURI().toURL());
                    }
                }
            }
        }
    } catch (IllegalArgumentException e) {
        throw new MojoFailureException(e.getMessage(), e);
    } catch (DependencyResolutionException e) {
        throw new MojoFailureException(e.getMessage(), e);
    } catch (MalformedURLException e) {
        throw new MojoFailureException(e.getMessage(), e);
    }
    return urls;
}
Also used : MalformedURLException(java.net.MalformedURLException) DependencyResult(org.eclipse.aether.resolution.DependencyResult) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) URL(java.net.URL) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 77 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project grails-maven by grails.

the class AbstractGrailsMojo method resolveArtifactIds.

protected Collection<File> resolveArtifactIds(Collection<String> artifactIds) throws MojoExecutionException {
    Collection<ArtifactRequest> requests = new ArrayList<ArtifactRequest>();
    for (String artifactId : artifactIds) {
        ArtifactRequest request = new ArtifactRequest();
        request.setArtifact(new DefaultArtifact(artifactId));
        request.setRepositories(remoteRepos);
        getLog().debug("Resolving artifact " + artifactId + " from " + remoteRepos);
        requests.add(request);
    }
    Collection<File> files = new ArrayList<File>();
    try {
        List<ArtifactResult> result = repoSystem.resolveArtifacts(repoSession, requests);
        for (ArtifactResult artifactResult : result) {
            File file = artifactResult.getArtifact().getFile();
            files.add(file);
            getLog().debug("Resolved artifact " + artifactResult.getArtifact().getArtifactId() + " to " + file + " from " + artifactResult.getRepository());
        }
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    return files;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 78 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project BIMserver by opensourceBIM.

the class MavenPluginLocation method iterateAllVersions.

public Iterator<MavenPluginVersion> iterateAllVersions() {
    Artifact artifact = new DefaultArtifact(groupId, artifactId, null, "[0,)");
    VersionRangeRequest rangeRequest = new VersionRangeRequest();
    rangeRequest.setArtifact(artifact);
    rangeRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList());
    try {
        VersionRangeResult rangeResult = mavenPluginRepository.getSystem().resolveVersionRange(mavenPluginRepository.getSession(), rangeRequest);
        List<Version> versions = rangeResult.getVersions();
        if (!versions.isEmpty()) {
            Iterator<Version> versionIterator = Lists.reverse(versions).iterator();
            return Iterators.transform(versionIterator, new Function<Version, MavenPluginVersion>() {

                @Override
                public MavenPluginVersion apply(Version version) {
                    try {
                        MavenPluginVersion mavenPluginVersion = createMavenVersion(version);
                        return mavenPluginVersion;
                    } catch (ArtifactDescriptorException | ArtifactResolutionException | IOException | XmlPullParserException e) {
                        LOGGER.error("", e);
                    }
                    return null;
                }
            });
        }
    } catch (VersionRangeResolutionException e) {
        LOGGER.error("", e);
    }
    return Collections.emptyIterator();
}
Also used : VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) Version(org.eclipse.aether.version.Version) SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException)

Example 79 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project BIMserver by opensourceBIM.

the class MavenPluginLocation method getLatestVersionString.

public String getLatestVersionString() {
    Artifact lastArt = new DefaultArtifact(groupId, artifactId, "jar", "LATEST");
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(lastArt);
    request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
    try {
        ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
        return resolveArtifact.getArtifact().getVersion();
    } catch (ArtifactResolutionException e1) {
        e1.printStackTrace();
    }
    return null;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 80 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project BIMserver by opensourceBIM.

the class MavenPluginLocation method getVersionJar.

public Path getVersionJar(String version) throws ArtifactResolutionException {
    Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "jar", version.toString());
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(versionArtifact);
    request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
    ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
    return resolveArtifact.getArtifact().getFile().toPath();
}
Also used : ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Aggregations

DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)110 Artifact (org.eclipse.aether.artifact.Artifact)70 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)42 File (java.io.File)39 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)34 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)29 IOException (java.io.IOException)24 Dependency (org.eclipse.aether.graph.Dependency)23 ArrayList (java.util.ArrayList)16 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)13 CollectRequest (org.eclipse.aether.collection.CollectRequest)12 VersionRangeRequest (org.eclipse.aether.resolution.VersionRangeRequest)12 VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)12 VersionRangeResult (org.eclipse.aether.resolution.VersionRangeResult)12 SubArtifact (org.eclipse.aether.util.artifact.SubArtifact)12 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)11 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)10 Version (org.eclipse.aether.version.Version)10 Model (org.apache.maven.model.Model)9 RepositorySystem (org.eclipse.aether.RepositorySystem)9