Search in sources :

Example 1 with LocalArtifactRequest

use of org.eclipse.aether.repository.LocalArtifactRequest in project wildfly-swarm by wildfly-swarm.

the class MavenArtifactResolvingHelper method resolve.

@Override
public ArtifactSpec resolve(ArtifactSpec spec) {
    if (spec.file == null) {
        final DefaultArtifact artifact = new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(), spec.type(), spec.version());
        final LocalArtifactResult localResult = this.session.getLocalRepositoryManager().find(this.session, new LocalArtifactRequest(artifact, this.remoteRepositories, null));
        if (localResult.isAvailable()) {
            spec.file = localResult.getFile();
        } else {
            try {
                final ArtifactResult result = resolver.resolveArtifact(this.session, new ArtifactRequest(artifact, this.remoteRepositories, null));
                if (result.isResolved()) {
                    spec.file = result.getArtifact().getFile();
                }
            } catch (ArtifactResolutionException e) {
                e.printStackTrace();
            }
        }
    }
    return spec.file != null ? spec : null;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) LocalArtifactRequest(org.eclipse.aether.repository.LocalArtifactRequest) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) LocalArtifactResult(org.eclipse.aether.repository.LocalArtifactResult) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) LocalArtifactRequest(org.eclipse.aether.repository.LocalArtifactRequest) LocalArtifactResult(org.eclipse.aether.repository.LocalArtifactResult) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 2 with LocalArtifactRequest

use of org.eclipse.aether.repository.LocalArtifactRequest in project revapi by revapi.

the class ArtifactResolver method makeRemoteOnly.

private RepositorySystemSession makeRemoteOnly(RepositorySystemSession session) {
    return new AbstractForwardingRepositorySystemSession() {

        @Override
        protected RepositorySystemSession getSession() {
            return session;
        }

        @Override
        public WorkspaceReader getWorkspaceReader() {
            return null;
        }

        @Override
        public LocalRepositoryManager getLocalRepositoryManager() {
            LocalRepositoryManager wrapped = session.getLocalRepositoryManager();
            return new LocalRepositoryManager() {

                @Override
                public LocalRepository getRepository() {
                    return wrapped.getRepository();
                }

                @Override
                public String getPathForLocalArtifact(Artifact artifact) {
                    return wrapped.getPathForLocalArtifact(artifact);
                }

                @Override
                public String getPathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context) {
                    return wrapped.getPathForRemoteArtifact(artifact, repository, context);
                }

                @Override
                public String getPathForLocalMetadata(Metadata metadata) {
                    return wrapped.getPathForLocalMetadata(metadata);
                }

                @Override
                public String getPathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context) {
                    return wrapped.getPathForRemoteMetadata(metadata, repository, context);
                }

                @Override
                public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request) {
                    return wrapped.find(session, request);
                }

                @Override
                public void add(RepositorySystemSession session, LocalArtifactRegistration request) {
                    wrapped.add(session, request);
                }

                @Override
                public LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request) {
                    if (request.getRepository() == null) {
                        // local metadata request... the returned file must not be null but may not exist
                        // we exploit that to not include the locally built results
                        LocalMetadataResult ret = new LocalMetadataResult(request);
                        ret.setFile(new File("<faked-to-force-remote-only-resolution-of-artifacts>"));
                        return ret;
                    } else {
                        return wrapped.find(session, request);
                    }
                }

                @Override
                public void add(RepositorySystemSession session, LocalMetadataRegistration request) {
                    wrapped.add(session, request);
                }
            };
        }
    };
}
Also used : AbstractForwardingRepositorySystemSession(org.eclipse.aether.AbstractForwardingRepositorySystemSession) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) LocalArtifactRegistration(org.eclipse.aether.repository.LocalArtifactRegistration) LocalMetadataRequest(org.eclipse.aether.repository.LocalMetadataRequest) LocalMetadataRegistration(org.eclipse.aether.repository.LocalMetadataRegistration) Metadata(org.eclipse.aether.metadata.Metadata) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) LocalRepositoryManager(org.eclipse.aether.repository.LocalRepositoryManager) LocalMetadataResult(org.eclipse.aether.repository.LocalMetadataResult) AbstractForwardingRepositorySystemSession(org.eclipse.aether.AbstractForwardingRepositorySystemSession) File(java.io.File) LocalArtifactRequest(org.eclipse.aether.repository.LocalArtifactRequest)

Aggregations

DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)2 LocalArtifactRequest (org.eclipse.aether.repository.LocalArtifactRequest)2 File (java.io.File)1 AbstractForwardingRepositorySystemSession (org.eclipse.aether.AbstractForwardingRepositorySystemSession)1 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)1 Artifact (org.eclipse.aether.artifact.Artifact)1 Metadata (org.eclipse.aether.metadata.Metadata)1 LocalArtifactRegistration (org.eclipse.aether.repository.LocalArtifactRegistration)1 LocalArtifactResult (org.eclipse.aether.repository.LocalArtifactResult)1 LocalMetadataRegistration (org.eclipse.aether.repository.LocalMetadataRegistration)1 LocalMetadataRequest (org.eclipse.aether.repository.LocalMetadataRequest)1 LocalMetadataResult (org.eclipse.aether.repository.LocalMetadataResult)1 LocalRepositoryManager (org.eclipse.aether.repository.LocalRepositoryManager)1 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)1 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)1 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)1 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)1