Search in sources :

Example 6 with ArtifactResolutionResult

use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project intellij-plugins by JetBrains.

the class RepositoryReplicatorMojo method resolveAndCopyArtifact.

private boolean resolveAndCopyArtifact(Artifact artifact) throws MojoExecutionException, IOException {
    if (copiedArtifacts.contains(artifact)) {
        return true;
    }
    copiedArtifacts.add(artifact);
    File artifactFile = artifact.getFile();
    if (artifactFile == null && !artifact.isResolved()) {
        ArtifactResolutionRequest request = new ArtifactResolutionRequest();
        request.setArtifact(artifact);
        request.setLocalRepository(session.getLocalRepository());
        request.setRemoteRepositories(remoteRepositories);
        ArtifactResolutionResult result = repositorySystem.resolve(request);
        artifactFile = artifact.getFile();
        if (!result.isSuccess() && artifactFile == null) {
            if (getLog().isDebugEnabled()) {
                for (Exception e : result.getExceptions()) {
                    getLog().error(e);
                }
            }
            throw new MojoExecutionException("Failed to resolve artifact " + artifact);
        }
    }
    return copyArtifact(artifactFile, artifactFile.getPath().substring(localRepositoryBasedirLength));
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) File(java.io.File) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 7 with ArtifactResolutionResult

use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project kotlin by JetBrains.

the class KotlinCompileMojoBase method getCompilerPluginClassPaths.

private List<String> getCompilerPluginClassPaths() {
    ArrayList<String> result = new ArrayList<String>();
    List<File> files = new ArrayList<File>();
    for (Dependency dependency : mojoExecution.getPlugin().getDependencies()) {
        Artifact artifact = system.createDependencyArtifact(dependency);
        ArtifactResolutionResult resolved = system.resolve(new ArtifactResolutionRequest().setArtifact(artifact));
        for (Artifact resolvedArtifact : resolved.getArtifacts()) {
            File file = resolvedArtifact.getFile();
            if (file != null && file.exists()) {
                files.add(file);
            }
        }
    }
    for (File file : files) {
        result.add(file.getAbsolutePath());
    }
    return result;
}
Also used : ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) Dependency(org.apache.maven.model.Dependency) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 8 with ArtifactResolutionResult

use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project cxf by apache.

the class AbstractCodegenMoho method resolveArbitraryWsdl.

private Artifact resolveArbitraryWsdl(Artifact artifact) {
    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifact);
    request.setResolveRoot(true).setResolveTransitively(false);
    request.setServers(mavenSession.getRequest().getServers());
    request.setMirrors(mavenSession.getRequest().getMirrors());
    request.setProxies(mavenSession.getRequest().getProxies());
    request.setLocalRepository(mavenSession.getLocalRepository());
    request.setRemoteRepositories(mavenSession.getRequest().getRemoteRepositories());
    ArtifactResolutionResult result = repositorySystem.resolve(request);
    Artifact resolvedArtifact = result.getOriginatingArtifact();
    if (resolvedArtifact == null && !CollectionUtils.isEmpty(result.getArtifacts())) {
        resolvedArtifact = result.getArtifacts().iterator().next();
    }
    return resolvedArtifact;
}
Also used : ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) Artifact(org.apache.maven.artifact.Artifact)

Example 9 with ArtifactResolutionResult

use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project xwiki-platform by xwiki.

the class PackageMojo method resolveArtifact.

private void resolveArtifact(Artifact artifact) throws MojoExecutionException {
    ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(artifact).setRemoteRepositories(this.remoteRepositories).setLocalRepository(this.localRepository);
    ArtifactResolutionResult resolutionResult = this.repositorySystem.resolve(request);
    if (resolutionResult.hasExceptions()) {
        throw new MojoExecutionException(String.format("Failed to resolve artifact [%s]", artifact, resolutionResult.getExceptions().get(0)));
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult)

Example 10 with ArtifactResolutionResult

use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project xwiki-platform by xwiki.

the class PackageMojo method resolveTransitively.

private Set<Artifact> resolveTransitively(Set<Artifact> artifacts) throws MojoExecutionException {
    AndArtifactFilter filter = new AndArtifactFilter(Arrays.asList(new ScopeArtifactFilter("runtime"), // for JSX. See https://jira.xwiki.org/browse/XWIKI-6151 for more details.
    new ExcludesArtifactFilter(Arrays.asList("org.apache.xmlgraphic:batik-js", "commons-logging:commons-logging", "commons-logging:commons-logging-api", "log4j:log4j"))));
    ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(this.project.getArtifact()).setArtifactDependencies(artifacts).setCollectionFilter(filter).setRemoteRepositories(this.remoteRepositories).setLocalRepository(this.localRepository).setManagedVersionMap(getManagedVersionMap()).setResolveRoot(false);
    ArtifactResolutionResult resolutionResult = this.repositorySystem.resolve(request);
    if (resolutionResult.hasExceptions()) {
        throw new MojoExecutionException(String.format("Failed to resolve artifacts [%s]", artifacts, resolutionResult.getExceptions().get(0)));
    }
    return resolutionResult.getArtifacts();
}
Also used : ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter)

Aggregations

ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)26 ArtifactResolutionRequest (org.apache.maven.artifact.resolver.ArtifactResolutionRequest)20 Artifact (org.apache.maven.artifact.Artifact)19 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)9 MavenProject (org.apache.maven.project.MavenProject)9 ArrayList (java.util.ArrayList)8 File (java.io.File)6 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)5 LinkedHashSet (java.util.LinkedHashSet)4 Dependency (org.apache.maven.model.Dependency)4 MojoFailureException (org.apache.maven.plugin.MojoFailureException)4 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)3 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)3 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 MavenExecutionException (org.apache.maven.MavenExecutionException)2 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)2 ArtifactResolver (org.apache.maven.artifact.resolver.ArtifactResolver)2 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)2