Search in sources :

Example 1 with RepositorySystem

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);
    }
}
Also used : MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) DependencyCollectionException(org.sonatype.aether.collection.DependencyCollectionException) CollectResult(org.sonatype.aether.collection.CollectResult) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) RepositorySystem(org.sonatype.aether.RepositorySystem) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Example 2 with RepositorySystem

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();
    }
}
Also used : LocalRepository(org.sonatype.aether.repository.LocalRepository) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) MavenRepositorySystemSession(org.motechproject.admin.service.impl.MavenRepositorySystemSession) CollectRequest(org.sonatype.aether.collection.CollectRequest) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) RepositorySystem(org.sonatype.aether.RepositorySystem) DependencyRequest(org.sonatype.aether.resolution.DependencyRequest) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Example 3 with RepositorySystem

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);
    }
}
Also used : RepositorySystem(org.sonatype.aether.RepositorySystem) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Dependency(org.sonatype.aether.graph.Dependency) ArtifactDescriptorResult(org.sonatype.aether.resolution.ArtifactDescriptorResult) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) ArtifactDescriptorRequest(org.sonatype.aether.resolution.ArtifactDescriptorRequest)

Example 4 with RepositorySystem

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());
}
Also used : RepositorySystem(org.sonatype.aether.RepositorySystem) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult)

Example 5 with RepositorySystem

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);
}
Also used : RepositorySystem(org.sonatype.aether.RepositorySystem) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) SubArtifact(org.sonatype.aether.util.artifact.SubArtifact) DeployRequest(org.sonatype.aether.deployment.DeployRequest) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) File(java.io.File) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) SubArtifact(org.sonatype.aether.util.artifact.SubArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Aggregations

RepositorySystem (org.sonatype.aether.RepositorySystem)13 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)11 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)10 Artifact (org.sonatype.aether.artifact.Artifact)10 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)9 CollectRequest (org.sonatype.aether.collection.CollectRequest)5 Dependency (org.sonatype.aether.graph.Dependency)5 CollectResult (org.sonatype.aether.collection.CollectResult)3 ConsoleDependencyGraphDumper (demo.util.ConsoleDependencyGraphDumper)2 File (java.io.File)2 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)2 DependencyRequest (org.sonatype.aether.resolution.DependencyRequest)2 VersionRangeRequest (org.sonatype.aether.resolution.VersionRangeRequest)2 VersionRangeResult (org.sonatype.aether.resolution.VersionRangeResult)2 SubArtifact (org.sonatype.aether.util.artifact.SubArtifact)2 Version (org.sonatype.aether.version.Version)2 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)1 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)1 Test (org.junit.Test)1 MavenRepositorySystemSession (org.motechproject.admin.service.impl.MavenRepositorySystemSession)1