### Eclipse Workspace Patch 1.0 #P org.eclipse.gmf.tests Index: src/org/eclipse/gmf/tests/AllTests.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/AllTests.java,v retrieving revision 1.36 diff -u -r1.36 AllTests.java --- src/org/eclipse/gmf/tests/AllTests.java 31 Mar 2006 18:08:34 -0000 1.36 +++ src/org/eclipse/gmf/tests/AllTests.java 3 Apr 2006 15:58:30 -0000 @@ -31,6 +31,7 @@ import org.eclipse.gmf.tests.gen.RTFigureTest; import org.eclipse.gmf.tests.gen.ShapePropertiesTest; import org.eclipse.gmf.tests.gen.StandaloneMapModeTest; +import org.eclipse.gmf.tests.gen.StandalonePluginConverterTest; import org.eclipse.gmf.tests.gen.ToolDefHandocodedImplTest; import org.eclipse.gmf.tests.gen.ViewmapProducersTest; import org.eclipse.gmf.tests.rt.AuditRulesTest; @@ -66,6 +67,7 @@ suite.addTestSuite(ShapePropertiesTest.class); suite.addTestSuite(FigureLayoutTest.class); suite.addTestSuite(StandaloneMapModeTest.class); + suite.addTestSuite(StandalonePluginConverterTest.class); suite.addTestSuite(RTFigureTest.class); suite.addTestSuite(MapModeStrategyTest.class); suite.addTestSuite(ViewmapProducersTest.class); Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/tests/org.eclipse.gmf.tests/META-INF/MANIFEST.MF,v retrieving revision 1.16 diff -u -r1.16 MANIFEST.MF --- META-INF/MANIFEST.MF 31 Mar 2006 16:50:32 -0000 1.16 +++ META-INF/MANIFEST.MF 3 Apr 2006 15:58:30 -0000 @@ -15,7 +15,8 @@ org.eclipse.gmf.runtime.emf.commands.core, org.eclipse.gmf.graphdef.codegen, org.eclipse.gmf.tooldef, - org.eclipse.emf.validation, - org.eclipse.gmf.codegen.ui + org.eclipse.emf.validation, + org.eclipse.gmf.codegen.ui, + org.eclipse.gmf.graphdef.codegen.ui Bundle-Activator: org.eclipse.gmf.tests.Plugin Eclipse-LazyStart: true Index: src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java,v retrieving revision 1.9 diff -u -r1.9 FigureCodegenTestBase.java --- src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java 31 Mar 2006 16:50:32 -0000 1.9 +++ src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java 3 Apr 2006 15:58:30 -0000 @@ -12,6 +12,8 @@ package org.eclipse.gmf.tests.gen; import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.Iterator; import junit.framework.Assert; import junit.framework.TestCase; @@ -122,24 +124,37 @@ } protected final Class generateAndCompile(StandaloneGenerator.Config config, Figure figure) { + FigureGallery gallery = GMFGraphFactory.eINSTANCE.createFigureGallery(); + gallery.setName("bb"); + gallery.getFigures().add(figure); + gallery.setImplementationBundle(Plugin.getPluginID()); + + GeneratedClassData[] theOnly = generateAndCompile(config, gallery); + assertNotNull(theOnly); + assertEquals(1, theOnly.length); + return theOnly[0].getLoadedClass(); + } + + protected final GeneratedClassData[] generateAndCompile(StandaloneGenerator.Config config, FigureGallery gallery) { + if (gallery.getName() == null){ + gallery.setName("NameDoesNotMakeSense"); + } + assertNotNull(gallery.getImplementationBundle()); + assertFalse(gallery.getFigures().isEmpty()); + try { - FigureGallery fg = GMFGraphFactory.eINSTANCE.createFigureGallery(); - fg.setName("bb"); - fg.getFigures().add(figure); - fg.setImplementationBundle(Plugin.getPluginID()); - StandaloneGenerator generator = new StandaloneGenerator(fg, config, new RuntimeFQNSwitch()); + StandaloneGenerator generator = new StandaloneGenerator(gallery, config, new RuntimeFQNSwitch()); generator.run(); assertTrue(generator.getRunStatus().getSeverity() < IStatus.ERROR); - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(config.getPluginID()); - SessionSetup.getRuntimeWorkspaceSetup().updateClassPath(project); - IStatus compileStatus = new CompileUtil().build(project); - assertTrue(compileStatus.getMessage(), compileStatus.getSeverity() < IStatus.ERROR); + Bundle bundle = installPlugin(config.getPluginID()); - String url = project.getLocation().toFile().toURL().toExternalForm(); - Bundle bundle = Plugin.getBundleContext().installBundle(url); - - return bundle.loadClass(config.getMainPackageName() + "." + figure.getName()); + ArrayList result = new ArrayList(); + for (Iterator figures = gallery.getFigures().iterator(); figures.hasNext();){ + Figure next = (Figure) figures.next(); + result.add(new GeneratedClassData(next, bundle.loadClass(config.getMainPackageName() + "." + next.getName()))); + } + return (GeneratedClassData[]) result.toArray(new GeneratedClassData[result.size()]); } catch (MalformedURLException e) { fail(e.getMessage()); } catch (BundleException e) { @@ -153,6 +168,16 @@ } throw new InternalError("Impossible"); } + + protected final Bundle installPlugin(String pluginId) throws CoreException, Exception { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(pluginId); + SessionSetup.getRuntimeWorkspaceSetup().updateClassPath(project); + IStatus compileStatus = new CompileUtil().build(project); + assertTrue(compileStatus.getMessage(), compileStatus.getSeverity() < IStatus.ERROR); + + String url = project.getLocation().toFile().toURL().toExternalForm(); + return Plugin.getBundleContext().installBundle(url); + } // custom top-level, hierarchical children, no custom properties protected final Figure figure1() { @@ -297,6 +322,24 @@ public abstract void checkFigure(IFigure figure); } + protected static class GeneratedClassData { + private final Figure myFigureDef; + private final Class myLoadedClass; + + public GeneratedClassData(Figure figureDef, Class loadedClass){ + myFigureDef = figureDef; + myLoadedClass = loadedClass; + } + + public Class getLoadedClass() { + return myLoadedClass; + } + + public Figure getFigureDef() { + return myFigureDef; + } + } + protected static final FigureCheck CHECK_CAN_CREATE_INSTANCE = new FigureCheck(){ public void checkFigure(IFigure figure) { // Index: src/org/eclipse/gmf/tests/gen/StandalonePluginConverterTest.java =================================================================== RCS file: src/org/eclipse/gmf/tests/gen/StandalonePluginConverterTest.java diff -N src/org/eclipse/gmf/tests/gen/StandalonePluginConverterTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/tests/gen/StandalonePluginConverterTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2006 Borland Software Corporation + * + * 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Michael Golubev (Borland) - initial API and implementation + */ + +package org.eclipse.gmf.tests.gen; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.gmf.gmfgraph.CustomFigure; +import org.eclipse.gmf.gmfgraph.Figure; +import org.eclipse.gmf.gmfgraph.FigureGallery; +import org.eclipse.gmf.gmfgraph.GMFGraphFactory; +import org.eclipse.gmf.gmfgraph.util.RuntimeFQNSwitch; +import org.eclipse.gmf.graphdef.codegen.StandaloneGenerator; +import org.eclipse.gmf.internal.graphdef.codegen.ui.StandaloneGalleryConverter; + +public class StandalonePluginConverterTest extends FigureCodegenTestBase { + + public StandalonePluginConverterTest(String name) { + super(name); + } + + public void testStandaloneGalleryConverter() throws Exception { + FigureGallery gallery = GMFGraphFactory.eINSTANCE.createFigureGallery(); + Figure[] originals = new Figure[] { + figure1(), + figure2(), + figure3(), + }; + + gallery.getFigures().addAll(Arrays.asList(originals)); + + final String standalonePlugin = "org.eclipse.gmf.tests.generated.custom.figures.t" + System.currentTimeMillis(); + final String customFiguresPackage = "custom.figures.pakkage"; + StandaloneGenerator.ConfigImpl config = new StandaloneGenerator.ConfigImpl(standalonePlugin, customFiguresPackage, false); + StandaloneGenerator generator = new StandaloneGenerator(gallery, config, new RuntimeFQNSwitch()); + generator.run(); + assertTrue(generator.getRunStatus().getSeverity() < IStatus.ERROR); + + StandaloneGenerator.GenerationInfo info = generator.getGenerationInfo(); + for (int i = 0; i < originals.length; i++){ + assertNotNull(info.getGeneratedClassFQN(originals[i])); + } + + StandaloneGalleryConverter galleryConverter = new StandaloneGalleryConverter(info); + FigureGallery mirroredGallery = galleryConverter.convertFigureGallery(); + assertEquals(standalonePlugin, mirroredGallery.getImplementationBundle()); + + assertEquals(3, mirroredGallery.getFigures().size()); + + for (Iterator mirroredFigures = mirroredGallery.getFigures().iterator(); mirroredFigures.hasNext();){ + Figure next = (Figure) mirroredFigures.next(); + assertTrue(next instanceof CustomFigure); + CustomFigure nextCustom = (CustomFigure)next; + assertNotNull(nextCustom.getName()); + assertEquals(standalonePlugin, nextCustom.getBundleName()); + assertTrue(nextCustom.getQualifiedClassName().startsWith(customFiguresPackage + ".")); + } + + installPlugin(standalonePlugin); + + //XXX: workaround for #134506 -- "GMFGraph generator should produce correct code if the name of CustomFigure is the same as its class's simple name" + Map workaroundNameMapping = new HashMap(); + for (Iterator mirroredFigures = mirroredGallery.getFigures().iterator(); mirroredFigures.hasNext();){ + Figure next = (Figure) mirroredFigures.next(); + String workaroundName = "My" + next.getName(); + workaroundNameMapping.put(next.getName(), workaroundName); + next.setName(workaroundName); + } + + GeneratedClassData[] mirroredClasses = generateAndCompile(getGMFGraphGeneratorConfig(), mirroredGallery); + for (int i = 0; i < originals.length; i++){ + Figure nextOriginal = originals[i]; + String workaroundName = (String) workaroundNameMapping.get(nextOriginal.getName()); + assertNotNull("Missed name for: " + nextOriginal.getName(), workaroundName); + Class nextClass = searchForFigureName(mirroredClasses, workaroundName); + assertNotNull("Missed class for : " + workaroundName, nextClass); + + FigureCheck nextCheck = new GenericFigureCheck(nextOriginal); + nextCheck.checkFigure(nextCheck.instantiateFigure(nextClass)); + } + } + + private static Class searchForFigureName(GeneratedClassData[] classes, String expectedName){ + Class result = null; + for (int i = 0; result == null && i < classes.length; i++){ + Class next = classes[i].getLoadedClass(); + if (expectedName.equals(classes[i].getFigureDef().getName())){ + result = next; + } + } + return result; + } +} #P org.eclipse.gmf.graphdef.codegen.ui Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.graphdef.codegen.ui/META-INF/MANIFEST.MF,v retrieving revision 1.2 diff -u -r1.2 MANIFEST.MF --- META-INF/MANIFEST.MF 7 Mar 2006 20:12:13 -0000 1.2 +++ META-INF/MANIFEST.MF 3 Apr 2006 15:58:31 -0000 @@ -15,3 +15,4 @@ org.eclipse.gmf.common, org.eclipse.ui, org.eclipse.jdt.core +Export-Package: org.eclipse.gmf.internal.graphdef.codegen.ui;x-friends:="org.eclipse.gmf.tests"