use of org.apache.maven.artifact.DefaultArtifact in project maven-plugins by apache.
the class RemoteResourcesMojoTest method testSimpleBundlesWithType.
public void testSimpleBundlesWithType() throws Exception {
final MavenProjectResourcesStub project = createTestProject("default-simplebundles");
final ProcessRemoteResourcesMojo mojo = lookupProcessMojoWithSettings(project, new String[] { "test:test:1.0:war" });
setupDefaultProject(project);
ArtifactRepository repo = (ArtifactRepository) getVariableValueFromObject(mojo, "localRepository");
String path = repo.pathOf(new DefaultArtifact("test", "test", VersionRange.createFromVersion("1.0"), null, "war", "", new DefaultArtifactHandler()));
File file = new File(repo.getBasedir() + "/" + path + ".war");
file.getParentFile().mkdirs();
buildResourceBundle("default-simplebundles-create", null, new String[] { "SIMPLE.txt" }, file);
mojo.execute();
file = (File) getVariableValueFromObject(mojo, "outputDirectory");
file = new File(file, "SIMPLE.txt");
assertTrue(file.exists());
}
use of org.apache.maven.artifact.DefaultArtifact in project maven-plugins by apache.
the class RemoteResourcesMojoTest method testFilteredBundlesWithProjectProperties.
public void testFilteredBundlesWithProjectProperties() throws Exception {
final MavenProjectResourcesStub project = createTestProject("default-filterbundles-two");
final ProcessRemoteResourcesMojo mojo = lookupProcessMojoWithSettings(project, new String[] { "test-filtered-bundles:test-filtered-bundles:2" });
mojo.includeProjectProperties = true;
setupDefaultProject(project);
project.addProperty("testingPropertyOne", "maven");
project.addProperty("testingPropertyTwo", "rules");
ArtifactRepository repo = (ArtifactRepository) getVariableValueFromObject(mojo, "localRepository");
String path = repo.pathOf(new DefaultArtifact("test-filtered-bundles", "test-filtered-bundles", VersionRange.createFromVersion("2"), null, "jar", "", new DefaultArtifactHandler()));
File file = new File(repo.getBasedir() + "/" + path + ".jar");
file.getParentFile().mkdirs();
buildResourceBundle("default-filterbundles-two-create", null, new String[] { "PROPERTIES.txt.vm" }, file);
mojo.execute();
// executing a second time (example: forked lifecycle) should still work
mojo.execute();
file = (File) getVariableValueFromObject(mojo, "outputDirectory");
file = new File(file, "PROPERTIES.txt");
assertTrue(file.exists());
String data = FileUtils.fileRead(file);
assertTrue(data.contains("maven"));
assertTrue(data.contains("rules"));
}
use of org.apache.maven.artifact.DefaultArtifact in project maven-plugins by apache.
the class ShadeMojoTest method testShadeWithFilter.
/**
* Tests if a Filter is installed correctly, also if createSourcesJar is set to true.
*
* @throws Exception
*/
public void testShadeWithFilter() throws Exception {
ShadeMojo mojo = new ShadeMojo();
// set createSourcesJar = true
Field createSourcesJar = ShadeMojo.class.getDeclaredField("createSourcesJar");
createSourcesJar.setAccessible(true);
createSourcesJar.set(mojo, Boolean.TRUE);
// configure artifactResolver (mocked) for mojo
ArtifactResolver mockArtifactResolver = new ArtifactResolver() {
@Override
public ArtifactResult resolveArtifact(ProjectBuildingRequest req, final Artifact art) throws ArtifactResolverException {
return new ArtifactResult() {
@Override
public Artifact getArtifact() {
art.setResolved(true);
String fileName = art.getArtifactId() + "-" + art.getVersion() + (art.getClassifier() != null ? "-" + art.getClassifier() : "") + ".jar";
art.setFile(new File(fileName));
return art;
}
};
}
@Override
public ArtifactResult resolveArtifact(ProjectBuildingRequest req, final ArtifactCoordinate coordinate) throws ArtifactResolverException {
return new ArtifactResult() {
@Override
public Artifact getArtifact() {
Artifact art = mock(Artifact.class);
when(art.getGroupId()).thenReturn(coordinate.getGroupId());
when(art.getArtifactId()).thenReturn(coordinate.getArtifactId());
when(art.getType()).thenReturn(coordinate.getExtension());
when(art.getClassifier()).thenReturn(coordinate.getClassifier());
when(art.isResolved()).thenReturn(true);
String fileName = coordinate.getArtifactId() + "-" + coordinate.getVersion() + (coordinate.getClassifier() != null ? "-" + coordinate.getClassifier() : "") + ".jar";
when(art.getFile()).thenReturn(new File(fileName));
return art;
}
};
}
};
Field artifactResolverField = ShadeMojo.class.getDeclaredField("artifactResolver");
artifactResolverField.setAccessible(true);
artifactResolverField.set(mojo, mockArtifactResolver);
// create and configure MavenProject
MavenProject project = new MavenProject();
ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE);
Artifact artifact = new DefaultArtifact("org.apache.myfaces.core", "myfaces-impl", VersionRange.createFromVersion("2.0.1-SNAPSHOT"), "compile", "jar", null, artifactHandler);
// setFile and setResolved
artifact = mockArtifactResolver.resolveArtifact(null, artifact).getArtifact();
project.setArtifact(artifact);
Field projectField = ShadeMojo.class.getDeclaredField("project");
projectField.setAccessible(true);
projectField.set(mojo, project);
// create and configure the ArchiveFilter
ArchiveFilter archiveFilter = new ArchiveFilter();
Field archiveFilterArtifact = ArchiveFilter.class.getDeclaredField("artifact");
archiveFilterArtifact.setAccessible(true);
archiveFilterArtifact.set(archiveFilter, "org.apache.myfaces.core:myfaces-impl");
// add ArchiveFilter to mojo
Field filtersField = ShadeMojo.class.getDeclaredField("filters");
filtersField.setAccessible(true);
filtersField.set(mojo, new ArchiveFilter[] { archiveFilter });
Field sessionField = ShadeMojo.class.getDeclaredField("session");
sessionField.setAccessible(true);
sessionField.set(mojo, mock(MavenSession.class));
// invoke getFilters()
Method getFilters = ShadeMojo.class.getDeclaredMethod("getFilters", new Class[0]);
getFilters.setAccessible(true);
List<Filter> filters = (List<Filter>) getFilters.invoke(mojo);
// assertions - there must be one filter
assertEquals(1, filters.size());
// the filter must be able to filter the binary and the sources jar
Filter filter = filters.get(0);
// binary jar
assertTrue(filter.canFilter(new File("myfaces-impl-2.0.1-SNAPSHOT.jar")));
// sources jar
assertTrue(filter.canFilter(new File("myfaces-impl-2.0.1-SNAPSHOT-sources.jar")));
}
use of org.apache.maven.artifact.DefaultArtifact in project maven-plugins by apache.
the class AbstractAntTestMavenProjectStub method getTestArtifacts.
/**
* @see org.apache.maven.project.MavenProject#getTestArtifacts()
*/
public List getTestArtifacts() {
Artifact junit = new DefaultArtifact("junit", "junit", VersionRange.createFromVersion("3.8.2"), Artifact.SCOPE_TEST, "jar", null, new DefaultArtifactHandler("jar"), false);
junit.setFile(new File("junit/junit/3.8.2/junit-3.8.2.jar"));
return Collections.singletonList(junit);
}
use of org.apache.maven.artifact.DefaultArtifact in project maven-plugins by apache.
the class AbstractAntTestMavenProjectStub method getCompileArtifacts.
/**
* @see org.apache.maven.project.MavenProject#getCompileArtifacts()
*/
public List getCompileArtifacts() {
Artifact junit = new DefaultArtifact("junit", "junit", VersionRange.createFromVersion("3.8.2"), Artifact.SCOPE_TEST, "jar", null, new DefaultArtifactHandler("jar"), false);
junit.setFile(new File("junit/junit/3.8.2/junit-3.8.2.jar"));
return Collections.singletonList(junit);
}
Aggregations