/** * Builds a URL with the given specification * @param spec the URL specification * @param trailingSlash flag to indicate a trailing slash on the spec * @return a URL */ @SuppressWarnings("deprecation") public static URL buildURL(String spec, boolean trailingSlash) { if (spec == null) return null; if (File.separatorChar == '\\') spec = spec.trim(); boolean isFile = spec.startsWith("file:"); //$NON-NLS-1$ try { if (isFile) return adjustTrailingSlash(new File(spec.substring(5)).toURL(), trailingSlash); return new URL(spec); } catch (MalformedURLException e) { // if we failed and it is a file spec, there is nothing more we can do // otherwise, try to make the spec into a file URL. if (isFile) return null; try { return adjustTrailingSlash(new File(spec).toURL(), trailingSlash); } catch (MalformedURLException e1) { return null; } } }
/** * Builds a URL with the given specification * @param spec the URL specification * @param trailingSlash flag to indicate a trailing slash on the spec * @return a URL */ public static URL buildURL(String spec, boolean trailingSlash) { return LocationHelper.buildURL(spec, trailingSlash); }
private void setLocker(File lock) { if (locker != null) return; String lockMode = environmentInfo.getConfiguration(LocationHelper.PROP_OSGI_LOCKING, LocationHelper.LOCKING_NIO); locker = LocationHelper.createLocker(lock, lockMode, debug); }
private static String getSysPathFromURL(String urlSpec) { if (urlSpec == null) return null; URL url = LocationHelper.buildURL(urlSpec, false); if (url == null) return null; File fwkFile = LocationHelper.decodePath(new File(url.getPath())); fwkFile = new File(fwkFile.getAbsolutePath()); fwkFile = new File(fwkFile.getParent()); return fwkFile.getAbsolutePath(); }
debugOptionsFilename = new File(userDir, OPTIONS).toString(); optionsFile = LocationHelper.buildURL(debugOptionsFilename, false); if (optionsFile == null) { System.out.println("Unable to construct URL for options file: " + debugOptionsFilename); //$NON-NLS-1$ InputStream input = LocationHelper.getStream(optionsFile); try { options.load(input);
f = LocationHelper.decodePath(new File(location.getPath())); devLastModified = f.lastModified(); loadDevProperties(LocationHelper.getStream(location)); devMode = true; } catch (IOException e) {
@Override public URLConnection run() throws IOException { return LocationHelper.getConnection(createURL(spec)); } });
public static File decodePath(File file) { // Pre-check if file exists, if not, and it contains escape characters, // try decoding the absolute path generated by makeAbsolute if (!file.exists() && (file.getPath().indexOf('%') >= 0 || file.getPath().indexOf('+') >= 0)) { String absolute = file.getAbsolutePath(); String decodePath = LocationHelper.decode(absolute, true); File f = new File(decodePath); if (f.exists()) { return f; } decodePath = LocationHelper.decode(absolute, false); f = new File(decodePath); if (f.exists()) { return f; } } return file; }
public synchronized void connect() throws IOException { if (!connected) { // TODO assumes that reference URLs are always based on file: URLs. // There are not solid usecases to the contrary. Yet. // Construct the ref File carefully so as to preserve UNC paths etc. String path = url.getPath(); if (!path.startsWith("file:")) { //$NON-NLS-1$ throw new IOException(NLS.bind(Msg.ADAPTOR_URL_CREATE_EXCEPTION, path)); } path = url.getPath().substring(5); File file = new File(path); if (!file.isAbsolute()) { if (installPath != null) file = makeAbsolute(installPath, file); } file = LocationHelper.decodePath(file); checkRead(file); reference = file; connected = true; } }
private Properties loadProperties(URL location) { Properties result = new Properties(); if (location == null) return result; try { InputStream in = LocationHelper.getStream(location); try { result.load(in); } finally { in.close(); } } catch (FileNotFoundException e) { // TODO probably should log, but the common case for non-eclipse // environments would be to not have a config.ini ... } catch (IOException e) { // We'll just use the defaults for everything but log the exception on reading exceptions.put(e, FrameworkLogEntry.WARNING); } return substituteVars(result); }
private static String getSysPathFromURL(String urlSpec) { if (urlSpec == null) return null; URL url = LocationHelper.buildURL(urlSpec, false); if (url == null) return null; File fwkFile = LocationHelper.decodePath(new File(url.getPath())); fwkFile = new File(fwkFile.getAbsolutePath()); fwkFile = new File(fwkFile.getParent()); return fwkFile.getAbsolutePath(); }
debugOptionsFilename = new File(userDir, OPTIONS).toString(); optionsFile = LocationHelper.buildURL(debugOptionsFilename, false); if (optionsFile == null) { System.out.println("Unable to construct URL for options file: " + debugOptionsFilename); //$NON-NLS-1$ InputStream input = LocationHelper.getStream(optionsFile); try { options.load(input);
f = LocationHelper.decodePath(new File(location.getPath())); devLastModified = f.lastModified(); loadDevProperties(LocationHelper.getStream(location)); devMode = true; } catch (IOException e) {
@Override public URLConnection run() throws IOException { return LocationHelper.getConnection(createURL(spec)); } });
public static File decodePath(File file) { // Pre-check if file exists, if not, and it contains escape characters, // try decoding the absolute path generated by makeAbsolute if (!file.exists() && (file.getPath().indexOf('%') >= 0 || file.getPath().indexOf('+') >= 0)) { String absolute = file.getAbsolutePath(); String decodePath = LocationHelper.decode(absolute, true); File f = new File(decodePath); if (f.exists()) { return f; } decodePath = LocationHelper.decode(absolute, false); f = new File(decodePath); if (f.exists()) { return f; } } return file; }
@SuppressWarnings("deprecation") public synchronized void connect() throws IOException { if (!connected) { // TODO assumes that reference URLs are always based on file: URLs. // There are not solid usecases to the contrary. Yet. // Construct the ref URL carefully so as to preserve UNC paths etc. String path = url.getPath().substring(5); File file = new File(path); URL ref; if (!file.isAbsolute()) { if (installPath != null) file = makeAbsolute(installPath, file); } file = LocationHelper.decodePath(file); ref = file.toURL(); checkRead(file); reference = ref; } }
private Properties loadProperties(URL location) { Properties result = new Properties(); if (location == null) return result; try { InputStream in = LocationHelper.getStream(location); try { result.load(in); } finally { in.close(); } } catch (FileNotFoundException e) { // TODO probably should log, but the common case for non-eclipse // environments would be to not have a config.ini ... } catch (IOException e) { // We'll just use the defaults for everything but log the exception on reading exceptions.put(e, FrameworkLogEntry.WARNING); } return substituteVars(result); }
/** * Builds a URL with the given specification * @param spec the URL specification * @param trailingSlash flag to indicate a trailing slash on the spec * @return a URL */ public static URL buildURL(String spec, boolean trailingSlash) { return LocationHelper.buildURL(spec, trailingSlash); }
private void initializeInstanceFile() throws IOException { if (instanceFile != null || readOnly) return; this.instanceFile = File.createTempFile(".tmp", ".instance", managerRoot); //$NON-NLS-1$//$NON-NLS-2$ this.instanceFile.deleteOnExit(); instanceLocker = LocationHelper.createLocker(instanceFile, lockMode, false); instanceLocker.lock(); }
if (value.getProtocol().equalsIgnoreCase("file")) { //$NON-NLS-1$ try { File f = LocationHelper.decodePath(new File(value.getPath())); String basePath = f.getCanonicalPath(); value = LocationHelper.buildURL("file:" + basePath, true); //$NON-NLS-1$ } catch (IOException e) {