summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbkolb2007-10-19 11:34:30 (EDT)
committer bkolb2007-10-19 11:34:30 (EDT)
commitd780f09f3879c007ce6ebfd6678fcea6bd474459 (patch)
tree715484a637cd74b9430cf93f8c1da4081ec8c414
parentc7f0f8160ca5dab817b017f3dfb8c171622191a8 (diff)
downloadorg.eclipse.mwe-d780f09f3879c007ce6ebfd6678fcea6bd474459.zip
org.eclipse.mwe-d780f09f3879c007ce6ebfd6678fcea6bd474459.tar.gz
org.eclipse.mwe-d780f09f3879c007ce6ebfd6678fcea6bd474459.tar.bz2
using EMFPlugin for loading resources
-rw-r--r--plugins/org.eclipse.emf.mwe.core/META-INF/MANIFEST.MF7
-rw-r--r--plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/core/WorkflowRunner.java3
-rw-r--r--plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/internal/core/MWEPlugin.java159
-rw-r--r--plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/internal/core/resources/ResourceLoaderDefaultImpl.java55
4 files changed, 204 insertions, 20 deletions
diff --git a/plugins/org.eclipse.emf.mwe.core/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.mwe.core/META-INF/MANIFEST.MF
index 2e644e4..f06952d 100644
--- a/plugins/org.eclipse.emf.mwe.core/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.mwe.core/META-INF/MANIFEST.MF
@@ -1,14 +1,15 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
-Bundle-SymbolicName: org.eclipse.emf.mwe.core
+Bundle-SymbolicName: org.eclipse.emf.mwe.core;singleton:=true
Bundle-Version: 0.7.0.qualifier
Bundle-Localization: plugin
Bundle-Vendor: %providerName
Require-Bundle: org.apache.ant,
org.apache.commons.cli,
org.apache.commons.logging,
- org.eclipse.emf.ecore
+ org.eclipse.emf.ecore,
+ org.eclipse.core.runtime
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Eclipse-BuddyPolicy: dependent
Export-Package: org.eclipse.emf.mwe.core,
@@ -36,3 +37,5 @@ Export-Package: org.eclipse.emf.mwe.core,
org.eclipse.emf.mwe.internal.core.debug.processing.handlers;x-friends:="org.eclipse.emf.mwe.ui,org.eclipse.emf.mwe.tests",
org.eclipse.emf.mwe.internal.core.resources;x-friends:="org.eclipse.emf.mwe.ui,org.eclipse.emf.mwe.tests",
org.eclipse.emf.mwe.internal.core.util;x-friends:="org.eclipse.emf.mwe.tests"
+Bundle-Activator: org.eclipse.emf.mwe.internal.core.MWEPlugin$Implementation
+Eclipse-LazyStart: true
diff --git a/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/core/WorkflowRunner.java b/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/core/WorkflowRunner.java
index f6b9ee9..7c5504c 100644
--- a/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/core/WorkflowRunner.java
+++ b/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/core/WorkflowRunner.java
@@ -377,6 +377,9 @@ wfContext.set(key, slotContents.get(key));
* @return The build version string, format "4.1.1, Build 200609291913"
*/
private String getVersion() {
+
+ // FIXME: Change getResources()
+
String version = null;
// get all META-INF/MANIFEST.MF found in the classpath
diff --git a/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/internal/core/MWEPlugin.java b/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/internal/core/MWEPlugin.java
new file mode 100644
index 0000000..2b50a92
--- /dev/null
+++ b/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/internal/core/MWEPlugin.java
@@ -0,0 +1,159 @@
+package org.eclipse.emf.mwe.internal.core;
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.common.EMFPlugin;
+import org.eclipse.emf.common.util.ResourceLocator;
+import org.eclipse.emf.common.util.URI;
+
+public class MWEPlugin extends EMFPlugin {
+ /**
+ * The singleton instance of the plugin.
+ */
+ public static final MWEPlugin INSTANCE = new MWEPlugin();
+
+ public static final String ID = "org.eclipse.emf.mwe.core";
+
+ /**
+ * The one instance of this class.
+ */
+ private static Implementation plugin;
+
+ /**
+ * Creates the singleton instance.
+ */
+ private MWEPlugin() {
+ super(new ResourceLocator[] {});
+ }
+
+ @Override
+ public ResourceLocator getPluginResourceLocator() {
+ return plugin;
+ }
+
+ /**
+ * Returns the singleton instance of the Eclipse plugin.
+ *
+ * @return the singleton instance.
+ */
+ public static Implementation getPlugin() {
+ return plugin;
+ }
+
+ /**
+ * Use the platform, if available, to convert to a local URI.
+ */
+ public static URI asLocalURI(URI uri) {
+ return plugin == null ? uri : Implementation.asLocalURI(uri);
+ }
+
+ /**
+ * Use the platform, if available, to resolve the URI.
+ */
+ public static URI resolve(URI uri) {
+ return plugin == null ? uri : Implementation.resolve(uri);
+ }
+
+ /**
+ * Use the platform, if available, to load the named class using the right
+ * class loader.
+ */
+ public static Class<?> loadClass(String pluginID, String className)
+ throws ClassNotFoundException {
+ return plugin == null ? Class.forName(className) : Implementation
+ .loadClass(pluginID, className);
+ }
+
+ /**
+ * The actual implementation of the Eclipse <b>Plugin</b>.
+ */
+ public static class Implementation extends EclipsePlugin {
+ /**
+ * Creates an instance.
+ */
+ public Implementation() {
+ super();
+
+ // Remember the static instance.
+ //
+ plugin = this;
+ }
+
+ /**
+ * Use the platform to convert to a local URI.
+ */
+ protected static URI asLocalURI(URI uri) {
+ try {
+ String fragment = uri.fragment();
+ URL url = FileLocator.toFileURL(new URL(uri.trimFragment()
+ .toString()));
+ return fix(url, fragment);
+ } catch (IOException exception) {
+ // Ignore the exception and return the original URI.
+ }
+ return uri;
+ }
+
+ /**
+ * Use the platform to convert to a local URI.
+ */
+ protected static URI resolve(URI uri) {
+ String fragment = uri.fragment();
+ URI uriWithoutFragment = uri.trimFragment();
+ String uriWithoutFragmentToString = uriWithoutFragment.toString();
+
+ URL url = null;
+ try {
+ url = FileLocator.resolve(new URL(uriWithoutFragmentToString));
+ } catch (IOException exception1) {
+ // Platform.resolve() doesn't work if the project is encoded.
+ //
+ try {
+ uriWithoutFragmentToString = URI
+ .decode(uriWithoutFragmentToString);
+ url = FileLocator.resolve(new URL(
+ uriWithoutFragmentToString));
+ } catch (IOException exception2) {
+ // Continue with the unresolved URI.
+ }
+ }
+ if (url != null) {
+ try {
+ return fix(url, fragment);
+ } catch (IOException exception) {
+ // Return the original URI.
+ }
+ }
+
+ return uri;
+ }
+
+ protected static URI fix(URL url, String fragment) throws IOException {
+ // Only file-scheme URIs will be re-encoded. If a URI was decoded in
+ // the workaround
+ // above, and Platform.resolve() didn't return a file-scheme URI,
+ // then this will return
+ // an decoded URI.
+ //
+ URI result = "file".equalsIgnoreCase(url.getProtocol()) ? URI
+ .createFileURI(URI.decode(url.getFile())) : URI
+ .createURI(url.toString());
+ if (fragment != null) {
+ result = result.appendFragment(fragment);
+ }
+ return result;
+ }
+
+ /**
+ * Use the platform to load the named class using the right class
+ * loader.
+ */
+ public static Class<?> loadClass(String pluginID, String className)
+ throws ClassNotFoundException {
+ return Platform.getBundle(pluginID).loadClass(className);
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/internal/core/resources/ResourceLoaderDefaultImpl.java b/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/internal/core/resources/ResourceLoaderDefaultImpl.java
index 828adf0..ac3988f 100644
--- a/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/internal/core/resources/ResourceLoaderDefaultImpl.java
+++ b/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/internal/core/resources/ResourceLoaderDefaultImpl.java
@@ -25,6 +25,7 @@ import java.util.Enumeration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.emf.mwe.core.resources.ResourceLoader;
+import org.eclipse.emf.mwe.internal.core.MWEPlugin;
public class ResourceLoaderDefaultImpl implements ResourceLoader {
@@ -34,22 +35,26 @@ public class ResourceLoaderDefaultImpl implements ResourceLoader {
.getLog(ResourceLoaderDefaultImpl.class);
public final InputStream getResourceAsStream(String path) {
- InputStream in = internalGetResourceAsStream(path);
- if (in == null) {
- try {
- in = new FileInputStream(path);
- } catch (final FileNotFoundException e) {
- if (!path.startsWith(FILE_PREFIX)) {
- path = FILE_PREFIX + path;
- }
+ try {
+ return new URL(MWEPlugin.INSTANCE.getBaseURL() + path).openStream();
+ } catch (Exception ex) {
+ InputStream in = internalGetResourceAsStream(path);
+ if (in == null) {
try {
in = new FileInputStream(path);
- } catch (final Exception ex) {
- return null;
+ } catch (final FileNotFoundException ex2) {
+ if (!path.startsWith(FILE_PREFIX)) {
+ path = FILE_PREFIX + path;
+ }
+ try {
+ in = new FileInputStream(path);
+ } catch (final Exception ex3) {
+ return null;
+ }
}
}
+ return in;
}
- return in;
}
protected InputStream internalGetResourceAsStream(final String path) {
@@ -59,14 +64,18 @@ public class ResourceLoaderDefaultImpl implements ResourceLoader {
public final Class<?> loadClass(final String clazzName) {
try {
- return internalLoadClass(clazzName);
- } catch (final Exception e) {
- if (clazzName.startsWith("mwe")) {
- return loadClass(clazzName.replaceFirst("mwe",
- "org.eclipse.emf.mwe"));
+ MWEPlugin.loadClass(MWEPlugin.ID, clazzName);
+ } catch (Exception e1) {
+ try {
+ return internalLoadClass(clazzName);
+ } catch (final Exception e2) {
+ if (clazzName.startsWith("mwe")) {
+ return loadClass(clazzName.replaceFirst("mwe",
+ "org.eclipse.emf.mwe"));
+ }
}
- return null;
}
+ return null;
}
protected Class<?> internalLoadClass(final String clazzName)
@@ -76,7 +85,17 @@ public class ResourceLoaderDefaultImpl implements ResourceLoader {
}
public final URL getResource(String path) {
- URL url = internalGetResource(path);
+ URL url = null;
+ try {
+ url = new URL(MWEPlugin.INSTANCE.getBaseURL() + path);
+ if ( url.getContent()== null) {
+ url = null;
+ }
+ } catch (Exception ex) {
+ }
+ if (url == null) {
+ url = internalGetResource(path);
+ }
if (url == null) {
try {
if (!path.startsWith(FILE_PREFIX)) {