Search in sources :

Example 1 with DefaultMirrorSelector

use of org.apache.maven.repository.DefaultMirrorSelector in project pom-manipulation-ext by release-engineering.

the class MavenLocationExpanderTest method mirrorAdjustsLocationURLs.

@Test
public void mirrorAdjustsLocationURLs() throws Exception {
    final Mirror mirror = new Mirror();
    mirror.setId("test-mirror");
    mirror.setMirrorOf("*");
    mirror.setUrl("http://nowhere.com");
    final ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
    final ArtifactRepositoryPolicy snapshots = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
    final ArtifactRepositoryPolicy releases = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
    final File localRepo = File.createTempFile("local.repo.", ".dir");
    localRepo.deleteOnExit();
    final ArtifactRepository local = new MavenArtifactRepository("local", localRepo.toURI().toString(), layout, snapshots, releases);
    final ArtifactRepository remote = new MavenArtifactRepository("remote", "http:///repo.maven.apache.org/maven2", layout, snapshots, releases);
    final Settings settings = new Settings();
    settings.addMirror(mirror);
    final MavenLocationExpander ex = new MavenLocationExpander(Collections.<Location>emptyList(), Collections.<ArtifactRepository>singletonList(remote), local, new DefaultMirrorSelector(), settings, Collections.<String>emptyList());
    final List<Location> result = ex.expand(MavenLocationExpander.EXPANSION_TARGET);
    assertThat(result.size(), equalTo(2));
    final Iterator<Location> iterator = result.iterator();
    Location loc = iterator.next();
    assertThat(loc.getName(), equalTo(local.getId()));
    assertThat(loc.getUri(), equalTo(local.getUrl()));
    loc = iterator.next();
    assertThat(loc.getName(), equalTo(mirror.getId()));
    assertThat(loc.getUri(), equalTo(mirror.getUrl()));
}
Also used : ArtifactRepositoryLayout(org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) DefaultMirrorSelector(org.apache.maven.repository.DefaultMirrorSelector) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) Mirror(org.apache.maven.settings.Mirror) File(java.io.File) Settings(org.apache.maven.settings.Settings) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 2 with DefaultMirrorSelector

use of org.apache.maven.repository.DefaultMirrorSelector in project pom-manipulation-ext by release-engineering.

the class MavenLocationExpanderTest method useActiveSettingsProfileRepos.

@Test
public void useActiveSettingsProfileRepos() throws Exception {
    final ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
    final ArtifactRepositoryPolicy snapshots = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
    final ArtifactRepositoryPolicy releases = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
    final File localRepo = File.createTempFile("local.repo.", ".dir");
    localRepo.deleteOnExit();
    final ArtifactRepository local = new MavenArtifactRepository("local", localRepo.toURI().toString(), layout, snapshots, releases);
    final Repository remote = new Repository();
    remote.setId("remote");
    remote.setUrl("http:///repo.maven.apache.org/maven2");
    final Profile profile = new Profile();
    profile.setId("test");
    profile.addRepository(remote);
    final Settings settings = new Settings();
    settings.addProfile(profile);
    final MavenLocationExpander ex = new MavenLocationExpander(Collections.<Location>emptyList(), Collections.<ArtifactRepository>emptyList(), local, new DefaultMirrorSelector(), settings, Collections.<String>singletonList(profile.getId()));
    final List<Location> result = ex.expand(MavenLocationExpander.EXPANSION_TARGET);
    assertThat(result.size(), equalTo(2));
    final Iterator<Location> iterator = result.iterator();
    Location loc = iterator.next();
    assertThat(loc.getName(), equalTo(local.getId()));
    assertThat(loc.getUri(), equalTo(local.getUrl()));
    loc = iterator.next();
    assertThat(loc.getName(), equalTo(remote.getId()));
    assertThat(loc.getUri(), equalTo(remote.getUrl()));
}
Also used : ArtifactRepositoryLayout(org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) DefaultMirrorSelector(org.apache.maven.repository.DefaultMirrorSelector) Profile(org.apache.maven.settings.Profile) Repository(org.apache.maven.settings.Repository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) File(java.io.File) Settings(org.apache.maven.settings.Settings) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Aggregations

File (java.io.File)2 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)2 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)2 ArtifactRepositoryLayout (org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout)2 DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)2 DefaultMirrorSelector (org.apache.maven.repository.DefaultMirrorSelector)2 Settings (org.apache.maven.settings.Settings)2 Location (org.commonjava.maven.galley.model.Location)2 Test (org.junit.Test)2 Mirror (org.apache.maven.settings.Mirror)1 Profile (org.apache.maven.settings.Profile)1 Repository (org.apache.maven.settings.Repository)1