Search in sources :

Example 16 with ArtifactRepositoryPolicy

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

Example 17 with ArtifactRepositoryPolicy

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);
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArrayList(java.util.ArrayList) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

Example 18 with ArtifactRepositoryPolicy

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()));
}
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 19 with ArtifactRepositoryPolicy

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);
            }
        }
    }
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) Mirror(org.apache.maven.settings.Mirror)

Example 20 with ArtifactRepositoryPolicy

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);
    }
}
Also used : ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Artifact(org.apache.maven.artifact.Artifact) URISyntaxException(java.net.URISyntaxException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) ScriptException(javax.script.ScriptException) OpenEJBException(org.apache.openejb.OpenEJBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchElementException(java.util.NoSuchElementException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

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