use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.
the class WarExplodedMojoTest method testExplodedWarWithMar.
/**
* @throws Exception in case of an error.
*/
public void testExplodedWarWithMar() throws Exception {
// setup test data
String testId = "ExplodedWarWithMar";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
File webAppDirectory = new File(getTestDirectory(), testId);
File webAppSource = createWebAppSource(testId);
File classesDir = createClassesDir(testId, true);
// Fake here since the mar artifact handler does not exist: no biggie
ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
ArtifactStub marArtifact = new MarArtifactStub(getBasedir(), artifactHandler);
File marFile = marArtifact.getFile();
assertTrue("jar not found: " + marFile.toString(), marFile.exists());
// configure mojo
project.addArtifact(marArtifact);
this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
mojo.execute();
// validate operation
File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
// final name form is <artifactId>-<version>.<type>
File expectedJarArtifact = new File(webAppDirectory, "WEB-INF/modules/marartifact-0.0-Test.jar");
assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
assertTrue("jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists());
// house keeping
expectedWebSourceFile.delete();
expectedWebSource2File.delete();
expectedJarArtifact.delete();
}
use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.
the class WarMojoTest method testFailOnMissingWebXmlNotSpecifiedAndServlet30Used.
public void testFailOnMissingWebXmlNotSpecifiedAndServlet30Used() throws Exception {
String testId = "SimpleWarUnderServlet30";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
File webAppDirectory = new File(getTestDirectory(), testId);
WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
String warName = "simple";
File webAppSource = createWebAppSource(testId);
File classesDir = createClassesDir(testId, true);
final ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
JarArtifactStub jarArtifactStub = new JarArtifactStub(getBasedir(), artifactHandler);
jarArtifactStub.setFile(new File(getBasedir(), "/target/test-classes/unit/sample_wars/javax.servlet-api-3.0.1.jar"));
jarArtifactStub.setScope(Artifact.SCOPE_PROVIDED);
project.addArtifact(jarArtifactStub);
project.setArtifact(warArtifact);
project.setFile(warArtifact.getFile());
this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
setVariableValueToObject(mojo, "outputDirectory", outputDir);
setVariableValueToObject(mojo, "warName", warName);
mojo.execute();
// validate war file
File expectedWarFile = new File(outputDir, "simple.war");
final Map<String, JarEntry> jarContent = assertJarContent(expectedWarFile, new String[] { "META-INF/MANIFEST.MF", "pansit.jsp", "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, null, null, null, null });
assertFalse("web.xml should be missing", jarContent.containsKey("WEB-INF/web.xml"));
}
use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.
the class WarZipTest method buildZipArtifact.
private Artifact buildZipArtifact() throws Exception {
ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
File zipFile = new File(getTestDirectory(), "foobar.zip");
return new ZipArtifactStub("src/test/resources/unit/warziptest", artifactHandler, zipFile);
}
use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.
the class AbstractCompilerMojo method resolveProcessorPathEntries.
private List<String> resolveProcessorPathEntries() throws MojoExecutionException {
if (annotationProcessorPaths == null || annotationProcessorPaths.isEmpty()) {
return null;
}
try {
Set<Artifact> requiredArtifacts = new LinkedHashSet<Artifact>();
for (DependencyCoordinate coord : annotationProcessorPaths) {
ArtifactHandler handler = artifactHandlerManager.getArtifactHandler(coord.getType());
Artifact artifact = new DefaultArtifact(coord.getGroupId(), coord.getArtifactId(), VersionRange.createFromVersionSpec(coord.getVersion()), Artifact.SCOPE_RUNTIME, coord.getType(), coord.getClassifier(), handler, false);
requiredArtifacts.add(artifact);
}
ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(requiredArtifacts.iterator().next()).setResolveRoot(true).setResolveTransitively(true).setArtifactDependencies(requiredArtifacts).setLocalRepository(session.getLocalRepository()).setRemoteRepositories(project.getRemoteArtifactRepositories());
ArtifactResolutionResult resolutionResult = repositorySystem.resolve(request);
resolutionErrorHandler.throwErrors(request, resolutionResult);
List<String> elements = new ArrayList<String>(resolutionResult.getArtifacts().size());
for (Object resolved : resolutionResult.getArtifacts()) {
elements.add(((Artifact) resolved).getFile().getAbsolutePath());
}
return elements;
} catch (Exception e) {
throw new MojoExecutionException("Resolution of annotationProcessorPath dependencies failed: " + e.getLocalizedMessage(), e);
}
}
use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.
the class TestSourcesMarkerFileHandler method setUp.
protected void setUp() throws Exception {
super.setUp();
ArtifactHandler ah = new DefaultArtifactHandler();
VersionRange vr = VersionRange.createFromVersion("1.1");
Artifact artifact = new DefaultArtifact("test", "1", vr, Artifact.SCOPE_COMPILE, "jar", "", ah, false);
artifacts.add(artifact);
artifact = new DefaultArtifact("test", "2", vr, Artifact.SCOPE_PROVIDED, "war", "", ah, false);
artifacts.add(artifact);
artifact = new DefaultArtifact("test", "3", vr, Artifact.SCOPE_TEST, "sources", "", ah, false);
artifacts.add(artifact);
artifact = new DefaultArtifact("test", "4", vr, Artifact.SCOPE_RUNTIME, "zip", "", ah, false);
artifacts.add(artifact);
// pick random output location
Random a = new Random();
outputFolder = new File("target/markers" + a.nextLong() + "/");
outputFolder.delete();
assertFalse(outputFolder.exists());
}
Aggregations