Search in sources :

Example 21 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project bnd by bndtools.

the class RemotePostProcessor method postProcessRelease.

private ArtifactResult postProcessRelease(ArtifactRequest request, Artifact artifact) throws MojoExecutionException {
    for (RemoteRepository repository : request.getRepositories()) {
        if (!repository.getPolicy(false).isEnabled()) {
            // Skip the repo if it isn't enabled for releases
            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(), null, "maven-metadata.xml", RELEASE));
        for (MetadataResult metadataResult : system.resolveMetadata(newSession, singletonList(mr))) {
            if (metadataResult.isResolved()) {
                try {
                    Metadata read = metadataReader.read(metadataResult.getMetadata().getFile(), null);
                    Versioning versioning = read.getVersioning();
                    if (versioning == null || versioning.getVersions() == null || versioning.getVersions().isEmpty()) {
                        continue;
                    } else if (versioning.getVersions().contains(artifact.getVersion())) {
                        ArtifactResult result = system.resolveArtifact(newSession, new ArtifactRequest().setArtifact(artifact).addRepository(repository));
                        if (result.isResolved()) {
                            File toUse = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForLocalArtifact(artifact));
                            if (!toUse.exists()) {
                                logger.warn("The resolved artifact {} does not exist at {}", artifact, toUse);
                                continue;
                            } else {
                                logger.debug("Located snapshot file {} for artifact {}", toUse, artifact);
                            }
                            result.getArtifact().setFile(toUse);
                            return result;
                        }
                    }
                } catch (Exception e) {
                    throw new MojoExecutionException("Unable to read project metadata for " + artifact, e);
                }
            }
        }
    }
    logger.debug("Unable to resolve a remote repository containing {}", artifact);
    return null;
}
Also used : Versioning(org.apache.maven.artifact.repository.metadata.Versioning) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MetadataRequest(org.eclipse.aether.resolution.MetadataRequest) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultMetadata(org.eclipse.aether.metadata.DefaultMetadata) DefaultMetadata(org.eclipse.aether.metadata.DefaultMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) File(java.io.File) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MetadataResult(org.eclipse.aether.resolution.MetadataResult) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Aggregations

RemoteRepository (org.eclipse.aether.repository.RemoteRepository)21 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)7 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)7 File (java.io.File)5 Artifact (org.eclipse.aether.artifact.Artifact)5 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)5 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)5 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)4 ArrayList (java.util.ArrayList)3 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)3 RepositorySystem (org.eclipse.aether.RepositorySystem)3 Dependency (org.eclipse.aether.graph.Dependency)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)2 Versioning (org.apache.maven.artifact.repository.metadata.Versioning)2 DefaultArtifactResolver (org.eclipse.aether.internal.impl.DefaultArtifactResolver)2 DefaultRepositorySystem (org.eclipse.aether.internal.impl.DefaultRepositorySystem)2