Search in sources :

Example 1 with ArtifactRepositoryPolicy

use of org.apache.maven.artifact.repository.ArtifactRepositoryPolicy in project fabric8 by jboss-fuse.

the class DeployToProfileMojo method addNeededRemoteRepository.

@SuppressWarnings("unchecked")
private void addNeededRemoteRepository() {
    // TODO: Remove this code when we use releases from Maven Central
    // included jboss-fs repo which is required until we use an Apache version of Karaf
    boolean found = false;
    if (remoteRepositories != null) {
        for (Object obj : remoteRepositories) {
            if (obj instanceof ArtifactRepository) {
                ArtifactRepository repo = (ArtifactRepository) obj;
                if (repo.getUrl().contains("repository.jboss.org/nexus/content/groups/fs-public")) {
                    found = true;
                    getLog().debug("Found existing (" + repo.getId() + ") remote repository: " + repo.getUrl());
                    break;
                }
            }
        }
    }
    if (!found) {
        ArtifactRepository fsPublic = new MavenArtifactRepository();
        fsPublic.setId("jboss-public-fs");
        fsPublic.setUrl("http://repository.jboss.org/nexus/content/groups/fs-public/");
        fsPublic.setLayout(new DefaultRepositoryLayout());
        fsPublic.setReleaseUpdatePolicy(new ArtifactRepositoryPolicy(true, "never", "warn"));
        fsPublic.setSnapshotUpdatePolicy(new ArtifactRepositoryPolicy(false, "never", "ignore"));
        if (remoteRepositories == null) {
            remoteRepositories = new ArrayList();
        }
        remoteRepositories.add(fsPublic);
        getLog().info("Adding needed remote repository: http://repository.jboss.org/nexus/content/groups/fs-public/");
    }
}
Also used : ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) ArrayList(java.util.ArrayList) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository)

Example 2 with ArtifactRepositoryPolicy

use of org.apache.maven.artifact.repository.ArtifactRepositoryPolicy in project maven-dependency-plugin by apache.

the class TestGetMojo method testParseRepository.

/**
 * Test parsing of the remote repositories parameter
 *
 * @throws Exception in case of errors
 */
public void testParseRepository() throws Exception {
    ArtifactRepository repo;
    ArtifactRepositoryPolicy policy = null;
    repo = mojo.parseRepository("central::default::http://repo1.maven.apache.org/maven2", policy);
    assertEquals("central", repo.getId());
    assertEquals(DefaultRepositoryLayout.class, repo.getLayout().getClass());
    assertEquals("http://repo1.maven.apache.org/maven2", repo.getUrl());
    try {
        repo = mojo.parseRepository("central::legacy::http://repo1.maven.apache.org/maven2", policy);
        fail("Exception expected: legacy repository not supported anymore");
    } catch (MojoFailureException e) {
    }
    repo = mojo.parseRepository("central::::http://repo1.maven.apache.org/maven2", policy);
    assertEquals("central", repo.getId());
    assertEquals(DefaultRepositoryLayout.class, repo.getLayout().getClass());
    assertEquals("http://repo1.maven.apache.org/maven2", repo.getUrl());
    repo = mojo.parseRepository("http://repo1.maven.apache.org/maven2", policy);
    assertEquals("temp", repo.getId());
    assertEquals(DefaultRepositoryLayout.class, repo.getLayout().getClass());
    assertEquals("http://repo1.maven.apache.org/maven2", repo.getUrl());
    try {
        mojo.parseRepository("::::http://repo1.maven.apache.org/maven2", policy);
        fail("Exception expected");
    } catch (MojoFailureException e) {
    // expected
    }
    try {
        mojo.parseRepository("central::http://repo1.maven.apache.org/maven2", policy);
        fail("Exception expected");
    } catch (MojoFailureException e) {
    // expected
    }
}
Also used : ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository)

Example 3 with ArtifactRepositoryPolicy

use of org.apache.maven.artifact.repository.ArtifactRepositoryPolicy in project spring-cloud-function by spring-cloud.

the class DependencyResolutionModule method repo.

private ArtifactRepository repo(String id, String url, boolean releases, boolean snapshots) {
    MavenArtifactRepository repository = new MavenArtifactRepository();
    repository.setLayout(new DefaultRepositoryLayout());
    repository.setId(id);
    repository.setUrl(url);
    ArtifactRepositoryPolicy enabled = new ArtifactRepositoryPolicy();
    enabled.setEnabled(true);
    ArtifactRepositoryPolicy disabled = new ArtifactRepositoryPolicy();
    disabled.setEnabled(false);
    repository.setReleaseUpdatePolicy(releases ? enabled : disabled);
    repository.setSnapshotUpdatePolicy(snapshots ? enabled : disabled);
    return repository;
}
Also used : ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository)

Example 4 with ArtifactRepositoryPolicy

use of org.apache.maven.artifact.repository.ArtifactRepositoryPolicy in project wildfly-swarm by wildfly-swarm.

the class MavenArtifactResolvingHelperTest method propagateRepositoryPolicies.

@Test
public // SWARM-1173: swarm-plugin trying to download SNAPSHOTs from Maven Central
void propagateRepositoryPolicies() {
    RepositorySystemSession sessionMock = Mockito.mock(RepositorySystemSession.class);
    MirrorSelector mirrorSelectorMock = Mockito.mock(MirrorSelector.class);
    Mockito.when(sessionMock.getMirrorSelector()).thenReturn(mirrorSelectorMock);
    ProxySelector proxySelectorMock = Mockito.mock(ProxySelector.class);
    Mockito.when(sessionMock.getProxySelector()).thenReturn(proxySelectorMock);
    MavenArtifactResolvingHelper artifactResolverHelper = new MavenArtifactResolvingHelper(null, null, sessionMock, null);
    ArtifactRepositoryPolicy testSnapshotPolicy = new ArtifactRepositoryPolicy(false, "hourly", "warn");
    ArtifactRepositoryPolicy testReleasesPolicy = new ArtifactRepositoryPolicy(true, "never", "warn");
    ArtifactRepository testingRepo = new MavenArtifactRepository("testing-repo", "http://testing-repo.org", new DefaultRepositoryLayout(), testSnapshotPolicy, testReleasesPolicy);
    artifactResolverHelper.remoteRepository(testingRepo);
    List<RemoteRepository> remoteRepos = artifactResolverHelper.getRemoteRepositories();
    Assert.assertTrue("Remote repositories " + remoteRepos + " do not contain expected testing repo " + testingRepo, remoteRepos.stream().anyMatch(remoteRepo -> {
        RepositoryPolicy snapshotsPolicy = remoteRepo.getPolicy(true);
        RepositoryPolicy releasesPolicy = remoteRepo.getPolicy(false);
        return remoteRepo.getId().equals(testingRepo.getId()) && !snapshotsPolicy.isEnabled() && snapshotsPolicy.getUpdatePolicy().equals(testSnapshotPolicy.getUpdatePolicy()) && snapshotsPolicy.getChecksumPolicy().equals(testSnapshotPolicy.getChecksumPolicy()) && releasesPolicy.isEnabled() && releasesPolicy.getUpdatePolicy().equals(testReleasesPolicy.getUpdatePolicy()) && releasesPolicy.getChecksumPolicy().equals(testReleasesPolicy.getChecksumPolicy());
    }));
}
Also used : ProxySelector(org.eclipse.aether.repository.ProxySelector) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) ProxySelector(org.eclipse.aether.repository.ProxySelector) Test(org.junit.Test) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Mockito(org.mockito.Mockito) List(java.util.List) MirrorSelector(org.eclipse.aether.repository.MirrorSelector) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Assert(org.junit.Assert) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) MirrorSelector(org.eclipse.aether.repository.MirrorSelector) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Test(org.junit.Test)

Example 5 with ArtifactRepositoryPolicy

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

the class MavenLocationExpander method addSettingsProfileRepositoriesTo.

private void addSettingsProfileRepositoriesTo(final Set<Location> locs, final Settings settings, final List<String> activeProfiles, final MirrorSelector mirrorSelector) throws MalformedURLException {
    if (settings != null) {
        final Map<String, Profile> profiles = settings.getProfilesAsMap();
        if (profiles != null && activeProfiles != null && !activeProfiles.isEmpty()) {
            final LinkedHashSet<String> active = new LinkedHashSet<>(activeProfiles);
            final List<String> settingsActiveProfiles = settings.getActiveProfiles();
            if (settingsActiveProfiles != null && !settingsActiveProfiles.isEmpty()) {
                active.addAll(settingsActiveProfiles);
            }
            for (final String profileId : active) {
                final Profile profile = profiles.get(profileId);
                if (profile != null) {
                    final List<Repository> repositories = profile.getRepositories();
                    if (repositories != null) {
                        final List<Mirror> mirrors = settings.getMirrors();
                        final ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
                        for (final Repository repo : repositories) {
                            String id = repo.getId();
                            String url = repo.getUrl();
                            if (mirrors != null) {
                                final ArtifactRepositoryPolicy snapshots = convertPolicy(repo.getSnapshots());
                                final ArtifactRepositoryPolicy releases = convertPolicy(repo.getReleases());
                                final MavenArtifactRepository arepo = new MavenArtifactRepository(id, url, layout, snapshots, releases);
                                final Mirror mirror = mirrorSelector == null ? null : mirrorSelector.getMirror(arepo, mirrors);
                                if (mirror != null) {
                                    id = mirror.getId();
                                    url = mirror.getUrl();
                                }
                                SimpleHttpLocation addition = new SimpleHttpLocation(id, url, snapshots.isEnabled(), releases.isEnabled(), true, false, null);
                                addition.setAttribute(Location.CONNECTION_TIMEOUT_SECONDS, 60);
                                locs.add(addition);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArtifactRepositoryLayout(org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout) SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) 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) Mirror(org.apache.maven.settings.Mirror)

Aggregations

ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)26 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)20 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)16 DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)16 ArrayList (java.util.ArrayList)5 MojoFailureException (org.apache.maven.plugin.MojoFailureException)5 File (java.io.File)4 Artifact (org.apache.maven.artifact.Artifact)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 ArtifactRepositoryLayout (org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout)3 Mirror (org.apache.maven.settings.Mirror)3 Location (org.commonjava.maven.galley.model.Location)3 List (java.util.List)2 ArtifactFactory (org.apache.maven.artifact.factory.ArtifactFactory)2 DefaultArtifactRepository (org.apache.maven.artifact.repository.DefaultArtifactRepository)2 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)2 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)2 DefaultMirrorSelector (org.apache.maven.repository.DefaultMirrorSelector)2 Profile (org.apache.maven.settings.Profile)2 Repository (org.apache.maven.settings.Repository)2