### Eclipse Workspace Patch 1.0 #P org.eclipse.gmf.tests Index: src/org/eclipse/gmf/tests/gen/RTFigureTest.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/RTFigureTest.java,v retrieving revision 1.2 diff -u -r1.2 RTFigureTest.java --- src/org/eclipse/gmf/tests/gen/RTFigureTest.java 24 Feb 2006 15:09:10 -0000 1.2 +++ src/org/eclipse/gmf/tests/gen/RTFigureTest.java 27 Feb 2006 22:01:51 -0000 @@ -13,78 +13,81 @@ import junit.framework.TestCase; +import org.eclipse.core.runtime.IStatus; import org.eclipse.gmf.gmfgraph.Alignment; +import org.eclipse.gmf.gmfgraph.BorderLayout; +import org.eclipse.gmf.gmfgraph.BorderLayoutData; +import org.eclipse.gmf.gmfgraph.CustomFigure; import org.eclipse.gmf.gmfgraph.Dimension; import org.eclipse.gmf.gmfgraph.Figure; import org.eclipse.gmf.gmfgraph.GMFGraphFactory; -import org.eclipse.gmf.gmfgraph.GridLayout; -import org.eclipse.gmf.gmfgraph.GridLayoutData; +import org.eclipse.gmf.gmfgraph.Layout; +import org.eclipse.gmf.gmfgraph.LayoutData; import org.eclipse.gmf.gmfgraph.RGBColor; +import org.eclipse.gmf.graphdef.codegen.standalone.GMFGraphTree; +import org.eclipse.gmf.graphdef.codegen.standalone.StandaloneGenerator; +import org.eclipse.gmf.graphdef.codegen.standalone.StandaloneGeneratorConfig; public class RTFigureTest extends TestCase { public void testRTGeneration() { - GMFGraphGenerator.Config config = new GMFGraphGenerator.ConfigImpl( + StandaloneGeneratorConfig config = new StandaloneGenerator.ConfigImpl( "com.test.plugin." + getName() + ".t" + System.currentTimeMillis(), "com.test.figures"); - GMFGraphGenerator.GMFGraphTree tree = new GMFGraphGenerator.GMFGraphTree.EObjectAdapter(createSampleFigure()); - GMFGraphGenerator generator = new GMFGraphGenerator(tree, config); + GMFGraphTree tree = new GMFGraphTree.EObjectAdapter(createSampleFigure()); + StandaloneGenerator generator = new StandaloneGenerator(tree, config); generator.run(); - assertTrue(generator.getRunStatus().isOK()); + IStatus status = generator.getRunStatus(); + assertTrue(status.getMessage(), status.isOK()); } private Figure createSampleFigure() { Figure parent = GMFGraphFactory.eINSTANCE.createRectangle(); parent.setName("Parent"); - parent.setLayout(createGridLayout()); + parent.setLayout(createLayout()); Figure leftGreenFilled = GMFGraphFactory.eINSTANCE.createRectangle(); leftGreenFilled.setName("LeftGreen"); RGBColor green = GMFGraphFactory.eINSTANCE.createRGBColor(); green.setGreen(255); leftGreenFilled.setBackgroundColor(green); - leftGreenFilled.setLayoutData(createGridLayoutData(true)); + leftGreenFilled.setLayoutData(createLayoutData(Alignment.BEGINNING_LITERAL, false)); Figure rightRedOutline = GMFGraphFactory.eINSTANCE.createRectangle(); - rightRedOutline.setName("RightRed"); + rightRedOutline.setName("CenterRed"); RGBColor red = GMFGraphFactory.eINSTANCE.createRGBColor(); red.setRed(255); rightRedOutline.setForegroundColor(green); - rightRedOutline.setLayoutData(createGridLayoutData(false)); + rightRedOutline.setLayoutData(createLayoutData(Alignment.FILL_LITERAL, true)); + + CustomFigure bottomCustom = GMFGraphFactory.eINSTANCE.createCustomFigure(); + bottomCustom.setName("BottomCustom"); + bottomCustom.setBundleName("org.eclipse.gmf.runtime.diagram.ui.geoshapes"); + bottomCustom.setQualifiedClassName("org.eclipse.gmf.runtime.diagram.ui.geoshapes.internal.draw2d.figures.GeoShapeCylinderFigure"); + RGBColor blue = GMFGraphFactory.eINSTANCE.createRGBColor(); + red.setBlue(255); + bottomCustom.setForegroundColor(blue); parent.getChildren().add(leftGreenFilled); parent.getChildren().add(rightRedOutline); + parent.getChildren().add(bottomCustom); return parent; } - private GridLayout createGridLayout() { - GridLayout layout = GMFGraphFactory.eINSTANCE.createGridLayout(); - layout.setEqualWidth(true); - layout.setNumColumns(2); - - Dimension margins = GMFGraphFactory.eINSTANCE.createDimension(); - margins.setDx(5); - margins.setDy(10); - layout.setMargins(margins); - + private Layout createLayout() { + BorderLayout layout = GMFGraphFactory.eINSTANCE.createBorderLayout(); Dimension spacing = GMFGraphFactory.eINSTANCE.createDimension(); spacing.setDx(7); spacing.setDy(8); layout.setSpacing(spacing); - return layout; } - private GridLayoutData createGridLayoutData(boolean horizontalBeginningNotEnd) { - GridLayoutData data = GMFGraphFactory.eINSTANCE.createGridLayoutData(); - data.setGrabExcessHorizontalSpace(true); - data.setGrabExcessVerticalSpace(false); - data.setHorizontalAlignment(horizontalBeginningNotEnd ? Alignment.BEGINNING_LITERAL : Alignment.END_LITERAL); - data.setVerticalAlignment(Alignment.CENTER_LITERAL); - data.setHorizontalIndent(5); - data.setHorizontalSpan(1); - data.setVerticalSpan(1); + private LayoutData createLayoutData(Alignment alignment, boolean isVerticalAlignment) { + BorderLayoutData data = GMFGraphFactory.eINSTANCE.createBorderLayoutData(); + data.setAlignment(alignment); + data.setVertical(isVerticalAlignment); return data; } Index: src/org/eclipse/gmf/tests/gen/GMFGraphGenerator.java =================================================================== RCS file: src/org/eclipse/gmf/tests/gen/GMFGraphGenerator.java diff -N src/org/eclipse/gmf/tests/gen/GMFGraphGenerator.java --- src/org/eclipse/gmf/tests/gen/GMFGraphGenerator.java 20 Feb 2006 12:18:33 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,193 +0,0 @@ -package org.eclipse.gmf.tests.gen; - -import java.net.URL; -import java.util.Collections; -import java.util.List; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.emf.codegen.jet.JETException; -import org.eclipse.emf.common.util.TreeIterator; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.gmf.common.UnexpectedBehaviourException; -import org.eclipse.gmf.common.codegen.GeneratorBase; -import org.eclipse.gmf.common.codegen.ImportUtil; -import org.eclipse.gmf.gmfgraph.Figure; -import org.eclipse.gmf.gmfgraph.util.FigureQualifiedNameSwitch; -import org.eclipse.gmf.graphdef.codegen.FigureGenerator; - -public class GMFGraphGenerator extends GeneratorBase { - private final Config myConfig; - private final Emitter myFigureGenerator; - private final GMFGraphTree myInputTree; - - public static interface Config { - public String getPluginName(); - public String getMainPackageName(); - } - - public static class ConfigImpl implements Config { - private final String myMainPackageName; - private final String myPluginName; - - public ConfigImpl(String pluginName, String mainPackageName){ - myPluginName = pluginName; - myMainPackageName = mainPackageName; - } - - public String getMainPackageName() { - return myMainPackageName; - } - - public String getPluginName() { - return myPluginName; - } - } - - public interface GMFGraphTree { - public TreeIterator getTreeContents(); - - public static class ResourceAdapter implements GMFGraphTree { - private final Resource myResource; - - public ResourceAdapter(Resource resource){ - myResource = resource; - } - - public TreeIterator getTreeContents() { - return myResource.getAllContents(); - } - } - - public static class EObjectAdapter implements GMFGraphTree { - private final EObject myRoot; - - public EObjectAdapter(EObject root){ - myRoot = root; - } - - public TreeIterator getTreeContents() { - return new TreeIteratorWithRoot(myRoot); - } - - private static class TreeIteratorWithRoot implements TreeIterator { - private final EObject myRoot; - private TreeIterator myContents; - private long myVisitedCount; - private boolean myIsRootCancelled; - - public TreeIteratorWithRoot(EObject root){ - myRoot = root; - } - - public void remove(){ - throw new UnsupportedOperationException(); - } - - private boolean isRootVisited(){ - return myVisitedCount > 0; - } - - private boolean isContentsVisitingStarted(){ - return myVisitedCount > 1; - } - - public boolean hasNext() { - if (myIsRootCancelled){ - return false; - } - return !isRootVisited() || myContents.hasNext(); - } - - public Object next() { - if (myIsRootCancelled){ - throw new IllegalStateException(); - } - Object result; - if (isRootVisited()){ - result = myContents.next(); - } else { - result = myRoot; - myContents = myRoot.eAllContents(); - } - myVisitedCount++; - return result; - } - - public void prune() { - if (!isRootVisited()){ - throw new IllegalStateException("You have at least try first"); - } - if (isContentsVisitingStarted()){ - myContents.prune(); - } else { - myIsRootCancelled = true; - } - } - } - } - } - - public GMFGraphGenerator(GMFGraphTree inputTree, Config config){ - myInputTree = inputTree; - myConfig = config; - myFigureGenerator = new FigureGeneratorAdapter( // - new FigureGenerator(getPackageName(), new ImportUtil(getPackageName()), new FigureQualifiedNameSwitch()) - ); - } - - protected void setupProgressMonitor() { - //setupProgressMonitor("Generating GMFGraph plugin", 100); - } - - protected URL getJMergeControlFile() { - return null; - } - - protected List createReferencedProjectsList() { - return Collections.EMPTY_LIST; - } - - protected void customRun() throws InterruptedException, JETException, UnexpectedBehaviourException { - initializeEditorProject(myConfig.getPluginName(), createReferencedProjectsList()); - try { - generateTopLevelFigures(); - } catch (IllegalStateException e){ - throw new UnexpectedBehaviourException(e); - } - } - - private void generateTopLevelFigures() throws InterruptedException { - for (TreeIterator treeContents = myInputTree.getTreeContents(); treeContents.hasNext();){ - EObject next = (EObject) treeContents.next(); - if (next instanceof Figure){ - visitFigure((Figure)next); - treeContents.prune(); - } - } - } - - private void visitFigure(Figure figure) throws InterruptedException { - doGenerateJavaClass(myFigureGenerator, getPackageName(), figure.getName(), figure); - } - - private String getPackageName(){ - return myConfig.getMainPackageName(); - } - - private static class FigureGeneratorAdapter implements GeneratorBase.Emitter { - private final FigureGenerator myDelegate; - - public FigureGeneratorAdapter(FigureGenerator delegate){ - myDelegate = delegate; - } - - public String generate(IProgressMonitor monitor, Object param) throws JETException { - if (false == param instanceof Figure){ - throw new IllegalStateException("Figure expected: " + param); - } - return myDelegate.go((Figure)param); - } - } - -} 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.3 diff -u -r1.3 FigureCodegenTestBase.java --- src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java 24 Feb 2006 15:11:33 -0000 1.3 +++ src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java 27 Feb 2006 22:01:51 -0000 @@ -11,8 +11,13 @@ */ package org.eclipse.gmf.tests.gen; +import java.net.MalformedURLException; + import junit.framework.TestCase; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IStatus; import org.eclipse.emf.codegen.jet.JETException; import org.eclipse.gmf.common.codegen.ImportUtil; import org.eclipse.gmf.gmfgraph.ConnectionFigure; @@ -30,11 +35,18 @@ import org.eclipse.gmf.gmfgraph.RoundedRectangle; import org.eclipse.gmf.gmfgraph.util.FigureQualifiedNameSwitch; import org.eclipse.gmf.graphdef.codegen.FigureGenerator; +import org.eclipse.gmf.graphdef.codegen.standalone.GMFGraphTree; +import org.eclipse.gmf.graphdef.codegen.standalone.StandaloneGenerator; +import org.eclipse.gmf.graphdef.codegen.standalone.StandaloneGeneratorConfig; +import org.eclipse.gmf.tests.CompileUtil; +import org.eclipse.gmf.tests.Plugin; import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTParser; import org.eclipse.jdt.core.dom.CompilationUnit; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleException; /** * TODO generate project, compile and instaniate figures to make sure values are set (like figure's bg/fg color) @@ -83,12 +95,41 @@ } } + private StandaloneGeneratorConfig getGMFGraphGeneratorConfig(){ + return new StandaloneGenerator.ConfigImpl(getTestPluginName(), getFigurePackageName()); + } + + protected final Class generateAndCompile(StandaloneGeneratorConfig config, Figure figure) { + try { + GMFGraphTree tree = new GMFGraphTree.EObjectAdapter(figure); + StandaloneGenerator generator = new StandaloneGenerator(tree, config); + generator.run(); + assertTrue(generator.getRunStatus().getSeverity() < IStatus.ERROR); + + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(config.getPluginID()); + IStatus compileStatus = new CompileUtil().build(project); + assertTrue(compileStatus.getMessage(), compileStatus.getSeverity() < IStatus.ERROR); + + String url = project.getLocation().toFile().toURL().toExternalForm(); + Bundle bundle = Plugin.getBundleContext().installBundle(url); + + return bundle.loadClass(config.getMainPackageName() + "." + figure.getName()); + } catch (MalformedURLException e) { + fail(e.getMessage()); + } catch (BundleException e) { + fail(e.getMessage()); + } catch (ClassNotFoundException e) { + fail(e.getMessage()); + } + throw new InternalError("Impossible"); + } + // custom top-level, hierarchical children. protected final Figure figure1() { CustomFigure cf = GMFGraphFactory.eINSTANCE.createCustomFigure(); cf.setName("MyCylinder"); - cf.setBundleName("org.eclipse.gmf.runtime.geoshapes"); - cf.setQualifiedClassName("org.eclipse.gmf.runtime.geoshapes.internal.GeoShapeCylinder"); + cf.setBundleName("org.eclipse.gmf.runtime.diagram.ui.geoshapes"); + cf.setQualifiedClassName("org.eclipse.gmf.runtime.diagram.ui.geoshapes.internal.draw2d.figures.GeoShapeCylinderFigure"); Point p = GMFGraphFactory.eINSTANCE.createPoint(); p.setX(1023); p.setY(33); #P org.eclipse.gmf.graphdef.codegen Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.graphdef.codegen/META-INF/MANIFEST.MF,v retrieving revision 1.6 diff -u -r1.6 MANIFEST.MF --- META-INF/MANIFEST.MF 13 Feb 2006 17:36:18 -0000 1.6 +++ META-INF/MANIFEST.MF 27 Feb 2006 22:01:52 -0000 @@ -12,4 +12,5 @@ org.eclipse.emf.codegen, org.eclipse.draw2d -Export-Package: org.eclipse.gmf.graphdef.codegen +Export-Package: org.eclipse.gmf.graphdef.codegen, + org.eclipse.gmf.graphdef.codegen.standalone Index: .jetproperties =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.graphdef.codegen/.jetproperties,v retrieving revision 1.1 diff -u -r1.1 .jetproperties --- .jetproperties 6 Jan 2006 19:17:28 -0000 1.1 +++ .jetproperties 27 Feb 2006 22:01:52 -0000 @@ -1,4 +1,4 @@ - templates src + templates;standalone_templates src Index: src/org/eclipse/gmf/graphdef/codegen/standalone/templates/BuildPropertiesGenerator.java =================================================================== RCS file: src/org/eclipse/gmf/graphdef/codegen/standalone/templates/BuildPropertiesGenerator.java diff -N src/org/eclipse/gmf/graphdef/codegen/standalone/templates/BuildPropertiesGenerator.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/graphdef/codegen/standalone/templates/BuildPropertiesGenerator.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,25 @@ +package org.eclipse.gmf.graphdef.codegen.standalone.templates; + +public class BuildPropertiesGenerator +{ + protected static String nl; + public static synchronized BuildPropertiesGenerator create(String lineSeparator) + { + nl = lineSeparator; + BuildPropertiesGenerator result = new BuildPropertiesGenerator(); + nl = null; + return result; + } + + protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "source.. = src/" + NL + "output.. = bin/" + NL + "bin.includes = META-INF/,\\"; + protected final String TEXT_2 = NL; + + public String generate(Object argument) + { + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append(TEXT_1); + stringBuffer.append(TEXT_2); + return stringBuffer.toString(); + } +} Index: src/org/eclipse/gmf/graphdef/codegen/standalone/StandaloneGenerator.java =================================================================== RCS file: src/org/eclipse/gmf/graphdef/codegen/standalone/StandaloneGenerator.java diff -N src/org/eclipse/gmf/graphdef/codegen/standalone/StandaloneGenerator.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/graphdef/codegen/standalone/StandaloneGenerator.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,210 @@ +/* + * 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.graphdef.codegen.standalone; + +import java.net.URL; +import java.util.Collections; +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.emf.codegen.jet.JETException; +import org.eclipse.emf.common.util.TreeIterator; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.gmf.common.UnexpectedBehaviourException; +import org.eclipse.gmf.common.codegen.GeneratorBase; +import org.eclipse.gmf.common.codegen.ImportAssistant; +import org.eclipse.gmf.common.codegen.ImportUtil; +import org.eclipse.gmf.gmfgraph.Figure; +import org.eclipse.gmf.gmfgraph.util.FigureQualifiedNameSwitch; +import org.eclipse.gmf.graphdef.codegen.FigureGenerator; +import org.eclipse.gmf.graphdef.codegen.MapModeCodeGenStrategy; + +public class StandaloneGenerator extends GeneratorBase { + private final Args myArgs; + private final Emitter myFigureGenerator; + private final StandaloneEmitters myAuxiliaryGenerators; + private boolean mySkipPluginStructire; + + public static class Args { + private final GMFGraphTree myInput; + private final StandaloneGeneratorConfig myConfig; + + public Args(StandaloneGeneratorConfig config, GMFGraphTree input){ + myConfig = config; + myInput = input; + } + + public StandaloneGeneratorConfig getConfig() { + return myConfig; + } + + public GMFGraphTree getInput() { + return myInput; + } + } + + public static class ConfigImpl implements StandaloneGeneratorConfig { + private final String myPluginId; + private final String myMainPackageName; + private final String myPluginFriendlyName; + private final String myPluginProviderName; + + private final String myPluginActivatorClassName; + private final String myPluginActivatorPackageName; + + private final boolean myNeedsMapMode; + + public ConfigImpl(String pluginId, String mainPackageName){ + this(pluginId, mainPackageName, pluginId, "", DEFAULT_PLUGIN_ACTIVATOR, mainPackageName + ".activator", true); + } + + public ConfigImpl(String pluginId, String mainPackageName, String pluginFriendlyName, String pluginProviderName, String pluginActivatorClassName, String pluginActivatorPackageName, boolean needsMapMode){ + myPluginId = pluginId; + myMainPackageName = mainPackageName; + myPluginFriendlyName = pluginFriendlyName; + myPluginProviderName = pluginProviderName; + myPluginActivatorClassName = pluginActivatorClassName; + myPluginActivatorPackageName = pluginActivatorPackageName; + myNeedsMapMode = needsMapMode; + } + + public String getMainPackageName() { + return myMainPackageName; + } + + public String getPluginFriendlyName() { + return myPluginFriendlyName; + } + + public String getPluginID() { + return myPluginId; + } + + public String getPluginProviderName() { + return myPluginProviderName; + } + + public String getPluginActivatorClassName() { + return myPluginActivatorClassName; + } + + public String getPluginActivatorPackageName() { + return myPluginActivatorPackageName; + } + + public boolean needsMapMode() { + return myNeedsMapMode; + } + } + + public StandaloneGenerator(GMFGraphTree inputTree, StandaloneGeneratorConfig config){ + this(new Args(config, inputTree)); + } + + public StandaloneGenerator(Args args){ + myArgs = args; + ImportAssistant importAssistant = new ImportUtil(getPackageName()); + String pluginActivatorFQN = composePluginActivatorClassFQN(myArgs.getConfig()); + MapModeCodeGenStrategy strategy = new MapModeCodeGenStrategy.RuntimeMapModeFromPluginClass( // + importAssistant, pluginActivatorFQN); + + myFigureGenerator = new FigureGeneratorAdapter( // + new FigureGenerator(getPackageName(), importAssistant, new FigureQualifiedNameSwitch(), strategy) + ); + myAuxiliaryGenerators = new StandaloneEmitters(); + } + + /** + * Allows clients to skip generating of manifest.mf, pligin and build properties files. + * "New-plugin-by-template" generator uses this feature because it delegates this generation to PDE defaults. + */ + public void setSkipPluginStructure(boolean skipManifest){ + mySkipPluginStructire = skipManifest; + } + + private static String composePluginActivatorClassFQN(StandaloneGeneratorConfig config) { + String packageName = config.getPluginActivatorPackageName(); + String className = config.getPluginActivatorClassName(); + return packageName == null || "".equals(packageName) ? className : packageName + "." + className; + } + + protected void setupProgressMonitor() { + //setupProgressMonitor("Generating GMFGraph plugin", 100); + } + + protected URL getJMergeControlFile() { + return null; + } + + protected List createReferencedProjectsList() { + return Collections.EMPTY_LIST; + } + + protected void customRun() throws InterruptedException, JETException, UnexpectedBehaviourException { + initializeEditorProject(myArgs.getConfig().getPluginID(), createReferencedProjectsList()); + + if (!mySkipPluginStructire){ + generatePluginStructure(); + } + try { + generatePluginActivator(); + generateTopLevelFigures(); + } catch (IllegalStateException e){ + throw new UnexpectedBehaviourException(e); + } + } + + private void generatePluginActivator() throws JETException, InterruptedException{ + doGenerateJavaClass(myAuxiliaryGenerators.getPluginActivatorEmitter(), myArgs.getConfig().getPluginActivatorPackageName(), myArgs.getConfig().getPluginActivatorClassName(), myArgs); + } + + private void generatePluginStructure() throws JETException, InterruptedException { + doGenerateFile(myAuxiliaryGenerators.getBuildPropertiesEmitter(), new Path("build.properties"), myArgs); + doGenerateFile(myAuxiliaryGenerators.getManifestMFEmitter(), new Path("META-INF/MANIFEST.MF"), myArgs); + doGenerateFile(myAuxiliaryGenerators.getPluginPropertiesEmitter(), new Path("plugin.properties"), myArgs); + } + + private void generateTopLevelFigures() throws InterruptedException { + for (TreeIterator treeContents = myArgs.getInput().getTreeContents(); treeContents.hasNext();){ + EObject next = (EObject) treeContents.next(); + if (next instanceof Figure){ + visitFigure((Figure)next); + treeContents.prune(); + } + } + } + + private void visitFigure(Figure figure) throws InterruptedException { + doGenerateJavaClass(myFigureGenerator, getPackageName(), figure.getName(), figure); + } + + private String getPackageName(){ + return myArgs.getConfig().getMainPackageName(); + } + + private static class FigureGeneratorAdapter implements GeneratorBase.Emitter { + private final FigureGenerator myDelegate; + + public FigureGeneratorAdapter(FigureGenerator delegate){ + myDelegate = delegate; + } + + public String generate(IProgressMonitor monitor, Object param) throws JETException { + if (false == param instanceof Figure){ + throw new IllegalStateException("Figure expected: " + param); + } + return myDelegate.go((Figure)param); + } + } + +} Index: src/org/eclipse/gmf/graphdef/codegen/standalone/GMFGraphTree.java =================================================================== RCS file: src/org/eclipse/gmf/graphdef/codegen/standalone/GMFGraphTree.java diff -N src/org/eclipse/gmf/graphdef/codegen/standalone/GMFGraphTree.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/graphdef/codegen/standalone/GMFGraphTree.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,117 @@ +/* + * 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.graphdef.codegen.standalone; + +import java.util.Collection; +import java.util.Iterator; + +import org.eclipse.emf.common.util.TreeIterator; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.gmf.gmfgraph.util.GMFGraphSwitch; + +public interface GMFGraphTree { + public TreeIterator getTreeContents(); + public void acceptSwitch(GMFGraphSwitch graphSwitch, Collection output); + + public static abstract class TreeBase implements GMFGraphTree { + public void acceptSwitch(GMFGraphSwitch graphSwitch, Collection output) { + for (Iterator contents = getTreeContents(); contents.hasNext();){ + EObject next = (EObject)contents.next(); + Object nextResult = graphSwitch.doSwitch(next); + if (nextResult != null){ + output.add(nextResult); + } + } + } + } + + public static class ResourceAdapter extends TreeBase { + private final Resource myResource; + + public ResourceAdapter(Resource resource){ + myResource = resource; + } + + public TreeIterator getTreeContents() { + return myResource.getAllContents(); + } + } + + public static class EObjectAdapter extends TreeBase { + private final EObject myRoot; + + public EObjectAdapter(EObject root){ + myRoot = root; + } + + public TreeIterator getTreeContents() { + return new TreeIteratorWithRoot(myRoot); + } + + private static class TreeIteratorWithRoot implements TreeIterator { + private final EObject myRoot; + private TreeIterator myContents; + private long myVisitedCount; + private boolean myIsRootCancelled; + + public TreeIteratorWithRoot(EObject root){ + myRoot = root; + } + + public void remove(){ + throw new UnsupportedOperationException(); + } + + private boolean isRootVisited(){ + return myVisitedCount > 0; + } + + private boolean isContentsVisitingStarted(){ + return myVisitedCount > 1; + } + + public boolean hasNext() { + if (myIsRootCancelled){ + return false; + } + return !isRootVisited() || myContents.hasNext(); + } + + public Object next() { + if (myIsRootCancelled){ + throw new IllegalStateException(); + } + Object result; + if (isRootVisited()){ + result = myContents.next(); + } else { + result = myRoot; + myContents = myRoot.eAllContents(); + } + myVisitedCount++; + return result; + } + + public void prune() { + if (!isRootVisited()){ + throw new IllegalStateException("You have at least try first"); + } + if (isContentsVisitingStarted()){ + myContents.prune(); + } else { + myIsRootCancelled = true; + } + } + } + } +} Index: src/org/eclipse/gmf/graphdef/codegen/standalone/templates/PluginPropertiesGenerator.java =================================================================== RCS file: src/org/eclipse/gmf/graphdef/codegen/standalone/templates/PluginPropertiesGenerator.java diff -N src/org/eclipse/gmf/graphdef/codegen/standalone/templates/PluginPropertiesGenerator.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/graphdef/codegen/standalone/templates/PluginPropertiesGenerator.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,35 @@ +package org.eclipse.gmf.graphdef.codegen.standalone.templates; + +import org.eclipse.gmf.graphdef.codegen.standalone.*; + +public class PluginPropertiesGenerator +{ + protected static String nl; + public static synchronized PluginPropertiesGenerator create(String lineSeparator) + { + nl = lineSeparator; + PluginPropertiesGenerator result = new PluginPropertiesGenerator(); + nl = null; + return result; + } + + protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "pluginName = "; + protected final String TEXT_2 = NL + "providerName = "; + protected final String TEXT_3 = NL; + + public String generate(Object argument) + { + StringBuffer stringBuffer = new StringBuffer(); + +final StandaloneGenerator.Args args = (StandaloneGenerator.Args)argument; +final StandaloneGeneratorConfig config = args.getConfig(); + + stringBuffer.append(TEXT_1); + stringBuffer.append(config.getPluginFriendlyName()); + stringBuffer.append(TEXT_2); + stringBuffer.append(config.getPluginProviderName()); + stringBuffer.append(TEXT_3); + return stringBuffer.toString(); + } +} Index: src/org/eclipse/gmf/graphdef/codegen/standalone/RequiredPluginsCollectorBase.java =================================================================== RCS file: src/org/eclipse/gmf/graphdef/codegen/standalone/RequiredPluginsCollectorBase.java diff -N src/org/eclipse/gmf/graphdef/codegen/standalone/RequiredPluginsCollectorBase.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/graphdef/codegen/standalone/RequiredPluginsCollectorBase.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,52 @@ +/* + * 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.graphdef.codegen.standalone; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.gmf.gmfgraph.util.GMFGraphBundleSwitch; +import org.eclipse.gmf.gmfgraph.util.GMFGraphSwitch; + +public class RequiredPluginsCollectorBase { + private final HashSet myBundles; + private final GMFGraphSwitch mySwitch; + + public RequiredPluginsCollectorBase() { + myBundles = new HashSet(); + mySwitch = new GMFGraphBundleSwitch(); + } + + public void visitAll(Iterator contents){ + while(contents.hasNext()){ + EObject next = (EObject)contents.next(); + String nextBundle = (String)mySwitch.doSwitch(next); + if (nextBundle != null){ + registerRequiredBundle(nextBundle); + } + } + } + + public void visitAll(GMFGraphTree tree){ + visitAll(tree.getTreeContents()); + } + + protected void registerRequiredBundle(String bundleId){ + myBundles.add(bundleId); + } + + public Set getCollectedBundles(){ + return (Set)myBundles.clone(); + } +} Index: standalone_templates/Plugin.javajet =================================================================== RCS file: standalone_templates/Plugin.javajet diff -N standalone_templates/Plugin.javajet --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ standalone_templates/Plugin.javajet 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,108 @@ +<%@ jet package="org.eclipse.gmf.graphdef.codegen.standalone.templates" class="PluginActivatorGenerator" + imports="org.eclipse.gmf.graphdef.codegen.standalone.* org.eclipse.gmf.common.codegen.ImportAssistant"%> +<% +final Object[] passedArgs = (Object[])argument; +final StandaloneGenerator.Args genArgs = (StandaloneGenerator.Args)passedArgs[0]; +final ImportAssistant importManager = (ImportAssistant)passedArgs[1]; +final StandaloneGeneratorConfig config = genArgs.getConfig(); + +importManager.emitPackageStatement(stringBuffer); +%> + +import org.eclipse.core.runtime.Plugin; + +<% +if (config.needsMapMode()){ +%> +import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode; +import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeTypes; +<% +} +%> + +import org.osgi.framework.BundleContext; +<%importManager.markImportLocation(stringBuffer);%> + +/** + * @generated + */ +public class <%=config.getPluginActivatorClassName()%> extends Plugin { + +<% +if (config.needsMapMode()){ +%> + private IMapMode myMapMode = MapModeTypes.IDENTITY_MM; +<% +} +%> + + /** + * @generated + */ + public static final String ID = "<%=config.getPluginID()%>"; //$NON-NLS-1$ + + /** + * @generated + */ + private static <%=config.getPluginActivatorClassName()%> ourInstance; + + /** + * @generated + */ + public <%=config.getPluginActivatorClassName()%>() { + } + + /** + * @generated + */ + public void start(BundleContext context) throws Exception { + super.start(context); + if (ourInstance != null){ + throw new IllegalStateException("Plugin: " + ID + " already started"); + } + ourInstance = this; + } + + /** + * @generated + */ + public void stop(BundleContext context) throws Exception { + if (ourInstance == null){ + throw new IllegalStateException("Plugin: " + ID + " is not started"); + } + ourInstance = null; + super.stop(context); + } + +<% +if (config.needsMapMode()){ +%> + /** + * @generated + */ + public void setMapMode(IMapMode mapMode) { + myMapMode = mapMode; + if (myMapMode == null){ + myMapMode = MapModeTypes.IDENTITY_MM; + } + } + + /** + * @generated + */ + public IMapMode getMapMode() { + return myMapMode; + } + +<% +} +%> + + /** + * @generated + */ + public static <%=config.getPluginActivatorClassName()%> getDefault() { + return ourInstance; + } +} +<%importManager.emitSortedImports();%> Index: standalone_templates/build.properties.jet =================================================================== RCS file: standalone_templates/build.properties.jet diff -N standalone_templates/build.properties.jet --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ standalone_templates/build.properties.jet 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,4 @@ +<%@ jet package="org.eclipse.gmf.graphdef.codegen.standalone.templates" class="BuildPropertiesGenerator"%> +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ Index: src/org/eclipse/gmf/graphdef/codegen/standalone/templates/PluginActivatorGenerator.java =================================================================== RCS file: src/org/eclipse/gmf/graphdef/codegen/standalone/templates/PluginActivatorGenerator.java diff -N src/org/eclipse/gmf/graphdef/codegen/standalone/templates/PluginActivatorGenerator.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/graphdef/codegen/standalone/templates/PluginActivatorGenerator.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,85 @@ +package org.eclipse.gmf.graphdef.codegen.standalone.templates; + +import org.eclipse.gmf.graphdef.codegen.standalone.*; +import org.eclipse.gmf.common.codegen.ImportAssistant; + +public class PluginActivatorGenerator +{ + protected static String nl; + public static synchronized PluginActivatorGenerator create(String lineSeparator) + { + nl = lineSeparator; + PluginActivatorGenerator result = new PluginActivatorGenerator(); + nl = null; + return result; + } + + protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = NL + "import org.eclipse.core.runtime.Plugin;" + NL; + protected final String TEXT_2 = NL + "import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;" + NL + "import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeTypes;"; + protected final String TEXT_3 = NL + NL + "import org.osgi.framework.BundleContext;"; + protected final String TEXT_4 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class "; + protected final String TEXT_5 = " extends Plugin {" + NL; + protected final String TEXT_6 = NL + "\tprivate IMapMode myMapMode = MapModeTypes.IDENTITY_MM;"; + protected final String TEXT_7 = NL + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final String ID = \""; + protected final String TEXT_8 = "\"; //$NON-NLS-1$" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static "; + protected final String TEXT_9 = " ourInstance;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic "; + protected final String TEXT_10 = "() {" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void start(BundleContext context) throws Exception {" + NL + "\t\tsuper.start(context);" + NL + "\t\tif (ourInstance != null){" + NL + "\t\t\tthrow new IllegalStateException(\"Plugin: \" + ID + \" already started\");" + NL + "\t\t}" + NL + "\t\tourInstance = this;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void stop(BundleContext context) throws Exception {" + NL + "\t\tif (ourInstance == null){" + NL + "\t\t\tthrow new IllegalStateException(\"Plugin: \" + ID + \" is not started\");" + NL + "\t\t}" + NL + "\t\tourInstance = null;" + NL + "\t\tsuper.stop(context);" + NL + "\t}" + NL + "\t"; + protected final String TEXT_11 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void setMapMode(IMapMode mapMode) {" + NL + "\t\tmyMapMode = mapMode;" + NL + "\t\tif (myMapMode == null){" + NL + "\t\t\tmyMapMode = MapModeTypes.IDENTITY_MM;" + NL + "\t\t}" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic IMapMode getMapMode() {" + NL + "\t\treturn myMapMode;" + NL + "\t}" + NL; + protected final String TEXT_12 = NL + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static "; + protected final String TEXT_13 = " getDefault() {" + NL + "\t\treturn ourInstance;" + NL + "\t}" + NL + "}"; + protected final String TEXT_14 = NL; + + public String generate(Object argument) + { + StringBuffer stringBuffer = new StringBuffer(); + +final Object[] passedArgs = (Object[])argument; +final StandaloneGenerator.Args genArgs = (StandaloneGenerator.Args)passedArgs[0]; +final ImportAssistant importManager = (ImportAssistant)passedArgs[1]; +final StandaloneGeneratorConfig config = genArgs.getConfig(); + +importManager.emitPackageStatement(stringBuffer); + + stringBuffer.append(TEXT_1); + +if (config.needsMapMode()){ + + stringBuffer.append(TEXT_2); + +} + + stringBuffer.append(TEXT_3); + importManager.markImportLocation(stringBuffer); + stringBuffer.append(TEXT_4); + stringBuffer.append(config.getPluginActivatorClassName()); + stringBuffer.append(TEXT_5); + +if (config.needsMapMode()){ + + stringBuffer.append(TEXT_6); + +} + + stringBuffer.append(TEXT_7); + stringBuffer.append(config.getPluginID()); + stringBuffer.append(TEXT_8); + stringBuffer.append(config.getPluginActivatorClassName()); + stringBuffer.append(TEXT_9); + stringBuffer.append(config.getPluginActivatorClassName()); + stringBuffer.append(TEXT_10); + +if (config.needsMapMode()){ + + stringBuffer.append(TEXT_11); + +} + + stringBuffer.append(TEXT_12); + stringBuffer.append(config.getPluginActivatorClassName()); + stringBuffer.append(TEXT_13); + importManager.emitSortedImports(); + stringBuffer.append(TEXT_14); + return stringBuffer.toString(); + } +} Index: standalone_templates/plugin.properties.jet =================================================================== RCS file: standalone_templates/plugin.properties.jet diff -N standalone_templates/plugin.properties.jet --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ standalone_templates/plugin.properties.jet 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,8 @@ +<%@ jet package="org.eclipse.gmf.graphdef.codegen.standalone.templates" class="PluginPropertiesGenerator" + imports="org.eclipse.gmf.graphdef.codegen.standalone.*"%> +<% +final StandaloneGenerator.Args args = (StandaloneGenerator.Args)argument; +final StandaloneGeneratorConfig config = args.getConfig(); +%> +pluginName = <%=config.getPluginFriendlyName()%> +providerName = <%=config.getPluginProviderName()%> Index: src/org/eclipse/gmf/graphdef/codegen/standalone/StandaloneEmitters.java =================================================================== RCS file: src/org/eclipse/gmf/graphdef/codegen/standalone/StandaloneEmitters.java diff -N src/org/eclipse/gmf/graphdef/codegen/standalone/StandaloneEmitters.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/graphdef/codegen/standalone/StandaloneEmitters.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,72 @@ +/* + * 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.graphdef.codegen.standalone; + +import org.eclipse.emf.codegen.jet.JETEmitter; +import org.eclipse.emf.codegen.jet.JETException; +import org.eclipse.gmf.common.UnexpectedBehaviourException; +import org.eclipse.gmf.graphdef.codegen.standalone.templates.BuildPropertiesGenerator; +import org.eclipse.gmf.graphdef.codegen.standalone.templates.ManifestMFGenerator; +import org.eclipse.gmf.graphdef.codegen.standalone.templates.PluginActivatorGenerator; +import org.eclipse.gmf.graphdef.codegen.standalone.templates.PluginPropertiesGenerator; +import org.eclipse.gmf.internal.codegen.dispatch.EmitterFactory; +import org.eclipse.gmf.internal.codegen.dispatch.NoSuchTemplateException; +import org.eclipse.gmf.internal.codegen.dispatch.StaticTemplateRegistry; +import org.eclipse.gmf.internal.codegen.dispatch.TemplateRegistry; + +public class StandaloneEmitters extends EmitterFactory { + private static final String[] TEMPLATE_PATH = {"standalone_templates"}; + + public StandaloneEmitters(){ + super(TEMPLATE_PATH, createTemplateRegistry()); + } + + public JETEmitter getBuildPropertiesEmitter() throws JETException { + return getRegistered(BuildPropertiesGenerator.class); + } + + public JETEmitter getPluginPropertiesEmitter() throws JETException { + return getRegistered(PluginPropertiesGenerator.class); + } + + public JETEmitter getManifestMFEmitter() throws JETException { + return getRegistered(ManifestMFGenerator.class); + } + + public JETEmitter getPluginActivatorEmitter() throws JETException { + return getRegistered(PluginActivatorGenerator.class); + } + + private JETEmitter getRegistered(Class key) throws JETException { + try { + return acquireEmitter(key); + } catch (NoSuchTemplateException ex) { + throw new JETException(ex.getClass().getName(), ex); + } catch (UnexpectedBehaviourException ex) { + throw new JETException(ex.getClass().getName(), ex); + } + } + + private static TemplateRegistry createTemplateRegistry() { + StaticTemplateRegistry result = new StaticTemplateRegistry(StandaloneEmitters.class.getClassLoader()); + registerTemplate(result, BuildPropertiesGenerator.class, "/build.properties.jet"); + registerTemplate(result, ManifestMFGenerator.class, "/manifest.mf.jet"); + registerTemplate(result, PluginPropertiesGenerator.class, "/plugin.properties.jet"); + registerTemplate(result, PluginActivatorGenerator.class, "/plugin.javajet"); + return result; + } + + private static void registerTemplate(StaticTemplateRegistry registry, Class compiled, String path){ + registry.put(compiled, path, compiled); + } + +} Index: src/org/eclipse/gmf/graphdef/codegen/standalone/StandaloneGeneratorConfig.java =================================================================== RCS file: src/org/eclipse/gmf/graphdef/codegen/standalone/StandaloneGeneratorConfig.java diff -N src/org/eclipse/gmf/graphdef/codegen/standalone/StandaloneGeneratorConfig.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/graphdef/codegen/standalone/StandaloneGeneratorConfig.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,27 @@ +/* + * 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.graphdef.codegen.standalone; + +public interface StandaloneGeneratorConfig { + public static final String DEFAULT_PLUGIN_ACTIVATOR = "PluginActivator"; + + public String getPluginID(); + public String getPluginFriendlyName(); + public String getPluginProviderName(); + public String getMainPackageName(); + + public String getPluginActivatorClassName(); + public String getPluginActivatorPackageName(); + + public boolean needsMapMode(); +} Index: src/org/eclipse/gmf/graphdef/codegen/standalone/templates/ManifestMFGenerator.java =================================================================== RCS file: src/org/eclipse/gmf/graphdef/codegen/standalone/templates/ManifestMFGenerator.java diff -N src/org/eclipse/gmf/graphdef/codegen/standalone/templates/ManifestMFGenerator.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/graphdef/codegen/standalone/templates/ManifestMFGenerator.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,68 @@ +package org.eclipse.gmf.graphdef.codegen.standalone.templates; + +import java.util.*; +import org.eclipse.gmf.graphdef.codegen.standalone.*; + +public class ManifestMFGenerator +{ + protected static String nl; + public static synchronized ManifestMFGenerator create(String lineSeparator) + { + nl = lineSeparator; + ManifestMFGenerator result = new ManifestMFGenerator(); + nl = null; + return result; + } + + protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "Manifest-Version: 1.0" + NL + "Bundle-ManifestVersion: 2" + NL + "Bundle-Name: %pluginName" + NL + "Bundle-SymbolicName: "; + protected final String TEXT_2 = "; singleton:=true" + NL + "Bundle-Version: 1.0.0" + NL + "Bundle-Vendor: %providerName" + NL + "Bundle-Localization: plugin"; + protected final String TEXT_3 = NL + "Export-Package: "; + protected final String TEXT_4 = NL + "Require-Bundle: "; + protected final String TEXT_5 = NL + "Eclipse-LazyStart: true"; + + public String generate(Object argument) + { + StringBuffer stringBuffer = new StringBuffer(); + +final StandaloneGenerator.Args args = (StandaloneGenerator.Args)argument; +final StandaloneGeneratorConfig config = args.getConfig(); +final GMFGraphTree inputTree = args.getInput(); + +class ListComposer { + public String composeList(Collection strings){ + StringBuffer result = new StringBuffer(); + for (Iterator it = strings.iterator(); it.hasNext();){ + result.append(" "); //do not miss required space here + result.append(it.next()); + if (it.hasNext()){ + result.append(", " + NL); + } + } + return result.toString(); + } +} + +final ListComposer listComposer = new ListComposer(); + + stringBuffer.append(TEXT_1); + stringBuffer.append(config.getPluginID()); + stringBuffer.append(TEXT_2); + + HashSet exportedPackages = new HashSet(); + exportedPackages.add(config.getMainPackageName()); + exportedPackages.add(config.getPluginActivatorPackageName()); + + stringBuffer.append(TEXT_3); + stringBuffer.append(listComposer.composeList(exportedPackages)); + + RequiredPluginsCollector collector = new RequiredPluginsCollector(config); + collector.visitAll(inputTree); + Set requiredBundles = collector.getCollectedBundles(); + + stringBuffer.append(TEXT_4); + stringBuffer.append(listComposer.composeList(requiredBundles)); + stringBuffer.append(TEXT_5); + return stringBuffer.toString(); + } +} Index: src/org/eclipse/gmf/graphdef/codegen/standalone/RequiredPluginsCollector.java =================================================================== RCS file: src/org/eclipse/gmf/graphdef/codegen/standalone/RequiredPluginsCollector.java diff -N src/org/eclipse/gmf/graphdef/codegen/standalone/RequiredPluginsCollector.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/graphdef/codegen/standalone/RequiredPluginsCollector.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,30 @@ +/* + * 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.graphdef.codegen.standalone; + +/** + * Captures knowledge about implicit plugin dependencies required by any standalone figure plugin + */ +public class RequiredPluginsCollector extends RequiredPluginsCollectorBase { + public RequiredPluginsCollector(StandaloneGeneratorConfig config){ + super(); + registerRequiredBundle("org.eclipse.gef"); + registerRequiredBundle("org.eclipse.draw2d"); + registerRequiredBundle("org.eclipse.osgi"); + registerRequiredBundle("org.eclipse.core.runtime"); + if (config.needsMapMode()){ + registerRequiredBundle("org.eclipse.gmf.runtime.draw2d.ui"); + } + } + +} Index: standalone_templates/manifest.mf.jet =================================================================== RCS file: standalone_templates/manifest.mf.jet diff -N standalone_templates/manifest.mf.jet --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ standalone_templates/manifest.mf.jet 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,43 @@ +<%@ jet package="org.eclipse.gmf.graphdef.codegen.standalone.templates" class="ManifestMFGenerator" + imports="java.util.* org.eclipse.gmf.graphdef.codegen.standalone.*"%> +<% +final StandaloneGenerator.Args args = (StandaloneGenerator.Args)argument; +final StandaloneGeneratorConfig config = args.getConfig(); +final GMFGraphTree inputTree = args.getInput(); + +class ListComposer { + public String composeList(Collection strings){ + StringBuffer result = new StringBuffer(); + for (Iterator it = strings.iterator(); it.hasNext();){ + result.append(" "); //do not miss required space here + result.append(it.next()); + if (it.hasNext()){ + result.append(", " + NL); + } + } + return result.toString(); + } +} + +final ListComposer listComposer = new ListComposer(); +%> +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: <%=config.getPluginID()%>; singleton:=true +Bundle-Version: 1.0.0 +Bundle-Vendor: %providerName +Bundle-Localization: plugin +<% + HashSet exportedPackages = new HashSet(); + exportedPackages.add(config.getMainPackageName()); + exportedPackages.add(config.getPluginActivatorPackageName()); +%> +Export-Package: <%=listComposer.composeList(exportedPackages)%> +<% + RequiredPluginsCollector collector = new RequiredPluginsCollector(config); + collector.visitAll(inputTree); + Set requiredBundles = collector.getCollectedBundles(); +%> +Require-Bundle: <%=listComposer.composeList(requiredBundles)%> +Eclipse-LazyStart: true #P org.eclipse.gmf.graphdef Index: src/org/eclipse/gmf/gmfgraph/util/GMFGraphBundleSwitch.java =================================================================== RCS file: src/org/eclipse/gmf/gmfgraph/util/GMFGraphBundleSwitch.java diff -N src/org/eclipse/gmf/gmfgraph/util/GMFGraphBundleSwitch.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/gmfgraph/util/GMFGraphBundleSwitch.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,114 @@ +/* + * 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.gmfgraph.util; + +import org.eclipse.gmf.gmfgraph.BorderLayout; +import org.eclipse.gmf.gmfgraph.CustomClass; +import org.eclipse.gmf.gmfgraph.Ellipse; +import org.eclipse.gmf.gmfgraph.FlowLayout; +import org.eclipse.gmf.gmfgraph.GridLayout; +import org.eclipse.gmf.gmfgraph.GridLayoutData; +import org.eclipse.gmf.gmfgraph.Label; +import org.eclipse.gmf.gmfgraph.LabeledContainer; +import org.eclipse.gmf.gmfgraph.Polygon; +import org.eclipse.gmf.gmfgraph.PolygonDecoration; +import org.eclipse.gmf.gmfgraph.Polyline; +import org.eclipse.gmf.gmfgraph.PolylineConnection; +import org.eclipse.gmf.gmfgraph.PolylineDecoration; +import org.eclipse.gmf.gmfgraph.Rectangle; +import org.eclipse.gmf.gmfgraph.RoundedRectangle; +import org.eclipse.gmf.gmfgraph.StackLayout; +import org.eclipse.gmf.gmfgraph.XYLayout; +import org.eclipse.gmf.gmfgraph.XYLayoutData; + +public class GMFGraphBundleSwitch extends GMFGraphSwitch { + + public Object caseCustomClass(CustomClass object) { + return object.getBundleName(); + } + + public Object caseGridLayout(GridLayout object) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public Object caseGridLayoutData(GridLayoutData object) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public Object caseFlowLayout(FlowLayout object) { + return draw2d(); + } + + public Object caseXYLayout(XYLayout object) { + return draw2d(); + } + + public Object caseXYLayoutData(XYLayoutData object) { + return draw2d(); + } + + public Object caseStackLayout(StackLayout object) { + return draw2d(); + } + + public Object caseBorderLayout(BorderLayout object) { + return draw2d(); + } + + public Object caseLabel(Label object) { + return draw2d(); + } + + public Object caseLabeledContainer(LabeledContainer object) { + return draw2d(); + } + + public Object caseRectangle(Rectangle object) { + return draw2d(); + } + + public Object caseRoundedRectangle(RoundedRectangle object) { + return draw2d(); + } + + public Object caseEllipse(Ellipse object) { + return draw2d(); + } + + public Object casePolygon(Polygon object) { + return draw2d(); + } + + public Object casePolygonDecoration(PolygonDecoration object) { + return draw2d(); + } + + public Object casePolyline(Polyline object) { + return draw2d(); + } + + public Object casePolylineDecoration(PolylineDecoration object) { + return draw2d(); + } + + public Object casePolylineConnection(PolylineConnection object) { + return runtimeDraw2dUI(); + } + + private String draw2d(){ + return "org.eclipse.draw2d"; //$NON-NLS-1$ + } + + private String runtimeDraw2dUI(){ + return "org.eclipse.gmf.runtime.draw2d.ui"; //$NON-NLS-1$ + } +} #P org.eclipse.gmf.common Index: src/org/eclipse/gmf/common/codegen/GeneratorBase.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.common/src/org/eclipse/gmf/common/codegen/GeneratorBase.java,v retrieving revision 1.1 diff -u -r1.1 GeneratorBase.java --- src/org/eclipse/gmf/common/codegen/GeneratorBase.java 20 Feb 2006 12:18:34 -0000 1.1 +++ src/org/eclipse/gmf/common/codegen/GeneratorBase.java 27 Feb 2006 22:01:54 -0000 @@ -207,7 +207,7 @@ String genText = emitter.generate(new SubProgressMonitor(pm, 1), input); IPackageFragment pf = myDestRoot.createPackageFragment(packageName, true, new SubProgressMonitor(pm, 1)); ICompilationUnit cu = pf.getCompilationUnit(className + ".java"); //$NON-NLS-1$ - if (cu.exists()) { + if (cu.exists() && canMerge()) { genText = merge(genText, cu.getSource(), new SubProgressMonitor(pm, 1)); } else { pm.worked(1); @@ -223,8 +223,15 @@ pm.done(); } } + + protected final boolean canMerge(){ + return getJControlModel() != null; + } protected final String merge(String generatedText, String oldContents, IProgressMonitor pm) { + if (!canMerge()){ + throw new IllegalStateException("Can not initialize JMerge model"); + } pm.beginTask(GeneratorBaseMessages.merge, 1); JMerger jMerge = new JMerger(); jMerge.setControlModel(getJControlModel()); @@ -271,7 +278,9 @@ private JControlModel getJControlModel() { if (myJControlModel == null) { URL controlFile = getJMergeControlFile(); - myJControlModel = controlFile == null ? createEmptyJControlModel() : new JControlModel(controlFile.toString()); + if (controlFile != null){ + myJControlModel = new JControlModel(controlFile.toString()); + } } return myJControlModel; }