use of org.eclipse.aether.repository.RemoteRepository in project fabric8-maven-plugin by fabric8io.
the class AbstractArtifactSearchMojo method resolveArtifactFile.
protected File resolveArtifactFile(HelmIndexMojo.ArtifactDTO artifactDTO, String classifier, String extension) {
File file = null;
try {
ArtifactRequest artifactRequest = new ArtifactRequest();
org.eclipse.aether.artifact.Artifact artifact = new DefaultArtifact(artifactDTO.getG(), artifactDTO.getA(), classifier, extension, artifactDTO.getV());
artifactRequest.setArtifact(artifact);
// convert maven remote repositories to Aether repos
List<RemoteRepository> aetherRepoList = new ArrayList<>();
for (MavenArtifactRepository remoteRepository : remoteRepositories) {
RemoteRepository.Builder builder = new RemoteRepository.Builder(remoteRepository.getId(), remoteRepository.getLayout().getId(), remoteRepository.getUrl());
RemoteRepository aetherRepo = builder.build();
aetherRepoList.add(aetherRepo);
}
artifactRequest.setRepositories(aetherRepoList);
ArtifactResult artifactResult = artifactResolver.resolveArtifact(repoSession, artifactRequest);
org.eclipse.aether.artifact.Artifact resolvedArtifact = artifactResult.getArtifact();
if (resolvedArtifact == null) {
getLog().warn("Could not resolve artifact " + artifactDTO.description());
return null;
}
file = resolvedArtifact.getFile();
} catch (Exception e) {
getLog().warn("Failed to resolve manifest manifest for " + artifactDTO.description() + ". " + e, e);
return null;
}
if (file == null) {
getLog().warn("Could not resolve artifact file for " + artifactDTO.description());
return null;
}
if (!file.isFile() || !file.exists()) {
getLog().warn("Resolved artifact file does not exist for " + artifactDTO.description());
return null;
}
return file;
}
use of org.eclipse.aether.repository.RemoteRepository in project acceptance-test-harness by jenkinsci.
the class ArtifactResolverUtil method resolve.
/**
* @param artifact The artifact to be resolved
*
* @return artifact resolution result
*/
public ArtifactResult resolve(DefaultArtifact artifact) {
Builder repoBuilder = new RemoteRepository.Builder("repo.jenkins-ci.org", "default", "http://repo.jenkins-ci.org/public/");
DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
File userHome = new File(System.getProperty("user.home"));
File userSettingsFile = new File(new File(userHome, ".m2"), "settings.xml");
request.setUserSettingsFile(userSettingsFile);
if (userSettingsFile.exists()) {
LOGGER.debug("Found maven settings file - " + userSettingsFile.getAbsolutePath());
SettingsBuilder settingsBuilder = new DefaultSettingsBuilderFactory().newInstance();
try {
Settings settings = settingsBuilder.build(request).getEffectiveSettings();
org.apache.maven.settings.Proxy mavenActiveproxy = settings.getActiveProxy();
if (mavenActiveproxy != null) {
LOGGER.debug("Found maven proxy settings. Will use for artifact resolution");
repoBuilder.setProxy(asProxy(mavenActiveproxy));
} else {
LOGGER.debug("Did not find an active proxy in maven settings xml file");
}
} catch (SettingsBuildingException e) {
LOGGER.warn("Could not find or load settings.xml to attempt to user proxy settings.", e);
}
}
RemoteRepository repo = repoBuilder.build();
ArtifactResult r;
try {
r = repoSystem.resolveArtifact(repoSystemSession, new ArtifactRequest(artifact, Arrays.asList(repo), null));
} catch (ArtifactResolutionException e) {
throw new RuntimeException("Could not resolve " + artifact + " from Maven repository", e);
}
LOGGER.debug("Found " + r);
return r;
}
use of org.eclipse.aether.repository.RemoteRepository in project wildfly-swarm by wildfly-swarm.
the class MavenArtifactResolvingHelper method buildRemoteRepository.
private RemoteRepository buildRemoteRepository(final String id, final String url, final Authentication auth, final ArtifactRepositoryPolicy releasesPolicy, final ArtifactRepositoryPolicy snapshotsPolicy) {
RemoteRepository.Builder builder = new RemoteRepository.Builder(id, "default", url);
if (auth != null && auth.getUsername() != null && auth.getPassword() != null) {
builder.setAuthentication(new AuthenticationBuilder().addUsername(auth.getUsername()).addPassword(auth.getPassword()).build());
}
builder.setSnapshotPolicy(new RepositoryPolicy(snapshotsPolicy.isEnabled(), snapshotsPolicy.getUpdatePolicy(), snapshotsPolicy.getChecksumPolicy()));
builder.setReleasePolicy(new RepositoryPolicy(releasesPolicy.isEnabled(), releasesPolicy.getUpdatePolicy(), releasesPolicy.getChecksumPolicy()));
RemoteRepository repository = builder.build();
final RemoteRepository mirror = session.getMirrorSelector().getMirror(repository);
if (mirror != null) {
final org.eclipse.aether.repository.Authentication mirrorAuth = session.getAuthenticationSelector().getAuthentication(mirror);
RemoteRepository.Builder mirrorBuilder = new RemoteRepository.Builder(mirror).setId(repository.getId()).setSnapshotPolicy(new RepositoryPolicy(snapshotsPolicy.isEnabled(), snapshotsPolicy.getUpdatePolicy(), snapshotsPolicy.getChecksumPolicy())).setReleasePolicy(new RepositoryPolicy(releasesPolicy.isEnabled(), releasesPolicy.getUpdatePolicy(), releasesPolicy.getChecksumPolicy()));
if (mirrorAuth != null) {
mirrorBuilder.setAuthentication(mirrorAuth);
}
repository = mirrorBuilder.build();
}
Proxy proxy = session.getProxySelector().getProxy(repository);
if (proxy != null) {
repository = new RemoteRepository.Builder(repository).setProxy(proxy).build();
}
return repository;
}
use of org.eclipse.aether.repository.RemoteRepository in project build-info by JFrogDev.
the class ArtifactoryEclipseResolversHelper method getResolutionRepositories.
/**
* Create a list containing one release and one snapshot resolution repositories, according to the configuration in the Artifactory plugin.
* The list is used to override Maven's default or configured repositories, so that the build dependencies are resolved from Artifactory.
* The list is saved and reused for further invokations to this method.
* @param session
* @return
*/
public List<RemoteRepository> getResolutionRepositories(RepositorySystemSession session) {
if (resolutionRepositories == null) {
Properties allMavenProps = new Properties();
allMavenProps.putAll(session.getSystemProperties());
allMavenProps.putAll(session.getUserProperties());
resolutionHelper.init(allMavenProps);
String releaseRepoUrl = resolutionHelper.getRepoReleaseUrl();
String snapshotRepoUrl = resolutionHelper.getRepoSnapshotUrl();
Authentication authentication = null;
if (StringUtils.isNotBlank(resolutionHelper.getRepoUsername())) {
authentication = new AuthenticationBuilder().addString("username", resolutionHelper.getRepoUsername()).addSecret("password", resolutionHelper.getRepoPassword()).build();
}
Proxy proxy = null;
if (StringUtils.isNotBlank(resolutionHelper.getProxyHost())) {
Authentication auth = new AuthenticationBuilder().addString("username", resolutionHelper.getProxyUsername()).addSecret("password", resolutionHelper.getProxyPassword()).build();
proxy = new Proxy(null, resolutionHelper.getProxyHost(), resolutionHelper.getProxyPort(), auth);
}
if (StringUtils.isNotBlank(snapshotRepoUrl)) {
logger.debug("[buildinfo] Enforcing snapshot repository for resolution: " + snapshotRepoUrl);
RepositoryPolicy releasePolicy = new RepositoryPolicy(false, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
RepositoryPolicy snapshotPolicy = new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
RemoteRepository.Builder builder = new RemoteRepository.Builder("artifactory-snapshot", "default", snapshotRepoUrl);
builder.setReleasePolicy(releasePolicy);
builder.setSnapshotPolicy(snapshotPolicy);
if (authentication != null) {
logger.debug("[buildinfo] Enforcing repository authentication: " + authentication + " for snapshot resolution repository");
builder.setAuthentication(authentication);
}
if (proxy != null) {
logger.debug("[buildinfo] Enforcing proxy: " + proxy + " for snapshot resolution repository");
builder.setProxy(proxy);
}
snapshotRepository = builder.build();
}
if (StringUtils.isNotBlank(releaseRepoUrl)) {
logger.debug("[buildinfo] Enforcing release repository for resolution: " + releaseRepoUrl);
boolean snapshotPolicyEnabled = snapshotRepository == null;
String repositoryId = snapshotPolicyEnabled ? "artifactory-release-snapshot" : "artifactory-release";
RepositoryPolicy releasePolicy = new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
RepositoryPolicy snapshotPolicy = new RepositoryPolicy(snapshotPolicyEnabled, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
RemoteRepository.Builder builder = new RemoteRepository.Builder(repositoryId, "default", releaseRepoUrl);
builder.setReleasePolicy(releasePolicy);
builder.setSnapshotPolicy(snapshotPolicy);
if (authentication != null) {
logger.debug("[buildinfo] Enforcing repository authentication: " + authentication + " for release resolution repository");
builder.setAuthentication(authentication);
}
if (proxy != null) {
logger.debug("[buildinfo] Enforcing proxy: " + proxy + " for release resolution repository");
builder.setProxy(proxy);
}
releaseRepository = builder.build();
}
List<RemoteRepository> tempRepositories = Lists.newArrayList();
if (releaseRepository != null) {
tempRepositories.add(releaseRepository);
}
if (snapshotRepository != null) {
tempRepositories.add(snapshotRepository);
}
resolutionRepositories = tempRepositories;
}
return resolutionRepositories;
}
use of org.eclipse.aether.repository.RemoteRepository in project gate-core by GateNLP.
the class SimpleMavenCache method cacheArtifact.
public void cacheArtifact(Artifact artifact) throws IOException, SettingsBuildingException, DependencyCollectionException, DependencyResolutionException, ArtifactResolutionException, ModelBuildingException {
List<RemoteRepository> repos = getRepositoryList();
Dependency dependency = new Dependency(artifact, "runtime");
RepositorySystem repoSystem = getRepositorySystem();
RepositorySystemSession repoSession = getRepositorySession(repoSystem, null);
CollectRequest collectRequest = new CollectRequest(dependency, repos);
DependencyNode node = repoSystem.collectDependencies(repoSession, collectRequest).getRoot();
DependencyRequest dependencyRequest = new DependencyRequest();
dependencyRequest.setRoot(node);
DependencyResult result = repoSystem.resolveDependencies(repoSession, dependencyRequest);
for (ArtifactResult ar : result.getArtifactResults()) {
// generate output file name from the *requested* artifact rather
// than the resolved one (e.g. if we requested a -SNAPSHOT version
// but got a timestamped one)
File file = getArtifactFile(ar.getRequest().getArtifact());
FileUtils.copyFile(ar.getArtifact().getFile(), file);
// get the POM corresponding to the specific resolved JAR
Artifact pomArtifact = new SubArtifact(ar.getArtifact(), "", "pom");
ArtifactRequest artifactRequest = new ArtifactRequest(pomArtifact, repos, null);
ArtifactResult artifactResult = repoSystem.resolveArtifact(repoSession, artifactRequest);
// but copy it to a file named for the original requested version number
file = getArtifactFile(new SubArtifact(ar.getRequest().getArtifact(), "", "pom"));
FileUtils.copyFile(artifactResult.getArtifact().getFile(), file);
cacheParents(artifactResult.getArtifact().getFile(), repoSystem, repoSession, repos);
}
}
Aggregations