Search in sources :

Example 21 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project revapi by revapi.

the class ReportAggregateMojo method getRunConfig.

private ProjectVersions getRunConfig(MavenProject project) {
    ProjectVersions ret = new ProjectVersions();
    Plugin revapiPlugin = findRevapi(project);
    if (revapiPlugin == null) {
        return ret;
    }
    Xpp3Dom pluginConfig = (Xpp3Dom) revapiPlugin.getConfiguration();
    String[] oldArtifacts = getArtifacts(pluginConfig, "oldArtifacts");
    String[] newArtifacts = getArtifacts(pluginConfig, "newArtifacts");
    String oldVersion = getValueOfChild(pluginConfig, "oldVersion");
    if (oldVersion == null) {
        oldVersion = System.getProperties().getProperty(Props.oldVersion.NAME, Props.oldVersion.DEFAULT_VALUE);
    }
    String newVersion = getValueOfChild(pluginConfig, "newVersion");
    if (newVersion == null) {
        newVersion = System.getProperties().getProperty(Props.newVersion.NAME, project.getVersion());
    }
    String defaultOldArtifact = Analyzer.getProjectArtifactCoordinates(project, oldVersion);
    String defaultNewArtifact = Analyzer.getProjectArtifactCoordinates(project, newVersion);
    if (oldArtifacts == null || oldArtifacts.length == 0) {
        if (!project.getArtifact().getArtifactHandler().isAddedToClasspath()) {
            return ret;
        }
        oldArtifacts = new String[] { defaultOldArtifact };
    }
    if (newArtifacts == null || newArtifacts.length == 0) {
        if (!project.getArtifact().getArtifactHandler().isAddedToClasspath()) {
            return ret;
        }
        newArtifacts = new String[] { defaultNewArtifact };
    }
    String versionRegexString = getValueOfChild(pluginConfig, "versionFormat");
    Pattern versionRegex = versionRegexString == null ? null : Pattern.compile(versionRegexString);
    DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession);
    session.setDependencySelector(new ScopeDependencySelector("compile", "provided"));
    session.setDependencyTraverser(new ScopeDependencyTraverser("compile", "provided"));
    if (alwaysCheckForReleaseVersion) {
        session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);
    }
    ArtifactResolver resolver = new ArtifactResolver(repositorySystem, session, mavenSession.getCurrentProject().getRemoteProjectRepositories());
    Function<String, Artifact> resolve = gav -> {
        try {
            return Analyzer.resolveConstrained(project, gav, versionRegex, resolver);
        } catch (VersionRangeResolutionException | ArtifactResolutionException e) {
            getLog().warn("Could not resolve artifact '" + gav + "' with message: " + e.getMessage());
            return null;
        }
    };
    ret.oldGavs = Stream.of(oldArtifacts).map(resolve).filter(f -> f != null).toArray(Artifact[]::new);
    ret.newGavs = Stream.of(newArtifacts).map(resolve).filter(f -> f != null).toArray(Artifact[]::new);
    return ret;
}
Also used : Component(org.apache.maven.plugins.annotations.Component) HashMap(java.util.HashMap) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Function(java.util.function.Function) Sink(org.apache.maven.doxia.sink.Sink) MessageFormat(java.text.MessageFormat) Execute(org.apache.maven.plugins.annotations.Execute) Mojo(org.apache.maven.plugins.annotations.Mojo) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) ResourceBundle(java.util.ResourceBundle) MavenProject(org.apache.maven.project.MavenProject) Locale(java.util.Locale) Map(java.util.Map) ArtifactResolver(org.revapi.maven.utils.ArtifactResolver) SITE(org.apache.maven.plugins.annotations.LifecyclePhase.SITE) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) API(org.revapi.API) MavenSession(org.apache.maven.execution.MavenSession) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) MavenReportException(org.apache.maven.reporting.MavenReportException) Artifact(org.eclipse.aether.artifact.Artifact) AnalysisResult(org.revapi.AnalysisResult) Collectors(java.util.stream.Collectors) Revapi(org.revapi.Revapi) File(java.io.File) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) PACKAGE(org.apache.maven.plugins.annotations.LifecyclePhase.PACKAGE) List(java.util.List) Plugin(org.apache.maven.model.Plugin) Stream(java.util.stream.Stream) ScopeDependencyTraverser(org.revapi.maven.utils.ScopeDependencyTraverser) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) ScopeDependencySelector(org.revapi.maven.utils.ScopeDependencySelector) Pattern(java.util.regex.Pattern) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) ArtifactResolver(org.revapi.maven.utils.ArtifactResolver) Artifact(org.eclipse.aether.artifact.Artifact) ScopeDependencyTraverser(org.revapi.maven.utils.ScopeDependencyTraverser) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) Plugin(org.apache.maven.model.Plugin) ScopeDependencySelector(org.revapi.maven.utils.ScopeDependencySelector)

Example 22 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project activemq-artemis by apache.

the class ArtemisAbstractPlugin method resolveArtifact.

protected File resolveArtifact(Artifact artifact) throws MojoExecutionException, DependencyCollectionException {
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(artifact);
    request.setRepositories(remoteRepos);
    ArtifactResult result;
    try {
        result = repositorySystem.resolveArtifact(repoSession, request);
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    return result.getArtifact().getFile();
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 23 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project spring-boot by spring-projects.

the class MavenResolverGrapeEngine method grab.

@Override
public Object grab(Map args, Map... dependencyMaps) {
    List<Exclusion> exclusions = createExclusions(args);
    List<Dependency> dependencies = createDependencies(dependencyMaps, exclusions);
    try {
        List<File> files = resolve(dependencies);
        GroovyClassLoader classLoader = getClassLoader(args);
        for (File file : files) {
            classLoader.addURL(file.toURI().toURL());
        }
    } catch (ArtifactResolutionException | MalformedURLException ex) {
        throw new DependencyResolutionFailedException(ex);
    }
    return null;
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MalformedURLException(java.net.MalformedURLException) Exclusion(org.eclipse.aether.graph.Exclusion) Dependency(org.eclipse.aether.graph.Dependency) File(java.io.File)

Example 24 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project grails-maven by grails.

the class AbstractGrailsMojo method resolveArtifact.

protected File resolveArtifact(String artifactId) throws MojoExecutionException {
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(new DefaultArtifact(artifactId));
    request.setRepositories(remoteRepos);
    getLog().debug("Resolving artifact " + artifactId + " from " + remoteRepos);
    ArtifactResult result;
    File file;
    try {
        result = repoSystem.resolveArtifact(repoSession, request);
        file = result.getArtifact().getFile();
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    getLog().debug("Resolved artifact " + artifactId + " to " + file + " from " + result.getRepository());
    return file;
}
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 25 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project drools by kiegroup.

the class MavenRepository method resolveArtifact.

public Artifact resolveArtifact(String artifactName, boolean logUnresolvedArtifact) {
    Artifact artifact = new DefaultArtifact(artifactName);
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(artifact);
    for (RemoteRepository repo : remoteRepositoriesForRequest) {
        artifactRequest.addRepository(repo);
    }
    RepositorySystemSession session = aether.getSession();
    Object sessionChecks = null;
    boolean isSnapshot = artifactName.endsWith("-SNAPSHOT");
    if (artifactName.endsWith("-SNAPSHOT")) {
        // ensure to always update snapshots
        sessionChecks = session.getData().get(SESSION_CHECKS);
        session.getData().set(SESSION_CHECKS, null);
    }
    try {
        ArtifactResult artifactResult = aether.getSystem().resolveArtifact(session, artifactRequest);
        return artifactResult.getArtifact();
    } catch (ArtifactResolutionException e) {
        if (logUnresolvedArtifact) {
            if (log.isDebugEnabled()) {
                log.debug("Unable to resolve artifact: " + artifactName, e);
            } else {
                log.warn("Unable to resolve artifact: " + artifactName);
            }
        }
        return null;
    } finally {
        if (sessionChecks != null) {
            session.getData().set(SESSION_CHECKS, sessionChecks);
        }
    }
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) 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

ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)52 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)33 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)32 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)27 File (java.io.File)21 Artifact (org.eclipse.aether.artifact.Artifact)21 IOException (java.io.IOException)19 VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)10 FileNotFoundException (java.io.FileNotFoundException)9 MalformedURLException (java.net.MalformedURLException)9 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)9 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)9 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)8 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)8 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)7 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)7 DependencyResolutionException (org.eclipse.aether.resolution.DependencyResolutionException)7 ArrayList (java.util.ArrayList)6 Model (org.apache.maven.model.Model)6 DependencyCollectionException (org.eclipse.aether.collection.DependencyCollectionException)6