From 1666772afdd130805a7b8bed005b197e541a9f5c Mon Sep 17 00:00:00 2001 From: Jan Belle Date: Fri, 7 Sep 2018 14:35:29 +0200 Subject: [generator] Use single output directory for generated files Change-Id: Ida568ff8f4e0657369de19ed418f63648e667686 --- .../generator/base/io/GeneratorResourceLoader.java | 4 +- .../etrice/generator/base/io/IGeneratorFileIO.java | 22 +-- .../base/io/IncrementalGeneratorFileIO.java | 20 +-- .../etrice/generator/c/gen/ActorClassGen.xtend | 13 +- .../etrice/generator/c/gen/DataClassGen.xtend | 9 +- .../generator/c/gen/EnumerationTypeGen.xtend | 7 +- .../eclipse/etrice/generator/c/gen/MainGen.xtend | 3 +- .../eclipse/etrice/generator/c/gen/NodeGen.xtend | 11 +- .../etrice/generator/c/gen/NodeRunnerGen.xtend | 9 +- .../etrice/generator/c/gen/ProtocolClassGen.xtend | 9 +- .../etrice/generator/cpp/gen/ActorClassGen.xtend | 9 +- .../etrice/generator/cpp/gen/DataClassGen.xtend | 14 +- .../eclipse/etrice/generator/cpp/gen/MainGen.xtend | 3 +- .../eclipse/etrice/generator/cpp/gen/NodeGen.xtend | 7 +- .../etrice/generator/cpp/gen/NodeRunnerGen.xtend | 7 +- .../generator/cpp/gen/ProtocolClassGen.xtend | 11 +- .../eclipse/etrice/generator/doc/gen/DocGen.xtend | 59 ++++---- .../generator/doc/gen/InstanceDiagramGen.xtend | 11 +- .../eclipse/etrice/generator/doc/gen/MainGen.xtend | 2 +- .../generator/gnuplot/GnuplotScriptGenerator.xtend | 12 +- .../generator/java/gen/ActorClassDataGen.xtend | 5 +- .../etrice/generator/java/gen/ActorClassGen.xtend | 5 +- .../etrice/generator/java/gen/DataClassGen.xtend | 5 +- .../generator/java/gen/EnumerationTypeGen.xtend | 5 +- .../etrice/generator/java/gen/MainGen.xtend | 3 +- .../etrice/generator/java/gen/NodeGen.xtend | 5 +- .../etrice/generator/java/gen/NodeRunnerGen.xtend | 5 +- .../java/gen/OptionalActorFactoryGen.xtend | 5 +- .../java/gen/OptionalActorInterfaceGen.xtend | 7 +- .../generator/java/gen/ProtocolClassGen.xtend | 5 +- .../generator/java/gen/VariableServiceGen.xtend | 5 +- .../JavaGeneratorLaunchConfigurationDelegate.java | 5 +- .../GeneratorLaunchConfigurationDelegate.java | 153 ++++++++++++--------- .../generator/launch/GeneratorLaunchHelper.xtend | 7 + .../etrice/generator/base/AbstractGenerator.java | 6 +- .../eclipse/etrice/generator/base/ModelLoader.java | 3 + .../etrice/generator/base/ModelValidator.java | 12 +- .../generator/generic/PrepareFileSystem.xtend | 86 +----------- .../etrice/generator/generic/RoomExtensions.xtend | 64 --------- 39 files changed, 247 insertions(+), 386 deletions(-) diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/GeneratorResourceLoader.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/GeneratorResourceLoader.java index 84e1cdd57..022125ddf 100644 --- a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/GeneratorResourceLoader.java +++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/GeneratorResourceLoader.java @@ -86,7 +86,7 @@ public class GeneratorResourceLoader implements IGeneratorResourceLoader { return rs.getResource(uri, true); } catch(RuntimeException | IOException e) { - logger.logError("couldn't load resource " + file + "; " + e.getMessage()); + logger.logError("couldn't load file " + file + "; " + e.getMessage()); throw new GeneratorException(e); } } @@ -112,7 +112,7 @@ public class GeneratorResourceLoader implements IGeneratorResourceLoader { public void notifyChanged(Notification msg) { if(msg.getEventType() == Notification.ADD) { Resource addedResource = (Resource) msg.getNewValue(); - logger.logInfo("added resource " + addedResource.getURI()); + logger.logDebug("added resource " + addedResource.getURI()); } } } diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IGeneratorFileIO.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IGeneratorFileIO.java index fc11ef3bc..add4e6cb5 100644 --- a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IGeneratorFileIO.java +++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IGeneratorFileIO.java @@ -25,18 +25,22 @@ import com.google.inject.ImplementedBy; public interface IGeneratorFileIO { /** - * This method saves the contents in a file in the given path. - * Implementations may use the infopath for extra information like a hash key - * for incremental generation. + * Saves the contents in a file at the given path. * - * @param desc a description which is may be logged - * @param path the file system path for the generated file - * @param infopath the file system path for the generated info file (if used by the implementation) - * @param file the file name of the generated file + * @param filePath the file path of the generated file * @param contents the contents of the generated file */ - void generateFile(String desc, String path, String infopath, String file, CharSequence contents); + void generateFile(String filePath, CharSequence contents); - void generateFile(String file, CharSequence contents); + /** + * This method saves the contents in a file in the given path. + * + * @param description a description which may be logged + * @param filePath the file path name of the generated file + * @param contents the contents of the generated file + */ + default void generateFile(String description, String filePath, CharSequence contents) { + generateFile(filePath, contents); + } } diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IncrementalGeneratorFileIO.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IncrementalGeneratorFileIO.java index f03a35bd2..2b77dd467 100644 --- a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IncrementalGeneratorFileIO.java +++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IncrementalGeneratorFileIO.java @@ -57,7 +57,7 @@ public class IncrementalGeneratorFileIO implements IGeneratorFileIO { * In the other case the key is stored and the file is stored to {@code infopath} and {@code path}. */ @Override - public void generateFile(String desc, String path, String infopath, String file, CharSequence contents) { + public void generateFile(String desc, String file, CharSequence contents) { long oldCRC = 0; @@ -66,7 +66,7 @@ public class IncrementalGeneratorFileIO implements IGeneratorFileIO { if (genInc) { // read old CRC value - fileAccess.setOutputPath(infopath); + fileAccess.setOutputPath(genInfoDir); try { CharSequence val = fileAccess.readTextFile(file+".info", JavaIoFileSystemAccess.DEFAULT_OUTPUT); oldCRC = Long.parseLong(val.toString()); @@ -93,25 +93,25 @@ public class IncrementalGeneratorFileIO implements IGeneratorFileIO { } if (write) { - logger.logInfo(desc+" '"+file+"' in '"+path+"'"); - fileAccess.setOutputPath(path); + logger.logInfo(desc+" '"+file+"'"); + fileAccess.setOutputPath(genDir); fileAccess.generateFile(file, contents); if (genInc) { // save a copy in the info directory which is not cleared (and not compiled) - fileAccess.setOutputPath(infopath); + fileAccess.setOutputPath(genInfoDir); fileAccess.generateFile(file + ".incgen.txt", contents); } } else { - logger.logInfo(desc+" (unchanged) '"+file+"' in '"+path+"'"); - File src = new File(infopath+file + ".incgen.txt"); - File dst = new File(path+file); + logger.logInfo(desc+" (unchanged) '"+file+"'"); + File src = new File(genInfoDir+file + ".incgen.txt"); + File dst = new File(genDir+file); try { FileUtils.copyFile(src, dst, true); } catch (IOException e) { - fileAccess.setOutputPath(path); + fileAccess.setOutputPath(genDir); fileAccess.generateFile(file, contents); } } @@ -119,7 +119,7 @@ public class IncrementalGeneratorFileIO implements IGeneratorFileIO { @Override public void generateFile(String file, CharSequence contents) { - generateFile("generating file", genDir, genInfoDir, file, contents); + generateFile("generating file", file, contents); } public void setGenDir(String genDir) { diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend index 0544eb7f1..dee7b704e 100644 --- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend +++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend @@ -29,7 +29,6 @@ import org.eclipse.etrice.generator.c.Main import org.eclipse.etrice.generator.generic.GenericActorClassGenerator import org.eclipse.etrice.generator.generic.ILanguageExtension import org.eclipse.etrice.generator.generic.ProcedureHelpers -import org.eclipse.etrice.generator.generic.RoomExtensions import org.eclipse.etrice.generator.base.io.IGeneratorFileIO import org.eclipse.etrice.generator.c.setup.GeneratorOptionsHelper import org.eclipse.etrice.generator.base.logging.ILogger @@ -37,7 +36,6 @@ import org.eclipse.etrice.generator.base.logging.ILogger @Singleton class ActorClassGen extends GenericActorClassGenerator { - @Inject protected extension RoomExtensions @Inject protected extension CExtensions @Inject protected extension ProcedureHelpers @Inject protected extension StateMachineGen @@ -49,24 +47,23 @@ class ActorClassGen extends GenericActorClassGenerator { def doGenerate(Root root) { for (xpac: root.actorClasses.map[root.getExpandedActorClass(it)]) { - val path = xpac.actorClass.generationTargetPath+xpac.actorClass.getPath - val infopath = xpac.actorClass.generationInfoPath+xpac.actorClass.getPath + val path = xpac.actorClass.getPath var file = xpac.actorClass.getCHeaderFileName // header file - fileIO.generateFile("generating ActorClass header", path, infopath, file, root.generateHeaderFile(xpac)) + fileIO.generateFile("generating ActorClass header", path + file, root.generateHeaderFile(xpac)) // utils file file = xpac.actorClass.getCUtilsFileName - fileIO.generateFile("generating ActorClass utils", path, infopath, file, root.generateUtilsFile(xpac)) + fileIO.generateFile("generating ActorClass utils", path + file, root.generateUtilsFile(xpac)) // source file if (xpac.actorClass.isBehaviorAnnotationPresent("BehaviorManual")) { - logger.logInfo("omitting ActorClass source for '"+xpac.actorClass.name+"' since @BehaviorManual is specified") + logger.logInfo("omitting ActorClass source for '" + xpac.actorClass.name + "' since @BehaviorManual is specified") } else { file = xpac.actorClass.getCSourceFileName - fileIO.generateFile("generating ActorClass source", path, infopath, file, root.generateSourceFile(xpac)) + fileIO.generateFile("generating ActorClass source", path + file, root.generateSourceFile(xpac)) } } } diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/DataClassGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/DataClassGen.xtend index f484c1e8e..46ceea2f9 100644 --- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/DataClassGen.xtend +++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/DataClassGen.xtend @@ -39,20 +39,19 @@ class DataClassGen { def doGenerate(Root root) { for (dc: root.dataClasses) { - val path = dc.generationTargetPath+dc.getPath - val infopath = dc.generationInfoPath+dc.getPath + val path = dc.getPath var file = dc.getCHeaderFileName // header file - fileIO.generateFile("generating DataClass header", path, infopath, file, root.generateHeaderFile(dc)) + fileIO.generateFile("generating DataClass header", path + file, root.generateHeaderFile(dc)) // utils file file = dc.getCUtilsFileName - fileIO.generateFile("generating ProtocolClass utils", path, infopath, file, root.generateUtilsFile(dc)) + fileIO.generateFile("generating ProtocolClass utils", path + file, root.generateUtilsFile(dc)) // source file file = dc.getCSourceFileName - fileIO.generateFile("generating DataClass source", path, infopath, file, root.generateSourceFile(dc)) + fileIO.generateFile("generating DataClass source", path + file, root.generateSourceFile(dc)) } } diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/EnumerationTypeGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/EnumerationTypeGen.xtend index 8b5a23aa3..a8f88af50 100644 --- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/EnumerationTypeGen.xtend +++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/EnumerationTypeGen.xtend @@ -34,16 +34,15 @@ class EnumerationTypeGen { def doGenerate(Root root) { for (et: root.enumClasses) { - val path = et.generationTargetPath+et.getPath - val infopath = et.generationInfoPath+et.getPath + val path = et.getPath var file = et.getCHeaderFileName // header file - fileIO.generateFile("generating Enumeration header", path, infopath, file, root.generateHeaderFile(et)) + fileIO.generateFile("generating Enumeration header", path + file, root.generateHeaderFile(et)) // header file file = et.getCSourceFileName - fileIO.generateFile("generating Enumeration source", path, infopath, file, root.generateSourceFile(et)) + fileIO.generateFile("generating Enumeration source", path + file, root.generateSourceFile(et)) } } diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/MainGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/MainGen.xtend index d0bc921fe..428b3071c 100644 --- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/MainGen.xtend +++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/MainGen.xtend @@ -33,8 +33,7 @@ class MainGen { @Inject PrepareFileSystem prepFS def void doGenerate(Resource resource) { - prepFS.prepareCodeTargetPaths(resource) - prepFS.prepareInfoTargetPaths(resource) + prepFS.prepare for (e: resource.contents){ if (e instanceof Root) { doGenerate(e as Root) diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend index 1bb434da0..a1aadf370 100644 --- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend +++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend @@ -68,24 +68,23 @@ class NodeGen { for (instpath : ETMapUtil::getSubSystemInstancePaths(nr)) { val ssi = root.getInstance(instpath) as SubSystemInstance if (ssi!==null) { - val filepath = ssi.subSystemClass.generationTargetPath+ssi.subSystemClass.getPath - val infopath = ssi.subSystemClass.generationInfoPath+ssi.subSystemClass.getPath + val filepath = ssi.subSystemClass.getPath var file = nr.getCHeaderFileName(ssi) checkDataPorts(ssi) val usedThreads = ETMapUtil::getUsedThreads(nr, ssi) - fileIO.generateFile("generating Node declaration", filepath, infopath, file, root.generateHeaderFile(ssi)) + fileIO.generateFile("generating Node declaration", filepath + file, root.generateHeaderFile(ssi)) file = nr.getCSourceFileName(ssi) - fileIO.generateFile("generating Node implementation", filepath, infopath, file, root.generateSourceFile(ssi, usedThreads)) + fileIO.generateFile("generating Node implementation", filepath + file, root.generateSourceFile(ssi, usedThreads)) file = nr.getInstSourceFileName(ssi) - fileIO.generateFile("generating Node instance file", filepath, infopath, file, root.generateInstanceFile(ssi, usedThreads)) + fileIO.generateFile("generating Node instance file", filepath + file, root.generateInstanceFile(ssi, usedThreads)) file = nr.getDispSourceFileName(ssi) - fileIO.generateFile("generating Node dispatcher file", filepath, infopath, file, root.generateDispatcherFile(ssi, usedThreads)) + fileIO.generateFile("generating Node dispatcher file", filepath + file, root.generateDispatcherFile(ssi, usedThreads)) } } } diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeRunnerGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeRunnerGen.xtend index 3cc0f697b..9279f22a7 100644 --- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeRunnerGen.xtend +++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeRunnerGen.xtend @@ -19,18 +19,18 @@ import com.google.inject.Inject import com.google.inject.Singleton import org.eclipse.etrice.core.genmodel.etricegen.Root import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance -import org.eclipse.xtext.generator.JavaIoFileSystemAccess import org.eclipse.etrice.generator.generic.RoomExtensions import org.eclipse.etrice.core.etmap.util.ETMapUtil import org.eclipse.etrice.core.common.base.util.BaseHelpers import org.eclipse.etrice.generator.c.Main import org.eclipse.etrice.generator.c.setup.GeneratorOptionsHelper +import org.eclipse.etrice.generator.base.io.IGeneratorFileIO @Singleton class NodeRunnerGen { @Inject extension BaseHelpers - @Inject extension JavaIoFileSystemAccess fileAccess + @Inject extension IGeneratorFileIO fileIO @Inject extension CExtensions @Inject extension RoomExtensions @Inject protected extension GeneratorOptionsHelper @@ -42,8 +42,9 @@ class NodeRunnerGen { val ssi = root.getInstance(instpath) as SubSystemInstance if (ssi!==null) { val clsname = nr.name+"_"+ssi.name - fileAccess.setOutputPath(ssi.subSystemClass.generationTargetPath+ssi.subSystemClass.getPath) - fileAccess.generateFile( clsname+"_Runner.c", root.generateSourceFile(ssi, first)) + val path = ssi.subSystemClass.getPath + val file = clsname + "_Runner.c" + fileIO.generateFile(path + file, root.generateSourceFile(ssi, first)) first = false } } diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.xtend index c455aa4f2..09516bec3 100644 --- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.xtend +++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.xtend @@ -45,20 +45,19 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { def doGenerate(Root root) { for (pc: root.protocolClasses) { - val path = pc.generationTargetPath+pc.getPath - val infopath = pc.generationInfoPath+pc.getPath + val path = pc.getPath var file = pc.getCHeaderFileName // header file - fileIO.generateFile("generating ProtocolClass header", path, infopath, file, root.generateHeaderFile(pc)) + fileIO.generateFile("generating ProtocolClass header", path + file, root.generateHeaderFile(pc)) // utils file file = pc.getCUtilsFileName - fileIO.generateFile("generating ProtocolClass utils", path, infopath, file, root.generateUtilsFile(pc)) + fileIO.generateFile("generating ProtocolClass utils", path + file, root.generateUtilsFile(pc)) // source file file = pc.getCSourceFileName - fileIO.generateFile("generating ProtocolClass source", path, infopath, file, root.generateSourceFile(pc)) + fileIO.generateFile("generating ProtocolClass source", path + file, root.generateSourceFile(pc)) } } diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend index f0fbb97cc..626746a6b 100644 --- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend +++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend @@ -50,11 +50,10 @@ class ActorClassGen extends GenericActorClassGenerator { for (xpac: root.actorClasses.filter[isValidGenerationLocation].map[root.getExpandedActorClass(it)]) { val wired = ac2wired.get(xpac.actorClass) val manualBehavior = xpac.actorClass.isBehaviorAnnotationPresent("BehaviorManual") - val path = xpac.actorClass.generationTargetPath+xpac.actorClass.getPath - val infopath = xpac.actorClass.generationInfoPath+xpac.actorClass.getPath + val path = xpac.actorClass.getPath var file = if (manualBehavior) 'Abstract' else '' - fileIO.generateFile("generating ActorClass declaration", path, infopath, file + xpac.actorClass.getCppHeaderFileName, root.generateHeaderFile(xpac, wired, manualBehavior)) - fileIO.generateFile("generating ActorClass implementation", path, infopath, file + xpac.actorClass.getCppSourceFileName, root.generateSourceFile(xpac, wired, manualBehavior)) + fileIO.generateFile("generating ActorClass declaration", path + file + xpac.actorClass.getCppHeaderFileName, root.generateHeaderFile(xpac, wired, manualBehavior)) + fileIO.generateFile("generating ActorClass implementation", path + file + xpac.actorClass.getCppSourceFileName, root.generateSourceFile(xpac, wired, manualBehavior)) } } @@ -91,7 +90,7 @@ class ActorClassGen extends GenericActorClassGenerator { #include "«dc.path»«dc.name».h" «ENDFOR» - «IF ac.actorBase==null» + «IF ac.actorBase===null» #include "common/modelbase/ActorClassBase.h" «ELSE» #include "«ac.actorBase.path»«ac.actorBase.name».h" diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend index 4946431d3..da261eacf 100644 --- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend +++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend @@ -24,12 +24,12 @@ import org.eclipse.etrice.core.room.ComplexType import org.eclipse.etrice.core.room.DataClass import org.eclipse.etrice.core.room.util.RoomHelpers import org.eclipse.etrice.generator.generic.RoomExtensions -import org.eclipse.xtext.generator.JavaIoFileSystemAccess +import org.eclipse.etrice.generator.base.io.IGeneratorFileIO @Singleton class DataClassGen { - @Inject extension JavaIoFileSystemAccess fileAccess + @Inject extension IGeneratorFileIO fileIO @Inject extension CppExtensions stdExt @Inject extension RoomExtensions roomExt @Inject extension CppProcedureHelpers helpers @@ -41,17 +41,13 @@ class DataClassGen { def doGenerate(Root root) { logger.logInfo("generating code") for (dc: root.dataClasses) { - var path = dc.generationTargetPath + dc.getPath + var path = dc.getPath // header file - logger.logInfo("generating DataClass header '"+dc.getCppHeaderFileName+"' in '"+path+"'") - fileAccess.setOutputPath(path) - fileAccess.generateFile(dc.getCppHeaderFileName, root.generateHeaderFile(dc)) + fileIO.generateFile("generating DataClass header", path + dc.getCppHeaderFileName, root.generateHeaderFile(dc)) // source file - logger.logInfo("generating DataClass source '"+dc.getCppSourceFileName+"' in '"+path+"'") - fileAccess.setOutputPath(path) - fileAccess.generateFile(dc.getCppSourceFileName, root.generateSourceFile(dc)) + fileIO.generateFile("generating DataClass source", path + dc.getCppSourceFileName, root.generateSourceFile(dc)) } diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/MainGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/MainGen.xtend index 6027b9358..f5c5bcf89 100644 --- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/MainGen.xtend +++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/MainGen.xtend @@ -32,8 +32,7 @@ class MainGen { @Inject PrepareFileSystem prepFS def void doGenerate(Resource resource) { - prepFS.prepareCodeTargetPaths(resource) - prepFS.prepareInfoTargetPaths(resource) + prepFS.prepare for (e: resource.contents){ if (e instanceof Root) { doGenerate(e as Root) diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/NodeGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/NodeGen.xtend index 0389ca8df..bea58540a 100644 --- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/NodeGen.xtend +++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/NodeGen.xtend @@ -56,15 +56,14 @@ class NodeGen { val ssi = root.getInstance(instpath) as SubSystemInstance if (ssi!=null && ssi.subSystemClass.validGenerationLocation) { val wired = sscc2wired.get(ssi.subSystemClass) - val path = ssi.subSystemClass.generationTargetPath+ssi.subSystemClass.getPath - val infopath = ssi.subSystemClass.generationInfoPath+ssi.subSystemClass.getPath + val path = ssi.subSystemClass.getPath //checkDataPorts(ssi) val usedThreads = ETMapUtil::getUsedThreads(nr, ssi) - fileIO.generateFile("generating Node declaration", path, infopath, getCppHeaderFileName(nr, ssi), root.generateHeaderFile(ssi, wired, usedThreads)) - fileIO.generateFile("generating Node implementation", path, infopath, getCppSourceFileName(nr, ssi), root.generateSourceFile(ssi, wired, usedThreads)) + fileIO.generateFile("generating Node declaration", path + getCppHeaderFileName(nr, ssi), root.generateHeaderFile(ssi, wired, usedThreads)) + fileIO.generateFile("generating Node implementation", path + getCppSourceFileName(nr, ssi), root.generateSourceFile(ssi, wired, usedThreads)) } } } diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/NodeRunnerGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/NodeRunnerGen.xtend index 3b5eed7e3..4ae998776 100644 --- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/NodeRunnerGen.xtend +++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/NodeRunnerGen.xtend @@ -40,10 +40,9 @@ class NodeRunnerGen { for (instpath : ETMapUtil::getSubSystemInstancePaths(nr)) { val ssi = root.getInstance(instpath) as SubSystemInstance if (ssi!=null && ssi.subSystemClass.validGenerationLocation) { - val filepath = ssi.subSystemClass.generationTargetPath+ssi.subSystemClass.getPath - val infopath = ssi.subSystemClass.generationInfoPath+ssi.subSystemClass.getPath - fileIO.generateFile("generating SubSystemRunner declaration", filepath, infopath, nr.getCppClassName(ssi)+"Runner.h", root.generateHeaderFile(ssi)) - fileIO.generateFile("generating SubSystemRunner implementation", filepath, infopath, nr.getCppClassName(ssi)+"Runner.cpp", root.generateSourceFile(ssi)) + val filepath = ssi.subSystemClass.getPath + fileIO.generateFile("generating SubSystemRunner declaration", filepath + nr.getCppClassName(ssi)+"Runner.h", root.generateHeaderFile(ssi)) + fileIO.generateFile("generating SubSystemRunner implementation", filepath + nr.getCppClassName(ssi)+"Runner.cpp", root.generateSourceFile(ssi)) } } } diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend index 769d5b825..9cb81b539 100644 --- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend +++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend @@ -53,16 +53,15 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { def doGenerate(Root root) { for (pc: root.protocolClasses.filter(cl|cl.isValidGenerationLocation)) { - val path = pc.generationTargetPath+pc.getPath - val infopath = pc.generationInfoPath+pc.getPath + val path = pc.getPath switch (pc.commType) { case CommunicationType::EVENT_DRIVEN:{ - fileIO.generateFile("generating ProtocolClass declaration", path, infopath, pc.cppHeaderFileName, root.generateHeaderFile(pc)) - fileIO.generateFile("generating ProtocolClass implementation", path, infopath, pc.cppSourceFileName, root.generateSourceFile(pc)) + fileIO.generateFile("generating ProtocolClass declaration", path + pc.cppHeaderFileName, root.generateHeaderFile(pc)) + fileIO.generateFile("generating ProtocolClass implementation", path + pc.cppSourceFileName, root.generateSourceFile(pc)) } case CommunicationType::DATA_DRIVEN:{ - fileIO.generateFile("generating ProtocolClass declaration", path, infopath, pc.cppHeaderFileName, root.generateDataDrivenHeaderFile(pc)) - fileIO.generateFile("generating ProtocolClass implementation", path, infopath, pc.cppSourceFileName, root.generateDataDrivenSourceFile(pc)) + fileIO.generateFile("generating ProtocolClass declaration", path + pc.cppHeaderFileName, root.generateDataDrivenHeaderFile(pc)) + fileIO.generateFile("generating ProtocolClass implementation", path + pc.cppSourceFileName, root.generateDataDrivenSourceFile(pc)) } case CommunicationType::SYNCHRONOUS: diagnostician.error("synchronous protocols not supported yet", pc, null) diff --git a/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/gen/DocGen.xtend b/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/gen/DocGen.xtend index 2ac75932e..989debf37 100644 --- a/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/gen/DocGen.xtend +++ b/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/gen/DocGen.xtend @@ -37,17 +37,15 @@ import org.eclipse.etrice.core.room.StandardOperation import org.eclipse.etrice.core.room.SubSystemClass import org.eclipse.etrice.core.room.util.RoomHelpers import org.eclipse.etrice.generator.fsm.base.CodegenHelpers -import org.eclipse.etrice.generator.generic.RoomExtensions -import org.eclipse.xtext.generator.JavaIoFileSystemAccess import org.eclipse.etrice.generator.base.logging.ILogger +import org.eclipse.etrice.generator.base.io.IGeneratorFileIO @Singleton class DocGen { @Inject extension RoomHelpers @Inject extension CodegenHelpers - @Inject extension JavaIoFileSystemAccess fileAccess - @Inject extension RoomExtensions roomExt + @Inject IGeneratorFileIO fileIO @Inject ILogger logger final val IMGDIR_DEFAULT = "./images" @@ -67,28 +65,25 @@ class DocGen { def doGenerate(Root root) { for (model: root.models) { val ctx = new DocGen.DocGenContext(root,model) - var path = model.generationTargetPath var file = model.name+".tex" val Set referencedModels = newHashSet - logger.logInfo("generating LaTeX documentation: '"+file+"' in '"+path+"'") + logger.logInfo("generating LaTeX documentation: '"+file+"'") // Save documentation fragments for RoomModel children - fileAccess.setOutputPath(path+model.name) - model.systems.forEach[generateDoc(ctx).saveAs(docFragmentName)] + model.systems.forEach[generateDoc(ctx).saveAs(model.name+docFragmentName)] model.systems.forEach[referencedModels.addAll(root.getReferencedModels(it))] - model.subSystemClasses.forEach[generateDoc(ctx).saveAs(docFragmentName)] + model.subSystemClasses.forEach[generateDoc(ctx).saveAs(model.name+docFragmentName)] model.subSystemClasses.forEach[referencedModels.addAll(root.getReferencedModels(it))] - model.protocolClasses.forEach[generateDoc(ctx).saveAs(docFragmentName)] + model.protocolClasses.forEach[generateDoc(ctx).saveAs(model.name+docFragmentName)] model.protocolClasses.forEach[referencedModels.addAll(root.getReferencedModels(it))] - model.enumerationTypes.forEach[generateDoc(ctx).saveAs(docFragmentName)] + model.enumerationTypes.forEach[generateDoc(ctx).saveAs(model.name+docFragmentName)] model.enumerationTypes.forEach[referencedModels.addAll(root.getReferencedModels(it))] - model.dataClasses.forEach[generateDoc(ctx).saveAs(docFragmentName)] + model.dataClasses.forEach[generateDoc(ctx).saveAs(model.name+docFragmentName)] model.dataClasses.forEach[referencedModels.addAll(root.getReferencedModels(it))] - model.actorClasses.forEach[generateDoc(ctx).saveAs(docFragmentName)] + model.actorClasses.forEach[generateDoc(ctx).saveAs(model.name+docFragmentName)] model.actorClasses.forEach[referencedModels.addAll(root.getReferencedModels(it))] // Save top-level documentation for RoomModel - fileAccess.setOutputPath(path) generateModelDoc(ctx, referencedModels).saveAs(file) // logger.logInfo("main path "+model.docGenerationTargetPath) @@ -191,9 +186,10 @@ class DocGen { \begin{itemize} «FOR refModel : referencedModels.sortBy[name]» - «val relPath = RelativePathHelpers.getRelativePath( - model.generationTargetPath.removeLast, refModel.generationTargetPath.removeLast, true).appendIfNotEmpty("/")» - \item \href{«(relPath.replace("\\", "/")+refModel.name).escapedString».pdf}{«refModel.name.escapedString»} +««« «val relPath = RelativePathHelpers.getRelativePath( +««« model.generationTargetPath.removeLast, refModel.generationTargetPath.removeLast, true).appendIfNotEmpty("/")» +««« \item \href{«(relPath.replace("\\", "/")+refModel.name).escapedString».pdf}{«refModel.name.escapedString»} + \item «refModel.name.escapedString» «ENDFOR» \end{itemize} \newpage @@ -564,18 +560,21 @@ class DocGen { } def private fileExists(RoomModel model, String f){ - val absPath = model.generationTargetPath + f - val file = new File(absPath); - val exist = file.exists(); - if (exist == true) { - // File or directory exists - logger.logInfo("File found ! " + f); - return "true" - } else { - // File or directory does not exist - logger.logInfo("File not found ! " + f); - return "false" - } +// val absPath = model.generationTargetPath + f +// val file = new File(absPath); +// val exist = file.exists(); +// if (exist == true) { +// // File or directory exists +// logger.logInfo("File found ! " + f); +// return "true" +// } else { +// // File or directory does not exist +// logger.logInfo("File not found ! " + f); +// return "false" +// } + + + return "false" } def private includeGraphics(String filename, String width, String caption){ @@ -600,7 +599,7 @@ class DocGen { } def private saveAs(CharSequence content, String filename) { - fileAccess.generateFile(filename, content) + fileIO.generateFile(filename, content) } def private docFragmentName(RoomClass rc) { diff --git a/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/gen/InstanceDiagramGen.xtend b/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/gen/InstanceDiagramGen.xtend index 76fb47b39..bdc8f62ff 100644 --- a/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/gen/InstanceDiagramGen.xtend +++ b/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/gen/InstanceDiagramGen.xtend @@ -24,30 +24,29 @@ import org.eclipse.etrice.core.genmodel.etricegen.Root import org.eclipse.etrice.core.genmodel.etricegen.StructureInstance import org.eclipse.etrice.core.genmodel.etricegen.SystemInstance import org.eclipse.etrice.generator.generic.RoomExtensions -import org.eclipse.xtext.generator.JavaIoFileSystemAccess import static java.lang.Runtime.* import org.eclipse.etrice.core.etmap.util.ETMapUtil import org.eclipse.etrice.generator.base.logging.ILogger +import org.eclipse.etrice.generator.base.io.IGeneratorFileIO @Singleton class InstanceDiagramGen { - @Inject extension JavaIoFileSystemAccess fileAccess + @Inject extension IGeneratorFileIO fileIO @Inject extension RoomExtensions roomExt @Inject ILogger logger def doGenerate(Root root) { for (model: root.models) { - var path = model.generationTargetPath + "/images" - fileAccess.setOutputPath(path) + var path = "images/" var batchFile = "dot2jpg.bat" for (sys : root.systemInstances) { var file = sys.name+"_instanceTree.dot" logger.logInfo("generating instance tree diagram: '"+file+"' in '"+path+"'") - fileAccess.generateFile(file, root.generate(sys)) + fileIO.generateFile(path + file, root.generate(sys)) } - fileAccess.generateFile(batchFile, root.generate2jpg()) + fileIO.generateFile(path + batchFile, root.generate2jpg()) runDot2Jpg(path, batchFile) } } diff --git a/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/gen/MainGen.xtend b/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/gen/MainGen.xtend index 56f6a61a0..327be64bc 100644 --- a/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/gen/MainGen.xtend +++ b/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/gen/MainGen.xtend @@ -28,7 +28,7 @@ class MainGen { @Inject DocGen docGen def void doGenerate(Resource resource) { - prepFS.prepareCodeTargetPaths(resource) + prepFS.prepare for (e: resource.contents){ if (e instanceof Root) { doGenerate(e as Root) diff --git a/plugins/org.eclipse.etrice.generator.gnuplot/src/org/eclipse/etrice/generator/gnuplot/GnuplotScriptGenerator.xtend b/plugins/org.eclipse.etrice.generator.gnuplot/src/org/eclipse/etrice/generator/gnuplot/GnuplotScriptGenerator.xtend index f7fb3acb9..a69ccace1 100644 --- a/plugins/org.eclipse.etrice.generator.gnuplot/src/org/eclipse/etrice/generator/gnuplot/GnuplotScriptGenerator.xtend +++ b/plugins/org.eclipse.etrice.generator.gnuplot/src/org/eclipse/etrice/generator/gnuplot/GnuplotScriptGenerator.xtend @@ -24,7 +24,6 @@ import org.eclipse.etrice.core.common.base.StringLiteral import org.eclipse.etrice.core.genmodel.etricegen.Root import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance import org.eclipse.etrice.generator.base.io.IGeneratorFileIO -import org.eclipse.etrice.generator.generic.RoomExtensions import com.google.inject.Singleton @Singleton @@ -32,9 +31,6 @@ class GnuplotScriptGenerator { @Inject IGeneratorFileIO fileIo - @Inject - extension RoomExtensions roomExtensions - def doGenerate(Root root) { if (root.subSystemInstances.empty) return; @@ -44,13 +40,9 @@ class GnuplotScriptGenerator { if(!ssi.subSystemClass.annotations.exists[a |a.type.name == "Gnuplot"]) return; - val path = ssi.subSystemClass.getGenerationTargetPath - val infoPath = ssi.subSystemClass.generationInfoPath try { - fileIo.generateFile("Generating gnuplot script for subsystem " + ssi.name, path, infoPath, - "/gnuplot/main.data.csv-script.plt", ssi.generatePlotScript) - fileIo.generateFile("Generating gnuplot launch configuration", path, infoPath, - "/gnuplot/create_gnuplot.launch", gnuPlotLaunchFile) + fileIo.generateFile("Generating gnuplot script for subsystem " + ssi.name, "/gnuplot/main.data.csv-script.plt", ssi.generatePlotScript) + fileIo.generateFile("Generating gnuplot launch configuration", "/gnuplot/create_gnuplot.launch", gnuPlotLaunchFile) } catch (Exception e) { //e.printStackTrace } diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ActorClassDataGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ActorClassDataGen.xtend index 3e2762aeb..b8ad9fb1a 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ActorClassDataGen.xtend +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ActorClassDataGen.xtend @@ -42,10 +42,9 @@ class ActorClassDataGen { root.wiredInstances.filter(w|w instanceof WiredActorClass).forEach[w|ac2wired.put((w as WiredActorClass).actorClass, w as WiredActorClass)] for (xpac: root.actorClasses.filter[isValidGenerationLocation].map[root.getExpandedActorClass(it)]) { val wired = ac2wired.get(xpac.actorClass) - val path = xpac.actorClass.generationTargetPath+xpac.actorClass.getPath - val infopath = xpac.actorClass.generationInfoPath+xpac.actorClass.getPath + val path = xpac.actorClass.getPath var file = xpac.actorClass.name+"_DataObject.java" - fileIO.generateFile("generating ActorClass implementation", path, infopath, file, root.generate(xpac, wired)) + fileIO.generateFile("generating ActorClass implementation", path + file, root.generate(xpac, wired)) } } diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ActorClassGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ActorClassGen.xtend index c6555a0db..13e19f72e 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ActorClassGen.xtend +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ActorClassGen.xtend @@ -65,12 +65,11 @@ class ActorClassGen extends GenericActorClassGenerator { for (xpac: root.actorClasses.filter[isValidGenerationLocation].map[root.getExpandedActorClass(it)]) { val wired = ac2wired.get(xpac.actorClass) val manualBehavior = xpac.actorClass.isBehaviorAnnotationPresent("BehaviorManual") - val path = xpac.actorClass.generationTargetPath+xpac.actorClass.getPath - val infopath = xpac.actorClass.generationInfoPath+xpac.actorClass.getPath + val path = xpac.actorClass.getPath var file = xpac.actorClass.getJavaFileName if (manualBehavior) file = "Abstract"+file - fileIO.generateFile("generating ActorClass implementation", path, infopath, file, root.generate(xpac, wired, manualBehavior)) + fileIO.generateFile("generating ActorClass implementation", path + file, root.generate(xpac, wired, manualBehavior)) } } diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/DataClassGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/DataClassGen.xtend index cce86cbaa..b58c0afb4 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/DataClassGen.xtend +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/DataClassGen.xtend @@ -40,10 +40,9 @@ class DataClassGen { def doGenerate(Root root) { for (dc: root.dataClasses.filter(cl|cl.isValidGenerationLocation)) { - var path = dc.generationTargetPath+dc.getPath - var infopath = dc.generationInfoPath+dc.getPath + var path = dc.getPath var file = dc.getJavaFileName - fileIO.generateFile("generating DataClass implementation", path, infopath, file, root.generate(dc)) + fileIO.generateFile("generating DataClass implementation", path + file, root.generate(dc)) } } diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/EnumerationTypeGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/EnumerationTypeGen.xtend index 6ca3186b2..9bdfa987b 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/EnumerationTypeGen.xtend +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/EnumerationTypeGen.xtend @@ -35,10 +35,9 @@ class EnumerationTypeGen { def doGenerate(Root root) { for (et: root.enumClasses.filter(cl|cl.isValidGenerationLocation)) { - var path = et.generationTargetPath+et.getPath - var infopath = et.generationInfoPath+et.getPath + var path = et.getPath var file = et.getJavaFileName - fileIO.generateFile("generating Enumeration implementation", path, infopath, file, root.generate(et)) + fileIO.generateFile("generating Enumeration implementation", path + file, root.generate(et)) } } diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/MainGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/MainGen.xtend index b8a600750..f6c41eaee 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/MainGen.xtend +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/MainGen.xtend @@ -39,8 +39,7 @@ class MainGen { @Inject protected extension GeneratorOptionsHelper def void doGenerate(Resource resource) { - prepFS.prepareCodeTargetPaths(resource) - prepFS.prepareInfoTargetPaths(resource) + prepFS.prepare for (e: resource.contents){ if (e instanceof Root) { doGenerate(e as Root) diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/NodeGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/NodeGen.xtend index 31814c3d1..7ac34c3d5 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/NodeGen.xtend +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/NodeGen.xtend @@ -70,15 +70,14 @@ class NodeGen { val ssi = root.getInstance(instpath) as SubSystemInstance if (ssi!==null && ssi.subSystemClass.validGenerationLocation) { val wired = sscc2wired.get(ssi.subSystemClass) - val path = ssi.subSystemClass.generationTargetPath+ssi.subSystemClass.getPath - val infopath = ssi.subSystemClass.generationInfoPath+ssi.subSystemClass.getPath + val path = ssi.subSystemClass.getPath val file = nr.getJavaFileName(ssi) checkDataPorts(ssi) val usedThreads = ETMapUtil::getUsedThreads(nr, ssi) - fileIO.generateFile("generating Node implementation", path, infopath, file, root.generate(ssi, wired, usedThreads)) + fileIO.generateFile("generating Node implementation", path + file, root.generate(ssi, wired, usedThreads)) if (dataConfigExt.hasVariableService(ssi)) varService.doGenerate(root, ssi); } diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/NodeRunnerGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/NodeRunnerGen.xtend index b6c383df7..1d6d1d65f 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/NodeRunnerGen.xtend +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/NodeRunnerGen.xtend @@ -39,9 +39,8 @@ class NodeRunnerGen { val ssi = root.getInstance(instpath) as SubSystemInstance if (ssi!==null && ssi.subSystemClass.validGenerationLocation) { val file = nr.getJavaClassName(ssi)+"Runner.java" - val filepath = ssi.subSystemClass.generationTargetPath+ssi.subSystemClass.getPath - val infopath = ssi.subSystemClass.generationInfoPath+ssi.subSystemClass.getPath - fileIO.generateFile("generating SubSystemRunner implementation", filepath, infopath, file, root.generate(ssi)) + val filepath = ssi.subSystemClass.getPath + fileIO.generateFile("generating SubSystemRunner implementation", filepath + file, root.generate(ssi)) } } } diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/OptionalActorFactoryGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/OptionalActorFactoryGen.xtend index ccf46358b..dc01fa902 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/OptionalActorFactoryGen.xtend +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/OptionalActorFactoryGen.xtend @@ -26,10 +26,9 @@ class OptionalActorFactoryGen { for (oi: root.optionalInstances.filter(cl|cl.actorClass.isValidGenerationLocation)) { val ac = oi.actorClass val wired = ac2wired.get(ac) - val path = ac.generationTargetPath+ac.path - val infopath = ac.generationInfoPath+ac.path + val path = ac.path val file = ac.getJavaFactoryFileName - fileIO.generateFile("generating ActorClass Interface implementation", path, infopath, file, root.generate(oi, wired)) + fileIO.generateFile("generating ActorClass Interface implementation", path + file, root.generate(oi, wired)) } } diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/OptionalActorInterfaceGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/OptionalActorInterfaceGen.xtend index 4e63c010f..d99478b0d 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/OptionalActorInterfaceGen.xtend +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/OptionalActorInterfaceGen.xtend @@ -36,13 +36,12 @@ class OptionalActorInterfaceGen extends GenericActorClassGenerator { def doGenerate(Root root) { for (ac: root.optionalActorClasses.filter(cl|cl.isValidGenerationLocation)) { - val path = ac.generationTargetPath+ac.path - val infopath = ac.generationInfoPath+ac.path + val path = ac.path var file = ac.getJavaInterfaceFileName(false) - fileIO.generateFile("generating ActorClass Interface implementation", path, infopath, file, root.generate(ac, false)) + fileIO.generateFile("generating ActorClass Interface implementation", path + file, root.generate(ac, false)) file = ac.getJavaInterfaceFileName(true) - fileIO.generateFile("generating ActorClass Interface implementation", path, infopath, file, root.generate(ac, true)) + fileIO.generateFile("generating ActorClass Interface implementation", path + file, root.generate(ac, true)) } } diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.xtend index 14788081f..749a6a1b3 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.xtend +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.xtend @@ -48,8 +48,7 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { def doGenerate(Root root) { for (pc: root.protocolClasses.filter(cl|cl.isValidGenerationLocation)) { - val path = pc.generationTargetPath+pc.getPath - val infopath = pc.generationInfoPath+pc.getPath + val path = pc.getPath val file = pc.getJavaFileName val contents = switch (pc.commType) { @@ -63,7 +62,7 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { if (contents.toString.empty) diagnostician.error("synchronous protocols not supported yet", pc, null) else - fileIO.generateFile("generating ProtocolClass implementation", path, infopath, file, contents) + fileIO.generateFile("generating ProtocolClass implementation", path + file, contents) } } diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/VariableServiceGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/VariableServiceGen.xtend index 19d52f1f5..3b6dd69a8 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/VariableServiceGen.xtend +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/VariableServiceGen.xtend @@ -53,10 +53,9 @@ class VariableServiceGen { def doGenerate(Root root, SubSystemInstance ssi) { val nr = ETMapUtil::getNodeRef(ssi) val clsname = nr.getJavaClassName(ssi) - val path = ssi.subSystemClass.generationTargetPath+ssi.subSystemClass.getPath - val infopath = ssi.subSystemClass.generationInfoPath+ssi.subSystemClass.getPath + val path = ssi.subSystemClass.getPath val file = clsname+"VariableService.java" - fileIO.generateFile("generating VariableService implementation", path, infopath, file, root.generate(ssi)) + fileIO.generateFile("generating VariableService implementation", path + file, root.generate(ssi)) } def private generate(Root root, SubSystemInstance comp) { diff --git a/plugins/org.eclipse.etrice.generator.launch.java/src/org/eclipse/etrice/generator/launch/java/JavaGeneratorLaunchConfigurationDelegate.java b/plugins/org.eclipse.etrice.generator.launch.java/src/org/eclipse/etrice/generator/launch/java/JavaGeneratorLaunchConfigurationDelegate.java index ea8dca066..23942c7e8 100644 --- a/plugins/org.eclipse.etrice.generator.launch.java/src/org/eclipse/etrice/generator/launch/java/JavaGeneratorLaunchConfigurationDelegate.java +++ b/plugins/org.eclipse.etrice.generator.launch.java/src/org/eclipse/etrice/generator/launch/java/JavaGeneratorLaunchConfigurationDelegate.java @@ -14,6 +14,7 @@ package org.eclipse.etrice.generator.launch.java; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.etrice.generator.base.io.ILineOutput; @@ -31,8 +32,8 @@ public class JavaGeneratorLaunchConfigurationDelegate extends GeneratorLaunchCon * @see org.eclipse.etrice.generator.launch.GeneratorLaunchConfigurationDelegate#addArguments(org.eclipse.debug.core.ILaunchConfiguration, java.lang.StringBuffer) */ @Override - protected void addArguments(ILaunchConfiguration configuration, StringBuffer argString) throws CoreException { - super.addArguments(configuration, argString); + protected void addArguments(ILaunchConfiguration configuration, IProject project, StringBuffer argString) throws CoreException { + super.addArguments(configuration, project, argString); if (configuration.getAttribute(JavaGeneratorConfigTab.PERSIST, false)) { argString.append(" -"+GeneratorOptions.GEN_PERSIST.getName()); diff --git a/plugins/org.eclipse.etrice.generator.launch/src/org/eclipse/etrice/generator/launch/GeneratorLaunchConfigurationDelegate.java b/plugins/org.eclipse.etrice.generator.launch/src/org/eclipse/etrice/generator/launch/GeneratorLaunchConfigurationDelegate.java index ec6ca26ef..73f11bb4c 100644 --- a/plugins/org.eclipse.etrice.generator.launch/src/org/eclipse/etrice/generator/launch/GeneratorLaunchConfigurationDelegate.java +++ b/plugins/org.eclipse.etrice.generator.launch/src/org/eclipse/etrice/generator/launch/GeneratorLaunchConfigurationDelegate.java @@ -17,7 +17,10 @@ package org.eclipse.etrice.generator.launch; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -72,64 +75,25 @@ public abstract class GeneratorLaunchConfigurationDelegate extends AbstractJavaL return; } try { - StringBuffer argString = new StringBuffer(); - - // constructing program arguments - addModels(configuration, argString); - addArguments(configuration, argString); - - String pgmArgs = argString.toString().trim(); - pgmArgs = VariablesPlugin.getDefault().getStringVariableManager() - .performStringSubstitution(pgmArgs); - - // split at single spaces but keep strings in double quotes as single argument - // (with double quotes removed) - ArrayList res = new ArrayList(); - int begin = 0; - int end = pgmArgs.indexOf(' '); - boolean inQuotes = false; - while (end>0) { - if (pgmArgs.charAt(begin)=='\"') - inQuotes = true; - if ((inQuotes && pgmArgs.charAt(end-1)=='\"')) { - inQuotes = false; - } - - if (!inQuotes) { - res.add(pgmArgs.substring(begin, end).replace("\"", "")); - begin = end+1; - } - end = pgmArgs.indexOf(' ', end+1); - } - res.add(pgmArgs.substring(begin).replace("\"", "")); + ConsoleOutput output = getConsoleOutput(); - String[] args = new String[res.size()]; - res.toArray(args); - - final MessageConsole myConsole = findConsole(getConsoleName()); - Display.getDefault().syncExec(new Runnable() { - @Override - public void run() { - try { - IWorkbench wb = PlatformUI.getWorkbench(); - IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); - IWorkbenchPage page = win.getActivePage(); - String id = IConsoleConstants.ID_CONSOLE_VIEW; - IConsoleView view = (IConsoleView) page.showView(id); - view.display(myConsole); - } catch (PartInitException e) { - e.printStackTrace(); - } + List models = getModels(configuration); + Map> project2Models = GeneratorLaunchHelper.groupByProject(models); + for(Entry> entry: project2Models.entrySet()) { + + // constructing program arguments + StringBuffer argString = new StringBuffer(); + addModels(configuration, entry.getValue(), argString); + addArguments(configuration, entry.getKey(), argString); + String[] args = splitCommandLine(argString.toString()); + + output.println("\n*** generating project " + entry.getKey().getName() + " ***"); + runGenerator(args, output); + + // check for cancellation + if (monitor.isCanceled()) { + return; } - }); - MessageConsoleStream out = myConsole.newMessageStream(); - out.getConsole().clearConsole(); - ConsoleOutput output = new ConsoleOutput(out); - runGenerator(args, output); - - // check for cancellation - if (monitor.isCanceled()) { - return; } } finally { monitor.done(); @@ -166,14 +130,30 @@ public abstract class GeneratorLaunchConfigurationDelegate extends AbstractJavaL conMan.addConsoles(new IConsole[] { myConsole }); return myConsole; } + + protected ConsoleOutput getConsoleOutput() { + final MessageConsole myConsole = findConsole(getConsoleName()); + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + try { + IWorkbench wb = PlatformUI.getWorkbench(); + IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); + IWorkbenchPage page = win.getActivePage(); + String id = IConsoleConstants.ID_CONSOLE_VIEW; + IConsoleView view = (IConsoleView) page.showView(id); + view.display(myConsole); + } catch (PartInitException e) { + e.printStackTrace(); + } + } + }); + MessageConsoleStream out = myConsole.newMessageStream(); + out.getConsole().clearConsole(); + return new ConsoleOutput(out); + } - protected void addModels(ILaunchConfiguration configuration, StringBuffer argString) throws CoreException { - IStringVariableManager variableManager = VariablesPlugin.getDefault().getStringVariableManager(); - - List models = Lists.newArrayList(); - for(String model : getModels(configuration)) { - models.add(variableManager.performStringSubstitution(model)); - } + protected void addModels(ILaunchConfiguration configuration, List models, StringBuffer argString) throws CoreException { if(configuration.getAttribute(GeneratorConfigTab.GEN_DEPS_WITHIN_PROJECT, true)) { // generate all dependencies within project for .etmap models = Lists.newArrayList(GeneratorLaunchHelper.getAllDependenciesWithinProjects(models)); @@ -185,7 +165,13 @@ public abstract class GeneratorLaunchConfigurationDelegate extends AbstractJavaL @SuppressWarnings("unchecked") protected List getModels(ILaunchConfiguration configuration) throws CoreException { - return configuration.getAttribute("ModelFiles", Collections.EMPTY_LIST); + IStringVariableManager variableManager = VariablesPlugin.getDefault().getStringVariableManager(); + List models = configuration.getAttribute("ModelFiles", Collections.EMPTY_LIST); + List substitutedModels = Lists.newArrayList(); + for(String model : models) { + substitutedModels.add(variableManager.performStringSubstitution(model)); + } + return substitutedModels; } /** @@ -195,7 +181,7 @@ public abstract class GeneratorLaunchConfigurationDelegate extends AbstractJavaL * @param argString * @throws CoreException */ - protected void addArguments(ILaunchConfiguration configuration, StringBuffer argString) throws CoreException { + protected void addArguments(ILaunchConfiguration configuration, IProject project, StringBuffer argString) throws CoreException { if (configuration.getAttribute(GeneratorConfigTab.LIB, false)) { argString.append(" -"+AbstractGeneratorOptions.LIB.getName()); } @@ -229,6 +215,7 @@ public abstract class GeneratorLaunchConfigurationDelegate extends AbstractJavaL argString.append(" -"+GeneratorApplicationOptions.GEN_INCREMENTAL.getName()); } + String projectDir = project.getLocation().toString() + "/"; boolean override = configuration.getAttribute(GeneratorConfigTab.OVERRIDE_DIRECTORIES, false); String srcgenDir = prefStore.getString(PreferenceConstants.GEN_DIR); String infoDir = prefStore.getString(PreferenceConstants.GEN_INFO_DIR); @@ -236,12 +223,42 @@ public abstract class GeneratorLaunchConfigurationDelegate extends AbstractJavaL srcgenDir = configuration.getAttribute(GeneratorConfigTab.SRCGEN_PATH, srcgenDir); infoDir = configuration.getAttribute(GeneratorConfigTab.INFO_PATH, infoDir); } + argString.append(" -"+GeneratorApplicationOptions.GEN_DIR.getName()); - argString.append(" "+srcgenDir); - + argString.append(" \""+projectDir+srcgenDir+"\""); + argString.append(" -"+GeneratorApplicationOptions.GEN_INFO_DIR.getName()); - argString.append(" "+infoDir); + argString.append(" \""+projectDir+infoDir+"\""); + + } + + /** + * split at single spaces but keep strings in double quotes as single argument + * (with double quotes removed) + */ + protected String[] splitCommandLine(String cl) { + cl = cl.trim(); + ArrayList res = new ArrayList(); + int begin = 0; + int end = cl.indexOf(' '); + boolean inQuotes = false; + while (end>0) { + if (cl.charAt(begin)=='\"') + inQuotes = true; + if ((inQuotes && cl.charAt(end-1)=='\"')) { + inQuotes = false; + } + + if (!inQuotes) { + res.add(cl.substring(begin, end).replace("\"", "")); + begin = end+1; + } + end = cl.indexOf(' ', end+1); + } + res.add(cl.substring(begin).replace("\"", "")); + String[] args = new String[res.size()]; + return res.toArray(args); } /** diff --git a/plugins/org.eclipse.etrice.generator.launch/src/org/eclipse/etrice/generator/launch/GeneratorLaunchHelper.xtend b/plugins/org.eclipse.etrice.generator.launch/src/org/eclipse/etrice/generator/launch/GeneratorLaunchHelper.xtend index d96a65a66..b36048ff5 100644 --- a/plugins/org.eclipse.etrice.generator.launch/src/org/eclipse/etrice/generator/launch/GeneratorLaunchHelper.xtend +++ b/plugins/org.eclipse.etrice.generator.launch/src/org/eclipse/etrice/generator/launch/GeneratorLaunchHelper.xtend @@ -78,4 +78,11 @@ class GeneratorLaunchHelper { } ].filterNull } + + def static groupByProject(Collection files) { + val ws = ResourcesPlugin.workspace.root + val m = files.groupBy[ws.getFileForLocation(new Path(it))?.project] + m.remove(null) + return m + } } diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/AbstractGenerator.java b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/AbstractGenerator.java index 8e06a7193..ca59d6376 100644 --- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/AbstractGenerator.java +++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/AbstractGenerator.java @@ -41,9 +41,7 @@ import org.eclipse.etrice.generator.base.io.IGeneratorFileIO; import org.eclipse.etrice.generator.base.io.ILineOutput; import org.eclipse.etrice.generator.base.io.LineOutput; import org.eclipse.etrice.generator.base.logging.ILogger; -import org.eclipse.etrice.generator.base.setup.GeneratorApplicationOptions; import org.eclipse.etrice.generator.fsm.generic.IDetailCodeTranslator; -import org.eclipse.etrice.generator.generic.RoomExtensions; import org.eclipse.etrice.generator.generic.TestInstanceCreator; import com.google.inject.Inject; @@ -155,8 +153,6 @@ public abstract class AbstractGenerator implements IGenerator, IDetailCodeTransl @Override public void generate(List resources, Arguments arguments, IGeneratorFileIO fileIO, ILogger logger) { AbstractGenerator.settings = arguments; - RoomExtensions.setGenDir(arguments.get(GeneratorApplicationOptions.GEN_DIR)); - RoomExtensions.setGenInfoDir(arguments.get(GeneratorApplicationOptions.GEN_INFO_DIR)); if(resources.isEmpty()) { logger.logError("no input files"); @@ -179,6 +175,8 @@ public abstract class AbstractGenerator implements IGenerator, IDetailCodeTransl * abstract method which is finally called by {@link #createAndRunGenerator(Module, String[])} * @param resources a list of the main models * @param arguments the generator arguments + * @param fileIO the generator file io + * @param logger the logger * @return GENERATOR_OK or GENERATOR_ERROR */ protected abstract int runGenerator(List resources, Arguments arguments, IGeneratorFileIO fileIO, ILogger logger); diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/ModelLoader.java b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/ModelLoader.java index 596d8615d..3a1c657a7 100644 --- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/ModelLoader.java +++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/ModelLoader.java @@ -73,6 +73,7 @@ public class ModelLoader implements IGeneratorResourceLoader { public List load(List files, Arguments arguments, ILogger logger) { if(!initializedEMF) { emfSetup.doEMFRegistration(); + initializedEMF = true; } logger.logInfo("-- reading models"); @@ -83,6 +84,8 @@ public class ModelLoader implements IGeneratorResourceLoader { return resources; } else { + logger.logError("reading models failed"); + logger.logInfo("-- terminating"); throw new GeneratorException("reading models failed"); } } diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/ModelValidator.java b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/ModelValidator.java index ce905492f..a078837d8 100644 --- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/ModelValidator.java +++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/ModelValidator.java @@ -43,12 +43,18 @@ public class ModelValidator extends GeneratorResourceValidator { if(!resources.isEmpty()) { ResourceSet rs = resources.get(0).getResourceSet(); if(rs != null) { - super.validate(rs.getResources(), arguments, logger); - return; + resources = rs.getResources(); } } - super.validate(resources, arguments, logger); + try { + super.validate(resources, arguments, logger); + } + catch(Exception e) { + logger.logError("validation failed"); + logger.logInfo("-- terminating"); + throw e; + } } } diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/PrepareFileSystem.xtend b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/PrepareFileSystem.xtend index 4fb52e43b..23cf8f283 100644 --- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/PrepareFileSystem.xtend +++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/PrepareFileSystem.xtend @@ -16,95 +16,21 @@ package org.eclipse.etrice.generator.generic import com.google.inject.Inject import com.google.inject.Singleton -import java.io.File -import java.util.Collection -import java.util.HashSet -import java.util.Set -import org.eclipse.emf.ecore.resource.Resource -import org.eclipse.etrice.core.genmodel.etricegen.Root -import org.eclipse.xtext.generator.JavaIoFileSystemAccess -import org.eclipse.etrice.generator.base.logging.ILogger -import org.eclipse.etrice.generator.base.AbstractGenerator -import org.eclipse.etrice.generator.base.setup.GeneratorApplicationOptions +import org.eclipse.etrice.generator.base.io.IGeneratorFileIO /** - * A class that is used to recursively erase all folders receiving generated code - * an to place a readme file into those folders. + * A class that is used to place a readme file in the generation directory. */ @Singleton class PrepareFileSystem { - @Inject extension RoomExtensions - @Inject JavaIoFileSystemAccess fileAccess - @Inject ILogger logger - - def void prepareCodeTargetPaths(Resource resource) { - var Set pathes = new HashSet(); - for (e: resource.contents){ - if (e instanceof Root) { - for (mdl : (e as Root).models) { - val tgtpath = mdl.generationTargetPath - if (tgtpath!==null && !tgtpath.empty) - pathes.add(tgtpath) - } - } - } - prepare(pathes) - } - - def void prepareInfoTargetPaths(Resource resource) { - if(!AbstractGenerator.settings.get(GeneratorApplicationOptions.GEN_INCREMENTAL)) - return; - - var Set pathes = new HashSet(); - for (e: resource.contents){ - if (e instanceof Root) { - for (mdl : (e as Root).models) { - val tgtpath = mdl.generationInfoPath - if (tgtpath!==null && !tgtpath.empty) - pathes.add(tgtpath) - } - } - } - pathes.forEach[ path | - fileAccess.setOutputPath(path) - fileAccess.generateFile("readme.txt", ''' - This directory is an eTrice code generation target. - It contains auxiliary files for the incremental generation feature. - - DO NOT MODIFY THIS PLACE! - ''') - ] - } + @Inject IGeneratorFileIO fileIO /** - * Recursively erase all folders receiving generated code - * and place a readme file in those folders. - * The folders are determined from the used models of every generator - * model found in the resource. - * - * @param resource a {@link Resource} + * Place a readme.txt in the generation directory. */ - def void prepare(Collection pathes) { - for (path : pathes) { - logger.logInfo("clearing "+path) - var f = new File(path) - f.eraseContents - fileAccess.setOutputPath(path) - fileAccess.generateFile("readme.txt", readmeText) - } - } - - def private void eraseContents(File f) { - if (f.directory) { - var children = f.listFiles - for (child : children) { - if (!(child.directory && child.name.equals("images"))) { - eraseContents(child) - child.delete - } - } - } + def void prepare() { + fileIO.generateFile("readme.txt", readmeText) } def private readmeText() { diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/RoomExtensions.xtend b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/RoomExtensions.xtend index 0a259aed1..e6e16c013 100644 --- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/RoomExtensions.xtend +++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/RoomExtensions.xtend @@ -40,7 +40,6 @@ import org.eclipse.etrice.core.room.SAP import org.eclipse.etrice.core.room.SPP import org.eclipse.etrice.core.room.ServiceImplementation import org.eclipse.etrice.core.room.util.RoomHelpers -import org.eclipse.etrice.generator.fsm.base.FileSystemHelpers import org.eclipse.etrice.generator.fsm.generic.FSMExtensions import java.util.Collections @@ -52,24 +51,8 @@ class RoomExtensions extends FSMExtensions { public val NEWLINE = System.getProperty("line.separator") - private static String genDir = "/src-gen/" - private static String genInfoDir = "/src-gen-info/" - @Inject protected extension RoomHelpers - def static setDefaultGenDir() { - genDir = "/src-gen/" - } - def static setDefaultGenInfoDir() { - genInfoDir = "/src-gen-info/" - } - def static setGenDir(String dir) { - genDir = "/"+dir+"/" - } - def static setGenInfoDir(String dir) { - genInfoDir = "/"+dir+"/" - } - //------------------------------------------------------- // union methods @@ -89,20 +72,6 @@ class RoomExtensions extends FSMExtensions { //------------------------------------------------------- // path related methods - /** - * @return the relative path to the destination folder for the generated code - */ - def String getGenerationPathSegment() { - genDir - } - - /** - * @return the relative path to the destination folder for the generated code - */ - def String getGenerationInfoSegment() { - genInfoDir - } - /** * @param e an {@link EObject} * @return the URI of the EObject's resource as file string @@ -118,7 +87,6 @@ class RoomExtensions extends FSMExtensions { } } - //------------------------------------------------------- // packages and paths @@ -155,38 +123,6 @@ class RoomExtensions extends FSMExtensions { getPathFromPackage(getPackage(rc)) } - // a directory is a eclipse project if it contains a ".project" file - /** - * @param e an {@link EObject} - * @return the path of the Eclipse project containing the EObject's resource - */ - def String getProjectPath(EObject e) { - val res = FileSystemHelpers::getProjectURI(e) - if (res===null) { - return "" - } - - return res.toFileString - } - - /** - * @param e an {@link EObject} - * @return the concatenation of the object's project path - * with the {@link #getGenerationPathSegment()} - */ - def String getGenerationTargetPath(EObject e){ - return getProjectPath(e)+getGenerationPathSegment() - } - - /** - * @param e an {@link EObject} - * @return the concatenation of the object's project path - * with the {@link #getGenerationInfoSegment()} - */ - def String getGenerationInfoPath(EObject e){ - return getProjectPath(e)+getGenerationInfoSegment() - } - /** * makes a valid identifier from a path string * @param path a slash (/) separated path -- cgit v1.2.3