diff options
author | Johannes Schanda <schanda@itestra.de> | 2013-09-03 15:52:10 +0200 |
---|---|---|
committer | Patrick Sattler <sattler@itestra.de> | 2013-09-04 10:36:29 +0200 |
commit | f1cfd6a842926efd4bbc71470e430e3f03d8aa82 (patch) | |
tree | ab7c8ec7fab6798f1c5d7d560e52f084cc3977b2 | |
parent | cbc8e935426f616ccadd01a956cf0910eb32a83a (diff) | |
download | genivi-common-api-runtime-f1cfd6a842926efd4bbc71470e430e3f03d8aa82.tar.gz |
Added CLI Generation and project specific properties.
- Tools for commandline interface generation from Franca files.
- Added project specific settings for eclipse code generation plugins.
Change-Id: I0854179051ef61b66210f09ac06cd8a7c5a1e420
34 files changed, 1932 insertions, 160 deletions
@@ -1,3 +1,4 @@ */bin */src-gen */xtend-gen +.DS_Store diff --git a/org.genivi.commonapi.core.cli/.classpath b/org.genivi.commonapi.core.cli/.classpath new file mode 100644 index 0000000..42c55cf --- /dev/null +++ b/org.genivi.commonapi.core.cli/.classpath @@ -0,0 +1,100 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="src" path="/org.genivi.commonapi.core"/> + <classpathentry kind="src" path="/org.genivi.commonapi.dbus"/> + <classpathentry kind="lib" path="/Applications/eclipse/plugins/org.eclipse.emf.common_2.9.0.v20130528-0742.jar" sourcepath="/Applications/eclipse/plugins/org.eclipse.emf.common_2.9.0.v20130528-0742.jar"> + <accessrules> + <accessrule kind="accessible" pattern="org/eclipse/emf/common/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/common/archive/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/common/command/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/common/notify/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/common/notify/impl/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/common/util/*"/> + <accessrule ignoreifbetter="true" kind="nonaccessible" pattern="**/*"/> + </accessrules> + </classpathentry> + <classpathentry kind="lib" path="/Applications/eclipse/plugins/org.eclipse.emf.ecore_2.9.0.v20130528-0742.jar" sourcepath="/Applications/eclipse/plugins/org.eclipse.emf.ecore_2.9.0.v20130528-0742.jar"> + <accessrules> + <accessrule kind="accessible" pattern="org/eclipse/emf/ecore/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/ecore/impl/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/ecore/plugin/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/ecore/resource/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/ecore/resource/impl/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/ecore/util/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/ecore/xml/namespace/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/ecore/xml/namespace/impl/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/ecore/xml/namespace/util/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/ecore/xml/type/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/ecore/xml/type/impl/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/ecore/xml/type/internal/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/ecore/xml/type/util/*"/> + <accessrule ignoreifbetter="true" kind="nonaccessible" pattern="**/*"/> + </accessrules> + </classpathentry> + <classpathentry kind="lib" path="/Applications/eclipse/plugins/org.eclipse.xtext_2.4.2.v201306120542.jar" sourcepath="/Applications/eclipse/plugins/org.eclipse.xtext_2.4.2.v201306120542.jar"> + <accessrules> + <accessrule kind="accessible" pattern="org/eclipse/xtext/generator/*"/> + <accessrule kind="accessible" pattern="org/eclipse/xtext/resource/*"/> + <accessrule kind="accessible" pattern="org/eclipse/xtext/Grammar"/> + <accessrule kind="accessible" pattern="org/eclipse/xtext/impl/*"/> + <accessrule kind="accessible" pattern="org/eclipse/xtext/linking/lazy/*"/> + <accessrule ignoreifbetter="true" kind="nonaccessible" pattern="**/*"/> + </accessrules> + </classpathentry> + <classpathentry kind="lib" path="/Applications/eclipse/plugins/org.eclipse.emf.codegen.ecore_2.9.0.v20130610-0406.jar" sourcepath="/Applications/eclipse/plugins/org.eclipse.emf.codegen.ecore_2.9.0.v20130610-0406.jar"> + <accessrules> + <accessrule kind="accessible" pattern="org/eclipse/emf/codegen/ecore/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/codegen/ecore/generator/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/codegen/ecore/genmodel/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/codegen/ecore/genmodel/generator/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/codegen/ecore/genmodel/impl/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/codegen/ecore/genmodel/util/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/codegen/ecore/templates/edit/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/codegen/ecore/templates/editor/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/codegen/ecore/templates/model/*"/> + <accessrule kind="accessible" pattern="org/eclipse/emf/codegen/ecore/templates/model/tests/*"/> + <accessrule ignoreifbetter="true" kind="nonaccessible" pattern="**/*"/> + </accessrules> + </classpathentry> + <classpathentry kind="lib" path="/Applications/eclipse/plugins/org.franca.core.dsl_0.8.8.201306170812.jar" sourcepath="/Applications/eclipse/plugins/org.franca.core.dsl.source_0.8.8.201306170812.jar"> + <accessrules> + <accessrule kind="accessible" pattern="org/franca/core/dsl/*"/> + <accessrule kind="accessible" pattern="org/franca/core/dsl/services/*"/> + <accessrule kind="accessible" pattern="org/franca/core/dsl/parseTreeConstruction/*"/> + <accessrule kind="accessible" pattern="org/franca/core/dsl/parser/antlr/*"/> + <accessrule kind="accessible" pattern="org/franca/core/dsl/parser/antlr/internal/*"/> + <accessrule kind="accessible" pattern="org/franca/core/dsl/validation/*"/> + <accessrule kind="accessible" pattern="org/franca/core/dsl/scoping/*"/> + <accessrule kind="accessible" pattern="org/franca/core/dsl/formatting/*"/> + <accessrule ignoreifbetter="true" kind="nonaccessible" pattern="**/*"/> + </accessrules> + </classpathentry> + <classpathentry kind="lib" path="/Applications/eclipse/plugins/com.google.inject_3.0.0.v201203062045.jar"/> + <classpathentry kind="lib" path="/Applications/eclipse/plugins/javax.inject_1.0.0.v20091030.jar"/> + <classpathentry kind="lib" path="/Applications/eclipse/plugins/org.franca.deploymodel.dsl_0.8.8.201306170812.jar" sourcepath="/Applications/eclipse/plugins/org.franca.deploymodel.dsl.source_0.8.8.201306170812.jar"> + <accessrules> + <accessrule kind="accessible" pattern="org/franca/deploymodel/core/*"/> + <accessrule kind="accessible" pattern="org/franca/deploymodel/dsl/*"/> + <accessrule kind="accessible" pattern="org/franca/deploymodel/dsl/fDeploy/*"/> + <accessrule kind="accessible" pattern="org/franca/deploymodel/dsl/fDeploy/impl/*"/> + <accessrule kind="accessible" pattern="org/franca/deploymodel/dsl/fDeploy/util/*"/> + <accessrule kind="accessible" pattern="org/franca/deploymodel/dsl/formatting/*"/> + <accessrule kind="accessible" pattern="org/franca/deploymodel/dsl/generator/*"/> + <accessrule kind="accessible" pattern="org/franca/deploymodel/dsl/parseTreeConstruction/*"/> + <accessrule kind="accessible" pattern="org/franca/deploymodel/dsl/parser/antlr/*"/> + <accessrule kind="accessible" pattern="org/franca/deploymodel/dsl/parser/antlr/internal/*"/> + <accessrule kind="accessible" pattern="org/franca/deploymodel/dsl/scoping/*"/> + <accessrule kind="accessible" pattern="org/franca/deploymodel/dsl/services/*"/> + <accessrule kind="accessible" pattern="org/franca/deploymodel/dsl/validation/*"/> + <accessrule ignoreifbetter="true" kind="nonaccessible" pattern="**/*"/> + </accessrules> + </classpathentry> + <classpathentry kind="lib" path="/Applications/eclipse/plugins/org.eclipse.emf.ecore.xmi_2.9.0.v20130528-0742.jar"/> + <classpathentry kind="lib" path="/Applications/eclipse/plugins/org.apache.log4j_1.2.15.v201012070815.jar"/> + <classpathentry kind="lib" path="/Applications/eclipse/plugins/org.antlr.runtime_3.2.0.v201101311130.jar"/> + <classpathentry kind="lib" path="/Applications/eclipse/plugins/org.franca.core_0.8.8.201306170812.jar"/> + <classpathentry kind="lib" path="/Applications/eclipse/plugins/org.eclipse.xtext_2.4.3.v201308130914.jar" sourcepath="/Applications/eclipse/plugins/org.eclipse.xtext.source_2.4.3.v201308130914.jar"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/org.genivi.commonapi.core.cli/.gitignore b/org.genivi.commonapi.core.cli/.gitignore new file mode 100644 index 0000000..4282050 --- /dev/null +++ b/org.genivi.commonapi.core.cli/.gitignore @@ -0,0 +1,8 @@ +/.settings +/.DS_Store +/org.genivi.commonapi.dbus +/org.genivi.commonapi.core +/.settings/org.eclipse.ltk.core.refactoring.prefs +/workspaceitestra.xml +/build.xml +/temp diff --git a/org.genivi.commonapi.core.cli/.project b/org.genivi.commonapi.core.cli/.project new file mode 100644 index 0000000..e4092a5 --- /dev/null +++ b/org.genivi.commonapi.core.cli/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.genivi.commonapi.core.cli</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/org.genivi.commonapi.core.cli/.settings/org.eclipse.ltk.core.refactoring.prefs b/org.genivi.commonapi.core.cli/.settings/org.eclipse.ltk.core.refactoring.prefs new file mode 100644 index 0000000..b196c64 --- /dev/null +++ b/org.genivi.commonapi.core.cli/.settings/org.eclipse.ltk.core.refactoring.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff --git a/org.genivi.commonapi.core.cli/src/.gitignore b/org.genivi.commonapi.core.cli/src/.gitignore new file mode 100644 index 0000000..9bb88d3 --- /dev/null +++ b/org.genivi.commonapi.core.cli/src/.gitignore @@ -0,0 +1 @@ +/.DS_Store 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 new file mode 100644 index 0000000..5bfffb8 --- /dev/null +++ b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/CommandlineToolMain.java @@ -0,0 +1,476 @@ +/* + * 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 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.List; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.xtext.generator.JavaIoFileSystemAccess; +import org.eclipse.xtext.resource.XtextResourceSet; +import org.genivi.commonapi.core.generator.FrancaGenerator; +import org.genivi.commonapi.core.preferences.FPreferences; +import org.genivi.commonapi.core.preferences.PreferenceConstants; +import org.genivi.commonapi.dbus.generator.FrancaDBusGenerator; + +import com.google.inject.Injector; + +/** + * 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 + */ +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>(); + + public static void main(String[] args) { + + // Initialization with all options + File tempfolder = null; + boolean dbus = false; + String dest = createAbsolutPath("." + FILESEPARATOR + "src-gen" + FILESEPARATOR); + if (args.length < 1) { + System.err + .println("NO ARGUMENTS!\nPlease start this tool with:\njava -jar generator.jar [options] file [file...]" + + "\nValid Options are:\n-dbus -> to generate files with the FrancaDBUSGenerator\n" + + "-dest path/to/output/folder -> the generated files will be saved at this Location\n" + + "-pref path/to/header/file -> here you can set the text which will be placed as a comment " + + "on each generated file (for example your license"); + System.exit(-1); + } + // All given files were saved in this list with an absolute path + List<String> filelist = new ArrayList<String>(); + FPreferences pref = FPreferences.getInstance(); + /* + * Reading the options and the files given in the arguments and they + * will be saved in the predefined attributes + */ + 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(-1); + } + File file = new File(args[i + 1]); + if (!file.exists() || !file.isDirectory()) { + System.err.println("Please use only existing folders after -dest as arguments"); + System.exit(-1); + } + 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(-1); + } + 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(-1); + } + System.out.println("The following file was set as header:\n" + file.getAbsolutePath()); + try { + pref.setPreference(PreferenceConstants.USEPROJECTSETTINGS, Boolean.toString(true), + System.getProperty("user.dir")); + pref.setPreferences(PreferenceConstants.P_LICENSE, file, System.getProperty("user.dir")); + } catch (IOException e) { + e.printStackTrace(); + } + } else + filelist.add(createAbsolutPath(arg)); + } + System.out.println("The following path was set as the Outputfolder: \n" + dest); + 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 (String file : filelist) { + String nfile = handleArgs(file); + filelist.remove(file); + filelist.add(nfile); + } + + Injector injectorcore = new StandaloneSetup().createInjectorAndDoEMFRegistration(); + Injector injectordepl = new DeployStandaloneSetup().createInjectorAndDoEMFRegistration(); + URI uri = null; + // we initialize both generators with the Injectors + FrancaDBusGenerator dbusgenerator = injectorcore.getInstance(FrancaDBusGenerator.class); + FrancaGenerator generator = injectorcore.getInstance(FrancaGenerator.class); + // The resourceset comes from a Provider because we needed a special + // way to build it + XtextResourceSet rsset = injectorcore.getProvider(XtextResourceSet.class).get(); + // Here the resourceset gets the bindings for the fileendings and + // the resourcefactory which has to create resources with this + // ending + rsset.getResourceFactoryRegistry().getExtensionToFactoryMap() + .put("fdepl", injectordepl.getInstance(FrancaResourceFactory.class)); + final JavaIoFileSystemAccess fsa = injectorcore.getInstance(JavaIoFileSystemAccess.class); + fsa.setOutputPath(createAbsolutPath(dest)); + for (String file : filelist) { + uri = URI.createFileURI(file); + Resource rs = rsset.createResource(uri); + if (dbus) + // Attention!!! some Methods form 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 { + deleteDir(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 handleArgs(String path) { + files.add(path); + 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); + // System.out.println(uristr); + 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.contains("import")) { + if (line.contains("dbus/deployment/deployment.fdepl")) { + line = "import \"file:" + FILESEPARATORIMP + replaceAll(DBUS_DEPL, "\\", "/") + "\""; + if (!files.contains(DBUS_DEPL)) { + handleDeployment(false); + } + } else if (line.contains("core/deployment/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))) + handleArgs(createAbsolutPath(getImportPath(cp), path)); + } else if (line.contains(".fidl")) { + String fidlpath = createAbsolutPath(getImportPath(line), + path.substring(0, path.lastIndexOf(FILESEPARATOR))); + 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) { + ; + } + } + } + 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 deleteDir(File path) { + if (path != null && path.isDirectory()) { + for (File file : path.listFiles()) { + if (file.isDirectory()) + deleteDir(file); + file.delete(); + } + } + if (path != null) + path.delete(); + } + +} 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 new file mode 100644 index 0000000..c25e319 --- /dev/null +++ b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/DeployStandaloneSetup.java @@ -0,0 +1,40 @@ +/* + * 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 new file mode 100644 index 0000000..938e9aa --- /dev/null +++ b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/FrancaResourceFactory.java @@ -0,0 +1,48 @@ +/* + * 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 new file mode 100644 index 0000000..31ee70d --- /dev/null +++ b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/MyProviderXtext.java @@ -0,0 +1,29 @@ +/* + * 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 new file mode 100644 index 0000000..6c36151 --- /dev/null +++ b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/MyURIConverter.java @@ -0,0 +1,36 @@ +/* + * 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 new file mode 100644 index 0000000..cadb147 --- /dev/null +++ b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/StandaloneSetup.java @@ -0,0 +1,43 @@ +/* + * 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 new file mode 100644 index 0000000..8e50c94 --- /dev/null +++ b/org.genivi.commonapi.core.cli/src/org/genivi/commonapi/core/cli/TestModule.java @@ -0,0 +1,30 @@ +/* + * 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); + } + +} diff --git a/org.genivi.commonapi.core.ui/META-INF/MANIFEST.MF b/org.genivi.commonapi.core.ui/META-INF/MANIFEST.MF index a194aa7..379b6cd 100644 --- a/org.genivi.commonapi.core.ui/META-INF/MANIFEST.MF +++ b/org.genivi.commonapi.core.ui/META-INF/MANIFEST.MF @@ -14,7 +14,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.xtext.ui;bundle-version="2.4.0", org.eclipse.xtext.ui.ecore;bundle-version="2.4.0", com.google.inject;bundle-version="3.0.0", - org.genivi.commonapi.core;bundle-version="2.1.0" + org.genivi.commonapi.core;bundle-version="2.1.0", + org.eclipse.cdt.ui;bundle-version="5.5.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Import-Package: javax.inject, diff --git a/org.genivi.commonapi.core.ui/plugin.xml b/org.genivi.commonapi.core.ui/plugin.xml index 2862b3b..0e3731c 100644 --- a/org.genivi.commonapi.core.ui/plugin.xml +++ b/org.genivi.commonapi.core.ui/plugin.xml @@ -80,5 +80,18 @@ class="org.genivi.commonapi.core.ui.preferences.PreferenceInitializer"> </initializer> </extension> - + <extension + point="org.eclipse.ui.propertyPages"> + <page + class="org.genivi.commonapi.core.ui.preferences.CommonAPIPreferencePage" + id="org.genivi.commonapi.core.ui.preferences.property.CommonAPIPreferencePage" + name="CommonAPI" + objectClass="org.eclipse.core.resources.IProject">> + <!--<enabledWhen> + <instanceof + value="org.eclipse.core.resources.IProject"> + </instanceof> + </enabledWhen>--> + </page> + </extension> </plugin> diff --git a/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/handler/GenerationCommand.java b/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/handler/GenerationCommand.java index 901136d..2322706 100644 --- a/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/handler/GenerationCommand.java +++ b/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/handler/GenerationCommand.java @@ -1,9 +1,11 @@ -/* 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/. */ +/* + * 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.ui.handler; import java.util.Iterator; @@ -15,6 +17,7 @@ import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -37,8 +40,11 @@ import org.eclipse.xtext.resource.XtextResource; import org.eclipse.xtext.ui.editor.XtextEditor; import org.eclipse.xtext.ui.resource.IResourceSetProvider; import org.eclipse.xtext.util.concurrent.IUnitOfWork; +import org.genivi.commonapi.core.preferences.FPreferences; import org.genivi.commonapi.core.preferences.PreferenceConstants; import org.genivi.commonapi.core.ui.CommonApiUiPlugin; +import org.genivi.commonapi.core.ui.preferences.CommonAPIPreferencePage; +import org.genivi.commonapi.core.ui.preferences.FieldEditorOverlayPage; import com.google.inject.Provider; @@ -64,35 +70,35 @@ public class GenerationCommand extends AbstractHandler { if (activeEditor instanceof XtextEditor) executeGeneratorForXtextEditor((XtextEditor) activeEditor); else - throw new ExecutionException("Cannot handle ExecutionEvent: " - + event); + throw new ExecutionException("Cannot handle ExecutionEvent: " + event); } return null; } - private void executeGeneratorForSelection( - final IStructuredSelection structuredSelection) { - final EclipseResourceFileSystemAccess2 fileSystemAccess = createFileSystemAccess(); - - for (Iterator<?> iterator = structuredSelection.iterator(); iterator - .hasNext();) { + private void executeGeneratorForSelection(final IStructuredSelection structuredSelection) { + IProject project = null; + for (Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) { final Object selectiobObject = iterator.next(); if (selectiobObject instanceof IFile) { final IFile file = (IFile) selectiobObject; - final URI uri = URI.createPlatformResourceURI(file - .getFullPath().toString(), true); - final ResourceSet rs = resourceSetProvider.get(file - .getProject()); + final URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true); + final ResourceSet rs = resourceSetProvider.get(file.getProject()); final Resource r = rs.getResource(uri, true); - fileSystemAccess.setProject(file.getProject()); + project = file.getProject(); + FieldEditorOverlayPage page = new CommonAPIPreferencePage(); + page.setElement(project); + page.createControl(null); + FPreferences.init(page.getPreferenceStore(), CommonApiUiPlugin.getDefault().getPreferenceStore(), + project); + final EclipseResourceFileSystemAccess2 fileSystemAccess = createFileSystemAccess(project); + fileSystemAccess.setProject(project); Job job = new Job("validation and generation") { @Override protected IStatus run(IProgressMonitor monitor) { - monitor.beginTask("handle " + file.getName(), - IProgressMonitor.UNKNOWN); + monitor.beginTask("handle " + file.getName(), IProgressMonitor.UNKNOWN); monitor.subTask("validation"); if (r.getErrors().size() == 0) { monitor.subTask("Generate"); @@ -106,70 +112,62 @@ public class GenerationCommand extends AbstractHandler { }; job.schedule(); - } } } private void executeGeneratorForXtextEditor(final XtextEditor xtextEditor) { - final Object fileObject = xtextEditor.getEditorInput().getAdapter( - IFile.class); - + final Object fileObject = xtextEditor.getEditorInput().getAdapter(IFile.class); if (fileObject instanceof IFile) { - final EclipseResourceFileSystemAccess2 fileSystemAccess = createFileSystemAccess(); - fileSystemAccess.setProject(((IResource) fileObject).getProject()); + IProject project = ((IResource) fileObject).getProject(); + final EclipseResourceFileSystemAccess2 fileSystemAccess = createFileSystemAccess(project); + fileSystemAccess.setProject(project); + + xtextEditor.getDocument().readOnly(new IUnitOfWork<Boolean, XtextResource>() { + @Override + public Boolean exec(XtextResource xtextResource) throws Exception { + final XtextResource xtextRes = xtextResource; + Job job = new Job("validation and generation") { - xtextEditor.getDocument().readOnly( - new IUnitOfWork<Boolean, XtextResource>() { @Override - public Boolean exec(XtextResource xtextResource) - throws Exception { - final XtextResource xtextRes = xtextResource; - Job job = new Job("validation and generation") { - - @Override - protected IStatus run(IProgressMonitor monitor) { - try { - - monitor.beginTask( - "handle " - + ((IResource) fileObject) - .getName(), - IProgressMonitor.UNKNOWN); - TimeUnit.SECONDS.sleep(1); - monitor.subTask("validation"); - if (xtextRes.getErrors().size() == 0) { - monitor.subTask("Generate"); - francaGenerator.doGenerate( - xtextRes, fileSystemAccess); - return Status.OK_STATUS; - } else { - return Status.CANCEL_STATUS; - } - } catch (InterruptedException ie) { - return Status.CANCEL_STATUS; - } + protected IStatus run(IProgressMonitor monitor) { + try { + + monitor.beginTask("handle " + ((IResource) fileObject).getName(), + IProgressMonitor.UNKNOWN); + TimeUnit.SECONDS.sleep(1); + monitor.subTask("validation"); + if (xtextRes.getErrors().size() == 0) { + monitor.subTask("Generate"); + francaGenerator.doGenerate(xtextRes, fileSystemAccess); + return Status.OK_STATUS; + } else { + return Status.CANCEL_STATUS; } - - }; - job.schedule(); - return Boolean.TRUE; + } catch (InterruptedException ie) { + return Status.CANCEL_STATUS; + } } - }); + + }; + job.schedule(); + return Boolean.TRUE; + } + }); } } - private EclipseResourceFileSystemAccess2 createFileSystemAccess() { - - IPreferenceStore store = CommonApiUiPlugin.getDefault() - .getPreferenceStore(); + private EclipseResourceFileSystemAccess2 createFileSystemAccess(IProject project) { + IPreferenceStore store = CommonApiUiPlugin.getDefault().getPreferenceStore(); String outputDir = store.getString(PreferenceConstants.P_OUTPUT); - + if (FPreferences.getInstance().getPreference(PreferenceConstants.P_OUTPUT, null, + project.getFullPath().toPortableString()) != null) + outputDir = FPreferences.getInstance().getPreference(PreferenceConstants.P_OUTPUT, null, + project.getFullPath().toPortableString()); final EclipseResourceFileSystemAccess2 fsa = fileAccessProvider.get(); fsa.setOutputPath(outputDir); - fsa.getOutputConfigurations().get(IFileSystemAccess.DEFAULT_OUTPUT) - .setCreateOutputDirectory(true); + fsa.getOutputConfigurations().get(IFileSystemAccess.DEFAULT_OUTPUT).setCreateOutputDirectory(true); fsa.setMonitor(new NullProgressMonitor()); return fsa; diff --git a/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/CommonAPIPreferencePage.java b/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/CommonAPIPreferencePage.java index 64421b0..b738fe5 100644 --- a/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/CommonAPIPreferencePage.java +++ b/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/CommonAPIPreferencePage.java @@ -1,55 +1,77 @@ +/* + * 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.ui.preferences; -import org.eclipse.jface.preference.*; -import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.core.runtime.preferences.DefaultScope; +import org.eclipse.jface.preference.FieldEditor; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.StringFieldEditor; import org.eclipse.ui.IWorkbench; -import org.genivi.commonapi.core.ui.CommonApiUiPlugin; +import org.eclipse.ui.IWorkbenchPreferencePage; import org.genivi.commonapi.core.preferences.PreferenceConstants; +import org.genivi.commonapi.core.ui.CommonApiUiPlugin; /** - * This class represents a preference page that - * is contributed to the Preferences dialog. By - * subclassing <samp>FieldEditorPreferencePage</samp>, we - * can use the field support built into JFace that allows - * us to create a page that is small and knows how to - * save, restore and apply itself. + * This class represents a preference page that is contributed to the + * Preferences dialog. By subclassing <samp>FieldEditorOverlayPage</samp>, we + * can use the field support built into JFace that allows us to create a page + * that is small and knows how to save, restore and apply itself. * <p> - * This page is used to modify preferences only. They - * are stored in the preference store that belongs to - * the main plug-in class. That way, preferences can - * be accessed directly via the preference store. + * This page is used to modify preferences only. They are stored in the + * preference store that belongs to the main plug-in class. That way, + * preferences can be accessed directly via the preference store. */ -public class CommonAPIPreferencePage - extends FieldEditorPreferencePage - implements IWorkbenchPreferencePage { - - public CommonAPIPreferencePage() { - super(GRID); - setDescription("Preferences for CommonAPI"); - } - - /** - * Creates the field editors. Field editors are abstractions of - * the common GUI blocks needed to manipulate various types - * of preferences. Each field editor knows how to save and - * restore itself. - */ - public void createFieldEditors() { - addField( - new StringFieldEditor(PreferenceConstants.P_LICENSE, "The header to insert for all generated files", 60, getFieldEditorParent())); - addField( - new StringFieldEditor(PreferenceConstants.P_OUTPUT, "Output directory inside project", 30, getFieldEditorParent())); - } - - - /* (non-Javadoc) - * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) - */ - public void init(IWorkbench workbench) { - //PreferenceInitializer init = new PreferenceInitializer(); - //init.initializeDefaultPreferences(); - setPreferenceStore(CommonApiUiPlugin.getDefault().getPreferenceStore()); - } - +public class CommonAPIPreferencePage extends FieldEditorOverlayPage implements IWorkbenchPreferencePage { + + private FieldEditor lizense = null; + private FieldEditor output = null; + + public CommonAPIPreferencePage() { + super(GRID); + setDescription("Preferences for CommonAPI"); + } + + /** + * Creates the field editors. Field editors are abstractions of the common + * GUI blocks needed to manipulate various types of preferences. Each field + * editor knows how to save and restore itself. + */ + public void createFieldEditors() { + lizense = new MultiLineTextField(PreferenceConstants.P_LICENSE, "The header to insert for all generated files", + 60, getFieldEditorParent()); + addField(lizense); + output = new StringFieldEditor(PreferenceConstants.P_OUTPUT, "Output directory inside project", 30, + getFieldEditorParent()); + addField(output); + } + + @Override + protected void performDefaults() { + DefaultScope.INSTANCE.getNode(PreferenceConstants.SCOPE).put(PreferenceConstants.P_OUTPUT, + PreferenceConstants.DEFAULT_OUTPUT); + super.performDefaults(); + } + + public void init(IWorkbench workbench) { + if (!isPropertyPage()) + setPreferenceStore(CommonApiUiPlugin.getDefault().getPreferenceStore()); + } + + @Override + protected String getPageId() { + return "org.genivi.commonapi.core.ui.preferences.CommonAPIPreferencePage"; + } + + @Override + protected IPreferenceStore doGetPreferenceStore() { + return CommonApiUiPlugin.getDefault().getPreferenceStore(); + } + }
\ No newline at end of file diff --git a/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/FieldEditorOverlayPage.java b/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/FieldEditorOverlayPage.java new file mode 100755 index 0000000..6c706bd --- /dev/null +++ b/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/FieldEditorOverlayPage.java @@ -0,0 +1,356 @@ +/* + * 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.ui.preferences; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.jface.preference.FieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.preference.IPreferenceNode; +import org.eclipse.jface.preference.IPreferencePage; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceDialog; +import org.eclipse.jface.preference.PreferenceManager; +import org.eclipse.jface.preference.PreferenceNode; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IWorkbenchPropertyPage; +import org.genivi.commonapi.core.preferences.FPreferences; +import org.genivi.commonapi.core.preferences.PreferenceConstants; + +public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage implements IWorkbenchPropertyPage { + + /*** + * Name of resource property for the selection of workbench or project + * settings + ***/ + // public static final String USEPROJECTSETTINGS = "useProjectSettings"; //$NON-NLS-1$ + + private static final String FALSE = "false"; //$NON-NLS-1$ + private static final String TRUE = "true"; //$NON-NLS-1$ + + // Stores all created field editors + private List<FieldEditor> editors = new ArrayList<FieldEditor>(); + + // Stores owning element of properties + private IAdaptable element; + + // Additional buttons for property pages + private Button useWorkspaceSettingsButton, useProjectSettingsButton, configureButton; + + // Overlay preference store for property pages + private IPreferenceStore overlayStore; + + // The image descriptor of this pages title image + private ImageDescriptor image; + + // Cache for page id + private String pageId; + + /** + * Constructor + * @param style + * - layout style + */ + public FieldEditorOverlayPage(int style) { + super(style); + } + + /** + * Constructor + * @param title + * - title string + * @param style + * - layout style + */ + public FieldEditorOverlayPage(String title, int style) { + super(title, style); + } + + /** + * Constructor + * @param title + * - title string + * @param image + * - title image + * @param style + * - layout style + */ + public FieldEditorOverlayPage(String title, ImageDescriptor image, int style) { + super(title, image, style); + this.image = image; + } + + /** + * Returns the id of the current preference page as defined in plugin.xml + * Subclasses must implement. + * @return - the qualifier + */ + protected abstract String getPageId(); + + /** + * Receives the object that owns the properties shown in this property page. + * @see org.eclipse.ui.IWorkbenchPropertyPage#setElement(org.eclipse.core.runtime.IAdaptable) + */ + public void setElement(IAdaptable element) { + this.element = element; + } + + /** + * Delivers the object that owns the properties shown in this property page. + * @see org.eclipse.ui.IWorkbenchPropertyPage#getElement() + */ + public IAdaptable getElement() { + return element; + } + + /** + * Returns true if this instance represents a property page + * @return - true for property pages, false for preference pages + */ + public boolean isPropertyPage() { + return getElement() != null; + } + + /** + * We override the addField method. This allows us to store each field + * editor added by subclasses in a list for later processing. + * @see org.eclipse.jface.preference.FieldEditorPreferencePage#addField(org.eclipse.jface.preference.FieldEditor) + */ + protected void addField(FieldEditor editor) { + editors.add(editor); + super.addField(editor); + } + + /** + * We override the createControl method. In case of property pages we create + * a new PropertyStore as local preference store. After all control have + * been create, we enable/disable these controls. + * @see org.eclipse.jface.preference.PreferencePage#createControl() + */ + public void createControl(Composite parent) { + // Special treatment for property pages + if (isPropertyPage()) { + // Cache the page id + pageId = getPageId(); + // Create an overlay preference store and fill it with properties + try { + overlayStore = new PropertyStore((IResource) getElement(), super.getPreferenceStore(), pageId); + } catch (IOException e) { + e.printStackTrace(); + } + // Set overlay store as current preference store + setPreferenceStore(overlayStore); + } + if (parent != null) { + super.createControl(parent); + // Update state of all subclass controls + if (isPropertyPage()) + updateFieldEditors(); + } + } + + /** + * We override the createContents method. In case of property pages we + * insert two radio buttons at the top of the page. + * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) + */ + protected Control createContents(Composite parent) { + if (isPropertyPage()) { + createSelectionGroup(parent); + updateFieldEditors(); + } + return super.createContents(parent); + } + + /** + * Creates and initializes a selection group with two choice buttons and one + * push button. + * @param parent + * - the parent composite + */ + private void createSelectionGroup(Composite parent) { + Composite comp = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + comp.setLayout(layout); + comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + Composite radioGroup = new Composite(comp, SWT.NONE); + radioGroup.setLayout(new GridLayout()); + radioGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + useWorkspaceSettingsButton = createRadioButton(radioGroup, + Messages.getString("OverlayPage.Use_Workspace_Settings")); //$NON-NLS-1$ + useProjectSettingsButton = createRadioButton(radioGroup, Messages.getString("OverlayPage.Use_Project_Settings")); //$NON-NLS-1$ + configureButton = new Button(comp, SWT.PUSH); + configureButton.setText(Messages.getString("OverlayPage.Configure_Workspace_Settings")); //$NON-NLS-1$ + configureButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + configureWorkspaceSettings(); + } + }); + // Set workspace/project radio buttons + try { + String use = ((IResource) getElement()).getPersistentProperty(new QualifiedName(pageId, + PreferenceConstants.USEPROJECTSETTINGS)); + if (TRUE.equals(use)) { + useProjectSettingsButton.setSelection(true); + configureButton.setEnabled(false); + } else + useWorkspaceSettingsButton.setSelection(true); + } catch (CoreException e) { + useWorkspaceSettingsButton.setSelection(true); + } + } + + /** + * Convenience method creating a radio button + * @param parent + * - the parent composite + * @param label + * - the button label + * @return - the new button + */ + private Button createRadioButton(Composite parent, String label) { + final Button button = new Button(parent, SWT.RADIO); + button.setText(label); + button.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + configureButton.setEnabled(button == useWorkspaceSettingsButton); + updateFieldEditors(); + } + }); + return button; + } + + /** + * Returns in case of property pages the overlay store, in case of + * preference pages the standard preference store + * @see org.eclipse.jface.preference.PreferencePage#getPreferenceStore() + */ + public IPreferenceStore getPreferenceStore() { + if (isPropertyPage()) + return overlayStore; + return super.getPreferenceStore(); + } + + /* + * Enables or disables the field editors and buttons of this page + */ + private void updateFieldEditors() { + // We iterate through all field editors + boolean enabled = useProjectSettingsButton.getSelection(); + updateFieldEditors(enabled); + } + + /** + * Enables or disables the field editors and buttons of this page Subclasses + * may override. + * @param enabled + * - true if enabled + */ + protected void updateFieldEditors(boolean enabled) { + Composite parent = getFieldEditorParent(); + Iterator<FieldEditor> it = editors.iterator(); + while (it.hasNext()) { + FieldEditor editor = it.next(); + editor.setEnabled(enabled, parent); + } + } + + /** + * We override the performOk method. In case of property pages we copy the + * values in the overlay store into the property values of the selected + * project. We also save the state of the radio buttons. + * @see org.eclipse.jface.preference.IPreferencePage#performOk() + */ + public boolean performOk() { + boolean result = super.performOk(); + if (result && isPropertyPage()) { + // Save state of radio buttons in project properties + IResource resource = (IResource) getElement(); + try { + String value = (useProjectSettingsButton.getSelection()) ? TRUE : FALSE; + resource.setPersistentProperty(new QualifiedName(pageId, PreferenceConstants.USEPROJECTSETTINGS), value); + } catch (CoreException e) { + } + } + return result; + } + + /** + * We override the performDefaults method. In case of property pages we + * switch back to the workspace settings and disable the field editors. + * @see org.eclipse.jface.preference.PreferencePage#performDefaults() + */ + protected void performDefaults() { + if (isPropertyPage()) { + useWorkspaceSettingsButton.setSelection(true); + useProjectSettingsButton.setSelection(false); + configureButton.setEnabled(true); + updateFieldEditors(); + } + super.performDefaults(); + } + + /** + * Creates a new preferences page and opens it + */ + protected void configureWorkspaceSettings() { + try { + // create a new instance of the current class + IPreferencePage page = (IPreferencePage) this.getClass().newInstance(); + page.setTitle(getTitle()); + page.setImageDescriptor(image); + // and show it + showPreferencePage(pageId, page); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + + /** + * Show a single preference pages + * @param id + * - the preference page identification + * @param page + * - the preference page + */ + protected void showPreferencePage(String id, IPreferencePage page) { + final IPreferenceNode targetNode = new PreferenceNode(id, page); + PreferenceManager manager = new PreferenceManager(); + manager.addToRoot(targetNode); + final PreferenceDialog dialog = new PreferenceDialog(getControl().getShell(), manager); + BusyIndicator.showWhile(getControl().getDisplay(), new Runnable() { + public void run() { + dialog.create(); + dialog.setMessage(targetNode.getLabelText()); + dialog.open(); + } + }); + } + +} diff --git a/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/Messages.java b/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/Messages.java new file mode 100755 index 0000000..a046b7b --- /dev/null +++ b/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/Messages.java @@ -0,0 +1,43 @@ +/* + * 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.ui.preferences; + +import java.util.ResourceBundle; + +public class Messages { + + private final static String RESOURCE_BUNDLE = "org.genivi.commonapi.core.ui.preferences.Messages";//$NON-NLS-1$ + + private static ResourceBundle fgResourceBundle = null; + + private static boolean notRead = true; + + public Messages() { + } + + public static ResourceBundle getResourceBundle() { + if (notRead) { + notRead = false; + try { + fgResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE); + } catch (Exception e) { + } + } + + return fgResourceBundle; + } + + public static String getString(String key) { + try { + return getResourceBundle().getString(key); + } catch (Exception e) { + return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$ + } + } +} diff --git a/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/Messages.properties b/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/Messages.properties new file mode 100755 index 0000000..6f24a50 --- /dev/null +++ b/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/Messages.properties @@ -0,0 +1,5 @@ +OverlayPage.Use_Workspace_Settings=Use workspace settings +OverlayPage.Use_Project_Settings=Use project settings +OverlayPage.Configure_Workspace_Settings=Configure Workspace Settings ... +PropertyStore.Cannot_write_resource_property=Cannot write resource property +PropertyStore.Cannot_read_resource_property=Cannot read resource property
\ No newline at end of file diff --git a/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/MultiLineTextField.java b/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/MultiLineTextField.java new file mode 100644 index 0000000..629e7bd --- /dev/null +++ b/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/MultiLineTextField.java @@ -0,0 +1,37 @@ +/* + * 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.ui.preferences; + +import org.eclipse.cdt.ui.newui.MultiLineTextFieldEditor; +import org.eclipse.swt.widgets.Composite; + +public class MultiLineTextField extends MultiLineTextFieldEditor { + + public MultiLineTextField() { + super(); + } + + public MultiLineTextField(String name, String labelText, Composite parent) { + super(name, labelText, parent); + } + + public MultiLineTextField(String name, String labelText, int width, Composite parent) { + super(name, labelText, width, parent); + } + + public MultiLineTextField(String name, String labelText, int width, int strategy, Composite parent) { + super(name, labelText, width, strategy, parent); + } + + @Override + public void setEnabled(boolean enabled, Composite parent) { + // super.setEnabled(enabled, parent); + getTextControl(parent).setEnabled(enabled); + } +}
\ No newline at end of file diff --git a/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/PreferenceInitializer.java b/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/PreferenceInitializer.java index 2eb7c3f..550aee2 100644 --- a/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/PreferenceInitializer.java +++ b/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/PreferenceInitializer.java @@ -1,7 +1,16 @@ +/* + * 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.ui.preferences; import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; import org.eclipse.jface.preference.IPreferenceStore; + import org.genivi.commonapi.core.preferences.PreferenceConstants; import org.genivi.commonapi.core.ui.CommonApiUiPlugin; @@ -10,19 +19,16 @@ import org.genivi.commonapi.core.ui.CommonApiUiPlugin; */ public class PreferenceInitializer extends AbstractPreferenceInitializer { - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences() - */ - public void initializeDefaultPreferences() { - IPreferenceStore store = CommonApiUiPlugin.getDefault().getPreferenceStore(); - store.setDefault(PreferenceConstants.P_LICENSE, - "* This Source Code Form is subject to the terms of the Mozilla Public\n" + - "* License, v. 2.0. If a copy of the MPL was not distributed with this\n" + - "* file, You can obtain one at http://mozilla.org/MPL/2.0/."); - - store.setDefault(PreferenceConstants.P_OUTPUT, "src-gen"); - } + /* + * (non-Javadoc) + * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer# + * initializeDefaultPreferences() + */ + public void initializeDefaultPreferences() { + IPreferenceStore store = CommonApiUiPlugin.getDefault().getPreferenceStore(); + store.setDefault(PreferenceConstants.USEPROJECTSETTINGS, true); + store.setDefault(PreferenceConstants.P_LICENSE, ""); + store.setDefault(PreferenceConstants.P_OUTPUT, PreferenceConstants.DEFAULT_OUTPUT); + } } diff --git a/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/PropertyStore.java b/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/PropertyStore.java new file mode 100755 index 0000000..4b1c1b6 --- /dev/null +++ b/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/preferences/PropertyStore.java @@ -0,0 +1,291 @@ +/* + * 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.ui.preferences; + +import java.io.IOException; +import java.io.OutputStream; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceStore; +import org.genivi.commonapi.core.preferences.FPreferences; +import org.genivi.commonapi.core.preferences.PreferenceConstants; + +public class PropertyStore extends PreferenceStore { + + private IResource resource; + private IPreferenceStore workbenchStore; + private String pageId; + private boolean inserting = false; + + public PropertyStore(IResource resource, IPreferenceStore workbenchStore, String pageId) throws IOException { + + this.resource = resource; + this.workbenchStore = workbenchStore; + this.pageId = pageId; + FPreferences pref = FPreferences.getInstance(); + try { + pref.setPreference(PreferenceConstants.P_LICENSE, getProperty(PreferenceConstants.P_LICENSE), resource + .getFullPath().toPortableString()); + pref.setPreference(PreferenceConstants.P_OUTPUT, getProperty(PreferenceConstants.P_OUTPUT), resource + .getFullPath().toPortableString()); + pref.setPreference(PreferenceConstants.USEPROJECTSETTINGS, + getProperty(PreferenceConstants.USEPROJECTSETTINGS), resource.getFullPath().toPortableString()); + } catch (CoreException e) { + throw new IOException(Messages.getString("PropertyStore.Cannot_read_resource_property") + + PreferenceConstants.P_LICENSE); + } + } + + /*** Write modified values back to properties ***/ + + /* + * (non-Javadoc) + * @see org.eclipse.jface.preference.IPersistentPreferenceStore#save() + */ + public void save() throws IOException { + try { + if (getProperty(PreferenceConstants.USEPROJECTSETTINGS).equals(Boolean.TRUE.toString())) + writeProperties(); + } catch (CoreException e) { + throw new IOException(Messages.getString("PropertyStore.Cannot_read_resource_property") + + PreferenceConstants.USEPROJECTSETTINGS); //$NON-NLS-1$ + } + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.jface.preference.PreferenceStore#save(java.io.OutputStream, + * java.lang.String) + */ + public void save(OutputStream out, String header) throws IOException { + writeProperties(); + } + + /** + * Writes modified preferences into resource properties. + */ + private void writeProperties() throws IOException { + String[] preferences = super.preferenceNames(); + for (int i = 0; i < preferences.length; i++) { + String name = preferences[i]; + try { + setProperty(name, getString(name)); + } catch (CoreException e) { + throw new IOException(Messages.getString("PropertyStore.Cannot_write_resource_property") + name); //$NON-NLS-1$ + } + } + } + + /** + * Convenience method to set a property + * @param name + * - the preference name + * @param value + * - the property value or null to delete the property + * @throws CoreException + */ + private void setProperty(String name, String value) throws CoreException { + resource.setPersistentProperty(new QualifiedName(pageId, name), value); + } + + /*** Get default values (Delegate to workbench store) ***/ + + /* + * (non-Javadoc) + * @see + * org.eclipse.jface.preference.IPreferenceStore#getDefaultBoolean(java. + * lang.String) + */ + public boolean getDefaultBoolean(String name) { + return workbenchStore.getDefaultBoolean(name); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.jface.preference.IPreferenceStore#getDefaultDouble(java.lang + * .String) + */ + public double getDefaultDouble(String name) { + return workbenchStore.getDefaultDouble(name); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.jface.preference.IPreferenceStore#getDefaultFloat(java.lang + * .String) + */ + public float getDefaultFloat(String name) { + return workbenchStore.getDefaultFloat(name); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.jface.preference.IPreferenceStore#getDefaultInt(java.lang + * .String) + */ + public int getDefaultInt(String name) { + return workbenchStore.getDefaultInt(name); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.jface.preference.IPreferenceStore#getDefaultLong(java.lang + * .String) + */ + public long getDefaultLong(String name) { + return workbenchStore.getDefaultLong(name); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.jface.preference.IPreferenceStore#getDefaultString(java.lang + * .String) + */ + public String getDefaultString(String name) { + return workbenchStore.getDefaultString(name); + } + + /*** Get property values ***/ + + /* + * (non-Javadoc) + * @see + * org.eclipse.jface.preference.IPreferenceStore#getBoolean(java.lang.String + * ) + */ + public boolean getBoolean(String name) { + insertValue(name); + return super.getBoolean(name); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.jface.preference.IPreferenceStore#getDouble(java.lang.String) + */ + public double getDouble(String name) { + insertValue(name); + return super.getDouble(name); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.jface.preference.IPreferenceStore#getFloat(java.lang.String) + */ + public float getFloat(String name) { + insertValue(name); + return super.getFloat(name); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.jface.preference.IPreferenceStore#getInt(java.lang.String) + */ + public int getInt(String name) { + insertValue(name); + return super.getInt(name); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.jface.preference.IPreferenceStore#getLong(java.lang.String) + */ + public long getLong(String name) { + insertValue(name); + return super.getLong(name); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.jface.preference.IPreferenceStore#getString(java.lang.String) + */ + public String getString(String name) { + insertValue(name); + return super.getString(name); + } + + /** + * @param name + */ + private synchronized void insertValue(String name) { + if (inserting) + return; + if (super.contains(name)) + return; + inserting = true; + String prop = null; + try { + prop = getProperty(name); + } catch (CoreException e) { + } + if (prop == null) + prop = workbenchStore.getString(name); + if (prop != null) + setValue(name, prop); + inserting = false; + } + + /** + * Convenience method to fetch a property + * @param name + * - the preference name + * @return - the property value + * @throws CoreException + */ + private String getProperty(String name) throws CoreException { + return resource.getPersistentProperty(new QualifiedName(pageId, name)); + } + + /*** Misc ***/ + + /* + * (non-Javadoc) + * @see + * org.eclipse.jface.preference.IPreferenceStore#contains(java.lang.String) + */ + public boolean contains(String name) { + return workbenchStore.contains(name); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.jface.preference.IPreferenceStore#setToDefault(java.lang. + * String) + */ + public void setToDefault(String name) { + setValue(name, getDefaultString(name)); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.jface.preference.IPreferenceStore#isDefault(java.lang.String) + */ + public boolean isDefault(String name) { + String defaultValue = getDefaultString(name); + if (defaultValue == null) + return false; + return defaultValue.equals(getString(name)); + } + +} diff --git a/org.genivi.commonapi.core/.classpath b/org.genivi.commonapi.core/.classpath index e24ea18..8912ab2 100644 --- a/org.genivi.commonapi.core/.classpath +++ b/org.genivi.commonapi.core/.classpath @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> + <classpathentry kind="src" path="deployment"/> <classpathentry kind="src" path="src-gen"/> <classpathentry kind="src" path="xtend-gen"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> diff --git a/org.genivi.commonapi.core/.settings/.gitignore b/org.genivi.commonapi.core/.settings/.gitignore new file mode 100644 index 0000000..3b1537c --- /dev/null +++ b/org.genivi.commonapi.core/.settings/.gitignore @@ -0,0 +1 @@ +/org.eclipse.jdt.core.prefs diff --git a/org.genivi.commonapi.core/META-INF/MANIFEST.MF b/org.genivi.commonapi.core/META-INF/MANIFEST.MF index 4322ad1..eee0d27 100644 --- a/org.genivi.commonapi.core/META-INF/MANIFEST.MF +++ b/org.genivi.commonapi.core/META-INF/MANIFEST.MF @@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.core.resources;bundle-version="3.8.0", org.eclipse.xtext.generator;bundle-version="2.4.0", org.eclipse.xtext.util;bundle-version="2.4.0", org.franca.core.dsl;bundle-version="0.8.8", - org.franca.deploymodel.dsl;bundle-version="0.8.8" + org.franca.deploymodel.dsl;bundle-version="0.8.8", + org.eclipse.jface Import-Package: javax.inject;version="1.0.0" Bundle-RequiredExecutionEnvironment: J2SE-1.5 Export-Package: org.genivi.commonapi.core.deployment, diff --git a/org.genivi.commonapi.core/deployment/deployment.fdepl b/org.genivi.commonapi.core/deployment/CommonAPI_deployment.fdepl index a587bee..a587bee 100644 --- a/org.genivi.commonapi.core/deployment/deployment.fdepl +++ b/org.genivi.commonapi.core/deployment/CommonAPI_deployment.fdepl diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceGenerator.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceGenerator.xtend index 7c1fd99..4f7840b 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceGenerator.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceGenerator.xtend @@ -26,7 +26,7 @@ class FInterfaceGenerator { } def private generateHeader(FInterface fInterface, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' - «generateCommonApiLicenseHeader» + «generateCommonApiLicenseHeader(fInterface)» #ifndef «fInterface.defineName»_H_ #define «fInterface.defineName»_H_ @@ -100,7 +100,7 @@ class FInterfaceGenerator { def private generateSource(FInterface fInterface) ''' - «generateCommonApiLicenseHeader» + «generateCommonApiLicenseHeader(fInterface)» #include "«fInterface.headerFile»" «fInterface.model.generateNamespaceBeginDeclaration» diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceProxyGenerator.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceProxyGenerator.xtend index 07381ea..be7e54c 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceProxyGenerator.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceProxyGenerator.xtend @@ -27,7 +27,7 @@ class FInterfaceProxyGenerator { } def private generateProxyBaseHeader(FInterface fInterface, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' - «generateCommonApiLicenseHeader» + «generateCommonApiLicenseHeader(fInterface)» #ifndef «fInterface.defineName»_PROXY_BASE_H_ #define «fInterface.defineName»_PROXY_BASE_H_ @@ -110,7 +110,7 @@ class FInterfaceProxyGenerator { ''' def private generateProxyHeader(FInterface fInterface) ''' - «generateCommonApiLicenseHeader» + «generateCommonApiLicenseHeader(fInterface)» #ifndef «fInterface.defineName»_PROXY_H_ #define «fInterface.defineName»_PROXY_H_ diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceStubGenerator.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceStubGenerator.xtend index 84a35c9..71d5ea3 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceStubGenerator.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceStubGenerator.xtend @@ -23,7 +23,7 @@ class FInterfaceStubGenerator { } def private generateStubHeader(FInterface fInterface) ''' - «generateCommonApiLicenseHeader» + «generateCommonApiLicenseHeader(fInterface)» #ifndef «fInterface.defineName»_STUB_H_ #define «fInterface.defineName»_STUB_H_ @@ -172,7 +172,7 @@ class FInterfaceStubGenerator { ''' def private generateStubDefaultHeader(FInterface fInterface) ''' - «generateCommonApiLicenseHeader» + «generateCommonApiLicenseHeader(fInterface)» #ifndef «fInterface.defineName»_STUB_DEFAULT_H_ #define «fInterface.defineName»_STUB_DEFAULT_H_ @@ -257,7 +257,7 @@ class FInterfaceStubGenerator { ''' def private generateStubDefaultSource(FInterface fInterface) ''' - «generateCommonApiLicenseHeader» + «generateCommonApiLicenseHeader(fInterface)» #include <«fInterface.stubDefaultHeaderPath»> «fInterface.model.generateNamespaceBeginDeclaration» diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCollectionGenerator.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCollectionGenerator.xtend index b699840..4040f44 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCollectionGenerator.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCollectionGenerator.xtend @@ -27,7 +27,7 @@ class FTypeCollectionGenerator { } def private generateHeader(FTypeCollection fTypeCollection, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' - «generateCommonApiLicenseHeader» + «generateCommonApiLicenseHeader(fTypeCollection)» #ifndef «fTypeCollection.defineName»_H_ #define «fTypeCollection.defineName»_H_ @@ -91,7 +91,7 @@ class FTypeCollectionGenerator { def private generateSource(FTypeCollection fTypeCollection) ''' - «generateCommonApiLicenseHeader» + «generateCommonApiLicenseHeader(fTypeCollection)» #include "«fTypeCollection.headerFile»" «FOR fStructTypeHeaderPath : fTypeCollection.allDerivedFStructTypeHeaderPaths» diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGeneratorExtensions.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGeneratorExtensions.xtend index d225d42..83bd0f4 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGeneratorExtensions.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGeneratorExtensions.xtend @@ -42,6 +42,7 @@ import org.genivi.commonapi.core.preferences.PreferenceConstants import static com.google.common.base.Preconditions.* import org.franca.core.franca.FTypedElement import java.util.Collection +import org.genivi.commonapi.core.preferences.FPreferences class FrancaGeneratorExtensions { def String getFullyQualifiedName(FModelElement fModelElement) { @@ -119,7 +120,8 @@ class FrancaGeneratorExtensions { val maxCount = Ints::min(sourceNamespaceList.size, destinationNamespaceList.size) var dropCount = 0 - while (dropCount < maxCount && sourceNamespaceList.get(dropCount).equals(destinationNamespaceList.get(dropCount))) + while (dropCount < maxCount && + sourceNamespaceList.get(dropCount).equals(destinationNamespaceList.get(dropCount))) dropCount = dropCount + 1 return destinationNamespaceList.drop(dropCount) @@ -502,7 +504,8 @@ class FrancaGeneratorExtensions { } var errorNameReference = fMethod.errors.errorName - errorNameReference = (fMethod.eContainer as FInterface).getRelativeNameReference(source) + '::' + errorNameReference + errorNameReference = (fMethod.eContainer as FInterface).getRelativeNameReference(source) + '::' + + errorNameReference return errorNameReference } @@ -730,22 +733,26 @@ class FrancaGeneratorExtensions { } } - def private dispatch String typeStreamFTypeSignature(FTypeDef fTypeDef, DeploymentInterfacePropertyAccessor deploymentAccessor) { + def private dispatch String typeStreamFTypeSignature(FTypeDef fTypeDef, + DeploymentInterfacePropertyAccessor deploymentAccessor) { return fTypeDef.actualType.typeStreamSignature(deploymentAccessor) } - def private dispatch String typeStreamFTypeSignature(FArrayType fArrayType, DeploymentInterfacePropertyAccessor deploymentAccessor) { + def private dispatch String typeStreamFTypeSignature(FArrayType fArrayType, + DeploymentInterfacePropertyAccessor deploymentAccessor) { return 'typeOutputStream.beginWriteVectorType();\n' + fArrayType.elementType.typeStreamSignature(deploymentAccessor) + '\n' + 'typeOutputStream.endWriteVectorType();' } - def private dispatch String typeStreamFTypeSignature(FMapType fMap, DeploymentInterfacePropertyAccessor deploymentAccessor) { + def private dispatch String typeStreamFTypeSignature(FMapType fMap, + DeploymentInterfacePropertyAccessor deploymentAccessor) { return 'typeOutputStream.beginWriteMapType();\n' + fMap.keyType.typeStreamSignature(deploymentAccessor) + '\n' + fMap.valueType.typeStreamSignature(deploymentAccessor) + '\n' + 'typeOutputStream.endWriteMapType();' } - def private dispatch String typeStreamFTypeSignature(FStructType fStructType, DeploymentInterfacePropertyAccessor deploymentAccessor) { + def private dispatch String typeStreamFTypeSignature(FStructType fStructType, + DeploymentInterfacePropertyAccessor deploymentAccessor) { return 'typeOutputStream.beginWriteStructType();\n' + fStructType.getElementsTypeStreamSignature(deploymentAccessor) + '\n' + 'typeOutputStream.endWriteStructType();' @@ -756,7 +763,8 @@ class FrancaGeneratorExtensions { return fEnumerationType.getBackingType(deploymentAccessor).basicTypeStreamSignature } - def private dispatch String typeStreamFTypeSignature(FUnionType fUnionType, DeploymentInterfacePropertyAccessor deploymentAccessor) { + def private dispatch String typeStreamFTypeSignature(FUnionType fUnionType, + DeploymentInterfacePropertyAccessor deploymentAccessor) { return 'typeOutputStream.writeVariantType();' } @@ -833,7 +841,7 @@ class FrancaGeneratorExtensions { hasher.putFTypeObject(fStructType.base) hasher.putString('FStructType', Charsets::UTF_8) - fStructType.elements.forEach[ + fStructType.elements.forEach [ hasher.putFTypeRef(type) // avoid cases where the positions of 2 consecutive elements of the same type are switched hasher.putString(name, Charsets::UTF_8) @@ -918,16 +926,27 @@ class FrancaGeneratorExtensions { return file.location.toString } - def getHeader() { + def getHeader(FModel model) { val deflt = DefaultScope::INSTANCE.getNode(PreferenceConstants::SCOPE).get(PreferenceConstants::P_LICENSE, ""); - return InstanceScope::INSTANCE.getNode(PreferenceConstants::SCOPE).get(PreferenceConstants::P_LICENSE, deflt); + return FPreferences.instance.getPreference(PreferenceConstants.P_LICENSE, + InstanceScope::INSTANCE.getNode(PreferenceConstants::SCOPE).get(PreferenceConstants::P_LICENSE, deflt), model); } - def generateCommonApiLicenseHeader() ''' + def generateCommonApiLicenseHeader(FModelElement model) ''' /* - * This file was generated by the CommonAPI Generators. - * - «getHeader()» - */ + * This file was generated by the CommonAPI Generators. + * + «getCommentedString(getHeader(model.model))» + */ ''' + + def getCommentedString(String string) { + val lines = string.split("\n"); + var builder = new StringBuilder(); + for (String line : lines) { + builder.append(" * " + line + "\n"); + } + return builder.toString() + } + } diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/preferences/FPreferences.java b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/preferences/FPreferences.java new file mode 100644 index 0000000..0358e8d --- /dev/null +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/preferences/FPreferences.java @@ -0,0 +1,142 @@ +/* + * 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.preferences; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.preference.IPreferenceStore; +import org.franca.core.franca.FModel; + +public class FPreferences { + + private static FPreferences instance = null; + private Map<String, Map<String, String>> preferences = null; + + private FPreferences() { + preferences = new HashMap<String, Map<String, String>>(); + preferences.put("default", new HashMap<String, String>()); + preferences.get("default").put(PreferenceConstants.USEPROJECTSETTINGS, Boolean.toString(false)); + } + + public static FPreferences getInstance() { + if (instance == null) + return instance = new FPreferences(); + return instance; + } + + public void setPreferences(String name, File file, String path) throws IOException { + Reader r = null; + try { + r = new FileReader(file); + setPreference(name, r, path); + } finally { + try { + r.close(); + } catch (IOException e) { + ; + } + } + } + + public void setPreference(String name, String preference, FModel model) { + getPreferencesForPathString(getModelPath(model), true).put(name, preference); + } + + public void setPreference(String name, String preference, String path) { + getPreferencesForPathString(path, true).put(name, preference); + } + + private Map<String, String> getPreferencesForPathString(String path, boolean setter) { + Map<String, String> ret = null; + for (String key : preferences.keySet()) { + if (path.contains(key)) + return preferences.get(key); + } + if (setter) { + preferences.put(path, new HashMap<String, String>()); + return preferences.get(path); + } + return ret; + } + + public void setPreference(String name, InputStream in, String path) throws IOException { + Reader r = null; + try { + r = new InputStreamReader(in); + setPreference(name, r, path); + } finally { + try { + r.close(); + } catch (IOException e) { + ; + } + } + } + + public void setPreference(String name, Reader inreader, String path) throws IOException { + BufferedReader reader = new BufferedReader(inreader); + StringBuilder builder = new StringBuilder(); + String line = ""; + while ((line = reader.readLine()) != null) { + builder.append(line + "\n"); + } + getPreferencesForPathString(path, true).put(name, builder.toString()); + } + + private String getModelPath(FModel model) { + String ret = model.eResource().getURI().toString(); + return ret; + } + + public String getPreference(String name, String defaultret, FModel model) { + if (getPreferencesForPathString(getModelPath(model), true).get(PreferenceConstants.USEPROJECTSETTINGS).equals( + Boolean.toString(true))) + return getPreferencesForPathString(getModelPath(model), true).get(name); + return defaultret; + } + + public String getPreference(String name, String defaultret, String path) { + if (getPreferencesForPathString(path, false).get(PreferenceConstants.USEPROJECTSETTINGS).equals( + Boolean.toString(true))) + return getPreferencesForPathString(path, false).get(name); + return defaultret; + } + + public static void init(IPreferenceStore store, IPreferenceStore defaultstore, IProject project) { + String propath = project.getFullPath().toPortableString(); + if (instance == null) + instance = new FPreferences(); + if (store.getString(PreferenceConstants.USEPROJECTSETTINGS).equals(Boolean.toString(true))) { + if (instance.preferences.get(propath) == null) + instance.preferences.put(propath, new HashMap<String, String>()); + instance.preferences.get(propath).put(PreferenceConstants.USEPROJECTSETTINGS, Boolean.toString(true)); + instance.preferences.get(propath).put(PreferenceConstants.P_OUTPUT, + store.getString(PreferenceConstants.P_OUTPUT)); + instance.preferences.get(propath).put(PreferenceConstants.P_LICENSE, + store.getString(PreferenceConstants.P_LICENSE)); + } else { + if (instance.preferences.get(propath) == null) + instance.preferences.put(propath, new HashMap<String, String>()); + instance.preferences.get(propath).put(PreferenceConstants.P_OUTPUT, + defaultstore.getString(PreferenceConstants.P_OUTPUT)); + instance.preferences.get(propath).put(PreferenceConstants.P_LICENSE, + defaultstore.getString(PreferenceConstants.P_LICENSE)); + } + } + +} diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/preferences/PreferenceConstants.java b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/preferences/PreferenceConstants.java index 68d0c47..3643f9c 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/preferences/PreferenceConstants.java +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/preferences/PreferenceConstants.java @@ -1,13 +1,18 @@ +/* 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.preferences; /** * Constant definitions for plug-in preferences */ public class PreferenceConstants { - - public static final String SCOPE = "org.genivi.commonapi.core.ui"; - - public static final String P_LICENSE = "licenseHeader"; - public static final String P_OUTPUT = "outputDir"; - + public static final String SCOPE = "org.genivi.commonapi.core.ui"; + public static final String P_LICENSE = "licenseHeader"; + public static final String P_OUTPUT = "outputDir"; + public static final String USEPROJECTSETTINGS = "useProjectSettings"; + public static final String DEFAULT_OUTPUT = "./src-gen/"; } |