Search in sources :

Example 1 with RepositoryException

use of org.eclipse.aether.RepositoryException in project bnd by bndtools.

the class BaselineMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        logger.debug("skip project as configured");
        return;
    }
    Artifact artifact = RepositoryUtils.toArtifact(project.getArtifact());
    List<RemoteRepository> aetherRepos = getRepositories(artifact);
    setupBase(artifact);
    try {
        if (base.getVersion() == null || base.getVersion().isEmpty()) {
            searchForBaseVersion(artifact, aetherRepos);
        }
        if (base.getVersion() != null && !base.getVersion().isEmpty()) {
            ArtifactResult artifactResult = locateBaseJar(aetherRepos);
            Reporter reporter;
            if (fullReport) {
                reporter = new ReporterAdapter(System.out);
                ((ReporterAdapter) reporter).setTrace(true);
            } else {
                reporter = new ReporterAdapter();
            }
            Baseline baseline = new Baseline(reporter, new DiffPluginImpl());
            if (checkFailures(artifact, artifactResult, baseline)) {
                if (continueOnError) {
                    logger.warn("The baselining check failed when checking {} against {} but the bnd-baseline-maven-plugin is configured not to fail the build.", artifact, artifactResult.getArtifact());
                } else {
                    throw new MojoExecutionException("The baselining plugin detected versioning errors");
                }
            } else {
                logger.info("Baselining check succeeded checking {} against {}", artifact, artifactResult.getArtifact());
            }
        } else {
            if (failOnMissing) {
                throw new MojoExecutionException("Unable to locate a previous version of the artifact");
            } else {
                logger.warn("No previous version of {} could be found to baseline against", artifact);
            }
        }
    } catch (RepositoryException re) {
        throw new MojoExecutionException("Unable to locate a previous version of the artifact", re);
    } catch (Exception e) {
        throw new MojoExecutionException("An error occurred while calculating the baseline", e);
    }
}
Also used : DiffPluginImpl(aQute.bnd.differ.DiffPluginImpl) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ReporterAdapter(aQute.libg.reporter.ReporterAdapter) Reporter(aQute.service.reporter.Reporter) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) RepositoryException(org.eclipse.aether.RepositoryException) Baseline(aQute.bnd.differ.Baseline) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) RepositoryException(org.eclipse.aether.RepositoryException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 2 with RepositoryException

use of org.eclipse.aether.RepositoryException in project fabric8 by jboss-fuse.

the class AetherBasedResolver method collectDependencies.

protected DependencyNode collectDependencies(Artifact root, String pomVersion, final Filter<Dependency> excludeDependencyFilter) throws RepositoryException, IOException {
    final DefaultRepositorySystemSession session = newSession();
    try {
        List<RemoteRepository> repos = selectRepositories();
        assignProxyAndMirrors(repos);
        ArtifactDescriptorResult artifactDescriptorResult = m_repoSystem.readArtifactDescriptor(session, new ArtifactDescriptorRequest(root, repos, null));
        repos.addAll(artifactDescriptorResult.getRepositories());
        Dependency rootDependency = new Dependency(root, null);
        List<Dependency> dependencies = artifactDescriptorResult.getDependencies();
        final DefaultDependencyNode rootNode = new DefaultDependencyNode(rootDependency);
        GenericVersionScheme versionScheme = new GenericVersionScheme();
        rootNode.setVersion(versionScheme.parseVersion(pomVersion));
        rootNode.setVersionConstraint(versionScheme.parseVersionConstraint(pomVersion));
        DependencyNode pomNode = rootNode;
        // final Filter<Dependency> shouldExclude = Filters.or(DependencyFilters.testScopeFilter, excludeDependencyFilter, new NewerVersionExistsFilter(rootNode));
        final Filter<Dependency> shouldExclude = Filters.or(Arrays.asList(DependencyFilters.testScopeFilter, excludeDependencyFilter));
        DependencySelector dependencySelector = new AndDependencySelector(new ScopeDependencySelector("test"), new ExclusionDependencySelector(), new DependencySelector() {

            @Override
            public DependencySelector deriveChildSelector(DependencyCollectionContext context) {
                return this;
            }

            @Override
            public boolean selectDependency(Dependency dependency) {
                try {
                    return !DependencyFilters.matches(dependency, shouldExclude);
                } catch (Exception e) {
                    failedToMakeDependencyTree(dependency, e);
                    return false;
                }
            }
        });
        session.setDependencySelector(dependencySelector);
        // work on the root dependency directly?
        if (true) {
            for (Dependency dependency : dependencies) {
                DependencyNode node = resolveDependencies(session, repos, pomNode, dependency, shouldExclude);
                if (node != null) {
                    pomNode.getChildren().add(node);
                }
            }
        } else {
            DependencyNode node = resolveDependencies(session, repos, pomNode, rootDependency, shouldExclude);
            if (node != null) {
                pomNode = node;
            }
        }
        // now lets transform the dependency tree to remove different versions for the same artifact
        final DependencyGraphTransformationContext tranformContext = new DependencyGraphTransformationContext() {

            Map<Object, Object> map = new HashMap<>();

            public RepositorySystemSession getSession() {
                return session;
            }

            public Object get(Object key) {
                return map.get(key);
            }

            public Object put(Object key, Object value) {
                return map.put(key, value);
            }
        };
        DependencyGraphTransformer transformer = new ReplaceConflictingVersionResolver();
        pomNode = transformer.transformGraph(pomNode, tranformContext);
        transformer = new DuplicateTransformer();
        pomNode = transformer.transformGraph(pomNode, tranformContext);
        return pomNode;
    } finally {
        releaseSession(session);
    }
}
Also used : DependencyGraphTransformationContext(org.eclipse.aether.collection.DependencyGraphTransformationContext) ReplaceConflictingVersionResolver(io.fabric8.maven.ReplaceConflictingVersionResolver) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DuplicateTransformer(io.fabric8.maven.DuplicateTransformer) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) DependencyNode(org.eclipse.aether.graph.DependencyNode) ChainedDependencyGraphTransformer(org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer) DependencyGraphTransformer(org.eclipse.aether.collection.DependencyGraphTransformer) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest) ScopeDependencySelector(org.eclipse.aether.util.graph.selector.ScopeDependencySelector) ExclusionDependencySelector(org.eclipse.aether.util.graph.selector.ExclusionDependencySelector) DependencyCollectionContext(org.eclipse.aether.collection.DependencyCollectionContext) AndDependencySelector(org.eclipse.aether.util.graph.selector.AndDependencySelector) Dependency(org.eclipse.aether.graph.Dependency) FailedToResolveDependency(io.fabric8.maven.FailedToResolveDependency) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ArtifactNotFoundException(org.eclipse.aether.transfer.ArtifactNotFoundException) RepositoryException(org.eclipse.aether.RepositoryException) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) MetadataTransferException(org.eclipse.aether.transfer.MetadataTransferException) NoRouteToHostException(java.net.NoRouteToHostException) ArtifactTransferException(org.eclipse.aether.transfer.ArtifactTransferException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) MalformedURLException(java.net.MalformedURLException) MetadataNotFoundException(org.eclipse.aether.transfer.MetadataNotFoundException) InvalidVersionSpecificationException(org.eclipse.aether.version.InvalidVersionSpecificationException) AndDependencySelector(org.eclipse.aether.util.graph.selector.AndDependencySelector) ScopeDependencySelector(org.eclipse.aether.util.graph.selector.ScopeDependencySelector) OptionalDependencySelector(org.eclipse.aether.util.graph.selector.OptionalDependencySelector) ExclusionDependencySelector(org.eclipse.aether.util.graph.selector.ExclusionDependencySelector) DependencySelector(org.eclipse.aether.collection.DependencySelector) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) GenericVersionScheme(org.eclipse.aether.util.version.GenericVersionScheme) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 3 with RepositoryException

use of org.eclipse.aether.RepositoryException in project fabric8 by jboss-fuse.

the class AetherBasedResolver method isRetryableException.

@Override
public RetryChance isRetryableException(Exception exception) {
    RetryChance retry = RetryChance.NEVER;
    RepositoryException aetherException = findAetherException(exception);
    if (aetherException instanceof ArtifactResolutionException) {
        // aggregate case - exception that contains exceptions - usually per repository
        ArtifactResolutionException resolutionException = (ArtifactResolutionException) aetherException;
        if (resolutionException.getResult() != null) {
            for (Exception ex : resolutionException.getResult().getExceptions()) {
                RetryChance singleRetry = isRetryableException(ex);
                if (retry.chance() < singleRetry.chance()) {
                    retry = singleRetry;
                }
            }
        }
    } else if (aetherException != null) {
        // single exception case
        if (aetherException instanceof ArtifactNotFoundException) {
            // very little chance we'll find the artifact next time
            retry = RetryChance.NEVER;
        } else if (aetherException instanceof MetadataNotFoundException) {
            retry = RetryChance.NEVER;
        } else if (aetherException instanceof ArtifactTransferException || aetherException instanceof MetadataTransferException) {
            // we could try again
            Throwable root = rootException(aetherException);
            if (root instanceof SocketTimeoutException) {
                // we could try again - but without assuming we'll succeed eventually
                retry = RetryChance.LOW;
            } else if (root instanceof ConnectException) {
                // "connection refused" - not retryable
                retry = RetryChance.NEVER;
            } else if (root instanceof NoRouteToHostException) {
                // not retryable
                retry = RetryChance.NEVER;
            }
        } else {
            // general aether exception - let's fallback to NEVER, as retryable cases should be
            // handled explicitly
            retry = RetryChance.NEVER;
        }
    } else {
        // we don't know about non-aether exceptions, so let's allow
        retry = RetryChance.UNKNOWN;
    }
    return retry;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MetadataNotFoundException(org.eclipse.aether.transfer.MetadataNotFoundException) ArtifactTransferException(org.eclipse.aether.transfer.ArtifactTransferException) SocketTimeoutException(java.net.SocketTimeoutException) MetadataTransferException(org.eclipse.aether.transfer.MetadataTransferException) RepositoryException(org.eclipse.aether.RepositoryException) ArtifactNotFoundException(org.eclipse.aether.transfer.ArtifactNotFoundException) NoRouteToHostException(java.net.NoRouteToHostException) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ArtifactNotFoundException(org.eclipse.aether.transfer.ArtifactNotFoundException) RepositoryException(org.eclipse.aether.RepositoryException) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) MetadataTransferException(org.eclipse.aether.transfer.MetadataTransferException) NoRouteToHostException(java.net.NoRouteToHostException) ArtifactTransferException(org.eclipse.aether.transfer.ArtifactTransferException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) MalformedURLException(java.net.MalformedURLException) MetadataNotFoundException(org.eclipse.aether.transfer.MetadataNotFoundException) InvalidVersionSpecificationException(org.eclipse.aether.version.InvalidVersionSpecificationException) ConnectException(java.net.ConnectException)

Example 4 with RepositoryException

use of org.eclipse.aether.RepositoryException in project fabric8 by jboss-fuse.

the class AetherBasedResolver method resolve.

private File resolve(List<LocalRepository> defaultRepos, List<RemoteRepository> remoteRepos, Artifact artifact) throws IOException {
    if (artifact.getExtension().isEmpty()) {
        artifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), "jar", artifact.getVersion());
    }
    // Try with default repositories
    try {
        VersionConstraint vc = new GenericVersionScheme().parseVersionConstraint(artifact.getVersion());
        if (vc.getVersion() != null) {
            for (LocalRepository repo : defaultRepos) {
                if (vc.getVersion().toString().endsWith("SNAPSHOT") && !handlesSnapshot(repo)) {
                    continue;
                }
                DefaultRepositorySystemSession session = newSession(repo);
                try {
                    return m_repoSystem.resolveArtifact(session, new ArtifactRequest(artifact, null, null)).getArtifact().getFile();
                } catch (ArtifactResolutionException e) {
                // Ignore
                } finally {
                    releaseSession(session);
                }
            }
        }
    } catch (InvalidVersionSpecificationException e) {
    // Should not happen
    }
    DefaultRepositorySystemSession session = newSession(null);
    try {
        artifact = resolveLatestVersionRange(session, remoteRepos, artifact);
        ArtifactResult result = m_repoSystem.resolveArtifact(session, new ArtifactRequest(artifact, remoteRepos, null));
        File resolved = result.getArtifact().getFile();
        LOG.debug("Resolved ({}) as {}", artifact.toString(), resolved.getAbsolutePath());
        return resolved;
    } catch (ArtifactResolutionException e) {
        // we know there's one ArtifactResult, because there was one ArtifactRequest
        ArtifactResolutionException original = new ArtifactResolutionException(e.getResults(), "Error resolving artifact " + artifact.toString(), null);
        original.setStackTrace(e.getStackTrace());
        List<String> messages = new ArrayList<>(e.getResult().getExceptions().size());
        List<Exception> suppressed = new ArrayList<>();
        for (Exception ex : e.getResult().getExceptions()) {
            messages.add(ex.getMessage() == null ? ex.getClass().getName() : ex.getMessage());
            suppressed.add(ex);
        }
        IOException exception = new IOException(original.getMessage() + ": " + messages, original);
        for (Exception ex : suppressed) {
            exception.addSuppressed(ex);
        }
        LOG.warn(exception.getMessage(), exception);
        for (Exception ex : suppressed) {
            LOG.warn(" - " + ex.getMessage());
        }
        throw exception;
    } catch (RepositoryException e) {
        throw new IOException("Error resolving artifact " + artifact.toString(), e);
    } finally {
        releaseSession(session);
    }
}
Also used : VersionConstraint(org.eclipse.aether.version.VersionConstraint) LocalRepository(org.eclipse.aether.repository.LocalRepository) RepositoryException(org.eclipse.aether.RepositoryException) IOException(java.io.IOException) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ArtifactNotFoundException(org.eclipse.aether.transfer.ArtifactNotFoundException) RepositoryException(org.eclipse.aether.RepositoryException) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) MetadataTransferException(org.eclipse.aether.transfer.MetadataTransferException) NoRouteToHostException(java.net.NoRouteToHostException) ArtifactTransferException(org.eclipse.aether.transfer.ArtifactTransferException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) MalformedURLException(java.net.MalformedURLException) MetadataNotFoundException(org.eclipse.aether.transfer.MetadataNotFoundException) InvalidVersionSpecificationException(org.eclipse.aether.version.InvalidVersionSpecificationException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) InvalidVersionSpecificationException(org.eclipse.aether.version.InvalidVersionSpecificationException) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) GenericVersionScheme(org.eclipse.aether.util.version.GenericVersionScheme) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) File(java.io.File) JarFile(java.util.jar.JarFile) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 5 with RepositoryException

use of org.eclipse.aether.RepositoryException in project fabric8 by jboss-fuse.

the class AetherResolutionWithHintsTest method hintedResolution.

@Test
public void hintedResolution() throws Exception {
    final MavenConfigurationImpl mavenConfiguration = mavenConfiguration();
    mavenConfiguration.setSettings(settingsWithProxy());
    MavenResolver resolver = new AetherBasedResolver(mavenConfiguration);
    try {
        resolver.download("mvn:org.ops4j.pax.web/pax-web-api/1");
        fail("Resolution should fail");
    } catch (IOException e) {
        RepositoryException exception = ((AetherBasedResolver) resolver).findAetherException(e);
        assertNotNull(exception);
        assertTrue(exception instanceof ArtifactResolutionException);
        ArtifactResolutionException are = (ArtifactResolutionException) exception;
        assertThat(are.getResult().getExceptions().size(), equalTo(3));
        assertTrue("Non-retryable exception", are.getResult().getExceptions().get(0) instanceof ArtifactNotFoundException);
        assertTrue("Non-retryable exception", are.getResult().getExceptions().get(1) instanceof ArtifactNotFoundException);
        assertTrue("Retryable exception", are.getResult().getExceptions().get(2) instanceof ArtifactTransferException);
        assertFalse("Retryable exception", are.getResult().getExceptions().get(2) instanceof ArtifactNotFoundException);
        try {
            // try again with exception hint
            resolver.download("mvn:org.ops4j.pax.web/pax-web-api/1", e);
            fail("Resolution should fail");
        } catch (IOException e2) {
            exception = ((AetherBasedResolver) resolver).findAetherException(e2);
            assertNotNull(exception);
            assertTrue(exception instanceof ArtifactResolutionException);
            are = (ArtifactResolutionException) exception;
            assertThat(are.getResult().getExceptions().size(), equalTo(1));
            assertTrue("Retryable exception", are.getResult().getExceptions().get(0) instanceof ArtifactTransferException);
            assertFalse("Retryable exception", are.getResult().getExceptions().get(0) instanceof ArtifactNotFoundException);
        }
    } finally {
        resolver.close();
    }
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MavenConfigurationImpl(io.fabric8.maven.util.MavenConfigurationImpl) ArtifactTransferException(org.eclipse.aether.transfer.ArtifactTransferException) MavenResolver(io.fabric8.maven.MavenResolver) RepositoryException(org.eclipse.aether.RepositoryException) IOException(java.io.IOException) ArtifactNotFoundException(org.eclipse.aether.transfer.ArtifactNotFoundException) Test(org.junit.Test)

Aggregations

RepositoryException (org.eclipse.aether.RepositoryException)10 IOException (java.io.IOException)7 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)6 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)5 DependencyResolutionException (org.eclipse.aether.resolution.DependencyResolutionException)5 VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)5 ArtifactNotFoundException (org.eclipse.aether.transfer.ArtifactNotFoundException)5 ArtifactTransferException (org.eclipse.aether.transfer.ArtifactTransferException)5 ConnectException (java.net.ConnectException)4 MalformedURLException (java.net.MalformedURLException)4 NoRouteToHostException (java.net.NoRouteToHostException)4 SocketTimeoutException (java.net.SocketTimeoutException)4 DependencyCollectionException (org.eclipse.aether.collection.DependencyCollectionException)4 MetadataNotFoundException (org.eclipse.aether.transfer.MetadataNotFoundException)4 MetadataTransferException (org.eclipse.aether.transfer.MetadataTransferException)4 InvalidVersionSpecificationException (org.eclipse.aether.version.InvalidVersionSpecificationException)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)3 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)3