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

The following examples show how to use org.apache.tools.ant.taskdefs.ManifestException. 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: JNLPUpdateManifestStartup.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void execute() throws BuildException {
    File tmpFile = null;
    try {
        if (isSigned(jar) == null) {
            tmpFile = extendLibraryManifest(getProject(), jar, destJar, codebase, permissions, appName);
        }
    } catch (IOException | ManifestException ex) {
        getProject().log(
                "Failed to extend libraries manifests: " + ex.getMessage(), //NOI18N
                Project.MSG_WARN);
    }
    if (tmpFile != null) {
        sign(tmpFile, destJar);
        deleteTmpFile(tmpFile);
    } else {
        sign(jar, destJar);
    }
}
 
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 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 #3
Source File: Bundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void execute()
{
  try {
    handleClassPath();

    analyze();

    handleActivator();

    addPackageHeader(IMPORT_PACKAGE_KEY, importPackage);
    addPackageHeader(EXPORT_PACKAGE_KEY, exportPackage);

    // TODO: better merge may be needed, currently overwrites
    // pre-existing headers
    addConfiguredManifest(generatedManifest);
  } catch (final ManifestException me) {
    throw new BuildException("Error merging manifest headers", me);
  }
  super.execute();
}
 
Example #4
Source File: Bundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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);
  }
}
 
Example #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
Source File: Bundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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));
  }
}
 
Example #12
Source File: CslJar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void addConfiguredManifest(Manifest newManifest) throws ManifestException {
    super.addConfiguredManifest(newManifest);
    this.mf = newManifest;

    layer = mf.getMainSection().getAttributeValue("OpenIDE-Module-Layer"); // NOI18N
}
 
Example #13
Source File: JNLPUpdateManifestBranding.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void execute() throws BuildException {
    Set<String> filePaths = new HashSet<>();
    File tmpFile = null;
    for (FileSet fs : filesets) {
        if (fs != null) {
            DirectoryScanner scan = fs.getDirectoryScanner(getProject());
            for (String f : scan.getIncludedFiles()) {
                filePaths.add(fs.getDir().getAbsolutePath() + File.separatorChar + f.replace(File.separatorChar, '/'));
            }
        }
    }
    try {
        for (String filePathIter : filePaths) {
            File jarFile = new File(filePathIter);
            if (isSigned(jarFile) == null) {
                tmpFile = extendLibraryManifest(getProject(), jarFile, jarFile, codebase, permissions, appName);
            }
            if (tmpFile != null) {
                sign(tmpFile, jarFile);
                deleteTmpFile(tmpFile);
            } else {
                sign(jarFile, jarFile);
            }

        }
    } catch (IOException | ManifestException ex) {
        getProject().log(
                "Failed to extend libraries manifests: " + ex.getMessage(), //NOI18N
                Project.MSG_WARN);
    }
}
 
Example #14
Source File: SignJarsTask.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void extendLibrariesManifests(
    final Project prj,
    final File mainJar,
    final List<? extends File> libraries) throws IOException {
    String codebase = null;
    String permissions = null;
    String appName = null;
    final JarFile jf = new JarFile(mainJar);
    try {
        final java.util.jar.Manifest mf = jf.getManifest();
        if (mf != null) {
            final Attributes attrs = mf.getMainAttributes();
            codebase = attrs.getValue(ATTR_CODEBASE);
            permissions = attrs.getValue(ATTR_PERMISSIONS);
            appName = attrs.getValue(ATTR_APPLICATION_NAME);
        }
    } finally {
        jf.close();
    }
    prj.log(
        String.format(
            "Application: %s manifest: Codebase: %s, Permissions: %s, Application-Name: %s",    //NOI18N
            safeRelativePath(prj.getBaseDir(), mainJar),
            codebase,
            permissions,
            appName),
        Project.MSG_VERBOSE);
    if (codebase != null || permissions != null || appName != null) {
        for (File library : libraries) {
            try {
                extendLibraryManifest(prj, library, codebase, permissions, appName);
            } catch (ManifestException mex) {
                throw new IOException(mex);
            }
        }
    }
}
 
Example #15
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 #16
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 #17
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 #18
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);
}
 
Example #19
Source File: BundleManifestTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Add a section to the manifest.
 *
 * @param section the manifest section to be added.
 *
 * @exception ManifestException if the section is not valid.
 */
public void addConfiguredSection(Manifest.Section section)
  throws ManifestException {
  manifestNested.addConfiguredSection(section);
}