Reputation: 2301
I am writing test cases that have to be executed in osgi environment, i have put the test data which is a set of files in the test bundle. I am able to access the test data files using bundle.getResource which returns an URL from which i can get the InputStream for a particular file, but how can i find out all the list of files in a particular folder in the test plugin. In eclispe i could use fileLocator to do this.
/bundle
testdata
one.txt
two.txt
three.txt
folder1
file1.txt
file2.txt
In the above bundle i want to find all the files and folders that are present in the testdata folder.
Best Reards,
Keshav
Upvotes: 5
Views: 5824
Reputation: 9384
If you know what bundle the information is in, use Bundle.findEntries or Bundle.getEntryPaths.
Upvotes: 12
Reputation: 1400
Resources (classes, files, streams etc) accessed by the classloader can be provided by everything. Usually, resources are loaded from a JAR file. But it could be a database, a file system or a HTTP resource, too. So in order to get a list of resources, you depend on the source behind the classloader. In case the resources are located inside a JAR, you'll need to get the JAR itself and access it through e.g. java.util.zip. Since, the ClassLoader interface does not provide information about the source behind, you have to go other ways (like hooking into the OSGi framework you use).
Upvotes: -6