Search in sources :

Example 1 with ArtifactTransferException

use of org.eclipse.aether.transfer.ArtifactTransferException 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 2 with ArtifactTransferException

use of org.eclipse.aether.transfer.ArtifactTransferException 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)

Example 3 with ArtifactTransferException

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

the class AetherBasedResolver method resolveFile.

/**
 * Resolve maven artifact as file in repository.
 */
public File resolveFile(Artifact artifact, MavenRepositoryURL repositoryURL, Exception previousException) throws IOException {
    List<LocalRepository> defaultRepos = selectDefaultRepositories();
    List<RemoteRepository> remoteRepos = selectRepositories();
    if (repositoryURL != null) {
        addRepo(remoteRepos, repositoryURL);
    }
    if (previousException != null) {
        // we'll try using previous repositories, without these that will fail again anyway
        List<RemoteRepository> altered = new LinkedList<>();
        RepositoryException repositoryException = findAetherException(previousException);
        if (repositoryException instanceof ArtifactResolutionException) {
            // check only this aggregate exception and assume it's related to current artifact
            ArtifactResult result = ((ArtifactResolutionException) repositoryException).getResult();
            if (result != null && result.getRequest() != null && result.getRequest().getArtifact().equals(artifact)) {
                // - these exceptions contain repository that was checked
                for (Exception exception : result.getExceptions()) {
                    RepositoryException singleException = findAetherException(exception);
                    if (singleException instanceof ArtifactTransferException) {
                        RemoteRepository repository = ((ArtifactTransferException) singleException).getRepository();
                        if (repository != null) {
                            RetryChance chance = isRetryableException(singleException);
                            if (chance == RetryChance.NEVER) {
                                LOG.debug("Removing " + repository + " from list of repositories, previous exception: " + singleException.getClass().getName() + ": " + singleException.getMessage());
                            } else {
                                altered.add(repository);
                            }
                        }
                    }
                }
                // swap list of repos now
                remoteRepos = altered;
            }
        }
    }
    assignProxyAndMirrors(remoteRepos);
    File resolved = resolve(defaultRepos, remoteRepos, artifact);
    LOG.debug("Resolved ({}) as {}", artifact.toString(), resolved.getAbsolutePath());
    return resolved;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactTransferException(org.eclipse.aether.transfer.ArtifactTransferException) LocalRepository(org.eclipse.aether.repository.LocalRepository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) RepositoryException(org.eclipse.aether.RepositoryException) File(java.io.File) JarFile(java.util.jar.JarFile) LinkedList(java.util.LinkedList) 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)

Aggregations

IOException (java.io.IOException)3 RepositoryException (org.eclipse.aether.RepositoryException)3 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)3 ArtifactNotFoundException (org.eclipse.aether.transfer.ArtifactNotFoundException)3 ArtifactTransferException (org.eclipse.aether.transfer.ArtifactTransferException)3 ConnectException (java.net.ConnectException)2 MalformedURLException (java.net.MalformedURLException)2 NoRouteToHostException (java.net.NoRouteToHostException)2 SocketTimeoutException (java.net.SocketTimeoutException)2 DependencyCollectionException (org.eclipse.aether.collection.DependencyCollectionException)2 DependencyResolutionException (org.eclipse.aether.resolution.DependencyResolutionException)2 VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)2 MetadataNotFoundException (org.eclipse.aether.transfer.MetadataNotFoundException)2 MetadataTransferException (org.eclipse.aether.transfer.MetadataTransferException)2 InvalidVersionSpecificationException (org.eclipse.aether.version.InvalidVersionSpecificationException)2 MavenResolver (io.fabric8.maven.MavenResolver)1 MavenConfigurationImpl (io.fabric8.maven.util.MavenConfigurationImpl)1 File (java.io.File)1 LinkedList (java.util.LinkedList)1 JarFile (java.util.jar.JarFile)1