浏览代码

Issue 1645 (#1683)

* Add Outlet/skipLibraryFiles to sgen lib

* Add skipLibraryFiles to C generator

* Add skipLibraryFiles to Java generator

* Remove xtend-gen contents

* Add xtend-gen to global .gitignore

* Add skipLibraryFiles to C++ generator

* Doc for new outlet parameter skipLibraryFiles

* added xtend plugin to maven config

* Revert 5c2c330 & 4c50874 - turns out /xtend-gen/ is needed.
Rene Beckmann 7 年之前
父节点
当前提交
687a8a99c4

+ 1 - 0
plugins/org.yakindu.sct.doc.user/src/user-guide/generating_code.textile

@@ -159,6 +159,7 @@ The *Outlet* feature specifies target project and target folder for the generate
 * _targetFolder_ (String, required): The folder within the _target folder_ to write the generated artifacts to. If a _library target folder_ (see below) is specified, only the model-dependent artifacts are generated in the _target folder_. All artifacts in this folder will be overwritten during re-generation.
 * _libraryTargetFolder_ (String, optional): The folder to write the model-independent artifacts to. If this parameter is not specified, these artifacts will be generated in the _target folder_ (see above). All artifacts in this folder will be preserved during re-generation. Manual modifications of these artifacts will _not_ be overwritten upon re-generation.
 * _apiTargetFolder_ (String, optional): The folder to write API code to, e.g. interfaces or header files. If this parameter is not specified, these artifacts will be generated in the _target folder_ (see above).
+* _skipLibraryFiles_ (Boolean, optional): If you wish to exclude the static files from the code generation, i.e. those that are put into the _libraryTargetFolder_, you can set this value to _true_. If the value is _false_ or not specified at all, the files are generated as usual. Currently supported for the Java, C and C++ generators.
 
 ==<div class="example">==
 

+ 16 - 16
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/CGenerator.xtend

@@ -13,16 +13,12 @@ package org.yakindu.sct.generator.c
 import com.google.inject.Inject
 import org.eclipse.xtext.generator.IFileSystemAccess
 import org.yakindu.sct.generator.c.IGenArtifactConfigurations.GenArtifactConfiguration
-import org.yakindu.sct.generator.c.eventdriven.StatechartEventsHeader
-import org.yakindu.sct.generator.c.eventdriven.StatechartEventsSource
 import org.yakindu.sct.generator.core.IExecutionFlowGenerator
 import org.yakindu.sct.generator.core.library.ICoreLibraryHelper
 import org.yakindu.sct.model.sexec.ExecutionFlow
 import org.yakindu.sct.model.sgen.GeneratorEntry
-import org.yakindu.sct.model.sgraph.Statechart
 
 import static org.yakindu.sct.generator.core.filesystem.ISCTFileSystemAccess.*
-import static org.yakindu.sct.model.stext.lib.StatechartAnnotations.EVENT_DRIVEN_ANNOTATION
 
 /**
  * This is the C code generators main class. 
@@ -30,7 +26,7 @@ import static org.yakindu.sct.model.stext.lib.StatechartAnnotations.EVENT_DRIVEN
  * @author Axel Terfloth
  */
 class CGenerator implements IExecutionFlowGenerator {
-	
+
 	@Inject extension Types types
 	@Inject extension StatemachineHeader statemachineHeader
 	@Inject extension StatemachineSource statemachineSource
@@ -42,27 +38,31 @@ class CGenerator implements IExecutionFlowGenerator {
 
 	@Inject
 	IGenArtifactConfigurations configs
-	
+
 	override generate(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
 		initGenerationArtifacts(flow, entry, configs)
 		generateArtifacts(flow, entry, fsa, configs)
 	}
-	
-	def generateArtifacts(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa, IGenArtifactConfigurations locations) {
+
+	def generateArtifacts(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa,
+		IGenArtifactConfigurations locations) {
 		for (GenArtifactConfiguration a : locations.configurations) {
-			fsa.generateFile(a.getName, a.getOutputName, a.getContentTemplate.content(flow, entry, locations))
+			if (!a.skip) {
+				fsa.generateFile(a.getName, a.getOutputName, a.getContentTemplate.content(flow, entry, locations))
+			}
 		}
 	}
-	
-	def protected initGenerationArtifacts(ExecutionFlow it, GeneratorEntry entry, IGenArtifactConfigurations locations) {
-		locations.configure(flow.typesModule.h, entry.libraryOutput, types)
+
+	def protected initGenerationArtifacts(ExecutionFlow it, GeneratorEntry entry,
+		IGenArtifactConfigurations locations) {
+		locations.configure(flow.typesModule.h, entry.libraryOutput, types, getSkipLibraryFiles(entry))
 		locations.configure(flow.module.h, entry.headerOutput, statemachineHeader)
 		locations.configure(flow.module.c, entry.sourceOutput, statemachineSource)
 		if (flow.timed || !flow.operations.empty || entry.tracingEnterState || entry.tracingExitState) {
 			locations.configure(flow.module.client.h, entry.headerOutput, statemachineRequiredHeader)
 		}
 	}
-	
+
 	def protected getHeaderOutput(GeneratorEntry entry) {
 		if (entry.apiTargetFolderValue != null) {
 			API_TARGET_FOLDER_OUTPUT
@@ -78,9 +78,9 @@ class CGenerator implements IExecutionFlowGenerator {
 			entry.headerOutput
 		}
 	}
-	
+
 	def protected getSourceOutput(GeneratorEntry entry) {
 		TARGET_FOLDER_OUTPUT
 	}
-	
-}
+
+}

+ 6 - 1
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/DefaultGenArtifactConfigurations.java

@@ -44,7 +44,12 @@ public class DefaultGenArtifactConfigurations implements IGenArtifactConfigurati
 
 	@Override
 	public void configure(String artifactName, String outputConfigName, IContentTemplate contentTemplate) {
-		generationArtifacts.add(new GenArtifactConfiguration(artifactName, outputConfigName, contentTemplate));
+		configure(artifactName, outputConfigName, contentTemplate, false);
+	}
+	
+	@Override
+	public void configure(String artifactName, String outputConfigName, IContentTemplate contentTemplate, boolean skip) {
+		generationArtifacts.add(new GenArtifactConfiguration(artifactName, outputConfigName, contentTemplate, skip));
 	}
 
 	protected URI getOutputFolder(String artifactName) {

+ 16 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/IGenArtifactConfigurations.java

@@ -30,6 +30,11 @@ public interface IGenArtifactConfigurations {
 	 */
 	void configure(String artifactName, String outputConfigName, IContentTemplate contentTemplate);
 
+	/**
+	 * Adds a configuration for a generation artifact.
+	 */
+	void configure(String artifactName, String outputConfigName, IContentTemplate contentTemplate, boolean skip);
+
 	/**
 	 * @return all stored configurations
 	 */
@@ -47,11 +52,18 @@ public interface IGenArtifactConfigurations {
 		private String outputName;
 		private String name;
 		private IContentTemplate contentTemplate;
+		
+		private boolean skip;
 
 		public GenArtifactConfiguration(String name, String outputConfigName, IContentTemplate contentTemplate) {
+			this(name, outputConfigName, contentTemplate, false);
+		}
+		
+		public GenArtifactConfiguration(String name, String outputConfigName, IContentTemplate contentTemplate, boolean skip) {
 			this.name = name;
 			this.outputName = outputConfigName;
 			this.contentTemplate = contentTemplate;
+			this.skip = skip;
 		}
 
 		public String getName() {
@@ -65,6 +77,10 @@ public interface IGenArtifactConfigurations {
 		public IContentTemplate getContentTemplate() {
 			return contentTemplate;
 		}
+		
+		public boolean getSkip() {
+			return skip;
+		}
 	}
 
 }

+ 48 - 12
plugins/org.yakindu.sct.generator.core/library/CoreFeatureTypeLibrary.xmi

@@ -17,24 +17,60 @@
         name="apiTargetFolder"
         comment="A distinct output folder for API code artifacts. If not specified, the code will be generated into the target folder."
         optional="true"/>
+    <parameters
+        name="skipLibraryFiles"
+        comment="Allows to skip the generation of everything that belongs into the libraryTargetFolder"
+        optional="true"
+        parameterType="BOOLEAN"/>
   </types>
   <types name="LicenseHeader"
       optional="true">
     <parameters
         name="licenseText"/>
   </types>
-   <types name="Debug" optional="true">
-    <parameters name="dumpSexec" parameterType="BOOLEAN"/>
+  <types name="Debug"
+      optional="true">
+    <parameters
+        name="dumpSexec"
+        parameterType="BOOLEAN"/>
   </types>
-  <types name="FunctionInlining" optional="true">
-    <parameters name="inlineReactions" optional="true" parameterType="BOOLEAN"/>
-    <parameters name="inlineEntryActions" optional="true" parameterType="BOOLEAN"/>
-    <parameters name="inlineExitActions" optional="true" parameterType="BOOLEAN"/>
-    <parameters name="inlineEnterSequences" optional="true" parameterType="BOOLEAN"/>
-    <parameters name="inlineExitSequences" optional="true" parameterType="BOOLEAN"/>
-    <parameters name="inlineChoices" optional="true" parameterType="BOOLEAN"/>
-    <parameters name="inlineEnterRegion" optional="true" parameterType="BOOLEAN"/>
-    <parameters name="inlineExitRegion" optional="true" parameterType="BOOLEAN"/>
-    <parameters name="inlineEntries" optional="true" parameterType="BOOLEAN"/>
+  <types name="FunctionInlining"
+      optional="true">
+    <parameters
+        name="inlineReactions"
+        optional="true"
+        parameterType="BOOLEAN"/>
+    <parameters
+        name="inlineEntryActions"
+        optional="true"
+        parameterType="BOOLEAN"/>
+    <parameters
+        name="inlineExitActions"
+        optional="true"
+        parameterType="BOOLEAN"/>
+    <parameters
+        name="inlineEnterSequences"
+        optional="true"
+        parameterType="BOOLEAN"/>
+    <parameters
+        name="inlineExitSequences"
+        optional="true"
+        parameterType="BOOLEAN"/>
+    <parameters
+        name="inlineChoices"
+        optional="true"
+        parameterType="BOOLEAN"/>
+    <parameters
+        name="inlineEnterRegion"
+        optional="true"
+        parameterType="BOOLEAN"/>
+    <parameters
+        name="inlineExitRegion"
+        optional="true"
+        parameterType="BOOLEAN"/>
+    <parameters
+        name="inlineEntries"
+        optional="true"
+        parameterType="BOOLEAN"/>
   </types>
 </sgen:FeatureTypeLibrary>

+ 1 - 0
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/library/ICoreLibraryConstants.java

@@ -23,6 +23,7 @@ public interface ICoreLibraryConstants {
 	String OUTLET_FEATURE_TARGET_FOLDER = "targetFolder";
 	String OUTLET_FEATURE_LIBRARY_TARGET_FOLDER = "libraryTargetFolder";
 	String OUTLET_FEATURE_API_TARGET_FOLDER = "apiTargetFolder";
+	String OUTLET_FEATURE_SKIP_LIBRARY_FILES = "skipLibraryFiles";
 	String LICENSE_HEADER = "LicenseHeader";
 	String LICENSE_TEXT = "licenseText";
 

+ 7 - 0
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/library/ICoreLibraryHelper.java

@@ -50,6 +50,13 @@ public interface ICoreLibraryHelper {
 	 * @return the project value
 	 */
 	FeatureParameterValue getTargetProjectValue(GeneratorEntry entry);
+	/**
+	 * The skipLibraryFiles defined in sgen - allows to skip everything that belongs 
+	 * in libraryTargetFolder
+	 * @param entry
+	 * @return the skipLibraryFiles value
+	 */
+	boolean getSkipLibraryFiles(GeneratorEntry entry);
 	/**
 	 * Convenience to combine targetProject & targetFolder values defined in SGen.
 	 * @param entry

+ 8 - 0
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/library/impl/DefaultCoreLibraryHelper.java

@@ -17,6 +17,7 @@ import static org.yakindu.sct.generator.core.library.ICoreLibraryConstants.OUTLE
 import static org.yakindu.sct.generator.core.library.ICoreLibraryConstants.OUTLET_FEATURE_LIBRARY_TARGET_FOLDER;
 import static org.yakindu.sct.generator.core.library.ICoreLibraryConstants.OUTLET_FEATURE_TARGET_FOLDER;
 import static org.yakindu.sct.generator.core.library.ICoreLibraryConstants.OUTLET_FEATURE_TARGET_PROJECT;
+import static org.yakindu.sct.generator.core.library.ICoreLibraryConstants.OUTLET_FEATURE_SKIP_LIBRARY_FILES;
 
 import org.eclipse.core.runtime.Path;
 import org.yakindu.sct.generator.core.library.ICoreLibraryHelper;
@@ -77,4 +78,11 @@ public class DefaultCoreLibraryHelper implements ICoreLibraryHelper {
 		}
 		return dumpSexec.getBooleanValue();
 	}
+
+	@Override
+	public boolean getSkipLibraryFiles(GeneratorEntry entry) {
+		FeatureParameterValue skipLibraryFiles = entry.getFeatureParameterValue(
+				OUTLET_FEATURE, OUTLET_FEATURE_SKIP_LIBRARY_FILES);
+		return skipLibraryFiles == null ? false : skipLibraryFiles.getBooleanValue();
+	}
 }

+ 9 - 5
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/CppGenerator.xtend

@@ -51,17 +51,21 @@ class CppGenerator implements IExecutionFlowGenerator {
 	def generateArtifacts(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa,
 		IGenArtifactConfigurations locations) {
 		for (GenArtifactConfiguration a : locations.configurations) {
-			fsa.generateFile(a.getName, a.getOutputName, a.getContentTemplate.content(flow, entry, locations))
+			if (!a.skip) {
+				fsa.generateFile(a.getName, a.getOutputName, a.getContentTemplate.content(flow, entry, locations))
+			}
 		}
 	}
 
 	def initGenerationArtifacts(ExecutionFlow flow, GeneratorEntry entry, IGenArtifactConfigurations locations) {
-		locations.configure(flow.typesModule.h, entry.libraryOutput, typesContent)
-		locations.configure(statemachineInterface.h, entry.libraryOutput, statemachineInterfaceContent)
+		locations.configure(flow.typesModule.h, entry.libraryOutput, typesContent, entry.skipLibraryFiles)
+		locations.configure(statemachineInterface.h, entry.libraryOutput, statemachineInterfaceContent,
+			entry.skipLibraryFiles)
 
 		if (flow.timed) {
-			locations.configure(timedStatemachineInterface.h, entry.libraryOutput, timedStatemachineInterfaceContent)
-			locations.configure(timerInterface.h, entry.libraryOutput, timerInterfaceContent)
+			locations.configure(timedStatemachineInterface.h, entry.libraryOutput, timedStatemachineInterfaceContent,
+				entry.skipLibraryFiles)
+			locations.configure(timerInterface.h, entry.libraryOutput, timerInterfaceContent, entry.skipLibraryFiles)
 		}
 
 		locations.configure(flow.module.h, entry.headerOutput, statemachineHeaderContent)

+ 3 - 0
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/IStatemachine.xtend

@@ -27,6 +27,9 @@ class IStatemachine {
 	@Inject ICoreLibraryHelper outletFeatureHelper
 	 
 	def generateIStatemachine(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
+		if(outletFeatureHelper.getSkipLibraryFiles(entry)) {
+			return
+		}
 		if (outletFeatureHelper.getLibraryTargetFolderValue(entry) != null) {
 			// generate into library target folder in case one is specified, as the contents are static
 			fsa.generateFile(entry.basePackagePath + '/' + iStatemachine.java,

+ 3 - 0
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/ITimer.xtend

@@ -28,6 +28,9 @@ class ITimer {
 	@Inject ICoreLibraryHelper outletFeatureHelper
 	
 	def generateITimer(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
+		if(outletFeatureHelper.getSkipLibraryFiles(entry)) {
+			return
+		}
 		if (outletFeatureHelper.getLibraryTargetFolderValue(entry) !== null) {
 			// generate into library target folder in case one is specified, as the contents are static
 			fsa.generateFile(entry.basePackagePath + '/' + iTimer.java,

+ 3 - 0
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/ITimerCallback.xtend

@@ -27,6 +27,9 @@ class ITimerCallback {
 	@Inject ICoreLibraryHelper outletFeatureHelper
 
 	def generateITimerCallback(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
+		if(outletFeatureHelper.getSkipLibraryFiles(entry)) {
+			return
+		}
 		if (outletFeatureHelper.getLibraryTargetFolderValue(entry) !== null) {
 			// generate into library target folder in case one is specified, as the contents are static
 			fsa.generateFile(entry.basePackagePath + '/' + iTimerCallback.java, LIBRARY_TARGET_FOLDER_OUTPUT,