use of org.eclipse.aether.RepositorySystemSession in project kie-wb-common by kiegroup.
the class MavenArtifactResolverTest method resolveArtifactNotOffline.
@Test
public void resolveArtifactNotOffline() throws Exception {
final boolean[] executedOffline = { false };
RepositorySystemSession session = Aether.getAether().getSession();
assertThat(checksIfArtifactIsPresent(session)).isFalse();
File file = new File("target/test-classes/fake-uberfire-m2repo-editor-backend-100-SNAPSHOT.jar");
assertThat(file).exists();
Artifact artifact = getArtifact();
artifact = artifact.setFile(file);
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(artifact);
ArtifactResult result;
try {
Aether.getAether().getSystem().resolveArtifact(session, artifactRequest);
} catch (ArtifactResolutionException ex) {
assertThat(ex).isNotNull();
}
deployTestJar(artifact, session);
MavenArtifactResolver resolver = new MavenArtifactResolver() {
public URI resolve(final String groupId, final String artifactId, final String version) throws Exception {
return internalResolver(false, groupId, artifactId, version);
}
URI resolveEmbedded(final String groupId, final String artifactId, final String version) throws IOException {
executedOffline[0] = false;
return super.resolveEmbedded(groupId, artifactId, version);
}
};
URI uri = resolver.resolve(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
assertThat(uri).isNotNull();
assertThat(uri.getPath()).endsWith(File.separator + "fake-uberfire-m2repo-editor-backend" + File.separator + "100-SNAPSHOT" + File.separator + "fake-uberfire-m2repo-editor-backend-100-SNAPSHOT.jar");
result = Aether.getAether().getSystem().resolveArtifact(session, artifactRequest);
assertThat(result.isMissing()).isFalse();
assertThat(result.isResolved()).isTrue();
assertThat(executedOffline[0]).isFalse();
}
use of org.eclipse.aether.RepositorySystemSession in project gradle by gradle.
the class MavenProjectsCreator method createNow.
private Set<MavenProject> createNow(Settings settings, File pomFile) throws PlexusContainerException, ComponentLookupException, MavenExecutionRequestPopulationException, ProjectBuildingException {
ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration().setClassWorld(new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader())).setName("mavenCore").setClassPathScanning(PlexusConstants.SCANNING_INDEX).setAutoWiring(true);
DefaultPlexusContainer container = new DefaultPlexusContainer(containerConfiguration);
ProjectBuilder builder = container.lookup(ProjectBuilder.class);
MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
final Properties properties = SystemProperties.getInstance().withSystemProperties(() -> {
final Properties currentProperties = new Properties();
currentProperties.putAll(System.getProperties());
return currentProperties;
});
executionRequest.setSystemProperties(properties);
MavenExecutionRequestPopulator populator = container.lookup(MavenExecutionRequestPopulator.class);
populateFromSettings(settings, executionRequest, populator);
populator.populateDefaults(executionRequest);
ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
buildingRequest.getRemoteRepositories().forEach(repository -> {
if (repository.getId().equals(RepositorySystem.DEFAULT_REMOTE_REPO_ID)) {
repository.setUrl(RepositoryHandler.MAVEN_CENTRAL_URL);
}
});
buildingRequest.setProcessPlugins(false);
MavenProject mavenProject = builder.build(pomFile, buildingRequest).getProject();
Set<MavenProject> reactorProjects = new LinkedHashSet<>();
// TODO adding the parent project first because the converter needs it this way ATM. This is oversimplified.
// the converter should not depend on the order of reactor projects.
// we should add coverage for nested multi-project builds with multiple parents.
reactorProjects.add(mavenProject);
List<ProjectBuildingResult> allProjects = builder.build(ImmutableList.of(pomFile), true, buildingRequest);
// noinspection NullableProblems
CollectionUtils.collect(allProjects, reactorProjects, ProjectBuildingResult::getProject);
MavenExecutionResult result = new DefaultMavenExecutionResult();
result.setProject(mavenProject);
RepositorySystemSession repoSession = new DefaultRepositorySystemSession();
@SuppressWarnings("deprecation") MavenSession session = new MavenSession(container, repoSession, executionRequest, result);
session.setCurrentProject(mavenProject);
return reactorProjects;
}
use of org.eclipse.aether.RepositorySystemSession in project wildfly-swarm by wildfly-swarm.
the class MavenArtifactResolvingHelper method resolveAll.
@Override
public Set<ArtifactSpec> resolveAll(Collection<ArtifactSpec> specs, boolean transitive, boolean defaultExcludes) throws Exception {
if (specs.isEmpty()) {
return Collections.emptySet();
}
List<DependencyNode> nodes;
if (transitive) {
final CollectRequest request = new CollectRequest();
request.setRepositories(this.remoteRepositories);
// SWARM-1031
if (this.dependencyManagement != null) {
List<Dependency> managedDependencies = this.dependencyManagement.getDependencies().stream().map(mavenDep -> {
DefaultArtifact artifact = new DefaultArtifact(mavenDep.getGroupId(), mavenDep.getArtifactId(), mavenDep.getType(), mavenDep.getVersion());
return new Dependency(artifact, mavenDep.getScope());
}).collect(Collectors.toList());
request.setManagedDependencies(managedDependencies);
}
specs.forEach(spec -> request.addDependency(new Dependency(new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(), spec.type(), spec.version()), "compile")));
RepositorySystemSession tempSession = new RepositorySystemSessionWrapper(this.session, new ConflictResolver(new NearestVersionSelector(), new JavaScopeSelector(), new SimpleOptionalitySelector(), new JavaScopeDeriver()), defaultExcludes);
CollectResult result = this.system.collectDependencies(tempSession, request);
PreorderNodeListGenerator gen = new PreorderNodeListGenerator();
result.getRoot().accept(gen);
nodes = gen.getNodes();
} else {
nodes = new ArrayList<>();
for (ArtifactSpec spec : specs) {
Dependency dependency = new Dependency(new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(), spec.type(), spec.version()), "compile");
DefaultDependencyNode node = new DefaultDependencyNode(dependency);
nodes.add(node);
}
}
List<DependencyNode> extraDependencies = ExtraArtifactsHandler.getExtraDependencies(nodes);
nodes.addAll(extraDependencies);
resolveDependenciesInParallel(nodes);
return nodes.stream().filter(node -> !"system".equals(node.getDependency().getScope())).map(node -> {
final Artifact artifact = node.getArtifact();
return new ArtifactSpec(node.getDependency().getScope(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getExtension(), artifact.getClassifier(), null);
}).map(this::resolve).filter(Objects::nonNull).collect(Collectors.toSet());
}
use of org.eclipse.aether.RepositorySystemSession 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);
}
}
use of org.eclipse.aether.RepositorySystemSession in project sts4 by spring-projects.
the class MavenBridge method createSession.
@SuppressWarnings("deprecation")
public MavenSession createSession(MavenExecutionRequest request, MavenProject project) throws MavenException {
RepositorySystemSession repoSession = createRepositorySession(request);
MavenExecutionResult result = new DefaultMavenExecutionResult();
MavenSession mavenSession = new MavenSession(plexus, repoSession, request, result);
if (project != null) {
mavenSession.setProjects(Collections.singletonList(project));
}
return mavenSession;
}
Aggregations