Search in sources :

Example 16 with MavenArtifactRepository

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()));
}
Also used : ArtifactRepositoryLayout(org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) DefaultMirrorSelector(org.apache.maven.repository.DefaultMirrorSelector) 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) File(java.io.File) Settings(org.apache.maven.settings.Settings) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 17 with MavenArtifactRepository

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;
}
Also used : ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 18 with MavenArtifactRepository

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;
}
Also used : P2ArtifactRepositoryLayout(org.eclipse.tycho.core.p2.P2ArtifactRepositoryLayout) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository)

Example 19 with MavenArtifactRepository

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);
}
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 20 with MavenArtifactRepository

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);
        }
    }
}
Also used : ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) 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) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

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