summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbkolb2007-10-19 12:55:23 (EDT)
committer bkolb2007-10-19 12:55:23 (EDT)
commit51af06b6e605f5a463fa1527d7c8e9f75af49672 (patch)
treec5dae3b7048ffe31849c7ce2c59cf1ef2648fea5
parent99908e0c60b45059ccb8f5dfd05d87ab965cb6aa (diff)
downloadorg.eclipse.mwe-51af06b6e605f5a463fa1527d7c8e9f75af49672.zip
org.eclipse.mwe-51af06b6e605f5a463fa1527d7c8e9f75af49672.tar.gz
org.eclipse.mwe-51af06b6e605f5a463fa1527d7c8e9f75af49672.tar.bz2
[206196] all tests green in standalone and osgi mode
-rw-r--r--plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/core/WorkflowRunner.java61
-rw-r--r--plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/core/resources/ResourceLoader.java2
-rw-r--r--plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/internal/core/resources/ResourceLoaderDefaultImpl.java112
-rw-r--r--plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/internal/core/resources/ResourceLoaderImpl.java8
-rw-r--r--plugins/org.eclipse.emf.mwe.ui/src/org/eclipse/emf/mwe/internal/ui/workflow/util/ProjectIncludingResourceLoader.java19
-rw-r--r--tests/org.eclipse.emf.mwe.tests/src/org/eclipse/emf/mwe/tests/ast/util/WorkflowFactoryTest.java3
-rw-r--r--tests/org.eclipse.emf.mwe.tests/src/org/eclipse/emf/mwe/tests/util/DummyResourceLoader.java5
7 files changed, 79 insertions, 131 deletions
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 7c5504c..c531c4f 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
@@ -13,7 +13,6 @@ package org.eclipse.emf.mwe.core;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.jar.Manifest;
@@ -158,9 +157,10 @@ public class WorkflowRunner {
int index = 0;
do {
// TODO BK change to resource loader factory
-// wfUrl = ResourceLoaderFactory.createResourceLoader()
-// .getResource(wfFile);
- wfUrl = Thread.currentThread().getContextClassLoader().getResource(wfFile);
+ // wfUrl = ResourceLoaderFactory.createResourceLoader()
+ // .getResource(wfFile);
+ wfUrl = Thread.currentThread().getContextClassLoader()
+ .getResource(wfFile);
if (wfUrl == null) {
index = wfFile.indexOf('/');
if (index >= 0) {
@@ -344,9 +344,9 @@ public class WorkflowRunner {
return;
}
for (Object name : slotContents.keySet()) {
-final String key = (String) name;
-wfContext.set(key, slotContents.get(key));
-}
+ final String key = (String) name;
+ wfContext.set(key, slotContents.get(key));
+ }
}
private void logIssues(final Log logger, final Issues issues) {
@@ -377,36 +377,31 @@ 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
- Enumeration<URL> manifestURLs = null;
- manifestURLs = ResourceLoaderFactory.createResourceLoader()
- .getResources("META-INF/MANIFEST.MF");
-
- while (manifestURLs.hasMoreElements()) {
- URL url = manifestURLs.nextElement();
- try {
- Manifest manifest = new Manifest(url.openStream());
- // identify the manifest from core.workflow plugin
- if ("org.eclipse.emf.mwe.core".equals(manifest
- .getMainAttributes().getValue("Bundle-SymbolicName"))) {
- // Read bundle version an split it.
- // Original value : "4.1.1.200609291913"
- // Resulting value : "4.1.1, Build 200609291913"
- version = manifest.getMainAttributes().getValue(
- "Bundle-Version");
- int lastPoint = version.lastIndexOf('.');
- version = version.substring(0, lastPoint) + ", Build "
- + version.substring(lastPoint + 1);
- return version;
- }
- } catch (IOException e) {
- logger.debug("Failed to read Manifest file: " + url);
+ try {
+ Manifest manifest = new Manifest(ResourceLoaderFactory
+ .createResourceLoader().getResource("META-INF/MANIFEST.MF")
+ .openStream());
+ // identify the manifest from core.workflow plugin
+ String bundleName = manifest.getMainAttributes()
+ .getValue("Bundle-SymbolicName");
+ if (bundleName.startsWith("org.eclipse.emf.mwe.core")) {
+ // Read bundle version an split it.
+ // Original value : "4.1.1.200609291913"
+ // Resulting value : "4.1.1, Build 200609291913"
+ version = manifest.getMainAttributes().getValue(
+ "Bundle-Version");
+ int lastPoint = version.lastIndexOf('.');
+ version = version.substring(0, lastPoint) + ", Build "
+ + version.substring(lastPoint + 1);
+ return version;
}
+ } catch (IOException e) {
+ logger
+ .debug("Failed to read Manifest file. Unable to retrieve version");
}
// build version not detected from manifest, fallback
// this will only occur in developer's workbench
diff --git a/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/core/resources/ResourceLoader.java b/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/core/resources/ResourceLoader.java
index 27c051b..c635024 100644
--- a/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/core/resources/ResourceLoader.java
+++ b/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/core/resources/ResourceLoader.java
@@ -16,7 +16,6 @@ package org.eclipse.emf.mwe.core.resources;
import java.io.InputStream;
import java.net.URL;
-import java.util.Enumeration;
public interface ResourceLoader {
@@ -38,5 +37,4 @@ public interface ResourceLoader {
public URL getResource(String uri);
- public Enumeration<URL> getResources(String uri);
}
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 73de928..d828ae8 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
@@ -14,16 +14,10 @@
*/
package org.eclipse.emf.mwe.internal.core.resources;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.net.MalformedURLException;
import java.net.URL;
-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;
@@ -31,35 +25,15 @@ public class ResourceLoaderDefaultImpl implements ResourceLoader {
private static final String FILE_PREFIX = "file:";
- private static final Log log = LogFactory
- .getLog(ResourceLoaderDefaultImpl.class);
-
public final InputStream getResourceAsStream(String 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 FileNotFoundException ex2) {
- if (!path.startsWith(FILE_PREFIX)) {
- path = FILE_PREFIX + path;
- }
- try {
- in = new FileInputStream(path);
- } catch (final Exception ex3) {
- return null;
- }
- }
+ URL resource = getResource(path);
+ if (resource != null) {
+ try {
+ return resource.openStream();
+ } catch (IOException ignore) {
}
- return in;
}
- }
-
- protected InputStream internalGetResourceAsStream(final String path) {
- return Thread.currentThread().getContextClassLoader()
- .getResourceAsStream(path);
+ return null;
}
public final Class<?> loadClass(final String clazzName) {
@@ -85,55 +59,57 @@ public class ResourceLoaderDefaultImpl implements ResourceLoader {
}
public final URL getResource(String path) {
- URL url = null;
- try {
- url = new URL(MWEPlugin.INSTANCE.getBaseURL() + path);
- if ( url.getContent()== null) {
- url = null;
- }
- } catch (Exception ex) {
+ URL url = loadDirectly(path);
+ if (url == null) {
+ url = loadFromBaseURL(path);
}
if (url == null) {
- url = internalGetResource(path);
+ url = loadFromContextClassLoader(path);
}
if (url == null) {
- try {
- if (!path.startsWith(FILE_PREFIX)) {
- path = FILE_PREFIX + path;
- }
- url = new URL(path);
- if (url.getContent() == null) {
- return null;
- }
- } catch (final MalformedURLException e) {
- return null;
- } catch (final IOException e) {
- return null;
- }
+ url = loadFromFile(path);
}
return url;
}
- protected URL internalGetResource(final String path) {
- return Thread.currentThread().getContextClassLoader().getResource(path);
+ private URL loadFromFile(String path) {
+ try {
+ if (!path.startsWith(FILE_PREFIX)) {
+ path = FILE_PREFIX + path;
+ }
+ URL url = new URL(path);
+ if (url.getContent() != null) {
+ return url;
+ }
+ } catch (final Exception e) {
+ }
+ return null;
}
- public Enumeration<URL> getResources(final String uri) {
+ private URL loadFromBaseURL(String path) {
try {
- return Thread.currentThread().getContextClassLoader().getResources(
- uri);
- } catch (IOException e) {
- log.error(e.getMessage(), e);
- return new Enumeration<URL>() {
- public boolean hasMoreElements() {
- return false;
- }
+ URL url = new URL(MWEPlugin.INSTANCE.getBaseURL() + path);
+ if (url.getContent() != null) {
+ return url;
+ }
+ } catch (Exception ignore) {
+ }
+ return null;
+ }
- public URL nextElement() {
- return null;
- }
- };
+ private URL loadDirectly(String path) {
+ try {
+ URL url = new URL(path);
+ if (url.getContent() != null) {
+ return url;
+ }
+ } catch (Exception ignore) {
}
+ return null;
+ }
+
+ protected URL loadFromContextClassLoader(final String path) {
+ return Thread.currentThread().getContextClassLoader().getResource(path);
}
}
diff --git a/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/internal/core/resources/ResourceLoaderImpl.java b/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/internal/core/resources/ResourceLoaderImpl.java
index 795bb27..5186d20 100644
--- a/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/internal/core/resources/ResourceLoaderImpl.java
+++ b/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/internal/core/resources/ResourceLoaderImpl.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.emf.mwe.internal.core.resources;
-import java.io.InputStream;
import java.net.URL;
public class ResourceLoaderImpl extends ResourceLoaderDefaultImpl {
@@ -22,16 +21,11 @@ public class ResourceLoaderImpl extends ResourceLoaderDefaultImpl {
}
@Override
- protected URL internalGetResource(final String path) {
+ protected URL loadFromContextClassLoader(final String path) {
return loader.getResource(path);
}
@Override
- protected InputStream internalGetResourceAsStream(final String path) {
- return loader.getResourceAsStream(path);
- }
-
- @Override
protected Class<?> internalLoadClass(final String clazzName) throws ClassNotFoundException {
return loader.loadClass(clazzName);
}
diff --git a/plugins/org.eclipse.emf.mwe.ui/src/org/eclipse/emf/mwe/internal/ui/workflow/util/ProjectIncludingResourceLoader.java b/plugins/org.eclipse.emf.mwe.ui/src/org/eclipse/emf/mwe/internal/ui/workflow/util/ProjectIncludingResourceLoader.java
index 9db8915..ec3969c 100644
--- a/plugins/org.eclipse.emf.mwe.ui/src/org/eclipse/emf/mwe/internal/ui/workflow/util/ProjectIncludingResourceLoader.java
+++ b/plugins/org.eclipse.emf.mwe.ui/src/org/eclipse/emf/mwe/internal/ui/workflow/util/ProjectIncludingResourceLoader.java
@@ -1,7 +1,5 @@
package org.eclipse.emf.mwe.internal.ui.workflow.util;
-import java.io.IOException;
-import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
@@ -17,7 +15,8 @@ import org.eclipse.jdt.core.JavaCore;
/**
* This ResourceLoader is capable of loading resources from a specific Java project within the workspace.
* Typical use is when invoking a workflow from within a plugin.
- *
+ *
+ * FIXME: Refactor this class to repect the EMFPlugin
*/
public class ProjectIncludingResourceLoader extends ResourceLoaderDefaultImpl {
private final ClassLoader projectCL;
@@ -49,22 +48,12 @@ public class ProjectIncludingResourceLoader extends ResourceLoaderDefaultImpl {
}
@Override
- protected URL internalGetResource(final String path) {
+ protected URL loadFromContextClassLoader(final String path) {
URL resource = projectCL.getResource(path);
if ( resource == null ) {
- resource = super.internalGetResource(path);
+ resource = super.loadFromContextClassLoader(path);
}
return resource;
}
- @Override
- protected InputStream internalGetResourceAsStream(final String path) {
- URL url = internalGetResource(path);
- try {
- return url != null ? url.openStream() : null;
- } catch (IOException e) {
- return null;
- }
- }
-
} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.mwe.tests/src/org/eclipse/emf/mwe/tests/ast/util/WorkflowFactoryTest.java b/tests/org.eclipse.emf.mwe.tests/src/org/eclipse/emf/mwe/tests/ast/util/WorkflowFactoryTest.java
index a0f5b98..6fabefb 100644
--- a/tests/org.eclipse.emf.mwe.tests/src/org/eclipse/emf/mwe/tests/ast/util/WorkflowFactoryTest.java
+++ b/tests/org.eclipse.emf.mwe.tests/src/org/eclipse/emf/mwe/tests/ast/util/WorkflowFactoryTest.java
@@ -27,7 +27,7 @@ import test.res.SubComponent;
@SuppressWarnings("unchecked")
public class WorkflowFactoryTest extends AbstractWorkflowParsingTestBase {
-
+
String simpleWorkflow1 = "<workflow> "
+ " <property name='property' value='true'/> "
+ " <component class='test.res.Component' booleanParam='true' booleanObjectParam='true'>"
@@ -44,6 +44,7 @@ public class WorkflowFactoryTest extends AbstractWorkflowParsingTestBase {
+ "</workflow> ";
public void testSimpleWorkflow() {
+ Component.INVOCATIONS = 0;
final Workflow cont = parseWorkflow(new StringInputStream(simpleWorkflow1), Collections.EMPTY_MAP);
assertNoIssues();
assertNotNull(cont);
diff --git a/tests/org.eclipse.emf.mwe.tests/src/org/eclipse/emf/mwe/tests/util/DummyResourceLoader.java b/tests/org.eclipse.emf.mwe.tests/src/org/eclipse/emf/mwe/tests/util/DummyResourceLoader.java
index 842daf9..5c6acf9 100644
--- a/tests/org.eclipse.emf.mwe.tests/src/org/eclipse/emf/mwe/tests/util/DummyResourceLoader.java
+++ b/tests/org.eclipse.emf.mwe.tests/src/org/eclipse/emf/mwe/tests/util/DummyResourceLoader.java
@@ -16,7 +16,6 @@ package org.eclipse.emf.mwe.tests.util;
import java.io.InputStream;
import java.net.URL;
-import java.util.Enumeration;
import org.eclipse.emf.mwe.core.resources.ResourceLoader;
@@ -39,8 +38,4 @@ public class DummyResourceLoader implements ResourceLoader {
return null;
}
- public Enumeration<URL> getResources(String uri) {
- return null;
- }
-
}