use of org.eclipse.aether.DefaultRepositorySystemSession in project spring-boot by spring-projects.
the class SettingsXmlRepositorySystemSessionAutoConfigurationTests method propertyInterpolation.
@Test
public void propertyInterpolation() throws SettingsBuildingException {
final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
given(this.repositorySystem.newLocalRepositoryManager(eq(session), any(LocalRepository.class))).willAnswer(new Answer<LocalRepositoryManager>() {
@Override
public LocalRepositoryManager answer(InvocationOnMock invocation) throws Throwable {
LocalRepository localRepository = invocation.getArgument(1);
return new SimpleLocalRepositoryManagerFactory().newInstance(session, localRepository);
}
});
SystemProperties.doWithSystemProperties(new Runnable() {
@Override
public void run() {
new SettingsXmlRepositorySystemSessionAutoConfiguration().apply(session, SettingsXmlRepositorySystemSessionAutoConfigurationTests.this.repositorySystem);
}
}, "user.home:src/test/resources/maven-settings/property-interpolation", "foo:bar");
assertThat(session.getLocalRepository().getBasedir().getAbsolutePath()).endsWith(File.separatorChar + "bar" + File.separatorChar + "repository");
}
use of org.eclipse.aether.DefaultRepositorySystemSession in project spring-boot by spring-projects.
the class ModifiedClassPathRunner method resolveCoordinates.
private List<URL> resolveCoordinates(String[] coordinates) throws Exception {
DefaultServiceLocator serviceLocator = MavenRepositorySystemUtils.newServiceLocator();
serviceLocator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
serviceLocator.addService(TransporterFactory.class, HttpTransporterFactory.class);
RepositorySystem repositorySystem = serviceLocator.getService(RepositorySystem.class);
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
LocalRepository localRepository = new LocalRepository(System.getProperty("user.home") + "/.m2/repository");
session.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager(session, localRepository));
CollectRequest collectRequest = new CollectRequest(null, Arrays.asList(new RemoteRepository.Builder("central", "default", "http://central.maven.org/maven2").build()));
collectRequest.setDependencies(createDependencies(coordinates));
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, null);
DependencyResult result = repositorySystem.resolveDependencies(session, dependencyRequest);
List<URL> resolvedArtifacts = new ArrayList<URL>();
for (ArtifactResult artifact : result.getArtifactResults()) {
resolvedArtifacts.add(artifact.getArtifact().getFile().toURI().toURL());
}
return resolvedArtifacts;
}
use of org.eclipse.aether.DefaultRepositorySystemSession in project bazel by bazelbuild.
the class MavenConnector method newRepositorySystemSession.
public RepositorySystemSession newRepositorySystemSession(RepositorySystem system) {
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
LocalRepository localRepo = new LocalRepository(localRepositoryPath);
session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
session.setTransferListener(new AbstractTransferListener() {
});
session.setRepositoryListener(new AbstractRepositoryListener() {
});
return session;
}
use of org.eclipse.aether.DefaultRepositorySystemSession in project karaf by apache.
the class Dependency31Helper method getDependencyTree.
private DependencyNode getDependencyTree(Artifact artifact) throws MojoExecutionException {
try {
CollectRequest collectRequest = new CollectRequest(new Dependency(artifact, "compile"), null, projectRepositories);
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession);
session.setDependencySelector(new AndDependencySelector(new OptionalDependencySelector(), new ScopeDependencySelector1(), new ExclusionDependencySelector()));
// between aether-util 0.9.0.M1 and M2, JavaEffectiveScopeCalculator was removed
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=397241
DependencyGraphTransformer transformer = new ChainedDependencyGraphTransformer(new ConflictMarker(), new ConflictResolver(new NearestVersionSelector(), new JavaScopeSelector(), new SimpleOptionalitySelector(), new JavaScopeDeriver()), new JavaDependencyContextRefiner());
session.setDependencyGraphTransformer(transformer);
CollectResult result = repositorySystem.collectDependencies(session, collectRequest);
return result.getRoot();
} catch (DependencyCollectionException e) {
throw new MojoExecutionException("Cannot build project dependency tree", e);
}
}
use of org.eclipse.aether.DefaultRepositorySystemSession in project bnd by bndtools.
the class AetherRepository method get.
@Override
public File get(String bsn, Version version, Map<String, String> properties, DownloadListener... listeners) throws Exception {
init();
// Use the index by preference
if (indexedRepo != null)
return indexedRepo.get(ConversionUtils.maybeMavenCoordsToBsn(bsn), version, properties, listeners);
File file = null;
boolean getSource = false;
try {
// Setup the Aether repo session and request
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
if (bsn.endsWith(".source")) {
String originalBsn = properties.get("bsn");
if (originalBsn != null) {
bsn = originalBsn;
getSource = true;
}
}
String[] coords = ConversionUtils.getGroupAndArtifactForBsn(bsn);
MavenVersion mvnVersion = new MavenVersion(version);
String versionStr = null;
if ("exact".equals(properties.get("strategy")) || getSource) {
versionStr = properties.get("version");
} else {
versionStr = mvnVersion.toString();
}
Artifact artifact = null;
if (getSource) {
artifact = new DefaultArtifact(coords[0], coords[1], "sources", "jar", versionStr);
} else {
artifact = new DefaultArtifact(coords[0], coords[1], "jar", versionStr);
}
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(artifact);
request.setRepositories(Collections.singletonList(remoteRepo));
// Log the transfer
session.setTransferListener(new AbstractTransferListener() {
@Override
public void transferStarted(TransferEvent event) throws TransferCancelledException {
System.err.println(event);
}
@Override
public void transferSucceeded(TransferEvent event) {
System.err.println(event);
}
@Override
public void transferFailed(TransferEvent event) {
System.err.println(event);
}
});
try {
// Resolve the version
ArtifactResult artifactResult = repoSystem.resolveArtifact(session, request);
artifact = artifactResult.getArtifact();
file = artifact.getFile();
} catch (ArtifactResolutionException ex) {
// could not download artifact, simply return null
}
return file;
} finally {
for (DownloadListener dl : listeners) {
if (file != null)
dl.success(file);
else
dl.failure(null, "Download failed");
}
}
}
Aggregations