Search in sources :

Example 1 with EarMavenArchiver

use of org.apache.maven.plugins.ear.util.EarMavenArchiver in project maven-plugins by apache.

the class EarMavenArchiverTest method testSimpleJarModuleWithCustomBundleDir.

@Test
public void testSimpleJarModuleWithCustomBundleDir() {
    final List<EarModule> modules = new ArrayList<EarModule>();
    final EarModule module = new EjbModule(createArtifact("foo", "jar"));
    setUri(module, "libs/foo-1.0.jar");
    modules.add(module);
    final EarMavenArchiver archiver = new EarMavenArchiver(modules);
    assertEquals("libs/foo-1.0.jar", archiver.generateClassPathEntry(""));
}
Also used : ArrayList(java.util.ArrayList) EarModule(org.apache.maven.plugins.ear.EarModule) EjbModule(org.apache.maven.plugins.ear.EjbModule) EarMavenArchiver(org.apache.maven.plugins.ear.util.EarMavenArchiver) Test(org.junit.Test)

Example 2 with EarMavenArchiver

use of org.apache.maven.plugins.ear.util.EarMavenArchiver in project maven-plugins by apache.

the class EarMavenArchiverTest method testSimpleEjbModule.

@Test
public void testSimpleEjbModule() {
    final List<EarModule> modules = new ArrayList<EarModule>();
    final EarModule module = new EjbModule(createArtifact("foo", "ejb"));
    setUri(module, "foo-1.0.jar");
    modules.add(module);
    final EarMavenArchiver archiver = new EarMavenArchiver(modules);
    assertEquals("foo-1.0.jar", archiver.generateClassPathEntry(""));
}
Also used : ArrayList(java.util.ArrayList) EarModule(org.apache.maven.plugins.ear.EarModule) EjbModule(org.apache.maven.plugins.ear.EjbModule) EarMavenArchiver(org.apache.maven.plugins.ear.util.EarMavenArchiver) Test(org.junit.Test)

Example 3 with EarMavenArchiver

use of org.apache.maven.plugins.ear.util.EarMavenArchiver in project maven-plugins by apache.

the class EarMojo method execute.

/** {@inheritDoc} */
public void execute() throws MojoExecutionException, MojoFailureException {
    // Initializes ear modules
    super.execute();
    zipArchiver.setUseJvmChmod(useJvmChmod);
    zipUnArchiver.setUseJvmChmod(useJvmChmod);
    final JavaEEVersion javaEEVersion = JavaEEVersion.getJavaEEVersion(version);
    // Initializes unpack types
    List<String> unpackTypesList = createUnpackList();
    // Copy modules
    copyModules(javaEEVersion, unpackTypesList);
    // Copy source files
    try {
        File earSourceDir = earSourceDirectory;
        if (earSourceDir.exists()) {
            getLog().info("Copy ear sources to " + getWorkDirectory().getAbsolutePath());
            String[] fileNames = getEarFiles(earSourceDir);
            for (String fileName : fileNames) {
                copyFile(new File(earSourceDir, fileName), new File(getWorkDirectory(), fileName));
            }
        }
        if (applicationXml != null && !"".equals(applicationXml)) {
            // rename to application.xml
            getLog().info("Including custom application.xml[" + applicationXml + "]");
            File metaInfDir = new File(getWorkDirectory(), META_INF);
            copyFile(new File(applicationXml), new File(metaInfDir, "/application.xml"));
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Error copying EAR sources", e);
    } catch (MavenFilteringException e) {
        throw new MojoExecutionException("Error filtering EAR sources", e);
    }
    // Check if deployment descriptor is there
    File ddFile = new File(getWorkDirectory(), APPLICATION_XML_URI);
    if (!ddFile.exists() && (javaEEVersion.lt(JavaEEVersion.FIVE))) {
        // CHECKSTYLE_OFF: LineLength
        throw new MojoExecutionException("Deployment descriptor: " + ddFile.getAbsolutePath() + " does not exist.");
    // CHECKSTYLE_ON: LineLength
    }
    try {
        File earFile = getEarFile(outputDirectory, finalName, classifier);
        final MavenArchiver archiver = new EarMavenArchiver(getModules());
        final JarArchiver theJarArchiver = getJarArchiver();
        getLog().debug("Jar archiver implementation [" + theJarArchiver.getClass().getName() + "]");
        archiver.setArchiver(theJarArchiver);
        archiver.setOutputFile(earFile);
        getLog().debug("Excluding " + Arrays.asList(getPackagingExcludes()) + " from the generated EAR.");
        getLog().debug("Including " + Arrays.asList(getPackagingIncludes()) + " in the generated EAR.");
        archiver.getArchiver().addDirectory(getWorkDirectory(), getPackagingIncludes(), getPackagingExcludes());
        archiver.createArchive(session, getProject(), archive);
        if (classifier != null) {
            projectHelper.attachArtifact(getProject(), "ear", classifier, earFile);
        } else {
            getProject().getArtifact().setFile(earFile);
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Error assembling EAR", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) JavaEEVersion(org.apache.maven.plugins.ear.util.JavaEEVersion) EarMavenArchiver(org.apache.maven.plugins.ear.util.EarMavenArchiver) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) EarMavenArchiver(org.apache.maven.plugins.ear.util.EarMavenArchiver) File(java.io.File) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 4 with EarMavenArchiver

use of org.apache.maven.plugins.ear.util.EarMavenArchiver in project maven-plugins by apache.

the class EarMavenArchiverTest method testTwoModules.

@Test
public void testTwoModules() {
    final List<EarModule> modules = new ArrayList<EarModule>();
    final EarModule module = new EjbModule(createArtifact("foo", "ejb"));
    setUri(module, "foo-1.0.jar");
    modules.add(module);
    final EarModule module2 = new EjbModule(createArtifact("bar", "war"));
    setUri(module2, "bar-2.0.1.war");
    modules.add(module2);
    final EarMavenArchiver archiver = new EarMavenArchiver(modules);
    assertEquals("foo-1.0.jar bar-2.0.1.war", archiver.generateClassPathEntry(""));
}
Also used : ArrayList(java.util.ArrayList) EarModule(org.apache.maven.plugins.ear.EarModule) EjbModule(org.apache.maven.plugins.ear.EjbModule) EarMavenArchiver(org.apache.maven.plugins.ear.util.EarMavenArchiver) Test(org.junit.Test)

Aggregations

EarMavenArchiver (org.apache.maven.plugins.ear.util.EarMavenArchiver)4 ArrayList (java.util.ArrayList)3 EarModule (org.apache.maven.plugins.ear.EarModule)3 EjbModule (org.apache.maven.plugins.ear.EjbModule)3 Test (org.junit.Test)3 File (java.io.File)1 IOException (java.io.IOException)1 ZipException (java.util.zip.ZipException)1 MavenArchiver (org.apache.maven.archiver.MavenArchiver)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 JavaEEVersion (org.apache.maven.plugins.ear.util.JavaEEVersion)1 MavenFilteringException (org.apache.maven.shared.filtering.MavenFilteringException)1 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)1 JarArchiver (org.codehaus.plexus.archiver.jar.JarArchiver)1 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)1 NoSuchArchiverException (org.codehaus.plexus.archiver.manager.NoSuchArchiverException)1