Working multi RCP platform
[lgpl/argeo-commons.git] / org.argeo.cms.jshell / src / org / argeo / internal / cms / jshell / osgi / OsgiExecutionControlProvider.java
index 4a8f1685f769b0d622373cff420362902dbea124..67515e69cbf8c1f0de8c19014e6b5e87b5cf75e8 100644 (file)
@@ -179,9 +179,9 @@ public class OsgiExecutionControlProvider implements ExecutionControlProvider {
        }
 
        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();
+               String framework = bc.getProperty("osgi.framework");
+               Path frameworkLocation = Paths.get(URI.create(framework)).toAbsolutePath();
                Bundle fromBundle = bc.getBundle(bundleId);
 
                BundleWiring fromBundleWiring = fromBundle.adapt(BundleWiring.class);
@@ -203,7 +203,8 @@ public class OsgiExecutionControlProvider implements ExecutionControlProvider {
                                continue bundles;
                        }
                        Path p = bundleToPath(frameworkLocation, b);
-                       classpath.add(p.toString());
+                       if (p != null)
+                               classpath.add(p.toString());
                }
 
                return classpath.toString();
@@ -211,13 +212,28 @@ public class OsgiExecutionControlProvider implements ExecutionControlProvider {
 
        static Path bundleToPath(Path frameworkLocation, Bundle bundle) throws IOException {
                String location = bundle.getLocation();
-               if (location.startsWith("initial@reference:file:")) {
+               if (location.startsWith("initial@reference:file:")) {// Eclipse IDE environment
                        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 = frameworkLocation.getParent().resolve(location).toAbsolutePath();
+                       if (Files.exists(p)) {
+                               p = p.toRealPath();
+                               // TODO load dev.properties from OSGi configuration directory
+                               if (Files.isDirectory(p))
+                                       p = p.resolve("bin");
+                               return p;
+                       } else {
+                               log.warn("Ignore bundle " + p + " as it does not exist");
+                               return null;
+                       }
+               } else if (location.startsWith("reference:file:")) {// a2+reference
+                       location = location.substring("reference:".length());
+                       Path p = Paths.get(URI.create(location));
+                       if (Files.exists(p)) {
+                               return p;
+                       } else {
+                               log.warn("Ignore bundle " + p + " as it does not exist");
+                               return null;
+                       }
                }
                Path p = Paths.get(location);
                return p;