blob: 4ed57903daa6b183ff633703ccec6ebe65b09875 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
package hu.bme.mit.inf.dslreasoner.application.execution
import com.google.inject.Guice
import com.google.inject.Injector
import hu.bme.mit.inf.dslreasoner.application.ApplicationConfigurationStandaloneSetup
import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript
import org.eclipse.core.runtime.NullProgressMonitor
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl
import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup
import org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine
import org.eclipse.xtext.resource.XtextResourceSet
class StandaloneScriptExecutor {
def static void main(String[] args) {
if(args.size == 1) {
val message = executeScript(args.head)
if(message !== null) {
println(message)
}
} else if(args.size == 0){
println('''Run generator with script file path as parameter!''')
} else { // args.size > 1
println('''Multiple arguments are not supported! Run generator with script file path as parameter!''')
}
}
static def protected Injector internalCreateInjector() {
var newInjector = new EMFPatternLanguageStandaloneSetup().createInjectorAndDoEMFRegistration();
val PatternLanguageWithRSModule module = new PatternLanguageWithRSModule
newInjector = Guice.createInjector(module)
//val XtextInjectorProvider x = null
return newInjector;
}
def static loadScript(String path) {
//Initialise extensions
val i = (new PatternLanguageWithRSSetup).createInjectorAndDoEMFRegistration
//PatternLanguageWithRSSetup.createInjectorAndDoEMFRegistration
ApplicationConfigurationStandaloneSetup.doSetup
Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("xmi",new XMIResourceFactoryImpl)
Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("logicproblem",new XMIResourceFactoryImpl)
Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("partialmodel",new XMIResourceFactoryImpl)
ReteEngine.getClass
val ext = path.split("\\.").last
if(ext.equals("vsconfig")) {
val resourceSet = //new ResourceSetImpl
i.getInstance(XtextResourceSet);
var Resource resource
try{
resource = resourceSet.getResource(URI.createURI(path),true)
} catch(Exception e) {
val message = '''Unable to load Configuration Script! «e.message»'''
throw new IllegalArgumentException(message)
}
EcoreUtil::resolveAll(resource)
val errors = resource.errors
if(errors.empty) {
val content = resource.contents.head
if(content instanceof ConfigurationScript) {
return content
} else {
val message = '''Content is not a Configuration Script! (Found : «content.class.simpleName»)'''
throw new IllegalArgumentException(message)
}
} else {
val message = '''
The Configuration Script contains «errors.size» error«IF errors.size>1»s«ENDIF»:
«FOR error : errors»
«"\t"»«error.message»
«ENDFOR»
'''
throw new IllegalArgumentException(message)
}
} else {
throw new IllegalArgumentException('''Unsupported file extension: «ext»''')
}
}
def static executeScript(String path) {
executeScript(path, StandardOutputBasedScriptConsole.FACTORY)
}
def static executeScript(String path, ScriptConsole.Factory scriptConsoleFactory){
val executor = new ScriptExecutor(scriptConsoleFactory)
try{
val content = loadScript(path)
executor.executeScript(content,new NullProgressMonitor)
return null
} catch(Exception e) {
return e.message
}
}
}
|