use of org.eclipse.aether.resolution.ArtifactResolutionException in project BIMserver by opensourceBIM.
the class PluginManager method loadDependencies.
private PublicFindClassClassLoader loadDependencies(Set<org.bimserver.plugins.Dependency> bimServerDependencies, Model model, PublicFindClassClassLoader previous) throws FileNotFoundException, IOException {
List<org.apache.maven.model.Dependency> dependencies = model.getDependencies();
Iterator<org.apache.maven.model.Dependency> it = dependencies.iterator();
Path workspaceDir = Paths.get("..");
bimServerDependencies.add(new org.bimserver.plugins.Dependency(workspaceDir.resolve("PluginBase/target/classes")));
bimServerDependencies.add(new org.bimserver.plugins.Dependency(workspaceDir.resolve("Shared/target/classes")));
while (it.hasNext()) {
org.apache.maven.model.Dependency depend = it.next();
try {
if (depend.getGroupId().equals("org.opensourcebim") && (depend.getArtifactId().equals("shared") || depend.getArtifactId().equals("pluginbase"))) {
// TODO we might want to check the version though
continue;
}
if (depend.isOptional() || "test".equals(depend.getScope())) {
continue;
}
Dependency dependency2 = new Dependency(new DefaultArtifact(depend.getGroupId() + ":" + depend.getArtifactId() + ":jar:" + depend.getVersion()), "compile");
DelegatingClassLoader depDelLoader = new DelegatingClassLoader(previous);
if (!dependency2.getArtifact().isSnapshot()) {
if (dependency2.getArtifact().getFile() != null) {
bimServerDependencies.add(new org.bimserver.plugins.Dependency(dependency2.getArtifact().getFile().toPath()));
loadDependencies(dependency2.getArtifact().getFile().toPath(), depDelLoader);
} else {
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(dependency2.getArtifact());
request.setRepositories(mavenPluginRepository.getRepositories());
try {
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
if (resolveArtifact.getArtifact().getFile() != null) {
bimServerDependencies.add(new org.bimserver.plugins.Dependency(resolveArtifact.getArtifact().getFile().toPath()));
loadDependencies(resolveArtifact.getArtifact().getFile().toPath(), depDelLoader);
} else {
// TODO error?
}
} catch (ArtifactResolutionException e) {
e.printStackTrace();
}
}
} else {
// Snapshot projects linked in Eclipse
ArtifactRequest request = new ArtifactRequest();
if ((!"test".equals(dependency2.getScope()) && !dependency2.getArtifact().isSnapshot())) {
request.setArtifact(dependency2.getArtifact());
request.setRepositories(mavenPluginRepository.getLocalRepositories());
try {
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
if (resolveArtifact.getArtifact().getFile() != null) {
bimServerDependencies.add(new org.bimserver.plugins.Dependency(resolveArtifact.getArtifact().getFile().toPath()));
loadDependencies(resolveArtifact.getArtifact().getFile().toPath(), depDelLoader);
} else {
// TODO error?
}
} catch (Exception e) {
LOGGER.info(dependency2.getArtifact().toString());
e.printStackTrace();
}
// bimServerDependencies.add(new
// org.bimserver.plugins.Dependency(resolveArtifact.getArtifact().getFile().toPath()));
}
}
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
descriptorRequest.setArtifact(dependency2.getArtifact());
descriptorRequest.setRepositories(mavenPluginRepository.getRepositories());
ArtifactDescriptorResult descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRootArtifact(descriptorResult.getArtifact());
collectRequest.setDependencies(descriptorResult.getDependencies());
collectRequest.setManagedDependencies(descriptorResult.getManagedDependencies());
collectRequest.setRepositories(descriptorResult.getRepositories());
DependencyNode node = mavenPluginRepository.getSystem().collectDependencies(mavenPluginRepository.getSession(), collectRequest).getRoot();
DependencyRequest dependencyRequest = new DependencyRequest();
dependencyRequest.setRoot(node);
CollectResult collectResult = mavenPluginRepository.getSystem().collectDependencies(mavenPluginRepository.getSession(), collectRequest);
PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
// collectResult.getRoot().accept(new
// ConsoleDependencyGraphDumper());
collectResult.getRoot().accept(nlg);
try {
mavenPluginRepository.getSystem().resolveDependencies(mavenPluginRepository.getSession(), dependencyRequest);
} catch (DependencyResolutionException e) {
// Ignore
}
for (DependencyNode dependencyNode : nlg.getNodes()) {
ArtifactRequest newRequest = new ArtifactRequest(dependencyNode);
newRequest.setRepositories(mavenPluginRepository.getRepositories());
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), newRequest);
Artifact artifact = resolveArtifact.getArtifact();
Path jarFile = Paths.get(artifact.getFile().getAbsolutePath());
loadDependencies(jarFile, depDelLoader);
Artifact versionArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion());
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(versionArtifact);
request.setRepositories(mavenPluginRepository.getRepositories());
// try {
// ArtifactResult resolveArtifact =
// mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(),
// request);
// File depPomFile =
// resolveArtifact.getArtifact().getFile();
// if (depPomFile != null) {
// MavenXpp3Reader mavenreader = new MavenXpp3Reader();
// Model depModel = null;
// try (FileReader reader = new FileReader(depPomFile)) {
// try {
// depModel = mavenreader.read(reader);
// } catch (XmlPullParserException e) {
// e.printStackTrace();
// }
// }
// previous = loadDependencies(bimServerDependencies,
// depModel, previous);
// } else {
// LOGGER.info("Artifact not found " + versionArtifact);
// }
// } catch (ArtifactResolutionException e1) {
// LOGGER.error(e1.getMessage());
// }
// EclipsePluginClassloader depLoader = new
// EclipsePluginClassloader(depDelLoader, projectRoot);
bimServerDependencies.add(new org.bimserver.plugins.Dependency(jarFile));
}
previous = depDelLoader;
} catch (DependencyCollectionException e) {
e.printStackTrace();
} catch (ArtifactDescriptorException e2) {
e2.printStackTrace();
} catch (ArtifactResolutionException e) {
e.printStackTrace();
}
}
return previous;
}
use of org.eclipse.aether.resolution.ArtifactResolutionException in project bnd by bndtools.
the class AetherRepository method get.
@Override
public File get(String bsn, Version version, Map<String, String> properties, DownloadListener... listeners) throws Exception {
init();
// Use the index by preference
if (indexedRepo != null)
return indexedRepo.get(ConversionUtils.maybeMavenCoordsToBsn(bsn), version, properties, listeners);
File file = null;
boolean getSource = false;
try {
// Setup the Aether repo session and request
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
if (bsn.endsWith(".source")) {
String originalBsn = properties.get("bsn");
if (originalBsn != null) {
bsn = originalBsn;
getSource = true;
}
}
String[] coords = ConversionUtils.getGroupAndArtifactForBsn(bsn);
MavenVersion mvnVersion = new MavenVersion(version);
String versionStr = null;
if ("exact".equals(properties.get("strategy")) || getSource) {
versionStr = properties.get("version");
} else {
versionStr = mvnVersion.toString();
}
Artifact artifact = null;
if (getSource) {
artifact = new DefaultArtifact(coords[0], coords[1], "sources", "jar", versionStr);
} else {
artifact = new DefaultArtifact(coords[0], coords[1], "jar", versionStr);
}
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(artifact);
request.setRepositories(Collections.singletonList(remoteRepo));
// Log the transfer
session.setTransferListener(new AbstractTransferListener() {
@Override
public void transferStarted(TransferEvent event) throws TransferCancelledException {
System.err.println(event);
}
@Override
public void transferSucceeded(TransferEvent event) {
System.err.println(event);
}
@Override
public void transferFailed(TransferEvent event) {
System.err.println(event);
}
});
try {
// Resolve the version
ArtifactResult artifactResult = repoSystem.resolveArtifact(session, request);
artifact = artifactResult.getArtifact();
file = artifact.getFile();
} catch (ArtifactResolutionException ex) {
// could not download artifact, simply return null
}
return file;
} finally {
for (DownloadListener dl : listeners) {
if (file != null)
dl.success(file);
else
dl.failure(null, "Download failed");
}
}
}
use of org.eclipse.aether.resolution.ArtifactResolutionException in project bnd by bndtools.
the class DependencyResolver method discoverArtifacts.
private void discoverArtifacts(Map<File, ArtifactResult> files, List<DependencyNode> nodes, String parent, List<RemoteRepository> remoteRepositories) throws MojoExecutionException {
for (DependencyNode node : nodes) {
// Ensure that the file is downloaded so we can index it
try {
ArtifactResult resolvedArtifact = postProcessor.postProcessResult(system.resolveArtifact(session, new ArtifactRequest(node.getArtifact(), remoteRepositories, parent)));
logger.debug("Located file: {} for artifact {}", resolvedArtifact.getArtifact().getFile(), resolvedArtifact);
files.put(resolvedArtifact.getArtifact().getFile(), resolvedArtifact);
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException("Failed to resolve the dependency " + node.getArtifact().toString(), e);
}
if (includeTransitive) {
discoverArtifacts(files, node.getChildren(), node.getRequestContext(), remoteRepositories);
} else {
logger.debug("Ignoring transitive dependencies of {}", node.getDependency());
}
}
}
use of org.eclipse.aether.resolution.ArtifactResolutionException in project bnd by bndtools.
the class RemotePostProcessor method postProcessSnapshot.
private ArtifactResult postProcessSnapshot(ArtifactRequest request, Artifact artifact) throws MojoExecutionException {
for (RemoteRepository repository : request.getRepositories()) {
if (!repository.getPolicy(true).isEnabled()) {
// Skip the repo if it isn't enabled for snapshots
continue;
}
// Remove the workspace from the session so that we don't use it
DefaultRepositorySystemSession newSession = new DefaultRepositorySystemSession(session);
newSession.setWorkspaceReader(null);
// Find the snapshot metadata for the module
MetadataRequest mr = new MetadataRequest().setRepository(repository).setMetadata(new DefaultMetadata(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "maven-metadata.xml", SNAPSHOT));
for (MetadataResult metadataResult : system.resolveMetadata(newSession, singletonList(mr))) {
if (metadataResult.isResolved()) {
String version;
try {
Metadata read = metadataReader.read(metadataResult.getMetadata().getFile(), null);
Versioning versioning = read.getVersioning();
if (versioning == null || versioning.getSnapshotVersions() == null || versioning.getSnapshotVersions().isEmpty()) {
continue;
} else {
version = versioning.getSnapshotVersions().get(0).getVersion();
}
} catch (Exception e) {
throw new MojoExecutionException("Unable to read project metadata for " + artifact, e);
}
Artifact fullVersionArtifact = new org.eclipse.aether.artifact.DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension(), version);
try {
ArtifactResult result = system.resolveArtifact(newSession, new ArtifactRequest().setArtifact(fullVersionArtifact).addRepository(repository));
if (result.isResolved()) {
File toUse = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteArtifact(fullVersionArtifact, repository, artifact.toString()));
if (!toUse.exists()) {
logger.warn("The resolved artifact {} does not exist at {}", fullVersionArtifact, toUse);
continue;
} else {
logger.debug("Located snapshot file {} for artifact {}", toUse, artifact);
}
result.getArtifact().setFile(toUse);
return result;
}
} catch (ArtifactResolutionException e) {
logger.debug("Unable to locate the artifact {}", fullVersionArtifact, e);
}
}
}
}
logger.debug("Unable to resolve a remote repository containing {}", artifact);
return null;
}
use of org.eclipse.aether.resolution.ArtifactResolutionException 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;
}
Aggregations