Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/Main.java42
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/InstanceDiagramGen.xtend62
-rw-r--r--plugins/org.eclipse.etrice.generator.launch.java/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.etrice.generator.launch.java/src/org/eclipse/etrice/generator/launch/java/JavaGeneratorConfigTab.java203
-rw-r--r--plugins/org.eclipse.etrice.generator.launch.java/src/org/eclipse/etrice/generator/launch/java/JavaGeneratorLaunchConfigurationDelegate.java9
-rw-r--r--plugins/org.eclipse.etrice.generator.launch.java/src/org/eclipse/etrice/generator/launch/java/JavaGeneratorLaunchConfigurationTabGroup.java1
6 files changed, 302 insertions, 18 deletions
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/Main.java b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/Main.java
index 90e376601..0bfae6831 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/Main.java
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/Main.java
@@ -27,6 +27,7 @@ import org.eclipse.etrice.generator.builder.GeneratorModelBuilder;
import org.eclipse.etrice.generator.builder.ILogger;
import org.eclipse.etrice.generator.etricegen.IDiagnostician;
import org.eclipse.etrice.generator.etricegen.Root;
+import org.eclipse.etrice.generator.java.gen.InstanceDiagramGen;
import org.eclipse.etrice.generator.java.setup.StandaloneSetup;
import org.eclipse.xtext.diagnostics.Severity;
import org.eclipse.xtext.generator.IGenerator;
@@ -41,6 +42,17 @@ import com.google.inject.Injector;
import com.google.inject.Provider;
public class Main {
+
+ /**
+ * print usage message to stderr
+ */
+ private static void printUsage() {
+ System.err.println(Main.class.getName()+" [-saveGenModel <genmodel path>] [-genInstDiag] <list of model file paths>");
+ System.err.println(" <list of model file paths> # model file paths may be specified as");
+ System.err.println(" # e.g. C:\\path\\to\\model\\mymodel.room");
+ System.err.println(" -saveGenModel <genmodel path> # if specified the generator model will be saved to this location");
+ System.err.println(" -genInstDiag # if specified an instance diagram is created for each subsystem");
+ }
public static void main(String[] args) {
if (args.length == 0) {
@@ -52,12 +64,16 @@ public class Main {
// parsing arguments
String genModelPath = null;
List<String> uriList = new ArrayList<String>();
+ boolean genInstDiag = false;
for (int i=0; i<args.length; ++i) {
if (args[i].equals("-saveGenModel")) {
if (++i<args.length) {
- genModelPath = convertToURI(args[i]);
+ genModelPath = convertToURI(args[i]+"/genmodel.rim");
}
}
+ else if (args[i].equals("-genInstDiag")) {
+ genInstDiag = true;
+ }
else {
uriList.add(convertToURI(args[i]));
}
@@ -70,7 +86,7 @@ public class Main {
Injector injector = new StandaloneSetup().createInjectorAndDoEMFRegistration();
Main main = injector.getInstance(Main.class);
- main.runGenerator(uriList, genModelPath, validator);
+ main.runGenerator(uriList, genModelPath, genInstDiag, validator);
}
private static String convertToURI(String uri) {
@@ -81,16 +97,6 @@ public class Main {
return "file://"+uri.replace('\\', '/');
}
}
-
- /**
- * print usage message to stderr
- */
- private static void printUsage() {
- System.err.println(Main.class.getName()+" [-saveGenModel <genmodel path>] <list of model file paths>");
- System.err.println(" <list of model file paths> # model file paths may be specified as");
- System.err.println(" # e.g. C:\\path\\to\\model\\mymodel.room");
- System.err.println(" -saveGenModel <genmodel path> # if specified the generator model will be saved to this location");
- }
@Inject
private Provider<ResourceSet> resourceSetProvider;
@@ -102,12 +108,15 @@ public class Main {
private IDiagnostician diagnostician;
@Inject
- private IGenerator generator;
+ private IGenerator mainGenerator;
@Inject
+ private InstanceDiagramGen instanceDiagramGenerator;
+
+ @Inject
private JavaIoFileSystemAccess fileAccess;
- protected void runGenerator(List<String> uriList, String genModelPath, IResourceValidator validator) {
+ protected void runGenerator(List<String> uriList, String genModelPath, boolean genInstDiag, IResourceValidator validator) {
ResourceSet rs = resourceSetProvider.get();
logger.logInfo("-- reading models");
@@ -184,7 +193,10 @@ public class Main {
}
logger.logInfo("-- starting code generation");
fileAccess.setOutputPath("src-gen/");
- generator.doGenerate(genResource, fileAccess);
+ mainGenerator.doGenerate(genResource, fileAccess);
+ if (genInstDiag) {
+ instanceDiagramGenerator.doGenerate(gmRoot);
+ }
logger.logInfo("-- finished code generation");
}
}
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/InstanceDiagramGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/InstanceDiagramGen.xtend
new file mode 100644
index 000000000..3ba0823d4
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/InstanceDiagramGen.xtend
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.java.gen
+
+import org.eclipse.xtext.generator.IFileSystemAccess
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess
+import com.google.inject.Inject
+
+import static extension org.eclipse.xtext.xtend2.lib.ResourceExtensions.*
+import static extension org.eclipse.xtext.xtend2.lib.*
+
+import org.eclipse.etrice.core.room.*
+import org.eclipse.etrice.generator.etricegen.*
+import org.eclipse.etrice.generator.java.setup.Logger
+
+class InstanceDiagramGen {
+
+ @Inject extension JavaIoFileSystemAccess fileAccess
+ @Inject extension StdExtensions stdExt
+ @Inject Logger logger
+
+ def doGenerate(Root root) {
+ for (sc: root.subSystemInstances) {
+ var path = sc.subSystemClass.generationTargetPath+sc.subSystemClass.getPath
+ var file = sc.subSystemClass.name+".dot"
+ logger.logInfo("generating instance diagram: '"+file+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(file, root.generate(sc, sc.subSystemClass))
+ }
+ }
+
+ def generate(Root root, SubSystemInstance ssc, SubSystemClass cc) {'''
+ digraph «ssc.name» {
+ rankdir=LR;
+ node [shape=box];
+ «cc.path.getPathName()» [label="«cc.name»\n(«ssc.name»)" style=filled color=yellow];
+ «FOR ai : ssc.instances»
+ «instance(ai)»
+ «ENDFOR»
+ }
+ '''
+ }
+
+ def instance(ActorInstance ai) {'''
+ «var parent = ai.eContainer as StructureInstance»
+ «ai.path.getPathName()» [label="«ai.name»\n(«ai.actorClass.name»)"];
+ «parent.path.getPathName()» -> «ai.path.getPathName()»;
+ «FOR sub_ai : ai.instances»
+ «instance(sub_ai)»
+ «ENDFOR»
+ '''}
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.generator.launch.java/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.generator.launch.java/META-INF/MANIFEST.MF
index 60001333d..f77f6ba22 100644
--- a/plugins/org.eclipse.etrice.generator.launch.java/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.generator.launch.java/META-INF/MANIFEST.MF
@@ -10,7 +10,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.debug.ui,
org.eclipse.jdt.ui;bundle-version="3.7.0",
org.eclipse.jdt.core;bundle-version="3.7.0",
- org.eclipse.etrice.generator.launch;bundle-version="0.1.0"
+ org.eclipse.etrice.generator.launch;bundle-version="0.1.0",
+ org.eclipse.core.variables;bundle-version="3.2.500"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.eclipse.jdt.launching,
diff --git a/plugins/org.eclipse.etrice.generator.launch.java/src/org/eclipse/etrice/generator/launch/java/JavaGeneratorConfigTab.java b/plugins/org.eclipse.etrice.generator.launch.java/src/org/eclipse/etrice/generator/launch/java/JavaGeneratorConfigTab.java
new file mode 100644
index 000000000..9879f210e
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.launch.java/src/org/eclipse/etrice/generator/launch/java/JavaGeneratorConfigTab.java
@@ -0,0 +1,203 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.launch.java;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.variables.VariablesPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.ContainerSelectionDialog;
+
+/**
+ * @author hrentz
+ *
+ */
+public class JavaGeneratorConfigTab extends AbstractLaunchConfigurationTab {
+
+ public static final String GEN_INSTANCE_DIAGRAM = "GenInstanceDiagram";
+ public static final String GEN_MODEL_PATH = "GenModelPath";
+ public static final String SAVE_GEN_MODEL = "SaveGenModel";
+
+ private Button instanceDiagramButton;
+ private Button saveGenModel;
+ private Text genModelPath;
+ private Button browsePath;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
+ */
+ @Override
+ public String getName() {
+ return "Java Generator";
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public void createControl(Composite parent) {
+ // Create main composite
+ Composite mainComposite = new Composite(parent,SWT.NONE);
+ setControl(mainComposite);
+
+ GridLayout layout= new GridLayout();
+ layout.numColumns = 2;
+ layout.marginHeight = 10;
+ layout.marginWidth = 10;
+ mainComposite.setLayout(layout);
+
+ saveGenModel = createCheckButton(mainComposite, "save generator model");
+ saveGenModel.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1));
+ saveGenModel.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ handleSaveGenModelSelected();
+ }
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ handleSaveGenModelSelected();
+ }
+
+ });
+ genModelPath = new Text(mainComposite, SWT.SINGLE | SWT.BORDER);
+ genModelPath.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ genModelPath.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ validate();
+ setDirty(true);
+ updateLaunchConfigurationDialog();
+ }
+ });
+ browsePath = createPushButton(mainComposite, "Browse...", null);
+ //browsePath.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 1, 1));
+ browsePath.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ handlePathButtonSelected();
+ }
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ handlePathButtonSelected();
+ }
+ });
+ instanceDiagramButton = createCheckButton(mainComposite, "generate instance diagram");
+ instanceDiagramButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1));
+ }
+
+ /**
+ *
+ */
+ protected void handleSaveGenModelSelected() {
+ boolean save = saveGenModel.getSelection();
+ genModelPath.setEnabled(save);
+ browsePath.setEnabled(save);
+ validate();
+ setDirty(true);
+ updateLaunchConfigurationDialog();
+ }
+
+ /**
+ *
+ */
+ private void validate() {
+ if (saveGenModel.getSelection())
+ if (genModelPath.getText().trim().isEmpty()) {
+ setErrorMessage("generator model path must not be empty");
+ return;
+ }
+ setErrorMessage(null);
+ }
+
+ /**
+ *
+ */
+ protected void handlePathButtonSelected() {
+ ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(),
+ ResourcesPlugin.getWorkspace().getRoot(),
+ false,
+ "select a container for the generator model");
+ dialog.showClosedProjects(false);
+ dialog.open();
+ Object[] results = dialog.getResult();
+ if ((results != null) && (results.length > 0) && (results[0] instanceof IPath)) {
+ IPath path = (IPath)results[0];
+ //path = path.append("genmodel.rim");
+ String fname = path.toString();
+ fname = VariablesPlugin.getDefault().getStringVariableManager().generateVariableExpression("workspace_loc", fname);
+ genModelPath.setText(fname);
+ setErrorMessage(null);
+ setDirty(true);
+ updateLaunchConfigurationDialog();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
+ */
+ @Override
+ public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
+ */
+ @Override
+ public void initializeFrom(ILaunchConfiguration configuration) {
+ try {
+ boolean save = configuration.getAttribute(SAVE_GEN_MODEL, false);
+ saveGenModel.setSelection(save);
+ genModelPath.setEnabled(save);
+ browsePath.setEnabled(save);
+ genModelPath.setText(configuration.getAttribute(GEN_MODEL_PATH, ""));
+ instanceDiagramButton.setSelection(configuration.getAttribute(GEN_INSTANCE_DIAGRAM, false));
+ }
+ catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
+ */
+ @Override
+ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
+ configuration.setAttribute(SAVE_GEN_MODEL, saveGenModel.getSelection());
+ configuration.setAttribute(GEN_MODEL_PATH, genModelPath.getText());
+ configuration.setAttribute(GEN_INSTANCE_DIAGRAM, instanceDiagramButton.getSelection());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#canSave()
+ */
+ @Override
+ public boolean canSave() {
+ if (saveGenModel.getSelection())
+ return !genModelPath.getText().trim().isEmpty();
+
+ return true;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.launch.java/src/org/eclipse/etrice/generator/launch/java/JavaGeneratorLaunchConfigurationDelegate.java b/plugins/org.eclipse.etrice.generator.launch.java/src/org/eclipse/etrice/generator/launch/java/JavaGeneratorLaunchConfigurationDelegate.java
index 4f832075d..c7335937f 100644
--- a/plugins/org.eclipse.etrice.generator.launch.java/src/org/eclipse/etrice/generator/launch/java/JavaGeneratorLaunchConfigurationDelegate.java
+++ b/plugins/org.eclipse.etrice.generator.launch.java/src/org/eclipse/etrice/generator/launch/java/JavaGeneratorLaunchConfigurationDelegate.java
@@ -45,14 +45,19 @@ public class JavaGeneratorLaunchConfigurationDelegate extends GeneratorLaunchCon
*/
@Override
protected void addArguments(ILaunchConfiguration configuration, StringBuffer argString) throws CoreException {
+ if (configuration.getAttribute(JavaGeneratorConfigTab.SAVE_GEN_MODEL, false)) {
+ argString.append(" -saveGenModel");
+ argString.append(" file://"+configuration.getAttribute(JavaGeneratorConfigTab.GEN_MODEL_PATH, "?"));
+ }
+ if (configuration.getAttribute(JavaGeneratorConfigTab.GEN_INSTANCE_DIAGRAM, false))
+ argString.append(" -genInstDiag");
}
/* (non-Javadoc)
* @see org.eclipse.etrice.generator.launch.GeneratorLaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
- public void launch(final ILaunchConfiguration configuration, String mode,
- ILaunch launch, IProgressMonitor monitor) throws CoreException {
+ public void launch(final ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
if (RefreshTab.getRefreshScope(configuration) != null) {
DebugPlugin.getDefault().addDebugEventListener(new IDebugEventSetListener() {
public void handleDebugEvents(DebugEvent[] events) {
diff --git a/plugins/org.eclipse.etrice.generator.launch.java/src/org/eclipse/etrice/generator/launch/java/JavaGeneratorLaunchConfigurationTabGroup.java b/plugins/org.eclipse.etrice.generator.launch.java/src/org/eclipse/etrice/generator/launch/java/JavaGeneratorLaunchConfigurationTabGroup.java
index a83d63629..4becd5323 100644
--- a/plugins/org.eclipse.etrice.generator.launch.java/src/org/eclipse/etrice/generator/launch/java/JavaGeneratorLaunchConfigurationTabGroup.java
+++ b/plugins/org.eclipse.etrice.generator.launch.java/src/org/eclipse/etrice/generator/launch/java/JavaGeneratorLaunchConfigurationTabGroup.java
@@ -13,6 +13,7 @@ public class JavaGeneratorLaunchConfigurationTabGroup extends AbstractLaunchConf
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
new JavaGeneratorMainTab(),
+ new JavaGeneratorConfigTab(),
new RefreshTab(),
new EnvironmentTab(),
new CommonTab()

Back to the top