Search in sources :

Example 36 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project kie-soup by kiegroup.

the class AetherTest method shouldUseWagonClass.

@Test
public void shouldUseWagonClass() throws ArtifactResolutionException {
    final RepositoryPolicy repositoryPolicy = new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_NEVER, RepositoryPolicy.CHECKSUM_POLICY_IGNORE);
    final RemoteRepository s3repository = new RemoteRepository.Builder("central", "default", "s3://amazon-s3-repository-bucket/").setPolicy(repositoryPolicy).build();
    final List<RemoteRepository> remoteRepositories = Collections.singletonList(s3repository);
    final MavenProject mavenProject = mock(MavenProject.class);
    when(mavenProject.getRemoteProjectRepositories()).thenReturn(remoteRepositories);
    final ArtifactRequest request = new ArtifactRequest(new DefaultArtifact("org.test:fake:0.0.1"), remoteRepositories, null);
    try {
        System.setProperty(Aether.S3_WAGON_CLASS, "org.appformer.maven.integration.S3WagonMock");
        final File tmpDirectory = IoUtils.getTmpDirectory();
        MavenSettings.getSettings().setLocalRepository(tmpDirectory.getAbsolutePath());
        final Aether aether = new Aether(mavenProject);
        final RepositorySystemSession session = aether.getSession();
        final ArtifactResult artifactResult = aether.getSystem().resolveArtifact(session, request);
        assertTrue(artifactResult.isResolved());
        assertTrue(S3WagonMock.wasUsed());
    } finally {
        System.clearProperty(Aether.S3_WAGON_CLASS);
        MavenSettings.reinitSettings();
    }
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MavenProject(org.apache.maven.project.MavenProject) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Test(org.junit.Test)

Example 37 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project kie-soup by kiegroup.

the class AetherTest method testNotOffline.

@Test
public void testNotOffline() {
    final RemoteRepository central = new RemoteRepository.Builder("central", "default", "http://repo1.maven.org/maven2/").build();
    final MavenProject mavenProject = mock(MavenProject.class);
    when(mavenProject.getRemoteProjectRepositories()).thenReturn(Collections.singletonList(central));
    final Aether aether = new Aether(mavenProject) {

        @Override
        boolean isForcedOffline() {
            return false;
        }
    };
    assertThat(aether.getRepositories()).contains(central);
}
Also used : MavenProject(org.apache.maven.project.MavenProject) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Test(org.junit.Test)

Example 38 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project kie-soup by kiegroup.

the class AetherTest method testForcedOffline.

@Test
public void testForcedOffline() {
    final RemoteRepository central = new RemoteRepository.Builder("central", "default", "http://repo1.maven.org/maven2/").build();
    final MavenProject mavenProject = mock(MavenProject.class);
    when(mavenProject.getRemoteProjectRepositories()).thenReturn(Collections.singletonList(central));
    final Aether aether = new Aether(mavenProject) {

        @Override
        boolean isForcedOffline() {
            return true;
        }
    };
    assertThat(aether.getRepositories()).doesNotContain(central);
}
Also used : MavenProject(org.apache.maven.project.MavenProject) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Test(org.junit.Test)

Example 39 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project kie-soup by kiegroup.

the class AetherTest method testProxies.

@Test
public void testProxies() {
    String oldSettingsXmlPath = System.getProperty(CUSTOM_SETTINGS_PROPERTY);
    try {
        if (oldSettingsXmlPath != null) {
            System.clearProperty(CUSTOM_SETTINGS_PROPERTY);
        }
        MavenSettings.reinitSettingsFromString(SETTINGS_WITH_PROXY);
        Aether aether = Aether.getAether();
        RemoteRepository remoteRepository = new RemoteRepository.Builder("local", "default", "http://myserver.com").build();
        Proxy proxy = aether.getSession().getProxySelector().getProxy(remoteRepository);
        assertEquals("http", proxy.getType());
        assertEquals("localhost", proxy.getHost());
        assertEquals(8888, proxy.getPort());
    } finally {
        if (oldSettingsXmlPath != null) {
            System.setProperty(CUSTOM_SETTINGS_PROPERTY, oldSettingsXmlPath);
        }
        MavenSettings.reinitSettings();
    }
}
Also used : Proxy(org.eclipse.aether.repository.Proxy) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Test(org.junit.Test)

Example 40 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project kie-soup by kiegroup.

the class MavenRepositoryTest method testMirrors.

@Test
public void testMirrors() {
    MavenRepositoryMock.setCustomSettingsFileName("settings_with_mirror.xml");
    final MavenRepository repo = new MavenRepositoryMock(Aether.getAether());
    final Collection<RemoteRepository> remoteRepos = repo.getRemoteRepositoriesForRequest();
    assertEquals(2, remoteRepos.size());
    for (final RemoteRepository remoteRepo : remoteRepos) {
        assertTrue(remoteRepo.getId().equals("qa") || remoteRepo.getId().equals("foo"));
    }
}
Also used : RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Test(org.junit.Test)

Aggregations

RemoteRepository (org.eclipse.aether.repository.RemoteRepository)258 File (java.io.File)69 ArrayList (java.util.ArrayList)66 Artifact (org.eclipse.aether.artifact.Artifact)59 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)59 Test (org.junit.Test)52 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)46 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)43 RepositorySystem (org.eclipse.aether.RepositorySystem)40 IOException (java.io.IOException)36 Dependency (org.eclipse.aether.graph.Dependency)36 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)36 RepositoryPolicy (org.eclipse.aether.repository.RepositoryPolicy)29 Proxy (org.eclipse.aether.repository.Proxy)28 AuthenticationBuilder (org.eclipse.aether.util.repository.AuthenticationBuilder)27 CollectRequest (org.eclipse.aether.collection.CollectRequest)26 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)26 List (java.util.List)25 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)24 Map (java.util.Map)22