use of org.eclipse.aether.repository.RemoteRepository in project drools by kiegroup.
the class MavenRepository method resolveArtifact.
public Artifact resolveArtifact(String artifactName, boolean logUnresolvedArtifact) {
Artifact artifact = new DefaultArtifact(artifactName);
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(artifact);
for (RemoteRepository repo : remoteRepositoriesForRequest) {
artifactRequest.addRepository(repo);
}
RepositorySystemSession session = aether.getSession();
Object sessionChecks = null;
boolean isSnapshot = artifactName.endsWith("-SNAPSHOT");
if (artifactName.endsWith("-SNAPSHOT")) {
// ensure to always update snapshots
sessionChecks = session.getData().get(SESSION_CHECKS);
session.getData().set(SESSION_CHECKS, null);
}
try {
ArtifactResult artifactResult = aether.getSystem().resolveArtifact(session, artifactRequest);
return artifactResult.getArtifact();
} catch (ArtifactResolutionException e) {
if (logUnresolvedArtifact) {
if (log.isDebugEnabled()) {
log.debug("Unable to resolve artifact: " + artifactName, e);
} else {
log.warn("Unable to resolve artifact: " + artifactName);
}
}
return null;
} finally {
if (sessionChecks != null) {
session.getData().set(SESSION_CHECKS, sessionChecks);
}
}
}
use of org.eclipse.aether.repository.RemoteRepository in project drools by kiegroup.
the class MavenRepository method initRemoteRepositoriesForRequest.
private Collection<RemoteRepository> initRemoteRepositoriesForRequest() {
final MavenRepositoryConfiguration repositoryUtils = getMavenRepositoryConfiguration();
Collection<RemoteRepository> remoteRepos = new HashSet<RemoteRepository>();
remoteRepos.addAll(repositoryUtils.getRemoteRepositoriesForRequest());
for (RemoteRepository repo : aether.getRepositories()) {
remoteRepos.add(repositoryUtils.resolveMirroredRepo(repo));
}
return remoteRepos;
}
use of org.eclipse.aether.repository.RemoteRepository in project drools by kiegroup.
the class MavenRepository method getRemoteRepositoryFromDistributionManagement.
protected RemoteRepository getRemoteRepositoryFromDistributionManagement(File pomfile) {
MavenProject mavenProject = parseMavenPom(pomfile);
DistributionManagement distMan = mavenProject.getDistributionManagement();
if (distMan == null) {
return null;
}
DeploymentRepository deployRepo = distMan.getSnapshotRepository() != null && mavenProject.getVersion().endsWith("SNAPSHOT") ? distMan.getSnapshotRepository() : distMan.getRepository();
if (deployRepo == null) {
return null;
}
RemoteRepository.Builder remoteRepoBuilder = new RemoteRepository.Builder(deployRepo.getId(), deployRepo.getLayout(), deployRepo.getUrl()).setSnapshotPolicy(new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN)).setReleasePolicy(new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_ALWAYS, RepositoryPolicy.CHECKSUM_POLICY_WARN));
Server server = MavenSettings.getSettings().getServer(deployRepo.getId());
if (server != null) {
MavenEmbedder embedder = MavenProjectLoader.newMavenEmbedder(false);
try {
Authentication authentication = embedder.getMavenSession().getRepositorySession().getAuthenticationSelector().getAuthentication(remoteRepoBuilder.build());
remoteRepoBuilder.setAuthentication(authentication);
} finally {
embedder.dispose();
}
}
return remoteRepoBuilder.build();
}
use of org.eclipse.aether.repository.RemoteRepository in project mule by mulesoft.
the class AetherClassPathClassifier method buildPluginUrlClassification.
/**
* Classifies an {@link Artifact} recursively. {@value org.eclipse.aether.util.artifact.JavaScopes#COMPILE} dependencies will be
* resolved for building the {@link URL}'s for the class loader. Once classified the node is added to {@link Map} of
* artifactsClassified.
*
* @param artifactToClassify {@link Artifact} that represents the artifact to be classified
* @param context {@link ClassPathClassifierContext} with settings for the classification process
* @param artifactsClassified {@link Map} that contains already classified plugins
* @param rootArtifactRemoteRepositories remote repositories defined at the root artifact.
*/
private void buildPluginUrlClassification(Artifact artifactToClassify, ClassPathClassifierContext context, Predicate<Dependency> directDependenciesFilter, Set<ArtifactClassificationNode> artifactsClassified, List<RemoteRepository> rootArtifactRemoteRepositories) {
List<URL> urls;
try {
final DependencyFilter dependencyFilter = andFilter(classpathFilter(COMPILE), new PatternExclusionsDependencyFilter(context.getExcludedArtifacts()), orFilter(new PatternExclusionsDependencyFilter("*:*:*:" + MULE_PLUGIN_CLASSIFIER + ":*"), new PatternInclusionsDependencyFilter(toId(artifactToClassify))));
urls = toUrl(dependencyResolver.resolveDependencies(new Dependency(artifactToClassify, COMPILE), emptyList(), emptyList(), dependencyFilter, rootArtifactRemoteRepositories));
} catch (Exception e) {
throw new IllegalStateException("Couldn't resolve dependencies for artifact: '" + artifactToClassify + "' classification", e);
}
List<Dependency> directDependencies;
List<ArtifactClassificationNode> artifactDependencies = newArrayList();
try {
directDependencies = dependencyResolver.getDirectDependencies(artifactToClassify, rootArtifactRemoteRepositories);
} catch (ArtifactDescriptorException e) {
throw new IllegalStateException("Couldn't get direct dependencies for artifact: '" + artifactToClassify + "'", e);
}
logger.debug("Searching for dependencies on direct dependencies of artifact {}", artifactToClassify);
List<Artifact> pluginArtifactDependencies = filterArtifacts(directDependencies, directDependenciesFilter);
logger.debug("Artifacts {} identified a plugin dependencies for plugin {}", pluginArtifactDependencies, artifactToClassify);
pluginArtifactDependencies.stream().map(artifact -> {
Optional<ArtifactClassificationNode> artifactClassificationNodeOptional = findArtifactClassified(artifactsClassified, artifact);
if (!artifactClassificationNodeOptional.isPresent()) {
buildPluginUrlClassification(artifact, context, directDependenciesFilter, artifactsClassified, rootArtifactRemoteRepositories);
} else {
if (!areCompatibleVersions(artifactClassificationNodeOptional.get().getArtifact().getVersion(), artifact.getVersion())) {
throw new IllegalStateException(format("Incompatible version of artifacts found: %s and %s", toId(artifactClassificationNodeOptional.get().getArtifact()), toId(artifact)));
}
logger.debug("Checking for highest version of artifact, already discovered: '{}' versus: '{}'", toId(artifactClassificationNodeOptional.get().getArtifact()), toId(artifact));
if (isHighestVersion(artifact.getVersion(), artifactClassificationNodeOptional.get().getArtifact().getVersion())) {
artifactsClassified.remove(artifactClassificationNodeOptional.get());
buildPluginUrlClassification(artifact, context, directDependenciesFilter, artifactsClassified, rootArtifactRemoteRepositories);
logger.warn("Replacing artifact: '{}' for highest version: '{}'", toId(artifactClassificationNodeOptional.get().getArtifact()), toId(artifact));
}
}
return findArtifactClassified(artifactsClassified, artifact).orElseThrow(() -> new IllegalStateException(format("Should %s be already added to the list of artifacts classified", toId(artifact))));
}).forEach(artifactDependencies::add);
final List<Class> exportClasses = getArtifactExportedClasses(artifactToClassify, context, rootArtifactRemoteRepositories);
resolveSnapshotVersionsToTimestampedFromClassPath(urls, context.getClassPathURLs());
ArtifactClassificationNode artifactUrlClassification = new ArtifactClassificationNode(artifactToClassify, urls, exportClasses, artifactDependencies);
logger.debug("Artifact discovered: {}", toId(artifactUrlClassification.getArtifact()));
artifactsClassified.add(artifactUrlClassification);
}
use of org.eclipse.aether.repository.RemoteRepository in project revapi by revapi.
the class Main method convertGavs.
private static ArchivesAndSupplementaryArchives convertGavs(String[] gavs, String errorMessagePrefix, File localRepo) {
RepositorySystem repositorySystem = MavenBootstrap.newRepositorySystem();
DefaultRepositorySystemSession session = MavenBootstrap.newRepositorySystemSession(repositorySystem, localRepo);
session.setDependencySelector(new ScopeDependencySelector("compile", "provided"));
session.setDependencyTraverser(new ScopeDependencyTraverser("compile", "provided"));
RemoteRepository mavenCentral = new RemoteRepository.Builder("@@forced-maven-central@@", "default", "http://repo.maven.apache.org/maven2/").build();
List<RemoteRepository> remoteRepositories = singletonList(mavenCentral);
ArtifactResolver resolver = new ArtifactResolver(repositorySystem, session, remoteRepositories);
List<FileArchive> archives = new ArrayList<>();
List<FileArchive> supplementaryArchives = new ArrayList<>();
for (String gav : gavs) {
try {
archives.add(new FileArchive(resolver.resolveArtifact(gav).getFile()));
ArtifactResolver.CollectionResult res = resolver.collectTransitiveDeps(gav);
res.getResolvedArtifacts().forEach(a -> supplementaryArchives.add(new FileArchive(a.getFile())));
if (!res.getFailures().isEmpty()) {
LOG.warn("Failed to resolve some transitive dependencies: " + res.getFailures().toString());
}
} catch (RepositoryException e) {
throw new IllegalArgumentException(errorMessagePrefix + " " + e.getMessage());
}
}
return new ArchivesAndSupplementaryArchives(archives, supplementaryArchives);
}
Aggregations