Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
ac3ffb7
add AdditionalTemplateGenerator MWE2 component
gitianvr Dec 19, 2019
cad2c40
switch generator
gitianvr Dec 20, 2019
9522955
dynamic switching
gitianvr Dec 20, 2019
666186f
Merge pull request #2 from MDSD-Tools/master
christianthechristian Dec 30, 2019
bd6a5b8
add auto-generated hint to switch template
gitianvr Dec 30, 2019
0d9a0bb
use constant for E_OBJECT_CLASS
gitianvr Dec 30, 2019
5ae02b8
separate interfaces ApplyableSwitch, DynamicSwitch, InspectableSwitch
gitianvr Jan 2, 2020
57cfbc3
checkstyle
gitianvr Jan 2, 2020
0106250
for usability, make dynamic switch iherit ApplyableSwitch, Inspectabl…
gitianvr Jan 2, 2020
c361339
allow to merge static switches with dynamic switches
gitianvr Jan 2, 2020
50e5001
move EObject-class treatment to setup-time method
gitianvr Jan 2, 2020
8ff072f
fix dynamic class loading
gitianvr Jan 2, 2020
094db1b
configure a new test project for switches
gitianvr Dec 30, 2019
0d6eb58
fix: for allowing to run junit tests from inside eclipse
gitianvr Jan 9, 2020
c9f957c
TEMPORARY: MSwitchGenerator as Java instead of xtend
gitianvr Jan 10, 2020
47180db
add model as test scenario
gitianvr Jan 10, 2020
1cc79cb
test case priorities of static mswitches
gitianvr Jan 10, 2020
600c134
further test cases for static MSwitches concerning default cases, mer…
gitianvr Jan 10, 2020
0eba493
add equivalent cases for dynamic switches
gitianvr Jan 10, 2020
e782a16
fix: add xtend-src to the build source
gitianvr Jan 15, 2020
e67e300
restore xtend version of MSwitchClassGenerator
gitianvr Jan 15, 2020
85ac44f
refactor tests
gitianvr Jan 19, 2020
ad3738e
benchmark to compare switches
gitianvr Jan 22, 2020
6ca5661
bugfix: fix missing parametrization
gitianvr Feb 1, 2020
46b8f32
bugfix: consider base package in generated switch classes
gitianvr Feb 1, 2020
4b22a52
build process: clean orderly
gitianvr Feb 1, 2020
98a884a
add a second test model package (for testing multi-package switching)
gitianvr Feb 1, 2020
6413ab7
benchmark the difference between ComposedSwitch and DynamicSwitch
gitianvr Feb 3, 2020
7166e5f
import tools.mdsd.ecoreworkflow.switches.tests.perf as an eclipse pro…
gitianvr Feb 3, 2020
6093dd2
add context dependent resource mapping to testmodel's generate.mwe2
gitianvr Feb 3, 2020
2a94475
refactor DynamicSwitch
gitianvr Feb 3, 2020
f8af2e0
test for byte code switch
gitianvr Feb 3, 2020
97078c6
require ByteBuddy
gitianvr Feb 3, 2020
43371fb
first working (but still ugly) version of ByteCodeDynamicSwitch
gitianvr Feb 4, 2020
add138d
fixup require ByteBuddy
gitianvr Feb 5, 2020
277e339
add a benchmark for the bytecode switch
gitianvr Feb 5, 2020
eb2eefa
fixup require ByteBuddy
gitianvr Feb 5, 2020
bb7d868
remove accidental dependency on google commons
gitianvr Feb 5, 2020
39624b2
refactor ByteCodeDynamicSwitch
gitianvr Feb 5, 2020
ca9bf57
bugfix: make MSwitches compatible with interpackage inheritance
gitianvr Feb 5, 2020
e0d78eb
add test for BytecodeDynamicSwitchTest with cross-package inheritance
gitianvr Feb 5, 2020
a870b1e
also test HashDynamicSwitch for cross package inheritance behaviour
gitianvr Feb 5, 2020
71b2993
ignore .polyglot.properties files
gitianvr Feb 5, 2020
c1ccbee
remove unnecessary comment
gitianvr Mar 20, 2020
6567932
let bytecode switch participate in single package benchmark
gitianvr Mar 20, 2020
0a88cb8
add switches eclipse feature
gitianvr Mar 21, 2020
be62a47
Merge remote-tracking branch 'base/master'
gitianvr Mar 21, 2020
9d072a2
add .project files
gitianvr Mar 22, 2020
75c861c
fixup add .project files
gitianvr Mar 22, 2020
b854f93
documentation: switch usage and benchmark results
christianthechristian Mar 24, 2020
5992e0f
add a reference to the switch documentation
christianthechristian Mar 24, 2020
8a8a320
add to the switch docu
hackmd-deploy Mar 25, 2020
ddaa13f
code cleanup and comments
gitianvr Mar 31, 2020
fa41798
Merge branch 'master' of https://github.com/christianthechristian/Eco…
gitianvr Mar 31, 2020
2508eb4
complete docu
hackmd-deploy Apr 8, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .checkstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
<fileset name="all" enabled="true" check-config-name="Copy of Google Checks" local="false">
<file-match-pattern match-pattern="." include-pattern="true"/>
</fileset>
<filter name="DerivedFiles" enabled="true"/>
</fileset-config>
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
target/
bin/
**/.polyglot.build.properties
xtend-gen/

*.xtendbin
*._trace
*._trace
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Ecore-Workflow
# Ecore-Workflow

* see also [Switch Documentation](docu/switches.MD)
7 changes: 5 additions & 2 deletions bundles/tools.mdsd.ecoreworkflow.mwe2lib/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ Bundle-Version: 0.1.0.qualifier
Automatic-Module-Name: tools.mdsd.ecoreworkflow.mwe2lib
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: tools.mdsd.ecoreworkflow.mwe2lib.bean,
tools.mdsd.ecoreworkflow.mwe2lib.component
tools.mdsd.ecoreworkflow.mwe2lib.component,
tools.mdsd.ecoreworkflow.mwe2lib.util
Require-Bundle: org.eclipse.emf.mwe.utils,
org.eclipse.emf.ecore,
org.eclipse.emf.mwe.core,
org.apache.commons.logging,
org.eclipse.core.resources
org.eclipse.core.resources,
org.eclipse.emf.codegen.ecore;bundle-version="2.18.0"
Import-Package: org.eclipse.core.runtime
DynamicImport-Package: *
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package tools.mdsd.ecoreworkflow.mwe2lib.component;

import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
import org.eclipse.emf.codegen.ecore.genmodel.impl.GenModelImpl;
import org.eclipse.emf.common.util.URI;
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.emf.mwe.core.WorkflowContext;
import org.eclipse.emf.mwe.core.issues.Issues;
import org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent2;
import org.eclipse.emf.mwe.core.monitor.ProgressMonitor;
import org.eclipse.emf.mwe2.runtime.Mandatory;

import tools.mdsd.ecoreworkflow.mwe2lib.util.URIToPath;

/**
* MWE2 component used to generate an additional extra file for an ecore package
* based on a template.
*
*/
public class AdditionalTemplateGenerator extends AbstractWorkflowComponent2 {

private String destPath;
private String genModel;
private List<PackageLevelCodeFileGenerator> packageLevelGenerators;


public AdditionalTemplateGenerator() {
packageLevelGenerators = new ArrayList<>();
}

/**
* Set the path to the base folder.
* (This is usually a platform:-URL pointing at the target project's src-gen folder).
* The template's relative path will be resolved against this URL.
*
* @param destPath path to the base folder
*/
@Mandatory
public void setDestPath(String destPath) {
this.destPath = destPath;
}

/**
* Set the path to the .genmodel-file.
* The template will have acces to the genmodel.
*
* @param genModel path to the .genmodel file
*/
@Mandatory
public void setGenModel(String genModel) {
this.genModel = genModel;
}

/**
* Add a template (=generator) to be executed.
* @param gen classname of the generator to be added. Must be on the classpath and must be a subclass of tools.mdsd.ecoreworkflow.mwe2lib.component.PackageLevelCodeFileGenerator.
*/
public void addPackageLevelGenerator(String gen) {
try {
packageLevelGenerators.add((PackageLevelCodeFileGenerator) Class.forName(gen).getConstructor().newInstance());
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
}

// This method is the workflow component's entry point.
@Override
protected void invokeInternal(WorkflowContext workflowContext, ProgressMonitor progressMonitor, Issues issues) {
// ProgressMonitor is a (useless) NullProgressMonitor in the mwe2 context :(
progressMonitor.beginTask("Creating additional templates", 20);

GenModel loadedGenModel = loadGenModel(this.genModel);
runGenerator(loadedGenModel);

progressMonitor.done();

}

/**
* Load the genmodel as an ecore resource
* @param pathToGenmodelFile TODO
* @return
*/
private GenModel loadGenModel(String pathToGenmodelFile) {
ResourceSet resSet = new ResourceSetImpl();
Resource resource = resSet.getResource(URI.createURI(pathToGenmodelFile), true);
GenModel genModel = (GenModelImpl) resource.getContents().get(0);
return genModel;
}

private void runGenerator(GenModel genModel) {
genModel.getGenPackages().forEach(this::generatePackageLevelCode);
}

private void generatePackageLevelCode(GenPackage genPackage) {
Path path = Paths.get(new URIToPath().convertUri(URI.createURI(destPath)));
for (PackageLevelCodeFileGenerator gen : packageLevelGenerators) {
gen.setGenPackage(genPackage);
Path outfilePath = path.resolve(gen.getRelativePath());

try {
Files.createDirectories(outfilePath.getParent());
} catch (IOException e) {
throw new RuntimeException("Parent directory could not be created", e);
}

try (FileOutputStream out = new FileOutputStream(outfilePath.toFile())) {
gen.generateCode(out);
} catch (IOException e) {
throw new RuntimeException("Error writing the generated code", e);
}
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
import org.eclipse.emf.mwe.core.WorkflowContext;
import org.eclipse.emf.mwe.core.issues.Issues;
import org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent2;
import org.eclipse.emf.mwe.core.monitor.ProgressMonitor;

import tools.mdsd.ecoreworkflow.mwe2lib.util.URIToPath;

public class GapPatternPostProcessor extends AbstractWorkflowComponent2 {
private static final String CLASSNAME_MATCHER_PATTERN =
"(?<=[^a-zA-Z\\d_$])(%s)(?=[^a-zA-Z\\d_$])";
Expand Down Expand Up @@ -61,11 +60,11 @@ protected void invokeInternal(WorkflowContext arg0, ProgressMonitor arg1, Issues
try {
List<Path> manualFolders = set.getManualSourceFolders().stream()
.map(URI::createURI)
.map(this::convertUri)
.map(new URIToPath()::convertUri)
.map(Paths::get).collect(Collectors.toList());
List<Path> generatedFolders = set.getGeneratedSourceFolders().stream()
.map(URI::createURI)
.map(this::convertUri)
.map(new URIToPath()::convertUri)
.map(Paths::get)
.collect(Collectors.toList());

Expand Down Expand Up @@ -117,19 +116,4 @@ public FileVisitResult visitFile(Path arg0, BasicFileAttributes arg1) throws IOE
}
arg1.done();
}

protected String convertUri(URI uri) {
if (uri.isPlatform()) {
if (Platform.isRunning()) {
return ResourcesPlugin.getWorkspace().getRoot()
.getFile(new org.eclipse.core.runtime.Path(uri.toPlatformString(true))).getLocation()
.toString();
} else {
return EcorePlugin.resolvePlatformResourcePath(uri.toPlatformString(true)).toFileString();
}
} else {
return uriConverter.normalize(uri).toFileString();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package tools.mdsd.ecoreworkflow.mwe2lib.component;

import java.io.OutputStream;
import java.nio.file.Path;

import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;

/**
* Generator that can generate an additional single code file given a GenPackage.
* The kind and contents of the generated is completely up to the implementation.
*/
public interface PackageLevelCodeFileGenerator {
/**
* Generate the code now.
* Must only be invoked after setGenPackage
* @param out the output stream to write the code to.
*/
public void generateCode(OutputStream out);

/**
* Specify where the generated code is to be written to,
* relative to the src-gen folder of the ecore code generation
* @return a relative Path
*/
public Path getRelativePath();

/**
* Set the GenPackage that the code is to be based upon / created for.
* @param genPackage
*/
public void setGenPackage(GenPackage genPackage);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package tools.mdsd.ecoreworkflow.mwe2lib.util;

import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;

/**
* utility class for converting platform: and other URIs to absolute file paths
* (method copied from {@link tools.mdsd.ecoreworkflow.mwe2lib.component.GapPatternPostProcessor})
*
*
*/

public class URIToPath {
public String convertUri(URI uri) {
if (uri.isPlatform()) {
if (Platform.isRunning()) {
return ResourcesPlugin.getWorkspace().getRoot()
.getFile(new org.eclipse.core.runtime.Path(uri.toPlatformString(true))).getLocation()
.toString();
} else {
return EcorePlugin.resolvePlatformResourcePath(uri.toPlatformString(true)).toFileString();
}
} else {
URIConverter uriConverter = new ExtensibleURIConverterImpl();
return uriConverter.normalize(uri).toFileString();
}
}
}
8 changes: 8 additions & 0 deletions bundles/tools.mdsd.ecoreworkflow.switches/.checkstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
<fileset name="all" enabled="true" check-config-name="Copy of Google Checks" local="false">
<file-match-pattern match-pattern="." include-pattern="true"/>
</fileset>
<filter name="DerivedFiles" enabled="true"/>
</fileset-config>
8 changes: 8 additions & 0 deletions bundles/tools.mdsd.ecoreworkflow.switches/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="xtend-gen"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions bundles/tools.mdsd.ecoreworkflow.switches/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xtend-gen
40 changes: 40 additions & 0 deletions bundles/tools.mdsd.ecoreworkflow.switches/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>tools.mdsd.ecoreworkflow.switches</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
<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>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
19 changes: 19 additions & 0 deletions bundles/tools.mdsd.ecoreworkflow.switches/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: MDSD Tools Ecore Workflow Switches
Bundle-SymbolicName: tools.mdsd.ecoreworkflow.switches
Bundle-Version: 0.1.0.qualifier
Automatic-Module-Name: tools.mdsd.ecoreworkflow.switches
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: tools.mdsd.ecoreworkflow.switches
Require-Bundle: org.eclipse.emf.mwe.utils,
org.eclipse.emf.ecore,
org.eclipse.emf.mwe.core,
org.apache.commons.logging,
org.eclipse.core.resources,
org.eclipse.emf.codegen.ecore;bundle-version="2.18.0",
org.eclipse.xtext.xbase.lib;bundle-version="2.18.0",
tools.mdsd.ecoreworkflow.mwe2lib;bundle-version="0.1.0",
net.bytebuddy.byte-buddy;bundle-version="1.9.0"
Import-Package: org.eclipse.core.runtime
DynamicImport-Package: *
5 changes: 5 additions & 0 deletions bundles/tools.mdsd.ecoreworkflow.switches/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source.. = src/,\
xtend-gen/
output.. = bin/
bin.includes = META-INF/,\
.
Loading