Reputation: 376
How do I access source code from an Eclipse/OSGI source-bundle?
I use Maven/Tycho to produce the source bundles using the source-feature packaging. This works well for attaching the source for 3rd party development. They are referenced on the JAR as 'External location' for 'Java Source Attachement'.
But how do I programmatically reach the source-bundle? Source bundles are not accessible as regular bundles, ie Platform.getBundle('com.myplugin.source')
, and the source files are not accessible through the master bundle, ie 'com.myplugin' There's no reference in the plugin manifest headers either. Is there an Eclipse OSGI service that I should use? Any help would be appreciated.
Upvotes: 0
Views: 188
Reputation: 376
Not the solution I was hoping for but as a workaround I can go directly to the source bundle JAR file. I would hope there is a better solution as I am not sure this is future proof with such as Oomph.
String bloc = Platform.getBundle(bundlename).getLocation();
String location = bloc.replace(bundlename, bundlename+".source");
String path = new URL(location.replace("reference:", "")).getPath();
// Depending on installation type it may to prefix with Eclipse's installation path
if(!new File(path).exists())
path=Platform.getInstallLocation().getURL().getFile()+path;
File srcbundle = new File(path);
if(!srcbundle.exists()){
Logger.IDE.severe("Source bundle '"+path+"' not found!");
// When in runtime workbench we will get the source files from the bundle
for (URL url : Collections.list(bundle.findEntries("/", "*.*", true))) {
try(InputStream input = url.openStream()){
outputFile(input, url.getFile());
}
}
} else {
// When plugin installation we will unzip the source bundle JAR.
try(JarFile jar=new JarFile(srcbundle)){
for (JarEntry ze : Collections.list(jar.entries())) {
try(InputStream input = jar.getInputStream(ze)){
outputFile(input, ze.getName());
}
}
}
}
Upvotes: 0