/** * Construct a manifest from Ant's default manifest file. * * @return the default manifest. * @exception BuildException if there is a problem loading the default manifest */ public static Manifest getDefaultManifest() throws BuildException { try { String defManifest = "/org/apache/tools/ant/defaultManifest.mf"; InputStream in = Manifest.class.getResourceAsStream(defManifest); if (in == null) { throw new BuildException("Could not find default manifest: " + defManifest); } try { Manifest defaultManifest = new Manifest(new InputStreamReader(in, "UTF-8")); Attribute createdBy = new Attribute( "Created-By", System.getProperty("java.vm.version") + " (" + System.getProperty("java.vm.vendor") + ")"); defaultManifest.getMainSection().storeAttribute(createdBy); return defaultManifest; } catch (UnsupportedEncodingException e) { return new Manifest(new InputStreamReader(in)); } } catch (ManifestException e) { throw new BuildException("Default manifest is invalid !!", e); } catch (IOException e) { throw new BuildException("Unable to read default manifest", e); } }
private void addPackageHeader(String headerName, Map<String, String> packageMap) throws ManifestException { final Iterator<Entry<String, String>> i = packageMap.entrySet().iterator(); if (i.hasNext()) { final StringBuffer valueBuffer = new StringBuffer(); while (i.hasNext()) { final Entry<String, String> entry = i.next(); final String name = entry.getKey(); String version = entry.getValue(); valueBuffer.append(name); if (version != null) { version = version.trim(); if (0 < version.length()) { valueBuffer.append(";version="); final boolean quotingNeeded = -1 != version.indexOf(',') && '"' != version.charAt(0); if (quotingNeeded) { valueBuffer.append('"'); } valueBuffer.append(version); if (quotingNeeded) { valueBuffer.append('"'); } } } valueBuffer.append(','); } valueBuffer.setLength(valueBuffer.length() - 1); final String value = valueBuffer.toString(); generatedManifest.addConfiguredAttribute(createAttribute(headerName, value)); log(headerName + ": " + value, Project.MSG_INFO); } }
private void handleActivator() throws ManifestException { if (activator == ACTIVATOR_NONE) { log("No BundleActivator set", Project.MSG_DEBUG); } else if (activator == ACTIVATOR_AUTO) { switch (bpInfo.countProvidedActivatorClasses()) { case 0: { log("No class implementing BundleActivator found", Project.MSG_INFO); break; } case 1: { activator = bpInfo.getActivatorClass(); break; } default: { log( "More than one class implementing BundleActivator found: " + bpInfo.providedActivatorClassesAsString(), Project.MSG_WARN); break; } } } if (activator != ACTIVATOR_NONE && activator != ACTIVATOR_AUTO) { log("Bundle-Activator: " + activator, Project.MSG_INFO); generatedManifest.addConfiguredAttribute(createAttribute(BUNDLE_ACTIVATOR_KEY, activator)); } }
void configureManifest(Manifest manifest) { // set manifest entries from Moxie metadata Manifest mft = new Manifest(); setManifest(mft, "Created-By", "Moxie v" + Toolkit.getVersion()); setManifest(mft, "Build-Jdk", System.getProperty("java.version")); setManifest(mft, "Build-Date", new SimpleDateFormat("yyyy-MM-dd").format(new Date())); setManifest(mft, "Implementation-Title", Key.name); setManifest(mft, "Implementation-Vendor", Key.organization); setManifest(mft, "Implementation-Vendor-Id", Key.groupId); setManifest(mft, "Implementation-Vendor-URL", Key.url); setManifest(mft, "Implementation-Version", Key.version); setManifest(mft, "Bundle-Name", Key.name); setManifest(mft, "Bundle-SymbolicName", Key.artifactId); setManifest(mft, "Bundle-Version", Key.version); setManifest(mft, "Bundle-Vendor", Key.organization); setManifest(mft, "Maven-Url", Key.mavenUrl); setManifest(mft, "Commit-Id", Key.commitId); try { manifest.merge(mft, true); } catch (ManifestException e) { console.error(e, "Failed to configure manifest!"); } }
/** * Merge the contents of the given manifest into this manifest * * @param other the Manifest to be merged with this one. * @param overwriteMain whether to overwrite the main section of the current manifest * @throws ManifestException if there is a problem merging the manifest according to the Manifest * spec. */ public void merge(Manifest other, boolean overwriteMain) throws ManifestException { if (other != null) { if (overwriteMain) { mainSection = (Section) other.mainSection.clone(); } else { mainSection.merge(other.mainSection); } if (other.manifestVersion != null) { manifestVersion = other.manifestVersion; } Enumeration e = other.getSectionNames(); while (e.hasMoreElements()) { String sectionName = (String) e.nextElement(); Section ourSection = (Section) sections.get(sectionName); Section otherSection = (Section) other.sections.get(sectionName); if (ourSection == null) { if (otherSection != null) { addConfiguredSection((Section) otherSection.clone()); } } else { ourSection.merge(otherSection); } } } }
void setManifest(Manifest man, String key, String value) { if (!StringUtils.isEmpty(value)) { try { man.addConfiguredAttribute(new Attribute(key, value)); } catch (ManifestException e) { console.error(e, "Failed to set manifest attribute \"{0}\"!", key); } } }
private void handleClassPath() throws ManifestException { final StringBuffer value = new StringBuffer(); boolean rootIncluded = false; if (baseDir != null || classes.size() == 0) { value.append(".,"); rootIncluded = true; } Iterator<ZipFileSet> i = classes.iterator(); while (i.hasNext()) { final ZipFileSet zipFileSet = i.next(); final String prefix = zipFileSet.getPrefix(getProject()); if (prefix.length() > 0) { value.append(prefix); value.append(','); } else if (!rootIncluded) { value.append(".,"); rootIncluded = true; } } i = libs.iterator(); while (i.hasNext()) { final ZipFileSet fileset = i.next(); if (fileset.getSrc(getProject()) == null) { final DirectoryScanner ds = fileset.getDirectoryScanner(getProject()); final String[] files = ds.getIncludedFiles(); if (files.length != 0) { zipgroups.add(fileset); final String prefix = fixPrefix(fileset.getPrefix(getProject())); for (final String file : files) { value.append(prefix.replace('\\', '/')); value.append(file.replace('\\', '/')); value.append(','); } } } } if (value.length() > 2) { generatedManifest.addConfiguredAttribute( createAttribute(BUNDLE_CLASS_PATH_KEY, value.substring(0, value.length() - 1))); } }
public void testNewlines() throws Exception { Manifest m = new Manifest(); Manifest.Section s = m.getMainSection(); new NetbeansManifestUpdateMojo().conditionallyAddAttribute(s, "Desc", "Something.\n Else.\n"); assertEquals("Something. Else.", s.getAttributeValue("Desc")); }