use of org.eclipse.aether.resolution.ArtifactResolutionException 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.resolution.ArtifactResolutionException 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();
}
}
use of org.eclipse.aether.resolution.ArtifactResolutionException in project elasticsearch-maven-plugin by alexcojocaru.
the class MyArtifactResolver method resolveArtifact.
/**
* Resolves an Artifact from the repositories.
*
* @param coordinates The artifact coordinates
* @return The local file resolved/downloaded for the given coordinates
* @throws ResolutionException If the artifact cannot be resolved
*/
public File resolveArtifact(String coordinates) throws ResolutionException {
ArtifactRequest request = new ArtifactRequest();
Artifact artifact = new DefaultArtifact(coordinates);
request.setArtifact(artifact);
request.setRepositories(remoteRepositories);
log.debug(String.format("Resolving artifact %s from %s", artifact, remoteRepositories));
ArtifactResult result;
try {
result = repositorySystem.resolveArtifact(repositorySession, request);
} catch (ArtifactResolutionException e) {
throw new ResolutionException(e.getMessage(), e);
}
log.debug(String.format("Resolved artifact %s to %s from %s", artifact, result.getArtifact().getFile(), result.getRepository()));
return result.getArtifact().getFile();
}
use of org.eclipse.aether.resolution.ArtifactResolutionException in project BIMserver by opensourceBIM.
the class MavenPluginLocation method createMavenVersion.
private MavenPluginVersion createMavenVersion(Version version) throws ArtifactDescriptorException, FileNotFoundException, IOException, ArtifactResolutionException, XmlPullParserException {
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "pom", version.toString());
descriptorRequest.setArtifact(versionArtifact);
descriptorRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList());
MavenPluginVersion mavenPluginVersion = new MavenPluginVersion(versionArtifact, version);
ArtifactDescriptorResult descriptorResult;
descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest);
try {
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(descriptorResult.getArtifact());
request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
File pomFile = resolveArtifact.getArtifact().getFile();
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
try (FileReader fileReader = new FileReader(pomFile)) {
Model model = mavenreader.read(fileReader);
mavenPluginVersion.setModel(model);
}
} catch (Exception e) {
LOGGER.error(e.getMessage());
}
for (org.eclipse.aether.graph.Dependency dependency : descriptorResult.getDependencies()) {
DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(dependency.getArtifact().getVersion());
mavenPluginVersion.addDependency(new MavenDependency(dependency.getArtifact(), artifactVersion));
}
return mavenPluginVersion;
}
use of org.eclipse.aether.resolution.ArtifactResolutionException in project BIMserver by opensourceBIM.
the class PluginBundleDatabaseAction method processMavenPluginLocation.
public SPluginBundle processMavenPluginLocation(MavenPluginLocation mavenPluginLocation, boolean strictVersionChecking, ArtifactVersion bimserverVersion) {
SPluginBundle pluginBundle = new SPluginBundle();
boolean usefulBundle = false;
Iterator<MavenPluginVersion> iterateAllVersions = mavenPluginLocation.iterateAllVersions();
int matchingPlugins = 0;
while (iterateAllVersions.hasNext() && matchingPlugins < DEFAULT_MATCHING_PLUGINS) {
MavenPluginVersion mavenPluginVersion = iterateAllVersions.next();
SPluginBundleVersion sPluginBundleVersion = new SPluginBundleVersion();
boolean useful = true;
boolean hasPluginBaseDependency = false;
for (MavenDependency mavenDependency : mavenPluginVersion.getDependencies()) {
if (mavenDependency.getArtifact().getGroupId().equals("org.opensourcebim")) {
String artifactId = mavenDependency.getArtifact().getArtifactId();
// for the plugin, it's version has to be ok
if (artifactId.equals("shared") || artifactId.equals("pluginbase")) {
hasPluginBaseDependency = true;
try {
String version = mavenDependency.getArtifact().getVersion();
if (!version.contains("[") && !version.contains("(")) {
version = "[" + version + "]";
}
VersionRange versionRange = VersionRange.createFromVersionSpec(version);
if (bimserverVersion == null || versionRange.containsVersion(bimserverVersion) || (bimserverVersion.getQualifier() != null && bimserverVersion.getQualifier().equals("SNAPSHOT"))) {
// OK
} else {
sPluginBundleVersion.setMismatch(true);
if (strictVersionChecking) {
useful = false;
}
}
} catch (InvalidVersionSpecificationException e) {
LOGGER.error("", e);
}
}
}
}
if (useful && hasPluginBaseDependency) {
usefulBundle = true;
matchingPlugins++;
sPluginBundleVersion.setName(mavenPluginVersion.getModel().getName());
sPluginBundleVersion.setOrganization(mavenPluginVersion.getModel().getOrganization().getName());
sPluginBundleVersion.setArtifactId(mavenPluginLocation.getArtifactId());
sPluginBundleVersion.setGroupId(mavenPluginLocation.getGroupId());
try {
sPluginBundleVersion.setRepository(mavenPluginLocation.getRepository(mavenPluginVersion.getVersion().toString()));
} catch (ArtifactResolutionException e) {
LOGGER.error("", e);
}
sPluginBundleVersion.setType(SPluginBundleType.MAVEN);
sPluginBundleVersion.setVersion(mavenPluginVersion.getVersion().toString());
sPluginBundleVersion.setDescription(mavenPluginVersion.getModel().getDescription());
pluginBundle.setName(mavenPluginVersion.getModel().getName());
pluginBundle.setOrganization(mavenPluginVersion.getModel().getOrganization().getName());
if (pluginBundle.getLatestVersion() == null) {
pluginBundle.setLatestVersion(sPluginBundleVersion);
}
pluginBundle.getAvailableVersions().add(sPluginBundleVersion);
try {
sPluginBundleVersion.setIcon(mavenPluginLocation.getVersionIcon(mavenPluginVersion.getVersion().toString()));
} catch (ArtifactResolutionException e) {
// This is not important
} catch (IOException e) {
LOGGER.error("", e);
}
try {
GregorianCalendar date = mavenPluginLocation.getVersionDate(mavenPluginVersion.getVersion().toString());
if (date != null) {
sPluginBundleVersion.setDate(date.getTime());
}
// byte[] bytes = Files.readAllBytes(date);
// Properties properties = new Properties();
// properties.load(new ByteArrayInputStream(bytes));
// String buildDateString = properties.getProperty("build.date");
//
// DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
// try {
// } catch (ParseException e) {
// LOGGER.error("Invalid date format for plugin " + mavenPluginVersion.getModel().getName() + ": '" + buildDateString + "'");
// }
} catch (ArtifactResolutionException e) {
// Not a problem
} catch (Exception e) {
LOGGER.error("", e);
}
}
}
if (usefulBundle) {
// }});
return pluginBundle;
}
return null;
}
Aggregations