use of org.apache.maven.artifact.repository.ArtifactRepositoryPolicy in project maven-dependency-plugin by apache.
the class TestCopyDependenciesMojo2 method testRepositoryLayout.
public void testRepositoryLayout() throws Exception {
String baseVersion = "2.0-SNAPSHOT";
String groupId = "testGroupId";
String artifactId = "expanded-snapshot";
Artifact expandedSnapshot = createExpandedVersionArtifact(baseVersion, groupId, artifactId, "compile", "jar", null);
mojo.getProject().getArtifacts().add(expandedSnapshot);
mojo.getProject().getDependencyArtifacts().add(expandedSnapshot);
Artifact pomExpandedSnapshot = createExpandedVersionArtifact(baseVersion, groupId, artifactId, "compile", "pom", null);
mojo.getProject().getArtifacts().add(pomExpandedSnapshot);
mojo.getProject().getDependencyArtifacts().add(pomExpandedSnapshot);
mojo.useRepositoryLayout = true;
mojo.execute();
ArtifactFactory artifactFactory = lookup(ArtifactFactory.class);
File outputDirectory = mojo.outputDirectory;
ArtifactRepository targetRepository = new MavenArtifactRepository("local", outputDirectory.toURL().toExternalForm(), new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy());
Set<Artifact> artifacts = mojo.getProject().getArtifacts();
for (Artifact artifact : artifacts) {
assertArtifactExists(artifact, targetRepository);
if (!artifact.getBaseVersion().equals(artifact.getVersion())) {
Artifact baseArtifact = artifactFactory.createArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact.getScope(), artifact.getType());
assertArtifactExists(baseArtifact, targetRepository);
}
}
}
use of org.apache.maven.artifact.repository.ArtifactRepositoryPolicy in project maven-dependency-plugin by apache.
the class GetMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (isSkip()) {
getLog().info("Skipping plugin execution");
return;
}
if (coordinate.getArtifactId() == null && artifact == null) {
throw new MojoFailureException("You must specify an artifact, " + "e.g. -Dartifact=org.apache.maven.plugins:maven-downloader-plugin:1.0");
}
if (artifact != null) {
String[] tokens = StringUtils.split(artifact, ":");
if (tokens.length < 3 || tokens.length > 5) {
throw new MojoFailureException("Invalid artifact, you must specify " + "groupId:artifactId:version[:packaging[:classifier]] " + artifact);
}
coordinate.setGroupId(tokens[0]);
coordinate.setArtifactId(tokens[1]);
coordinate.setVersion(tokens[2]);
if (tokens.length >= 4) {
coordinate.setType(tokens[3]);
}
if (tokens.length == 5) {
coordinate.setClassifier(tokens[4]);
}
}
ArtifactRepositoryPolicy always = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
List<ArtifactRepository> repoList = new ArrayList<ArtifactRepository>();
if (pomRemoteRepositories != null) {
repoList.addAll(pomRemoteRepositories);
}
if (remoteRepositories != null) {
// Use the same format as in the deploy plugin id::layout::url
List<String> repos = Arrays.asList(StringUtils.split(remoteRepositories, ","));
for (String repo : repos) {
repoList.add(parseRepository(repo, always));
}
}
try {
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setRemoteRepositories(repoList);
if (transitive) {
getLog().info("Resolving " + coordinate + " with transitive dependencies");
dependencyResolver.resolveDependencies(buildingRequest, coordinate, null);
} else {
getLog().info("Resolving " + coordinate);
artifactResolver.resolveArtifact(buildingRequest, toArtifactCoordinate(coordinate));
}
} catch (ArtifactResolverException e) {
throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
} catch (DependencyResolverException e) {
throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
}
}
use of org.apache.maven.artifact.repository.ArtifactRepositoryPolicy 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()));
}
use of org.apache.maven.artifact.repository.ArtifactRepositoryPolicy in project pom-manipulation-ext by release-engineering.
the class MavenLocationExpander method addRequestRepositoriesTo.
private void addRequestRepositoriesTo(final Set<Location> locs, final List<ArtifactRepository> artifactRepositories, final Settings settings, final MirrorSelector mirrorSelector) throws MalformedURLException {
if (artifactRepositories != null) {
for (final ArtifactRepository repo : artifactRepositories) {
// TODO: Authentication via memory password manager.
String id = repo.getId();
String url = repo.getUrl();
if (url.startsWith("file:")) {
locs.add(new SimpleLocation(id, url));
} else {
final List<Mirror> mirrors = settings.getMirrors();
if (mirrors != null) {
final Mirror mirror = mirrorSelector == null ? null : mirrorSelector.getMirror(repo, mirrors);
if (mirror != null) {
id = mirror.getId();
url = mirror.getUrl();
}
}
final ArtifactRepositoryPolicy releases = repo.getReleases();
final ArtifactRepositoryPolicy snapshots = repo.getSnapshots();
SimpleHttpLocation addition = new SimpleHttpLocation(id, url, snapshots != null && snapshots.isEnabled(), releases == null || releases.isEnabled(), true, false, null);
addition.setAttribute(Location.CONNECTION_TIMEOUT_SECONDS, 60);
locs.add(addition);
}
}
}
}
use of org.apache.maven.artifact.repository.ArtifactRepositoryPolicy in project tomee by apache.
the class AbstractTomEEMojo method resolve.
private File resolve() {
if (!settings.isOffline()) {
try {
if ("snapshots".equals(apacheRepos) || "true".equals(apacheRepos)) {
remoteRepos.add(new DefaultArtifactRepository("apache", "https://repository.apache.org/content/repositories/snapshots/", new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(true, UPDATE_POLICY_DAILY, CHECKSUM_POLICY_WARN), new ArtifactRepositoryPolicy(false, UPDATE_POLICY_NEVER, CHECKSUM_POLICY_WARN)));
} else {
try {
// to check it is a uri
new URI(apacheRepos);
remoteRepos.add(new DefaultArtifactRepository("additional-repo-tomee-mvn-plugin", apacheRepos, new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(true, UPDATE_POLICY_DAILY, CHECKSUM_POLICY_WARN), new ArtifactRepositoryPolicy(true, UPDATE_POLICY_NEVER, CHECKSUM_POLICY_WARN)));
} catch (final URISyntaxException e) {
// ignored, use classical repos
}
}
} catch (final UnsupportedOperationException uoe) {
// can happen if remoterepos is unmodifiable (possible in complex builds)
// no-op
}
} else if (remoteRepos != null && remoteRepos.isEmpty()) {
remoteRepos = new ArrayList<>();
}
if ((tomeeClassifier != null && (tomeeClassifier.isEmpty() || tomeeClassifier.equals("ignore"))) || ("org.apache.tomee".equals(tomeeGroupId) && "openejb-standalone".equals(tomeeArtifactId))) {
tomeeClassifier = null;
}
try {
final Artifact artifact = factory.createDependencyArtifact(tomeeGroupId, tomeeArtifactId, createFromVersion(tomeeVersion), tomeeType, tomeeClassifier, SCOPE_COMPILE);
resolver.resolve(artifact, remoteRepos, local);
return artifact.getFile();
} catch (final Exception e) {
getLog().error(e.getMessage(), e);
throw new TomEEException(e.getMessage(), e);
}
}
Aggregations