String conditionallyAddAttribute( Manifest.Section section, String key, String value ) { Manifest.Attribute attr = section.getAttribute( key ); if ( attr == null ) { attr = new Manifest.Attribute(); attr.setName( key ); attr.setValue( value != null ? value.replaceAll("\\s+", " ").trim() : "<undefined>" ); try { section.addConfiguredAttribute( attr ); } catch ( ManifestException ex ) { getLog().error( "Cannot update manifest (key=" + key + ")" ); ex.printStackTrace(); } } return attr.getValue(); }
void createManifest() { this.manifestFile = new File(scratchDir(), "MANIFEST.MF"); Manifest.Attribute mainClass = new Manifest.Attribute(); mainClass.setName("Main-Class"); mainClass.setValue(parent.getMainClass()); ManifestTask manifest = createTask(ManifestTask.class); manifest.setFile(manifestFile); try { manifest.addConfiguredAttribute(mainClass); } catch (ManifestException e) { throw new BuildException("Manifest error", e); } manifest.execute(); }
@Override public void addConfiguredManifest(Manifest newManifest) throws ManifestException { super.addConfiguredManifest(newManifest); this.mf = newManifest; layer = mf.getMainSection().getAttributeValue("OpenIDE-Module-Layer"); // NOI18N }
private static boolean isSigned(final Manifest manifest) { Section section = manifest.getSection(MANIFEST); if (section != null) { final Enumeration<String> sectionKeys = (Enumeration<String>) section.getAttributeKeys(); while (sectionKeys.hasMoreElements()) { if (sectionKeys.nextElement().endsWith("-Digest")) { //NOI18N return true; } } } return false; }
private Manifest createManifest() throws ManifestException { Manifest manifest = new Manifest(); manifest.addConfiguredAttribute(new Manifest.Attribute("Main-Class", MAIN_CLASS)); for (Map.Entry<String, String> entry : manifestEntries.entrySet()) manifest.addConfiguredAttribute(new Manifest.Attribute(entry.getKey(), entry.getValue())); return manifest; }
private void addAttributesToAnt(Manifest antManifest) { for (Map.Entry<String, Object> entry : attributes.entrySet()) { try { antManifest.addConfiguredAttribute(new Attribute(entry.getKey(), entry.getValue().toString())); } catch (ManifestException e) { throw new org.gradle.api.java.archives.ManifestException(e.getMessage(), e); } } }
private void addSectionAttributesToAnt(Manifest antManifest) { for (Map.Entry<String, Attributes> entry : sections.entrySet()) { Section section = new Section(); section.setName(entry.getKey()); try { antManifest.addConfiguredSection(section); for (Map.Entry<String, Object> attributeEntry : entry.getValue().entrySet()) { section.addConfiguredAttribute(new Attribute(attributeEntry.getKey(), attributeEntry.getValue().toString())); } } catch (ManifestException e) { throw new org.gradle.api.java.archives.ManifestException(e.getMessage(), e); } } }
public org.gradle.api.java.archives.Manifest writeTo(Object path) { IoActions.writeTextFile(fileResolver.resolve(path), new ErroringAction<Writer>() { @Override protected void doExecute(Writer writer) throws Exception { writeTo(writer); } }); return this; }
private void addAntManifestToAttributes(Manifest antManifest) { Enumeration<String> attributeKeys = antManifest.getMainSection().getAttributeKeys(); while (attributeKeys.hasMoreElements()) { String key = attributeKeys.nextElement(); String attributeKey = antManifest.getMainSection().getAttribute(key).getName(); attributes.put(attributeKey, antManifest.getMainSection().getAttributeValue(key)); } attributes.put("Manifest-Version", antManifest.getManifestVersion()); }
private void addAntManifestToSections(Manifest antManifest) { Enumeration<String> sectionNames = antManifest.getSectionNames(); while (sectionNames.hasMoreElements()) { String sectionName = sectionNames.nextElement(); addAntManifestToSection(antManifest, sectionName); } }
private void addAntManifestToSection(Manifest antManifest, String sectionName) { DefaultAttributes attributes = new DefaultAttributes(); sections.put(sectionName, attributes); Enumeration<String> attributeKeys = antManifest.getSection(sectionName).getAttributeKeys(); while (attributeKeys.hasMoreElements()) { String key = attributeKeys.nextElement(); String attributeKey = antManifest.getSection(sectionName).getAttribute(key).getName(); attributes.put(attributeKey, antManifest.getSection(sectionName).getAttributeValue(key)); } }
private void addAttributesToAnt(Manifest antManifest) { for (Map.Entry<String, Object> entry : attributes.entrySet()) { try { antManifest.addConfiguredAttribute(new Attribute(entry.getKey().toString(), entry.getValue().toString())); } catch (ManifestException e) { throw new org.gradle.api.java.archives.ManifestException(e.getMessage(), e); } } }
private void addSectionAttributesToAnt(Manifest antManifest) { for (Map.Entry<String, Attributes> entry : sections.entrySet()) { Section section = new Section(); section.setName(entry.getKey()); try { antManifest.addConfiguredSection(section); for (Map.Entry<String, Object> attributeEntry : entry.getValue().entrySet()) { section.addConfiguredAttribute(new Attribute(attributeEntry.getKey().toString(), attributeEntry.getValue().toString())); } } catch (ManifestException e) { throw new org.gradle.api.java.archives.ManifestException(e.getMessage(), e); } } }
private void addAntManifestToAttributes(Manifest antManifest) { Enumeration attributeKeys = antManifest.getMainSection().getAttributeKeys(); while (attributeKeys.hasMoreElements()) { String key = (String) attributeKeys.nextElement(); String attributeKey = antManifest.getMainSection().getAttribute(key).getName(); attributes.put(attributeKey, antManifest.getMainSection().getAttributeValue(key)); } attributes.put("Manifest-Version", antManifest.getManifestVersion()); }
private void addAntManifestToSections(Manifest antManifest) { Enumeration sectionNames = antManifest.getSectionNames(); while (sectionNames.hasMoreElements()) { String sectionName = (String) sectionNames.nextElement(); addAntManifestToSection(antManifest, sectionName); } }
private void addAntManifestToSection(Manifest antManifest, String sectionName) { DefaultAttributes attributes = new DefaultAttributes(); sections.put(sectionName, attributes); Enumeration attributeKeys = antManifest.getSection(sectionName).getAttributeKeys(); while (attributeKeys.hasMoreElements()) { String key = (String) attributeKeys.nextElement(); String attributeKey = antManifest.getSection(sectionName).getAttribute(key).getName(); attributes.put(attributeKey, antManifest.getSection(sectionName).getAttributeValue(key)); } }
/** * Check that the given project has the <em>AutoUpdate-Show-In-Client</em> * entry set to <em>false</em> in its manifest. * * @param proj project * @throws MojoExecutionException if an error occurs */ protected void checkManifestShowClientFalse(MavenProject proj) throws MojoExecutionException { Manifest manifest = getManifest(proj); Manifest.Section mainSection = manifest.getMainSection(); String showInClient = mainSection.getAttributeValue("AutoUpdate-Show-In-Client"); if (showInClient == null || showInClient.isEmpty() || !showInClient.equals("false")) { throw new MojoExecutionException("The manifest.mf file for project '" + proj.getName() + "' should contain a 'AutoUpdate-Show-In-Client' entry set at 'false'"); } }
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" )); }
private Manifest generateAntManifest() { Manifest antManifest = new Manifest(); addAttributesToAnt(antManifest); addSectionAttributesToAnt(antManifest); return antManifest; }
protected void readManifestMetadata(MavenProject proj, PluginMetadata metadata) throws MojoExecutionException { Manifest manifest = getManifest(proj); // Read branding attributes Manifest.Section mainSection = manifest.getMainSection(); String brandingName = mainSection.getAttributeValue("OpenIDE-Module-Name"); String brandingShortDescription = mainSection.getAttributeValue("OpenIDE-Module-Short-Description"); String brandingLongDescrption = mainSection.getAttributeValue("OpenIDE-Module-Long-Description"); String brandingDisplayCategory = mainSection.getAttributeValue("OpenIDE-Module-Display-Category"); //Read localized if (mainSection.getAttribute("OpenIDE-Module-Localizing-Bundle") != null) { File folder = proj.getBasedir(); String path = mainSection.getAttributeValue("OpenIDE-Module-Localizing-Bundle"); File bundlerFile = new File(folder, "src" + File.separator + "main" + File.separator + "resources"); if (!bundlerFile.exists()) { throw new MojoExecutionException("The 'src/main/resources' folder can't be found in '" + folder.getAbsolutePath() + "'"); } bundlerFile = new File(bundlerFile, path.replace('/', File.separatorChar)); if (!bundlerFile.exists()) { throw new MojoExecutionException("The '" + path + "' file can't be found"); } Properties prop = new Properties(); FileReader bundleReader = null; try { bundleReader = new FileReader(bundlerFile); prop.load(bundleReader); brandingName = prop.getProperty("OpenIDE-Module-Name", brandingName); brandingDisplayCategory = prop.getProperty("OpenIDE-Module-Display-Category", brandingDisplayCategory); brandingShortDescription = prop.getProperty("OpenIDE-Module-Short-Description", brandingShortDescription); brandingLongDescrption = prop.getProperty("OpenIDE-Module-Long-Description", brandingLongDescrption); } catch (IOException e) { throw new MojoExecutionException("Error while reading '" + bundlerFile.getAbsolutePath() + "'", e); } finally { if (bundleReader != null) { try { bundleReader.close(); } catch (IOException ex) { } } } } if (brandingName == null || brandingName.isEmpty()) { throw new MojoExecutionException("The manifest.mf file for project '" + proj.getName() + "' should contain a 'OpenIDE-Module-Name' entry"); } if (brandingShortDescription == null || brandingShortDescription.isEmpty()) { throw new MojoExecutionException("The manifest.mf file for project '" + proj.getName() + "' should contain a 'OpenIDE-Module-Short-Description' entry"); } if (brandingLongDescrption == null || brandingLongDescrption.isEmpty()) { throw new MojoExecutionException("The manifest.mf file for project '" + proj.getName() + "' should contain a 'OpenIDE-Module-Long-Description' entry"); } if (brandingDisplayCategory == null || brandingDisplayCategory.isEmpty()) { throw new MojoExecutionException("The manifest.mf file for project '" + proj.getName() + "' should contain a 'OpenIDE-Module-Display-Category' entry"); } if (!validateCategory(brandingDisplayCategory)) { throw new MojoExecutionException("The manifest entry 'OpenIDE-Module-Display-Category' is '"+brandingDisplayCategory+"' but should be one of the following values: " + Arrays.toString(CATEGORIES).replace("[", "").replace("]", "")); } metadata.name = brandingName; metadata.short_description = brandingShortDescription; metadata.long_description = brandingLongDescrption; metadata.category = brandingDisplayCategory; }
public void addManifest( Manifest manifest ) { this.manifest = manifest; }