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);
}
}
}
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);
}
}
}
}
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);
}
}
Aggregations