Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoratikhomirov2006-01-24 15:42:30 +0000
committeratikhomirov2006-01-24 15:42:30 +0000
commitb090cdfeeb8489492a55353366915485206d5320 (patch)
tree18951084b1bb1db8929a6ac232e0ed4454d30087 /tests
parent4caacb07aedc8f6db6f4a501cc1034586adf9128 (diff)
downloadorg.eclipse.gmf-tooling-b090cdfeeb8489492a55353366915485206d5320.tar.gz
org.eclipse.gmf-tooling-b090cdfeeb8489492a55353366915485206d5320.tar.xz
org.eclipse.gmf-tooling-b090cdfeeb8489492a55353366915485206d5320.zip
another approach to enable tests runs from development environment. This time, with incredible speed up and no use of PDE internal code
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/GenProjectBaseSetup.java1
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/RuntimeWorkspaceSetup.java181
2 files changed, 124 insertions, 58 deletions
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/GenProjectBaseSetup.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/GenProjectBaseSetup.java
index ac6a94519..880ee4519 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/GenProjectBaseSetup.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/GenProjectBaseSetup.java
@@ -52,6 +52,7 @@ public class GenProjectBaseSetup {
Generator generator = new Generator(d);
generator.run();
hookGeneratorStatus(generator.getRunStatus());
+ rtWorkspace.updateClassPath(ResourcesPlugin.getWorkspace().getRoot().getProject(d.getPluginID()));
projectsToInit.add(d.getPluginID());
for (Iterator it = projectsToInit.iterator(); it.hasNext();) {
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/RuntimeWorkspaceSetup.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/RuntimeWorkspaceSetup.java
index 76f5d93ae..4e5dbb626 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/RuntimeWorkspaceSetup.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/RuntimeWorkspaceSetup.java
@@ -11,33 +11,44 @@
*/
package org.eclipse.gmf.tests.setup;
+import java.io.ByteArrayInputStream;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Set;
-import junit.framework.AssertionFailedError;
-
-import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.codegen.ecore.Generator;
import org.eclipse.gmf.tests.Plugin;
-import org.eclipse.jdt.core.IJavaModelMarker;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.pde.internal.core.PDECore;
-import org.eclipse.pde.internal.core.PDEState;
-import org.eclipse.pde.internal.ui.wizards.imports.PluginImportOperation;
import org.osgi.framework.Bundle;
/**
- * With PDE, we need source code in the running workspace to allow compilation of our code
+ * ALMOST TRUE: With PDE, we need source code in the running workspace to allow compilation of our code
* (because PDE doesn't reexport set of plugins from it's running configuration, and it's no longer possible
* to set Target Platform to "same as running" as it was back in Eclipse 2.x).
*
+ * !!! NEW !!!
+ *
+ * Now, we managed to compile against linked binary folders, although using linked content instead of plugins
+ * requires us to explicitly add some plugins earlier available through plugin re-export (namely, oe.jface.text)
+ *
+ *
* Classloading works because there's -dev argument in the command line. With PDE launch, it's done by PDE.
* Without PDE, running tests as part of the build relies on Eclipse Testing Framework's org.eclipse.test_3.1.0/library.xml
* which specifies "-dev bin". Once it's not specified, or new format (properties file with plugin-id=binfolder)
@@ -49,7 +60,28 @@ import org.osgi.framework.Bundle;
*/
public class RuntimeWorkspaceSetup {
+ /**
+ * Copy of <code>PDECore.CLASSPATH_CONTAINER_ID</code>
+ */
+ private static final String PLUGIN_CONTAINER_ID = "org.eclipse.pde.core.requiredPlugins";
+
+ private boolean isDevLaunchMode;
+
public RuntimeWorkspaceSetup() {
+ isDevLaunchMode = isDevLaunchMode();
+ }
+
+ /**
+ * Copy (almost, except for strange unused assignment) of <code>PDECore.isDevLaunchMode()</code>
+ */
+ private static boolean isDevLaunchMode() {
+ String[] args = Platform.getApplicationArgs();
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].equals("-pdelaunch")) { //$NON-NLS-1$
+ return true;
+ }
+ }
+ return false;
}
/**
@@ -58,10 +90,10 @@ public class RuntimeWorkspaceSetup {
// TODO Refactor to clear away similar code (CodeCompilationTest, RuntimeWorkspaceSetup, GenProjectSetup)
public RuntimeWorkspaceSetup init() throws Exception {
ensureJava14();
- if (PDECore.isDevLaunchMode()) {
+ if (isDevLaunchMode) {
// Need to get some gmf source code into target workspace
importDevPluginsIntoRunTimeWorkspace(new String[] {
- "org.apache.batik",
+// "org.apache.batik",
"org.eclipse.gmf.runtime.notation",
"org.eclipse.gmf.runtime.notation.edit",
"org.eclipse.wst.common.ui.properties",
@@ -92,7 +124,7 @@ public class RuntimeWorkspaceSetup {
"org.eclipse.gmf.runtime.diagram.ui.resources.editor",
"org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide",
"org.eclipse.gmf.runtime.notation.providers",
- "antlr", //$NON-NLS-1$
+// "antlr", //$NON-NLS-1$
"org.eclipse.emf.ocl", //$NON-NLS-1$
"org.eclipse.emf.query", //$NON-NLS-1$
"org.eclipse.emf.query.ocl", //$NON-NLS-1$
@@ -101,25 +133,89 @@ public class RuntimeWorkspaceSetup {
return this;
}
+ public static IProject getSOSProject() {
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(".SOSProject");
+ }
+
+ /**
+ * Another approach - output binary folders of required plugins are linked as subfolders
+ * of our own sosProject (created in the target workspace). Then, we could use library classpathEntries
+ * (details why we should use _workspace_ paths for libraries could be found at
+ * <code>org.eclipse.jdt.internal.core.builder.NameEnvironment#computeClasspathLocations</code>)
+ *
+ * TODO don't assume workspace is clear, check sosProject existence first
+ * TODO utilize GenDiagram.requiredPluginIDs once it's a field (i.e. add oe.jface.text and don't create plugin project then, just plain project with links
+ */
private void importDevPluginsIntoRunTimeWorkspace(String[] pluginIDs) throws CoreException {
- PDEState pdeState = new PDEState(getDevPluginsLocations(pluginIDs), false, new NullProgressMonitor());
- PluginImportOperation.IImportQuery query = new PluginImportOperation.IImportQuery() {
- public int doQuery(String arg0) {
- return YES;
+ IProject p = getSOSProject();
+ final Path srcPath = new Path('/' + p.getName() + "/src"); //$NON-NLS-1$
+ Generator.createEMFProject(srcPath, null, Collections.EMPTY_LIST, new NullProgressMonitor(), Generator.EMF_PLUGIN_PROJECT_STYLE, null);
+ URL[] urls = getDevPluginsLocations(pluginIDs);
+ for (int i = 0; i < urls.length; i++) {
+ IPath path = new Path(urls[i].getPath());
+ IFolder f = p.getFolder(path.lastSegment().replace('.', '_'));
+ f.createLink(path.append("bin/"), IResource.REPLACE, new NullProgressMonitor());
+ }
+
+ StringBuffer pluginXmlContent = new StringBuffer();
+ pluginXmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?eclipse version=\"3.0\"?>\n<plugin ");
+ pluginXmlContent.append(" version=\"1.0.0\" name='%providerName' id='");
+ pluginXmlContent.append(p.getName());
+ pluginXmlContent.append("'>\n<requires>\n");
+ pluginXmlContent.append("<import plugin='org.eclipse.jface.text' export='true'/>");
+ pluginXmlContent.append("</requires>\n</plugin>");
+ p.getFile("plugin.xml").create(new ByteArrayInputStream(pluginXmlContent.toString().getBytes()), true, new NullProgressMonitor());
+ }
+
+ private IJavaProject asJavaProject(IProject p) {
+ return JavaCore.create(p);
+ }
+
+ /**
+ * TODO uniqueClassPathEntries is not needed if diagramProj gets here only once. It's not the case
+ * now - refactor LinkCreationConstraintsTest to utilize genProject created in AuditRulesTest (?)
+ * TODO refactor with ClasspathContainerInitializer - just for the sake of fixing the knowledge
+ */
+ public void updateClassPath(IProject diagramProj) throws CoreException {
+ if (!isDevLaunchMode) {
+ return;
+ }
+ IResource[] members;
+ try {
+ members = getSOSProject().members();
+ } catch (CoreException ex) {
+ ex.printStackTrace();
+ members = new IResource[0];
+ }
+ final IJavaProject sosJavaPrj = asJavaProject(getSOSProject());
+ IClasspathEntry[] cpOrig = asJavaProject(diagramProj).getRawClasspath();
+ ArrayList rv = new ArrayList(10 + cpOrig.length + members.length);
+ rv.addAll(Arrays.asList(cpOrig));
+ IClasspathContainer c = JavaCore.getClasspathContainer(new Path(PLUGIN_CONTAINER_ID), sosJavaPrj);
+ if (c != null) {
+ IClasspathEntry[] cpAdd = c.getClasspathEntries();
+ rv.addAll(Arrays.asList(cpAdd));
+ }
+ for (int i = 0; i < members.length; i++) {
+ if (members[i].getType() != IResource.FOLDER || !members[i].isLinked()) {
+ continue;
}
- };
- PluginImportOperation op = new PluginImportOperation(pdeState.getModels(), PluginImportOperation.IMPORT_BINARY, query, query, true);
- ResourcesPlugin.getWorkspace().run(op, new NullProgressMonitor());
- for (int i = 0; i < pluginIDs.length; i++) {
- IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(pluginIDs[i]);
- p.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
- IMarker[] compileErrors = getJavaErrors(p);
- if (compileErrors.length > 0) {
- String errorsMsg = formatErrors(new StringBuffer("UNEXPECTED: Compilation errors in imported plugin " + pluginIDs[i] + ":\n"), compileErrors);
- Plugin.logError(errorsMsg);
- throw new AssertionFailedError(errorsMsg);
+ rv.add(JavaCore.newLibraryEntry(members[i].getFullPath(), null, null));
+ }
+ IPath antlrPath = new Path(getDevPluginsLocations(new String[] {"antlr"})[0].getPath());
+ rv.add(JavaCore.newLibraryEntry(antlrPath.append("lib/antlr.jar"), null, null));
+
+ final Set uniqueClassPathEntries = new HashSet();
+ for (Iterator it = rv.iterator(); it.hasNext();) {
+ IClasspathEntry next = (IClasspathEntry) it.next();
+ if (uniqueClassPathEntries.contains(next.getPath())) {
+ it.remove();
+ } else {
+ uniqueClassPathEntries.add(next.getPath());
}
}
+ IClasspathEntry[] cpNew = (IClasspathEntry[]) rv.toArray(new IClasspathEntry[rv.size()]);
+ asJavaProject(diagramProj).setRawClasspath(cpNew, new NullProgressMonitor());
}
private URL[] getDevPluginsLocations(String[] pluginIDs) {
@@ -140,37 +236,6 @@ public class RuntimeWorkspaceSetup {
return (URL[]) urls.toArray(new URL[urls.size()]);
}
- private IMarker[] collectJavaMarkers(IProject p) throws CoreException {
- return p.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
- }
-
- private IMarker[] getJavaErrors(IProject p) throws CoreException {
- return filterSevereMarkers(collectJavaMarkers(p));
- }
-
- private IMarker[] filterSevereMarkers(IMarker[] problems) throws CoreException {
- ArrayList rv = new ArrayList(problems.length);
- for (int i = 0; i < problems.length; i++) {
- if (IMarker.SEVERITY_ERROR == ((Integer) problems[i].getAttribute(IMarker.SEVERITY)).intValue()) {
- rv.add(problems[i]);
- }
- }
- return (IMarker[]) rv.toArray(new IMarker[rv.size()]);
- }
-
- private String formatErrors(StringBuffer sb, IMarker[] compileErrors) {
- for (int i = 0; i < compileErrors.length; i++) {
- try {
- sb.append(compileErrors[i].getAttribute(IMarker.MESSAGE));
- } catch (CoreException ex) {
- sb.append("--ex:");
- sb.append(ex.getMessage());
- }
- sb.append(",\n");
- }
- return sb.toString();
- }
-
/**
* at least
*/

Back to the top