Search in sources :

Example 1 with MavenArtifactRepository

use of org.apache.maven.artifact.repository.MavenArtifactRepository 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 MavenArtifactRepository

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

the class GetMojo method parseRepository.

ArtifactRepository parseRepository(String repo, ArtifactRepositoryPolicy policy) throws MojoFailureException {
    // if it's a simple url
    String id = "temp";
    ArtifactRepositoryLayout layout = getLayout("default");
    String url = repo;
    // if it's an extended repo URL of the form id::layout::url
    if (repo.contains("::")) {
        Matcher matcher = ALT_REPO_SYNTAX_PATTERN.matcher(repo);
        if (!matcher.matches()) {
            throw new MojoFailureException(repo, "Invalid syntax for repository: " + repo, "Invalid syntax for repository. Use \"id::layout::url\" or \"URL\".");
        }
        id = matcher.group(1).trim();
        if (!StringUtils.isEmpty(matcher.group(2))) {
            layout = getLayout(matcher.group(2).trim());
        }
        url = matcher.group(3).trim();
    }
    return new MavenArtifactRepository(id, url, layout, policy, policy);
}
Also used : ArtifactRepositoryLayout(org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout) Matcher(java.util.regex.Matcher) MojoFailureException(org.apache.maven.plugin.MojoFailureException) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository)

Example 3 with MavenArtifactRepository

use of org.apache.maven.artifact.repository.MavenArtifactRepository 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 MavenArtifactRepository

use of org.apache.maven.artifact.repository.MavenArtifactRepository 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 MavenArtifactRepository

use of org.apache.maven.artifact.repository.MavenArtifactRepository 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

MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)26 ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)18 DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)17 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)14 File (java.io.File)6 ArtifactRepositoryLayout (org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout)6 MavenSession (org.apache.maven.execution.MavenSession)4 Settings (org.apache.maven.settings.Settings)4 Location (org.commonjava.maven.galley.model.Location)3 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 Artifact (org.apache.maven.artifact.Artifact)2 ArtifactFactory (org.apache.maven.artifact.factory.ArtifactFactory)2 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)2 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)2 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 DefaultMirrorSelector (org.apache.maven.repository.DefaultMirrorSelector)2 Mirror (org.apache.maven.settings.Mirror)2 Profile (org.apache.maven.settings.Profile)2