Java Code Examples for org.apache.tools.ant.taskdefs.Manifest#Attribute

The following examples show how to use org.apache.tools.ant.taskdefs.Manifest#Attribute . 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: Bundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Manifest.Attribute createAttribute(String name, String value)
{
  final Manifest.Attribute attribute = new Manifest.Attribute();
  attribute.setName(name);
  attribute.setValue(value);
  return attribute;
}
 
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: 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 8
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 9
Source File: BundleManifestTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * If the manifest contains a capability requirement on osgi.ee for the
 * OSGi/Minimum EE then replace the filter part of that requirement with the
 * given replacement value.
 *
 * @param mf
 *          The manifest to replace in.
 */
private void replaceEEminmum(Manifest mf)
{
  if (replaceEEmin != null) {
    final Manifest.Section mainS = mf.getMainSection();
    final Manifest.Attribute attr =
      mainS.getAttribute(Constants.REQUIRE_CAPABILITY);
    if (attr != null) {
      final String reqCapValue = attr.getValue();
      if (reqCapValue.contains(OSGI_MINIMUM_EE_NAME)) {
        log("Found '" + Constants.REQUIRE_CAPABILITY
            + "' attribute with requirement on '" + OSGI_MINIMUM_EE_NAME
            + "'.", Project.MSG_DEBUG);

        // Must replace...
        final List<HeaderEntry> hes =
          Util.parseManifestHeader(Constants.REQUIRE_CAPABILITY, reqCapValue,
                                   true, true, false);
        for (final HeaderEntry he : hes) {
          log("Processing header entry '" + he.getKey()
                  + "' with attributes " + he.getAttributes()
                  + " and directives " + he.getDirectives() + ".",
              Project.MSG_DEBUG);
          for (final Entry<String, String> directiveEntry : he
              .getDirectives().entrySet()) {
            if ("osgi.ee".equals(he.getKey())
                && "filter".equals(directiveEntry.getKey())
                && directiveEntry.getValue().contains(OSGI_MINIMUM_EE_NAME)) {
              log("Replacing filter '" + directiveEntry.getValue()
                      + "' with '" + replaceEEmin + "' in '" + reqCapValue
                      + "'.", Project.MSG_VERBOSE);
              directiveEntry.setValue(replaceEEmin);
              break;
            }
          }
        }
        attr.setValue(Util.toString(hes));
      }
    }
  }
}
 
Example 10
Source File: BundleManifestTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * If this is a distribution build (the
 * <code>Knopflerfish-Version</code> attribute is present) then use
 * the version number as replacement for:
 * <ul>
 *   <li>the <code>current</code>-part of a Bundle-DocURL
 *       value that start with {@link #DOC_URL_PREFIX}.
 *   <li>the <code>trunk</code>-part of a Bundle-GitURL
 *       value that start with {@link #GIT_URL_PREFIX}.
 * </ul>
 */
private void replaceTrunkWithVersion(Manifest mf)
{
  final Manifest.Attribute kfVerAttr
    = mf.getMainSection().getAttribute("Knopflerfish-Version");
  if (null!=kfVerAttr) {
    final String version = kfVerAttr.getValue();
    final boolean isSnapshot = -1<version.indexOf("snapshot");

    final String toReplace   = "/releases/current/";
    final String replacement = isSnapshot
      ? "/snapshots/" +version +"/"
      : ("/releases/" +version +"/");
    final Manifest.Attribute docAttr
      = mf.getMainSection().getAttribute("Bundle-DocURL");
    if (null!=docAttr) {
      final String docURL = docAttr.getValue();
      if (docURL.startsWith(DOC_URL_PREFIX)) {
        final int ix = DOC_URL_PREFIX.indexOf(toReplace);
        final String newDocURL
          = DOC_URL_PREFIX.substring(0,ix)
          +replacement +docURL.substring(ix + toReplace.length());
        docAttr.setValue(newDocURL);
      }
    }

    if (!isSnapshot) {
      final Manifest.Attribute gitAttr
        = mf.getMainSection().getAttribute("Bundle-GitURL");
      if (null!=gitAttr) {
        final String gitURL = gitAttr.getValue();
        if (gitURL.startsWith(GIT_URL_PREFIX)) {
          final String newGitURL
            = GIT_URL_PREFIX.substring(0,GIT_URL_PREFIX.indexOf("master/"))
            +version +gitURL.substring(GIT_URL_PREFIX.length()-1);
          gitAttr.setValue(newGitURL);
        }
      }
    }
  }
}
 
Example 11
Source File: BundleManifestTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Add an attribute to the main section of the manifest.
 * Attributes with the value BUNDLE_EMPTY_STRING are not added.
 *
 * @param attribute the attribute to be added.
 *
 * @exception ManifestException if the attribute is not valid.
 */
public void addConfiguredAttribute(Manifest.Attribute attribute)
  throws ManifestException {
  if(BUNDLE_EMPTY_STRING.equals(attribute.getValue())) {
    return;
  }
  manifestNested.addConfiguredAttribute(attribute);
}