Browse Source

#162 : a sample of SCT code generation from pure java application

Johannes Dicks 9 years ago
parent
commit
b0941afa6b
20 changed files with 767 additions and 0 deletions
  1. 7 0
      examples/org.yakindu.sct.standalone/.classpath
  2. 1 0
      examples/org.yakindu.sct.standalone/.gitignore
  3. 28 0
      examples/org.yakindu.sct.standalone/.project
  4. 11 0
      examples/org.yakindu.sct.standalone/.settings/org.eclipse.jdt.core.prefs
  5. 15 0
      examples/org.yakindu.sct.standalone/META-INF/MANIFEST.MF
  6. 3 0
      examples/org.yakindu.sct.standalone/build.properties
  7. 22 0
      examples/org.yakindu.sct.standalone/libraries/CoreFeatureTypeLibrary.xmi
  8. 8 0
      examples/org.yakindu.sct.standalone/libraries/GenericJavaFeatureTypeLibrary.xmi
  9. 17 0
      examples/org.yakindu.sct.standalone/libraries/SCTBaseFeatureLibrary.xmi
  10. 160 0
      examples/org.yakindu.sct.standalone/src/com/yakindu/sct/standalone/SCTStandaloneGeneration.java
  11. 56 0
      examples/org.yakindu.sct.standalone/src/com/yakindu/sct/standalone/extension/GenericDomainDesciptor.java
  12. 46 0
      examples/org.yakindu.sct.standalone/src/com/yakindu/sct/standalone/extension/JavaGeneratorDescriptor.java
  13. 31 0
      examples/org.yakindu.sct.standalone/src/com/yakindu/sct/standalone/extension/LibraryDescriptor.java
  14. 30 0
      examples/org.yakindu.sct.standalone/src/com/yakindu/sct/standalone/generator/Log4jGeneratorLog.java
  15. 179 0
      examples/org.yakindu.sct.standalone/src/com/yakindu/sct/standalone/generator/StandaloneFileSystemAccess.java
  16. 54 0
      examples/org.yakindu.sct.standalone/src/com/yakindu/sct/standalone/generator/StandaloneGeneratorModule.java
  17. 1 0
      examples/org.yakindu.sct.standalone/workspace/test.java.plain/.gitignore
  18. 17 0
      examples/org.yakindu.sct.standalone/workspace/test.java.plain/.project
  19. 73 0
      examples/org.yakindu.sct.standalone/workspace/test.java.plain/default.sct
  20. 8 0
      examples/org.yakindu.sct.standalone/workspace/test.java.plain/java.sgen

+ 7 - 0
examples/org.yakindu.sct.standalone/.classpath

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 1 - 0
examples/org.yakindu.sct.standalone/.gitignore

@@ -0,0 +1 @@
+/bin/

+ 28 - 0
examples/org.yakindu.sct.standalone/.project

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.yakindu.sct.standalone</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.pde.PluginNature</nature>
+	</natures>
+</projectDescription>

+ 11 - 0
examples/org.yakindu.sct.standalone/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7

+ 15 - 0
examples/org.yakindu.sct.standalone/META-INF/MANIFEST.MF

@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Standalone
+Bundle-SymbolicName: org.yakindu.sct.standalone
+Bundle-Version: 1.0.0.qualifier
+Export-Package: com.yakindu.sct.standalone
+Require-Bundle: org.yakindu.sct.model.sgen,
+ org.yakindu.sct.generator.genmodel,
+ org.yakindu.sct.model.stext,
+ org.eclipse.gmf.runtime.notation.edit,
+ org.yakindu.sct.model.resource,
+ org.yakindu.sct.domain,
+ org.eclipse.swt,
+ org.yakindu.sct.domain.generic,
+ org.yakindu.sct.generator.java

+ 3 - 0
examples/org.yakindu.sct.standalone/build.properties

@@ -0,0 +1,3 @@
+source.. = src/
+bin.includes = META-INF/,\
+               .

+ 22 - 0
examples/org.yakindu.sct.standalone/libraries/CoreFeatureTypeLibrary.xmi

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="ASCII"?>
+<sgen:FeatureTypeLibrary
+    xmi:version="2.0"
+    xmlns:xmi="http://www.omg.org/XMI"
+    xmlns:sgen="http://www.yakindu.org/sct/statechart/SGen"
+    name="Core">
+  <types name="Outlet">
+    <parameters
+        name="targetProject"/>
+    <parameters
+        name="targetFolder"/>
+    <parameters
+        name="libraryTargetFolder"
+        comment="A distinct output folder for static code artifacts (which are independent of concrete statechart models). It will not be cleaned or overwritten in succeeding generation passes. If not specified, the code will be generated into the target folder as well."
+        optional="true"/>
+  </types>
+  <types name="LicenseHeader"
+      optional="true">
+    <parameters
+        name="licenseText"/>
+  </types>
+</sgen:FeatureTypeLibrary>

+ 8 - 0
examples/org.yakindu.sct.standalone/libraries/GenericJavaFeatureTypeLibrary.xmi

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="ASCII"?>
+<sgen:FeatureTypeLibrary xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sgen="http://www.yakindu.org/sct/statechart/SGen" xsi:schemaLocation="http://www.yakindu.org/sct/statechart/SGen ../../org.yakindu.sct.model.sgen/model/emf/sgen.ecore" name="Java">
+  <types name="Generator">
+    <parameters name="generatorProject"/>
+    <parameters name="generatorClass"/>
+    <parameters name="configurationModule" optional="true"/>
+  </types>
+</sgen:FeatureTypeLibrary>

+ 17 - 0
examples/org.yakindu.sct.standalone/libraries/SCTBaseFeatureLibrary.xmi

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="ASCII"?>
+<sgen:FeatureTypeLibrary xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:sgen="http://www.yakindu.org/sct/statechart/SGen" name="SCT Base">
+  <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>
+</sgen:FeatureTypeLibrary>

+ 160 - 0
examples/org.yakindu.sct.standalone/src/com/yakindu/sct/standalone/SCTStandaloneGeneration.java

@@ -0,0 +1,160 @@
+package com.yakindu.sct.standalone;
+
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.xtext.resource.IResourceServiceProvider;
+import org.eclipse.xtext.scoping.IGlobalScopeProvider;
+import org.eclipse.xtext.scoping.impl.ResourceSetGlobalScopeProvider;
+import org.yakindu.sct.domain.extension.DomainRegistry;
+import org.yakindu.sct.domain.extension.IDomainDescriptor;
+import org.yakindu.sct.generator.core.GeneratorExecutor;
+import org.yakindu.sct.generator.core.extensions.GeneratorExtensions;
+import org.yakindu.sct.generator.core.extensions.LibraryExtensions;
+import org.yakindu.sct.generator.core.features.impl.CoreLibraryDefaultFeatureValueProvider;
+import org.yakindu.sct.generator.core.features.impl.GenericJavaLibraryDefaultValueProvider;
+import org.yakindu.sct.generator.core.features.impl.SCTBaseLibaryDefaultFeatureValueProvider;
+import org.yakindu.sct.generator.genmodel.SGenRuntimeModule;
+import org.yakindu.sct.generator.genmodel.SGenStandaloneSetup;
+import org.yakindu.sct.model.resource.SCTResourceFactory;
+import org.yakindu.sct.model.sgen.GeneratorModel;
+import org.yakindu.sct.model.sgen.SGenPackage;
+import org.yakindu.sct.model.stext.STextRuntimeModule;
+import org.yakindu.sct.model.stext.STextStandaloneSetup;
+
+import com.google.common.collect.Lists;
+import com.google.inject.Binder;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import com.google.inject.util.Modules;
+import com.yakindu.sct.standalone.extension.GenericDomainDesciptor;
+import com.yakindu.sct.standalone.extension.JavaGeneratorDescriptor;
+import com.yakindu.sct.standalone.extension.LibraryDescriptor;
+
+public class SCTStandaloneGeneration {
+
+	private static final String SCT_FILE_EXTENSION = "sct";
+	private static ResourceSet resourceSet;
+	private static Charset encoding = StandardCharsets.UTF_8;
+
+	private static String absoluteLibrariesDir = System.getProperty("user.dir") + "/libraries";
+	private static String absoluteWorkspaceDir = System.getProperty("user.dir") + "/workspace";
+	private static String relativeSgenPath = "/test.java.plain/java.sgen";
+	private static String relativeSCTPath = "/test.java.plain/default.sct";
+
+	public static void main(String[] args) {
+
+		initLanguages();
+		initResourceSet();
+
+		initSCTDomain();
+		initSgenLibraries();
+		initSCTGenerator();
+
+		loadSCTModels();
+
+		generateAll();
+
+	}
+
+	protected static void loadSCTModels() {
+		load(absoluteWorkspaceDir + relativeSCTPath);
+		load(absoluteWorkspaceDir + relativeSgenPath);
+	}
+
+	protected static void generateAll() {
+		EList<Resource> resources = resourceSet.getResources();
+		List<GeneratorModel> genModels = Lists.newArrayList();
+		for (Resource resource : resources) {
+			EObject content = resource.getContents().get(0);
+			if (content instanceof GeneratorModel)
+				genModels.add((GeneratorModel) content);
+		}
+		for (GeneratorModel generatorModel : genModels) {
+			new GeneratorExecutor().executeGenerator(generatorModel);
+		}
+	}
+
+	protected static void initSCTGenerator() {
+		GeneratorExtensions.getGeneratorDescriptors().add(new JavaGeneratorDescriptor());
+	}
+	
+	protected static void initSgenLibraries() {
+		LibraryExtensions.getLibraryDescriptors()
+				.add(new LibraryDescriptor("org.yakindu.generator.core.features",
+						URI.createFileURI(absoluteLibrariesDir + "/CoreFeatureTypeLibrary.xmi"),
+						new CoreLibraryDefaultFeatureValueProvider()));
+		LibraryExtensions.getLibraryDescriptors()
+				.add(new LibraryDescriptor("org.yakindu.sct.generator.feature.java",
+						URI.createFileURI(absoluteLibrariesDir + "/GenericJavaFeatureTypeLibrary.xmi"),
+						new GenericJavaLibraryDefaultValueProvider()));
+		LibraryExtensions.getLibraryDescriptors()
+				.add(new LibraryDescriptor("org.yakindu.generator.core.features.sctbase",
+						URI.createFileURI(SCTStandaloneGeneration.absoluteLibrariesDir + "/SCTBaseFeatureLibrary.xmi"),
+						new SCTBaseLibaryDefaultFeatureValueProvider()));
+	}
+
+	protected static Resource load(String string) {
+		return resourceSet.getResource(URI.createFileURI(string), true);
+	}
+
+	protected static void initSCTDomain() {
+		IDomainDescriptor domainDescriptor = new GenericDomainDesciptor(absoluteWorkspaceDir, encoding);
+		DomainRegistry.getDomainDescriptors().add(domainDescriptor);
+	}
+
+	protected static void initResourceSet() {
+		resourceSet = new ResourceSetImpl();
+		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(SCT_FILE_EXTENSION,
+				new SCTResourceFactory());
+	}
+
+	protected static void initLanguages() {
+		doSgenSetup();
+		doSTextSetup();
+	}
+
+	protected static void doSgenSetup() {
+		SGenPackage.eINSTANCE.eClass();
+		new SGenStandaloneSetup() {
+			@Override
+			public Injector createInjector() {
+				return Guice.createInjector(
+						Modules.override(new SGenRuntimeModule()).with(new Module() {
+							@Override
+							public void configure(Binder binder) {
+								binder.bind(IGlobalScopeProvider.class).to(ResourceSetGlobalScopeProvider.class);
+							}
+						}));
+			}
+		}.createInjectorAndDoEMFRegistration();
+	}
+
+	protected static void doSTextSetup() {
+		NotationPackage.eINSTANCE.eClass();
+
+		Injector stextInjector = new STextStandaloneSetup() {
+			@Override
+			public Injector createInjector() {
+				return Guice.createInjector(
+						Modules.override(new STextRuntimeModule()).with(new Module() {
+							@Override
+							public void configure(Binder binder) {
+								binder.bind(IGlobalScopeProvider.class).to(ResourceSetGlobalScopeProvider.class);
+							}
+						}));
+			}
+		}.createInjectorAndDoEMFRegistration();
+		IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put(SCT_FILE_EXTENSION,
+				stextInjector.getInstance(IResourceServiceProvider.class));
+	}
+}

+ 56 - 0
examples/org.yakindu.sct.standalone/src/com/yakindu/sct/standalone/extension/GenericDomainDesciptor.java

@@ -0,0 +1,56 @@
+package com.yakindu.sct.standalone.extension;
+
+import java.nio.charset.Charset;
+
+import org.eclipse.swt.graphics.Image;
+import org.yakindu.sct.domain.extension.IDomainDescriptor;
+import org.yakindu.sct.domain.extension.IDomainInjectorProvider;
+import org.yakindu.sct.domain.generic.extension.GenericDomainInjectorProvider;
+
+import com.google.inject.Module;
+import com.google.inject.util.Modules;
+import com.yakindu.sct.standalone.generator.StandaloneFileSystemAccess;
+import com.yakindu.sct.standalone.generator.Log4jGeneratorLog;
+import com.yakindu.sct.standalone.generator.StandaloneGeneratorModule;
+
+public class GenericDomainDesciptor implements IDomainDescriptor {
+	
+	
+	private String genRootDir;
+	private Charset encoding;
+	public GenericDomainDesciptor(String genRootDir, Charset encoding) {
+		this.genRootDir = genRootDir;
+		this.encoding = encoding;
+	}
+	
+	@Override
+	public String getDomainID() {
+		return "org.yakindu.domain.default";
+	}
+	@Override
+	public String getName() {
+		return "Default";
+	}
+	@Override
+	public String getDescription() {
+		return "The default domain for YAKINDU Statechart Tools.";
+	}
+	@Override
+	public IDomainInjectorProvider getDomainInjectorProvider() {
+		return new GenericDomainInjectorProvider() {
+			@Override
+			public Module getGeneratorModule(String generatorId) {
+				Module generatorModule = super.getGeneratorModule(generatorId);
+				return Modules.override(generatorModule).with(new StandaloneGeneratorModule(genRootDir,
+						encoding, StandaloneFileSystemAccess.class, Log4jGeneratorLog.class));
+			}
+			protected Module getResourceModule() {
+				return Modules.override(getLanguageRuntimeModule()).with(getTypeSystemModule());
+			};
+		};
+	}
+	@Override
+	public Image getImage() {
+		return null;
+	}
+}

+ 46 - 0
examples/org.yakindu.sct.standalone/src/com/yakindu/sct/standalone/extension/JavaGeneratorDescriptor.java

@@ -0,0 +1,46 @@
+package com.yakindu.sct.standalone.extension;
+
+import java.util.List;
+
+import org.eclipse.swt.graphics.Image;
+import org.yakindu.sct.generator.core.ISCTGenerator;
+import org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor;
+import org.yakindu.sct.generator.java.JavaCodeGenerator;
+
+import com.google.common.collect.Lists;
+
+public class JavaGeneratorDescriptor implements IGeneratorDescriptor {
+	@Override
+	public String getName() {
+		return "YAKINDU SCT Java Code Generator";
+	}
+	@Override
+	public List<String> getLibraryIDs() {
+		return Lists.newArrayList("org.yakindu.generator.core.features",
+				"org.yakindu.generator.core.features.sctbase", "org.yakindu.sct.generator.feature.java");
+	}
+	@Override
+	public Image getImage() {
+		return null;
+	}
+	@Override
+	public String getId() {
+		return "yakindu::java";
+	}
+	@Override
+	public String getElementRefType() {
+		return "org.yakindu.sct.model.sgraph.Statechart";
+	}
+	@Override
+	public String getDescription() {
+		return "YAKINDU SCT Java Code Generator";
+	}
+	@Override
+	public String getContentType() {
+		return "statechart";
+	}
+	@Override
+	public ISCTGenerator createGenerator() {
+		return new JavaCodeGenerator();
+	}
+}

+ 31 - 0
examples/org.yakindu.sct.standalone/src/com/yakindu/sct/standalone/extension/LibraryDescriptor.java

@@ -0,0 +1,31 @@
+package com.yakindu.sct.standalone.extension;
+
+import org.eclipse.emf.common.util.URI;
+import org.yakindu.sct.generator.core.extensions.ILibraryDescriptor;
+import org.yakindu.sct.generator.core.features.IDefaultFeatureValueProvider;
+
+public class LibraryDescriptor implements ILibraryDescriptor {
+	
+	private IDefaultFeatureValueProvider defaultFeatureValueProvider;
+	private String id;
+	private URI uri;
+	
+	public LibraryDescriptor(String id,URI uri,IDefaultFeatureValueProvider defaultFeatureValueProvider) {
+		this.id = id;
+		this.uri = uri;
+		this.defaultFeatureValueProvider = defaultFeatureValueProvider;
+	}
+	
+	@Override
+	public URI getURI() {
+		return uri;
+	}
+	@Override
+	public String getLibraryId() {
+		return id;
+	}
+	@Override
+	public IDefaultFeatureValueProvider createFeatureValueProvider() {
+		return defaultFeatureValueProvider;
+	}
+}

+ 30 - 0
examples/org.yakindu.sct.standalone/src/com/yakindu/sct/standalone/generator/Log4jGeneratorLog.java

@@ -0,0 +1,30 @@
+package com.yakindu.sct.standalone.generator;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.yakindu.sct.generator.core.impl.IGeneratorLog;
+
+import com.google.common.collect.Lists;
+
+public class Log4jGeneratorLog implements IGeneratorLog {
+	private static final Logger LOG = Logger.getLogger(Log4jGeneratorLog.class);
+	public static final List<String> lines = Lists.newArrayList();
+	public static final List<Throwable> throwables = Lists.newArrayList();
+
+	@Override
+	public void writeToConsole(String line) {
+		lines.add(line);
+		LOG.info(line);
+	}
+	@Override
+	public void writeToConsole(Throwable t) {
+		throwables.add(t);
+		LOG.error(t.getMessage(),t);
+	}
+	
+	@Override
+	public void close() throws Throwable {
+		
+	}
+}

+ 179 - 0
examples/org.yakindu.sct.standalone/src/com/yakindu/sct/standalone/generator/StandaloneFileSystemAccess.java

@@ -0,0 +1,179 @@
+package com.yakindu.sct.standalone.generator;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.Charset;
+
+import org.apache.log4j.Logger;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.xtext.generator.AbstractFileSystemAccess;
+import org.eclipse.xtext.generator.IFileSystemAccess;
+import org.eclipse.xtext.generator.OutputConfiguration;
+import org.yakindu.sct.generator.core.features.ICoreFeatureConstants;
+import org.yakindu.sct.generator.core.filesystem.ISCTFileSystemAccess;
+
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+
+public class StandaloneFileSystemAccess extends AbstractFileSystemAccess implements ISCTFileSystemAccess {
+	private static final Logger LOG = Logger.getLogger(StandaloneFileSystemAccess.class);
+	@Inject
+	@Named(StandaloneGeneratorModule.ENCODING)
+	protected Charset encoding;
+	@Inject
+	@Named(StandaloneGeneratorModule.BASE_DIR)
+	protected String absoluteBaseDir;
+
+	@Override
+	public void generateFile(String fileName, String outputConfigurationName, CharSequence contents) {
+		// validate setup
+		validateFileSystemAccess();
+
+		OutputConfiguration outputConfig = getOutputConfig(outputConfigurationName);
+
+		File outputDir = getOutputDir(outputConfig);
+
+		String contentsAsString = doPostProcesses(fileName, outputConfigurationName, contents);
+
+		File outputFile = new File(outputDir, fileName);
+		if (outputFile.exists()) {
+			if (outputConfig.isOverrideExistingResources()) {
+				tryOverride(contentsAsString, outputFile);
+			}
+		} else {
+			LOG.trace("creating folder "+outputFile.getParentFile().getAbsolutePath());
+			outputFile.getParentFile().mkdirs();
+			try {
+				outputFile.createNewFile();
+				LOG.info("created "+outputFile.getAbsolutePath());
+			} catch (IOException e) {
+				throw new RuntimeException(e);
+			}
+			writeContent(contentsAsString, outputFile, encoding);
+		}
+	}
+
+	protected void validateFileSystemAccess() {
+		if (this.absoluteBaseDir == null || this.absoluteBaseDir.isEmpty())
+			throw new IllegalStateException("base dir must have been set");
+	}
+
+	protected void tryOverride(String contentsAsString, File outputFile) {
+		String currentContent = getCurrentContent(outputFile);
+		if (!isSame(contentsAsString, currentContent)) {
+			LOG.info("writing(/overriding) "+outputFile.getAbsolutePath());
+			writeContent(contentsAsString, outputFile, encoding);
+		} else {
+			LOG.info("content did not change, skip writing "+outputFile.getAbsolutePath());
+			// ignore same content...
+		}
+	}
+
+	/**
+	 * Respects 'Pigeonhole_principle'.
+	 * 
+	 * @param newContent
+	 * @param currentContent
+	 * @return true if hashCode && content are same
+	 */
+	protected boolean isSame(String newContent, String currentContent) {
+		return currentContent.hashCode() == newContent.hashCode() &&
+				/* Pigeonhole_principle */currentContent.equals(newContent);
+	}
+
+	protected String getCurrentContent(File outputFile) {
+		String currentContent = null;
+		BufferedReader reader = null;
+		try {
+			reader = new BufferedReader(new FileReader(outputFile));
+			String line = null;
+			StringBuilder stringBuilder = new StringBuilder();
+			String ls = System.getProperty("line.separator");
+			while ((line = reader.readLine()) != null) {
+				stringBuilder.append(line);
+				stringBuilder.append(ls);
+			}
+			currentContent = stringBuilder.toString();
+		} catch (FileNotFoundException e1) {
+			throw new RuntimeException("Error during load of current file", e1);
+		} catch (IOException e) {
+			throw new RuntimeException("Error during load of current file", e);
+		} finally {
+			try {
+				reader.close();
+			} catch (IOException e) {
+				// ignore
+			}
+		}
+		return currentContent;
+	}
+
+	protected String doPostProcesses(String fileName, String outputConfigurationName, CharSequence contents) {
+		CharSequence postProcessedContent = postProcess(fileName, outputConfigurationName, contents);
+		String contentsAsString = postProcessedContent.toString();
+		return contentsAsString;
+	}
+
+	protected File getOutputDir(OutputConfiguration outputConfig) {
+		String fullPath = getFullPath(outputConfig);
+		File outputDir = new File(fullPath);
+		if (!outputDir.exists()) {
+			if (outputConfig.isCreateOutputDirectory()) {
+				outputDir.mkdirs();
+			} else {
+				outputDir = null;
+			}
+		}
+		return outputDir;
+	}
+
+	protected String getFullPath(OutputConfiguration outputConfig) {
+		String outputDirectory = outputConfig.getOutputDirectory();
+		String fullPath = absoluteBaseDir + File.separator
+				+ getOutputConfig(ICoreFeatureConstants.OUTLET_FEATURE_TARGET_PROJECT).getOutputDirectory()
+				+ File.separator + outputDirectory;
+		return fullPath;
+	}
+
+	protected void writeContent(String contentsAsString, File outputFile, Charset encoding) {
+		Writer out = null;
+		try {
+			out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), encoding));
+			out.write(contentsAsString);
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		} finally {
+			try {
+				if (out != null)
+					out.close();
+			} catch (IOException e) {
+				// ignore
+			}
+
+		}
+	}
+
+	@Override
+	public URI getURI(String relativePath, String outputConfiguration) {
+		OutputConfiguration outputConfig = getOutputConfig(outputConfiguration);
+		return URI.createFileURI(getFullPath(outputConfig) + File.separator + relativePath);
+	}
+
+	@Override
+	public IFileSystemAccess getIFileSystemAccess() {
+		return this;
+	}
+
+	@Override
+	public void afterGeneration() {
+		// currently nothing
+	}
+
+}

+ 54 - 0
examples/org.yakindu.sct.standalone/src/com/yakindu/sct/standalone/generator/StandaloneGeneratorModule.java

@@ -0,0 +1,54 @@
+/**
+ * Copyright (c) 2016 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * 		committers of YAKINDU - initial API and implementation
+ * 
+ */
+package com.yakindu.sct.standalone.generator;
+
+import java.nio.charset.Charset;
+
+import org.yakindu.sct.generator.core.filesystem.ISCTFileSystemAccess;
+import org.yakindu.sct.generator.core.impl.IGeneratorLog;
+
+import com.google.inject.Binder;
+import com.google.inject.Module;
+import com.google.inject.name.Names;
+
+/**
+ * @author Johannes Dicks - Initial contribution and API
+ *
+ */
+public class StandaloneGeneratorModule implements Module {
+	
+	public static final String BASE_DIR = "filesystemAccess.absolute.baseDir";
+	public static final String ENCODING = "filesystemAccess.encoding";
+	
+	
+	private String baseDir;
+	private Charset encoding;
+	private Class<? extends StandaloneFileSystemAccess> fsaImpl;
+	private Class<? extends IGeneratorLog> gLogImpl;
+	
+	
+	
+	public StandaloneGeneratorModule(String baseDir, Charset encoding,Class<? extends StandaloneFileSystemAccess> fsaImpl,Class<? extends IGeneratorLog> gLogImpl) {
+		this.baseDir = baseDir;
+		this.encoding = encoding;
+		this.fsaImpl = fsaImpl;
+		this.gLogImpl = gLogImpl;
+	}
+
+	@Override
+	public void configure(Binder binder) {
+		binder.bind(ISCTFileSystemAccess.class).to(fsaImpl);
+		binder.bind(IGeneratorLog.class).to(gLogImpl);
+		binder.bind(String.class).annotatedWith(Names.named(BASE_DIR)).toInstance(baseDir);
+		binder.bind(Charset.class).annotatedWith(Names.named(ENCODING)).toInstance(encoding);
+	}
+}

+ 1 - 0
examples/org.yakindu.sct.standalone/workspace/test.java.plain/.gitignore

@@ -0,0 +1 @@
+/gen/

+ 17 - 0
examples/org.yakindu.sct.standalone/workspace/test.java.plain/.project

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>test.java.plain</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
+	</natures>
+</projectDescription>

+ 73 - 0
examples/org.yakindu.sct.standalone/workspace/test.java.plain/default.sct

@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:sgraph="http://www.yakindu.org/sct/sgraph/2.0.0">
+  <sgraph:Statechart xmi:id="_Oyj74L-HEeWOuOsEof1gMw" specification="internal : var test : integer&#xD;&#xA;" name="default">
+    <regions xmi:id="_OzJKsL-HEeWOuOsEof1gMw" name="main region">
+      <vertices xsi:type="sgraph:Entry" xmi:id="_OzizUL-HEeWOuOsEof1gMw">
+        <outgoingTransitions xmi:id="_Ozz5EL-HEeWOuOsEof1gMw" target="_Oznr0L-HEeWOuOsEof1gMw"/>
+      </vertices>
+      <vertices xsi:type="sgraph:State" xmi:id="_Oznr0L-HEeWOuOsEof1gMw" name="A" incomingTransitions="_Ozz5EL-HEeWOuOsEof1gMw"/>
+    </regions>
+  </sgraph:Statechart>
+  <notation:Diagram xmi:id="_OzGucL-HEeWOuOsEof1gMw" type="org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor" element="_Oyj74L-HEeWOuOsEof1gMw" measurementUnit="Pixel">
+    <children xmi:id="_OzOqQL-HEeWOuOsEof1gMw" type="Region" element="_OzJKsL-HEeWOuOsEof1gMw">
+      <children xsi:type="notation:DecorationNode" xmi:id="_Oza3gL-HEeWOuOsEof1gMw" type="RegionName">
+        <styles xsi:type="notation:ShapeStyle" xmi:id="_Oza3gb-HEeWOuOsEof1gMw"/>
+        <layoutConstraint xsi:type="notation:Location" xmi:id="_Oza3gr-HEeWOuOsEof1gMw"/>
+      </children>
+      <children xsi:type="notation:Shape" xmi:id="_OzcFoL-HEeWOuOsEof1gMw" type="RegionCompartment" fontName="Verdana" lineColor="4210752">
+        <children xmi:id="_OzkBcL-HEeWOuOsEof1gMw" type="Entry" element="_OzizUL-HEeWOuOsEof1gMw">
+          <children xmi:id="_OzkBdL-HEeWOuOsEof1gMw" type="BorderItemLabelContainer">
+            <children xsi:type="notation:DecorationNode" xmi:id="_OzkogL-HEeWOuOsEof1gMw" type="BorderItemLabel">
+              <styles xsi:type="notation:ShapeStyle" xmi:id="_Ozkogb-HEeWOuOsEof1gMw"/>
+              <layoutConstraint xsi:type="notation:Location" xmi:id="_Ozkogr-HEeWOuOsEof1gMw"/>
+            </children>
+            <styles xsi:type="notation:ShapeStyle" xmi:id="_OzkBdb-HEeWOuOsEof1gMw" fontName="Verdana" lineColor="4210752"/>
+            <layoutConstraint xsi:type="notation:Bounds" xmi:id="_OzkBdr-HEeWOuOsEof1gMw"/>
+          </children>
+          <styles xsi:type="notation:ShapeStyle" xmi:id="_OzkBcb-HEeWOuOsEof1gMw" fontName="Verdana" fillColor="0" lineColor="16777215"/>
+          <styles xsi:type="notation:NamedStyle" xmi:id="_OzkBcr-HEeWOuOsEof1gMw" name="allowColors"/>
+          <layoutConstraint xsi:type="notation:Bounds" xmi:id="_Ozkog7-HEeWOuOsEof1gMw" x="70" y="20"/>
+        </children>
+        <children xmi:id="_OzuZgL-HEeWOuOsEof1gMw" type="State" element="_Oznr0L-HEeWOuOsEof1gMw">
+          <children xsi:type="notation:DecorationNode" xmi:id="_OzvAkL-HEeWOuOsEof1gMw" type="StateName">
+            <styles xsi:type="notation:ShapeStyle" xmi:id="_OzvAkb-HEeWOuOsEof1gMw"/>
+            <layoutConstraint xsi:type="notation:Location" xmi:id="_OzvAkr-HEeWOuOsEof1gMw"/>
+          </children>
+          <children xsi:type="notation:Compartment" xmi:id="_OzwOsL-HEeWOuOsEof1gMw" type="StateTextCompartment">
+            <children xsi:type="notation:Shape" xmi:id="_OzwOsb-HEeWOuOsEof1gMw" type="StateTextCompartmentExpression" fontName="Verdana" lineColor="4210752">
+              <layoutConstraint xsi:type="notation:Bounds" xmi:id="_OzwOsr-HEeWOuOsEof1gMw"/>
+            </children>
+          </children>
+          <children xsi:type="notation:Compartment" xmi:id="_Ozw1wL-HEeWOuOsEof1gMw" type="StateFigureCompartment"/>
+          <styles xsi:type="notation:ShapeStyle" xmi:id="_OzuZgb-HEeWOuOsEof1gMw" fontName="Verdana" fillColor="15981773" lineColor="12632256"/>
+          <styles xsi:type="notation:FontStyle" xmi:id="_OzuZgr-HEeWOuOsEof1gMw"/>
+          <styles xsi:type="notation:BooleanValueStyle" xmi:id="_Ozw1wb-HEeWOuOsEof1gMw" name="isHorizontal" booleanValue="true"/>
+          <layoutConstraint xsi:type="notation:Bounds" xmi:id="_Ozw1wr-HEeWOuOsEof1gMw" x="40" y="80"/>
+        </children>
+        <layoutConstraint xsi:type="notation:Bounds" xmi:id="_OzcssL-HEeWOuOsEof1gMw"/>
+      </children>
+      <styles xsi:type="notation:ShapeStyle" xmi:id="_OzOqQb-HEeWOuOsEof1gMw" fontName="Verdana" fillColor="15790320" lineColor="12632256"/>
+      <layoutConstraint xsi:type="notation:Bounds" xmi:id="_Ozcssb-HEeWOuOsEof1gMw" x="365" y="10" width="400" height="400"/>
+    </children>
+    <children xsi:type="notation:Shape" xmi:id="_Oz-RI7-HEeWOuOsEof1gMw" type="StatechartText" fontName="Verdana" lineColor="4210752">
+      <children xsi:type="notation:DecorationNode" xmi:id="_Oz-4ML-HEeWOuOsEof1gMw" type="StatechartName">
+        <styles xsi:type="notation:ShapeStyle" xmi:id="_Oz-4Mb-HEeWOuOsEof1gMw"/>
+        <layoutConstraint xsi:type="notation:Location" xmi:id="_Oz-4Mr-HEeWOuOsEof1gMw"/>
+      </children>
+      <children xsi:type="notation:Shape" xmi:id="_Oz-4M7-HEeWOuOsEof1gMw" type="StatechartTextExpression" fontName="Verdana" lineColor="4210752">
+        <layoutConstraint xsi:type="notation:Bounds" xmi:id="_Oz-4NL-HEeWOuOsEof1gMw"/>
+      </children>
+      <layoutConstraint xsi:type="notation:Bounds" xmi:id="_Oz_fQL-HEeWOuOsEof1gMw" x="10" y="10" width="341" height="400"/>
+    </children>
+    <styles xsi:type="notation:DiagramStyle" xmi:id="_OzGucb-HEeWOuOsEof1gMw"/>
+    <edges xmi:id="_Oz9qEL-HEeWOuOsEof1gMw" type="Transition" element="_Ozz5EL-HEeWOuOsEof1gMw" source="_OzkBcL-HEeWOuOsEof1gMw" target="_OzuZgL-HEeWOuOsEof1gMw">
+      <children xsi:type="notation:DecorationNode" xmi:id="_Oz-RIL-HEeWOuOsEof1gMw" type="TransitionExpression">
+        <styles xsi:type="notation:ShapeStyle" xmi:id="_Oz-RIb-HEeWOuOsEof1gMw"/>
+        <layoutConstraint xsi:type="notation:Location" xmi:id="_Oz-RIr-HEeWOuOsEof1gMw" y="10"/>
+      </children>
+      <styles xsi:type="notation:ConnectorStyle" xmi:id="_Oz9qEb-HEeWOuOsEof1gMw" lineColor="4210752"/>
+      <styles xsi:type="notation:FontStyle" xmi:id="_Oz9qE7-HEeWOuOsEof1gMw" fontName="Verdana"/>
+      <bendpoints xsi:type="notation:RelativeBendpoints" xmi:id="_Oz9qEr-HEeWOuOsEof1gMw" points="[0, 0, 0, 0]$[0, 0, 0, 0]"/>
+    </edges>
+  </notation:Diagram>
+</xmi:XMI>

+ 8 - 0
examples/org.yakindu.sct.standalone/workspace/test.java.plain/java.sgen

@@ -0,0 +1,8 @@
+GeneratorModel for yakindu::java {
+	statechart default {
+		feature Outlet {
+			targetProject = "test.java.plain"
+			targetFolder = "gen"
+		}
+	}
+}