|
@@ -11,6 +11,7 @@
|
|
|
package org.yakindu.sct.generator.core.impl;
|
|
|
|
|
|
import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.OUTLET_FEATURE_TARGET_FOLDER;
|
|
|
+import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.OUTLET_FEATURE_LIBRARY_TARGET_FOLDER;
|
|
|
import static org.yakindu.sct.generator.core.features.impl.IGenericJavaFeatureConstants.CONFIGURATION_MODULE;
|
|
|
import static org.yakindu.sct.generator.core.features.impl.IGenericJavaFeatureConstants.GENERATOR_CLASS;
|
|
|
import static org.yakindu.sct.generator.core.features.impl.IGenericJavaFeatureConstants.GENERATOR_PROJECT;
|
|
@@ -23,6 +24,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
|
|
|
import org.eclipse.core.runtime.Path;
|
|
|
import org.eclipse.emf.common.util.URI;
|
|
|
import org.eclipse.xtext.generator.IFileSystemAccess;
|
|
|
+import org.eclipse.xtext.generator.OutputConfiguration;
|
|
|
import org.eclipse.xtext.util.Strings;
|
|
|
import org.yakindu.sct.commons.WorkspaceClassLoaderFactory;
|
|
|
import org.yakindu.sct.generator.core.AbstractWorkspaceGenerator;
|
|
@@ -47,28 +49,23 @@ public class GenericJavaBasedGenerator extends AbstractSExecModelGenerator {
|
|
|
Module defaultModule = super.getChildInjectorModule(entry);
|
|
|
|
|
|
String overridingModuleClass = null;
|
|
|
- FeatureConfiguration featureConfiguration = entry
|
|
|
- .getFeatureConfiguration(TEMPLATE_FEATURE);
|
|
|
+ FeatureConfiguration featureConfiguration = entry.getFeatureConfiguration(TEMPLATE_FEATURE);
|
|
|
if (featureConfiguration != null) {
|
|
|
- FeatureParameterValue parameterValue = featureConfiguration
|
|
|
- .getParameterValue(CONFIGURATION_MODULE);
|
|
|
+ FeatureParameterValue parameterValue = featureConfiguration.getParameterValue(CONFIGURATION_MODULE);
|
|
|
if (parameterValue != null) {
|
|
|
overridingModuleClass = parameterValue.getStringValue();
|
|
|
}
|
|
|
}
|
|
|
if (!Strings.isEmpty(overridingModuleClass)) {
|
|
|
try {
|
|
|
- Class<?> moduleClass = getClassLoader(entry).loadClass(
|
|
|
- overridingModuleClass);
|
|
|
+ Class<?> moduleClass = getClassLoader(entry).loadClass(overridingModuleClass);
|
|
|
if (Module.class.isAssignableFrom(moduleClass)) {
|
|
|
Module module = (Module) moduleClass.newInstance();
|
|
|
- defaultModule = Modules.override(defaultModule)
|
|
|
- .with(module);
|
|
|
+ defaultModule = Modules.override(defaultModule).with(module);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- writeToConsole("Overriding module not found: "
|
|
|
- + overridingModuleClass);
|
|
|
+ writeToConsole("Overriding module not found: " + overridingModuleClass);
|
|
|
}
|
|
|
}
|
|
|
return defaultModule;
|
|
@@ -76,8 +73,8 @@ public class GenericJavaBasedGenerator extends AbstractSExecModelGenerator {
|
|
|
|
|
|
protected ClassLoader getClassLoader(GeneratorEntry entry) {
|
|
|
IProject project = getLookupRoot(entry);
|
|
|
- final ClassLoader classLoader = new WorkspaceClassLoaderFactory()
|
|
|
- .createClassLoader(project, getClass().getClassLoader());
|
|
|
+ final ClassLoader classLoader = new WorkspaceClassLoaderFactory().createClassLoader(project,
|
|
|
+ getClass().getClassLoader());
|
|
|
return classLoader;
|
|
|
}
|
|
|
|
|
@@ -87,38 +84,32 @@ public class GenericJavaBasedGenerator extends AbstractSExecModelGenerator {
|
|
|
final ClassLoader classLoader = getClassLoader(entry);
|
|
|
IFileSystemAccess fsa = getFileSystemAccess(entry);
|
|
|
try {
|
|
|
- Class<?> delegateGeneratorClass = (Class<?>) classLoader
|
|
|
- .loadClass(templateClass);
|
|
|
- Object delegate = getInjector(entry).getInstance(
|
|
|
- delegateGeneratorClass);
|
|
|
-
|
|
|
- Class<?> iType_ = (Class<?>) getClass()
|
|
|
- .getClassLoader()
|
|
|
- .loadClass(
|
|
|
- "org.yakindu.sct.generator.core.impl.IExecutionFlowGenerator");
|
|
|
+ Class<?> delegateGeneratorClass = (Class<?>) classLoader.loadClass(templateClass);
|
|
|
+ Object delegate = getInjector(entry).getInstance(delegateGeneratorClass);
|
|
|
+
|
|
|
+ Class<?> iType_ = (Class<?>) getClass().getClassLoader()
|
|
|
+ .loadClass("org.yakindu.sct.generator.core.impl.IExecutionFlowGenerator");
|
|
|
Class<?> iType__ = IExecutionFlowGenerator.class;
|
|
|
Class<?> iType = (Class<?>) classLoader
|
|
|
.loadClass("org.yakindu.sct.generator.core.impl.IExecutionFlowGenerator");
|
|
|
-
|
|
|
+
|
|
|
ExecutionFlow flow = createExecutionFlow(statechart, entry);
|
|
|
-
|
|
|
+
|
|
|
if (isDumpSexec(entry)) {
|
|
|
dumpSexec(entry, flow);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (delegate instanceof AbstractWorkspaceGenerator) {
|
|
|
((AbstractWorkspaceGenerator) delegate).setBridge(bridge);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (delegate instanceof IExecutionFlowGenerator) {
|
|
|
IExecutionFlowGenerator flowGenerator = (IExecutionFlowGenerator) delegate;
|
|
|
- flowGenerator.generate(flow, entry,
|
|
|
- fsa);
|
|
|
+ flowGenerator.generate(flow, entry, fsa);
|
|
|
}
|
|
|
if (iType.isInstance(delegate)) {
|
|
|
IExecutionFlowGenerator flowGenerator = (IExecutionFlowGenerator) delegate;
|
|
|
- flowGenerator.generate(flow, entry,
|
|
|
- fsa);
|
|
|
+ flowGenerator.generate(flow, entry, fsa);
|
|
|
}
|
|
|
if (delegate instanceof ISGraphGenerator) {
|
|
|
ISGraphGenerator graphGenerator = (ISGraphGenerator) delegate;
|
|
@@ -131,8 +122,7 @@ public class GenericJavaBasedGenerator extends AbstractSExecModelGenerator {
|
|
|
}
|
|
|
|
|
|
protected String getTemplateClassName(GeneratorEntry entry) {
|
|
|
- return entry.getFeatureConfiguration(TEMPLATE_FEATURE)
|
|
|
- .getParameterValue(GENERATOR_CLASS).getStringValue();
|
|
|
+ return entry.getFeatureConfiguration(TEMPLATE_FEATURE).getParameterValue(GENERATOR_CLASS).getStringValue();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -141,17 +131,14 @@ public class GenericJavaBasedGenerator extends AbstractSExecModelGenerator {
|
|
|
*/
|
|
|
protected IProject getLookupRoot(GeneratorEntry entry) {
|
|
|
IProject project = null;
|
|
|
- FeatureConfiguration templateConfig = entry
|
|
|
- .getFeatureConfiguration(TEMPLATE_FEATURE);
|
|
|
- FeatureParameterValue projectName = templateConfig
|
|
|
- .getParameterValue(GENERATOR_PROJECT);
|
|
|
+ FeatureConfiguration templateConfig = entry.getFeatureConfiguration(TEMPLATE_FEATURE);
|
|
|
+ FeatureParameterValue projectName = templateConfig.getParameterValue(GENERATOR_PROJECT);
|
|
|
if (projectName != null) {
|
|
|
- project = ResourcesPlugin.getWorkspace().getRoot()
|
|
|
- .getProject(projectName.getStringValue());
|
|
|
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName.getStringValue());
|
|
|
} else {
|
|
|
URI uri = entry.getElementRef().eResource().getURI();
|
|
|
- project = ResourcesPlugin.getWorkspace().getRoot()
|
|
|
- .getFile(new Path(uri.toPlatformString(true))).getProject();
|
|
|
+ project = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uri.toPlatformString(true)))
|
|
|
+ .getProject();
|
|
|
}
|
|
|
return project;
|
|
|
}
|
|
@@ -165,19 +152,28 @@ public class GenericJavaBasedGenerator extends AbstractSExecModelGenerator {
|
|
|
fileSystemAccess.setProject(getTargetProject(entry));
|
|
|
|
|
|
FeatureConfiguration outletConfig = getOutletFeatureConfiguration(entry);
|
|
|
- String targetFolder = outletConfig
|
|
|
- .getParameterValue(OUTLET_FEATURE_TARGET_FOLDER)
|
|
|
- .getExpression().toString();
|
|
|
-
|
|
|
- fileSystemAccess.setOutputPath(IFileSystemAccess.DEFAULT_OUTPUT,
|
|
|
- targetFolder);
|
|
|
-
|
|
|
- if (fileSystemAccess.getOutputConfigurations().get(
|
|
|
- IFileSystemAccess.DEFAULT_OUTPUT) != null) {
|
|
|
- fileSystemAccess.getOutputConfigurations()
|
|
|
- .get(IFileSystemAccess.DEFAULT_OUTPUT)
|
|
|
- .setCreateOutputDirectory(true);
|
|
|
+
|
|
|
+ String targetFolder = outletConfig.getParameterValue(OUTLET_FEATURE_TARGET_FOLDER).getExpression().toString();
|
|
|
+ fileSystemAccess.setOutputPath(IFileSystemAccess.DEFAULT_OUTPUT, targetFolder);
|
|
|
+
|
|
|
+ FeatureParameterValue libraryTargetFolderValue = outletConfig
|
|
|
+ .getParameterValue(OUTLET_FEATURE_LIBRARY_TARGET_FOLDER);
|
|
|
+ if (libraryTargetFolderValue != null) {
|
|
|
+ fileSystemAccess.setOutputPath(IExecutionFlowGenerator.LIBRARY_TARGET_FOLDER_OUTPUT,
|
|
|
+ libraryTargetFolderValue.getExpression().toString());
|
|
|
}
|
|
|
+
|
|
|
+ fileSystemAccess.getOutputConfigurations().get(IFileSystemAccess.DEFAULT_OUTPUT).setCreateOutputDirectory(true);
|
|
|
+ OutputConfiguration librarytargetFolderOutputConfiguration = fileSystemAccess.getOutputConfigurations()
|
|
|
+ .get(IExecutionFlowGenerator.LIBRARY_TARGET_FOLDER_OUTPUT);
|
|
|
+ if (librarytargetFolderOutputConfiguration != null) {
|
|
|
+ librarytargetFolderOutputConfiguration.setCreateOutputDirectory(true);
|
|
|
+ // do not overwrite existing resources and ensure the folder is not
|
|
|
+ // cleaned.
|
|
|
+ librarytargetFolderOutputConfiguration.setCanClearOutputDirectory(false);
|
|
|
+ librarytargetFolderOutputConfiguration.setOverrideExistingResources(false);
|
|
|
+ }
|
|
|
+
|
|
|
return fileSystemAccess;
|
|
|
}
|
|
|
|