use of org.apache.maven.plugins.war.util.ClassesPackager in project maven-plugins by apache.
the class WarMojo method performPackaging.
/**
* Generates the webapp according to the <tt>mode</tt> attribute.
*
* @param warFile the target WAR file
* @throws IOException if an error occurred while copying files
* @throws ArchiverException if the archive could not be created
* @throws ManifestException if the manifest could not be created
* @throws DependencyResolutionRequiredException if an error occurred while resolving the dependencies
* @throws MojoExecutionException if the execution failed
* @throws MojoFailureException if a fatal exception occurred
*/
private void performPackaging(File warFile) throws IOException, ManifestException, DependencyResolutionRequiredException, MojoExecutionException, MojoFailureException {
getLog().info("Packaging webapp");
buildExplodedWebapp(getWebappDirectory());
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(warArchiver);
archiver.setOutputFile(warFile);
// CHECKSTYLE_OFF: LineLength
getLog().debug("Excluding " + Arrays.asList(getPackagingExcludes()) + " from the generated webapp archive.");
getLog().debug("Including " + Arrays.asList(getPackagingIncludes()) + " in the generated webapp archive.");
// CHECKSTYLE_ON: LineLength
warArchiver.addDirectory(getWebappDirectory(), getPackagingIncludes(), getPackagingExcludes());
final File webXmlFile = new File(getWebappDirectory(), "WEB-INF/web.xml");
if (webXmlFile.exists()) {
warArchiver.setWebxml(webXmlFile);
}
warArchiver.setRecompressAddedZips(isRecompressZippedFiles());
warArchiver.setIncludeEmptyDirs(isIncludeEmptyDirectories());
if (Boolean.FALSE.equals(failOnMissingWebXml) || (failOnMissingWebXml == null && isProjectUsingAtLeastServlet30())) {
getLog().debug("Build won't fail if web.xml file is missing.");
warArchiver.setExpectWebXml(false);
}
// create archive
archiver.createArchive(getSession(), getProject(), getArchive());
// create the classes to be attached if necessary
if (isAttachClasses()) {
if (isArchiveClasses() && getJarArchiver().getDestFile() != null) {
// special handling in case of archived classes: MWAR-240
File targetClassesFile = getTargetClassesFile();
FileUtils.copyFile(getJarArchiver().getDestFile(), targetClassesFile);
projectHelper.attachArtifact(getProject(), "jar", getClassesClassifier(), targetClassesFile);
} else {
ClassesPackager packager = new ClassesPackager();
final File classesDirectory = packager.getClassesDirectory(getWebappDirectory());
if (classesDirectory.exists()) {
getLog().info("Packaging classes");
packager.packageClasses(classesDirectory, getTargetClassesFile(), getJarArchiver(), getSession(), getProject(), getArchive());
projectHelper.attachArtifact(getProject(), "jar", getClassesClassifier(), getTargetClassesFile());
}
}
}
if (this.classifier != null) {
projectHelper.attachArtifact(getProject(), "war", this.classifier, warFile);
} else {
Artifact artifact = getProject().getArtifact();
if (primaryArtifact) {
artifact.setFile(warFile);
} else if (artifact.getFile() == null || artifact.getFile().isDirectory()) {
artifact.setFile(warFile);
}
}
}
use of org.apache.maven.plugins.war.util.ClassesPackager in project maven-plugins by apache.
the class ClassesPackagingTask method generateJarArchive.
/**
* @param context The warPackingContext.
* @throws MojoExecutionException In casae of an error.
*/
protected void generateJarArchive(WarPackagingContext context) throws MojoExecutionException {
MavenProject project = context.getProject();
ArtifactFactory factory = context.getArtifactFactory();
Artifact artifact = factory.createBuildArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), "jar");
String archiveName;
try {
archiveName = getArtifactFinalName(context, artifact);
} catch (InterpolationException e) {
throw new MojoExecutionException("Could not get the final name of the artifact [" + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + "]", e);
}
final String targetFilename = LIB_PATH + archiveName;
if (context.getWebappStructure().registerFile(currentProjectOverlay.getId(), targetFilename)) {
final File libDirectory = new File(context.getWebappDirectory(), LIB_PATH);
final File jarFile = new File(libDirectory, archiveName);
final ClassesPackager packager = new ClassesPackager();
packager.packageClasses(context.getClassesDirectory(), jarFile, context.getJarArchiver(), context.getSession(), project, context.getArchive());
} else {
context.getLog().warn("Could not generate archive classes file [" + targetFilename + "] has already been copied.");
}
}
Aggregations