views:

114

answers:

2

Hi,
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

A: 

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).

oeogijjowefi
Wrong!!! Iterating over zip files etc. is NOT portable in Java, Java has an abstraction for resources that is completely broken. It is a very bad practice that is unfortunately prevalent because class loaders do not have an iterator for their resources. See the answer of BJ: OSGi has Bundle.findEntries and Bundle.getEntryPaths that allows you to iterate over resources in a portable way.
Peter Kriens
+2  A: 

If you know what bundle the information is in, use Bundle.findEntries or Bundle.getEntryPaths.

BJ Hargrave