All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.itemis.maven.aether.ArtifactCacheLoader Maven / Gradle / Ivy

Go to download

This plugin provides a generic alternative to the error-prone default release plugin provided by Maven. It is designed to require a minimal effort of work for releasing modules and being extensible to integrate in every project setup.

There is a newer version: 2.10.0
Show newest version
package com.itemis.maven.aether;

import java.util.List;

import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactRequest;
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.aether.resolution.ArtifactResult;

import com.google.common.base.Optional;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.itemis.maven.plugins.cdi.logging.Logger;

/**
 * A loader strategy that can be used by a {@link LoadingCache} which caches {@link ArtifactResult ArtifactResults}
 * identified by {@link ArtifactCoordinates} during a resolution process.
* This loader retrieves the results by explicitly querying the repositories for an artifact with the specified * coordinates. * * @author Stanley Hillner * @since 1.0.0 */ class ArtifactCacheLoader extends CacheLoader> { private RepositorySystem repoSystem; private RepositorySystemSession repoSession; private List remoteProjectRepos; private Logger log; public ArtifactCacheLoader(RepositorySystem repoSystem, RepositorySystemSession repoSession, List remoteProjectRepos, Logger log) { this.repoSystem = repoSystem; this.repoSession = repoSession; this.remoteProjectRepos = remoteProjectRepos; this.log = log; } @Override public Optional load(ArtifactCoordinates coordinates) throws Exception { Artifact artifact = new DefaultArtifact(coordinates.toString()); ArtifactRequest artifactRequest = new ArtifactRequest(); artifactRequest.setArtifact(artifact); artifactRequest.setRepositories(this.remoteProjectRepos); ArtifactResult artifactResult; try { artifactResult = this.repoSystem.resolveArtifact(this.repoSession, artifactRequest); } catch (ArtifactResolutionException e) { // must not throw the error or log as an error since this is an expected behavior artifactResult = null; } return Optional.fromNullable(artifactResult); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy