• Intro Headers Instructions Macros Commands
  • Fork me on GitHub
    • Introduction
    • How to install bnd
    • Guided Tour
    • Guided Tour Workspace & Projects
    • Concepts
    • Best practices
    • Build
    • Generating JARs
    • Versioning
    • Baselining
    • Service Components
    • Metatype
    • Contracts
    • Manifest Annotations
    • Resolving Dependencies
    • Launching
    • Plain JUnit Testing with OSGi (PRELIMENARY)
    • Testing
    • Packaging Applications
    • Wrapping Libraries to OSGi Bundles
    • Commands
    • For Developers
    • Tools bound to bnd
    • Headers
    • Instruction Reference
    • Instruction Index
    • Macro Reference
    • Macro Index
    • Plugins
    • Settings
    • Errors
    • Warnings
    • Frequently Asked Questions
  • -namesection RESOURCE-SPEC ( ',' RESOURCE-SPEC ) *

    /**
     * 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);
    	}
    
    }
    
    • GitHub