use of org.eclipse.aether.DefaultRepositorySystemSession in project bnd by bndtools.
the class AetherRepository method versions.
@Override
public SortedSet<Version> versions(String bsn) throws Exception {
init();
// Use the index by preference
if (indexedRepo != null)
return indexedRepo.versions(ConversionUtils.maybeMavenCoordsToBsn(bsn));
Artifact artifact = null;
try {
artifact = new DefaultArtifact(bsn + ":[0,)");
} catch (Exception e) {
// ignore non-GAV style dependencies
}
if (artifact == null)
return null;
// Setup the Aether repo session and create the range request
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact(artifact);
rangeRequest.setRepositories(Collections.singletonList(remoteRepo));
// Resolve the range
VersionRangeResult rangeResult = repoSystem.resolveVersionRange(session, rangeRequest);
// Add to the result
SortedSet<Version> versions = new TreeSet<Version>();
for (org.eclipse.aether.version.Version version : rangeResult.getVersions()) {
try {
versions.add(MavenVersion.parseString(version.toString()).getOSGiVersion());
} catch (IllegalArgumentException e) {
// ignore version
}
}
return versions;
}
use of org.eclipse.aether.DefaultRepositorySystemSession in project bnd by bndtools.
the class RemotePostProcessor method postProcessRelease.
private ArtifactResult postProcessRelease(ArtifactRequest request, Artifact artifact) throws MojoExecutionException {
for (RemoteRepository repository : request.getRepositories()) {
if (!repository.getPolicy(false).isEnabled()) {
// Skip the repo if it isn't enabled for releases
continue;
}
// Remove the workspace from the session so that we don't use it
DefaultRepositorySystemSession newSession = new DefaultRepositorySystemSession(session);
newSession.setWorkspaceReader(null);
// Find the snapshot metadata for the module
MetadataRequest mr = new MetadataRequest().setRepository(repository).setMetadata(new DefaultMetadata(artifact.getGroupId(), artifact.getArtifactId(), null, "maven-metadata.xml", RELEASE));
for (MetadataResult metadataResult : system.resolveMetadata(newSession, singletonList(mr))) {
if (metadataResult.isResolved()) {
try {
Metadata read = metadataReader.read(metadataResult.getMetadata().getFile(), null);
Versioning versioning = read.getVersioning();
if (versioning == null || versioning.getVersions() == null || versioning.getVersions().isEmpty()) {
continue;
} else if (versioning.getVersions().contains(artifact.getVersion())) {
ArtifactResult result = system.resolveArtifact(newSession, new ArtifactRequest().setArtifact(artifact).addRepository(repository));
if (result.isResolved()) {
File toUse = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForLocalArtifact(artifact));
if (!toUse.exists()) {
logger.warn("The resolved artifact {} does not exist at {}", artifact, toUse);
continue;
} else {
logger.debug("Located snapshot file {} for artifact {}", toUse, artifact);
}
result.getArtifact().setFile(toUse);
return result;
}
}
} catch (Exception e) {
throw new MojoExecutionException("Unable to read project metadata for " + artifact, e);
}
}
}
}
logger.debug("Unable to resolve a remote repository containing {}", artifact);
return null;
}
use of org.eclipse.aether.DefaultRepositorySystemSession in project meecrowave by apache.
the class MeecrowaveRunMojoTest method run.
@Test
public void run() throws Exception {
final File moduleBase = jarLocation(MeecrowaveRunMojoTest.class).getParentFile().getParentFile();
final File basedir = new File(moduleBase, "src/test/resources/" + getClass().getSimpleName());
final File pom = new File(basedir, "pom.xml");
final MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setBaseDirectory(basedir);
final ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
final DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(repositorySession, new LocalRepository(new File(moduleBase, "target/fake"), "")));
configuration.setRepositorySession(repositorySession);
final MavenProject project = mojo.lookup(ProjectBuilder.class).build(pom, configuration).getProject();
final MavenSession session = mojo.newMavenSession(project);
final int port;
try (final ServerSocket serverSocket = new ServerSocket(0)) {
port = serverSocket.getLocalPort();
}
final MojoExecution execution = mojo.newMojoExecution("run");
execution.getConfiguration().addChild(new Xpp3Dom("httpPort") {
{
setValue(Integer.toString(port));
}
});
final InputStream in = System.in;
final CountDownLatch latch = new CountDownLatch(1);
System.setIn(new InputStream() {
// just to not return nothing
private int val = 2;
@Override
public int read() throws IOException {
try {
latch.await();
} catch (final InterruptedException e) {
Thread.interrupted();
fail(e.getMessage());
}
return val--;
}
});
final Thread runner = new Thread() {
@Override
public void run() {
try {
mojo.executeMojo(session, project, execution);
} catch (final Exception e) {
fail(e.getMessage());
}
}
};
try {
runner.start();
for (int i = 0; i < 120; i++) {
try {
assertEquals("simple", IOUtils.toString(new URL("http://localhost:" + port + "/api/test")));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("first_name"));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("last_name"));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("firstname"));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("null"));
latch.countDown();
break;
} catch (final Exception | AssertionError e) {
Thread.sleep(500);
}
}
} finally {
runner.join(TimeUnit.MINUTES.toMillis(1));
System.setIn(in);
if (runner.isAlive()) {
runner.interrupt();
fail("Runner didn't terminate properly");
}
}
}
Aggregations