+ public static String getBundleClasspath(Long bundleId) throws IOException {
+ String framework = System.getProperty("osgi.framework");
+ Path frameworkLocation = Paths.get(URI.create(framework)).toAbsolutePath();
+ BundleContext bc = FrameworkUtil.getBundle(OsgiExecutionControlProvider.class).getBundleContext();
+ Bundle fromBundle = bc.getBundle(bundleId);
+
+ BundleWiring fromBundleWiring = fromBundle.adapt(BundleWiring.class);
+
+ Set<Bundle> bundlesToAddToCompileClasspath = new TreeSet<>();
+
+ // from bundle
+ bundlesToAddToCompileClasspath.add(fromBundle);
+
+ List<BundleWire> bundleWires = fromBundleWiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
+ for (BundleWire bw : bundleWires) {
+ bundlesToAddToCompileClasspath.add(bw.getProviderWiring().getBundle());
+ }
+
+ StringJoiner classpath = new StringJoiner(File.pathSeparator);
+ bundles: for (Bundle b : bundlesToAddToCompileClasspath) {
+ if (b.getBundleId() == 0) {// system bundle
+ classpath.add(frameworkLocation.toString());
+ continue bundles;
+ }
+ Path p = bundleToPath(frameworkLocation, b);
+ classpath.add(p.toString());
+ }
+
+ return classpath.toString();
+ }
+
+ static Path bundleToPath(Path frameworkLocation, Bundle bundle) throws IOException {
+ String location = bundle.getLocation();
+ if (location.startsWith("initial@reference:file:")) {
+ location = location.substring("initial@reference:file:".length());
+ Path p = frameworkLocation.getParent().resolve(location).toRealPath();
+ // TODO load dev.properties from OSGi configuration directory
+ if (Files.isDirectory(p))
+ p = p.resolve("bin");
+ return p;
+ }
+ Path p = Paths.get(location);
+ return p;
+ }