use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.
the class WarDependenciesAnalysisTest method testDependencyNowProvided.
public void testDependencyNowProvided() throws Exception {
// setup test data
final String testId = "dependency-now-provided";
final ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
ArtifactStub jarArtifact = new JarArtifactStub(getBasedir(), artifactHandler);
jarArtifact.setArtifactId("lib-test");
jarArtifact.setVersion("1.0");
ArtifactStub jarArtifact2 = new JarArtifactStub(getBasedir(), artifactHandler);
jarArtifact2.setArtifactId("lib-test");
jarArtifact2.setVersion("1.0");
jarArtifact2.setScope(Artifact.SCOPE_PROVIDED);
doTestTwiceWithUpdatedDependency(testId, new ArtifactStub[] { jarArtifact }, new ArtifactStub[] { jarArtifact2 }, new String[] { "WEB-INF/lib/lib-test-1.0.jar" }, null);
}
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 sling by apache.
the class PreparePackageMojoTest method getMojoUnderTest.
private PreparePackageMojo getMojoUnderTest(String... knownArtifacts) throws Exception {
File mrr = getMavenRepoRoot();
ArtifactHandler ah = Mockito.mock(ArtifactHandler.class);
ArtifactHandlerManager ahm = Mockito.mock(ArtifactHandlerManager.class);
Mockito.when(ahm.getArtifactHandler(Mockito.anyString())).thenReturn(ah);
Set<org.apache.maven.artifact.Artifact> artifacts = new HashSet<>();
for (String s : knownArtifacts) {
String[] parts = s.split("[/]");
switch(parts.length) {
case 3:
artifacts.add(getMavenArtifact(mrr, ah, parts[0], parts[1], parts[2]));
break;
case 4:
artifacts.add(getMavenArtifact(mrr, ah, parts[0], parts[1], parts[2], parts[3]));
break;
default:
throw new IllegalStateException(s);
}
}
MavenProject mavenPrj = new MavenProject();
Build build = new Build();
Path tempDir = Files.createTempDirectory(getClass().getSimpleName());
build.setOutputDirectory(tempDir.toString());
build.setDirectory(tempDir.toString());
mavenPrj.setBuild(build);
mavenPrj.setDependencyArtifacts(artifacts);
PreparePackageMojo ppm = new PreparePackageMojo();
ppm.mavenSession = Mockito.mock(MavenSession.class);
ppm.project = mavenPrj;
ArchiverManager am = Mockito.mock(ArchiverManager.class);
UnArchiver ua = Mockito.mock(UnArchiver.class);
Mockito.when(am.getUnArchiver(Mockito.isA(File.class))).thenReturn(ua);
setPrivateField(ppm, "archiverManager", am);
setPrivateField(ppm, "artifactHandlerManager", ahm);
setPrivateField(ppm, "resolver", Mockito.mock(ArtifactResolver.class));
return ppm;
}
Aggregations