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);
}
}
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);
}
}
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;
}
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);
}
}
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();
}
}
Aggregations