Search in sources :

Example 51 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project mule by mulesoft.

the class AetherClassPathClassifier method getArtifactExportedClasses.

/**
 * Resolves the exported plugin classes from the given {@link Artifact}
 *
 * @param exporterArtifact {@link Artifact} used to resolve the exported classes
 * @param context {@link ClassPathClassifierContext} with settings for the classification process
 * @param rootArtifactRemoteRepositories remote repositories defined by the rootArtifact
 * @return {@link List} of {@link Class} that the given {@link Artifact} exports
 */
private List<Class> getArtifactExportedClasses(Artifact exporterArtifact, ClassPathClassifierContext context, List<RemoteRepository> rootArtifactRemoteRepositories) {
    final AtomicReference<URL> artifactUrl = new AtomicReference<>();
    try {
        artifactUrl.set(dependencyResolver.resolveArtifact(exporterArtifact, rootArtifactRemoteRepositories).getArtifact().getFile().toURI().toURL());
    } catch (MalformedURLException | ArtifactResolutionException e) {
        throw new IllegalStateException("Unable to resolve artifact URL", e);
    }
    Artifact rootArtifact = context.getRootArtifact();
    return context.getExportPluginClasses().stream().filter(clazz -> {
        boolean isFromCurrentArtifact = clazz.getProtectionDomain().getCodeSource().getLocation().equals(artifactUrl.get());
        if (isFromCurrentArtifact && exporterArtifact != rootArtifact) {
            logger.warn("Exported class '{}' from plugin '{}' is being used from another artifact, {}", clazz.getSimpleName(), exporterArtifact, rootArtifact);
        }
        return isFromCurrentArtifact;
    }).collect(toList());
}
Also used : PLUGIN(org.mule.test.runner.api.ArtifactClassificationType.PLUGIN) ListIterator(java.util.ListIterator) URL(java.net.URL) Optional.of(java.util.Optional.of) TEST(org.eclipse.aether.util.artifact.JavaScopes.TEST) LoggerFactory(org.slf4j.LoggerFactory) DependencyFilterUtils.orFilter(org.eclipse.aether.util.filter.DependencyFilterUtils.orFilter) FileUtils.toFile(org.apache.commons.io.FileUtils.toFile) APPLICATION(org.mule.test.runner.api.ArtifactClassificationType.APPLICATION) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) Collections.singleton(java.util.Collections.singleton) DependencyFilterUtils.andFilter(org.eclipse.aether.util.filter.DependencyFilterUtils.andFilter) Map(java.util.Map) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Collectors.toSet(java.util.stream.Collectors.toSet) ArtifactIdUtils.toId(org.eclipse.aether.util.artifact.ArtifactIdUtils.toId) PROVIDED(org.eclipse.aether.util.artifact.JavaScopes.PROVIDED) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) Artifact(org.eclipse.aether.artifact.Artifact) Preconditions.checkNotNull(org.mule.runtime.api.util.Preconditions.checkNotNull) PatternInclusionsDependencyFilter(org.mule.test.runner.classification.PatternInclusionsDependencyFilter) String.format(java.lang.String.format) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Optional(java.util.Optional) Maps.newLinkedHashMap(com.google.common.collect.Maps.newLinkedHashMap) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) PatternExclusionsDependencyFilter(org.mule.test.runner.classification.PatternExclusionsDependencyFilter) Optional.empty(java.util.Optional.empty) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) Extension(org.mule.runtime.extension.api.annotation.Extension) Dependency(org.eclipse.aether.graph.Dependency) AtomicReference(java.util.concurrent.atomic.AtomicReference) COMPILE(org.eclipse.aether.util.artifact.JavaScopes.COMPILE) MODULE(org.mule.test.runner.api.ArtifactClassificationType.MODULE) VersionChecker.areCompatibleVersions(org.mule.maven.client.internal.util.VersionChecker.areCompatibleVersions) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) Properties(java.util.Properties) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Sets.newLinkedHashSet(com.google.common.collect.Sets.newLinkedHashSet) IOException(java.io.IOException) File(java.io.File) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Collectors.toList(java.util.stream.Collectors.toList) FileFilter(java.io.FileFilter) StringUtils.endsWithIgnoreCase(org.apache.commons.lang3.StringUtils.endsWithIgnoreCase) VersionChecker.isHighestVersion(org.mule.maven.client.internal.util.VersionChecker.isHighestVersion) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) Exclusion(org.eclipse.aether.graph.Exclusion) DependencyFilterUtils.classpathFilter(org.eclipse.aether.util.filter.DependencyFilterUtils.classpathFilter) Collections(java.util.Collections) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MalformedURLException(java.net.MalformedURLException) AtomicReference(java.util.concurrent.atomic.AtomicReference) URL(java.net.URL) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 52 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project syndesis by syndesisio.

the class RepackageExtensionMojo method downloadAndInstallArtifact.

/*
     * @param artifact The artifact coordinates in the format
     *            {@code <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>}, must not be {@code null}.
     *
     */
protected ArtifactResult downloadAndInstallArtifact(String artifact) throws MojoExecutionException {
    ArtifactResult result;
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(new DefaultArtifact(artifact));
    request.setRepositories(remoteRepos);
    getLog().info("Resolving artifact " + artifact + " from " + remoteRepos);
    try {
        result = repoSystem.resolveArtifact(repoSession, request);
        return result;
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 53 with ArtifactResolutionException

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

the class MavenBridge method resolve.

public Artifact resolve(final Artifact artifact, List<ArtifactRepository> remoteRepositories, MavenExecutionRequest executionRequest) throws MavenException {
    if (remoteRepositories == null) {
        try {
            remoteRepositories = getArtifactRepositories();
        } catch (MavenException e) {
            // we've tried
            remoteRepositories = Collections.emptyList();
        }
    }
    final List<ArtifactRepository> _remoteRepositories = remoteRepositories;
    org.eclipse.aether.RepositorySystem repoSystem = lookup(org.eclipse.aether.RepositorySystem.class);
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(RepositoryUtils.toArtifact(artifact));
    request.setRepositories(RepositoryUtils.toRepos(_remoteRepositories));
    ArtifactResult result;
    try {
        result = repoSystem.resolveArtifact(createRepositorySession(executionRequest), request);
    } catch (ArtifactResolutionException ex) {
        result = ex.getResults().get(0);
    }
    setLastUpdated(executionRequest.getLocalRepository(), _remoteRepositories, artifact);
    if (result.isResolved()) {
        artifact.selectVersion(result.getArtifact().getVersion());
        artifact.setFile(result.getArtifact().getFile());
        artifact.setResolved(true);
    } else {
        throw new MavenException(result.getExceptions().toArray(new Exception[result.getExceptions().size()]));
    }
    return artifact;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) PlexusContainerException(org.codehaus.plexus.PlexusContainerException) DuplicateProjectException(org.apache.maven.project.DuplicateProjectException) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) FileNotFoundException(java.io.FileNotFoundException) ConcurrentModificationException(java.util.ConcurrentModificationException) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) PluginVersionResolutionException(org.apache.maven.plugin.version.PluginVersionResolutionException) NoSuchRealmException(org.codehaus.plexus.classworlds.realm.NoSuchRealmException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) CycleDetectedException(org.codehaus.plexus.util.dag.CycleDetectedException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) IOException(java.io.IOException) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 54 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project unleash-maven-plugin by shillner.

the class ArtifactCacheLoader method load.

@Override
public Optional<ArtifactResult> load(ArtifactCoordinates coordinates) throws Exception {
    Artifact artifact = new DefaultArtifact(coordinates.toString());
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(artifact);
    artifactRequest.setRepositories(this.remoteProjectRepos);
    ArtifactResult artifactResult;
    try {
        artifactResult = this.repoSystem.resolveArtifact(this.repoSession, artifactRequest);
    } catch (ArtifactResolutionException e) {
        // must not throw the error or log as an error since this is an expected behavior
        artifactResult = null;
    }
    return Optional.fromNullable(artifactResult);
}
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 55 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project spf4j by zolyfarkas.

the class ApiChangesMojo method execute.

@Override
public void execute() throws MojoExecutionException {
    MavenProject mavenProject = getMavenProject();
    try {
        getLog().info("Executing JDiff javadoc doclet");
        JDiffRunner runner = new JDiffRunner(getMojoExecution(), getToolchainManager(), getMavenSession(), getProjectRepos(), getRepoSystem(), getJavadocExecutable());
        runner.runDiffBetweenReleases(mavenProject.getGroupId(), mavenProject.getArtifactId(), this.versionRange, destDir, maxNumberOfDiffs);
        runner.writeChangesIndexHtml(destDir, "changes.html");
        getLog().info("Generated " + destDir + File.separatorChar + "changes.html");
    } catch (IOException | DependencyResolutionException | VersionRangeResolutionException | ArtifactResolutionException | JavadocExecutionException ex) {
        throw new MojoExecutionException("Failed executing mojo " + this, ex);
    }
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) IOException(java.io.IOException) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException)

Aggregations

ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)55 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)24 Artifact (org.eclipse.aether.artifact.Artifact)21 IOException (java.io.IOException)20 VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)11 FileNotFoundException (java.io.FileNotFoundException)9 MalformedURLException (java.net.MalformedURLException)9 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)9 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)9 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)9 Path (java.nio.file.Path)8 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)8 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)8 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