public Properties getProductCustomization() { initValues(); URL url = null; if (customizationValue != null) { // try to convert the key to a URL try { url = new URL(customizationValue); } catch (MalformedURLException e) { // didn't work so treat it as a filename url = FileLocator.find(customizationBundle, new Path(customizationValue), null); } } if (url == null) { if (InternalPlatform.DEBUG_PLUGIN_PREFERENCES) InternalPlatform.message("Product preference customization file: " + customizationValue + " not found for bundle: " + productID); //$NON-NLS-1$//$NON-NLS-2$ } return loadProperties(url); }
/** * Returns a URL that is the local equivalent of the * supplied URL. This method is expected to be used with the * plug-in-relative URLs returned by IPluginDescriptor, Bundle.getEntry() * and Platform.find(). * If the specified URL is not a plug-in-relative URL, it * is returned as is. If the specified URL is a plug-in-relative * URL of a file (including .jar archive), it is returned as * a locally accessible URL using "file:" protocol * (extracting/caching the file locally, if required). If the specified URL * is a plug-in-relative URL of a directory, the directory and any files and directories * under it are made locally accessible likewise. * * @param url original plug-in-relative URL. * @return the resolved URL * @exception IOException if unable to resolve URL * @see #resolve(URL) * @see #find(Bundle, IPath) * @see Bundle#getEntry(String) * @deprecated use {@link FileLocator#toFileURL(URL)} instead */ @Deprecated public static URL asLocalURL(URL url) throws IOException { return FileLocator.toFileURL(url); }
/** * Returns a URL which is the resolved equivalent of the * supplied URL. This method is expected to be used with the * plug-in-relative URLs returned by IPluginDescriptor, Bundle.getEntry() * and Platform.find(). * <p> * If the specified URL is not a plug-in-relative URL, it is returned * as is. If the specified URL is a plug-in-relative URL, this method * attempts to reduce the given URL to one which is native to the Java * class library (eg. file, http, etc). * </p><p> * Note however that users of this API should not assume too much about the * results of this method. While it may consistently return a file: URL in certain * installation configurations, others may result in jar: or http: URLs. * </p> * @param url original plug-in-relative URL. * @return the resolved URL * @exception IOException if unable to resolve URL * @see #asLocalURL(URL) * @see #find(Bundle, IPath) * @see Bundle#getEntry(String) * @deprecated use {@link FileLocator#resolve(URL)} instead */ @Deprecated public static URL resolve(URL url) throws IOException { return FileLocator.resolve(url); }
public InputStream getInputStream(String uri) throws Exception { return FileLocator.resolve( new URL(startLocation + uri) ).openStream(); }
private String[] getLTWClasspath() throws IOException { URL resolvedaspectjWeaverJar = FileLocator.resolve(new URL(Platform.getBundle(AspectJPlugin.WEAVER_PLUGIN_ID).getEntry("/"), "aspectjweaver.jar")); //$NON-NLS-1$ //$NON-NLS-2$ URL resolvedaspectjRTJar = FileLocator.resolve(new URL(Platform.getBundle(AspectJPlugin.RUNTIME_PLUGIN_ID).getEntry("/"), "aspectjrt.jar")); //$NON-NLS-1$ //$NON-NLS-2$ String weaverPath = new Path(resolvedaspectjWeaverJar.getFile()).toOSString(); String rtPath = new Path(resolvedaspectjRTJar.getFile()).toOSString(); return new String[] {weaverPath, rtPath}; }
@Override public URL toFileURL(URL url) throws IOException { URLConnection connection = url.openConnection(); if (!(connection instanceof PlatformURLConnection)) return url; URL result = ((PlatformURLConnection) connection).getURLAsLocal(); // if we have a bundle*: URL we should try to convert it if (!result.getProtocol().startsWith(PlatformURLHandler.BUNDLE)) return result; return FileLocator.toFileURL(result); }
@Override public URL resolve(URL url) throws IOException { URLConnection connection = url.openConnection(); if (!(connection instanceof PlatformURLConnection)) return url; URL result = ((PlatformURLConnection) connection).getResolvedURL(); // if we have a bundle*: URL we should try to convert it if (!result.getProtocol().startsWith(PlatformURLHandler.BUNDLE)) return result; return FileLocator.resolve(result); } }
public static IFile copyFileToWorkspace(Plugin srcPlugin, String srcFilePath, IFile destFile) throws IOException, CoreException { Bundle bundle = srcPlugin.getBundle(); URL bundleUrl = bundle.getResource(srcFilePath); URL fileUrl = FileLocator.toFileURL(bundleUrl); InputStream openStream = new BufferedInputStream(fileUrl.openStream()); if (destFile.exists()) { destFile.delete(true, null); } destFile.create(openStream, true, null); return destFile; } }
private URI findResourceInBundle(Bundle bundle, URI classpathUri) throws MalformedURLException, IOException { Path fullPath = new Path(classpathUri.path()); if (bundle != null) { String projectRelativePath = "/" + fullPath; URL resourceUrl = bundle.getResource(projectRelativePath); if (resourceUrl != null) { URL resolvedUrl = FileLocator.resolve(resourceUrl); URI normalizedURI = URI.createURI( resolvedUrl.toString(), true); return normalizedURI; } } return classpathUri; }
private static IPath getBinFolderPath(Bundle bundle) { for (final String binFolder : BIN_FOLDERS) { final URL binFolderURL = FileLocator.find(bundle, Path.fromPortableString(binFolder), null); if (binFolderURL != null) { try { final URL binFolderFileURL = FileLocator.toFileURL(binFolderURL); return new Path(binFolderFileURL.getPath()).makeAbsolute(); } catch (IOException e) { throw new RuntimeException(e); } } } return null; }
private static IPath getBundleLocation(Bundle bundle) { if (bundle == null) { return null; } URL local; try { local = FileLocator.toFileURL(bundle.getEntry("/")); //$NON-NLS-1$ } catch (IOException e) { return null; } String fullPath = new File(local.getPath()).getAbsolutePath(); return Path.fromOSString(fullPath); }
public static File getTestDataFile(Plugin plugin, String filename) { Bundle bundle = plugin.getBundle(); IPath path = new Path("testdata").append(filename); URL url = FileLocator.find(bundle, path, null); assert url != null : bundle.toString() + " path " + path.toString(); try { URL fileURL = FileLocator.toFileURL(url); File file = new File(fileURL.getPath()); return file; } catch (IOException e) { reportException(e); } return null; }
private static URI makeUri ( final String contributerId, final String resource, final String uri ) throws URISyntaxException { if ( uri != null && !uri.isEmpty () ) { return new URI ( uri ); } final Bundle bundle = Platform.getBundle ( contributerId ); return FileLocator.find ( bundle, new Path ( resource ), new HashMap<String, String> () ).toURI (); }