Search in sources :

Example 11 with ArtifactRepositoryPolicy

use of org.apache.maven.artifact.repository.ArtifactRepositoryPolicy in project maven-plugins 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 12 with ArtifactRepositoryPolicy

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

the class DependenciesRenderer method printRepositories.

private void printRepositories(Map<String, ArtifactRepository> repoMap, List<String> repoUrlBlackListed) {
    // i18n
    String repoid = getI18nString("repo.locations.column.repoid");
    String url = getI18nString("repo.locations.column.url");
    String release = getI18nString("repo.locations.column.release");
    String snapshot = getI18nString("repo.locations.column.snapshot");
    String blacklisted = getI18nString("repo.locations.column.blacklisted");
    String releaseEnabled = getI18nString("repo.locations.cell.release.enabled");
    String releaseDisabled = getI18nString("repo.locations.cell.release.disabled");
    String snapshotEnabled = getI18nString("repo.locations.cell.snapshot.enabled");
    String snapshotDisabled = getI18nString("repo.locations.cell.snapshot.disabled");
    String blacklistedEnabled = getI18nString("repo.locations.cell.blacklisted.enabled");
    String blacklistedDisabled = getI18nString("repo.locations.cell.blacklisted.disabled");
    // Table header
    String[] tableHeader;
    int[] justificationRepo;
    if (repoUrlBlackListed.isEmpty()) {
        tableHeader = new String[] { repoid, url, release, snapshot };
        justificationRepo = new int[] { Sink.JUSTIFY_LEFT, Sink.JUSTIFY_LEFT, Sink.JUSTIFY_CENTER, Sink.JUSTIFY_CENTER };
    } else {
        tableHeader = new String[] { repoid, url, release, snapshot, blacklisted };
        justificationRepo = new int[] { Sink.JUSTIFY_LEFT, Sink.JUSTIFY_LEFT, Sink.JUSTIFY_CENTER, Sink.JUSTIFY_CENTER, Sink.JUSTIFY_CENTER };
    }
    startTable(justificationRepo, false);
    tableHeader(tableHeader);
    for (ArtifactRepository repo : repoMap.values()) {
        List<ArtifactRepository> mirroredRepos = getMirroredRepositories(repo);
        sink.tableRow();
        sink.tableCell();
        boolean addLineBreak = false;
        for (ArtifactRepository r : mirroredRepos) {
            if (addLineBreak) {
                sink.lineBreak();
            }
            addLineBreak = true;
            sink.text(r.getId());
        }
        sink.tableCell_();
        sink.tableCell();
        addLineBreak = false;
        for (ArtifactRepository r : mirroredRepos) {
            if (addLineBreak) {
                sink.lineBreak();
            }
            addLineBreak = true;
            if (repo.isBlacklisted()) {
                sink.text(r.getUrl());
            } else {
                sink.link(r.getUrl());
                sink.text(r.getUrl());
                sink.link_();
            }
        }
        sink.tableCell_();
        ArtifactRepositoryPolicy releasePolicy = repo.getReleases();
        tableCell(releasePolicy.isEnabled() ? releaseEnabled : releaseDisabled);
        ArtifactRepositoryPolicy snapshotPolicy = repo.getSnapshots();
        tableCell(snapshotPolicy.isEnabled() ? snapshotEnabled : snapshotDisabled);
        if (!repoUrlBlackListed.isEmpty()) {
            tableCell(repoUrlBlackListed.contains(repo.getUrl()) ? blacklistedEnabled : blacklistedDisabled);
        }
        sink.tableRow_();
    }
    endTable();
}
Also used : ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository)

Example 13 with ArtifactRepositoryPolicy

use of org.apache.maven.artifact.repository.ArtifactRepositoryPolicy in project drools by kiegroup.

the class MavenRepositoryConfiguration method toArtifactRepository.

private ArtifactRepository toArtifactRepository(RemoteRepository remoteRepository) {
    final String id = remoteRepository.getId();
    final String url = remoteRepository.getUrl();
    final Proxy activeProxy = settings.getActiveProxy();
    final ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
    ArtifactRepositoryPolicy snapshots = new ArtifactRepositoryPolicy();
    ArtifactRepositoryPolicy releases = new ArtifactRepositoryPolicy();
    if (remoteRepository.getPolicy(true) != null) {
        snapshots = new ArtifactRepositoryPolicy(remoteRepository.getPolicy(true).isEnabled(), remoteRepository.getPolicy(true).getUpdatePolicy(), remoteRepository.getPolicy(true).getChecksumPolicy());
    }
    if (remoteRepository.getPolicy(false) != null) {
        releases = new ArtifactRepositoryPolicy(remoteRepository.getPolicy(false).isEnabled(), remoteRepository.getPolicy(false).getUpdatePolicy(), remoteRepository.getPolicy(false).getChecksumPolicy());
    }
    final ArtifactRepository artifactRepository = new MavenArtifactRepository(id, url, layout, snapshots, releases);
    final Server server = settings.getServer(id);
    if (server != null) {
        artifactRepository.setAuthentication(new Authentication(server.getUsername(), server.getPassword()));
    }
    if (activeProxy != null) {
        if (null == activeProxy.getNonProxyHosts()) {
            artifactRepository.setProxy(getActiveMavenProxyFromSettings(settings));
        } else if (!repositoryUrlMatchNonProxyHosts(settings.getActiveProxy().getNonProxyHosts(), artifactRepository.getUrl())) {
            artifactRepository.setProxy(getActiveMavenProxyFromSettings(settings));
        }
    }
    return artifactRepository;
}
Also used : ArtifactRepositoryLayout(org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout) Proxy(org.apache.maven.settings.Proxy) Server(org.apache.maven.settings.Server) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) Authentication(org.apache.maven.artifact.repository.Authentication) 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)

Example 14 with ArtifactRepositoryPolicy

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

the class CompileMojoRule method provideLocalRepository.

/**
 * maven-plugin-testing-harness can not inject local repositories (though the real runtime supports it).
 * and the default stubs have no sufficient implementation of getPath():
 * @see "http://maven.apache.org/plugin-testing/maven-plugin-testing-harness/examples/repositories.html"
 */
private ArtifactRepository provideLocalRepository() throws IllegalAccessException {
    DefaultArtifactRepositoryFactory factory = new DefaultArtifactRepositoryFactory();
    setVariableValueToObject(factory, "factory", new org.apache.maven.repository.legacy.repository.DefaultArtifactRepositoryFactory());
    LegacySupport legacySupport = new DefaultLegacySupport();
    setVariableValueToObject(factory, "legacySupport", legacySupport);
    ArtifactRepository localRepository = factory.createArtifactRepository("local", "http://localhost", new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy());
    setVariableValueToObject(localRepository, "basedir", BaseEngineProjectMojoTest.LOCAL_REPOSITORY);
    return localRepository;
}
Also used : LegacySupport(org.apache.maven.plugin.LegacySupport) DefaultLegacySupport(org.apache.maven.plugin.internal.DefaultLegacySupport) DefaultLegacySupport(org.apache.maven.plugin.internal.DefaultLegacySupport) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) DefaultArtifactRepositoryFactory(org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository)

Example 15 with ArtifactRepositoryPolicy

use of org.apache.maven.artifact.repository.ArtifactRepositoryPolicy in project sling by apache.

the class BundleInstallFileMojo method resolveBundleFileFromArtifact.

@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
private String resolveBundleFileFromArtifact() throws MojoExecutionException {
    if (artifactId == null && artifact == null) {
        return null;
    }
    if (artifactId == null) {
        String[] tokens = StringUtils.split(artifact, ":");
        if (tokens.length != 3 && tokens.length != 4 && tokens.length != 5) {
            throw new MojoExecutionException("Invalid artifact, you must specify " + "groupId:artifactId:version[:packaging[:classifier]] " + artifact);
        }
        groupId = tokens[0];
        artifactId = tokens[1];
        version = tokens[2];
        if (tokens.length >= 4)
            packaging = tokens[3];
        if (tokens.length == 5)
            classifier = tokens[4];
    }
    Artifact packageArtifact = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, packaging, classifier);
    if (pomRemoteRepositories == null) {
        pomRemoteRepositories = new ArrayList();
    }
    List repoList = new ArrayList(pomRemoteRepositories);
    if (repositoryUrl != null) {
        ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
        ArtifactRepository remoteRepo = artifactRepositoryFactory.createArtifactRepository(repositoryId, repositoryUrl, repositoryLayout, policy, policy);
        repoList.add(remoteRepo);
    }
    try {
        artifactResolver.resolve(packageArtifact, repoList, localRepository);
        getLog().info("Resolved artifact to " + packageArtifact.getFile().getAbsolutePath());
    } catch (AbstractArtifactResolutionException e) {
        throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
    }
    return packageArtifact.getFile().getAbsolutePath();
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)28 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)21 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)18 DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)18 ArrayList (java.util.ArrayList)5 MojoFailureException (org.apache.maven.plugin.MojoFailureException)5 File (java.io.File)4 Artifact (org.apache.maven.artifact.Artifact)4 ArtifactRepositoryLayout (org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 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