Search in sources :

Example 1 with JavaEEVersion

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

the class GenerateApplicationXmlMojo method execute.

/**
 * {@inheritDoc}
 */
public void execute() throws MojoExecutionException, MojoFailureException {
    // Initializes ear modules
    super.execute();
    // Handle application.xml
    if (!generateApplicationXml) {
        getLog().debug("Generation of application.xml is disabled");
    } else {
        final JavaEEVersion javaEEVersion = JavaEEVersion.getJavaEEVersion(version);
        // Generate deployment descriptor and copy it to the build directory
        getLog().info("Generating application.xml");
        try {
            generateStandardDeploymentDescriptor(javaEEVersion);
        } catch (EarPluginException e) {
            throw new MojoExecutionException("Failed to generate application.xml", e);
        }
        try {
            FileUtils.copyFileToDirectory(new File(generatedDescriptorLocation, "application.xml"), new File(getWorkDirectory(), "META-INF"));
        } catch (IOException e) {
            throw new MojoExecutionException("Unable to copy application.xml to final destination", e);
        }
    }
    // Handle jboss-app.xml
    if (getJbossConfiguration() == null) {
        getLog().debug("Generation of jboss-app.xml is disabled");
    } else {
        // Generate deployment descriptor and copy it to the build directory
        getLog().info("Generating jboss-app.xml");
        try {
            generateJbossDeploymentDescriptor();
        } catch (EarPluginException e) {
            throw new MojoExecutionException("Failed to generate jboss-app.xml", e);
        }
        try {
            FileUtils.copyFileToDirectory(new File(generatedDescriptorLocation, "jboss-app.xml"), new File(getWorkDirectory(), "META-INF"));
        } catch (IOException e) {
            throw new MojoExecutionException("Unable to copy jboss-app.xml to final destination", e);
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JavaEEVersion(org.apache.maven.plugins.ear.util.JavaEEVersion) IOException(java.io.IOException) File(java.io.File)

Example 2 with JavaEEVersion

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

the class AbstractEarMojo method execute.

/**
 * {@inheritDoc}
 */
public void execute() throws MojoExecutionException, MojoFailureException {
    final JavaEEVersion javaEEVersion = JavaEEVersion.getJavaEEVersion(version);
    getLog().debug("Resolving artifact type mappings ...");
    ArtifactTypeMappingService typeMappingService;
    try {
        typeMappingService = new ArtifactTypeMappingService();
        typeMappingService.configure(artifactTypeMappings);
    } catch (EarPluginException e) {
        throw new MojoExecutionException("Failed to initialize artifact type mappings", e);
    } catch (PlexusConfigurationException e) {
        throw new MojoExecutionException("Invalid artifact type mappings configuration", e);
    }
    getLog().debug("Initializing JBoss configuration if necessary ...");
    try {
        initializeJbossConfiguration();
    } catch (EarPluginException e) {
        throw new MojoExecutionException("Failed to initialize JBoss configuration", e);
    }
    getLog().debug("Initializing ear execution context");
    EarExecutionContext earExecutionContext = new EarExecutionContext(project, mainArtifactId, defaultLibBundleDir, jbossConfiguration, outputFileNameMapping, typeMappingService);
    if (useBaseVersion != null) {
        getLog().warn("Using useBaseVersion not yet fixed.");
    // earExecutionContext.getOutputFileNameMapping().setUseBaseVersion( useBaseVersion );
    }
    getLog().debug("Resolving ear modules ...");
    List<EarModule> allModules = new ArrayList<EarModule>();
    try {
        if (modules != null && modules.length > 0) {
            // Let's validate user-defined modules
            EarModule module;
            for (EarModule module1 : modules) {
                module = module1;
                getLog().debug("Resolving ear module[" + module + "]");
                module.setEarExecutionContext(earExecutionContext);
                module.resolveArtifact(project.getArtifacts());
                allModules.add(module);
            }
        }
        // Let's add other modules
        Set<Artifact> artifacts = project.getArtifacts();
        for (Artifact artifact : artifacts) {
            // since it's used for transitive deps only.
            if ("pom".equals(artifact.getType())) {
                continue;
            }
            // Artifact is not yet registered and it has not test scope, nor is it optional
            ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_COMPILE_PLUS_RUNTIME);
            if (!isArtifactRegistered(artifact, allModules) && !artifact.isOptional() && filter.include(artifact)) {
                EarModule module = EarModuleFactory.newEarModule(artifact, javaEEVersion, defaultLibBundleDir, includeLibInApplicationXml, typeMappingService);
                module.setEarExecutionContext(earExecutionContext);
                allModules.add(module);
            }
        }
    } catch (EarPluginException e) {
        throw new MojoExecutionException("Failed to initialize ear modules", e);
    }
    // Now we have everything let's built modules which have not been excluded
    ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
    allJarModules = new ArrayList<JarModule>();
    earModules = new ArrayList<EarModule>();
    for (EarModule earModule : allModules) {
        if (earModule.isExcluded()) {
            getLog().debug("Skipping ear module[" + earModule + "]");
        } else {
            if (earModule instanceof JarModule) {
                allJarModules.add((JarModule) earModule);
            }
            if (filter.include(earModule.getArtifact())) {
                earModules.add(earModule);
            }
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JavaEEVersion(org.apache.maven.plugins.ear.util.JavaEEVersion) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) PlexusConfigurationException(org.codehaus.plexus.configuration.PlexusConfigurationException) ArtifactTypeMappingService(org.apache.maven.plugins.ear.util.ArtifactTypeMappingService)

Example 3 with JavaEEVersion

use of org.apache.maven.plugins.ear.util.JavaEEVersion 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)

Aggregations

MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 JavaEEVersion (org.apache.maven.plugins.ear.util.JavaEEVersion)3 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)1 ZipException (java.util.zip.ZipException)1 MavenArchiver (org.apache.maven.archiver.MavenArchiver)1 Artifact (org.apache.maven.artifact.Artifact)1 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 ArtifactTypeMappingService (org.apache.maven.plugins.ear.util.ArtifactTypeMappingService)1 EarMavenArchiver (org.apache.maven.plugins.ear.util.EarMavenArchiver)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 PlexusConfigurationException (org.codehaus.plexus.configuration.PlexusConfigurationException)1