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