Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2011-09-15 06:30:22 -0400
committerHenrik Rentz-Reichert2011-09-15 06:30:22 -0400
commitfde485e48614d11adf60ba927654b939d6c20984 (patch)
tree64740121d812e3fba279f249032265cd6b08f94d
parentca30194a2188ca91e6edc783615259eeec795adc (diff)
downloadorg.eclipse.etrice-fde485e48614d11adf60ba927654b939d6c20984.tar.gz
org.eclipse.etrice-fde485e48614d11adf60ba927654b939d6c20984.tar.xz
org.eclipse.etrice-fde485e48614d11adf60ba927654b939d6c20984.zip
[generator, generator.java] improved main and let wizard create Java launch configuration
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/newwizard/ProjectCreator.java27
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/Logger.java5
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/Main.java85
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/newwizard/EmptyProjectWizard.java9
4 files changed, 80 insertions, 46 deletions
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/newwizard/ProjectCreator.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/newwizard/ProjectCreator.java
index c8e23280d..c5bd3e17b 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/newwizard/ProjectCreator.java
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/newwizard/ProjectCreator.java
@@ -407,6 +407,12 @@ public class ProjectCreator {
}
}
+ /**
+ * @param uri
+ * @param name
+ * @param generatorName
+ * @deprecated new Xtend2 based generator uses Java launch
+ */
public static void createWorkflow(URI uri, String name, String generatorName) {
try {
PrintStream workflow = new PrintStream(
@@ -515,27 +521,22 @@ public class ProjectCreator {
false,
"UTF-8");
launch.println("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
- launch.println("<launchConfiguration type=\"org.eclipse.emf.mwe2.launch.Mwe2LaunchConfigurationType\">");
- launch.println("<stringAttribute key=\"org.eclipse.debug.core.ATTR_REFRESH_SCOPE\" value=\"${workspace}\"/>");
+ launch.println("<launchConfiguration type=\"org.eclipse.jdt.launching.localJavaApplication\">");
launch.println("<listAttribute key=\"org.eclipse.debug.core.MAPPED_RESOURCE_PATHS\">");
- launch.println("<listEntry value=\"/"+baseName+"\"/>");
+ launch.println("<listEntry value=\"/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/Main.java\"/>");
launch.println("</listAttribute>");
launch.println("<listAttribute key=\"org.eclipse.debug.core.MAPPED_RESOURCE_TYPES\">");
- launch.println("<listEntry value=\"4\"/>");
+ launch.println("<listEntry value=\"1\"/>");
launch.println("</listAttribute>");
launch.println("<listAttribute key=\"org.eclipse.debug.ui.favoriteGroups\">");
launch.println("<listEntry value=\"org.eclipse.debug.ui.launchGroup.run\"/>");
launch.println("</listAttribute>");
- launch.println("<listAttribute key=\"org.eclipse.jdt.launching.CLASSPATH\">");
- launch.println("<listEntry value=\"&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6&quot; javaProject=&quot;"+baseName+"&quot; path=&quot;1&quot; type=&quot;4&quot;/&gt;&#13;&#10;\"/>");
- launch.println("<listEntry value=\"&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry id=&quot;org.eclipse.jdt.launching.classpathentry.defaultClasspath&quot;&gt;&#13;&#10;&lt;memento exportedEntriesOnly=&quot;false&quot; project=&quot;"+baseName+"&quot;/&gt;&#13;&#10;&lt;/runtimeClasspathEntry&gt;&#13;&#10;\"/>");
- launch.println("<listEntry value=\"&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/org.eclipse.etrice.modellib/models&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;\"/>");
- launch.println("</listAttribute>");
- launch.println("<booleanAttribute key=\"org.eclipse.jdt.launching.DEFAULT_CLASSPATH\" value=\"false\"/>");
- launch.println("<stringAttribute key=\"org.eclipse.jdt.launching.MAIN_TYPE\" value=\"org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher\"/>");
- launch.println("<stringAttribute key=\"org.eclipse.jdt.launching.PROGRAM_ARGUMENTS\" value=\"src/workflow/"+baseName+".mwe2\"/>");
- launch.println("<stringAttribute key=\"org.eclipse.jdt.launching.PROJECT_ATTR\" value=\""+baseName+"\"/>");
+ launch.println("<stringAttribute key=\"org.eclipse.jdt.launching.MAIN_TYPE\" value=\"org.eclipse.etrice.generator.java.Main\"/>");
+ launch.println("<stringAttribute key=\"org.eclipse.jdt.launching.PROGRAM_ARGUMENTS\" value=\"${workspace_loc:"+baseName+"}\\model\\"+baseName+".room"
+ +"&#13;&#10;${workspace_loc:org.eclipse.etrice.modellib}\\models\\TimingService.room\"/>");
+ launch.println("<stringAttribute key=\"org.eclipse.jdt.launching.PROJECT_ATTR\" value=\"org.eclipse.etrice.generator.java\"/>");
launch.println("<stringAttribute key=\"org.eclipse.jdt.launching.VM_ARGUMENTS\" value=\"-ea\"/>");
+ launch.println("<stringAttribute key=\"org.eclipse.jdt.launching.WORKING_DIRECTORY\" value=\"${workspace_loc:org.eclipse.etrice.tutorials}\"/>");
launch.println("</launchConfiguration>");
launch.close();
} catch (UnsupportedEncodingException e) {
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/Logger.java b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/Logger.java
index 73794fc70..37a4ab4ad 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/Logger.java
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/Logger.java
@@ -26,7 +26,10 @@ public class Logger implements ILogger {
}
public void logError(String text, EObject obj) {
- System.out.println("Error: " + text + " " + obj.toString());
+ if (obj == null)
+ System.out.println("Error: " + text);
+ else
+ System.out.println("Error: " + text + " " + obj.toString());
}
}
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 a403cfe31..90c595af9 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
@@ -12,7 +12,9 @@
package org.eclipse.etrice.generator.java;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.eclipse.emf.common.util.URI;
@@ -27,6 +29,10 @@ import org.eclipse.etrice.generator.etricegen.IDiagnostician;
import org.eclipse.etrice.generator.etricegen.Root;
import org.eclipse.xtext.generator.IGenerator;
import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
+import org.eclipse.xtext.util.CancelIndicator;
+import org.eclipse.xtext.validation.CheckMode;
+import org.eclipse.xtext.validation.IResourceValidator;
+import org.eclipse.xtext.validation.Issue;
import com.google.inject.Inject;
import com.google.inject.Injector;
@@ -36,28 +42,52 @@ public class Main {
public static void main(String[] args) {
if (args.length == 0) {
- System.err.println("Aborting: no path to EMF resource provided!");
+ System.err.println(Main.class.getName()+" - aborting: no arguments!");
+ printUsage();
return;
}
- // building uri list
+ // parsing arguments
+ String genModelPath = null;
List<String> uriList = new ArrayList<String>();
- for (String arg : args) {
- if (arg.indexOf("file:") == 0) {
- uriList.add(arg.replace('\\', '/'));
+ for (int i=0; i<args.length; ++i) {
+ if (args[i].equals("-saveGenModel")) {
+ if (++i<args.length) {
+ genModelPath = convertToURI(args[i]);
+ }
}
else {
- uriList.add("file://"+arg.replace('\\', '/'));
+ uriList.add(convertToURI(args[i]));
}
}
// setting up required models
- org.eclipse.etrice.core.RoomStandaloneSetup.doSetup();
+ Injector roomInjector = new org.eclipse.etrice.core.RoomStandaloneSetup().createInjectorAndDoEMFRegistration();
+ IResourceValidator validator = roomInjector.getInstance(IResourceValidator.class);
org.eclipse.etrice.generator.SetupGenerator.doSetup();
Injector injector = new StandaloneSetup().createInjectorAndDoEMFRegistration();
Main main = injector.getInstance(Main.class);
- main.runGenerator(uriList);
+ main.runGenerator(uriList, genModelPath, validator);
+ }
+
+ private static String convertToURI(String uri) {
+ if (uri.startsWith("file:")) {
+ return uri.replace('\\', '/');
+ }
+ else {
+ 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
@@ -69,25 +99,19 @@ public class Main {
@Inject
private IDiagnostician diagnostician;
- //@Inject
- //private IResourceValidator validator;
-
@Inject
private IGenerator generator;
@Inject
private JavaIoFileSystemAccess fileAccess;
- protected void runGenerator(List<String> uriList) {
- logger.logInfo("Starting code generation");
-
- // creating ResourceSet for all room models
+ protected void runGenerator(List<String> uriList, String genModelPath, IResourceValidator validator) {
ResourceSet rs = resourceSetProvider.get();
- // building list of all resources for room models
+ logger.logInfo("-- reading models");
List<Resource> resourceList = new ArrayList<Resource>();
for (String uriString : uriList) {
- logger.logInfo("Parsing " + uriString);
+ logger.logInfo("Loading " + uriString);
resourceList.add(rs.getResource(URI.createURI(uriString), true));
}
@@ -95,17 +119,20 @@ public class Main {
EcoreUtil.resolveAll(rs);
// validate all resources
- /*for (Resource resource : resourceList) {
+ logger.logInfo("-- validating models");
+ for (Resource resource : resourceList) {
List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
if (!list.isEmpty()) {
for (Issue issue : list) {
- System.err.println(issue);
+ logger.logError(issue.toString(), null);
}
return;
}
- }*/
+ }
fileAccess.setOutputPath("src-gen/");
+ logger.logInfo("-- starting code generation");
+
// check resources for right number and types of room models and build a list of them
List<RoomModel> rml = new ArrayList<RoomModel>();
for (Resource resource : resourceList) {
@@ -114,15 +141,27 @@ public class Main {
rml.add((RoomModel)contents.get(0));
}
}
- if (rml.size()>0){
+ if (rml.isEmpty()) {
+ logger.logError("no RoomModels found", null);
+ }
+ else {
// create generator model
GeneratorModelBuilder gmb = new GeneratorModelBuilder(logger, diagnostician);
Root gmRoot = gmb.createGeneratorModel(rml);
- Resource genResource = rs.createResource(URI.createFileURI("./src-gen-out/tmp.rim"));
+ URI genModelURI = genModelPath!=null? URI.createURI(genModelPath) : URI.createFileURI("tmp.rim");
+ Resource genResource = rs.createResource(genModelURI);
genResource.getContents().add(gmRoot);
+ if (genModelPath!=null) {
+ try {
+ logger.logInfo("-- saving genmodel to "+genModelPath);
+ genResource.save(Collections.EMPTY_MAP);
+ } catch (IOException e) {
+ logger.logError(e.getMessage(), null);
+ }
+ }
generator.doGenerate(genResource, fileAccess);
}
- logger.logInfo("Code generation finished.");
+ logger.logInfo("-- fineshed code generation");
}
}
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/newwizard/EmptyProjectWizard.java b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/newwizard/EmptyProjectWizard.java
index 8733cd2c2..c8328e208 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/newwizard/EmptyProjectWizard.java
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/newwizard/EmptyProjectWizard.java
@@ -125,15 +125,6 @@ public class EmptyProjectWizard extends Wizard implements INewWizard {
baseName,
getRequiredBundles());
- ProjectCreator.findOrCreateContainer(new Path("/"
- + baseName + "/src/workflow"),
- true, projectLocation, progressMonitor);
- ProjectCreator.createWorkflow(URI.createPlatformResourceURI("/"
- + baseName
- + "/src/workflow/"+baseName+".mwe2", true),
- baseName,
- "RoomGenerator");
-
ProjectCreator.createBuildProperties(URI.createPlatformResourceURI("/"
+baseName+"/build.properties", true),
baseName);

Back to the top