1 package org.simantics.scl.osgi.internal;
\r
6 import org.eclipse.core.runtime.FileLocator;
\r
7 import org.osgi.framework.Bundle;
\r
9 public class BundleUtils {
\r
12 * Attempt to find the given entry from the given bundle.
\r
14 * This method looks for the entry in all bundles that have the appropriate
\r
15 * symbolic name and returns the first result.
\r
17 * @param bundle name of the bundle
\r
18 * @param entry name of the entry
\r
19 * @return URL of the entry or null if not found
\r
21 public static URL getEntryFromBundle(String bundle, String entry) {
\r
22 for (Bundle b : Activator.getContext().getBundles()) {
\r
23 if (b.getSymbolicName().equals(bundle)) {
\r
24 URL e = b.getEntry(entry);
\r
33 * Find the file that corresponds to the given URL.
\r
35 * Note that this method does not work if the url points inside a bundle
\r
36 * which is compiled into a jar file.
\r
38 * @param url URL of a file (obtained with getEntryFromBundle or otherwise,
\r
39 * must actually be a file)
\r
40 * @return File object that corresponds to the given URL
\r
42 public static File getFileFromURL(URL url) {
\r
44 return new File(FileLocator.toFileURL(url).toURI());
\r
46 catch (Exception e) {
\r
47 throw new RuntimeException(e);
\r