Search in sources :

Example 91 with Artifact

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

the class FilterUtilsTest method testFilterArtifacts_ShouldThrowExceptionUsingStrictModeWithUnmatchedInclude.

public void testFilterArtifacts_ShouldThrowExceptionUsingStrictModeWithUnmatchedInclude() {
    final Artifact artifact = mockManager.createMock(Artifact.class);
    expect(artifact.getGroupId()).andReturn("group").atLeastOnce();
    expect(artifact.getArtifactId()).andReturn("artifact").atLeastOnce();
    expect(artifact.getId()).andReturn("group:artifact:type:version").atLeastOnce();
    expect(artifact.getDependencyConflictId()).andReturn("group:artifact:type").atLeastOnce();
    final List<String> includes = new ArrayList<String>();
    includes.add("other.group:other-artifact:type:version");
    final List<String> excludes = Collections.emptyList();
    final Set<Artifact> artifacts = new HashSet<Artifact>();
    artifacts.add(artifact);
    mockManager.replayAll();
    try {
        FilterUtils.filterArtifacts(artifacts, includes, excludes, true, false, logger);
        fail("Should fail because of unmatched include.");
    } catch (final InvalidAssemblerConfigurationException e) {
    // expected.
    }
    mockManager.verifyAll();
}
Also used : ArrayList(java.util.ArrayList) InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException) Artifact(org.apache.maven.artifact.Artifact) HashSet(java.util.HashSet)

Example 92 with Artifact

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

the class TestCollectMojo method testCollectTestEnvironment.

/**
     * tests the proper discovery and configuration of the mojo
     * 
     * @throws Exception if a problem occurs
     */
public void testCollectTestEnvironment() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml");
    CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo("collect", testPom);
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    MavenProject project = mojo.getProject();
    mojo.setSilent(true);
    Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
    Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
    artifacts.addAll(directArtifacts);
    project.setArtifacts(artifacts);
    project.setDependencyArtifacts(directArtifacts);
    mojo.execute();
    DependencyStatusSets results = mojo.getResults();
    assertNotNull(results);
    assertEquals(artifacts.size(), results.getResolvedDependencies().size());
}
Also used : CollectDependenciesMojo(org.apache.maven.plugins.dependency.resolvers.CollectDependenciesMojo) MavenProject(org.apache.maven.project.MavenProject) DependencyStatusSets(org.apache.maven.plugins.dependency.utils.DependencyStatusSets) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 93 with Artifact

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

the class TestAnalyzeDepMgt method testGetManagementKey.

public void testGetManagementKey() throws IOException {
    Dependency dep = new Dependency();
    dep.setArtifactId("artifact");
    dep.setClassifier("class");
    dep.setGroupId("group");
    dep.setType("type");
    // version isn't used in the key, it can be different
    dep.setVersion("1.1");
    Artifact artifact = stubFactory.createArtifact("group", "artifact", "1.0", Artifact.SCOPE_COMPILE, "type", "class");
    // basic case ok
    assertEquals(dep.getManagementKey(), mojo.getArtifactManagementKey(artifact));
    // now change each one and make sure it fails, then set it back and make
    // sure it's ok before
    // testing the next one
    dep.setType("t");
    assertFalse(dep.getManagementKey().equals(mojo.getArtifactManagementKey(artifact)));
    dep.setType("type");
    assertEquals(dep.getManagementKey(), mojo.getArtifactManagementKey(artifact));
    dep.setArtifactId("a");
    assertFalse(dep.getManagementKey().equals(mojo.getArtifactManagementKey(artifact)));
    dep.setArtifactId("artifact");
    assertEquals(dep.getManagementKey(), mojo.getArtifactManagementKey(artifact));
    dep.setClassifier("c");
    assertFalse(dep.getManagementKey().equals(mojo.getArtifactManagementKey(artifact)));
    dep.setClassifier("class");
    assertEquals(dep.getManagementKey(), mojo.getArtifactManagementKey(artifact));
    dep.setGroupId("g");
    assertFalse(dep.getManagementKey().equals(mojo.getArtifactManagementKey(artifact)));
    dep.setGroupId("group");
    dep.setClassifier(null);
    artifact = stubFactory.createArtifact("group", "artifact", "1.0", Artifact.SCOPE_COMPILE, "type", null);
    assertEquals(dep.getManagementKey(), mojo.getArtifactManagementKey(artifact));
    dep.setClassifier("");
    artifact = stubFactory.createArtifact("group", "artifact", "1.0", Artifact.SCOPE_COMPILE, "type", "");
    assertEquals(dep.getManagementKey(), mojo.getArtifactManagementKey(artifact));
}
Also used : Dependency(org.apache.maven.model.Dependency) Artifact(org.apache.maven.artifact.Artifact)

Example 94 with Artifact

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

the class TestCopyDependenciesMojo2 method testCopyDependenciesMojoIncludesystemScope.

public void testCopyDependenciesMojoIncludesystemScope() throws Exception {
    mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts());
    mojo.getProject().setDependencyArtifacts(new HashSet<Artifact>());
    mojo.includeScope = "system";
    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_SYSTEM.equals(artifact.getScope()), file.exists());
    }
}
Also used : File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 95 with Artifact

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

the class TestCopyDependenciesMojo2 method testCopyDependenciesMojoIncludeTestScope.

public void testCopyDependenciesMojoIncludeTestScope() throws Exception {
    mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts());
    mojo.getProject().setDependencyArtifacts(new HashSet<Artifact>());
    mojo.includeScope = "test";
    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)

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