]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/BundleUtils.java
SCL-compiler should activate installed bundles
[simantics/platform.git] / bundles / org.simantics.scl.osgi / src / org / simantics / scl / osgi / internal / BundleUtils.java
index 4c6d3a0a1ab333cd8db827b0a98b3ca4f663654e..0f3d9c7c7e7f45ac8a2ce5f8bf5bda266fa05993 100644 (file)
@@ -1,51 +1,70 @@
-package org.simantics.scl.osgi.internal;\r
-\r
-import java.io.File;\r
-import java.net.URL;\r
-\r
-import org.eclipse.core.runtime.FileLocator;\r
-import org.osgi.framework.Bundle;\r
-\r
-public class BundleUtils {\r
-       \r
-       /**\r
-        * Attempt to find the given entry from the given bundle.\r
-        * \r
-        * This method looks for the entry in all bundles that have the appropriate\r
-        * symbolic name and returns the first result.\r
-        * \r
-        * @param bundle name of the bundle\r
-        * @param entry name of the entry\r
-        * @return URL of the entry or null if not found\r
-        */\r
-       public static URL getEntryFromBundle(String bundle, String entry) {\r
-               for (Bundle b : Activator.getContext().getBundles()) {\r
-                       if (b.getSymbolicName().equals(bundle)) {\r
-                               URL e = b.getEntry(entry);\r
-                               if (e != null)\r
-                                       return e; \r
-                       }\r
-               }\r
-               return null;\r
-       }\r
-       \r
-       /**\r
-        * Find the file that corresponds to the given URL.\r
-        * \r
-        * Note that this method does not work if the url points inside a bundle \r
-        * which is compiled into a jar file.\r
-        * \r
-        * @param url URL of a file (obtained with getEntryFromBundle or otherwise, \r
-        *            must actually be a file)\r
-        * @return File object that corresponds to the given URL\r
-        */\r
-       public static File getFileFromURL(URL url) {\r
-               try {\r
-                       return new File(FileLocator.toFileURL(url).toURI());\r
-               }\r
-               catch (Exception e) {\r
-                       throw new RuntimeException(e);\r
-               }\r
-       }\r
-\r
-}\r
+package org.simantics.scl.osgi.internal;
+
+import java.io.File;
+import java.net.URL;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.osgi.framework.Bundle;
+
+public class BundleUtils {
+       
+       /**
+        * Attempt to find the given entry from the given bundle.
+        * 
+        * This method looks for the entry in all bundles that have the appropriate
+        * symbolic name and returns the first result.
+        * 
+        * @param bundle name of the bundle
+        * @param entry name of the entry
+        * @return URL of the entry or null if not found
+        */
+       public static URL getEntryFromBundle(String bundle, String entry) {
+               for (Bundle b : Activator.getContext().getBundles()) {
+                       if (b.getSymbolicName().equals(bundle)) {
+                               URL e = b.getEntry(entry);
+                               if (e != null)
+                                       return e; 
+                       }
+               }
+               return null;
+       }
+       
+       /**
+        * Find the file that corresponds to the given URL.
+        * 
+        * Note that this method does not work if the url points inside a bundle 
+        * which is compiled into a jar file.
+        * 
+        * @param url URL of a file (obtained with getEntryFromBundle or otherwise, 
+        *            must actually be a file)
+        * @return File object that corresponds to the given URL
+        */
+       public static File getFileFromURL(URL url) {
+               try {
+                       return new File(FileLocator.toFileURL(url).toURI());
+               }
+               catch (Exception e) {
+                       throw new RuntimeException(e);
+               }
+       }
+
+    public static String resolveBundleState(Bundle bundle) {
+        switch (bundle.getState()) {
+        case Bundle.UNINSTALLED:
+            return "UNINSTALLED";
+        case Bundle.INSTALLED:
+            return "INSTALLED";
+        case Bundle.RESOLVED:
+            return "RESOLVED";
+        case Bundle.STARTING:
+            return "STARTING";
+        case Bundle.STOPPING:
+            return "STOPPING";
+        case Bundle.ACTIVE:
+            return "ACTIVE";
+        default:
+            return "UNKNOWN";
+        }
+    }
+
+}