• Intro Headers Instructions Macros
  • Fork me on GitHub
    • Release
    • 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
    • Testing
    • Packaging Applications
    • Wrapping Libraries to OSGi Bundles
    • From the command line
    • For Developers
    • Plugins
    • Tools bound to bnd
    • File Format
    • Header Reference
    • Instruction
    • Instruction Index
    • Macro Reference
    • Command Reference
    • Plugins Reference
    • Settings
    • Errors
    • Warnings
    • Frequently Asked Questions
    Supported by OSGi enRoute
  • lsr ';' DIR (';' INSTRUCTION )

    layout: default

    /**
     * Wildcard a directory. The lists can contain Instruction that are matched
     * against the given directory ${lsr;<dir>;<list>(;<list>)*}
     * ${lsa;<dir>;<list>(;<list>)*}
     *
     * @author aqute
     */
    
    public String _lsr(String args[]) {
    	return ls(args, true);
    }
    
    public String _lsa(String args[]) {
    	return ls(args, false);
    }
    
    String ls(String args[], boolean relative) {
    	if (args.length < 2)
    		throw new IllegalArgumentException("the ${ls} macro must at least have a directory as parameter");
    
    	File dir = domain.getFile(args[1]);
    	if (!dir.isAbsolute())
    		throw new IllegalArgumentException("the ${ls} macro directory parameter is not absolute: " + dir);
    
    	if (!dir.exists())
    		throw new IllegalArgumentException("the ${ls} macro directory parameter does not exist: " + dir);
    
    	if (!dir.isDirectory())
    		throw new IllegalArgumentException(
    				"the ${ls} macro directory parameter points to a file instead of a directory: " + dir);
    
    	Collection<File> files = new ArrayList<File>(new SortedList<File>(dir.listFiles()));
    
    	for (int i = 2; i < args.length; i++) {
    		Instructions filters = new Instructions(args[i]);
    		files = filters.select(files, true);
    	}
    
    	List<String> result = new ArrayList<String>();
    	for (File file : files)
    		result.add(relative ? file.getName() : file.getAbsolutePath());
    
    	return Processor.join(result, ",");
    }
    
    • Contact
    • Developers
    • More