use of org.sonatype.aether.RepositorySystemSession in project sonatype-aether by sonatype.
the class FindAvailableVersions method main.
public static void main(String[] args) throws Exception {
System.out.println("------------------------------------------------------------");
System.out.println(FindAvailableVersions.class.getSimpleName());
RepositorySystem system = Booter.newRepositorySystem();
RepositorySystemSession session = Booter.newRepositorySystemSession(system);
Artifact artifact = new DefaultArtifact("org.sonatype.aether:aether-util:[0,)");
RemoteRepository repo = Booter.newCentralRepository();
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact(artifact);
rangeRequest.addRepository(repo);
VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);
List<Version> versions = rangeResult.getVersions();
System.out.println("Available versions " + versions);
}
use of org.sonatype.aether.RepositorySystemSession in project sonatype-aether by sonatype.
the class GetDependencyTree method main.
public static void main(String[] args) throws Exception {
System.out.println("------------------------------------------------------------");
System.out.println(GetDependencyTree.class.getSimpleName());
RepositorySystem system = Booter.newRepositorySystem();
RepositorySystemSession session = Booter.newRepositorySystemSession(system);
Artifact artifact = new DefaultArtifact("org.apache.maven:maven-aether-provider:3.0.2");
RemoteRepository repo = Booter.newCentralRepository();
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, ""));
collectRequest.addRepository(repo);
CollectResult collectResult = system.collectDependencies(session, collectRequest);
collectResult.getRoot().accept(new ConsoleDependencyGraphDumper());
}
use of org.sonatype.aether.RepositorySystemSession in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method testLocalArtifactAvailable.
@Test
public void testLocalArtifactAvailable() throws ArtifactResolutionException {
session.setLocalRepositoryManager(new LocalRepositoryManager() {
public LocalRepository getRepository() {
return null;
}
public String getPathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context) {
return null;
}
public String getPathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context) {
return null;
}
public String getPathForLocalMetadata(Metadata metadata) {
return null;
}
public String getPathForLocalArtifact(Artifact artifact) {
return null;
}
public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request) {
LocalArtifactResult result = new LocalArtifactResult(request);
result.setAvailable(true);
try {
result.setFile(TestFileUtils.createTempFile(""));
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
public void add(RepositorySystemSession session, LocalArtifactRegistration request) {
}
public LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request) {
LocalMetadataResult result = new LocalMetadataResult(request);
try {
result.setFile(TestFileUtils.createTempFile(""));
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
public void add(RepositorySystemSession session, LocalMetadataRegistration request) {
}
});
ArtifactRequest request = new ArtifactRequest(artifact, null, "");
request.addRepository(new RemoteRepository("id", "default", "file:///"));
ArtifactResult result = resolver.resolveArtifact(session, request);
assertTrue(result.getExceptions().isEmpty());
Artifact resolved = result.getArtifact();
assertNotNull(resolved.getFile());
resolved = resolved.setFile(null);
assertEquals(artifact, resolved);
}
use of org.sonatype.aether.RepositorySystemSession in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method testVersionResolverFails.
@Test
public void testVersionResolverFails() {
resolver.setVersionResolver(new VersionResolver() {
public VersionResult resolveVersion(RepositorySystemSession session, VersionRequest request) throws VersionResolutionException {
throw new VersionResolutionException(new VersionResult(request));
}
});
ArtifactRequest request = new ArtifactRequest(artifact, null, "");
try {
resolver.resolveArtifact(session, request);
fail("expected exception");
} catch (ArtifactResolutionException e) {
connector.assertSeenExpected();
assertNotNull(e.getResults());
assertEquals(1, e.getResults().size());
ArtifactResult result = e.getResults().get(0);
assertSame(request, result.getRequest());
assertFalse(result.getExceptions().isEmpty());
assertTrue(result.getExceptions().get(0) instanceof VersionResolutionException);
Artifact resolved = result.getArtifact();
assertNull(resolved);
}
}
use of org.sonatype.aether.RepositorySystemSession in project sonatype-aether by sonatype.
the class DefaultDependencyCollectorTest method testArtifactDescriptorResolutionNotRestrictedToRepoHostingSelectedVersion.
@Test
public void testArtifactDescriptorResolutionNotRestrictedToRepoHostingSelectedVersion() throws Exception {
RemoteRepository repo2 = new RemoteRepository("test", "default", "file:///");
final List<RemoteRepository> repos = new ArrayList<RemoteRepository>();
collector.setArtifactDescriptorReader(new ArtifactDescriptorReader() {
public ArtifactDescriptorResult readArtifactDescriptor(RepositorySystemSession session, ArtifactDescriptorRequest request) throws ArtifactDescriptorException {
repos.addAll(request.getRepositories());
return new ArtifactDescriptorResult(request);
}
});
DependencyNode root = parser.parseLiteral("verrange:parent:jar:[1,):compile");
List<Dependency> dependencies = Arrays.asList(root.getDependency());
CollectRequest request = new CollectRequest(dependencies, null, Arrays.asList(repository, repo2));
CollectResult result = collector.collectDependencies(session, request);
assertEquals(0, result.getExceptions().size());
assertEquals(2, repos.size());
assertEquals("id", repos.get(0).getId());
assertEquals("test", repos.get(1).getId());
}
Aggregations