Search in sources :

Example 6 with ArtifactRequest

use of org.sonatype.aether.resolution.ArtifactRequest in project sonatype-aether by sonatype.

the class DefaultArtifactResolverTest method testResolveFromWorkspace.

@Test
public void testResolveFromWorkspace() throws IOException, ArtifactResolutionException {
    session = new TestRepositorySystemSession() {

        @Override
        public WorkspaceReader getWorkspaceReader() {
            return new WorkspaceReader() {

                public WorkspaceRepository getRepository() {
                    return new WorkspaceRepository("default");
                }

                public List<String> findVersions(Artifact artifact) {
                    return Arrays.asList(artifact.getVersion());
                }

                public File findArtifact(Artifact artifact) {
                    try {
                        return TestFileUtils.createTempFile(artifact.toString());
                    } catch (IOException e) {
                        throw new RuntimeException(e.getMessage(), e);
                    }
                }
            };
        }
    };
    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());
    byte[] expected = resolved.toString().getBytes("UTF-8");
    TestFileUtils.assertContent(expected, resolved.getFile());
    resolved = resolved.setFile(null);
    assertEquals(artifact, resolved);
    connector.assertSeenExpected();
}
Also used : RemoteRepository(org.sonatype.aether.repository.RemoteRepository) IOException(java.io.IOException) WorkspaceReader(org.sonatype.aether.repository.WorkspaceReader) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) LocalArtifactResult(org.sonatype.aether.repository.LocalArtifactResult) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) TestRepositorySystemSession(org.sonatype.aether.test.impl.TestRepositorySystemSession) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) WorkspaceRepository(org.sonatype.aether.repository.WorkspaceRepository) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 7 with ArtifactRequest

use of org.sonatype.aether.resolution.ArtifactRequest in project sonatype-aether by sonatype.

the class DefaultArtifactResolverTest method testRepositoryEventsUnsuccessfulLocal.

@Test
public void testRepositoryEventsUnsuccessfulLocal() throws IOException {
    RecordingRepositoryListener listener = new RecordingRepositoryListener();
    session.setRepositoryListener(listener);
    Map<String, String> properties = new HashMap<String, String>();
    properties.put(ArtifactProperties.LOCAL_PATH, "doesnotexist");
    artifact = artifact.setProperties(properties);
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    try {
        resolver.resolveArtifact(session, request);
        fail("expected exception");
    } catch (ArtifactResolutionException e) {
    }
    List<EventWrapper> events = listener.getEvents();
    assertEquals(2, events.size());
    EventWrapper event = events.get(0);
    assertEquals(artifact, event.getEvent().getArtifact());
    assertEquals(Type.ARTIFACT_RESOLVING, event.getType());
    event = events.get(1);
    assertEquals(artifact, event.getEvent().getArtifact());
    assertEquals(Type.ARTIFACT_RESOLVED, event.getType());
    assertNotNull(event.getEvent().getException());
    assertEquals(1, event.getEvent().getExceptions().size());
}
Also used : ArtifactResolutionException(org.sonatype.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) HashMap(java.util.HashMap) RecordingRepositoryListener(org.sonatype.aether.test.impl.RecordingRepositoryListener) EventWrapper(org.sonatype.aether.test.impl.RecordingRepositoryListener.EventWrapper) Test(org.junit.Test)

Example 8 with ArtifactRequest

use of org.sonatype.aether.resolution.ArtifactRequest in project sonatype-aether by sonatype.

the class ArtifactRequestBuilder method visitEnter.

public boolean visitEnter(DependencyNode node) {
    if (node.getDependency() != null) {
        ArtifactRequest request = new ArtifactRequest(node);
        request.setTrace(trace);
        requests.add(request);
    }
    return true;
}
Also used : ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest)

Example 9 with ArtifactRequest

use of org.sonatype.aether.resolution.ArtifactRequest 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 10 with ArtifactRequest

use of org.sonatype.aether.resolution.ArtifactRequest in project karaf by apache.

the class Dependency30Helper method resolve.

@Override
public File resolve(Object artifact, Log log) {
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact((Artifact) artifact);
    request.setRepositories(projectRepositories);
    log.debug("Resolving artifact " + artifact + " from " + projectRepositories);
    ArtifactResult result;
    try {
        result = repositorySystem.resolveArtifact(repositorySystemSession, request);
    } catch (ArtifactResolutionException e) {
        log.warn("Could not resolve " + artifact, e);
        return null;
    }
    log.debug("Resolved artifact " + artifact + " to " + result.getArtifact().getFile() + " from " + result.getRepository());
    return result.getArtifact().getFile();
}
Also used : ArtifactResolutionException(org.sonatype.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult)

Aggregations

ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)25 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)18 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)18 Test (org.junit.Test)16 Artifact (org.sonatype.aether.artifact.Artifact)14 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)12 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)12 ArtifactResolutionException (org.sonatype.aether.resolution.ArtifactResolutionException)12 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)11 File (java.io.File)8 TestRepositorySystemSession (org.sonatype.aether.test.impl.TestRepositorySystemSession)7 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)6 IOException (java.io.IOException)5 LocalRepositoryManager (org.sonatype.aether.repository.LocalRepositoryManager)5 VersionRequest (org.sonatype.aether.resolution.VersionRequest)5 VersionResolutionException (org.sonatype.aether.resolution.VersionResolutionException)5 VersionResult (org.sonatype.aether.resolution.VersionResult)5 RecordingRepositoryListener (org.sonatype.aether.test.impl.RecordingRepositoryListener)5 EventWrapper (org.sonatype.aether.test.impl.RecordingRepositoryListener.EventWrapper)5 ArtifactNotFoundException (org.sonatype.aether.transfer.ArtifactNotFoundException)5