/** * 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); }
/** * Converts a URL that uses a user-defined protocol into a URL that uses the file protocol. * @param url the url to be converted * @return the converted URL * @throws IOException */ public URL resolveURLAsFileURL(URL url) throws IOException { return FileLocator.toFileURL(url); }
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); }
public String pluginIdToJarPath(String pluginId) throws IOException { Bundle bundle = getBundle(pluginId); URL url = bundle.getEntry("/"); if (url == null) { throw new IOException(); } return FileLocator.toFileURL(url).getFile(); }
public static URL getResourceURL(String bundleID, String resourcePath) { try { Bundle bundle = Platform.getBundle(bundleID); if (bundle != null && resourcePath != null) { URL entry = bundle.getEntry(resourcePath); if (entry != null) return FileLocator.toFileURL(entry); } } catch (IOException e) { } return null; }
private URL getResourceURL(String bundleID, String resourcePath) { try { Bundle bundle = Platform.getBundle(bundleID); if (bundle != null) { URL entry = bundle.getEntry(resourcePath); if (entry != null) return FileLocator.toFileURL(entry); } } catch (IOException e) { } return null; }
@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); }
private URL getResourceURL(String bundleID, String resourcePath) { try { Bundle bundle = Platform.getBundle(bundleID); if (bundle != null) { URL entry = bundle.getEntry(resourcePath); if (entry != null) return FileLocator.toFileURL(entry); } } catch (IOException e) { } return null; }
public static IPath findPathInPlugin(Plugin srcPlugin, String fileName) throws IOException { URL bundleUrl = srcPlugin.getBundle().getResource(fileName); URL fileUrl = FileLocator.toFileURL(bundleUrl); Path filePath = new Path(fileUrl.getPath()); return filePath; }
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 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); }
public static IPath findPathInPlugin(Plugin srcPlugin, String fileName) throws IOException { URL bundleUrl = srcPlugin.getBundle().getResource(fileName); URL fileUrl = FileLocator.toFileURL(bundleUrl); Path filePath = new Path(fileUrl.getPath()); return filePath; }
/** * Ensures that a file:// URL exists for the bundle root. This will * cause jarred bundles to be extracted into a cache directory. */ public static void ensureFileURLsExist(Bundle bundle, String contentFile) { try { FileLocator.toFileURL(bundle.getEntry("/")); //$NON-NLS-1$ } catch (Exception e) { if (contentFile != null) Log.error("Failed to extract Intro content folder for: " //$NON-NLS-1$ + contentFile, e); } }
static IPath getPluginHome(String pluginId) throws Exception { Bundle bundle = Platform.getBundle(pluginId); if (bundle == null) { throw new Exception("Plugin not found: " + pluginId); } URL localUrl = FileLocator.toFileURL(bundle.getEntry("/")); String fullPath = new File(localUrl.getPath()).getAbsolutePath(); return new Path(fullPath); }
@SuppressWarnings("null") @Override public @NonNull Path resolveToLocalPath(URL url) { try { return Paths.get(FileLocator.toFileURL(url).toURI()); } catch (Throwable e) { throw new RuntimeException(e); } }
private ZipFile getZipFileFromPluginDir(String pluginRelativePath, Bundle bundle) throws CoreException { try { URL starterURL = FileLocator.resolve(bundle.getEntry(pluginRelativePath)); return new ZipFile(FileLocator.toFileURL(starterURL).getFile()); } catch (IOException e) { String message = pluginRelativePath + ": " + e.getMessage(); //$NON-NLS-1$ Status status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, message, e); throw new CoreException(status); } }
protected File getAgentFile() throws CoreException { try { final URL agentfileurl = FileLocator.toFileURL(AgentJar.getResource()); return new Path(agentfileurl.getPath()).toFile(); } catch (IOException e) { throw new CoreException( EclEmmaStatus.NO_LOCAL_AGENTJAR_ERROR.getStatus(e)); } }
private String localURL(JUnitRuntimeClasspathEntry jar) throws IOException, MalformedURLException { Bundle bundle= JUnitCorePlugin.getDefault().getBundle(jar.getPluginId()); URL url; if (jar.getPluginRelativePath() == null) url= bundle.getEntry("/"); //$NON-NLS-1$ else url= bundle.getEntry(jar.getPluginRelativePath()); if (url == null) throw new IOException(); return FileLocator.toFileURL(url).getFile(); } }
private Image createImage(IPath path) { Bundle bundle = Platform.getBundle(IntroPlugin.PLUGIN_ID); URL url = FileLocator.find(bundle, path, null); try { url = FileLocator.toFileURL(url); ImageDescriptor desc = ImageDescriptor.createFromURL(url); return desc.createImage(); } catch (IOException e) { return null; } }
public static long[] calculateSerialVersionIds(String[] qualifiedNames, IJavaProject project, final IProgressMonitor monitor) throws CoreException, IOException { final String[] entries= computeUserAndBootClasspath(project); final IRuntimeClasspathEntry[] classpath= new IRuntimeClasspathEntry[entries.length + 2]; classpath[0]= JavaRuntime.newRuntimeContainerClasspathEntry(new Path(JavaRuntime.JRE_CONTAINER), IRuntimeClasspathEntry.STANDARD_CLASSES, project); classpath[1]= JavaRuntime.newArchiveRuntimeClasspathEntry(Path.fromOSString(FileLocator.toFileURL(JavaPlugin.getDefault().getBundle().getEntry(SERIAL_SUPPORT_JAR)).getFile())); for (int index= 2; index < classpath.length; index++) classpath[index]= JavaRuntime.newArchiveRuntimeClasspathEntry(Path.fromOSString(entries[index - 2])); return SerialVersionComputationHelper.computeSerialIDs(classpath, project, qualifiedNames, monitor); }