summaryrefslogtreecommitdiff
path: root/org.genivi.commonapi.core.cli
diff options
context:
space:
mode:
Diffstat (limited to 'org.genivi.commonapi.core.cli')
-rw-r--r--org.genivi.commonapi.core.cli/.classpath8
-rw-r--r--org.genivi.commonapi.core.cli/.gitignore11
-rw-r--r--org.genivi.commonapi.core.cli/.project2
-rw-r--r--org.genivi.commonapi.core.cli/.settings/org.eclipse.core.resources.prefs2
-rw-r--r--org.genivi.commonapi.core.cli/.settings/org.eclipse.core.runtime.prefs2
-rw-r--r--org.genivi.commonapi.core.cli/META-INF/MANIFEST.MF21
-rw-r--r--org.genivi.commonapi.core.cli/plugin.xml118
-rw-r--r--org.genivi.commonapi.core.cli/pom.xml8
-rw-r--r--org.genivi.commonapi.core.cli/src/.gitignore1
-rw-r--r--org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/Application.java54
-rw-r--r--org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/CommandExecutableExtensionFactory.java51
-rw-r--r--org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/CommandLineHandler.java124
-rw-r--r--org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/CommandlineToolMain.java1041
-rw-r--r--org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/DBusCommandExecutableExtensionFactory.java28
-rw-r--r--org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/DeployStandaloneSetup.java40
-rw-r--r--org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/FrancaResourceFactory.java48
-rw-r--r--org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/MyProviderXtext.java28
-rw-r--r--org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/MyURIConverter.java36
-rw-r--r--org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/StandaloneSetup.java43
-rw-r--r--org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/TestModule.java29
20 files changed, 649 insertions, 1046 deletions
diff --git a/org.genivi.commonapi.core.cli/.classpath b/org.genivi.commonapi.core.cli/.classpath
index 8572780..5ba1743 100644
--- a/org.genivi.commonapi.core.cli/.classpath
+++ b/org.genivi.commonapi.core.cli/.classpath
@@ -1,9 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con"
- path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6" />
- <classpathentry kind="con"
- path="org.eclipse.pde.core.requiredPlugins" />
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" />
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins" />
<classpathentry kind="src" path="src" />
<classpathentry kind="output" path="bin" />
-</classpath> \ No newline at end of file
+</classpath>
diff --git a/org.genivi.commonapi.core.cli/.gitignore b/org.genivi.commonapi.core.cli/.gitignore
index 912c25a..ad19da6 100644
--- a/org.genivi.commonapi.core.cli/.gitignore
+++ b/org.genivi.commonapi.core.cli/.gitignore
@@ -1,10 +1,3 @@
-/.settings
-/.DS_Store
-/org.genivi.commonapi.dbus
-/org.genivi.commonapi.core
-/.settings/org.eclipse.ltk.core.refactoring.prefs
-/workspaceitestra.xml
-/build.xml
-/temp
-/.classpath
+*~
+/bin
/target
diff --git a/org.genivi.commonapi.core.cli/.project b/org.genivi.commonapi.core.cli/.project
index f719ee6..aec6f21 100644
--- a/org.genivi.commonapi.core.cli/.project
+++ b/org.genivi.commonapi.core.cli/.project
@@ -25,4 +25,4 @@
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
-</projectDescription> \ No newline at end of file
+</projectDescription>
diff --git a/org.genivi.commonapi.core.cli/.settings/org.eclipse.core.resources.prefs b/org.genivi.commonapi.core.cli/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/org.genivi.commonapi.core.cli/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/<project>=UTF-8
diff --git a/org.genivi.commonapi.core.cli/.settings/org.eclipse.core.runtime.prefs b/org.genivi.commonapi.core.cli/.settings/org.eclipse.core.runtime.prefs
new file mode 100644
index 0000000..5a0ad22
--- /dev/null
+++ b/org.genivi.commonapi.core.cli/.settings/org.eclipse.core.runtime.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+line.separator=\n
diff --git a/org.genivi.commonapi.core.cli/META-INF/MANIFEST.MF b/org.genivi.commonapi.core.cli/META-INF/MANIFEST.MF
index bbfa462..9647524 100644
--- a/org.genivi.commonapi.core.cli/META-INF/MANIFEST.MF
+++ b/org.genivi.commonapi.core.cli/META-INF/MANIFEST.MF
@@ -2,20 +2,15 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: commonapi generator Console Interface
Bundle-SymbolicName: org.genivi.commonapi.core.cli;singleton:=true
-Bundle-Version: 2.1.6.qualifier
+Bundle-Version: 3.1.1.qualifier
Bundle-Activator: org.genivi.commonapi.core.cli.Activator
Require-Bundle: org.eclipse.core.runtime,
- org.eclipse.emf.common,
- org.eclipse.emf.ecore,
- org.eclipse.emf.codegen.ecore,
- org.eclipse.xtext,
- org.franca.core.dsl,
- org.franca.deploymodel.dsl,
- org.genivi.commonapi.core,
- org.genivi.commonapi.dbus,
- org.eclipse.xtext.ui.ecore,
- org.eclipse.xtext.ui,
- org.eclipse.xtext.builder
+ org.eclipse.xtext;bundle-version="[2.7.0,3.0.0)";visibility:=reexport,
+ org.franca.core.dsl;bundle-version="[0.9.0,0.10.0)";visibility:=reexport,
+ org.franca.deploymodel.dsl;bundle-version="[0.9.0,0.10.0)";visibility:=reexport,
+ org.genivi.commonapi.core;bundle-version="3.1.1";visibility:=reexport,
+ org.genivi.commonapi.console;bundle-version="3.1.1"
Bundle-ActivationPolicy: lazy
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-Vendor: BMW AG
+Export-Package: org.genivi.commonapi.core.cli
diff --git a/org.genivi.commonapi.core.cli/plugin.xml b/org.genivi.commonapi.core.cli/plugin.xml
index 71e23e9..cbbd9d3 100644
--- a/org.genivi.commonapi.core.cli/plugin.xml
+++ b/org.genivi.commonapi.core.cli/plugin.xml
@@ -1,15 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin>
- <extension
- id="application"
- point="org.eclipse.core.runtime.applications">
- <application>
- <run
- class="org.genivi.commonapi.core.cli.Application">
- </run>
- </application>
- </extension>
<extension
id="product"
@@ -23,4 +14,113 @@
</property>
</product>
</extension>
+ <extension
+ point="org.genivi.commonapi.console.commands">
+ <command
+ class="org.genivi.commonapi.core.cli.CommandLineHandler"
+ id="org.genivi.commonapi.core.cli.command"
+ name="CommonAPI Core Code Generation">
+ <options>
+ <option
+ argCount="0"
+ description="Switch off generation of proxy code"
+ hasOptionalArg="false"
+ id="org.genivi.commonapi.core.cli.option.noproxy"
+ longName="no-proxy"
+ required="false"
+ shortName="np">
+ </option>
+ <option
+ argCount="0"
+ description="Switch off generation of stub code"
+ hasOptionalArg="false"
+ id="org.genivi.commonapi.core.cli.option.nostub"
+ longName="no-stub"
+ required="false"
+ shortName="ns">
+ </option>
+ <option
+ argCount="1"
+ description="The default output directory"
+ hasOptionalArg="false"
+ id="org.genivi.commonapi.core.cli.option.dir.default"
+ longName="dest"
+ required="false"
+ shortName="d">
+ </option>
+ <option
+ argCount="1"
+ description="The directory for the common code"
+ hasOptionalArg="false"
+ id="org.genivi.commonapi.core.cli.option.dir.common"
+ longName="dest-common"
+ required="false"
+ shortName="dc">
+ </option>
+ <option
+ argCount="1"
+ description="The directory for proxy code"
+ hasOptionalArg="false"
+ id="org.genivi.commonapi.core.cli.option.dir.proxy"
+ longName="dest-proxy"
+ required="false"
+ shortName="dp">
+ </option>
+ <option
+ argCount="1"
+ description="The directory for stub code"
+ hasOptionalArg="false"
+ id="org.genivi.commonapi.core.cli.option.dir.stub"
+ longName="dest-stub"
+ required="false"
+ shortName="ds">
+ </option>
+ <option
+ argCount="1"
+ description="The directory for the skeleton code"
+ hasOptionalArg="false"
+ id="org.genivi.commonapi.core.cli.option.dir.skel"
+ longName="dest-skel"
+ required="false"
+ shortName="dsk">
+ </option>
+ <option
+ argCount="1"
+ description="The file path to the license text that will be added to each generated file"
+ hasOptionalArg="false"
+ id="org.genivi.commonapi.core.cli.option.license"
+ longName="license"
+ required="false"
+ shortName="l">
+ </option>
+ <option
+ argCount="1"
+ description="The log level (quiet or verbose)"
+ hasOptionalArg="false"
+ id="org.genivi.commonapi.core.cli.option.loglevel"
+ longName="loglevel"
+ required="false"
+ shortName="ll">
+ </option>
+ <option
+ argCount="1"
+ description="The prefix added to all generated enumeration literals"
+ hasOptionalArg="false"
+ id="org.genivi.commonapi.core.cli.option.prefix"
+ longName="prefix-enum-literal"
+ required="false"
+ shortName="pre">
+ </option>
+ <option
+ argCount="1"
+ description="Generate skeleton code. The optional argument specifies the postfix. Without argument, the postfix is 'default'"
+ hasOptionalArg="true"
+ id="org.genivi.commonapi.core.cli.option.prefix"
+ longName="skel"
+ required="false"
+ shortName="sk">
+ </option>
+ </options>
+ </command>
+ </extension>
</plugin>
diff --git a/org.genivi.commonapi.core.cli/pom.xml b/org.genivi.commonapi.core.cli/pom.xml
index 6de7307..c19c5b2 100644
--- a/org.genivi.commonapi.core.cli/pom.xml
+++ b/org.genivi.commonapi.core.cli/pom.xml
@@ -6,8 +6,8 @@
<packaging>eclipse-plugin</packaging>
<parent>
<groupId>commonapi</groupId>
- <artifactId>org.genivi.commonapi.releng</artifactId>
- <version>2.1.6-SNAPSHOT</version>
- <relativePath>../org.genivi.commonapi.releng</relativePath>
+ <artifactId>org.genivi.commonapi.core.releng</artifactId>
+ <version>3.1.1-SNAPSHOT</version>
+ <relativePath>../org.genivi.commonapi.core.releng</relativePath>
</parent>
-</project> \ No newline at end of file
+</project>
diff --git a/org.genivi.commonapi.core.cli/src/.gitignore b/org.genivi.commonapi.core.cli/src/.gitignore
deleted file mode 100644
index 9bb88d3..0000000
--- a/org.genivi.commonapi.core.cli/src/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/.DS_Store
diff --git a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/Application.java b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/Application.java
deleted file mode 100644
index 2a45fd4..0000000
--- a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/Application.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2013 BMW Group Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de) This Source Code Form is
- * subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the
- * MPL was not distributed with this file, You can obtain one at
- * http://mozilla.org/MPL/2.0/.
- */
-package org.genivi.commonapi.core.cli;
-
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.equinox.app.IApplication;
-import org.eclipse.equinox.app.IApplicationContext;
-
-public class Application implements IApplication
-{
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.
- * IApplicationContext)
- */
- @Override
- public Object start(IApplicationContext context) throws Exception
- {
- /*
- * sleep 100 ms to guarantee that the gogo.shell.Activator is not
- * interrupted in start-up, sometimes causing a InterruptException
- */
- Thread.sleep(100);
- String[] args = Platform.getApplicationArgs();
-
- try
- {
- CommandlineToolMain.generate(args);
- }
- catch (IllegalArgumentException e)
- {
- System.err.println(e.getMessage());
- }
-
- return IApplication.EXIT_OK;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.equinox.app.IApplication#stop()
- */
- @Override
- public void stop()
- {
-
- }
-}
diff --git a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/CommandExecutableExtensionFactory.java b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/CommandExecutableExtensionFactory.java
deleted file mode 100644
index 768c1ab..0000000
--- a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/CommandExecutableExtensionFactory.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-package org.genivi.commonapi.core.cli;
-
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.xtext.generator.IGenerator;
-import org.eclipse.xtext.ui.ecore.ExecutableExtensionFactory;
-import org.genivi.commonapi.core.generator.FrancaGenerator;
-import org.osgi.framework.Bundle;
-
-import com.google.inject.Binder;
-import com.google.inject.Injector;
-import com.google.inject.Module;
-
-public class CommandExecutableExtensionFactory extends ExecutableExtensionFactory
-{
- private Injector injector;
-
- @Override
- protected Bundle getBundle()
- {
- return Activator.getDefault().getBundle();
- }
-
- @Override
- protected Injector getInjector()
- {
- if (injector == null)
- injector = super.getInjector().createChildInjector(new Module()
- {
- @Override
- public void configure(final Binder binder)
- {
- binder.bind(ResourceSet.class).to(ResourceSetImpl.class);
- bindGeneratorClass(binder);
- }
- });
-
- return injector;
- }
-
- protected void bindGeneratorClass(final Binder binder)
- {
- binder.bind(IGenerator.class).to(FrancaGenerator.class);
- }
-}
diff --git a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/CommandLineHandler.java b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/CommandLineHandler.java
new file mode 100644
index 0000000..07f43ea
--- /dev/null
+++ b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/CommandLineHandler.java
@@ -0,0 +1,124 @@
+package org.genivi.commonapi.core.cli;
+
+import java.util.List;
+
+import org.apache.commons.cli.CommandLine;
+import org.genivi.commonapi.console.AbstractCommandLineHandler;
+import org.genivi.commonapi.console.ICommandLineHandler;
+
+
+/**
+ * Handle command line options
+ */
+public class CommandLineHandler extends AbstractCommandLineHandler implements
+ ICommandLineHandler {
+
+
+ public static final String FILE_EXTENSION_FDEPL = "fdepl";
+ public static final String FILE_EXTENSION_FIDL = "fidl";
+ private CommandlineToolMain cliTool;
+
+ public CommandLineHandler() {
+ cliTool = new CommandlineToolMain();
+ }
+
+ @Override
+ public int excute(CommandLine parsedArguments) {
+
+ @SuppressWarnings("unchecked")
+ List<String> files = parsedArguments.getArgList();
+
+ // Disable log outputs if "quiet" as the very first action.
+ // -ll --loglevel quiet or verbose
+ if(parsedArguments.hasOption("ll")) {
+ cliTool.setLogLevel(parsedArguments.getOptionValue("ll"));
+ }
+
+ if(parsedArguments.hasOption("sk")) {
+ // Switch on generation of skeletons (if this option has a parameter,
+ // the parameter is the postfix for the file names
+ cliTool.setCreateSkeletonCode();
+ String skArgument = parsedArguments.getOptionValue("sk");
+ if(skArgument == null) {
+ // no -sk argument was given, use "Default"
+ skArgument = "Default";
+ }
+ // The fidl/fdepl file will be interpreted as sk argument,
+ // if "-sk" is placed just before the fidl/fdepl file in the command line !
+ if(skArgument.endsWith(FILE_EXTENSION_FDEPL) || skArgument.endsWith(FILE_EXTENSION_FIDL)) {
+ // it is not an -sk argument but it is the file to generate code from !
+ files.add(skArgument);
+ }
+ else {
+ cliTool.setSkeletonPostfix(skArgument);
+ }
+ }
+ // we expect at least the fidel/fdepl file as command line argument
+ if(files.size() > 0 && files.get(0) != null) {
+ String file = files.get(0);
+ if(file.endsWith(FILE_EXTENSION_FDEPL) || file.endsWith(FILE_EXTENSION_FIDL)) {
+ // handle command line options
+
+ // Switch off generation of proxy code
+ // -np --no-proxy do not generate proxy code
+ if(parsedArguments.hasOption("np")) {
+ cliTool.setNoProxyCode();
+ }
+
+ // Switch off generation of stub code
+ // -ns --no-stub do not generate stub code
+ if(parsedArguments.hasOption("ns")) {
+ cliTool.setNoStubCode();
+ }
+
+ // destination: -d --dest overwrite default directory
+ if(parsedArguments.hasOption("d")) {
+ cliTool.setDefaultDirectory(parsedArguments.getOptionValue("d"));
+ }
+
+ // destination: -dc --dest-common overwrite target directory for common part
+ if(parsedArguments.hasOption("dc")) {
+ cliTool.setCommonDirectory(parsedArguments.getOptionValue("dc"));
+ }
+
+ // destination: -dp --dest-proxy overwrite target directory for proxy code
+ if(parsedArguments.hasOption("dp")) {
+ cliTool.setProxyDirectory(parsedArguments.getOptionValue("dp"));
+ }
+
+ // destination: -ds --dest-stub overwrite target directory for stub code
+ if(parsedArguments.hasOption("ds")) {
+ cliTool.setStubtDirectory(parsedArguments.getOptionValue("ds"));
+ }
+
+ // destination: -dsk --dest-skel overwrite target directory for skeleton code
+ if(parsedArguments.hasOption("dsk")) {
+ cliTool.setSkeletonDirectory(parsedArguments.getOptionValue("dsk"));
+ }
+
+ // A file path, that points to a file, that contains the license text.
+ // -l --license license text in generated files
+ if(parsedArguments.hasOption("l")) {
+ cliTool.setLicenseText(parsedArguments.getOptionValue("l"));
+ }
+
+ // Add prefixes to enumeration literals
+ // -pre --prefix-enum-literal additional prefix to all generated enumeration literals
+ if(parsedArguments.hasOption("pre")) {
+ cliTool.setEnumPrefix(parsedArguments.getOptionValue("pre"));
+ }
+
+ // finally invoke the generator.
+ // the remaining arguments are assumed to be files !
+ cliTool.generateCore(files);
+ }
+ else {
+ System.out.println("The file extension should be ." + FILE_EXTENSION_FIDL + " or ." + FILE_EXTENSION_FDEPL);
+ }
+ }
+ else {
+ System.out.println("A *.fidl or *.fdepl file was not specified !");
+ }
+ return 0;
+ }
+}
diff --git a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/CommandlineToolMain.java b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/CommandlineToolMain.java
index 18f247e..5756906 100644
--- a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/CommandlineToolMain.java
+++ b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/CommandlineToolMain.java
@@ -9,676 +9,423 @@
package org.genivi.commonapi.core.cli;
import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.DataOutputStream;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.FileReader;
-import java.io.FileWriter;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
-import javax.inject.Inject;
-
import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.preferences.DefaultScope;
-import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.xtext.generator.IFileSystemAccess;
+import org.eclipse.xtext.generator.IGenerator;
import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
import org.eclipse.xtext.resource.XtextResourceSet;
+import org.eclipse.xtext.validation.AbstractValidationMessageAcceptor;
+import org.eclipse.xtext.validation.ValidationMessageAcceptor;
+import org.franca.core.dsl.FrancaIDLRuntimeModule;
+import org.franca.core.franca.FModel;
+import org.genivi.commonapi.console.ConsoleLogger;
import org.genivi.commonapi.core.generator.FrancaGenerator;
import org.genivi.commonapi.core.generator.FrancaGeneratorExtensions;
import org.genivi.commonapi.core.preferences.FPreferences;
import org.genivi.commonapi.core.preferences.PreferenceConstants;
-import org.genivi.commonapi.dbus.generator.FrancaDBusGenerator;
+import org.genivi.commonapi.core.verification.ValidatorCore;
+import com.google.inject.Guice;
import com.google.inject.Injector;
-import com.google.inject.Provider;
/**
- * This is a little Tool to generate C++ files from Franca files over the
- * commandline without Eclipse. The arguments of this tool can be the Franca
- * files which have to be generated. Additional you can set an argument -dbus to
- * generate for dbus, -dest and a path to a folder in the arguments will set the
- * output-destination to the given path and finally with -pref and a path to a
- * Textile will set the comment in the head of each file to the text from the
- * file given after -pref
- *
- * @author Patrick Sattler
+ * Receive command line arguments and set them as preference values for the code generation.
*/
public class CommandlineToolMain
{
- public static final String FILESEPARATOR = System.getProperty("file.separator");
-
- public static final String FILESEPARATORIMP = "/";
- public static final String TEMP_PFAD = System.getProperty("user.dir") + FILESEPARATOR + "temp/";
- public static final String CORE_DEPL = TEMP_PFAD + FILESEPARATOR + "org.genivi.commonapi.core"
- + FILESEPARATOR + "deployment" + FILESEPARATOR
- + "CommonAPI_deployment.fdepl";
- public static final String CORE_PFAD = TEMP_PFAD + FILESEPARATOR + "org.genivi.commonapi.core"
- + FILESEPARATOR + "deployment";
- public static final String DBUS_DEPL = TEMP_PFAD + FILESEPARATOR + "org.genivi.commonapi.dbus"
- + FILESEPARATOR + "deployment" + FILESEPARATOR
- + "CommonAPI-DBus_deployment.fdepl";
- public static final String DBUS_PFAD = TEMP_PFAD + FILESEPARATOR + "org.genivi.commonapi.dbus"
- + FILESEPARATOR + "deployment";
- public static final String TEMP_FDEPL_PFAD = TEMP_PFAD + FILESEPARATOR + "fdepl";
- public static List<String> files = new ArrayList<String>();
- // All given files were saved in this list with an absolute path
- private static Set<String> filelist = new LinkedHashSet<String>();
- // true if for all interfaces have to be generated the stubs
- private static boolean allstubs = false;
-
- @Inject
- private static Provider<JavaIoFileSystemAccess> fileAccessProvider;
-
- public static void generate(String[] args)
- {
-
- // Initialization with all options
- File tempfolder = null;
- boolean dbus = false;
- String dest = createAbsolutPath("." + FILESEPARATOR + "src-gen" + FILESEPARATOR);
- if (args.length < 1)
- {
- String errorMessage = "Usage: commonapi_generator [options] file...\n"
- + "\n"
- + "Options:\n"
- + " -dbus Additionally generate gluecode for the CommonAPI-D-Bus middleware binding\n"
- + " -dest <path/to/folder> Relative to current location, the generated files will be saved there\n"
- + " -pref <path/to/file> The text in this file which will be inserted as a comment in each generated file (for example your license)\n"
- + " -version Used versions from the CommonAPI-Generator and Franca plugin\n"
- + " -genallincl Generates all included fidls too (all Proxys and Stubs will be generated)\n";
- throw new IllegalArgumentException(errorMessage);
- }
-
- List<String> tempfilelist = new ArrayList<String>();
- FPreferences pref = FPreferences.getInstance();
- pref.clidefPreferences();
- /*
- * Reading the options and the files given in the arguments and they
- * will be saved in the predefined attributes
- */
- String francaversion = getFrancaVersion();
- String coreversion = FrancaGeneratorExtensions.getCoreVersion();
- pref.setPreference(PreferenceConstants.FRANCA_VERSION, francaversion);
- pref.setPreference(PreferenceConstants.USEPROJECTSETTINGS, Boolean.TRUE.toString());
- for (int i = 0; i < args.length; i++)
- {
- String arg = args[i];
- if (arg.equals("-dbus"))
- dbus = true;
- else if (arg.equals("-dest"))
- {
- if (i + 1 == args.length)
- {
- System.err.println("Please write a destination folder after -dest");
- System.exit(0);
- }
- File file = new File(args[i + 1]);
- if (!file.exists() || !file.isDirectory())
- {
- if (!file.mkdirs())
- {
- System.err.println("Could not create dest path");
- System.exit(0);
- }
- }
- dest = createAbsolutPath(args[i + 1]);
- i++;
- }
- else if (arg.equals("-pref"))
- {
- if (i + 1 == args.length)
- {
- System.err.println("Please write a path to an existing file after -pref");
- System.exit(0);
- }
- File file = new File(createAbsolutPath(args[i + 1]));
- i++;
- if (!file.exists() || file.isDirectory())
- {
- System.err.println("Please write a path to an existing file after -pref");
- System.exit(0);
- }
- System.out.println("The following file was set as header:\n" + file.getAbsolutePath());
- try
- {
- pref.setPreference(PreferenceConstants.USEPROJECTSETTINGS, Boolean.toString(true));
- pref.setPreferences(PreferenceConstants.P_LICENSE, file);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- else if (arg.equals("-version"))
- {
- System.out.println("Franca Version: " + francaversion);
- System.out.println("CommonAPI Version: " + coreversion);
- System.exit(0);
- }
- else if (arg.equals("-genallincl"))
- {
- allstubs = true;
- }
- else
- {
- File file = new File(createAbsolutPath(args[i]));
- if (!file.exists() || file.isDirectory())
- {
- System.err.println("The following path won't be generated because it doesn't exists:\n" + args[i] + "\n");
- }
- else
- tempfilelist.add(createAbsolutPath(arg));
- }
- }
- if (tempfilelist.size() == 0)
- {
- System.err.println("There are no valid files to generate!");
- System.exit(0);
- }
- System.out.println("The following path was set as the Outputfolder: \n" + dest);
- System.out.println("Using Franca Version " + francaversion);
- System.out.println("and CommonAPI Version " + coreversion);
- try
- {
- /*
- * The FDeploy.xmi will be loaded from the jar in a temporary folder
- * because the Generator expects a hierarchical URI an with a
- * Hierarchical URI you can't refer to a file in a jar
- */
- File xmifile = null;
- InputStream in = null;
- OutputStream out = null;
- try
- {
- in = CommandlineToolMain.class.getResourceAsStream("/org/franca/deploymodel/dsl/FDeploy.xmi");
- xmifile = new File(TEMP_PFAD + FILESEPARATOR + "FDeploy.xmi");
- tempfolder = new File(TEMP_PFAD);
- tempfolder.mkdir();
- xmifile.createNewFile();
- out = new DataOutputStream(new FileOutputStream(xmifile));
- int l = 0;
- while ((l = in.read()) != -1)
- out.write(l);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- finally
- {
- try
- {
- out.close();
- }
- catch (Exception e)
- {
- }
- try
- {
- in.close();
- }
- catch (Exception e)
- {
- }
- }
- /*
- * Here we look recursively at all files and their imports because
- * all fdepls must have overwritten imports so that the user can use
- * the same files in eclipse and the Commandline to generate. In the
- * same time the temporary path to the modified file will be saved
- * instead of the original one
- */
-
- for (int i = 0; i < tempfilelist.size(); i++)
- {
- filelist.add(rewriteImports(tempfilelist.get(i)));
- }
-
- DBusCommandExecutableExtensionFactory dbusCommandFactory = new DBusCommandExecutableExtensionFactory();
- Injector injectorDBus = dbusCommandFactory.getInjector();
- CommandExecutableExtensionFactory commandFactory = new CommandExecutableExtensionFactory();
- Injector injectorCore = commandFactory.getInjector();
- URI uri = null;
- // we initialize both generators with the Injectors
- FrancaDBusGenerator dbusgenerator = injectorDBus.getInstance(FrancaDBusGenerator.class);
- FrancaGenerator generator = injectorCore.getInstance(FrancaGenerator.class);
-
- XtextResourceSet rsset = injectorCore.getProvider(XtextResourceSet.class).get();
- fileAccessProvider = injectorCore.getProvider(JavaIoFileSystemAccess.class);
-
- final JavaIoFileSystemAccess fsa = fileAccessProvider.get();
-
- DefaultScope.INSTANCE.getNode(PreferenceConstants.SCOPE).put(PreferenceConstants.P_OUTPUT_PROXIES, dest);
- DefaultScope.INSTANCE.getNode(PreferenceConstants.SCOPE).put(PreferenceConstants.P_OUTPUT_STUBS, dest);
- InstanceScope.INSTANCE.getNode(PreferenceConstants.SCOPE).get(PreferenceConstants.P_OUTPUT_PROXIES, dest);
- InstanceScope.INSTANCE.getNode(PreferenceConstants.SCOPE).get(PreferenceConstants.P_OUTPUT_STUBS, dest);
- pref.setPreference(PreferenceConstants.P_OUTPUT_PROXIES, dest);
- pref.setPreference(PreferenceConstants.P_OUTPUT_STUBS, dest);
- fsa.setOutputPath(createAbsolutPath(dest));
- fsa.getOutputConfigurations().get(IFileSystemAccess.DEFAULT_OUTPUT).setCreateOutputDirectory(true);
- for (String file : filelist)
- {
- uri = URI.createFileURI(file);
- Resource rs = rsset.createResource(uri);
- if (dbus)
- {
- // Attention!!! some Methods from the generator are
- // deprecated because of this it could be in the near future
- // that URI's will be used
- dbusgenerator.doGenerate(rs, fsa);
- }
- else
- {
- generator.doGenerate(rs, fsa);
- }
- }
-
- }
- finally
- {
- deleteTempFiles(tempfolder);
- }
- }
-
- /**
- * gets the last segment from a path which fileseperators are
- * System.getProperty("file.separator")
- *
- * @param pfad
- * the path from were the filename is going to be extracted
- * @return the last segment of the path
- */
- private static String getFileName(String pfad)
- {
- if (pfad.lastIndexOf(FILESEPARATOR) >= 0)
- return pfad.substring(pfad.lastIndexOf(FILESEPARATOR) + 1).trim();
- return pfad.trim();
- }
-
- /**
- * the file on the path will be loaded, if the file has imports then the
- * imports will be overwritten with the right path. if the imported files
- * are also *.fdepl then thex will be also loaded
- *
- * @param path
- * the path to the file which has to be loaded and analyzed
- * @return the new path to the file
- */
- private static String rewriteImports(String path)
- {
- files.add(path);
- String rootpath = path.substring(0, path.lastIndexOf(FILESEPARATOR));
- String ret = path;
- if (path.endsWith(".fdepl"))
- {
- File filein = new File(createAbsolutPath(path));
- String uristr = "";
- File fileout = null;
- uristr = TEMP_FDEPL_PFAD + FILESEPARATOR + getFileName(path);
- fileout = new File(uristr);
- ret = uristr;
- File folder = new File(TEMP_FDEPL_PFAD);
- folder.mkdirs();
- BufferedReader instr = null;
- BufferedWriter outstr = null;
- try
- {
- fileout.createNewFile();
- instr = new BufferedReader(new FileReader(filein));
- outstr = new BufferedWriter(new FileWriter(fileout));
- String line = "";
- while ((line = instr.readLine()) != null)
- {
- // if a line contains the string "import" it will be
- // analyzed if there is something imported that i dont know
- // how to handle it will be passed through
-
- // here could be problems with relative paths on things that
- // get imported but not handled
-
- // the imported files will only be handled if they weren't
- // handled before
- if (line.trim().startsWith("import"))
- {
- if (line.contains("dbus/deployment/CommonAPI-DBus_deployment.fdepl"))
- {
- line = "import \"file:" + FILESEPARATORIMP + replaceAll(DBUS_DEPL, "\\", "/") + "\"";
- if (!files.contains(DBUS_DEPL))
- {
- handleDeployment(false);
- }
- }
- else if (line.contains("core/deployment/CommonAPI_deployment.fdepl"))
- {
- line = "import \"file:" + FILESEPARATORIMP + replaceAll(CORE_DEPL, "\\", "/") + "\"";
- if (!files.contains(CORE_DEPL))
- {
- handleDeployment(true);
- }
- }
- else if (line.contains(".fdepl"))
- {
- String cp = line;
- line = "import \"file:" + FILESEPARATORIMP + replaceAll(TEMP_FDEPL_PFAD, "\\", "/") + FILESEPARATORIMP
- + getImportsName(line) + "\"";
- if (!files.contains(createAbsolutPath(getImportPath(cp), path)))
- rewriteImports(createAbsolutPath(getImportPath(cp), path));
- }
- else if (line.contains(".fidl"))
- {
- String fidlpath = createAbsolutPath(getImportPath(line), path.substring(0, path.lastIndexOf(FILESEPARATOR)));
- if (allstubs)
- filelist.add(fidlpath);
- line = "import \"file:" + replaceAll(fidlpath, "\\", "/") + "\"";
-
- }
- }
- outstr.write(line + "\n");
- }
-
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- finally
- {
- try
- {
- instr.close();
- }
- catch (Exception e)
- {
- ;
- }
- try
- {
- outstr.close();
- }
- catch (Exception e)
- {
- ;
- }
- }
- }
- else if (allstubs)
- {
- File file = new File(createAbsolutPath(path));
- BufferedReader str = null;
- try
- {
- str = new BufferedReader(new FileReader(file));
- String line = "";
- while ((line = str.readLine()) != null)
- {
- if (line.contains("import"))
- {
- String importfile = line.substring(line.indexOf('"') + 1);
- importfile = importfile.substring(0, importfile.indexOf('"'));
- filelist.add(createAbsolutPath(importfile,rootpath));
- }
- }
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- finally
- {
- try
- {
- str.close();
- }
- catch (Exception e)
- {
- }
- }
- }
- return ret;
- }
-
- /**
- * Here we create an absolute path from a relativ path and a rootpath from
- * which the relative path begins
- *
- * @param path
- * the relative path which begins on rootpath
- * @param rootpath
- * an absolute path to a folder
- * @return the merded absolute path without points
- */
- private static String createAbsolutPath(String path, String rootpath)
- {
- if (System.getProperty("os.name").contains("Windows"))
- {
- if (path.startsWith(":", 1))
- return path;
- }
- else
- {
- if (path.startsWith(FILESEPARATOR))
- return path;
- }
-
- String ret = (rootpath.endsWith(FILESEPARATOR) ? rootpath : (rootpath + FILESEPARATOR)) + path;
- while (ret.contains(FILESEPARATOR + "." + FILESEPARATOR) || ret.contains(FILESEPARATOR + ".." + FILESEPARATOR))
- {
- if (ret.contains(FILESEPARATOR + ".." + FILESEPARATOR))
- {
- String temp = ret.substring(0, ret.indexOf(FILESEPARATOR + ".."));
- temp = temp.substring(0, temp.lastIndexOf(FILESEPARATOR));
- ret = temp + ret.substring(ret.indexOf(FILESEPARATOR + "..") + 3);
- }
- else
- {
- ret = replaceAll(ret, FILESEPARATOR + "." + FILESEPARATOR, FILESEPARATOR);
- }
- }
- return ret;
- }
-
- /**
- * reads from a line with import "path/to/file" the path to file
- *
- * @param line
- * the line with the import instruction
- * @return the path alone without import and ""
- */
- private static String getImportPath(String line)
- {
- line = line.substring(line.indexOf("import") + 8).trim();
- line = line.substring(0, line.length() - 1);
- return line;
- }
-
- /**
- * creates a absolute path from a relative path which starts on the current
- * user directory
- *
- * @param path
- * the relative path which start on the current user-directory
- * @return the created absolute path
- */
- public static String createAbsolutPath(String path)
- {
- return createAbsolutPath(path, System.getProperty("user.dir") + FILESEPARATOR);
- }
-
- /**
- * reads from a line with import "path/to/import/file" the filename
- *
- * @param line
- * the line with the import instruction
- * @return The name of the imported file
- */
- private static String getImportsName(String line)
- {
- return getFileName(getImportPath(line));
- }
-
- /**
- * handles the import instructions which refer to a deployment.fdepl (dbus
- * or core). These deployment files are in the commandline jar and because
- * of this they have to be loaded on a different way you can choose if you
- * would like only to load the core or also the dbus depl (because the dbus
- * deployment.fdepl imports the core deployment.fdepl)
- *
- * @param core
- * if true only the core file will be loaded otherwise also the
- * dbus deployment.fdepl will be loaded
- */
- private static void handleDeployment(boolean core)
- {
- BufferedReader reader = null;
- BufferedWriter writer = null;
- if (!core)
- {
- File file = new File(DBUS_DEPL);
- File folder = new File(DBUS_PFAD);
- folder.mkdirs();
- try
- {
- file.createNewFile();
- reader = new BufferedReader(new InputStreamReader(
- CommandlineToolMain.class.getResourceAsStream("/CommonAPI-DBus_deployment.fdepl")));
- writer = new BufferedWriter(new FileWriter(file));
- String line = "";
- while ((line = reader.readLine()) != null)
- {
- if (line.contains("import"))
- {
- line = "import \"file:" + FILESEPARATORIMP + replaceAll(CORE_DEPL, "\\", "/") + "\"";
- }
-
- writer.write(line + "\n");
- }
- files.add(DBUS_DEPL);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- finally
- {
- try
- {
- reader.close();
- }
- catch (Exception e)
- {
- ;
- }
- try
- {
- writer.close();
- }
- catch (Exception e)
- {
- ;
- }
- }
-
- }
- File file = new File(CORE_DEPL);
- File folder = new File(CORE_PFAD);
- folder.mkdirs();
- try
- {
- file.createNewFile();
- reader = new BufferedReader(new InputStreamReader(CommandlineToolMain.class.getResourceAsStream("/CommonAPI_deployment.fdepl")));
- writer = new BufferedWriter(new FileWriter(file));
- int i = 0;
- while ((i = reader.read()) != -1)
- writer.write(i);
- files.add(CORE_DEPL);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- finally
- {
- try
- {
- reader.close();
- }
- catch (Exception e)
- {
- ;
- }
- try
- {
- writer.close();
- }
- catch (Exception e)
- {
- ;
- }
- }
- }
-
- /**
- * a relaceAll Method which doesn't interprets the toreplace String as a
- * regex and so you can also replace \ and such special things
- *
- * @param text
- * the text who has to be modified
- * @param toreplace
- * the text which has to be replaced
- * @param replacement
- * the text which has to be inserted instead of toreplace
- * @return the modified text with all toreplace parts replaced with
- * replacement
- */
- public static String replaceAll(String text, String toreplace, String replacement)
- {
- String ret = "";
- while (text.contains(toreplace))
- {
- ret += text.substring(0, text.indexOf(toreplace)) + replacement;
- text = text.substring(text.indexOf(toreplace) + toreplace.length());
- }
- ret += text;
- return ret;
- }
-
- /**
- * removes recursively all files on the path and his folders and at the end
- * himself
- *
- * @param path
- * the path to the folder which has to be deleted
- */
- public static void deleteTempFiles(File path)
- {
- if (path != null && path.isDirectory())
- {
- for (File file : path.listFiles())
- {
- if (file.isDirectory())
- deleteTempFiles(file);
- file.delete();
- }
- }
- if (path != null)
- path.delete();
- }
-
- public static String getFrancaVersion()
- {
- return Platform.getBundle("org.franca.core").getVersion().toString();
- }
-
+ public static final String FILESEPARATOR = System.getProperty("file.separator");
+
+ public static List<String> files = new ArrayList<String>();
+ // All given files were saved in this list with an absolute path
+ protected static Set<String> filelist = new LinkedHashSet<String>();
+ // true if for all interfaces have to be generated the stubs
+ protected static boolean allstubs = false;
+
+ protected JavaIoFileSystemAccess fsa;
+ private FPreferences pref;
+ protected Injector injector;
+ private List<String> tempfilelist;
+
+ protected IGenerator francaGenerator;
+
+ protected ValidatorCore validator;
+ private int validationErrorCount;
+ protected String SCOPE = "Core validation: ";
+
+ private ValidationMessageAcceptor cliMessageAcceptor = new AbstractValidationMessageAcceptor() {
+
+ @Override
+ public void acceptInfo(String message, EObject object, EStructuralFeature feature, int index, String code, String... issueData) {
+ ConsoleLogger.printLog(SCOPE + message);
+ }
+
+ @Override
+ public void acceptWarning(String message, EObject object, EStructuralFeature feature, int index, String code, String... issueData) {
+ ConsoleLogger.printLog("Warning: " + SCOPE + message);
+ }
+
+ @Override
+ public void acceptError(String message, EObject object, EStructuralFeature feature, int index, String code, String... issueData) {
+ validationErrorCount++;
+ ConsoleLogger.printLog("Error: " + SCOPE + message);
+ }
+ };
+
+ /**
+ * The constructor registers the needed bindings to use the generator
+ */
+ public CommandlineToolMain()
+ {
+ injector = Guice.createInjector(new FrancaIDLRuntimeModule());
+
+ fsa = injector.getInstance(JavaIoFileSystemAccess.class);
+
+ pref = FPreferences.getInstance();
+
+ validator = new ValidatorCore();
+
+ }
+
+ /**
+ * Set the text from a file which will be inserted as a comment in each generated file (for example your license)
+ *
+ * @param fileWithText
+ * @return
+ */
+ public void setLicenseText(String fileWithText) {
+ if (fileWithText != null && !fileWithText.isEmpty())
+ {
+ File file = new File(createAbsolutPath(fileWithText));
+ if (!file.exists() || file.isDirectory())
+ {
+ ConsoleLogger.printErrorLog("Please specify a path to an existing file after option -l");
+ }
+ BufferedReader inReader = null;
+ String licenseText = "";
+ try
+ {
+ inReader = new BufferedReader(new FileReader(file));
+ String thisLine;
+ while ((thisLine = inReader.readLine()) != null)
+ {
+ licenseText = licenseText + thisLine + "\n";
+ }
+ if (licenseText != null && !licenseText.isEmpty())
+ {
+ pref.setPreference(PreferenceConstants.P_LICENSE, licenseText);
+ }
+ }
+ catch (IOException e)
+ {
+ ConsoleLogger.printLog("Failed to set the text from the given file: " + e.getLocalizedMessage());
+ }
+ finally
+ {
+ try
+ {
+ inReader.close();
+ }
+ catch (Exception e)
+ {
+ ;
+ }
+ }
+ ConsoleLogger.printLog("The following text was set as header: \n" + licenseText);
+ }
+ else
+ {
+ ConsoleLogger.printErrorLog("Please write a path to an existing file after -p");
+ }
+ }
+
+ public void generateCore(List<String> fileList)
+ {
+ francaGenerator = injector.getInstance(FrancaGenerator.class);
+
+ doGenerate(fileList);
+ }
+
+ /**
+ * Call the franca generator for the specified list of files.
+ *
+ * @param fileList
+ * the list of files to generate code from
+ */
+ protected void doGenerate(List<String> fileList)
+ {
+ fsa.setOutputConfigurations(FPreferences.getInstance().getOutputpathConfiguration());
+
+ XtextResourceSet rsset = injector.getProvider(XtextResourceSet.class).get();
+
+ tempfilelist = new ArrayList<String>();
+
+ /*
+ * Reading the options and the files given in the arguments and they
+ * will be saved in the predefined attributes
+ */
+ String francaversion = getFrancaVersion();
+ String coreversion = FrancaGeneratorExtensions.getCoreVersion();
+ for (String element : fileList)
+ {
+ File file = new File(createAbsolutPath(element));
+ if (!file.exists() || file.isDirectory())
+ {
+ ConsoleLogger.printErrorLog("The following path won't be generated because it doesn't exists:\n" + element + "\n");
+ }
+ else
+ tempfilelist.add(createAbsolutPath(element));
+ }
+ if (tempfilelist.size() == 0)
+ {
+ ConsoleLogger.printErrorLog("There are no valid files to generate !");
+ return;
+ }
+ ConsoleLogger.printLog("Using Franca Version " + francaversion);
+ ConsoleLogger.printLog("and CommonAPI Version " + coreversion);
+
+ for (String file : tempfilelist)
+ {
+ URI uri = URI.createFileURI(file);
+ Resource resource = rsset.createResource(uri);
+ validationErrorCount = 0;
+ validate(resource);
+ if(validationErrorCount == 0) {
+ ConsoleLogger.printLog("Generating code for " + file);
+ try {
+ francaGenerator.doGenerate(resource, fsa);
+ }
+ catch (Exception e) {
+ ConsoleLogger.printErrorLog("Failed to generate code !");
+ ConsoleLogger.printErrorLog(e.getMessage());
+ }
+ }
+ else {
+ ConsoleLogger.printErrorLog(file + " contains errors !");
+ }
+ }
+ }
+
+ private void validate(Resource resource) {
+ EObject model = null;
+
+ if(resource != null && resource.getURI().isFile()) {
+
+ try {
+ resource.load(Collections.EMPTY_MAP);
+ model = resource.getContents().get(0);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ ConsoleLogger.printLog("validating...");
+
+ // check for (internal )resource validation errors
+ for(org.eclipse.emf.ecore.resource.Resource.Diagnostic error : resource.getErrors()) {
+ ConsoleLogger.printErrorLog("ERROR at line: " + error.getLine() + " : " + error.getMessage());
+ validationErrorCount++;
+ }
+
+ // check for external validation errors if no errors have been detected so far
+ if(validationErrorCount == 0 ) {
+ if( model instanceof FModel) {
+ FModel fmodel = (FModel)model;
+ try {
+ validator.validateModel(fmodel, cliMessageAcceptor);
+ } catch (Exception e) {
+ ConsoleLogger.printErrorLog(e.getMessage());
+ validationErrorCount++;
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * creates a absolute path from a relative path which starts on the current
+ * user directory
+ *
+ * @param path
+ * the relative path which start on the current user-directory
+ * @return the created absolute path
+ */
+ public String createAbsolutPath(String path)
+ {
+ return createAbsolutPath(path, System.getProperty("user.dir") + FILESEPARATOR);
+ }
+
+ /**
+ * Here we create an absolute path from a relativ path and a rootpath from
+ * which the relative path begins
+ *
+ * @param path
+ * the relative path which begins on rootpath
+ * @param rootpath
+ * an absolute path to a folder
+ * @return the merded absolute path without points
+ */
+ private String createAbsolutPath(String path, String rootpath)
+ {
+ if (System.getProperty("os.name").contains("Windows"))
+ {
+ if (path.startsWith(":", 1))
+ return path;
+ }
+ else
+ {
+ if (path.startsWith(FILESEPARATOR))
+ return path;
+ }
+
+ String ret = (rootpath.endsWith(FILESEPARATOR) ? rootpath : (rootpath + FILESEPARATOR)) + path;
+ while (ret.contains(FILESEPARATOR + "." + FILESEPARATOR) || ret.contains(FILESEPARATOR + ".." + FILESEPARATOR))
+ {
+ if (ret.contains(FILESEPARATOR + ".." + FILESEPARATOR))
+ {
+ String temp = ret.substring(0, ret.indexOf(FILESEPARATOR + ".."));
+ temp = temp.substring(0, temp.lastIndexOf(FILESEPARATOR));
+ ret = temp + ret.substring(ret.indexOf(FILESEPARATOR + "..") + 3);
+ }
+ else
+ {
+ ret = replaceAll(ret, FILESEPARATOR + "." + FILESEPARATOR, FILESEPARATOR);
+ }
+ }
+ return ret;
+ }
+
+
+ /**
+ * a relaceAll Method which doesn't interprets the toreplace String as a
+ * regex and so you can also replace \ and such special things
+ *
+ * @param text
+ * the text who has to be modified
+ * @param toreplace
+ * the text which has to be replaced
+ * @param replacement
+ * the text which has to be inserted instead of toreplace
+ * @return the modified text with all toreplace parts replaced with
+ * replacement
+ */
+ public String replaceAll(String text, String toreplace, String replacement)
+ {
+ String ret = "";
+ while (text.contains(toreplace))
+ {
+ ret += text.substring(0, text.indexOf(toreplace)) + replacement;
+ text = text.substring(text.indexOf(toreplace) + toreplace.length());
+ }
+ ret += text;
+ return ret;
+ }
+
+ /**
+ * removes recursively all files on the path and his folders and at the end
+ * himself
+ *
+ * @param path
+ * the path to the folder which has to be deleted
+ */
+ public void deleteTempFiles(File path)
+ {
+ if (path != null && path.isDirectory())
+ {
+ for (File file : path.listFiles())
+ {
+ if (file.isDirectory())
+ deleteTempFiles(file);
+ file.delete();
+ }
+ }
+ if (path != null)
+ path.delete();
+ }
+
+ public String getFrancaVersion()
+ {
+ return Platform.getBundle("org.franca.core").getVersion().toString();
+ }
+
+ public void setNoProxyCode() {
+ pref.setPreference(PreferenceConstants.P_GENERATEPROXY, "false");
+ ConsoleLogger.printLog("No proxy code will be generated");
+ }
+
+ public void setNoStubCode() {
+ pref.setPreference(PreferenceConstants.P_GENERATESTUB, "false");
+ ConsoleLogger.printLog("No stub code will be generated");
+ }
+
+ public void setDefaultDirectory(String optionValue) {
+ ConsoleLogger.printLog("Default output directory: " + optionValue);
+ pref.setPreference(PreferenceConstants.P_OUTPUT_DEFAULT, optionValue);
+ // In the case where no other output directories are set,
+ // this default directory will be used for them
+ pref.setPreference(PreferenceConstants.P_OUTPUT_COMMON, optionValue);
+ pref.setPreference(PreferenceConstants.P_OUTPUT_PROXIES, optionValue);
+ pref.setPreference(PreferenceConstants.P_OUTPUT_STUBS, optionValue);
+ pref.setPreference(PreferenceConstants.P_OUTPUT_SKELETON, optionValue);
+ }
+
+ public void setCommonDirectory(String optionValue) {
+ ConsoleLogger.printLog("Common output directory: " + optionValue);
+ pref.setPreference(PreferenceConstants.P_OUTPUT_COMMON, optionValue);
+ }
+
+ public void setProxyDirectory(String optionValue) {
+ ConsoleLogger.printLog("Proxy output directory: " + optionValue);
+ pref.setPreference(PreferenceConstants.P_OUTPUT_PROXIES, optionValue);
+ }
+
+ public void setStubtDirectory(String optionValue) {
+ ConsoleLogger.printLog("Stub output directory: " + optionValue);
+ pref.setPreference(PreferenceConstants.P_OUTPUT_STUBS, optionValue);
+ }
+
+ public void setSkeletonDirectory(String optionValue) {
+ ConsoleLogger.printLog("Skeleton output directory: " + optionValue);
+ pref.setPreference(PreferenceConstants.P_OUTPUT_SKELETON, optionValue);
+ }
+
+ public void setLogLevel(String optionValue) {
+ if(PreferenceConstants.LOGLEVEL_QUIET.equals(optionValue)) {
+ pref.setPreference(PreferenceConstants.P_LOGOUTPUT, "false");
+ ConsoleLogger.enableLogging(false);
+ ConsoleLogger.enableErrorLogging(false);
+ }
+ if(PreferenceConstants.LOGLEVEL_VERBOSE.equals(optionValue)) {
+ pref.setPreference(PreferenceConstants.P_LOGOUTPUT, "true");
+ ConsoleLogger.enableErrorLogging(true);
+ ConsoleLogger.enableLogging(true);
+ }
+ }
+
+ public void setEnumPrefix(String optionValue) {
+ pref.setPreference(PreferenceConstants.P_ENUMPREFIX, optionValue);
+ ConsoleLogger.printLog("Enum prefix: " + optionValue);
+ }
+
+ public void setCreateSkeletonCode() {
+ pref.setPreference(PreferenceConstants.P_GENERATESKELETON, "true");
+ ConsoleLogger.printLog("Skeleton code will be created");
+ }
+
+ public void setSkeletonPostfix(String optionValue) {
+ String postfix = (optionValue == null ? "Default" : optionValue);
+ pref.setPreference(PreferenceConstants.P_SKELETONPOSTFIX, postfix);
+ ConsoleLogger.printLog("Skeleton postfix: " + postfix);
+ }
}
diff --git a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/DBusCommandExecutableExtensionFactory.java b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/DBusCommandExecutableExtensionFactory.java
deleted file mode 100644
index 8a20c7d..0000000
--- a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/DBusCommandExecutableExtensionFactory.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-package org.genivi.commonapi.core.cli;
-
-import org.eclipse.xtext.generator.IGenerator;
-import org.genivi.commonapi.dbus.generator.FrancaDBusGenerator;
-import org.osgi.framework.Bundle;
-
-import com.google.inject.Binder;
-
-public class DBusCommandExecutableExtensionFactory extends CommandExecutableExtensionFactory
-{
- @Override
- protected Bundle getBundle()
- {
- return Activator.getDefault().getBundle();
- }
-
- @Override
- protected void bindGeneratorClass(Binder binder)
- {
- binder.bind(IGenerator.class).to(FrancaDBusGenerator.class);
- }
-}
diff --git a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/DeployStandaloneSetup.java b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/DeployStandaloneSetup.java
deleted file mode 100644
index c25e319..0000000
--- a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/DeployStandaloneSetup.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2013 BMW Group Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de) This Source Code Form is
- * subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the
- * MPL was not distributed with this file, You can obtain one at
- * http://mozilla.org/MPL/2.0/.
- */
-
-package org.genivi.commonapi.core.cli;
-
-import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.franca.deploymodel.dsl.FDeployRuntimeModule;
-import org.franca.deploymodel.dsl.FDeployStandaloneSetup;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.util.Modules;
-
-public class DeployStandaloneSetup extends FDeployStandaloneSetup {
-
- @Override
- public Injector createInjector() {
- // The Module has to replace some standard bindings in the
- // FDeployRuntimeModule
- return Guice.createInjector(Modules.override(new FDeployRuntimeModule()).with(new TestModule()));
- }
-
- @Override
- public Injector createInjectorAndDoEMFRegistration() {
- // Here the Resourcefactory is set for the fileending .fdepl so that the
- // resourceset knows where to search for a factory for files with these
- // ending
- Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("fdepl", new FrancaResourceFactory());
- EPackage.Registry.INSTANCE.put(GenModelPackage.eNS_URI, GenModelPackage.eINSTANCE);
- return super.createInjectorAndDoEMFRegistration();
- }
-
-}
diff --git a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/FrancaResourceFactory.java b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/FrancaResourceFactory.java
deleted file mode 100644
index 938e9aa..0000000
--- a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/FrancaResourceFactory.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2013 BMW Group Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de) This Source Code Form is
- * subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the
- * MPL was not distributed with this file, You can obtain one at
- * http://mozilla.org/MPL/2.0/.
- */
-
-package org.genivi.commonapi.core.cli;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.xtext.linking.lazy.LazyLinker;
-import org.eclipse.xtext.linking.lazy.LazyLinkingResource;
-import org.eclipse.xtext.linking.lazy.LazyURIEncoder;
-import org.eclipse.xtext.resource.IResourceFactory;
-import org.franca.deploymodel.dsl.parser.antlr.FDeployParser;
-import org.franca.deploymodel.dsl.services.FDeployGrammarAccess;
-
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-
-public class FrancaResourceFactory implements IResourceFactory {
-
- @Inject
- Injector in;
-
- /**
- * creates from uris to files with the fdepl fileending resources
- */
- public Resource createResource(URI uri) {
-
- LazyLinkingResource rs = in.getInstance(LazyLinkingResource.class);
- rs.setURI(uri);
- FDeployParser parser = in.getInstance(FDeployParser.class);
- FDeployGrammarAccess access = in.getInstance(FDeployGrammarAccess.class);
-
- // For here the FDeploy.xmi is loaded
- parser.setGrammarAccess(access);
- rs.setParser(parser);
-
- rs.setLinker(in.getInstance(LazyLinker.class));
- rs.setEncoder(in.getInstance(LazyURIEncoder.class));
-
- return rs;
- }
-
-}
diff --git a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/MyProviderXtext.java b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/MyProviderXtext.java
deleted file mode 100644
index e383e04..0000000
--- a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/MyProviderXtext.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2013 BMW Group Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de) This Source Code Form is
- * subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the
- * MPL was not distributed with this file, You can obtain one at
- * http://mozilla.org/MPL/2.0/.
- */
-
-package org.genivi.commonapi.core.cli;
-
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.xtext.resource.XtextResourceSet;
-
-import com.google.inject.Provider;
-
-public class MyProviderXtext implements Provider<XtextResourceSet> {
-
- /**
- * These Provider creates a XtextResourceSet because i had to modify the
- * URIConverter so that the FDeploy.xmi will be loaded correctly
- */
- public XtextResourceSet get() {
- XtextResourceSet rsset = new XtextResourceSet();
- rsset.setURIConverter(new MyURIConverter());
- rsset.setResourceFactoryRegistry(Resource.Factory.Registry.INSTANCE);
- return rsset;
- }
-}
diff --git a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/MyURIConverter.java b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/MyURIConverter.java
deleted file mode 100644
index 6c36151..0000000
--- a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/MyURIConverter.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2013 BMW Group Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de) This Source Code Form is
- * subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the
- * MPL was not distributed with this file, You can obtain one at
- * http://mozilla.org/MPL/2.0/.
- */
-
-package org.genivi.commonapi.core.cli;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
-import org.eclipse.xtext.resource.FileNotFoundOnClasspathException;
-
-public class MyURIConverter extends ExtensibleURIConverterImpl {
-
- /**
- * If these URIConverter gets as URI the file FDeploy.xmi sothe path will be
- * new created to the temporary loaded file. the path to the temporary file
- * we get from the Main class which knows the temporary path. If the given
- * URI is FDeploy.xtextbin we throw a FileNotFoundOnClasspathException
- * because we don't have these file and the calling method expects this
- * error if the file is not available
- */
- @Override
- public URI normalize(URI uri) {
- if (uri.lastSegment() != null && uri.lastSegment().contains("FDeploy.xmi")) {
- URI ret = URI.createFileURI(CommandlineToolMain.createAbsolutPath("." + CommandlineToolMain.FILESEPARATOR
- + "temp" + CommandlineToolMain.FILESEPARATOR + "FDeploy.xmi"));
- return ret;
- }
- if (uri.lastSegment() != null && uri.lastSegment().contains("FDeploy.xtextbin"))
- throw new FileNotFoundOnClasspathException("");
- return super.normalize(uri);
- }
-}
diff --git a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/StandaloneSetup.java b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/StandaloneSetup.java
deleted file mode 100644
index cadb147..0000000
--- a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/StandaloneSetup.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2013 BMW Group Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de) This Source Code Form is
- * subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the
- * MPL was not distributed with this file, You can obtain one at
- * http://mozilla.org/MPL/2.0/.
- */
-
-package org.genivi.commonapi.core.cli;
-
-import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.xtext.Grammar;
-import org.eclipse.xtext.generator.IGenerator;
-import org.eclipse.xtext.impl.GrammarImpl;
-import org.franca.core.dsl.FrancaIDLRuntimeModule;
-import org.franca.core.dsl.FrancaIDLStandaloneSetup;
-import org.genivi.commonapi.core.generator.FrancaGenerator;
-
-import com.google.inject.Binder;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.Module;
-import com.google.inject.util.Modules;
-
-public class StandaloneSetup extends FrancaIDLStandaloneSetup {
- @Override
- public Injector createInjector() {
- return Guice.createInjector(Modules.combine(new FrancaIDLRuntimeModule(), new Module() {
-
- public void configure(Binder binder) {
- binder.bind(IGenerator.class).to(FrancaGenerator.class);
- binder.bind(Grammar.class).to(GrammarImpl.class);
- }
- }));
- }
-
- @Override
- public Injector createInjectorAndDoEMFRegistration() {
- EPackage.Registry.INSTANCE.put(GenModelPackage.eNS_URI, GenModelPackage.eINSTANCE);
- return super.createInjectorAndDoEMFRegistration();
- }
-} \ No newline at end of file
diff --git a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/TestModule.java b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/TestModule.java
deleted file mode 100644
index d94eba0..0000000
--- a/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/TestModule.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2013 BMW Group Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de) This Source Code Form is
- * subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the
- * MPL was not distributed with this file, You can obtain one at
- * http://mozilla.org/MPL/2.0/.
- */
-
-package org.genivi.commonapi.core.cli;
-
-import org.eclipse.xtext.resource.IResourceFactory;
-import org.eclipse.xtext.resource.XtextResourceSet;
-import org.franca.deploymodel.dsl.FDeployRuntimeModule;
-
-import com.google.inject.Binder;
-
-public class TestModule extends FDeployRuntimeModule {
-
- /**
- * Here the Injector gets the bindings which we need for correct generating.
- * For example there we set the binding for the XtextResourceSet that these
- * classes can only be created by the injector by a Provider which i have
- * implemented
- */
- public void configure(Binder binder) {
- binder.bind(IResourceFactory.class).to(FrancaResourceFactory.class);
- binder.bind(XtextResourceSet.class).toProvider(MyProviderXtext.class);
- }
-}