X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.osgi%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fosgi%2Finternal%2FBundleUtils.java;h=c16545889425e4ffc0b7fd2d5dbbd6e41f4bab44;hb=1e6b0f31a45cfdb30ef8c28a0763eb05d705e6fb;hp=4c6d3a0a1ab333cd8db827b0a98b3ca4f663654e;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/BundleUtils.java b/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/BundleUtils.java index 4c6d3a0a1..c16545889 100644 --- a/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/BundleUtils.java +++ b/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/BundleUtils.java @@ -1,51 +1,51 @@ -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); - } - } - -} +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); + } + } + +}