use of org.apache.maven.archiver.MavenArchiver in project maven-plugins by apache.
the class EjbMojo method generateEjb.
private File generateEjb() throws MojoExecutionException {
File jarFile = EjbHelper.getJarFile(outputDirectory, jarName, getClassifier());
getLog().info("Building EJB " + jarName + " with EJB version " + ejbVersion);
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(jarFile);
File deploymentDescriptor = new File(sourceDirectory, ejbJar);
checkEJBVersionCompliance(deploymentDescriptor);
try {
List<String> defaultExcludes = Lists.newArrayList(ejbJar, "**/package.html");
List<String> defaultIncludes = DEFAULT_INCLUDES_LIST;
IncludesExcludes ie = new IncludesExcludes(Collections.<String>emptyList(), excludes, defaultIncludes, defaultExcludes);
archiver.getArchiver().addDirectory(sourceDirectory, ie.resultingIncludes(), ie.resultingExcludes());
// FIXME: We should be able to filter more than just the deployment descriptor?
if (deploymentDescriptor.exists()) {
// EJB-34 Filter ejb-jar.xml
if (filterDeploymentDescriptor) {
filterDeploymentDescriptor(deploymentDescriptor);
}
archiver.getArchiver().addFile(deploymentDescriptor, ejbJar);
}
// create archive
archiver.createArchive(session, project, archive);
} catch (ArchiverException e) {
throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
} catch (ManifestException e) {
throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
} catch (IOException e) {
throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
} catch (DependencyResolutionRequiredException e) {
throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
} catch (MavenFilteringException e) {
throw new MojoExecutionException("There was a problem filtering the deployment descriptor: " + e.getMessage(), e);
}
return jarFile;
}
use of org.apache.maven.archiver.MavenArchiver 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);
}
}
use of org.apache.maven.archiver.MavenArchiver in project maven-plugins by apache.
the class SiteJarMojo method createArchive.
/**
* Method that creates the jar file.
*
* @param siteDirectory the directory where the site files are located
* @param jarFilename the filename of the created jar file
* @return a File object that contains the created jar file
* @throws ArchiverException
* @throws IOException
* @throws ManifestException
* @throws DependencyResolutionRequiredException
*/
private File createArchive(File siteDirectory, String jarFilename) throws ArchiverException, IOException, ManifestException, DependencyResolutionRequiredException {
File siteJar = new File(jarOutputDirectory, jarFilename);
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(this.jarArchiver);
archiver.setOutputFile(siteJar);
if (!siteDirectory.isDirectory()) {
getLog().warn("JAR will be empty - no content was marked for inclusion !");
} else {
archiver.getArchiver().addDirectory(siteDirectory, getArchiveIncludes(), getArchiveExcludes());
}
archiver.createArchive(getSession(), getProject(), archive);
return siteJar;
}
use of org.apache.maven.archiver.MavenArchiver in project maven-plugins by apache.
the class AbstractSourceJarMojo method createArchiver.
/**
* @return {@link MavenArchiver}
* @throws MojoExecutionException in case of an error.
*/
protected MavenArchiver createArchiver() throws MojoExecutionException {
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
if (project.getBuild() != null) {
List<Resource> resources = project.getBuild().getResources();
for (Resource r : resources) {
if (r.getDirectory().endsWith("maven-shared-archive-resources")) {
addDirectory(archiver.getArchiver(), new File(r.getDirectory()), getCombinedIncludes(null), getCombinedExcludes(null));
}
}
}
return archiver;
}
Aggregations