Skip to content

Commit 891fc5d

Browse files
committed
correct logic in Driver and adapt ATOL solution
1 parent bcef136 commit 891fc5d

File tree

5 files changed

+76
-47
lines changed

5 files changed

+76
-47
lines changed

models/emptyChange.xmi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="ASCII"?>
2+
<xmi:XMI xmi:version="2.0"
3+
xmlns:xmi="http://www.omg.org/XMI"
4+
xmlns="Changes">
5+
</xmi:XMI>

solutions/atol/transformation/src/main/java/atol/example/transformation/Run.xtend

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,38 @@ package atol.example.transformation
33

44
import atl.research.AbstractDriver
55
import atl.research.class_.Class
6+
import atl.research.class_.DataType
67
import io.github.atlresearch.emfmodelfuzzer.SimpleEMFModelFuzzer
78
import org.eclipse.emf.ecore.EObject
89

910

1011
class Run extends AbstractDriver {
11-
val Class2Relational transformation
12+
var Class2Relational transformation
1213

1314
static def void main(String[] args) {
14-
new Run()
15-
}
15+
val solution = new Run()
1616

17-
new() throws Exception {
18-
// call AbstractDriver constructor to initialize source, changes and target
19-
super()
17+
solution.init
18+
solution.applyTransformation
19+
solution.applyChange
20+
solution.saveTarget
21+
}
2022

23+
new() {
2124
// initialize transformation
22-
transformation = new Class2Relational()
25+
this.transformation = new Class2Relational()
2326

2427
// other initialization code
2528
}
2629

2730
override void applyTransformation() {
2831
for(EObject e : source.contents) {
2932
if(e instanceof Class) {
30-
val res = transformation.Class2Table(e)._out
33+
val res = this.transformation.Class2Table(e)._out
34+
target.contents.add(res)
35+
}
36+
else if (e instanceof DataType) {
37+
val res = this.transformation.DataType2Type(e)._out
3138
target.contents.add(res)
3239
}
3340
}

utils/SolutionDriver/build.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
plugins {
2+
id 'application'
23
id 'java-library'
34
id 'maven-publish'
45
}
@@ -10,10 +11,14 @@ repositories {
1011
}
1112

1213
dependencies {
13-
implementation 'org.eclipse.emf:org.eclipse.emf.ecore:2.33.0'
14-
implementation "org.eclipse.emf:org.eclipse.emf.ecore.xmi:2.18.0"
14+
implementation 'org.eclipse.emf:org.eclipse.emf.ecore:+'
15+
implementation "org.eclipse.emf:org.eclipse.emf.ecore.xmi:+"
1516
}
1617

18+
application {
19+
// Define the main class for the application.
20+
mainClass = 'atl.research.ExampleSolution'
21+
}
1722

1823
publishing {
1924
publications {

utils/SolutionDriver/src/main/java/atl/research/AbstractDriver.java

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,7 @@ public abstract class AbstractDriver {
2020
Resource target;
2121
Resource changes;
2222

23-
public AbstractDriver() throws Exception {
24-
// setup EMF resource set to load models
25-
setupResourceSet();
2623

27-
// loading & creating models
28-
if (System.getenv("SOURCE_PATH") == null) {
29-
throw new Exception("SOURCE_PATH environment variable not set");
30-
}
31-
else if (System.getenv("CHANGE_PATH") == null) {
32-
throw new Exception("CHANGE_PATH environment variable not set");
33-
}
34-
else if (System.getenv("TARGET_PATH") == null) {
35-
throw new Exception("TARGET_PATH environment variable not set");
36-
}
37-
38-
source = loadModel(System.getenv("SOURCE_PATH"));
39-
changes = loadModel(System.getenv("CHANGES_PATH"));
40-
target = createModel(System.getenv("TARGET_PATH"));
41-
42-
// apply transformation
43-
applyTransformation();
44-
45-
// apply changes
46-
applyChange();
47-
48-
// save target model
49-
saveTarget();
50-
}
51-
52-
53-
5424

5525
public Resource getSource() {
5626
return source;
@@ -62,8 +32,12 @@ public Resource getTarget() {
6232
return target;
6333
}
6434

65-
66-
void setupResourceSet() {
35+
public void init() throws Exception {
36+
setupResourceSet();
37+
loadModels();
38+
}
39+
40+
protected void setupResourceSet() {
6741
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
6842
"xmi",
6943
new XMIResourceFactoryImpl()
@@ -82,23 +56,40 @@ void setupResourceSet() {
8256
);
8357
}
8458

85-
Resource loadModel(String modelPath) {
86-
return resourceSet.getResource(URI.createFileURI(modelPath), false);
59+
protected void loadModels() throws Exception {
60+
if (System.getenv("SOURCE_PATH") == null) {
61+
throw new Exception("SOURCE_PATH environment variable not set");
62+
}
63+
else if (System.getenv("CHANGE_PATH") == null) {
64+
throw new Exception("CHANGE_PATH environment variable not set");
65+
}
66+
else if (System.getenv("TARGET_PATH") == null) {
67+
throw new Exception("TARGET_PATH environment variable not set");
68+
}
69+
70+
source = loadModel(System.getenv("SOURCE_PATH"));
71+
changes = loadModel(System.getenv("CHANGE_PATH"));
72+
target = createModel(System.getenv("TARGET_PATH"));
73+
}
74+
75+
private Resource loadModel(String modelPath) {
76+
System.out.println("Loading model from " + modelPath);
77+
return resourceSet.getResource(URI.createFileURI(modelPath), true);
8778
}
8879

89-
Resource createModel(String modelPath) {
80+
private Resource createModel(String modelPath) {
9081
return resourceSet.createResource(URI.createFileURI(modelPath));
9182
}
9283

93-
void applyChange() {
84+
protected void applyChange() {
9485
// we ignore change models that are empty (for checking correctness)
9586
if (changes.getContents().size() > 0) {
9687
ModelChange change = (ModelChange) changes.getContents().get(0);
9788
change.apply();
9889
}
9990
}
10091

101-
void saveTarget() throws IOException {
92+
protected void saveTarget() throws IOException {
10293
target.save(Collections.emptyMap());
10394
}
10495

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package atl.research;
2+
3+
import org.eclipse.emf.ecore.EObject;
4+
5+
public class ExampleSolution extends AbstractDriver {
6+
public static void main(String[] args) throws Exception {
7+
ExampleSolution solution = new ExampleSolution();
8+
9+
solution.init();
10+
solution.applyTransformation();
11+
solution.applyChange();
12+
solution.saveTarget();
13+
}
14+
15+
@Override
16+
protected void applyTransformation() {
17+
for (EObject e : this.getSource().getContents()) {
18+
System.out.println(e);
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)