use of org.codehaus.plexus.archiver.jar.Manifest.Attribute in project intellij-community by JetBrains.
the class ManifestBuilder method addManifestAttribute.
private static void addManifestAttribute(@NotNull Manifest manifest, String key, String value) throws ManifestException {
if (!StringUtil.isEmpty(value)) {
Attribute attr = new Attribute(key, value);
manifest.addConfiguredAttribute(attr);
}
}
use of org.codehaus.plexus.archiver.jar.Manifest.Attribute in project intellij-community by JetBrains.
the class ManifestBuilder method addCustomManifestSections.
private static void addCustomManifestSections(@NotNull Manifest manifest, @NotNull Element mavenArchiveConfiguration) throws ManifestException {
for (Element section : MavenJDOMUtil.findChildrenByPath(mavenArchiveConfiguration, "manifestSections", "manifestSection")) {
Manifest.Section theSection = new Manifest.Section();
final String sectionName = MavenJDOMUtil.findChildValueByPath(section, "name");
theSection.setName(sectionName);
final Element manifestEntries = section.getChild("manifestEntries");
Map<String, String> entries = getManifestEntries(manifestEntries);
if (!entries.isEmpty()) {
for (Map.Entry<String, String> entry : entries.entrySet()) {
Attribute attr = new Attribute(entry.getKey(), entry.getValue());
theSection.addConfiguredAttribute(attr);
}
}
manifest.addConfiguredSection(theSection);
}
}
use of org.codehaus.plexus.archiver.jar.Manifest.Attribute in project maven-plugins by apache.
the class EarMojo method changeManifestClasspath.
private void changeManifestClasspath(EarModule module, File original, JavaEEVersion javaEEVersion) throws MojoFailureException {
try {
File workDirectory;
// Handle the case that the destination might be a directory (project-038)
if (original.isFile()) {
// Create a temporary work directory
// MEAR-167 use uri as directory to prevent merging of artifacts with the same artifactId
workDirectory = new File(new File(getTempFolder(), "temp"), module.getUri());
workDirectory.mkdirs();
getLog().debug("Created a temporary work directory: " + workDirectory.getAbsolutePath());
// Unpack the archive to a temporary work directory
zipUnArchiver.setSourceFile(original);
zipUnArchiver.setDestDirectory(workDirectory);
zipUnArchiver.extract();
} else {
workDirectory = original;
}
// Create a META-INF/MANIFEST.MF file if it doesn't exist (project-038)
File metaInfDirectory = new File(workDirectory, "META-INF");
boolean newMetaInfCreated = metaInfDirectory.mkdirs();
if (newMetaInfCreated) {
// CHECKSTYLE_OFF: LineLength
getLog().debug("This project did not have a META-INF directory before, so a new directory was created.");
// CHECKSTYLE_ON: LineLength
}
File newCreatedManifestFile = new File(metaInfDirectory, "MANIFEST.MF");
boolean newManifestCreated = newCreatedManifestFile.createNewFile();
if (newManifestCreated) {
// CHECKSTYLE_OFF: LineLength
getLog().debug("This project did not have a META-INF/MANIFEST.MF file before, so a new file was created.");
// CHECKSTYLE_ON: LineLength
}
// Read the manifest from disk
Manifest mf = new Manifest(new FileInputStream(newCreatedManifestFile));
Attribute classPath = mf.getMainSection().getAttribute("Class-Path");
List<String> classPathElements = new ArrayList<String>();
if (classPath != null) {
classPathElements.addAll(Arrays.asList(classPath.getValue().split(" ")));
} else {
classPath = new Attribute("Class-Path", "");
}
// Remove JAR modules
for (JarModule jm : getAllJarModules()) {
if (module.getLibDir() != null) {
// MEAR-189:
// We use the original name, cause in case of fileNameMapping to no-version/full
// we could not not delete it and it will end up in the resulting EAR and the WAR
// will not be cleaned up.
File artifact = new File(new File(workDirectory, module.getLibDir()), jm.getOriginalBundleFileName());
// the artifact is not found. Therefore respect the current fileNameMapping additionally.
if (!artifact.exists()) {
artifact = new File(new File(workDirectory, module.getLibDir()), jm.getBundleFileName());
}
if (artifact.exists()) {
getLog().debug(" -> Artifact to delete: " + artifact);
if (!artifact.delete()) {
getLog().error("Could not delete '" + artifact + "'");
}
}
}
}
// Modify the classpath entries in the manifest
for (EarModule o : getModules()) {
if (o instanceof JarModule) {
JarModule jm = (JarModule) o;
if (classPathElements.contains(jm.getBundleFileName())) {
classPathElements.set(classPathElements.indexOf(jm.getBundleFileName()), jm.getUri());
} else {
if (!skipClassPathModification) {
classPathElements.add(jm.getUri());
} else {
if (javaEEVersion.lt(JavaEEVersion.FIVE) || defaultLibBundleDir == null) {
classPathElements.add(jm.getUri());
}
}
}
}
}
classPath.setValue(StringUtils.join(classPathElements.iterator(), " "));
mf.getMainSection().addConfiguredAttribute(classPath);
// Write the manifest to disk
PrintWriter pw = new PrintWriter(newCreatedManifestFile);
mf.write(pw);
pw.close();
if (original.isFile()) {
// Pack up the archive again from the work directory
if (!original.delete()) {
getLog().error("Could not delete original artifact file " + original);
}
getLog().debug("Zipping module");
zipArchiver.setDestFile(original);
zipArchiver.addDirectory(workDirectory);
zipArchiver.createArchive();
}
} catch (ManifestException e) {
throw new MojoFailureException(e.getMessage());
} catch (ZipException e) {
throw new MojoFailureException(e.getMessage());
} catch (IOException e) {
throw new MojoFailureException(e.getMessage());
} catch (ArchiverException e) {
throw new MojoFailureException(e.getMessage());
}
}
use of org.codehaus.plexus.archiver.jar.Manifest.Attribute in project sling by apache.
the class JarArchiverHelper method createManifest.
/**
* Create a manifest
*/
private void createManifest(final java.util.jar.Manifest manifest) throws MojoExecutionException {
// create a new manifest
final Manifest outManifest = new Manifest();
try {
boolean hasMain = false;
// copy entries from existing manifest
if (manifest != null) {
final Map<Object, Object> attrs = manifest.getMainAttributes();
for (final Map.Entry<Object, Object> entry : attrs.entrySet()) {
final String key = entry.getKey().toString();
if (!BuildConstants.ATTRS_EXCLUDES.contains(key)) {
final Attribute a = new Attribute(key, entry.getValue().toString());
outManifest.addConfiguredAttribute(a);
}
if (key.equals(BuildConstants.ATTR_MAIN_CLASS)) {
hasMain = true;
}
}
}
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_BUILD, project.getVersion()));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_VERSION, project.getVersion()));
String organizationName = project.getOrganization() != null ? project.getOrganization().getName() : null;
if (organizationName != null) {
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_VENDOR, organizationName));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_CREATED_BY, organizationName));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_BUILT_BY, organizationName));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_SPECIFICATION_VENDOR, organizationName));
}
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_VENDOR_ID, project.getGroupId()));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_TITLE, project.getName()));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_SPECIFICATION_TITLE, project.getName()));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_SPECIFICATION_VERSION, project.getVersion()));
if (archiver.getDestFile().getName().endsWith(".jar") && !hasMain) {
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_MAIN_CLASS, BuildConstants.ATTR_VALUE_MAIN_CLASS));
}
archiver.addConfiguredManifest(outManifest);
} catch (final ManifestException e) {
throw new MojoExecutionException("Unable to create manifest for " + this.archiver.getDestFile(), e);
}
}
Aggregations