Search in sources :

Example 96 with Artifact

use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.

the class TestCopyDependenciesMojo2 method testCopyDependenciesMojoIncludeRuntimeScope.

public void testCopyDependenciesMojoIncludeRuntimeScope() throws Exception {
    mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts());
    mojo.getProject().setDependencyArtifacts(new HashSet<Artifact>());
    mojo.includeScope = "runtime";
    mojo.execute();
    ScopeArtifactFilter saf = new ScopeArtifactFilter(mojo.includeScope);
    Set<Artifact> artifacts = mojo.getProject().getArtifacts();
    for (Artifact artifact : artifacts) {
        String fileName = DependencyUtil.getFormattedFileName(artifact, false);
        File file = new File(mojo.outputDirectory, fileName);
        assertEquals(saf.include(artifact), file.exists());
    }
}
Also used : ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 97 with Artifact

use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.

the class TestCopyDependenciesMojo2 method testCopyDependenciesMojoIncludeprovidedScope.

public void testCopyDependenciesMojoIncludeprovidedScope() throws Exception {
    mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts());
    mojo.getProject().setDependencyArtifacts(new HashSet<Artifact>());
    mojo.includeScope = "provided";
    mojo.execute();
    Set<Artifact> artifacts = mojo.getProject().getArtifacts();
    for (Artifact artifact : artifacts) {
        String fileName = DependencyUtil.getFormattedFileName(artifact, false);
        File file = new File(mojo.outputDirectory, fileName);
        assertEquals(Artifact.SCOPE_PROVIDED.equals(artifact.getScope()), file.exists());
    }
}
Also used : File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 98 with Artifact

use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.

the class TestCopyDependenciesMojo2 method createExpandedVersionArtifact.

private Artifact createExpandedVersionArtifact(String baseVersion, String groupId, String artifactId, String scope, String type, String classifier) throws IOException {
    Artifact expandedSnapshot = this.stubFactory.createArtifact(groupId, artifactId, VersionRange.createFromVersion(baseVersion), scope, type, classifier, false);
    Snapshot snapshot = new Snapshot();
    snapshot.setTimestamp("20130710.122148");
    snapshot.setBuildNumber(1);
    RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata(expandedSnapshot, snapshot);
    String newVersion = snapshot.getTimestamp() + "-" + snapshot.getBuildNumber();
    expandedSnapshot.setResolvedVersion(StringUtils.replace(baseVersion, Artifact.SNAPSHOT_VERSION, newVersion));
    expandedSnapshot.addMetadata(metadata);
    return expandedSnapshot;
}
Also used : Snapshot(org.apache.maven.artifact.repository.metadata.Snapshot) RepositoryMetadata(org.apache.maven.artifact.repository.metadata.RepositoryMetadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) Artifact(org.apache.maven.artifact.Artifact)

Example 99 with Artifact

use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.

the class TestCopyDependenciesMojo2 method testSubPerArtifactAndTypeRemoveVersion.

public void testSubPerArtifactAndTypeRemoveVersion() throws Exception {
    mojo.getProject().setArtifacts(stubFactory.getTypedArtifacts());
    mojo.getProject().setDependencyArtifacts(new HashSet<Artifact>());
    mojo.useSubDirectoryPerArtifact = true;
    mojo.useSubDirectoryPerType = true;
    mojo.stripVersion = true;
    mojo.execute();
    Set<Artifact> artifacts = mojo.getProject().getArtifacts();
    for (Artifact artifact : artifacts) {
        String fileName = DependencyUtil.getFormattedFileName(artifact, true);
        File folder = DependencyUtil.getFormattedOutputDirectory(false, true, true, false, true, mojo.outputDirectory, artifact);
        File file = new File(folder, fileName);
        assertTrue(file.exists());
    }
}
Also used : File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 100 with Artifact

use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.

the class TestCopyDependenciesMojo2 method testSubPerArtifact.

public void testSubPerArtifact() throws Exception {
    mojo.useSubDirectoryPerArtifact = true;
    mojo.execute();
    Set<Artifact> artifacts = mojo.getProject().getArtifacts();
    for (Artifact artifact : artifacts) {
        String fileName = DependencyUtil.getFormattedFileName(artifact, false);
        File folder = DependencyUtil.getFormattedOutputDirectory(false, false, true, false, false, mojo.outputDirectory, artifact);
        File file = new File(folder, fileName);
        assertTrue(file.exists());
    }
}
Also used : File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

Artifact (org.apache.maven.artifact.Artifact)450 File (java.io.File)175 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)92 ArrayList (java.util.ArrayList)91 MavenProject (org.apache.maven.project.MavenProject)63 IOException (java.io.IOException)50 HashSet (java.util.HashSet)42 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)32 LinkedHashSet (java.util.LinkedHashSet)29 MojoFailureException (org.apache.maven.plugin.MojoFailureException)24 HashMap (java.util.HashMap)22 Set (java.util.Set)22 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)22 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)21 URL (java.net.URL)20 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)20 Test (org.junit.Test)20 MalformedURLException (java.net.MalformedURLException)18 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)17 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)16