--- /dev/null
+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