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
}
}
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();
}
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;
}
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;
}
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();
}
Aggregations