### Eclipse Workspace Patch 1.0 #P org.eclipse.equinox.common Index: src/org/eclipse/core/internal/runtime/FindSupport.java =================================================================== RCS file: /cvsroot/rt/org.eclipse.equinox/components/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/FindSupport.java,v retrieving revision 1.6 diff -u -r1.6 FindSupport.java --- src/org/eclipse/core/internal/runtime/FindSupport.java 29 Jun 2006 17:54:42 -0000 1.6 +++ src/org/eclipse/core/internal/runtime/FindSupport.java 8 Mar 2009 17:44:08 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. + * Copyright (c) 2003, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -273,4 +273,24 @@ return url.openStream(); throw new IOException("Cannot find " + file.toString()); //$NON-NLS-1$ } + + /** + * See doc on {@link FileLocator#find(URL)} + */ + public static URL find(URL url) throws IOException { + // if !platform/plugin | fragment URL return + if (!"platform".equalsIgnoreCase(url.getProtocol())) //$NON-NLS-1$ + return null; + + // call a helper method to get the bundle object and rest of the path + String spec = url.getFile().trim(); + Object[] obj = PlatformURLPluginConnection.parse(spec, url); + Bundle bundle = (Bundle) obj[0]; + String path = (String) obj[1]; + + // use FileLocator.find(bundle, path, null) to look for the file + if ("/".equals(path)) //$NON-NLS-1$ + return bundle.getEntry(path); + return find(bundle, new Path(path), null); + } } Index: src/org/eclipse/core/internal/runtime/PlatformURLPluginConnection.java =================================================================== RCS file: /cvsroot/rt/org.eclipse.equinox/components/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/PlatformURLPluginConnection.java,v retrieving revision 1.2 diff -u -r1.2 PlatformURLPluginConnection.java --- src/org/eclipse/core/internal/runtime/PlatformURLPluginConnection.java 6 Mar 2006 22:36:57 -0000 1.2 +++ src/org/eclipse/core/internal/runtime/PlatformURLPluginConnection.java 8 Mar 2009 17:44:08 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -41,32 +41,45 @@ return true; } - /* (non-Javadoc) - * @see org.eclipse.equinox.internal.url.PlatformURLConnection#resolve() + /* + * spec - /plugin/com.example/META-INF/MANIFEST.MF + * originalURL - used only for exception messages + * result[0] - Bundle (e.g. com.example) + * result[1] - String (path) (e.g. META-INF/MANIFEST.MF) */ - protected URL resolve() throws IOException { - String spec = url.getFile().trim(); + public static Object[] parse(String spec, URL originalURL) throws IOException { + Object[] result = new Object[2]; if (spec.startsWith("/")) //$NON-NLS-1$ spec = spec.substring(1); if (!spec.startsWith(PLUGIN)) - throw new IOException(NLS.bind(CommonMessages.url_badVariant, url)); + throw new IOException(NLS.bind(CommonMessages.url_badVariant, originalURL)); int ix = spec.indexOf("/", PLUGIN.length() + 1); //$NON-NLS-1$ String ref = ix == -1 ? spec.substring(PLUGIN.length() + 1) : spec.substring(PLUGIN.length() + 1, ix); String id = getId(ref); Activator activator = Activator.getDefault(); if (activator == null) throw new IOException(CommonMessages.activator_not_available); - target = activator.getBundle(id); - if (target == null) - throw new IOException(NLS.bind(CommonMessages.url_resolvePlugin, url)); - if (ix == -1 || (ix + 1) >= spec.length()) - return target.getEntry("/"); //$NON-NLS-1$ - URL result = target.getEntry(spec.substring(ix + 1)); - if (result != null) + Bundle bundle = activator.getBundle(id); + if (bundle == null) + throw new IOException(NLS.bind(CommonMessages.url_resolvePlugin, originalURL)); + result[0] = bundle; + result[1] = (ix == -1 || (ix + 1) >= spec.length()) ? "/" : spec.substring(ix + 1); //$NON-NLS-1$ + return result; + } + + /* (non-Javadoc) + * @see org.eclipse.equinox.internal.url.PlatformURLConnection#resolve() + */ + protected URL resolve() throws IOException { + String spec = url.getFile().trim(); + Object[] obj = parse(spec, url); + Bundle b = (Bundle) obj[0]; + String path = (String) obj[1]; + URL result = b.getEntry(path); + if (result != null || "/".equals(path)) //$NON-NLS-1$ return result; // if the result is null then force the creation of a URL that will throw FileNotFoundExceptions - return new URL(target.getEntry("/"), spec.substring(ix + 1)); //$NON-NLS-1$ - + return new URL(b.getEntry("/"), path); //$NON-NLS-1$ } public static void startup() { Index: src/org/eclipse/core/internal/boot/PlatformURLConnection.java =================================================================== RCS file: /cvsroot/rt/org.eclipse.equinox/components/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/boot/PlatformURLConnection.java,v retrieving revision 1.3 diff -u -r1.3 PlatformURLConnection.java --- src/org/eclipse/core/internal/boot/PlatformURLConnection.java 10 Apr 2007 18:19:09 -0000 1.3 +++ src/org/eclipse/core/internal/boot/PlatformURLConnection.java 8 Mar 2009 17:44:08 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -321,17 +321,17 @@ throw new IOException(); } - protected String getId(String spec) { + protected static String getId(String spec) { String id = (String) parse(spec)[0]; return id == null ? spec : id; } - protected String getVersion(String spec) { + protected static String getVersion(String spec) { Version version = (Version) parse(spec)[1]; return version == null ? "" : version.toString(); //$NON-NLS-1$ } - private Object[] parse(String spec) { + private static Object[] parse(String spec) { String bsn = null; Version version = null; int underScore = spec.indexOf('_'); Index: src/org/eclipse/core/runtime/FileLocator.java =================================================================== RCS file: /cvsroot/rt/org.eclipse.equinox/components/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/FileLocator.java,v retrieving revision 1.10 diff -u -r1.10 FileLocator.java --- src/org/eclipse/core/runtime/FileLocator.java 12 Feb 2009 16:55:45 -0000 1.10 +++ src/org/eclipse/core/runtime/FileLocator.java 8 Mar 2009 17:44:08 -0000 @@ -107,6 +107,51 @@ } /** + * Returns the URL of a resource inside a bundle corresponding to the given URL. + * Returns null if the URL could not be computed or created. + *

+ * This method looks for a bundle resource described by the given input URL, + * and returns the URL of the first resource found in the bundle or any attached + * fragments. null is returned if no such entry is found. Note that + * there is no specific order to the fragments. + *

+ * The following variables may also be used as segments in the path of the provided URL: + *

+ *

+ * A URL path of "$nl$/about.properties" in an environment with a default + * locale of en_CA will return a URL corresponding to the first location + * about.properties is found according to the following order: + *

+	 *     plugin root/nl/en/CA/about.properties
+	 *     fragment1 root/nl/en/CA/about.properties
+	 *     fragment2 root/nl/en/CA/about.properties
+	 *     ...
+	 *     plugin root/nl/en/about.properties
+	 *     fragment1 root/nl/en/about.properties
+	 *     fragment2 root/nl/en/about.properties
+	 *     ...
+	 *     plugin root/about.properties
+	 *     fragment1 root/about.properties
+	 *     fragment2 root/about.properties
+	 *     ...
+	 * 
+ *

+ * + * @param url The location of a bundle entry that potentially includes the above + * environment variables + * @return The URL of the bundle entry matching the input URL, or null + * if no matching entry could be found. The actual form of the returned URL is not specified. + * @since org.eclipse.equinox.common 3.5 + */ + public static URL find(URL url) throws IOException { + return FindSupport.find(url); + } + + /** * This is a convenience method, fully equivalent to {@link #findEntries(Bundle, IPath, Map)}, * with a value of null for the map argument. *