瀏覽代碼

#366 : migrated AbstractWorkspaceGenerator to get Xtend, Java & Xpand
sample generators running again

Johannes Dicks 9 年之前
父節點
當前提交
340dfda2c8

+ 24 - 5
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/AbstractWorkspaceGenerator.java

@@ -12,6 +12,7 @@ package org.yakindu.sct.generator.core;
 
 import java.io.File;
 
+import org.eclipse.emf.common.util.URI;
 import org.yakindu.sct.generator.core.impl.AbstractSExecModelGenerator;
 import org.yakindu.sct.model.sgen.GeneratorEntry;
 
@@ -19,23 +20,41 @@ import org.yakindu.sct.model.sgen.GeneratorEntry;
  * Base class for generators that are executed inside the workspace
  * 
  * @author holger willebrandt - Initial contribution and API
+ * @author Johannes Dicks - refactored because of EFS decoupling
  */ 
-//FIXME !!! used in generator runtime samples (Xtend2 & Java, see e.g. org.yakindu.sct.generator.genmodel.ui.wizard.GeneratorProjectTemplate)
 public abstract class AbstractWorkspaceGenerator extends AbstractSExecModelGenerator {
 	
+	/**
+	 * 
+	 * @param entry
+	 * @deprecated Will be removed in future. Refreshing the project is moved to concrete file system access implementations 
+	 */
+	@Deprecated
 	public final void refreshTargetProject(GeneratorEntry entry) {
-		throw new UnsupportedOperationException("implement me!");
+		/**
+		 * This functionality will be provided by concrete file system accesses from now.
+		 */
 	}
 
 	public final File getTargetProject(GeneratorEntry entry) {
-		throw new UnsupportedOperationException("implement me!");
+		URI uri = sctFileSystemAccess.getURI(outletFeatureHelper.getTargetProjectValue(entry).getStringValue());
+		return new File(uri.toFileString());
 	}
 
 	public final File getTargetFolder(GeneratorEntry entry) {
-		throw new UnsupportedOperationException("implement me!");
+		URI uri = sctFileSystemAccess.getURI(outletFeatureHelper.getRelativeTargetFolder(entry));
+		return new File(uri.toFileString());
 	}
 	
 	public final File getLibraryTargetFolder(GeneratorEntry entry) {
-		throw new UnsupportedOperationException("implement me!");
+		URI uri = sctFileSystemAccess.getURI(outletFeatureHelper.getRelativeLibraryFolder(entry));
+		return new File(uri.toFileString());
+	}
+	
+	public final void writeToConsole(String line){
+		log.writeToConsole(line);
+	}
+	public final void writeToConsole(Throwable e){
+		log.writeToConsole(e);
 	}
 }

+ 9 - 9
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/filesystem/EFSResourceFileSystemAccess.java

@@ -31,27 +31,27 @@ public class EFSResourceFileSystemAccess extends EclipseResourceFileSystemAccess
 	@Override
 	public void setOutputPath(String outputName, String path) {
 		super.setOutputPath(outputName, path);
-		// FIXME !!! ??? setting the targetProject has to be done firstly
-		trySetTargetProject(outputName, path);
+		boolean isTargetProject = trySetTargetProject(outputName, path);
 		// otherwise java classpath extension will fail, MSG?
-			IProject project = getProject();
-			if (isValidProject(project)) {
-				// FIXME !!! should be handled if and only of java/xtend is generated?!
-				if (hasJavaNature(project) && hasClasspath(project)) {
-					new ClasspathChanger().addFolderToClassPath(project, path);
-				}
+		IProject project = getProject();
+		if (!isTargetProject && isValidProject(project)) {
+			if (hasJavaNature(project) && hasClasspath(project)) {
+				new ClasspathChanger().addFolderToClassPath(project, path);
 			}
+		}
 	}
 
 
-	protected void trySetTargetProject(String outputName, String path) {
+	protected boolean trySetTargetProject(String outputName, String path) {
 		if (outputName.equals(ICoreFeatureConstants.OUTLET_FEATURE_TARGET_PROJECT)) {
 			IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path);
 			if (!project.exists()) {
 				createProject(project);
 			}
 			setProject(project);
+			return true;
 		}
+		return false;
 	}
 
 	protected boolean isValidProject(IProject project) {

+ 25 - 1
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/library/IOutletFeatureHelper.java

@@ -21,10 +21,34 @@ import org.yakindu.sct.model.sgen.GeneratorEntry;
  *
  */
 public interface IOutletFeatureHelper {
+	/**
+	 * The targetFolder value defined in SGen.
+	 * @param entry
+	 * @return the target folder value
+	 */
 	FeatureParameterValue getTargetFolderValue(GeneratorEntry entry);
+	/**
+	 * The libraryFolder value defined in SGen.
+	 * @param entry
+	 * @return the library target folder value
+	 */
 	FeatureParameterValue getLibraryTargetFolderValue(GeneratorEntry entry);
+	/**
+	 * The project value defined in SGen.
+	 * @param entry
+	 * @return the project value
+	 */
 	FeatureParameterValue getTargetProjectValue(GeneratorEntry entry);
+	/**
+	 * Convenience to combine targetProject & targetFolder values defined in SGen.
+	 * @param entry
+	 * @return a string representing the relative output path 'targetProject/targetFolder'
+	 */
 	String getRelativeTargetFolder(GeneratorEntry entry);
+	/**
+	 * Convenience to combine targetProject & libraryTargetFolder values defined in SGen.
+	 * @param entry
+	 * @return a string representing the relative output path 'targetProject/libraryTargetFolder'
+	 */
 	String getRelativeLibraryFolder(GeneratorEntry entry);
-
 }

+ 19 - 30
plugins/org.yakindu.sct.generator.genmodel.ui/src/org/yakindu/sct/generator/genmodel/ui/wizard/GeneratorProjectTemplate.xtend

@@ -8,23 +8,23 @@
  * 	committers of YAKINDU - initial API and implementation
  * 
  */ 
-package org.yakindu.sct.generator.genmodel.ui.wizard
-
-import java.io.BufferedInputStream
-import java.io.ByteArrayInputStream
-import java.io.ByteArrayOutputStream
-import java.util.Collections
-import org.apache.commons.lang.StringEscapeUtils
-import org.eclipse.core.resources.IContainer
-import org.eclipse.core.resources.IFile
-import org.eclipse.core.resources.IFolder
-import org.eclipse.core.resources.IResource
-import org.eclipse.core.runtime.IProgressMonitor
-import org.eclipse.core.runtime.Path
-import org.eclipse.core.runtime.SubProgressMonitor
-import org.eclipse.emf.common.util.URI
-import org.eclipse.emf.ecore.EObject
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
+package org.yakindu.sct.generator.genmodel.ui.wizard
+
+import java.io.BufferedInputStream
+import java.io.ByteArrayInputStream
+import java.io.ByteArrayOutputStream
+import java.util.Collections
+import org.apache.commons.lang.StringEscapeUtils
+import org.eclipse.core.resources.IContainer
+import org.eclipse.core.resources.IFile
+import org.eclipse.core.resources.IFolder
+import org.eclipse.core.resources.IResource
+import org.eclipse.core.runtime.IProgressMonitor
+import org.eclipse.core.runtime.Path
+import org.eclipse.core.runtime.SubProgressMonitor
+import org.eclipse.emf.common.util.URI
+import org.eclipse.emf.ecore.EObject
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
 import org.yakindu.sct.model.sgen.ParameterTypes
 import org.yakindu.sct.model.sgen.SGenFactory
 import com.google.inject.Provider
@@ -441,8 +441,7 @@ class GeneratorProjectTemplate {
 		class «data.generatorClass.simpleName» extends AbstractWorkspaceGenerator implements IExecutionFlowGenerator {
 		
 			override generate(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess access) {
-				entry.targetFolder.write(flow.name+'.txt',flow.info)
-				refreshTargetProject(entry)
+				access.generateFile(flow.name+'.txt',flow.info);
 			}
 		
 			def info(ExecutionFlow flow) {''«"'"»
@@ -453,17 +452,7 @@ class GeneratorProjectTemplate {
 				«'«'»FOR ExecutionState state : flow.states»
 					«'«'»state.name.replaceFirst(flow.name+'\\.','')»
 				«'«'»ENDFOR»
-			''«"'"».toString}
-		
-			def write(File dir, String filename, String content) {
-				try {
-					dir.mkdirs
-					val bos = new FileOutputStream(new File(dir.path+File::separator+filename))
-					bos.write(content.bytes)
-					bos.close
-				} catch(Exception e) {
-					writeToConsole(e)
-				}
+			''«"'"».toString
 			}
 		}
 	'''