Search in sources :

Example 6 with RepositoryException

use of org.sonatype.aether.RepositoryException in project sonatype-aether by sonatype.

the class DefaultDependencyCollector method collectDependencies.

public CollectResult collectDependencies(RepositorySystemSession session, CollectRequest request) throws DependencyCollectionException {
    session = optimizeSession(session);
    RequestTrace trace = DefaultRequestTrace.newChild(request.getTrace(), request);
    CollectResult result = new CollectResult(request);
    DependencySelector depSelector = session.getDependencySelector();
    DependencyManager depManager = session.getDependencyManager();
    DependencyTraverser depTraverser = session.getDependencyTraverser();
    Dependency root = request.getRoot();
    List<RemoteRepository> repositories = request.getRepositories();
    List<Dependency> dependencies = request.getDependencies();
    List<Dependency> managedDependencies = request.getManagedDependencies();
    GraphEdge edge = null;
    if (root != null) {
        VersionRangeResult rangeResult;
        try {
            VersionRangeRequest rangeRequest = new VersionRangeRequest(root.getArtifact(), request.getRepositories(), request.getRequestContext());
            rangeRequest.setTrace(trace);
            rangeResult = versionRangeResolver.resolveVersionRange(session, rangeRequest);
            if (rangeResult.getVersions().isEmpty()) {
                throw new VersionRangeResolutionException(rangeResult, "No versions available for " + root.getArtifact() + " within specified range");
            }
        } catch (VersionRangeResolutionException e) {
            result.addException(e);
            throw new DependencyCollectionException(result);
        }
        Version version = rangeResult.getVersions().get(rangeResult.getVersions().size() - 1);
        root = root.setArtifact(root.getArtifact().setVersion(version.toString()));
        ArtifactDescriptorResult descriptorResult;
        try {
            ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
            descriptorRequest.setArtifact(root.getArtifact());
            descriptorRequest.setRepositories(request.getRepositories());
            descriptorRequest.setRequestContext(request.getRequestContext());
            descriptorRequest.setTrace(trace);
            if (isLackingDescriptor(root.getArtifact())) {
                descriptorResult = new ArtifactDescriptorResult(descriptorRequest);
            } else {
                descriptorResult = descriptorReader.readArtifactDescriptor(session, descriptorRequest);
            }
        } catch (ArtifactDescriptorException e) {
            result.addException(e);
            throw new DependencyCollectionException(result);
        }
        root = root.setArtifact(descriptorResult.getArtifact());
        repositories = remoteRepositoryManager.aggregateRepositories(session, repositories, descriptorResult.getRepositories(), true);
        dependencies = mergeDeps(dependencies, descriptorResult.getDependencies());
        managedDependencies = mergeDeps(managedDependencies, descriptorResult.getManagedDependencies());
        GraphNode node = new GraphNode();
        node.setAliases(descriptorResult.getAliases());
        node.setRepositories(request.getRepositories());
        edge = new GraphEdge(node);
        edge.setDependency(root);
        edge.setRequestContext(request.getRequestContext());
        edge.setRelocations(descriptorResult.getRelocations());
        edge.setVersionConstraint(rangeResult.getVersionConstraint());
        edge.setVersion(version);
    } else {
        edge = new GraphEdge(new GraphNode());
    }
    result.setRoot(edge);
    boolean traverse = (root == null) || depTraverser.traverseDependency(root);
    if (traverse && !dependencies.isEmpty()) {
        DataPool pool = new DataPool(session);
        EdgeStack edges = new EdgeStack();
        edges.push(edge);
        DefaultDependencyCollectionContext context = new DefaultDependencyCollectionContext(session, root, managedDependencies);
        Args args = new Args(result, session, trace, pool, edges, context);
        process(args, dependencies, repositories, depSelector.deriveChildSelector(context), depManager.deriveChildManager(context), depTraverser.deriveChildTraverser(context));
    }
    DependencyGraphTransformer transformer = session.getDependencyGraphTransformer();
    try {
        DefaultDependencyGraphTransformationContext context = new DefaultDependencyGraphTransformationContext(session);
        result.setRoot(transformer.transformGraph(edge, context));
    } catch (RepositoryException e) {
        result.addException(e);
    }
    if (!result.getExceptions().isEmpty()) {
        throw new DependencyCollectionException(result);
    }
    return result;
}
Also used : DependencyManager(org.sonatype.aether.collection.DependencyManager) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) RequestTrace(org.sonatype.aether.RequestTrace) DefaultRequestTrace(org.sonatype.aether.util.DefaultRequestTrace) DependencyTraverser(org.sonatype.aether.collection.DependencyTraverser) Version(org.sonatype.aether.version.Version) DependencyGraphTransformer(org.sonatype.aether.collection.DependencyGraphTransformer) VersionRangeRequest(org.sonatype.aether.resolution.VersionRangeRequest) ArtifactDescriptorRequest(org.sonatype.aether.resolution.ArtifactDescriptorRequest) VersionRangeResolutionException(org.sonatype.aether.resolution.VersionRangeResolutionException) DependencyCollectionException(org.sonatype.aether.collection.DependencyCollectionException) VersionRangeResult(org.sonatype.aether.resolution.VersionRangeResult) CollectResult(org.sonatype.aether.collection.CollectResult) RepositoryException(org.sonatype.aether.RepositoryException) Dependency(org.sonatype.aether.graph.Dependency) DependencySelector(org.sonatype.aether.collection.DependencySelector) ArtifactDescriptorResult(org.sonatype.aether.resolution.ArtifactDescriptorResult) ArtifactDescriptorException(org.sonatype.aether.resolution.ArtifactDescriptorException)

Example 7 with RepositoryException

use of org.sonatype.aether.RepositoryException in project sonatype-aether by sonatype.

the class DefaultDeployer method upload.

private void upload(Collection<MetadataUpload> metadataUploads, RepositorySystemSession session, Metadata metadata, RemoteRepository repository, RepositoryConnector connector, EventCatapult catapult) throws DeploymentException {
    LocalRepositoryManager lrm = session.getLocalRepositoryManager();
    File basedir = lrm.getRepository().getBasedir();
    File dstFile = new File(basedir, lrm.getPathForRemoteMetadata(metadata, repository, ""));
    if (metadata instanceof MergeableMetadata) {
        if (!((MergeableMetadata) metadata).isMerged()) {
            {
                DefaultRepositoryEvent event = new DefaultRepositoryEvent(EventType.METADATA_RESOLVING, session, catapult.getTrace());
                event.setMetadata(metadata);
                event.setRepository(repository);
                repositoryEventDispatcher.dispatch(event);
                event = new DefaultRepositoryEvent(EventType.METADATA_DOWNLOADING, session, catapult.getTrace());
                event.setMetadata(metadata);
                event.setRepository(repository);
                repositoryEventDispatcher.dispatch(event);
            }
            RepositoryPolicy policy = getPolicy(session, repository, metadata.getNature());
            MetadataDownload download = new MetadataDownload();
            download.setMetadata(metadata);
            download.setFile(dstFile);
            download.setChecksumPolicy(policy.getChecksumPolicy());
            connector.get(null, Arrays.asList(download));
            Exception error = download.getException();
            if (error instanceof MetadataNotFoundException) {
                dstFile.delete();
            }
            {
                DefaultRepositoryEvent event = new DefaultRepositoryEvent(EventType.METADATA_DOWNLOADED, session, catapult.getTrace());
                event.setMetadata(metadata);
                event.setRepository(repository);
                event.setException(error);
                event.setFile(dstFile);
                repositoryEventDispatcher.dispatch(event);
                event = new DefaultRepositoryEvent(EventType.METADATA_RESOLVED, session, catapult.getTrace());
                event.setMetadata(metadata);
                event.setRepository(repository);
                event.setException(error);
                event.setFile(dstFile);
                repositoryEventDispatcher.dispatch(event);
            }
            if (error != null && !(error instanceof MetadataNotFoundException)) {
                throw new DeploymentException("Failed to retrieve remote metadata " + metadata + ": " + error.getMessage(), error);
            }
        }
        try {
            ((MergeableMetadata) metadata).merge(dstFile, dstFile);
        } catch (RepositoryException e) {
            throw new DeploymentException("Failed to update metadata " + metadata + ": " + e.getMessage(), e);
        }
    } else {
        if (metadata.getFile() == null) {
            throw new DeploymentException("Failed to update metadata " + metadata + ": No file attached.");
        }
        try {
            fileProcessor.copy(metadata.getFile(), dstFile, null);
        } catch (IOException e) {
            throw new DeploymentException("Failed to update metadata " + metadata + ": " + e.getMessage(), e);
        }
    }
    UpdateCheck<Metadata, MetadataTransferException> check = new UpdateCheck<Metadata, MetadataTransferException>();
    check.setItem(metadata);
    check.setFile(dstFile);
    check.setRepository(repository);
    check.setAuthoritativeRepository(repository);
    updateCheckManager.touchMetadata(session, check);
    metadataUploads.add(new MetadataUploadEx(metadata, dstFile, catapult));
}
Also used : RepositoryPolicy(org.sonatype.aether.repository.RepositoryPolicy) MergeableMetadata(org.sonatype.aether.metadata.MergeableMetadata) MergeableMetadata(org.sonatype.aether.metadata.MergeableMetadata) Metadata(org.sonatype.aether.metadata.Metadata) RepositoryException(org.sonatype.aether.RepositoryException) IOException(java.io.IOException) MetadataNotFoundException(org.sonatype.aether.transfer.MetadataNotFoundException) DeploymentException(org.sonatype.aether.deployment.DeploymentException) NoRepositoryConnectorException(org.sonatype.aether.transfer.NoRepositoryConnectorException) ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) RepositoryException(org.sonatype.aether.RepositoryException) IOException(java.io.IOException) MetadataTransferException(org.sonatype.aether.transfer.MetadataTransferException) DefaultRepositoryEvent(org.sonatype.aether.util.listener.DefaultRepositoryEvent) MetadataNotFoundException(org.sonatype.aether.transfer.MetadataNotFoundException) UpdateCheck(org.sonatype.aether.impl.UpdateCheck) LocalRepositoryManager(org.sonatype.aether.repository.LocalRepositoryManager) MetadataTransferException(org.sonatype.aether.transfer.MetadataTransferException) DeploymentException(org.sonatype.aether.deployment.DeploymentException) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) File(java.io.File)

Aggregations

RepositoryException (org.sonatype.aether.RepositoryException)7 File (java.io.File)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)2 Artifact (org.sonatype.aether.artifact.Artifact)2 Dependency (org.sonatype.aether.graph.Dependency)2 MergeableMetadata (org.sonatype.aether.metadata.MergeableMetadata)2 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)2 MetadataDownload (org.sonatype.aether.spi.connector.MetadataDownload)2 MetadataNotFoundException (org.sonatype.aether.transfer.MetadataNotFoundException)2 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)2 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 DependencyResolver (org.apache.zeppelin.dep.DependencyResolver)1 GradleException (org.gradle.api.GradleException)1 Test (org.junit.Test)1 RequestTrace (org.sonatype.aether.RequestTrace)1