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