use of java.util.jar.Attributes in project felix by apache.
the class DefaultManifestBuilder method build.
/**
* Update the given manifest.
* @param original original manifest to be modified
* @return modified manifest
*/
public Manifest build(final Manifest original) {
Attributes att = original.getMainAttributes();
// Set the imports (add ipojo and handler namespaces
setImports(att);
// Add iPOJO-Component
setPOJOMetadata(att);
// Add iPOJO to the creators
setCreatedBy(att);
return original;
}
use of java.util.jar.Attributes in project felix by apache.
the class DefaultManifestBuilderTestCase method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
manifest = new Manifest();
Attributes attributes = manifest.getMainAttributes();
attributes.putValue("Import-Package", ORG_OSGI_FRAMEWORK_VERSION_1_5);
attributes.putValue("Created-By", "TestCase");
builder = new DefaultManifestBuilder();
builder.addReferredPackage(Collections.singleton("org.osgi.service.http"));
}
use of java.util.jar.Attributes in project felix by apache.
the class BundlePlugin method mergeManifest.
protected static void mergeManifest(Instructions instructions, Manifest... manifests) throws IOException {
for (int i = manifests.length - 2; i >= 0; i--) {
Manifest mergedManifest = manifests[i];
Manifest manifest = manifests[i + 1];
Attributes mergedMainAttributes = mergedManifest.getMainAttributes();
Attributes mainAttributes = manifest.getMainAttributes();
Attributes filteredMainAttributes = filterAttributes(instructions, mainAttributes, null);
if (!filteredMainAttributes.isEmpty()) {
mergeAttributes(mergedMainAttributes, filteredMainAttributes);
}
Map<String, Attributes> mergedEntries = mergedManifest.getEntries();
Map<String, Attributes> entries = manifest.getEntries();
for (Map.Entry<String, Attributes> entry : entries.entrySet()) {
String name = entry.getKey();
Attributes attributes = entry.getValue();
Attributes filteredAttributes = filterAttributes(instructions, attributes, null);
if (!filteredAttributes.isEmpty()) {
Attributes mergedAttributes = mergedManifest.getAttributes(name);
if (mergedAttributes != null) {
mergeAttributes(mergedAttributes, filteredAttributes);
} else {
mergedEntries.put(name, filteredAttributes);
}
}
}
}
}
use of java.util.jar.Attributes in project felix by apache.
the class BundlePlugin method filterAttributes.
/**
* @see Analyzer#filter
*/
private static Attributes filterAttributes(Instructions instructions, Attributes source, Set<Instruction> nomatch) {
Attributes result = new Attributes();
Map<String, Object> keys = new TreeMap<String, Object>();
for (Object key : source.keySet()) {
keys.put(key.toString(), key);
}
List<Instruction> filters = new ArrayList<Instruction>(instructions.keySet());
if (nomatch == null) {
nomatch = Create.set();
}
for (Instruction instruction : filters) {
boolean match = false;
for (Iterator<Map.Entry<String, Object>> i = keys.entrySet().iterator(); i.hasNext(); ) {
Map.Entry<String, Object> entry = i.next();
String key = entry.getKey();
if (instruction.matches(key)) {
match = true;
if (!instruction.isNegated()) {
Object name = entry.getValue();
Object value = source.get(name);
result.put(name, value);
}
// Can never match again for another pattern
i.remove();
}
}
if (!match && !instruction.isAny())
nomatch.add(instruction);
}
for (Iterator<Instruction> i = nomatch.iterator(); i.hasNext(); ) {
Instruction instruction = i.next();
// #252, we should not be negated to make it a constant
if (instruction.isLiteral() && !instruction.isNegated()) {
Object key = keys.get(instruction.getLiteral());
if (key != null) {
Object value = source.get(key);
result.put(key, value);
}
i.remove();
continue;
}
// the !package will never match anymore.
if (instruction.isNegated()) {
i.remove();
continue;
}
// an error
if (instruction.isOptional()) {
i.remove();
continue;
}
}
return result;
}
use of java.util.jar.Attributes in project gocd by gocd.
the class MacAboutBox method getCruiseVersion.
public static String getCruiseVersion(String jar) {
String version = null;
try {
JarFile jarFile = new JarFile(jar);
Manifest manifest = jarFile.getManifest();
if (manifest != null) {
Attributes attributes = manifest.getMainAttributes();
version = attributes.getValue("Go-Version");
}
} catch (IOException e) {
}
return version;
}
Aggregations