Search in sources :

Example 11 with MavenProjectArtifactsStub

use of org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub in project maven-plugins by apache.

the class WarExplodedMojoTest method testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies.

/**
 * @throws Exception in case of an error.
 */
public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies() throws Exception {
    // setup test data
    String testId = "ExplodedWarWithFileNameMappingAndDuplicateDependencies";
    MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    File webAppDirectory = new File(getTestDirectory(), testId);
    File webAppSource = createWebAppSource(testId);
    File classesDir = createClassesDir(testId, true);
    EJBArtifactStub ejbArtifact = new EJBArtifactStub(getBasedir());
    EJBArtifactStub ejbArtifactDup = new EJBArtifactStub(getBasedir());
    File ejbFile = ejbArtifact.getFile();
    // ejbArtifact has a hard coded file, only one assert is needed
    assertTrue("ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists());
    // configure mojo
    ejbArtifact.setGroupId("org.sample.ejb");
    ejbArtifactDup.setGroupId("org.dup.ejb");
    project.addArtifact(ejbArtifact);
    project.addArtifact(ejbArtifactDup);
    mojo.setOutputFileNameMapping("@{artifactId}@.@{extension}@");
    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 expectedEJBArtifact = new File(webAppDirectory, "WEB-INF/lib/org.sample.ejb-ejbartifact.jar");
    File expectedEJBDupArtifact = new File(webAppDirectory, "WEB-INF/lib/org.dup.ejb-ejbartifact.jar");
    assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
    assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
    assertTrue("ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists());
    assertTrue("ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists());
    // house keeping
    expectedWebSourceFile.delete();
    expectedWebSource2File.delete();
    expectedEJBArtifact.delete();
    expectedEJBDupArtifact.delete();
}
Also used : MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) EJBArtifactStub(org.apache.maven.plugins.war.stub.EJBArtifactStub) File(java.io.File)

Example 12 with MavenProjectArtifactsStub

use of org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub in project maven-plugins by apache.

the class OverlayManagerTest method testSimpleOverlay.

public void testSimpleOverlay() throws Exception {
    final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    final ArtifactStub first = newWarArtifact("test", "test-webapp");
    project.addArtifact(first);
    final List<Overlay> overlays = new ArrayList<Overlay>();
    overlays.add(new DefaultOverlay(first));
    try {
        final Overlay currentProjectOverlay = Overlay.createInstance();
        OverlayManager manager = new OverlayManager(overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, currentProjectOverlay);
        assertNotNull(manager.getOverlays());
        assertEquals(2, manager.getOverlays().size());
        assertEquals(Overlay.createInstance(), manager.getOverlays().get(0));
        assertEquals(overlays.get(0), manager.getOverlays().get(1));
    } catch (InvalidOverlayConfigurationException e) {
        e.printStackTrace();
        fail("Should not have failed to validate a valid overlay config " + e.getMessage());
    }
}
Also used : DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) OverlayManager(org.apache.maven.plugins.war.overlay.OverlayManager) MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) WarArtifactStub(org.apache.maven.plugins.war.stub.WarArtifactStub) Overlay(org.apache.maven.plugins.war.Overlay) DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) InvalidOverlayConfigurationException(org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException)

Example 13 with MavenProjectArtifactsStub

use of org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub in project maven-plugins by apache.

the class OverlayManagerTest method testOverlaysWithSameArtifactAndGroupId.

public void testOverlaysWithSameArtifactAndGroupId() throws Exception {
    final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    final ArtifactStub first = newWarArtifact("test", "test-webapp");
    final ArtifactStub second = newWarArtifact("test", "test-webapp", "my-classifier");
    project.addArtifact(first);
    project.addArtifact(second);
    final List<Overlay> overlays = new ArrayList<Overlay>();
    overlays.add(new DefaultOverlay(first));
    overlays.add(new DefaultOverlay(second));
    try {
        final Overlay currentProjectOverlay = Overlay.createInstance();
        OverlayManager manager = new OverlayManager(overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, currentProjectOverlay);
        assertNotNull(manager.getOverlays());
        assertEquals(3, manager.getOverlays().size());
        assertEquals(currentProjectOverlay, manager.getOverlays().get(0));
        assertEquals(overlays.get(0), manager.getOverlays().get(1));
        assertEquals(overlays.get(1), manager.getOverlays().get(2));
    } catch (InvalidOverlayConfigurationException e) {
        e.printStackTrace();
        fail("Should not have failed to validate a valid overlay config " + e.getMessage());
    }
}
Also used : DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) OverlayManager(org.apache.maven.plugins.war.overlay.OverlayManager) MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) WarArtifactStub(org.apache.maven.plugins.war.stub.WarArtifactStub) Overlay(org.apache.maven.plugins.war.Overlay) DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) InvalidOverlayConfigurationException(org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException)

Example 14 with MavenProjectArtifactsStub

use of org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub 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();
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MarArtifactStub(org.apache.maven.plugins.war.stub.MarArtifactStub) MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) XarArtifactStub(org.apache.maven.plugins.war.stub.XarArtifactStub) MarArtifactStub(org.apache.maven.plugins.war.stub.MarArtifactStub) EJBArtifactStub(org.apache.maven.plugins.war.stub.EJBArtifactStub) WarArtifactStub(org.apache.maven.plugins.war.stub.WarArtifactStub) PARArtifactStub(org.apache.maven.plugins.war.stub.PARArtifactStub) TLDArtifactStub(org.apache.maven.plugins.war.stub.TLDArtifactStub) IncludeExcludeWarArtifactStub(org.apache.maven.plugins.war.stub.IncludeExcludeWarArtifactStub) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) EJBClientArtifactStub(org.apache.maven.plugins.war.stub.EJBClientArtifactStub) JarArtifactStub(org.apache.maven.plugins.war.stub.JarArtifactStub) AarArtifactStub(org.apache.maven.plugins.war.stub.AarArtifactStub) File(java.io.File)

Example 15 with MavenProjectArtifactsStub

use of org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub in project maven-plugins by apache.

the class WarExplodedMojoTest method testExplodedWar_WithEJB.

// The last modified thingy behavior is not applicable anymore. This is the only test that
// has been removed.
// /**
// * Merge a dependent WAR that gets updated since the last run.
// */
// public void testExplodedWarMergeWarUpdated()
// throws Exception
// {
// // setup test data
// MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
// WarArtifactStub warArtifact = new WarArtifactStub( getBasedir() );
// 
// String testId = "testExplodedWarMergeWarUpdated";
// File webAppDirectory = new File( getTestDirectory(), testId );
// FileUtils.deleteDirectory( webAppDirectory );
// 
// File webAppSource = getWebAppSource( testId );
// 
// File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
// createDir( workDirectory );
// 
// File classesDir = createClassesDir( testId, true );
// 
// // configure mojo
// project.addArtifact( warArtifact );
// this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
// setVariableValueToObject( mojo, "workDirectory", workDirectory );
// mojo.execute();
// 
// // validate operation
// File expectedFile = new File( webAppDirectory, "/org/sample/company/test.jsp" );
// 
// assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
// assertEquals( "file incorrect", "", FileUtils.fileRead( expectedFile ) );
// 
// // update file, so the local one is older
// warArtifact.setFile( new File( warArtifact.getFile().getParentFile(), "simple-updated.war" ) );
// 
// mojo.execute();
// 
// assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
// assertEquals( "file incorrect", "updated\n", FileUtils.fileRead( expectedFile ) );
// 
// // update file, so the local one is newer
// warArtifact.setFile( new File( warArtifact.getFile().getParentFile(), "simple.war" ) );
// 
// mojo.execute();
// 
// assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
// assertEquals( "file incorrect", "updated\n", FileUtils.fileRead( expectedFile ) );
// 
// // house keeping
// expectedFile.delete();
// }
/**
 * @throws Exception in case of an error.
 */
public void testExplodedWar_WithEJB() throws Exception {
    // setup test data
    String testId = "ExplodedWar_WithEJB";
    MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    File webAppDirectory = new File(getTestDirectory(), testId);
    File webAppSource = createWebAppSource(testId);
    File classesDir = createClassesDir(testId, true);
    EJBArtifactStub ejbArtifact = new EJBArtifactStub(getBasedir());
    File ejbFile = ejbArtifact.getFile();
    assertTrue("ejb jar not found: " + ejbFile.toString(), ejbFile.exists());
    // configure mojo
    project.addArtifact(ejbArtifact);
    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 expectedEJBArtifact = new File(webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar");
    // File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar" );
    assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
    assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
    assertTrue("ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists());
    // house keeping
    expectedWebSourceFile.delete();
    expectedWebSource2File.delete();
    expectedEJBArtifact.delete();
}
Also used : MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) EJBArtifactStub(org.apache.maven.plugins.war.stub.EJBArtifactStub) File(java.io.File)

Aggregations

MavenProjectArtifactsStub (org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub)24 File (java.io.File)18 WarArtifactStub (org.apache.maven.plugins.war.stub.WarArtifactStub)12 ArtifactStub (org.apache.maven.plugin.testing.stubs.ArtifactStub)11 EJBArtifactStub (org.apache.maven.plugins.war.stub.EJBArtifactStub)9 IncludeExcludeWarArtifactStub (org.apache.maven.plugins.war.stub.IncludeExcludeWarArtifactStub)8 ArrayList (java.util.ArrayList)6 ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)6 Overlay (org.apache.maven.plugins.war.Overlay)6 DefaultOverlay (org.apache.maven.plugins.war.overlay.DefaultOverlay)6 InvalidOverlayConfigurationException (org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException)6 OverlayManager (org.apache.maven.plugins.war.overlay.OverlayManager)6 EJBClientArtifactStub (org.apache.maven.plugins.war.stub.EJBClientArtifactStub)6 JarArtifactStub (org.apache.maven.plugins.war.stub.JarArtifactStub)6 PARArtifactStub (org.apache.maven.plugins.war.stub.PARArtifactStub)6 TLDArtifactStub (org.apache.maven.plugins.war.stub.TLDArtifactStub)6 AarArtifactStub (org.apache.maven.plugins.war.stub.AarArtifactStub)5 MarArtifactStub (org.apache.maven.plugins.war.stub.MarArtifactStub)5 XarArtifactStub (org.apache.maven.plugins.war.stub.XarArtifactStub)5 JarFile (java.util.jar.JarFile)2