Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Belle2018-08-29 05:36:53 -0400
committerJan Belle2018-08-29 06:19:46 -0400
commit0c4faa4761c9085523c8f51dac59106eb2fbda48 (patch)
tree28ee683b537956224569bfdc3b107abd8dee122f
parent3403977e874c1c6de888c66568227ccf8241ecfc (diff)
downloadorg.eclipse.etrice-0c4faa4761c9085523c8f51dac59106eb2fbda48.tar.gz
org.eclipse.etrice-0c4faa4761c9085523c8f51dac59106eb2fbda48.tar.xz
org.eclipse.etrice-0c4faa4761c9085523c8f51dac59106eb2fbda48.zip
[generator.base] Base generator application implementation
* Created common interface for generators * Moved Logger and GeneratorFileIO to common generator project * Added base implementations for resource loading and resource validation * Defined common generator options Change-Id: Ie02da027720b4588dff9ac23c4c60353266fe52b
-rw-r--r--plugins/org.eclipse.etrice.generator.base/META-INF/MANIFEST.MF9
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/GeneratorApplication.java232
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/GeneratorException.java40
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/IGenerator.java45
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/GeneratorResourceLoader.java103
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IGeneratorFileIO.java42
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IGeneratorResourceLoader.java42
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/ILineOutput.java32
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IncrementalGeneratorFileIO.java140
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/LineOutput.java51
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/ILineOutputLogger.java35
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/ILogger.java59
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/Logger.java106
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/Loglevel.java30
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/NullLogger.java59
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/setup/GeneratorBaseModule.java46
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/setup/GeneratorBaseOptions.java72
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/setup/GeneratorBaseOptionsHelper.java45
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/validation/GeneratorResourceValidator.java78
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/validation/IGeneratorResourceValidator.java42
20 files changed, 1306 insertions, 2 deletions
diff --git a/plugins/org.eclipse.etrice.generator.base/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.generator.base/META-INF/MANIFEST.MF
index f0c909e0c..18d19c1f4 100644
--- a/plugins/org.eclipse.etrice.generator.base/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.generator.base/META-INF/MANIFEST.MF
@@ -11,6 +11,11 @@ Require-Bundle: org.eclipse.emf.ecore,
org.eclipse.core.resources,
org.eclipse.core.runtime,
org.apache.commons.io
-Export-Package: org.eclipse.etrice.generator.base.args,
- org.eclipse.etrice.generator.base.cli
+Export-Package: org.eclipse.etrice.generator.base,
+ org.eclipse.etrice.generator.base.args,
+ org.eclipse.etrice.generator.base.cli,
+ org.eclipse.etrice.generator.base.io,
+ org.eclipse.etrice.generator.base.logging,
+ org.eclipse.etrice.generator.base.setup,
+ org.eclipse.etrice.generator.base.validation
Bundle-Name: Base Generator
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/GeneratorApplication.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/GeneratorApplication.java
new file mode 100644
index 000000000..e3795bd8a
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/GeneratorApplication.java
@@ -0,0 +1,232 @@
+/*******************************************************************************
+* Copyright (c) 2018 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Jan Belle (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.List;
+
+import org.eclipse.emf.common.EMFPlugin;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.etrice.generator.base.args.Arguments;
+import org.eclipse.etrice.generator.base.args.Options;
+import org.eclipse.etrice.generator.base.cli.CommandLineParseException;
+import org.eclipse.etrice.generator.base.cli.ICommandLineParser;
+import org.eclipse.etrice.generator.base.cli.IHelpFormatter;
+import org.eclipse.etrice.generator.base.io.IGeneratorFileIO;
+import org.eclipse.etrice.generator.base.io.ILineOutput;
+import org.eclipse.etrice.generator.base.io.IGeneratorResourceLoader;
+import org.eclipse.etrice.generator.base.io.IncrementalGeneratorFileIO;
+import org.eclipse.etrice.generator.base.io.LineOutput;
+import org.eclipse.etrice.generator.base.logging.ILogger;
+import org.eclipse.etrice.generator.base.logging.Logger;
+import org.eclipse.etrice.generator.base.logging.Loglevel;
+import org.eclipse.etrice.generator.base.setup.GeneratorBaseOptions;
+import org.eclipse.etrice.generator.base.validation.IGeneratorResourceValidator;
+import com.google.inject.Guice;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import com.google.inject.Provider;
+
+/**
+ * Executes a generator.
+ */
+public class GeneratorApplication {
+
+ /**
+ * Creates a new generator instance using the specified generator module.
+ *
+ * @param module the generator module
+ * @return the new generator application
+ */
+ public static GeneratorApplication create(Module module) {
+ Injector injector = Guice.createInjector(module);
+ GeneratorApplication genAppl = injector.getInstance(GeneratorApplication.class);
+ return genAppl;
+ }
+
+ /**
+ * Creates a new generator instance using the specified generator module.
+ *
+ * @param moduleName the name of the class of the generator module
+ * @return the new generator application
+ */
+ public static GeneratorApplication create(String moduleName) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
+ Module module = (Module) Class.forName(moduleName).newInstance();
+ return create(module);
+ }
+
+ private final Options options;
+ private boolean initializedEMF = EMFPlugin.IS_ECLIPSE_RUNNING;
+ private ICommandLineParser commandLineParser;
+ private IHelpFormatter helpFormatter;
+ private Provider<Logger> loggerProvider;
+ private Provider<IncrementalGeneratorFileIO> fileIOProvider;
+ private Provider<IGenerator> generatorProvider;
+ private IGeneratorResourceLoader resourceLoader;
+ private IGeneratorResourceValidator resourceValidator;
+
+ @Inject
+ public GeneratorApplication(GeneratorBaseOptions optionsModule, ICommandLineParser commandLineParser,
+ IHelpFormatter helpFormatter, Provider<Logger> loggerProvider,
+ Provider<IncrementalGeneratorFileIO> fileIOProvider, Provider<IGenerator> generatorProvider,
+ IGeneratorResourceLoader resourceLoader, IGeneratorResourceValidator resourceValidator) {
+ this.options = new Options(optionsModule);
+ this.initializedEMF = EMFPlugin.IS_ECLIPSE_RUNNING;
+ this.commandLineParser = commandLineParser;
+ this.helpFormatter = helpFormatter;
+ this.loggerProvider = loggerProvider;
+ this.fileIOProvider = fileIOProvider;
+ this.generatorProvider = generatorProvider;
+ this.resourceLoader = resourceLoader;
+ this.resourceValidator = resourceValidator;
+ }
+
+ /**
+ * Runs the generator with the specified command line arguments.
+ *
+ * @param args the command line arguments
+ */
+ public void run(String[] args) throws GeneratorException {
+ run(args, new LineOutput());
+ }
+
+ /**
+ * Runs the generator with the specified command line arguments and output.
+ *
+ * @param args the command line arguments
+ * @param out the output
+ */
+ public void run(String[] args, ILineOutput out) throws GeneratorException {
+ try {
+ Arguments arguments = commandLineParser.parseArgs(options, args);
+
+ if(arguments.get(GeneratorBaseOptions.HELP)) {
+ printHelp(out);
+ }
+ else {
+ run(arguments, out);
+ }
+ }
+ catch (CommandLineParseException e) {
+ out.println("Error: " + e.getMessage());
+ printHelp(out);
+ throw new GeneratorException(e);
+ }
+ }
+
+ /**
+ * Runs the generator using the specified arguments and output.
+ *
+ * @param arguments the generator arguments
+ * @param out the output
+ */
+ public void run(Arguments arguments, ILineOutput out) throws GeneratorException {
+ ILogger logger = createLogger(arguments, out);
+ IGeneratorFileIO fileIO = createGeneratorFileIO(arguments, logger);
+
+ execute(arguments, fileIO, logger);
+ }
+
+ /**
+ * Returns the options of this generator.
+ *
+ * @return the options
+ */
+ public final Options getOptions() {
+ return options;
+ }
+
+ /**
+ * Creates a new set of arguments for this generator.
+ *
+ * @return the default arguments
+ */
+ public Arguments createArguments() {
+ return new Arguments(getOptions());
+ }
+
+ private void execute(Arguments arguments, IGeneratorFileIO fileIO, ILogger logger) throws GeneratorException {
+ try {
+ logger.logDebug(arguments.toString());
+
+ // Create new generator to avoid problems with static states in eTrice AbstractGenerator
+ IGenerator generator = generatorProvider.get();
+
+ doEMFRegistration(generator);
+
+ List<Resource> resources = load(arguments.getFiles(), arguments, logger);
+
+ validate(resources, arguments, logger);
+
+ generate(generator, resources, arguments, fileIO, logger);
+ }
+ catch (Exception e) {
+ logException(e, logger);
+ throw e;
+ }
+ }
+
+ private void printHelp(ILineOutput out) {
+ String help = helpFormatter.getHelp(options);
+ out.println(help);
+ }
+
+ private ILogger createLogger(Arguments arguments, ILineOutput out) {
+ Logger logger = loggerProvider.get();
+ logger.setLoglevel(arguments.get(GeneratorBaseOptions.LOGLEVEL));
+ logger.setOutput(out);
+ return logger;
+ }
+
+ private IGeneratorFileIO createGeneratorFileIO(Arguments arguments, ILogger logger) {
+ IncrementalGeneratorFileIO fileIO = fileIOProvider.get();
+ fileIO.setGenDir(arguments.get(GeneratorBaseOptions.GEN_DIR));
+ fileIO.setGenInfoDir(arguments.get(GeneratorBaseOptions.GEN_INFO_DIR));
+ fileIO.setGenerateIncremental(arguments.get(GeneratorBaseOptions.GEN_INCREMENTAL));
+ fileIO.setLogger(logger);
+ return fileIO;
+ }
+
+ private void doEMFRegistration(IGenerator generator) {
+ if(!initializedEMF) {
+ generator.doEMFRegistration();
+ initializedEMF = true;
+ }
+ }
+
+ private List<Resource> load(List<String> files, Arguments arguments, ILogger logger) {
+ return resourceLoader.load(arguments, logger);
+ }
+
+ private void validate(List<Resource> models, Arguments arguments, ILogger logger) {
+ resourceValidator.validate(models, arguments, logger);
+ }
+
+ private void generate(IGenerator generator, List<Resource> resources, Arguments arguments, IGeneratorFileIO fileIO, ILogger logger) {
+ generator.generate(resources, arguments, fileIO, logger);
+ }
+
+ private void logException(Exception e, ILogger logger) {
+ if(Loglevel.DEBUG.compareTo(logger.getLoglevel()) >= 0) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ e.printStackTrace(pw);
+ logger.logDebug(sw.toString());
+ }
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/GeneratorException.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/GeneratorException.java
new file mode 100644
index 000000000..2692f61af
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/GeneratorException.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+* Copyright (c) 2018 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Jan Belle (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base;
+
+/**
+ * An Exception that indicates an error in a generator application.
+ */
+public class GeneratorException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ public GeneratorException() {
+ }
+
+ public GeneratorException(String message) {
+ super(message);
+ }
+
+ public GeneratorException(Throwable cause) {
+ super(cause);
+ }
+
+ public GeneratorException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/IGenerator.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/IGenerator.java
new file mode 100644
index 000000000..32c0719b9
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/IGenerator.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+* Copyright (c) 2018 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Jan Belle (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.etrice.generator.base.args.Arguments;
+import org.eclipse.etrice.generator.base.io.IGeneratorFileIO;
+import org.eclipse.etrice.generator.base.logging.ILogger;
+
+/**
+ * A generator that produces code from an emf resource.
+ */
+public interface IGenerator {
+
+ /**
+ * Registers the required EMF packages of the generator.
+ */
+ void doEMFRegistration();
+
+ /**
+ * Generates code for the passed resources.
+ *
+ * @param resources the resources to generate the code from
+ * @param arguments the generator arguments
+ * @param fileIO the file access
+ * @param logger the logger
+ */
+ void generate(List<Resource> resources, Arguments arguments, IGeneratorFileIO fileIO, ILogger logger) throws GeneratorException;
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/GeneratorResourceLoader.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/GeneratorResourceLoader.java
new file mode 100644
index 000000000..b0bd76461
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/GeneratorResourceLoader.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+* Copyright (c) 2018 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Jan Belle (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base.io;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.etrice.generator.base.GeneratorException;
+import org.eclipse.etrice.generator.base.args.Arguments;
+import org.eclipse.etrice.generator.base.logging.ILogger;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+
+/**
+ * Simple implementation for resource loading and resolving.
+ * Only supports file paths and <b>not</b> URIs.
+ */
+public class GeneratorResourceLoader implements IGeneratorResourceLoader {
+
+ private Provider<ResourceSet> resourceSetProvider;
+
+ @Inject
+ public GeneratorResourceLoader(Provider<ResourceSet> resourceSetProvider) {
+ this.resourceSetProvider = resourceSetProvider;
+ }
+
+ @Override
+ public List<Resource> load(Arguments arguments, ILogger logger) throws GeneratorException {
+ List<Resource> models = new ArrayList<>(arguments.getFiles().size());
+ ResourceSet resourceSet = resourceSetProvider.get();
+ Adapter resourceAddedAdapter = new ResourceAddedAdapter(logger);
+ resourceSet.eAdapters().add(resourceAddedAdapter);
+
+ for(String f: arguments.getFiles()) {
+ Resource r = loadResource(f, resourceSet, logger);
+ models.add(r);
+ }
+
+ EcoreUtil.resolveAll(resourceSet);
+
+ return models;
+ }
+
+ private Resource loadResource(String file, ResourceSet rs, ILogger logger) {
+ try {
+ URI uri = createURI(file);
+ return rs.getResource(uri, true);
+ }
+ catch(RuntimeException | IOException e) {
+ logger.logError("couldn't load resource " + file + "; " + e.getMessage());
+ throw new GeneratorException(e);
+ }
+ }
+
+ private URI createURI(String file) throws IOException {
+ File f = new File(file);
+ String canonicalPath = f.getCanonicalPath();
+ URI uri = URI.createFileURI(canonicalPath);
+ return uri;
+ }
+
+
+
+ private class ResourceAddedAdapter extends AdapterImpl {
+
+ private ILogger logger;
+
+ public ResourceAddedAdapter(ILogger logger) {
+ this.logger = logger;
+ }
+
+ @Override
+ public void notifyChanged(Notification msg) {
+ if(msg.getEventType() == Notification.ADD) {
+ Resource addedResource = (Resource) msg.getNewValue();
+ logger.logInfo("added resource " + addedResource.getURI());
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IGeneratorFileIO.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IGeneratorFileIO.java
new file mode 100644
index 000000000..fc11ef3bc
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IGeneratorFileIO.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+* Copyright (c) 2013 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Henrik Rentz-Reichert (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base.io;
+
+import com.google.inject.ImplementedBy;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+@ImplementedBy(IncrementalGeneratorFileIO.class)
+public interface IGeneratorFileIO {
+
+ /**
+ * This method saves the contents in a file in the given path.
+ * Implementations may use the infopath for extra information like a hash key
+ * for incremental generation.
+ *
+ * @param desc a description which is may be logged
+ * @param path the file system path for the generated file
+ * @param infopath the file system path for the generated info file (if used by the implementation)
+ * @param file the file name of the generated file
+ * @param contents the contents of the generated file
+ */
+ void generateFile(String desc, String path, String infopath, String file, CharSequence contents);
+
+ void generateFile(String file, CharSequence contents);
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IGeneratorResourceLoader.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IGeneratorResourceLoader.java
new file mode 100644
index 000000000..8e097f961
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IGeneratorResourceLoader.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+* Copyright (c) 2018 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Jan Belle (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base.io;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.etrice.generator.base.GeneratorException;
+import org.eclipse.etrice.generator.base.args.Arguments;
+import org.eclipse.etrice.generator.base.logging.ILogger;
+
+import com.google.inject.ImplementedBy;
+
+/**
+ * Loads and resolves resources.
+ */
+@ImplementedBy(GeneratorResourceLoader.class)
+public interface IGeneratorResourceLoader {
+
+ /**
+ * Loads the specified files.
+ *
+ * @param arguments the generator arguments
+ * @param logger the logger
+ * @return the loaded resources
+ */
+ List<Resource> load(Arguments arguments, ILogger logger) throws GeneratorException;
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/ILineOutput.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/ILineOutput.java
new file mode 100644
index 000000000..5b80a989e
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/ILineOutput.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+* 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Henrik Rentz-Reichert (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base.io;
+
+import com.google.inject.ImplementedBy;
+
+/**
+ * A simple interface for output with just a {@link #println(String)} method.
+ *
+ * @author Henrik Rentz-Reichert
+ */
+@ImplementedBy(LineOutput.class)
+public interface ILineOutput {
+
+ /**
+ * @param txt the text to output
+ */
+ void println(String txt);
+}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IncrementalGeneratorFileIO.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IncrementalGeneratorFileIO.java
new file mode 100644
index 000000000..f03a35bd2
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IncrementalGeneratorFileIO.java
@@ -0,0 +1,140 @@
+/*******************************************************************************
+* Copyright (c) 2013 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Henrik Rentz-Reichert (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base.io;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.zip.CRC32;
+
+import org.apache.commons.io.FileUtils;
+import org.eclipse.etrice.generator.base.logging.ILogger;
+import org.eclipse.etrice.generator.base.logging.NullLogger;
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
+import org.eclipse.xtext.util.RuntimeIOException;
+
+import com.google.inject.Inject;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class IncrementalGeneratorFileIO implements IGeneratorFileIO {
+
+ private String genDir;
+ private String genInfoDir;
+ private ILogger logger;
+ private boolean generateIncremental;
+ private JavaIoFileSystemAccess fileAccess;
+
+ @Inject
+ public IncrementalGeneratorFileIO(JavaIoFileSystemAccess fileAccess) {
+ setGenDir("src-gen");
+ setGenInfoDir("src-gen-info");
+ setGenerateIncremental(false);
+ setLogger(new NullLogger());
+
+ this.fileAccess = fileAccess;
+ }
+
+ /**
+ * This method computes a hash key (a {@link java.util.zip.CRC32 CRC32} value) for the file contents
+ * and compares it to the
+ * one stored in the {@code infopath} directory with an added extension ".info". If the values are equal
+ * then the file stored in the {@code infopath} is copied to {@code path} while preserving the file data.
+ * In the other case the key is stored and the file is stored to {@code infopath} and {@code path}.
+ */
+ @Override
+ public void generateFile(String desc, String path, String infopath, String file, CharSequence contents) {
+
+ long oldCRC = 0;
+
+ // use local copy to avoid inconsistencies due to concurrent change
+ boolean genInc = generateIncremental;
+
+ if (genInc) {
+ // read old CRC value
+ fileAccess.setOutputPath(infopath);
+ try {
+ CharSequence val = fileAccess.readTextFile(file+".info", JavaIoFileSystemAccess.DEFAULT_OUTPUT);
+ oldCRC = Long.parseLong(val.toString());
+ }
+ catch (RuntimeIOException e) {
+ }
+ catch (NumberFormatException e) {
+ }
+ }
+
+ boolean write = true;
+ long newCRC = 0;
+
+ if (genInc) {
+ CRC32 crc32 = new CRC32();
+ crc32.update(contents.toString().getBytes());
+ newCRC = crc32.getValue();
+ if (oldCRC==newCRC) {
+ write = false;
+ }
+ else {
+ fileAccess.generateFile(file+".info", ""+newCRC);
+ }
+ }
+
+ if (write) {
+ logger.logInfo(desc+" '"+file+"' in '"+path+"'");
+ fileAccess.setOutputPath(path);
+ fileAccess.generateFile(file, contents);
+
+ if (genInc) {
+ // save a copy in the info directory which is not cleared (and not compiled)
+ fileAccess.setOutputPath(infopath);
+ fileAccess.generateFile(file + ".incgen.txt", contents);
+ }
+ }
+ else {
+ logger.logInfo(desc+" (unchanged) '"+file+"' in '"+path+"'");
+ File src = new File(infopath+file + ".incgen.txt");
+ File dst = new File(path+file);
+ try {
+ FileUtils.copyFile(src, dst, true);
+ }
+ catch (IOException e) {
+ fileAccess.setOutputPath(path);
+ fileAccess.generateFile(file, contents);
+ }
+ }
+ }
+
+ @Override
+ public void generateFile(String file, CharSequence contents) {
+ generateFile("generating file", genDir, genInfoDir, file, contents);
+ }
+
+ public void setGenDir(String genDir) {
+ this.genDir = genDir + "/";
+ }
+
+ public void setGenInfoDir(String genInfoDir) {
+ this.genInfoDir = genInfoDir + "/";
+ }
+
+ public void setGenerateIncremental(boolean generateIncremental) {
+ this.generateIncremental = generateIncremental;
+ }
+
+ public void setLogger(ILogger logger) {
+ this.logger = logger;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/LineOutput.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/LineOutput.java
new file mode 100644
index 000000000..6270a1d41
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/LineOutput.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+* 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base.io;
+
+import java.io.PrintStream;
+
+/**
+ * A line output that prints to a {@link PrintStream}
+ *
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class LineOutput implements ILineOutput {
+
+ private PrintStream stream;
+
+ /**
+ * Creates a new line output that prints to {@link System#out}
+ */
+ public LineOutput() {
+ this(System.out);
+ }
+
+ /**
+ * Creates a new line output that print to the passed stream.
+ *
+ * @param stream the stream
+ */
+ public LineOutput(PrintStream stream) {
+ this.stream = stream;
+ }
+
+ @Override
+ public void println(String txt) {
+ stream.println(txt);
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/ILineOutputLogger.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/ILineOutputLogger.java
new file mode 100644
index 000000000..3bb421dc3
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/ILineOutputLogger.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+* 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base.logging;
+
+import org.eclipse.etrice.generator.base.io.ILineOutput;
+
+import com.google.inject.ImplementedBy;
+
+/**
+ * An ILineOutputLogger will send its output to the specified {@link ILineOutput} if one is set.
+ *
+ * @author Henrik Rentz-Reichert
+ *
+ */
+@ImplementedBy(Logger.class)
+public interface ILineOutputLogger extends ILogger {
+
+ /**
+ * @param lo a line output to be used by the logger
+ */
+ void setOutput(ILineOutput lo);
+}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/ILogger.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/ILogger.java
new file mode 100644
index 000000000..1f4bc178b
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/ILogger.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+* Copyright (c) 2010 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base.logging;
+
+import com.google.inject.ImplementedBy;
+
+/**
+ * A simple logger interface for error messages during model validation and code generation.
+ *
+ * @author Henrik Rentz-Reichert
+ *
+ */
+@ImplementedBy(Logger.class)
+public interface ILogger {
+
+ /**
+ * @param text debug text
+ */
+ void logDebug(String text);
+
+ /**
+ * @param text informational text
+ */
+ void logInfo(String text);
+
+ /**
+ * @param text warning text
+ */
+ void logWarning(String text);
+
+ /**
+ * @param text error text
+ */
+ void logError(String text);
+
+ /**
+ * @return the loglevel
+ */
+ Loglevel getLoglevel();
+
+ /**
+ * @param loglevel the loglevel
+ */
+ void setLoglevel(Loglevel loglevel);
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/Logger.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/Logger.java
new file mode 100644
index 000000000..85b506eec
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/Logger.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+* 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base.logging;
+
+import org.eclipse.etrice.generator.base.io.ILineOutput;
+import org.eclipse.etrice.generator.base.io.LineOutput;
+
+/**
+ * A simple logger class implementing the
+ * {@link ILineOutputLogger ILineOutputLogger}
+ * interface. If no ILineOutputLogger is set then output is sent to
+ * {@link java.lang.System#out System.out}.
+ *
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class Logger implements ILineOutputLogger, ILineOutput {
+
+ private static final String DEBUG_PREFIX = "[DEBUG] ";
+ private static final String INFO_PREFIX = "[INFO] ";
+ private static final String WARNING_PREFIX = "[WARNING] ";
+ private static final String ERROR_PREFIX = "[ERROR] ";
+
+
+ private Loglevel loglevel;
+ private ILineOutput output;
+
+ public Logger() {
+ this(Loglevel.WARNING, new LineOutput());
+ }
+
+ public Logger(Loglevel loglevel) {
+ this(loglevel, new LineOutput());
+ }
+
+ public Logger(ILineOutput out) {
+ this(Loglevel.WARNING, out);
+ }
+
+ public Logger(Loglevel loglevel, ILineOutput out) {
+ setLoglevel(loglevel);
+ setOutput(out);
+ }
+
+ @Override
+ public void logDebug(String text) {
+ if(Loglevel.DEBUG.compareTo(loglevel) >= 0) {
+ println(DEBUG_PREFIX + text);
+ }
+ }
+
+ @Override
+ public void logInfo(String text) {
+ if(Loglevel.INFO.compareTo(loglevel) >= 0) {
+ println(INFO_PREFIX + text);
+ }
+ }
+
+ @Override
+ public void logWarning(String text) {
+ if(Loglevel.WARNING.compareTo(loglevel) >= 0) {
+ println(WARNING_PREFIX + text);
+ }
+ }
+
+ @Override
+ public void logError(String text) {
+ if(Loglevel.ERROR.compareTo(loglevel) >= 0) {
+ println(ERROR_PREFIX + text);
+ }
+ }
+
+ @Override
+ public Loglevel getLoglevel() {
+ return loglevel;
+ }
+
+ @Override
+ public void setLoglevel(Loglevel loglevel) {
+ this.loglevel = loglevel;
+ }
+
+ @Override
+ public void setOutput(ILineOutput out) {
+ output = out;
+ }
+
+ @Override
+ public void println(String txt) {
+ output.println(txt);
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/Loglevel.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/Loglevel.java
new file mode 100644
index 000000000..17c189c65
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/Loglevel.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+* Copyright (c) 2018 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Jan Belle (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base.logging;
+
+/**
+ * The loglevel for an {@link ILogger}.
+ */
+public enum Loglevel {
+
+ ALL,
+ DEBUG,
+ INFO,
+ WARNING,
+ ERROR,
+ OFF;
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/NullLogger.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/NullLogger.java
new file mode 100644
index 000000000..54ea2cc73
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/logging/NullLogger.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+* Copyright (c) 2012 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Henrik Rentz-Reichert (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base.logging;
+
+import org.eclipse.etrice.generator.base.logging.ILogger;
+import org.eclipse.etrice.generator.base.logging.Loglevel;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class NullLogger implements ILogger {
+
+ private boolean hasErrors = false;
+
+ @Override
+ public void logInfo(String text) {
+ }
+
+ @Override
+ public void logError(String text) {
+ hasErrors = true;
+ }
+
+ @Override
+ public void logDebug(String text) {
+ }
+
+ @Override
+ public void logWarning(String text) {
+ }
+
+ @Override
+ public Loglevel getLoglevel() {
+ return Loglevel.OFF;
+ }
+
+ @Override
+ public void setLoglevel(Loglevel loglevel) {
+ }
+
+ public boolean hasErrors() {
+ return hasErrors;
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/setup/GeneratorBaseModule.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/setup/GeneratorBaseModule.java
new file mode 100644
index 000000000..96270f23e
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/setup/GeneratorBaseModule.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+* Copyright (c) 2018 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Jan Belle (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base.setup;
+
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.etrice.generator.base.IGenerator;
+import org.eclipse.xtext.parser.IEncodingProvider;
+import org.eclipse.xtext.resource.XtextResourceSet;
+
+import com.google.inject.Binder;
+import com.google.inject.Module;
+
+/**
+ * An abstract base module for generators that configures standard implementations.
+ */
+public abstract class GeneratorBaseModule implements Module {
+
+ @Override
+ public void configure(Binder binder) {
+ binder.bind(ResourceSet.class).to(XtextResourceSet.class);
+ binder.bind(IEncodingProvider.class).to(IEncodingProvider.Runtime.class);
+
+ binder.bind(IGenerator.class).to(bindIGenerator());
+ }
+
+ /**
+ * Binds the {@link IGenerator}.
+ *
+ * @return the class of the generator implementation
+ */
+ public abstract Class<? extends IGenerator> bindIGenerator();
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/setup/GeneratorBaseOptions.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/setup/GeneratorBaseOptions.java
new file mode 100644
index 000000000..c9d3d53a5
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/setup/GeneratorBaseOptions.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+* Copyright (c) 2018 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Jan Belle (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base.setup;
+
+import java.util.List;
+
+import org.eclipse.etrice.generator.base.args.BooleanOption;
+import org.eclipse.etrice.generator.base.args.EnumOption;
+import org.eclipse.etrice.generator.base.args.IOptionsModule;
+import org.eclipse.etrice.generator.base.args.Option;
+import org.eclipse.etrice.generator.base.args.StringOption;
+import org.eclipse.etrice.generator.base.logging.Loglevel;
+
+/**
+ * Configures standard options for generators.
+ */
+public class GeneratorBaseOptions implements IOptionsModule {
+
+ public static final BooleanOption HELP = new BooleanOption(
+ "help",
+ "isHelp",
+ "display this help text",
+ false);
+
+ public static final BooleanOption GEN_INCREMENTAL = new BooleanOption(
+ "inc",
+ "isInc",
+ "if specified the generation is incremental",
+ false);
+
+ public static final StringOption GEN_DIR = new StringOption(
+ "genDir",
+ "directory",
+ "the directory for generated files",
+ "src-gen");
+
+ public static final StringOption GEN_INFO_DIR = new StringOption(
+ "genInfoDir",
+ "directory",
+ "the directory for generated info files",
+ "src-gen-info");
+
+ public static final EnumOption<Loglevel> LOGLEVEL = new EnumOption<>(
+ Loglevel.class,
+ "loglevel",
+ "level",
+ "the loglevel for the logger [all, debug, info, warning, error, off]",
+ Loglevel.INFO);
+
+ @Override
+ public void configure(List<Option<?>> options) {
+ options.add(HELP);
+ options.add(GEN_INCREMENTAL);
+ options.add(GEN_DIR);
+ options.add(GEN_INFO_DIR);
+ options.add(LOGLEVEL);
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/setup/GeneratorBaseOptionsHelper.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/setup/GeneratorBaseOptionsHelper.java
new file mode 100644
index 000000000..53afd25b7
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/setup/GeneratorBaseOptionsHelper.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+* Copyright (c) 2018 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Jan Belle (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base.setup;
+
+import org.eclipse.etrice.generator.base.args.Arguments;
+import org.eclipse.etrice.generator.base.logging.Loglevel;
+
+/**
+ * Helper class for {@link GeneratorBaseOptions}.
+ */
+public class GeneratorBaseOptionsHelper {
+
+ public boolean isHelp(Arguments args) {
+ return args.get(GeneratorBaseOptions.HELP);
+ }
+
+ public boolean isIncremental(Arguments args) {
+ return args.get(GeneratorBaseOptions.GEN_INCREMENTAL);
+ }
+
+ public String getGenDir(Arguments args) {
+ return args.get(GeneratorBaseOptions.GEN_DIR);
+ }
+
+ public String getGenInfoDir(Arguments args) {
+ return args.get(GeneratorBaseOptions.GEN_INFO_DIR);
+ }
+
+ public Loglevel getLoglevel(Arguments args) {
+ return args.get(GeneratorBaseOptions.LOGLEVEL);
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/validation/GeneratorResourceValidator.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/validation/GeneratorResourceValidator.java
new file mode 100644
index 000000000..3f74b3547
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/validation/GeneratorResourceValidator.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+* Copyright (c) 2018 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Jan Belle (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base.validation;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.etrice.generator.base.GeneratorException;
+import org.eclipse.etrice.generator.base.args.Arguments;
+import org.eclipse.etrice.generator.base.logging.ILogger;
+import org.eclipse.xtext.diagnostics.Severity;
+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;
+
+/**
+ * Simple implementation of an resource validator using an {@link IResourceValidator}.
+ */
+public class GeneratorResourceValidator implements IGeneratorResourceValidator {
+
+ private IResourceValidator resourceValidator;
+
+ /**
+ * Creates a new instance that uses the specified resource validator.
+ *
+ * @param resourceValiator the validator to use
+ */
+ @Inject
+ public GeneratorResourceValidator(IResourceValidator resourceValidator) {
+ this.resourceValidator = resourceValidator;
+ }
+
+ @Override
+ public void validate(List<Resource> resources, Arguments arguments, ILogger logger) throws GeneratorException {
+ int errors = 0;
+ int warnings = 0;
+ for (Resource resource : resources) {
+ List<Issue> list = resourceValidator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
+ if (!list.isEmpty()) {
+ for (Issue issue : list) {
+ if (issue.getSeverity() == Severity.ERROR) {
+ ++errors;
+ logger.logError(issue.toString());
+ }
+ else if(issue.getSeverity() == Severity.WARNING) {
+ ++warnings;
+ logger.logWarning(issue.toString());
+ }
+ else {
+ logger.logInfo(issue.toString());
+ }
+ }
+ }
+ }
+ logger.logInfo("validation finished with " + errors + " errors and " + warnings + " warnings");
+
+ if (errors > 0) {
+ throw new GeneratorException("validation failed");
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/validation/IGeneratorResourceValidator.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/validation/IGeneratorResourceValidator.java
new file mode 100644
index 000000000..be6378dfc
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/validation/IGeneratorResourceValidator.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+* Copyright (c) 2018 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 2.0
+* which is available at https://www.eclipse.org/legal/epl-2.0/
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* CONTRIBUTORS:
+* Jan Belle (initial contribution)
+*
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base.validation;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.etrice.generator.base.GeneratorException;
+import org.eclipse.etrice.generator.base.args.Arguments;
+import org.eclipse.etrice.generator.base.logging.ILogger;
+
+import com.google.inject.ImplementedBy;
+
+/**
+ * Validates resources.
+ */
+@ImplementedBy(GeneratorResourceValidator.class)
+public interface IGeneratorResourceValidator {
+
+ /**
+ * Validates a list of resources.
+ *
+ * @param resources the resources to validate
+ * @param arguments the generator arguments
+ * @param logger the logger to log issues
+ */
+ void validate(List<Resource> resources, Arguments arguments, ILogger logger) throws GeneratorException;
+
+}

Back to the top