diff options
author | 2018-07-06 15:19:02 +0200 | |
---|---|---|
committer | 2018-07-06 15:19:02 +0200 | |
commit | 3961e8630edc5cb9f13d352383f6f7be59fdf457 (patch) | |
tree | 582e69a41423e1e2d8c7f237722af4d90c893b2a /Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution | |
parent | Added support for running application in plain java. (diff) | |
download | VIATRA-Generator-3961e8630edc5cb9f13d352383f6f7be59fdf457.tar.gz VIATRA-Generator-3961e8630edc5cb9f13d352383f6f7be59fdf457.tar.zst VIATRA-Generator-3961e8630edc5cb9f13d352383f6f7be59fdf457.zip |
Additional packages for standalone runtime environment
Diffstat (limited to 'Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution')
-rw-r--r-- | Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/StandaloneScriptExecutor.xtend | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/StandaloneScriptExecutor.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/StandaloneScriptExecutor.xtend new file mode 100644 index 00000000..825bfdcc --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/StandaloneScriptExecutor.xtend | |||
@@ -0,0 +1,74 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.execution | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.application.ApplicationConfigurationStandaloneSetup | ||
4 | import org.eclipse.emf.common.util.URI | ||
5 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl | ||
6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript | ||
7 | import org.eclipse.core.runtime.NullProgressMonitor | ||
8 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup | ||
9 | import org.eclipse.emf.ecore.util.EcoreUtil | ||
10 | import java.io.FileNotFoundException | ||
11 | import org.eclipse.emf.ecore.resource.Resource | ||
12 | import java.io.IOException | ||
13 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | ||
14 | import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackendFactoryProvider | ||
15 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteBackendFactoryProvider | ||
16 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngineOptions | ||
17 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint | ||
18 | import org.eclipse.viatra.query.runtime.rete.util.ReteHintOptions | ||
19 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine | ||
20 | |||
21 | class StandaloneScriptExecutor { | ||
22 | def static void main(String[] args) { | ||
23 | if(args.size == 1) { | ||
24 | val message = executeScript(args.head) | ||
25 | println(message) | ||
26 | } else if(args.size == 0){ | ||
27 | println('''Run generator with script file path as parameter!''') | ||
28 | } else { // args.size > 1 | ||
29 | println('''Multiple arguments are not supported! Run generator with script file path as parameter!''') | ||
30 | } | ||
31 | } | ||
32 | |||
33 | def static executeScript(String path){ | ||
34 | //Initialise extensions | ||
35 | EMFPatternLanguageStandaloneSetup.doSetup | ||
36 | ApplicationConfigurationStandaloneSetup.doSetup | ||
37 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("xmi",new XMIResourceFactoryImpl) | ||
38 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("logicproblem",new XMIResourceFactoryImpl) | ||
39 | ReteEngine.getClass | ||
40 | |||
41 | val ext = path.split("\\.").last | ||
42 | if(ext.equals("vsconfig")) { | ||
43 | val resourceSet = new ResourceSetImpl | ||
44 | var Resource resource | ||
45 | |||
46 | try{ | ||
47 | resource = resourceSet.getResource(URI.createURI(path),true) | ||
48 | } catch(Exception e) { | ||
49 | return '''Unable to load Configuration Script!''' | ||
50 | } | ||
51 | |||
52 | EcoreUtil::resolveAll(resource) | ||
53 | val errors = resource.errors | ||
54 | if(errors.empty) { | ||
55 | val content = resource.contents.head | ||
56 | if(content instanceof ConfigurationScript) { | ||
57 | val executor = new ScriptExecutor | ||
58 | executor.executeScript(content,new NullProgressMonitor) | ||
59 | } else { | ||
60 | return('''Content is not a Configuration Script! (Found : «content.class.simpleName»)''') | ||
61 | } | ||
62 | } else { | ||
63 | return ''' | ||
64 | The Configuration Script contains «errors.size» error«IF errors.size>1»s«ENDIF»: | ||
65 | «FOR error : errors» | ||
66 | «"\t"»«error.message» | ||
67 | «ENDFOR» | ||
68 | ''' | ||
69 | } | ||
70 | } else { | ||
71 | return '''Unsupported file extension: «ext»''' | ||
72 | } | ||
73 | } | ||
74 | } \ No newline at end of file | ||