Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2013-09-20 06:31:24 +0000
committerHenrik Rentz-Reichert2013-09-20 07:06:29 +0000
commite35469696de3e226a3190bc622e9be2b5dc60902 (patch)
tree8154aca33ac636ac3eef2050083e96e737e7b01b /plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse
parenta277b5eb27b06037c4f775a897c469e1f843f673 (diff)
downloadorg.eclipse.etrice-e35469696de3e226a3190bc622e9be2b5dc60902.tar.gz
org.eclipse.etrice-e35469696de3e226a3190bc622e9be2b5dc60902.tar.xz
org.eclipse.etrice-e35469696de3e226a3190bc622e9be2b5dc60902.zip
[generator, generator.*] bug 406009: pull up standard options to base class
https://bugs.eclipse.org/406009 Change-Id: If3e3ce63e9fa192f575ad79c257bad9a5acf9bcc
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse')
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/Main.java143
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend4
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend4
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/GeneratorSettings.java (renamed from plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/GeneratorOptions.java)14
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend4
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/setup/GeneratorModule.java4
6 files changed, 82 insertions, 91 deletions
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/Main.java b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/Main.java
index a6712dc89..c6ecdd549 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/Main.java
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/Main.java
@@ -12,8 +12,7 @@
package org.eclipse.etrice.generator.cpp;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Iterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.etmap.eTMap.MappingModel;
@@ -23,6 +22,7 @@ import org.eclipse.etrice.core.genmodel.etricegen.Root;
import org.eclipse.etrice.generator.base.AbstractGenerator;
import org.eclipse.etrice.generator.base.IDataConfiguration;
import org.eclipse.etrice.generator.base.IResourceURIAcceptor;
+import org.eclipse.etrice.generator.cpp.gen.GeneratorSettings;
import org.eclipse.etrice.generator.cpp.gen.Validator;
import org.eclipse.etrice.generator.cpp.setup.GeneratorModule;
import org.eclipse.xtext.generator.IGenerator;
@@ -31,26 +31,16 @@ import org.eclipse.xtext.scoping.impl.ImportUriResolver;
import com.google.inject.Inject;
public class Main extends AbstractGenerator {
-
- public static final String OPTION_LIB = "-lib";
- public static final String OPTION_NOEXIT = "-noexit";
- public static final String OPTION_DOCUMENTATION = "-genDocu";
- public static final String OPTION_SAVE_GEN_MODEL = "-saveGenModel";
- public static final String OPTION_DEBUG = "-debug";
+
public static final String OPTION_ETUNIT = "-etunit";
/**
- * print usage message to stderr
+ * print usage message to output/console
*/
- private static void printUsage() {
- output.println(Main.class.getName()+" [-saveGenModel <genmodel path>] [-genInstDiag] [-lib] <list of model file paths>");
- output.println(" <list of model file paths> # model file paths may be specified as");
- output.println(" # e.g. C:\\path\\to\\model\\mymodel.room");
- output.println(" -saveGenModel <genmodel path> # if specified the generator model will be saved to this location");
- output.println(" -genDocu # if specified documentation is created");
- output.println(" -lib # if specified all classes are generated and no instances");
- output.println(" -noexit # if specified the JVM is not exited");
- output.println(" -debug # if specified create debug output");
+ protected void printUsage() {
+ output.println(this.getClass().getName()+getCommonOptions()
+ +" <list of model file paths>");
+ output.println(getCommonOptionDescriptions());
}
public static void main(String[] args) {
@@ -73,95 +63,90 @@ public class Main extends AbstractGenerator {
@Inject
protected ImportUriResolver uriResolver;
-
- public int runGenerator(String[] args) {
- if (args.length == 0) {
- logger.logError(Main.class.getName()+" - aborting: no arguments!", null);
- printUsage();
- return GENERATOR_ERROR;
- }
- // parsing arguments
- String genModelPath = null;
- List<String> uriList = new ArrayList<String>();
- boolean genDocumentation = false;
- boolean asLibrary = false;
- boolean debug = false;
- for (int i=0; i<args.length; ++i) {
- if (args[i].equals(OPTION_SAVE_GEN_MODEL)) {
- if (++i<args.length) {
- genModelPath = args[i]+"/genmodel.egm";
- }
- }
- else if (args[i].equals(OPTION_DOCUMENTATION)) {
- genDocumentation = true;
- }
- else if (args[i].equals(OPTION_LIB)) {
- asLibrary = true;
- }
- else if (args[i].equals(OPTION_NOEXIT)) {
- setTerminateOnError(false);
- }
- else if (args[i].equals(OPTION_DEBUG)) {
- debug = true;
- }
- else if (args[i].equals(OPTION_ETUNIT)) {
- GeneratorOptions.setUseEtUnit(true);
- }
- else {
- uriList.add(args[i]);
- }
+ /**
+ * @return the unique {@link GlobalSettings}
+ */
+ public static GeneratorSettings getSettings() {
+ return (GeneratorSettings) getInstance().getGeneratorSettings();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.generator.base.AbstractGenerator#parseOption(java.lang.String, java.util.Iterator)
+ */
+ @Override
+ protected boolean parseOption(String arg, Iterator<String> it) {
+ if (arg.equals(OPTION_ETUNIT)) {
+ getSettings().setUseEtUnit(true);
+ return true;
}
-
+
+ return super.parseOption(arg, it);
+ }
+
+ protected int runGenerator() {
setupRoomModel();
dataConfig.doSetup();
- if (!runGenerator(uriList, genModelPath, genDocumentation, asLibrary, debug))
+ if (!loadModels(getSettings().getInputModelURIs())) {
+ logger.logInfo("loading of models failed");
+ logger.logError("-- terminating", null);
return GENERATOR_ERROR;
-
- return GENERATOR_OK;
- }
-
- protected boolean runGenerator(List<String> uriList, String genModelPath, boolean genDocumentation, boolean asLibrary, boolean debug) {
- if (!loadModels(uriList))
- return false;
+ }
- if (!validateModels())
- return false;
-
- if(!dataConfig.setResources(getResourceSet(), logger))
- return false;
+ if (!validateModels()) {
+ logger.logInfo("validation failed");
+ logger.logError("-- terminating", null);
+ return GENERATOR_ERROR;
+ }
- Root genModel = createGeneratorModel(asLibrary, genModelPath);
- if (genModel==null)
- return false;
+ if (!dataConfig.setResources(getResourceSet(), logger)) {
+ logger.logInfo("configuration errors");
+ logger.logError("-- terminating", null);
+ return GENERATOR_ERROR;
+ }
+
+ Root genModel = createGeneratorModel(getSettings().isGenerateAsLibrary(), getSettings().getGeneratorModelPath());
+ if (diagnostician.isFailed() || genModel==null) {
+ logger.logInfo("errors during build of generator model");
+ logger.logError("-- terminating", null);
+ return GENERATOR_ERROR;
+ }
- if (!validator.validate(genModel))
- return false;
+ if (!validator.validate(genModel)) {
+ logger.logInfo("validation failed during build of generator model");
+ logger.logError("-- terminating", null);
+ return GENERATOR_ERROR;
+ }
ETMapUtil.processModels(genModel, getResourceSet(), diagnostician);
- if (debug) {
+ if (getSettings().isDebugMode()) {
logger.logInfo("-- begin dump of mappings");
logger.logInfo(ETMapUtil.dumpMappings());
logger.logInfo("-- end dump of mappings");
}
+ if (diagnostician.isFailed() || genModel==null) {
+ logger.logInfo("errors in mapping");
+ logger.logError("-- terminating", null);
+ return GENERATOR_ERROR;
+ }
logger.logInfo("-- starting code generation");
fileAccess.setOutputPath("src-gen/");
mainGenerator.doGenerate(genModel.eResource(), fileAccess);
- if (genDocumentation) {
+ if (getSettings().isGenerateDocumentation()) {
mainDocGenerator.doGenerate(genModel);
}
if (diagnostician.isFailed()) {
- logger.logInfo("validation failed during build of generator model");
+ logger.logInfo("errors during code generation");
logger.logError("-- terminating", null);
- return false;
+ return GENERATOR_ERROR;
}
logger.logInfo("-- finished code generation");
- return true;
+ return GENERATOR_OK;
}
/* (non-Javadoc)
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend
index d4f72ae20..76744b06e 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend
@@ -24,9 +24,9 @@ import org.eclipse.etrice.generator.generic.GenericActorClassGenerator
import org.eclipse.etrice.generator.generic.ProcedureHelpers
import org.eclipse.etrice.generator.generic.RoomExtensions
import org.eclipse.xtext.generator.JavaIoFileSystemAccess
-import org.eclipse.etrice.generator.cpp.GeneratorOptions
import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
import org.eclipse.etrice.core.room.ActorCommunicationType
+import org.eclipse.etrice.generator.cpp.Main
/**
* @author Peter Karlitschek
@@ -80,7 +80,7 @@ class ActorClassGen extends GenericActorClassGenerator {
#include "common/messaging/Address.h"
#include "common/messaging/IMessageReceiver.h"
#include "common/debugging/DebuggingService.h"
- «IF GeneratorOptions::useEtUnit»
+ «IF Main::settings.isUseEtUnit»
extern "C" {
#include "etUnit.h"
}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend
index 001d92f39..1ff4c13ae 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend
@@ -25,9 +25,9 @@ import org.eclipse.etrice.generator.generic.RoomExtensions
import org.eclipse.etrice.generator.generic.TypeHelpers
import org.eclipse.etrice.generator.cpp.gen.Initialization
import org.eclipse.xtext.generator.JavaIoFileSystemAccess
-import org.eclipse.etrice.generator.cpp.GeneratorOptions
import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
+import org.eclipse.etrice.generator.cpp.Main
/**
* @author Peter Karlitschek
@@ -129,7 +129,7 @@ class DataClassGen {
*/
#include "«dc.getCppHeaderFileName»"
- «IF GeneratorOptions::useEtUnit»
+ «IF Main::settings.isUseEtUnit»
extern "C" {
#include "etUnit.h"
}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/GeneratorOptions.java b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/GeneratorSettings.java
index cd35099fd..823b5513f 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/GeneratorOptions.java
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/GeneratorSettings.java
@@ -10,21 +10,23 @@
*
*******************************************************************************/
-package org.eclipse.etrice.generator.cpp;
+package org.eclipse.etrice.generator.cpp.gen;
+
+import org.eclipse.etrice.generator.base.GlobalGeneratorSettings;
/**
* @author Henrik Rentz-Reichert
*
*/
-public class GeneratorOptions {
+public class GeneratorSettings extends GlobalGeneratorSettings {
- static private boolean useEtUnit = false;
+ private boolean useEtUnit = false;
- public static boolean isUseEtUnit() {
+ public boolean isUseEtUnit() {
return useEtUnit;
}
- public static void setUseEtUnit(boolean useEtUnit) {
- GeneratorOptions.useEtUnit = useEtUnit;
+ public void setUseEtUnit(boolean useEtUnit) {
+ this.useEtUnit = useEtUnit;
}
}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend
index 5c2923d91..2f2f250de 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend
@@ -32,8 +32,8 @@ import org.eclipse.etrice.generator.generic.RoomExtensions
import org.eclipse.etrice.generator.generic.TypeHelpers
import org.eclipse.xtext.generator.JavaIoFileSystemAccess
import org.eclipse.etrice.core.room.PortClass
-import org.eclipse.etrice.generator.cpp.GeneratorOptions
import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
+import org.eclipse.etrice.generator.cpp.Main
/**
* @author Peter Karlitschek
@@ -189,7 +189,7 @@ class ProtocolClassGen extends GenericProtocolClassGenerator {
#include "«pc.getCppHeaderFileName»"
#include "common/debugging/DebuggingService.h"
#include <iostream>
- «IF GeneratorOptions::useEtUnit»
+ «IF Main::settings.isUseEtUnit»
extern "C" {
#include "etUnit.h"
}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/setup/GeneratorModule.java b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/setup/GeneratorModule.java
index bffd9ba17..5325a4394 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/setup/GeneratorModule.java
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/setup/GeneratorModule.java
@@ -15,11 +15,13 @@ package org.eclipse.etrice.generator.cpp.setup;
import org.eclipse.etrice.core.scoping.PlatformRelativeUriResolver;
import org.eclipse.etrice.generator.base.AbstractGenerator;
import org.eclipse.etrice.generator.base.AbstractGeneratorBaseModule;
+import org.eclipse.etrice.generator.base.GlobalGeneratorSettings;
import org.eclipse.etrice.generator.base.IDataConfiguration;
import org.eclipse.etrice.generator.base.ITranslationProvider;
import org.eclipse.etrice.generator.cpp.Main;
import org.eclipse.etrice.generator.cpp.gen.CppExtensions;
import org.eclipse.etrice.generator.cpp.gen.CppTranslationProvider;
+import org.eclipse.etrice.generator.cpp.gen.GeneratorSettings;
import org.eclipse.etrice.generator.cpp.gen.MainGen;
import org.eclipse.etrice.generator.generic.ILanguageExtension;
import org.eclipse.xtext.generator.IGenerator;
@@ -37,6 +39,8 @@ public class GeneratorModule extends AbstractGeneratorBaseModule {
binder.bind(IGenerator.class).to(MainGen.class);
binder.bind(ImportUriResolver.class).to(PlatformRelativeUriResolver.class);
+
+ binder.bind(GlobalGeneratorSettings.class).to(GeneratorSettings.class);
}
public Class<? extends ILanguageExtension> bindILanguageExtension() {

Back to the top