use of org.codehaus.plexus.archiver.jar.JarArchiver in project maven-plugins by apache.
the class DefaultAssemblyArchiver method createArchiver.
/**
* Creates the necessary archiver to build the distribution file.
*
* @param format Archive format
* @param includeBaseDir the base directory for include.
* @param finalName The final name.
* @param configSource {@link AssemblerConfigurationSource}
* @param containerHandlers The list of {@link ContainerDescriptorHandler}
* @param recompressZippedFiles recompress zipped files.
* @param mergeManifestMode how to handle already existing Manifest files
* @return archiver Archiver generated
* @throws org.codehaus.plexus.archiver.ArchiverException
* @throws org.codehaus.plexus.archiver.manager.NoSuchArchiverException
*/
protected Archiver createArchiver(final String format, final boolean includeBaseDir, final String finalName, final AssemblerConfigurationSource configSource, final List<ContainerDescriptorHandler> containerHandlers, boolean recompressZippedFiles, String mergeManifestMode) throws NoSuchArchiverException {
Archiver archiver;
if ("txz".equals(format) || "tgz".equals(format) || "tbz2".equals(format) || format.startsWith("tar")) {
archiver = createTarArchiver(format, TarLongFileMode.valueOf(configSource.getTarLongFileMode()));
} else if ("war".equals(format)) {
archiver = createWarArchiver();
} else {
archiver = archiverManager.getArchiver(format);
}
if (archiver instanceof AbstractZipArchiver) {
((AbstractZipArchiver) archiver).setRecompressAddedZips(recompressZippedFiles);
}
final List<FileSelector> extraSelectors = new ArrayList<FileSelector>();
final List<ArchiveFinalizer> extraFinalizers = new ArrayList<ArchiveFinalizer>();
if (archiver instanceof JarArchiver) {
if (mergeManifestMode != null) {
((JarArchiver) archiver).setFilesetmanifest(JarArchiver.FilesetManifestConfig.valueOf(mergeManifestMode));
}
extraSelectors.add(new JarSecurityFileSelector());
extraFinalizers.add(new ManifestCreationFinalizer(configSource.getMavenSession(), configSource.getProject(), configSource.getJarArchiveConfiguration()));
}
if (configSource.getArchiverConfig() != null) {
configureArchiver(archiver, configSource);
}
String prefix = "";
if (includeBaseDir) {
prefix = finalName;
}
archiver = new AssemblyProxyArchiver(prefix, archiver, containerHandlers, extraSelectors, extraFinalizers, configSource.getWorkingDirectory(), getLogger());
if (configSource.isDryRun()) {
archiver = new DryRunArchiver(archiver, getLogger());
}
archiver.setUseJvmChmod(configSource.isUpdateOnly());
archiver.setIgnorePermissions(configSource.isIgnorePermissions());
archiver.setForced(!configSource.isUpdateOnly());
return archiver;
}
use of org.codehaus.plexus.archiver.jar.JarArchiver in project maven-plugins by apache.
the class ManifestCreationFinalizer method finalizeArchiveCreation.
@Override
public void finalizeArchiveCreation(final Archiver archiver) {
if (archiveConfiguration != null) {
try {
Manifest manifest;
final File manifestFile = archiveConfiguration.getManifestFile();
if (manifestFile != null) {
Reader manifestFileReader = null;
try {
manifestFileReader = new InputStreamReader(new FileInputStream(manifestFile), "UTF-8");
manifest = new Manifest(manifestFileReader);
manifestFileReader.close();
manifestFileReader = null;
} catch (final FileNotFoundException e) {
throw new ArchiverException("Manifest not found: " + e.getMessage(), e);
} catch (final IOException e) {
throw new ArchiverException("Error processing manifest: " + e.getMessage(), e);
} finally {
IOUtil.close(manifestFileReader);
}
} else {
manifest = mavenArchiver.getManifest(session, project, archiveConfiguration);
}
if ((manifest != null) && (archiver instanceof JarArchiver)) {
final JarArchiver jarArchiver = (JarArchiver) archiver;
jarArchiver.addConfiguredManifest(manifest);
}
} catch (final ManifestException e) {
throw new ArchiverException("Error creating manifest: " + e.getMessage(), e);
} catch (final DependencyResolutionRequiredException e) {
throw new ArchiverException("Dependencies were not resolved: " + e.getMessage(), e);
}
}
}
use of org.codehaus.plexus.archiver.jar.JarArchiver in project maven-plugins by apache.
the class ManifestCreationFinalizerTest method testShouldAddManifestWhenArchiverIsJarArchiver.
public void testShouldAddManifestWhenArchiverIsJarArchiver() throws ArchiverException, IOException {
MavenProject project = new MavenProject(new Model());
MavenArchiveConfiguration config = new MavenArchiveConfiguration();
File tempDir = fileManager.createTempDir();
File manifestFile = fileManager.createFile(tempDir, "MANIFEST.MF", "Main-Class: Stuff\n");
config.setManifestFile(manifestFile);
JarArchiver archiver = new JarArchiver();
archiver.setArchiveFinalizers(Collections.<ArchiveFinalizer>singletonList(new ManifestCreationFinalizer(null, project, config)));
File file = fileManager.createTempFile();
archiver.setDestFile(file);
archiver.createArchive();
URL resource = new URL("jar:file:" + file.getAbsolutePath() + "!/META-INF/MANIFEST.MF");
BufferedReader reader = new BufferedReader(new InputStreamReader(resource.openStream()));
StringWriter writer = new StringWriter();
IOUtil.copy(reader, writer);
assertTrue(writer.toString().contains("Main-Class: Stuff"));
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4823678
((JarURLConnection) resource.openConnection()).getJarFile().close();
}
use of org.codehaus.plexus.archiver.jar.JarArchiver in project maven-plugins by apache.
the class ManifestCreationFinalizerTest method testShouldAddManifestEntriesWhenArchiverIsJarArchiver.
public void testShouldAddManifestEntriesWhenArchiverIsJarArchiver() throws ArchiverException, IOException {
MavenProject project = new MavenProject(new Model());
MavenArchiveConfiguration config = new MavenArchiveConfiguration();
String testKey = "Test-Key";
String testValue = "test-value";
config.addManifestEntry(testKey, testValue);
JarArchiver archiver = new JarArchiver();
archiver.setArchiveFinalizers(Collections.<ArchiveFinalizer>singletonList(new ManifestCreationFinalizer(null, project, config)));
File file = fileManager.createTempFile();
archiver.setDestFile(file);
archiver.createArchive();
URL resource = new URL("jar:file:" + file.getAbsolutePath() + "!/META-INF/MANIFEST.MF");
BufferedReader reader = new BufferedReader(new InputStreamReader(resource.openStream()));
StringWriter writer = new StringWriter();
IOUtil.copy(reader, writer);
System.out.println("Test Manifest:\n\n" + writer);
assertTrue(writer.toString().contains(testKey + ": " + testValue));
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4823678
((JarURLConnection) resource.openConnection()).getJarFile().close();
}
use of org.codehaus.plexus.archiver.jar.JarArchiver 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