Search in sources :

Example 41 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project sonatype-aether by sonatype.

the class IniArtifactDescriptorReaderTest method testLookup.

@Test
public void testLookup() throws ArtifactDescriptorException {
    StubArtifact art = new StubArtifact("gid:aid:ext:ver");
    ArtifactDescriptorRequest request = new ArtifactDescriptorRequest(art, null, "");
    ArtifactDescriptorResult description = reader.readArtifactDescriptor(session, request);
    assertEquals(request, description.getRequest());
    assertEquals(art, description.getArtifact());
    assertEquals(1, description.getRelocations().size());
    Artifact artifact = description.getRelocations().get(0);
    assertEquals("gid", artifact.getGroupId());
    assertEquals("aid", artifact.getArtifactId());
    assertEquals("ver", artifact.getVersion());
    assertEquals("ext", artifact.getExtension());
    assertEquals(1, description.getRepositories().size());
    RemoteRepository repo = description.getRepositories().get(0);
    assertEquals("id", repo.getId());
    assertEquals("type", repo.getContentType());
    assertEquals("protocol://some/url?for=testing", repo.getUrl());
    assertDependencies(description.getDependencies());
    assertDependencies(description.getManagedDependencies());
}
Also used : StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) ArtifactDescriptorResult(org.sonatype.aether.resolution.ArtifactDescriptorResult) ArtifactDescriptorRequest(org.sonatype.aether.resolution.ArtifactDescriptorRequest) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 42 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project sonatype-aether by sonatype.

the class DefaultDeployerTest method setup.

@Before
public void setup() throws IOException {
    artifact = new DefaultArtifact("gid", "aid", "jar", "ver");
    artifact = artifact.setFile(TestFileUtils.createTempFile("artifact"));
    metadata = new DefaultMetadata("gid", "aid", "ver", "type", Nature.RELEASE_OR_SNAPSHOT, TestFileUtils.createTempFile("metadata"));
    session = new TestRepositorySystemSession();
    manager = new StubRemoteRepositoryManager();
    deployer = new DefaultDeployer();
    deployer.setRemoteRepositoryManager(manager);
    deployer.setRepositoryEventDispatcher(new StubRepositoryEventDispatcher());
    UpdateCheckManager updateCheckManager = new StaticUpdateCheckManager(true);
    deployer.setUpdateCheckManager(updateCheckManager);
    deployer.setFileProcessor(TestFileProcessor.INSTANCE);
    deployer.setSyncContextFactory(new StubSyncContextFactory());
    request = new DeployRequest();
    request.setRepository(new RemoteRepository("id", "default", "file:///"));
    connector = new RecordingRepositoryConnector();
    manager.setConnector(connector);
    listener = new RecordingRepositoryListener();
    session.setRepositoryListener(listener);
}
Also used : DeployRequest(org.sonatype.aether.deployment.DeployRequest) DefaultMetadata(org.sonatype.aether.util.metadata.DefaultMetadata) UpdateCheckManager(org.sonatype.aether.impl.UpdateCheckManager) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) TestRepositorySystemSession(org.sonatype.aether.test.impl.TestRepositorySystemSession) RecordingRepositoryListener(org.sonatype.aether.test.impl.RecordingRepositoryListener) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) Before(org.junit.Before)

Example 43 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project sonatype-aether by sonatype.

the class ResolveTransitiveDependencies method main.

public static void main(String[] args) throws Exception {
    System.out.println("------------------------------------------------------------");
    System.out.println(ResolveTransitiveDependencies.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();
    DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
    collectRequest.addRepository(repo);
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFlter);
    List<ArtifactResult> artifactResults = system.resolveDependencies(session, dependencyRequest).getArtifactResults();
    for (ArtifactResult artifactResult : artifactResults) {
        System.out.println(artifactResult.getArtifact() + " resolved to " + artifactResult.getArtifact().getFile());
    }
}
Also used : RepositorySystem(org.sonatype.aether.RepositorySystem) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) DependencyRequest(org.sonatype.aether.resolution.DependencyRequest) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) DependencyFilter(org.sonatype.aether.graph.DependencyFilter) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) 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 44 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project sonatype-aether by sonatype.

the class Aether method resolve.

public AetherResult resolve(String groupId, String artifactId, String version) throws DependencyResolutionException {
    RepositorySystemSession session = newSession();
    Dependency dependency = new Dependency(new DefaultArtifact(groupId, artifactId, "", "jar", version), "runtime");
    RemoteRepository central = new RemoteRepository("central", "default", remoteRepository);
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(dependency);
    collectRequest.addRepository(central);
    DependencyRequest dependencyRequest = new DependencyRequest();
    dependencyRequest.setCollectRequest(collectRequest);
    DependencyNode rootNode = repositorySystem.resolveDependencies(session, dependencyRequest).getRoot();
    StringBuilder dump = new StringBuilder();
    displayTree(rootNode, dump);
    PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
    rootNode.accept(nlg);
    return new AetherResult(rootNode, nlg.getFiles(), nlg.getClassPath());
}
Also used : MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) DependencyRequest(org.sonatype.aether.resolution.DependencyRequest) DependencyNode(org.sonatype.aether.graph.DependencyNode) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) PreorderNodeListGenerator(org.sonatype.aether.util.graph.PreorderNodeListGenerator) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Example 45 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project sonatype-aether by sonatype.

the class EnhancedLocalRepositoryManagerTest method testGetPathForRemoteArtifact.

@Test
public void testGetPathForRemoteArtifact() {
    RemoteRepository remoteRepo = new RemoteRepository("repo", "default", "ram:/void");
    Artifact artifact = new DefaultArtifact("g.i.d:a.i.d:1.0-SNAPSHOT");
    assertEquals("1.0-SNAPSHOT", artifact.getBaseVersion());
    assertEquals("g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar", manager.getPathForRemoteArtifact(artifact, remoteRepo, ""));
    artifact = new DefaultArtifact("g.i.d:a.i.d:1.0-20110329.221805-4");
    assertEquals("1.0-SNAPSHOT", artifact.getBaseVersion());
    assertEquals("g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-20110329.221805-4.jar", manager.getPathForRemoteArtifact(artifact, remoteRepo, ""));
}
Also used : 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) Test(org.junit.Test)

Aggregations

RemoteRepository (org.sonatype.aether.repository.RemoteRepository)71 Artifact (org.sonatype.aether.artifact.Artifact)30 Test (org.junit.Test)27 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)18 File (java.io.File)15 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)15 TestRepositorySystemSession (org.sonatype.aether.test.impl.TestRepositorySystemSession)13 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)13 Dependency (org.sonatype.aether.graph.Dependency)12 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)12 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)12 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)11 CollectRequest (org.sonatype.aether.collection.CollectRequest)10 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)10 ArrayList (java.util.ArrayList)8 RepositorySystem (org.sonatype.aether.RepositorySystem)8 IOException (java.io.IOException)7 Before (org.junit.Before)7 Metadata (org.sonatype.aether.metadata.Metadata)7 DependencyRequest (org.sonatype.aether.resolution.DependencyRequest)7