1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
---
layout: default
class: Builder
title: -namesection RESOURCE-SPEC ( ',' RESOURCE-SPEC ) *
summary: Create a name section (second part of manifest) with optional property expansion and addition of custom attributes.
---
/**
* Parse the namesection as instructions and then match them against the
* current set of resources For example:
*
* <pre>
* -namesection: *;baz=true, abc/def/bar/X.class=3
* </pre>
*
* The raw value of {@link Constants#NAMESECTION} is used but the values of
* the attributes are replaced where @ is set to the resource name. This
* allows macro to operate on the resource
*/
private void doNamesection(Jar dot, Manifest manifest) {
Parameters namesection = parseHeader(getProperties().getProperty(NAMESECTION));
Instructions instructions = new Instructions(namesection);
Set<String> resources = new HashSet<String>(dot.getResources().keySet());
//
// For each instruction, iterator over the resources and filter
// them. If a resource matches, it must be removed even if the
// instruction is negative. If positive, add a name section
// to the manifest for the given resource name. Then add all
// attributes from the instruction to that name section.
//
for (Map.Entry<Instruction,Attrs> instr : instructions.entrySet()) {
boolean matched = false;
// For each instruction
for (Iterator<String> i = resources.iterator(); i.hasNext();) {
String path = i.next();
// For each resource
if (instr.getKey().matches(path)) {
// Instruction matches the resource
matched = true;
if (!instr.getKey().isNegated()) {
// Positive match, add the attributes
Attributes attrs = manifest.getAttributes(path);
if (attrs == null) {
attrs = new Attributes();
manifest.getEntries().put(path, attrs);
}
//
// Add all the properties from the instruction to the
// name section
//
for (Map.Entry<String,String> property : instr.getValue().entrySet()) {
setProperty("@", path);
try {
String processed = getReplacer().process(property.getValue());
attrs.putValue(property.getKey(), processed);
}
finally {
unsetProperty("@");
}
}
}
i.remove();
}
}
if (!matched && resources.size() > 0)
warning("The instruction %s in %s did not match any resources", instr.getKey(), NAMESECTION);
}
}
|