use of org.sonatype.aether.RequestTrace in project sonatype-aether by sonatype.
the class DefaultInstaller method install.
private InstallResult install(SyncContext syncContext, RepositorySystemSession session, InstallRequest request) throws InstallationException {
InstallResult result = new InstallResult(request);
RequestTrace trace = DefaultRequestTrace.newChild(request.getTrace(), request);
List<MetadataGenerator> generators = getMetadataGenerators(session, request);
List<Artifact> artifacts = new ArrayList<Artifact>(request.getArtifacts());
IdentityHashMap<Metadata, Object> processedMetadata = new IdentityHashMap<Metadata, Object>();
List<Metadata> metadatas = Utils.prepareMetadata(generators, artifacts);
syncContext.acquire(artifacts, Utils.combine(request.getMetadata(), metadatas));
for (Metadata metadata : metadatas) {
install(session, trace, metadata);
processedMetadata.put(metadata, null);
result.addMetadata(metadata);
}
for (int i = 0; i < artifacts.size(); i++) {
Artifact artifact = artifacts.get(i);
for (MetadataGenerator generator : generators) {
artifact = generator.transformArtifact(artifact);
}
artifacts.set(i, artifact);
install(session, trace, artifact);
result.addArtifact(artifact);
}
metadatas = Utils.finishMetadata(generators, artifacts);
syncContext.acquire(null, metadatas);
for (Metadata metadata : metadatas) {
install(session, trace, metadata);
processedMetadata.put(metadata, null);
result.addMetadata(metadata);
}
for (Metadata metadata : request.getMetadata()) {
if (!processedMetadata.containsKey(metadata)) {
install(session, trace, metadata);
result.addMetadata(metadata);
}
}
return result;
}
use of org.sonatype.aether.RequestTrace in project sonatype-aether by sonatype.
the class DefaultRepositorySystem method resolveDependencies.
public DependencyResult resolveDependencies(RepositorySystemSession session, DependencyRequest request) throws DependencyResolutionException {
validateSession(session);
RequestTrace trace = DefaultRequestTrace.newChild(request.getTrace(), request);
DependencyResult result = new DependencyResult(request);
DependencyCollectionException dce = null;
ArtifactResolutionException are = null;
if (request.getRoot() != null) {
result.setRoot(request.getRoot());
} else if (request.getCollectRequest() != null) {
CollectResult collectResult;
try {
request.getCollectRequest().setTrace(trace);
collectResult = dependencyCollector.collectDependencies(session, request.getCollectRequest());
} catch (DependencyCollectionException e) {
dce = e;
collectResult = e.getResult();
}
result.setRoot(collectResult.getRoot());
result.setCollectExceptions(collectResult.getExceptions());
} else {
throw new IllegalArgumentException("dependency node or collect request missing");
}
ArtifactRequestBuilder builder = new ArtifactRequestBuilder(trace);
DependencyFilter filter = request.getFilter();
DependencyVisitor visitor = (filter != null) ? new FilteringDependencyVisitor(builder, filter) : builder;
visitor = new TreeDependencyVisitor(visitor);
result.getRoot().accept(visitor);
List<ArtifactRequest> requests = builder.getRequests();
List<ArtifactResult> results;
try {
results = artifactResolver.resolveArtifacts(session, requests);
} catch (ArtifactResolutionException e) {
are = e;
results = e.getResults();
}
result.setArtifactResults(results);
updateNodesWithResolvedArtifacts(results);
if (dce != null) {
throw new DependencyResolutionException(result, dce);
} else if (are != null) {
throw new DependencyResolutionException(result, are);
}
return result;
}
use of org.sonatype.aether.RequestTrace in project sonatype-aether by sonatype.
the class DefaultRepositorySystem method resolveDependencies.
public List<ArtifactResult> resolveDependencies(RepositorySystemSession session, DependencyNode node, DependencyFilter filter) throws ArtifactResolutionException {
validateSession(session);
RequestTrace trace = DefaultRequestTrace.newChild(null, node);
ArtifactRequestBuilder builder = new ArtifactRequestBuilder(trace);
DependencyVisitor visitor = (filter != null) ? new FilteringDependencyVisitor(builder, filter) : builder;
visitor = new TreeDependencyVisitor(visitor);
node.accept(visitor);
List<ArtifactRequest> requests = builder.getRequests();
try {
List<ArtifactResult> results = resolveArtifacts(session, requests);
updateNodesWithResolvedArtifacts(results);
return results;
} catch (ArtifactResolutionException e) {
updateNodesWithResolvedArtifacts(e.getResults());
throw e;
}
}
use of org.sonatype.aether.RequestTrace in project sonatype-aether by sonatype.
the class DefaultMetadataResolver method resolve.
private List<MetadataResult> resolve(RepositorySystemSession session, Collection<? extends MetadataRequest> requests) {
List<MetadataResult> results = new ArrayList<MetadataResult>(requests.size());
List<ResolveTask> tasks = new ArrayList<ResolveTask>(requests.size());
Map<File, Long> localLastUpdates = new HashMap<File, Long>();
for (MetadataRequest request : requests) {
RequestTrace trace = DefaultRequestTrace.newChild(request.getTrace(), request);
MetadataResult result = new MetadataResult(request);
results.add(result);
Metadata metadata = request.getMetadata();
RemoteRepository repository = request.getRepository();
if (repository == null) {
LocalRepository localRepo = session.getLocalRepositoryManager().getRepository();
metadataResolving(session, trace, metadata, localRepo);
File localFile = getLocalFile(session, metadata);
if (localFile != null) {
metadata = metadata.setFile(localFile);
result.setMetadata(metadata);
} else {
result.setException(new MetadataNotFoundException(metadata, localRepo));
}
metadataResolved(session, trace, metadata, localRepo, result.getException());
continue;
}
List<RemoteRepository> repositories = getEnabledSourceRepositories(repository, metadata.getNature());
if (repositories.isEmpty()) {
continue;
}
metadataResolving(session, trace, metadata, repository);
LocalRepositoryManager lrm = session.getLocalRepositoryManager();
LocalMetadataRequest localRequest = new LocalMetadataRequest(metadata, repository, request.getRequestContext());
LocalMetadataResult lrmResult = lrm.find(session, localRequest);
File metadataFile = lrmResult.getFile();
if (session.isOffline()) {
if (metadataFile != null) {
metadata = metadata.setFile(metadataFile);
result.setMetadata(metadata);
} else {
String msg = "The repository system is offline but the metadata " + metadata + " from " + repository + " is not available in the local repository.";
result.setException(new MetadataNotFoundException(metadata, repository, msg));
}
metadataResolved(session, trace, metadata, repository, result.getException());
continue;
}
Long localLastUpdate = null;
if (request.isFavorLocalRepository()) {
File localFile = getLocalFile(session, metadata);
localLastUpdate = localLastUpdates.get(localFile);
if (localLastUpdate == null) {
localLastUpdate = Long.valueOf(localFile != null ? localFile.lastModified() : 0);
localLastUpdates.put(localFile, localLastUpdate);
}
}
List<UpdateCheck<Metadata, MetadataTransferException>> checks = new ArrayList<UpdateCheck<Metadata, MetadataTransferException>>();
Exception exception = null;
for (RemoteRepository repo : repositories) {
UpdateCheck<Metadata, MetadataTransferException> check = new UpdateCheck<Metadata, MetadataTransferException>();
check.setLocalLastUpdated((localLastUpdate != null) ? localLastUpdate.longValue() : 0);
check.setItem(metadata);
// use 'main' installation file for the check (-> use requested repository)
File checkFile = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteMetadata(metadata, repository, request.getRequestContext()));
check.setFile(checkFile);
check.setRepository(repository);
check.setAuthoritativeRepository(repo);
check.setPolicy(getPolicy(session, repo, metadata.getNature()).getUpdatePolicy());
if (lrmResult.isStale()) {
checks.add(check);
} else {
updateCheckManager.checkMetadata(session, check);
if (check.isRequired()) {
checks.add(check);
} else if (exception == null) {
exception = check.getException();
}
}
}
if (!checks.isEmpty()) {
RepositoryPolicy policy = getPolicy(session, repository, metadata.getNature());
// install path may be different from lookup path
File installFile = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteMetadata(metadata, request.getRepository(), request.getRequestContext()));
ResolveTask task = new ResolveTask(session, trace, result, installFile, checks, policy.getChecksumPolicy());
tasks.add(task);
} else {
result.setException(exception);
if (metadataFile != null) {
metadata = metadata.setFile(metadataFile);
result.setMetadata(metadata);
}
metadataResolved(session, trace, metadata, repository, result.getException());
}
}
if (!tasks.isEmpty()) {
int threads = ConfigUtils.getInteger(session, 4, "aether.metadataResolver.threads");
Executor executor = getExecutor(Math.min(tasks.size(), threads));
try {
RunnableErrorForwarder errorForwarder = new RunnableErrorForwarder();
for (ResolveTask task : tasks) {
executor.execute(errorForwarder.wrap(task));
}
errorForwarder.await();
for (ResolveTask task : tasks) {
task.result.setException(task.exception);
}
} finally {
shutdown(executor);
}
for (ResolveTask task : tasks) {
Metadata metadata = task.request.getMetadata();
// re-lookup metadata for resolve
LocalMetadataRequest localRequest = new LocalMetadataRequest(metadata, task.request.getRepository(), task.request.getRequestContext());
File metadataFile = session.getLocalRepositoryManager().find(session, localRequest).getFile();
if (metadataFile != null) {
metadata = metadata.setFile(metadataFile);
task.result.setMetadata(metadata);
}
if (task.result.getException() == null) {
task.result.setUpdated(true);
}
metadataResolved(session, task.trace, metadata, task.request.getRepository(), task.result.getException());
}
}
return results;
}
Aggregations