org.apache.tools.ant.taskdefs.Manifest Java Examples

The following examples show how to use org.apache.tools.ant.taskdefs.Manifest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BundleManifestTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * If <code>attributePropertyPrefix</code> is set then iterate over
 * all attributes in the main section and set the value for
 * corresponding property to the value of that attribute.
 *
 * The name of the attribute will be the property name without the
 * prefix and the value will be the property value.
 */
private void updatePropertiesFromMainSectionAttributeValues(Manifest mf)
{
  if (null!=attributePropertyPrefix) {
    final Project   project      = getProject();
    final Manifest.Section mainS = mf.getMainSection();
    for (@SuppressWarnings("unchecked")
    final Enumeration<String> ae = mainS.getAttributeKeys(); ae.hasMoreElements();) {
      final String key = ae.nextElement();
      final Manifest.Attribute attr = mainS.getAttribute(key);
      // Ensure that the default case is used for OSGi specified attributes
      final String propKey = attributePropertyPrefix
        + (osgiAttrNamesMap.containsKey(key)
           ? osgiAttrNamesMap.get(key) : attr.getName() );
      final String propVal = attr.getValue();
      log("setting '" +propKey +"'='"+propVal+"'.", Project.MSG_VERBOSE);
      project.setProperty(propKey,propVal);
    }
  }
}
 
Example #2
Source File: BundleManifestTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Ensure that the first value of the named main section attribute
 * ends with the specified suffix.
 *
 * @param mf       The manifest object to work with.
 * @param attrName The name of the attribute to check / update.
 * @param suffix   The required suffix.
 */
private void ensureAttrFirstValueEndsWith(final Manifest mf,
                                          final String attrName,
                                          final String suffix)
{
  final Manifest.Attribute attr = mf.getMainSection().getAttribute(attrName);
  if (null != attr) {
    final String rhs = attr.getValue();
    if (rhs != null && 0 < rhs.length()) {
      final int semiPos = rhs.indexOf(';');
      if (0 < semiPos) {
        // Found manifest attribute with parameter(s) or directive(s)
        final String firstValue = rhs.substring(0, semiPos).trim();
        if (!firstValue.endsWith(suffix)) {
          attr.setValue( firstValue + suffix + rhs.substring(semiPos));
        }
      } else {
        if (!rhs.endsWith(suffix)) {
          attr.setValue( rhs +suffix );
        }
      }
    }
  }
}
 
Example #3
Source File: BundleManifestTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Ensure that the named main section attribute have the given
 * value.
 * @param mf       The manifest object to work with.
 * @param attrName The name of the attribute to check / update.
 * @param value    The required attribute value.
 */
private void ensureAttrValue(Manifest mf, String attrName, String value){
  Manifest.Attribute ma = mf.getMainSection().getAttribute(attrName);
  if (null==ma) {
    ma = new Manifest.Attribute(attrName,value);
    try {
      mf.getMainSection().addConfiguredAttribute(ma);
    } catch (final ManifestException me) {
      throw new BuildException("ensureAttrValue("+attrName+","
                               +value +") failed.",
                               me, getLocation());
    }
  } else {
    ma.setValue(value);
  }
}
 
Example #4
Source File: BundleManifestTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * If we have a bundle version suffix add it to the 
 * <code>Bundle-Version</code> attribute.
 */
private void appendVersionSuffix(Manifest mf)
{
  if (versionSuffix != null && !versionSuffix.equals("")) {
    final Manifest.Attribute bundleVerAttr
      = mf.getMainSection().getAttribute("Bundle-Version");
    if (null!=bundleVerAttr) {
      final Version ver = new Version(bundleVerAttr.getValue());
      String q = ver.getQualifier();
      int major = ver.getMajor();
      int minor = ver.getMinor();
      int micro = ver.getMicro();
      if (q.length() == 0) {
        bundleVerAttr.setValue(new Version(major, minor, micro, versionSuffix).toString());
      } else if (!q.endsWith(versionSuffix)) {
        bundleVerAttr.setValue(new Version(major, minor, micro, q + "-" + versionSuffix).toString());
      }
    }
  }
}
 
Example #5
Source File: BundleManifestTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * If <code>attributePropertyPrefix</code> is set then iterate over
 * all properties and add attributes to the main section of
 * the given manifest for those properties that starts with the prefix.
 *
 * The name of the attribute will be the property name without the
 * prefix and the value will be the property value.
 *
 * @param mf The manifest to add the property based attributes to.
 */
private void addAttributesFromProperties(Manifest mf)
{
  if (null!=attributePropertyPrefix) {
    final int       prefixLength = attributePropertyPrefix.length();
    final Project   project      = getProject();
    final Manifest.Section mainS = mf.getMainSection();
    @SuppressWarnings("unchecked")
    final Hashtable<String,?> properties   = project.getProperties();
    for (final Enumeration<String> pe = properties.keys(); pe.hasMoreElements();) {
      final String key = pe.nextElement();
      if (key.startsWith(attributePropertyPrefix)) {
        final String attrName  = key.substring(prefixLength);
        final String attrValue = (String) properties.get(key);
        if(!BUNDLE_EMPTY_STRING.equals(attrValue)) {
          Manifest.Attribute attr = mainS.getAttribute(attrName);
          if (null!=attr) {
            throw new BuildException
              ( "Can not add main section attribute for property '"
                +key+"' with value '"+attrValue+"' since a "
                +"main section attribute with that name exists: '"
                +attr.getName() +": "+attr.getValue() +"'.",
                getLocation());
          }
          try {
            attr = new Manifest.Attribute(attrName, attrValue);
            mf.addConfiguredAttribute(attr);
            log("from propety '" +attrName +": "+attrValue+"'.",
                Project.MSG_VERBOSE);
          } catch (final ManifestException me) {
            throw new BuildException
              ( "Failed to add main section attribute for property '"
                +key+"' with value '"+attrValue+"'.\n"+me.getMessage(),
                me, getLocation());
          }
        }
      }
    }
  }
}
 
Example #6
Source File: BundleManifestTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void doVerbose(Manifest.Section ms, String attrName, String heading)
{
  final Manifest.Attribute ma = ms.getAttribute(attrName);
  if (null!=ma) {
    final String val = ma.getValue();
    if (!isPropertyValueEmpty(val)) {
      log( heading +" = "+val, Project.MSG_INFO);
    }
  }
}
 
Example #7
Source File: DefaultManifest.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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));
    }
}
 
Example #8
Source File: DefaultManifest.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void addAntManifestToSections(Manifest antManifest) {
    Enumeration sectionNames = antManifest.getSectionNames();
    while (sectionNames.hasMoreElements()) {
        String sectionName = (String) sectionNames.nextElement();
        addAntManifestToSection(antManifest, sectionName);
    }
}
 
Example #9
Source File: DefaultManifest.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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());
}
 
Example #10
Source File: BundleManifestTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Ensure that the named main section attribute ends with the
 * specified suffix.
 * @param mf       The manifest object to work with.
 * @param attrName The name of the attribute to check / update.
 * @param suffix   The required suffix.
 */
private void ensureAttrEndsWith(final Manifest mf,
                                final String attrName,
                                final String suffix){
  final Manifest.Attribute attr = mf.getMainSection().getAttribute(attrName);
  if (null!=attr) {
    final String rhs = attr.getValue();
    if (!rhs.endsWith(suffix)) {
      attr.setValue( rhs +suffix );
    }
  }
}
 
Example #11
Source File: DefaultManifest.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #12
Source File: DefaultManifest.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
        }
    }
}
 
Example #13
Source File: DefaultManifest.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
        }
    }
}
 
Example #14
Source File: DefaultManifest.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
        }
    }
}
 
Example #15
Source File: DefaultManifest.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #16
Source File: DefaultManifest.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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());
}
 
Example #17
Source File: DefaultManifest.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void addAntManifestToSections(Manifest antManifest) {
    Enumeration<String> sectionNames = antManifest.getSectionNames();
    while (sectionNames.hasMoreElements()) {
        String sectionName = sectionNames.nextElement();
        addAntManifestToSection(antManifest, sectionName);
    }
}
 
Example #18
Source File: DefaultManifest.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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));
    }
}
 
Example #19
Source File: DefaultManifest.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
        }
    }
}
 
Example #20
Source File: DefaultManifest.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
        }
    }
}
 
Example #21
Source File: DefaultManifest.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
        }
    }
}
 
Example #22
Source File: DefaultManifest.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
        }
    }
}
 
Example #23
Source File: DefaultManifest.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #24
Source File: DefaultManifest.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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());
}
 
Example #25
Source File: DefaultManifest.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void addAntManifestToSections(Manifest antManifest) {
    Enumeration<String> sectionNames = antManifest.getSectionNames();
    while (sectionNames.hasMoreElements()) {
        String sectionName = sectionNames.nextElement();
        addAntManifestToSection(antManifest, sectionName);
    }
}
 
Example #26
Source File: DefaultManifest.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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));
    }
}
 
Example #27
Source File: DefaultManifest.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
        }
    }
}
 
Example #28
Source File: DefaultManifest.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #29
Source File: DefaultManifest.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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());
}
 
Example #30
Source File: DefaultManifest.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void addAntManifestToSections(Manifest antManifest) {
    Enumeration sectionNames = antManifest.getSectionNames();
    while (sectionNames.hasMoreElements()) {
        String sectionName = (String) sectionNames.nextElement();
        addAntManifestToSection(antManifest, sectionName);
    }
}