use of org.sonatype.aether.RepositorySystem in project archiva by apache.
the class Maven3DependencyTreeBuilder method resolve.
private void resolve(ResolveRequest resolveRequest) {
RepositorySystem system = newRepositorySystem();
RepositorySystemSession session = newRepositorySystemSession(system, resolveRequest.localRepoDir);
org.sonatype.aether.artifact.Artifact artifact = new DefaultArtifact(resolveRequest.groupId + ":" + resolveRequest.artifactId + ":" + resolveRequest.version);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, ""));
// add remote repositories
for (RemoteRepository remoteRepository : resolveRequest.remoteRepositories) {
collectRequest.addRepository(new org.sonatype.aether.repository.RemoteRepository(remoteRepository.getId(), "default", remoteRepository.getUrl()));
}
collectRequest.setRequestContext("project");
try {
CollectResult collectResult = system.collectDependencies(session, collectRequest);
collectResult.getRoot().accept(resolveRequest.dependencyVisitor);
log.debug("test");
} catch (DependencyCollectionException e) {
log.error(e.getMessage(), e);
}
}
use of org.sonatype.aether.RepositorySystem in project motech by motech.
the class ModuleAdminServiceImpl method resolveDependencies.
private List<ArtifactResult> resolveDependencies(Dependency dependency, PomInformation pomInformation) throws RepositoryException {
LOGGER.info("Resolving dependencies for {}", dependency);
org.apache.maven.repository.internal.DefaultServiceLocator locator = new org.apache.maven.repository.internal.DefaultServiceLocator();
locator.addService(RepositoryConnectorFactory.class, WagonRepositoryConnectorFactory.class);
locator.setServices(WagonProvider.class, new HttpWagonProvider());
RepositorySystem system = locator.getService(RepositorySystem.class);
MavenRepositorySystemSession mvnRepository = new MavenRepositorySystemSession();
mvnRepository.setLocalRepositoryManager(system.newLocalRepositoryManager(new LocalRepository(System.getProperty("java.io.tmpdir") + "/repo")));
RemoteRepository remoteRepository = new RemoteRepository("central", "default", "http://nexus.motechproject.org/content/repositories/public");
CollectRequest collectRequest = new CollectRequest();
if (pomInformation != null) {
String version = parseDependencyVersion(dependency, mvnRepository, system, remoteRepository, pomInformation);
String groupId = parseDependencyGroupId(dependency, mvnRepository, system, remoteRepository, pomInformation);
Artifact artifact = dependency.getArtifact();
Artifact updatedArtifact = new DefaultArtifact(groupId, artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension(), version);
// The method setArtifact instead of updating dependency object, creates new dependency object with the given artifact
// NO CHECKSTYLE ParameterAssignmentCheck
dependency = dependency.setArtifact(updatedArtifact);
if (pomInformation.getRepositories() != null) {
for (RemoteRepository repository : pomInformation.getRepositories()) {
collectRequest.addRepository(repository);
}
}
}
collectRequest.setRoot(dependency);
collectRequest.addRepository(remoteRepository);
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME));
try {
LOGGER.debug("Sending dependency request");
return system.resolveDependencies(mvnRepository, dependencyRequest).getArtifactResults();
} catch (RuntimeException e) {
LOGGER.error("Unable to resolve dependencies for {}", dependency.toString(), e);
return Collections.emptyList();
}
}
use of org.sonatype.aether.RepositorySystem in project sonatype-aether by sonatype.
the class GetDirectDependencies method main.
public static void main(String[] args) throws Exception {
System.out.println("------------------------------------------------------------");
System.out.println(GetDirectDependencies.class.getSimpleName());
RepositorySystem system = Booter.newRepositorySystem();
RepositorySystemSession session = Booter.newRepositorySystemSession(system);
Artifact artifact = new DefaultArtifact("org.sonatype.aether:aether-impl:1.9");
RemoteRepository repo = Booter.newCentralRepository();
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
descriptorRequest.setArtifact(artifact);
descriptorRequest.addRepository(repo);
ArtifactDescriptorResult descriptorResult = system.readArtifactDescriptor(session, descriptorRequest);
for (Dependency dependency : descriptorResult.getDependencies()) {
System.out.println(dependency);
}
}
use of org.sonatype.aether.RepositorySystem in project sonatype-aether by sonatype.
the class ResolveArtifact method main.
public static void main(String[] args) throws Exception {
System.out.println("------------------------------------------------------------");
System.out.println(ResolveArtifact.class.getSimpleName());
RepositorySystem system = Booter.newRepositorySystem();
RepositorySystemSession session = Booter.newRepositorySystemSession(system);
Artifact artifact = new DefaultArtifact("org.sonatype.aether:aether-util:1.9");
RemoteRepository repo = Booter.newCentralRepository();
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(artifact);
artifactRequest.addRepository(repo);
ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest);
artifact = artifactResult.getArtifact();
System.out.println(artifact + " resolved to " + artifact.getFile());
}
use of org.sonatype.aether.RepositorySystem in project sonatype-aether by sonatype.
the class DeployArtifacts method main.
public static void main(String[] args) throws Exception {
System.out.println("------------------------------------------------------------");
System.out.println(DeployArtifacts.class.getSimpleName());
RepositorySystem system = Booter.newRepositorySystem();
RepositorySystemSession session = Booter.newRepositorySystemSession(system);
Artifact jarArtifact = new DefaultArtifact("test", "demo", "", "jar", "0.1-SNAPSHOT");
jarArtifact = jarArtifact.setFile(new File("demo.jar"));
Artifact pomArtifact = new SubArtifact(jarArtifact, "", "pom");
pomArtifact = pomArtifact.setFile(new File("pom.xml"));
RemoteRepository distRepo = new RemoteRepository("demo", "default", new File("target/dist-repo").toURI().toString());
DeployRequest deployRequest = new DeployRequest();
deployRequest.addArtifact(jarArtifact).addArtifact(pomArtifact);
deployRequest.setRepository(distRepo);
system.deploy(session, deployRequest);
}
Aggregations