use of org.apache.maven.artifact.repository.MavenArtifactRepository 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.MavenArtifactRepository in project fabric8-maven-plugin by fabric8io.
the class AbstractArtifactSearchMojo method resolveArtifactFile.
protected File resolveArtifactFile(HelmIndexMojo.ArtifactDTO artifactDTO, String classifier, String extension) {
File file = null;
try {
ArtifactRequest artifactRequest = new ArtifactRequest();
org.eclipse.aether.artifact.Artifact artifact = new DefaultArtifact(artifactDTO.getG(), artifactDTO.getA(), classifier, extension, artifactDTO.getV());
artifactRequest.setArtifact(artifact);
// convert maven remote repositories to Aether repos
List<RemoteRepository> aetherRepoList = new ArrayList<>();
for (MavenArtifactRepository remoteRepository : remoteRepositories) {
RemoteRepository.Builder builder = new RemoteRepository.Builder(remoteRepository.getId(), remoteRepository.getLayout().getId(), remoteRepository.getUrl());
RemoteRepository aetherRepo = builder.build();
aetherRepoList.add(aetherRepo);
}
artifactRequest.setRepositories(aetherRepoList);
ArtifactResult artifactResult = artifactResolver.resolveArtifact(repoSession, artifactRequest);
org.eclipse.aether.artifact.Artifact resolvedArtifact = artifactResult.getArtifact();
if (resolvedArtifact == null) {
getLog().warn("Could not resolve artifact " + artifactDTO.description());
return null;
}
file = resolvedArtifact.getFile();
} catch (Exception e) {
getLog().warn("Failed to resolve manifest manifest for " + artifactDTO.description() + ". " + e, e);
return null;
}
if (file == null) {
getLog().warn("Could not resolve artifact file for " + artifactDTO.description());
return null;
}
if (!file.isFile() || !file.exists()) {
getLog().warn("Resolved artifact file does not exist for " + artifactDTO.description());
return null;
}
return file;
}
use of org.apache.maven.artifact.repository.MavenArtifactRepository in project tycho by eclipse.
the class TychoMirrorSelectorTest method createArtifactRepository.
private ArtifactRepository createArtifactRepository(String id, String url) {
ArtifactRepository repository = new MavenArtifactRepository();
repository.setId(id);
repository.setUrl(url);
repository.setLayout(new P2ArtifactRepositoryLayout());
return repository;
}
use of org.apache.maven.artifact.repository.MavenArtifactRepository in project maven-plugins 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);
}
use of org.apache.maven.artifact.repository.MavenArtifactRepository in project maven-plugins 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);
}
}
}
Aggregations