Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2011-09-22 03:38:04 -0400
committerHenrik Rentz-Reichert2011-09-22 03:38:04 -0400
commit5913885d5381aa202862b5f6de669e3ae35fa2ed (patch)
treea4ebf41e62841e03c08fe93b4c5e5872dfe15cb8 /plugins/org.eclipse.etrice.generator.launch
parent620e431a025ad21876c0164da7684e2df3ca819b (diff)
downloadorg.eclipse.etrice-5913885d5381aa202862b5f6de669e3ae35fa2ed.tar.gz
org.eclipse.etrice-5913885d5381aa202862b5f6de669e3ae35fa2ed.tar.xz
org.eclipse.etrice-5913885d5381aa202862b5f6de669e3ae35fa2ed.zip
[generator, generator.java, generator.launch] some re-factoring
- moved generic stuff to generator - new wizard simplified (simple Java project, no plug-in)
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.launch')
-rw-r--r--plugins/org.eclipse.etrice.generator.launch/META-INF/MANIFEST.MF4
-rw-r--r--plugins/org.eclipse.etrice.generator.launch/src/org/eclipse/etrice/generator/launch/GeneratorLaunchConfigurationDelegate.java173
-rw-r--r--plugins/org.eclipse.etrice.generator.launch/src/org/eclipse/etrice/generator/launch/GeneratorMainTab.java113
3 files changed, 106 insertions, 184 deletions
diff --git a/plugins/org.eclipse.etrice.generator.launch/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.generator.launch/META-INF/MANIFEST.MF
index e223ff36b..7dbbdbb7c 100644
--- a/plugins/org.eclipse.etrice.generator.launch/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.generator.launch/META-INF/MANIFEST.MF
@@ -4,8 +4,10 @@ Bundle-Name: eTrice Generator Launch Base Classes
Bundle-SymbolicName: org.eclipse.etrice.generator.launch;singleton:=true
Bundle-Version: 0.1.0.qualifier
Bundle-Activator: org.eclipse.etrice.generator.launch.Activator
-Require-Bundle: org.eclipse.ui,
+Require-Bundle: org.eclipse.etrice.generator;bundle-version="0.1.0",
org.eclipse.core.runtime,
+ org.eclipse.ui,
+ org.eclipse.ui.console;bundle-version="3.5.100",
org.eclipse.debug.ui,
org.eclipse.jdt.ui;bundle-version="3.7.0",
org.eclipse.jdt.core;bundle-version="3.7.0",
diff --git a/plugins/org.eclipse.etrice.generator.launch/src/org/eclipse/etrice/generator/launch/GeneratorLaunchConfigurationDelegate.java b/plugins/org.eclipse.etrice.generator.launch/src/org/eclipse/etrice/generator/launch/GeneratorLaunchConfigurationDelegate.java
index fb3a15020..d9334f793 100644
--- a/plugins/org.eclipse.etrice.generator.launch/src/org/eclipse/etrice/generator/launch/GeneratorLaunchConfigurationDelegate.java
+++ b/plugins/org.eclipse.etrice.generator.launch/src/org/eclipse/etrice/generator/launch/GeneratorLaunchConfigurationDelegate.java
@@ -12,21 +12,34 @@
package org.eclipse.etrice.generator.launch;
-import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.ui.RefreshTab;
+import org.eclipse.etrice.generator.base.ILineOutput;
import org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate;
-import org.eclipse.jdt.launching.ExecutionArguments;
-import org.eclipse.jdt.launching.IVMRunner;
-import org.eclipse.jdt.launching.VMRunnerConfiguration;
-import org.eclipse.core.variables.VariablesPlugin;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.console.ConsolePlugin;
+import org.eclipse.ui.console.IConsole;
+import org.eclipse.ui.console.IConsoleConstants;
+import org.eclipse.ui.console.IConsoleManager;
+import org.eclipse.ui.console.IConsoleView;
+import org.eclipse.ui.console.MessageConsole;
+import org.eclipse.ui.console.MessageConsoleStream;
/**
* @author Henrik Rentz-Reichert (initial contribution)
@@ -34,6 +47,20 @@ import org.eclipse.core.variables.VariablesPlugin;
*/
public abstract class GeneratorLaunchConfigurationDelegate extends AbstractJavaLaunchConfigurationDelegate{
+ protected static class ConsoleLineOutput implements ILineOutput {
+
+ private MessageConsoleStream stream;
+
+ public ConsoleLineOutput(MessageConsoleStream stream) {
+ this.stream = stream;
+ }
+
+ @Override
+ public void println(String txt) {
+ stream.println(txt);
+ }
+ }
+
@Override
public void launch(ILaunchConfiguration configuration, String mode,
ILaunch launch, IProgressMonitor monitor) throws CoreException {
@@ -53,72 +80,71 @@ public abstract class GeneratorLaunchConfigurationDelegate extends AbstractJavaL
// constructing program arguments
addModels(configuration, argString);
addArguments(configuration, argString);
-
- monitor.subTask("launching generator");
-
- String mainTypeName = getMainTypeName();
- IVMRunner runner = getVMRunner(configuration, mode);
-
- File workingDir = verifyWorkingDirectory(configuration);
- String workingDirName = null;
- if (workingDir != null) {
- workingDirName = workingDir.getAbsolutePath();
- }
-
- // Environment variables
- String[] envp= getEnvironment(configuration);
-
- // Program & VM arguments
- String pgmArgs = argString.toString();
- pgmArgs = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(pgmArgs);
- String vmArgs = getVMArguments(configuration);
- ExecutionArguments execArgs = new ExecutionArguments(vmArgs, pgmArgs);
-
- // VM-specific attributes
- @SuppressWarnings("rawtypes")
- Map vmAttributesMap = getVMSpecificAttributesMap(configuration);
-
- // Classpath
- String[] classpath = getClasspath(configuration);
-
- // Create VM config
- VMRunnerConfiguration runConfig = new VMRunnerConfiguration(mainTypeName, classpath);
- runConfig.setProgramArguments(execArgs.getProgramArgumentsArray());
- runConfig.setEnvironment(envp);
- runConfig.setVMArguments(execArgs.getVMArgumentsArray());
- runConfig.setWorkingDirectory(workingDirName);
- runConfig.setVMSpecificAttributesMap(vmAttributesMap);
-
- // Bootpath
- runConfig.setBootClassPath(getBootpath(configuration));
-
- // check for cancellation
- if (monitor.isCanceled()) {
- return;
- }
-
- // stop in main
- prepareStopInMain(configuration);
-
- // done the verification phase
- monitor.worked(1);
-
- monitor.subTask("locating sources");
- // set the default source locator if required
- setDefaultSourceLocator(launch, configuration);
- monitor.worked(1);
-
- // Launch the configuration - 1 unit of work
- runner.run(runConfig, launch, monitor);
-
+
+ String pgmArgs = argString.toString().trim();
+ pgmArgs = VariablesPlugin.getDefault().getStringVariableManager()
+ .performStringSubstitution(pgmArgs);
+
+ String[] args = pgmArgs.split("[ \t]");
+
+ final MessageConsole myConsole = findConsole("EM Generator Output");
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ IWorkbench wb = PlatformUI.getWorkbench();
+ IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
+ IWorkbenchPage page = win.getActivePage();
+ String id = IConsoleConstants.ID_CONSOLE_VIEW;
+ IConsoleView view = (IConsoleView) page.showView(id);
+ view.display(myConsole);
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ MessageConsoleStream out = myConsole.newMessageStream();
+ out.getConsole().clearConsole();
+ ConsoleLineOutput output = new ConsoleLineOutput(out);
+ runGenerator(args, output);
+
// check for cancellation
if (monitor.isCanceled()) {
return;
- }
- }
- finally {
+ }
+ } finally {
monitor.done();
}
+
+ launchRefreshJob(configuration);
+ }
+
+ private void launchRefreshJob(final ILaunchConfiguration configuration) {
+ Job job = new Job("refresh resources after code generation") {
+ public IStatus run(IProgressMonitor monitor) {
+ try {
+ RefreshTab.refreshResources(configuration, monitor);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ return e.getStatus();
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.schedule();
+ }
+
+ private MessageConsole findConsole(String name) {
+ ConsolePlugin plugin = ConsolePlugin.getDefault();
+ IConsoleManager conMan = plugin.getConsoleManager();
+ IConsole[] existing = conMan.getConsoles();
+ for (int i = 0; i < existing.length; i++)
+ if (name.equals(existing[i].getName()))
+ return (MessageConsole) existing[i];
+ // no console found, so create a new one
+ MessageConsole myConsole = new MessageConsole(name, null);
+ conMan.addConsoles(new IConsole[] { myConsole });
+ return myConsole;
}
protected void addModels(ILaunchConfiguration configuration, StringBuffer argString) throws CoreException {
@@ -128,11 +154,6 @@ public abstract class GeneratorLaunchConfigurationDelegate extends AbstractJavaL
argString.append(" file://"+model);
}
}
-
- /**
- * @return the main type of the generator as fully qualified name
- */
- protected abstract String getMainTypeName();
/**
* assemble the command line by adding further parameters
@@ -142,4 +163,12 @@ public abstract class GeneratorLaunchConfigurationDelegate extends AbstractJavaL
* @throws CoreException
*/
protected abstract void addArguments(ILaunchConfiguration configuration, StringBuffer argString) throws CoreException;
+
+ /**
+ * call the generator main method
+ *
+ * @param args the command line arguments
+ * @param out line wise output to console
+ */
+ protected abstract void runGenerator(String[] args, ILineOutput out);
}
diff --git a/plugins/org.eclipse.etrice.generator.launch/src/org/eclipse/etrice/generator/launch/GeneratorMainTab.java b/plugins/org.eclipse.etrice.generator.launch/src/org/eclipse/etrice/generator/launch/GeneratorMainTab.java
index fa139d932..09b1455a3 100644
--- a/plugins/org.eclipse.etrice.generator.launch/src/org/eclipse/etrice/generator/launch/GeneratorMainTab.java
+++ b/plugins/org.eclipse.etrice.generator.launch/src/org/eclipse/etrice/generator/launch/GeneratorMainTab.java
@@ -15,27 +15,15 @@ package org.eclipse.etrice.generator.launch;
import java.util.ArrayList;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
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.jdt.core.IJavaModel;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
-import org.eclipse.jdt.ui.JavaElementLabelProvider;
import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.window.Window;
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;
@@ -46,7 +34,6 @@ import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.dialogs.ElementListSelectionDialog;
import org.eclipse.ui.dialogs.ResourceListSelectionDialog;
import org.eclipse.ui.dialogs.ResourceSelectionDialog;
@@ -58,7 +45,6 @@ public abstract class GeneratorMainTab extends AbstractLaunchConfigurationTab {
private List modelList;
private Text projectText;
- private Button browseProject;
@Override
public void createControl(Composite parent) {
@@ -69,12 +55,10 @@ public abstract class GeneratorMainTab extends AbstractLaunchConfigurationTab {
GridLayout layout= new GridLayout();
layout.numColumns = 2;
- layout.marginHeight = 10;
+ layout.marginHeight = 0;
layout.marginWidth = 10;
mainComposite.setLayout(layout);
- createProjectEditor(mainComposite);
-
createModelsEditor(mainComposite);
Dialog.applyDialogFont(mainComposite);
@@ -118,7 +102,7 @@ public abstract class GeneratorMainTab extends AbstractLaunchConfigurationTab {
*/
private void createModelList(Composite parent) {
Label label = new Label(parent, SWT.NONE);
- label.setText("ROOM Models:");
+ label.setText("Models to generate:");
GridData gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false, 2, 1);
gd.verticalIndent = 20;
label.setLayoutData(gd);
@@ -148,97 +132,6 @@ public abstract class GeneratorMainTab extends AbstractLaunchConfigurationTab {
addBtn.addListener(SWT.Selection,listener);
return gd;
}
-
- protected void createProjectEditor(Composite parent) {
- Label label = new Label(parent, SWT.NONE);
- label.setText("Project:");
- GridData gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false, 2, 1);
- label.setLayoutData(gd);
-
- projectText = createSingleText(parent, 1);
- projectText.addModifyListener(new ModifyListener() {
- @Override
- public void modifyText(ModifyEvent e) {
- updateLaunchConfigurationDialog();
- }
- });
- browseProject = createPushButton(parent, "Browse...", null);
- browseProject.addSelectionListener(new SelectionListener( ) {
- @Override
- public void widgetSelected(SelectionEvent e) {
- handleProjectButtonSelected();
- }
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- handleProjectButtonSelected();
- }
- });
- }
-
- private void updateProjectFromConfig(ILaunchConfiguration config) {
- String projectName = "";
- try {
- projectName = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");
- }
- catch (CoreException ce) {
- setErrorMessage(ce.getStatus().getMessage());
- }
- projectText.setText(projectName);
- }
-
- private void handleProjectButtonSelected() {
- IJavaProject project = chooseJavaProject();
- if (project == null) {
- return;
- }
- String projectName = project.getElementName();
- projectText.setText(projectName);
- updateLaunchConfigurationDialog();
- }
-
- private IJavaProject chooseJavaProject() {
- ILabelProvider labelProvider= new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT);
- ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), labelProvider);
- dialog.setTitle("Project Selection");
- dialog.setMessage("Select a project to constrain your search");
- try {
- dialog.setElements(JavaCore.create(getWorkspaceRoot()).getJavaProjects());
- }
- catch (JavaModelException jme) {Activator.getDefault().log(jme);}
- IJavaProject javaProject= getJavaProject();
- if (javaProject != null) {
- dialog.setInitialSelections(new Object[] { javaProject });
- }
- if (dialog.open() == Window.OK) {
- return (IJavaProject) dialog.getFirstResult();
- }
- return null;
- }
-
- private IJavaModel getJavaModel() {
- return JavaCore.create(getWorkspaceRoot());
- }
-
- private IJavaProject getJavaProject() {
- String projectName = projectText.getText().trim();
- if (projectName.length() < 1) {
- return null;
- }
- return getJavaModel().getJavaProject(projectName);
- }
-
- private IWorkspaceRoot getWorkspaceRoot() {
- return ResourcesPlugin.getWorkspace().getRoot();
- }
-
- private static Text createSingleText(Composite parent, int hspan) {
- Text t = new Text(parent, SWT.SINGLE | SWT.BORDER);
- t.setFont(parent.getFont());
- GridData gd = new GridData(GridData.FILL_HORIZONTAL);
- gd.horizontalSpan = hspan;
- t.setLayoutData(gd);
- return t;
- }
@Override
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
@@ -248,8 +141,6 @@ public abstract class GeneratorMainTab extends AbstractLaunchConfigurationTab {
@Override
public void initializeFrom(ILaunchConfiguration configuration) {
try {
- updateProjectFromConfig(configuration);
-
modelList.removeAll();
ArrayList<String> param = new ArrayList<String>();
param = (ArrayList<String>) configuration.getAttribute("ModelFiles", param);

Back to the top