Преглед изворни кода

Merge pull request #449 from Yakindu/issue_366

Issue 366
jdicks пре 9 година
родитељ
комит
a2b96f0b17

+ 11 - 2
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/filesystem/ISCTFileSystemAccess.java

@@ -45,8 +45,17 @@ public interface ISCTFileSystemAccess {
 	 * @param outletFeatureTargetProject
 	 * @param stringValue
 	 */
-	void setOutputPath(String outputName, String path);
-
+	void setOutputPath(String outputName, String relativePath);
+	
+	/**
+	 * Set the default output path.
+	 * 
+	 * @param relativePath
+	 * @see IFileSystemAccess#DEFAULT_OUTPUT
+	 */
+	void setOutputPath(String relativePath);
+	
+	
 	Map<String, OutputConfiguration> getOutputConfigurations();
 	/**
 	 * For convenience... and compatibility reasons, might be removed in further

+ 40 - 15
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/impl/AbstractSGraphModelGenerator.java

@@ -63,12 +63,13 @@ public abstract class AbstractSGraphModelGenerator implements ISCTGenerator {
 	}
 
 	/**
-	 * This method should not be overridden anymore. It is meant to do
-	 * initializations which are urgently needed for the generator
-	 * infrastructure. Use {@link #doGenerate(GeneratorEntry)} instead.
+	 * This method should not be overridden anymore. It is meant to define a
+	 * general process all generators might follow.
 	 * 
-	 * This method might become final in further versions. Please
-	 *             override {@link #doGenerate(GeneratorEntry)}
+	 * Use {@link #doGenerate(GeneratorEntry)} instead.
+	 * 
+	 * This method might become final in further versions. Please override
+	 * {@link #doGenerate(GeneratorEntry)}
 	 * 
 	 * @see {@link #doGenerate(GeneratorEntry)}
 	 */
@@ -115,8 +116,8 @@ public abstract class AbstractSGraphModelGenerator implements ISCTGenerator {
 	 * includes a {@link Statechart}. Sub-classes may override this method if
 	 * they handle elements with type other than @link {@link Statechart}.
 	 * 
-	 * @param entry
-	 * @return
+	 * @param entry the upcomming GeneratorEntry
+	 * @return true if this instance can handle the given {@link GeneratorEntry}
 	 */
 	protected boolean canHandle(GeneratorEntry entry) {
 		EObject elementRef = entry.getElementRef();
@@ -145,7 +146,9 @@ public abstract class AbstractSGraphModelGenerator implements ISCTGenerator {
 
 	/**
 	 * Sub-classes might override this method to add custom bindings for a
-	 * specific {@link GeneratorEntry}. In normal case sub-classes will just
+	 * specific {@link GeneratorEntry}. 
+	 * 
+	 * In normal case sub-classes will just
 	 * override or add custom bindings and ensure all other bindings of
 	 * super-class implementations are still available.
 	 * 
@@ -164,16 +167,29 @@ public abstract class AbstractSGraphModelGenerator implements ISCTGenerator {
 	}
 
 	/**
-	 * Provides a pre configured IFileSystemAccess instance
+	 * Initialize the current file system access through generated files are
+	 * written to a particular target location.
+	 * 
+	 * In case of overriding this method it has to be ensured that at least
+	 * {@link IFileSystemAccess#DEFAULT_OUTPUT} will be initialized. Dependent
+	 * on usage of FSA functionality
+	 * <ul>
+	 * <li>{@link IFileSystemAccess#generateFile(String, CharSequence)}</li>
+	 * <li>{@link IFileSystemAccess#generateFile(String, String, CharSequence)}
+	 * </li>
+	 * </ul>
+	 * Optional output configurations has to be registered. How output
+	 * configurations are interpreted is defined by the concrete FSA
+	 * implementation.
 	 */
 	protected IFileSystemAccess initFileSystemAccess(GeneratorEntry entry) {
 
 		// set target project value
-		sctFsa.setOutputPath(ICoreFeatureConstants.OUTLET_FEATURE_TARGET_PROJECT,
-				outletFeatureHelper.getTargetProjectValue(entry).getStringValue());
+		//NOTE: this is urgently necessary for EFS based IFileSystemAcccess for now
+		initFsaTargetProject(entry);
 		// set target folder
-		sctFsa.setOutputPath(IFileSystemAccess.DEFAULT_OUTPUT,
-				outletFeatureHelper.getTargetFolderValue(entry).getExpression().toString());
+		String defaultOutput = outletFeatureHelper.getTargetFolderValue(entry).getExpression().toString();
+		initDefaultOutput(defaultOutput);
 
 		FeatureParameterValue libraryTargetFolderValue = outletFeatureHelper.getLibraryTargetFolderValue(entry);
 
@@ -182,7 +198,6 @@ public abstract class AbstractSGraphModelGenerator implements ISCTGenerator {
 					libraryTargetFolderValue.getExpression().toString());
 		}
 
-		sctFsa.getOutputConfigurations().get(IFileSystemAccess.DEFAULT_OUTPUT).setCreateOutputDirectory(true);
 		OutputConfiguration librarytargetFolderOutputConfiguration = sctFsa.getOutputConfigurations()
 				.get(IExecutionFlowGenerator.LIBRARY_TARGET_FOLDER_OUTPUT);
 		if (librarytargetFolderOutputConfiguration != null) {
@@ -192,7 +207,17 @@ public abstract class AbstractSGraphModelGenerator implements ISCTGenerator {
 			librarytargetFolderOutputConfiguration.setCanClearOutputDirectory(false);
 			librarytargetFolderOutputConfiguration.setOverrideExistingResources(false);
 		}
-
 		return sctFsa.getIFileSystemAccess();
 	}
+
+	protected void initDefaultOutput(String defaultOutput) {
+		sctFsa.setOutputPath(IFileSystemAccess.DEFAULT_OUTPUT,
+				defaultOutput);
+		sctFsa.getOutputConfigurations().get(IFileSystemAccess.DEFAULT_OUTPUT).setCreateOutputDirectory(true);
+	}
+
+	protected void initFsaTargetProject(GeneratorEntry entry) {
+		sctFsa.setOutputPath(ICoreFeatureConstants.OUTLET_FEATURE_TARGET_PROJECT,
+				outletFeatureHelper.getTargetProjectValue(entry).getStringValue());
+	}
 }