Search in sources :

Example 6 with ArtifactRepositoryPolicy

use of org.apache.maven.artifact.repository.ArtifactRepositoryPolicy 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)

Example 7 with ArtifactRepositoryPolicy

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();
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)7 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)6 ArrayList (java.util.ArrayList)3 Artifact (org.apache.maven.artifact.Artifact)3 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)3 DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 File (java.io.File)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 ScriptException (javax.script.ScriptException)1 ArtifactFactory (org.apache.maven.artifact.factory.ArtifactFactory)1 DefaultArtifactRepository (org.apache.maven.artifact.repository.DefaultArtifactRepository)1 AbstractArtifactResolutionException (org.apache.maven.artifact.resolver.AbstractArtifactResolutionException)1