• Intro Headers Instructions Macros Commands
Fork me on GitHub
    • Getting Started
      • How to install bnd
      • Guided Tour
      • Guided Tour Workspace & Projects
      • FAQ - Frequently Asked Questions
    • Concepts and Practices
      • Introduction
      • Concepts
      • Best practices
    • Build and Development
      • Project Setup
      • Generating JARs
      • Versioning
      • Baselining
      • Service Components
      • Metatype
      • Contracts
      • Bundle Annotations
      • Accessor Properties
      • SPI Annotations
    • Dependency and Launching
      • Resolving Dependencies
      • Launching
      • Startlevels
    • Testing
      • Testing
      • Testing with Launchpad
    • Packaging and Distribution
      • Packaging Applications
      • JPMS Libraries
      • Wrapping Libraries to OSGi Bundles
    • Documentation and Tools
      • Generating Documentation
      • Commands
      • For Developers
      • Templates for Workspaces
      • Tips for Windows users
      • Tools bound to bnd
    • Reference Material
      • Reference
      • Headers
      • Instruction Reference
      • Instruction Index
      • Macro Reference
      • Macro Index
      • Plugins
      • External Plugins
    • Configuration and Troubleshooting
      • Settings
      • Errors
      • Warnings
  • Bnd-AddXmlToTest RESOURCE ( ',' RESOURCE )
    Macro

    Add XML resources from the tested bundle to the output of a test report.

    public void setup(Bundle fw, Bundle targetBundle) {
    	startTime = System.currentTimeMillis();
    
    	testsuite.addAttribute("hostname", hostname);
    	if (targetBundle != null) {
    		testsuite.addAttribute("name", "test." + targetBundle.getSymbolicName());
    		testsuite.addAttribute("target", targetBundle.getLocation());
    	} else {
    		testsuite.addAttribute("name", "test.run");
    
    	}
    	testsuite.addAttribute("timestamp", df.format(new Date()));
    	testsuite.addAttribute("framework", fw);
    	testsuite.addAttribute("framework-version", fw.getVersion());
    
    	Tag properties = new Tag("properties");
    	testsuite.addContent(properties);
    
    	for (Map.Entry<Object,Object> entry : System.getProperties().entrySet()) {
    		Tag property = new Tag(properties, "property");
    		property.addAttribute("name", entry.getKey());
    		property.addAttribute("value", entry.getValue());
    	}
    
    	Tag bundles = new Tag(testsuite, "bundles");
    	Bundle bs[] = fw.getBundleContext().getBundles();
    
    	for (int i = 0; i < bs.length; i++) {
    		Tag bundle = new Tag("bundle");
    		bundle.addAttribute("location", bs[i].getLocation());
    		bundle.addAttribute("modified", df.format(new Date(bs[i].getLastModified())));
    		bundle.addAttribute("state", bs[i].getState());
    		bundle.addAttribute("id", bs[i].getBundleId() + "");
    		if ( bs[i].getSymbolicName() != null)
    			bundle.addAttribute("bsn", bs[i].getSymbolicName());
    		if ( bs[i].getVersion() != null)
    			bundle.addAttribute("version", bs[i].getVersion());
    
    		if (bs[i].equals(targetBundle))
    			bundle.addAttribute("target", "true");
    
    		bundles.addContent(bundle);
    	}
    	if (targetBundle != null) {
    		String header = (String) targetBundle.getHeaders().get(aQute.bnd.osgi.Constants.BND_ADDXMLTOTEST);
    		if (header != null) {
    			StringTokenizer st = new StringTokenizer(header, " ,");
    
    			while (st.hasMoreTokens()) {
    				String resource = st.nextToken();
    				URL url = targetBundle.getEntry(resource);
    
    				if (url != null) {
    					String name = url.getFile();
    					int n = name.lastIndexOf('/');
    					if (n < 0)
    						n = 0;
    					else
    						n = n + 1;
    
    					if (name.endsWith(".xml"))
    						name = name.substring(n, name.length() - 4);
    					else
    						name = name.substring(n, name.length()).replace('.', '_');
    
    					testsuite.addContent(url);
    
    				} else {
    					Tag addxml = new Tag(testsuite, "error");
    					addxml.addAttribute("reason", "no such resource: " + resource);
    				}
    			}
    		}
    	}
    }
    
Search
    • Home