diff options
author | OszkarSemerath <oszkar.semerath@gmail.com> | 2018-07-06 15:19:02 +0200 |
---|---|---|
committer | OszkarSemerath <oszkar.semerath@gmail.com> | 2018-07-06 15:19:02 +0200 |
commit | 3961e8630edc5cb9f13d352383f6f7be59fdf457 (patch) | |
tree | 582e69a41423e1e2d8c7f237722af4d90c893b2a | |
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
3 files changed, 192 insertions, 0 deletions
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/ApplicationConfigurationStandaloneRuntimeModule.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/ApplicationConfigurationStandaloneRuntimeModule.xtend new file mode 100644 index 00000000..2738dfff --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/ApplicationConfigurationStandaloneRuntimeModule.xtend | |||
@@ -0,0 +1,53 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application | ||
2 | |||
3 | import com.google.inject.Binder | ||
4 | import com.google.inject.multibindings.Multibinder | ||
5 | import hu.bme.mit.inf.dslreasoner.application.linking.ApplicationConfigurationLinkingService | ||
6 | import hu.bme.mit.inf.dslreasoner.application.valueconverter.ApplicationConfigurationValueConverterService | ||
7 | import org.apache.log4j.Logger | ||
8 | import org.eclipse.viatra.query.patternlanguage.emf.GenmodelExtensionLoader | ||
9 | import org.eclipse.viatra.query.patternlanguage.emf.IGenmodelMappingLoader | ||
10 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.CompoundMetamodelProviderService | ||
11 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProvider | ||
12 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProviderInstance | ||
13 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.MetamodelProviderService | ||
14 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.ResourceSetMetamodelProviderService | ||
15 | import org.eclipse.viatra.query.tooling.core.targetplatform.ITargetPlatformMetamodelLoader | ||
16 | import org.eclipse.viatra.query.tooling.core.targetplatform.TargetPlatformMetamodelProviderService | ||
17 | import org.eclipse.viatra.query.tooling.core.targetplatform.TargetPlatformMetamodelsIndex | ||
18 | |||
19 | /** | ||
20 | * Use this class to register components to be used at runtime / without the Equinox extension registry. | ||
21 | */ | ||
22 | class ApplicationConfigurationStandaloneRuntimeModule extends AbstractApplicationConfigurationRuntimeModule { | ||
23 | override bindILinkingService() { | ||
24 | ApplicationConfigurationLinkingService | ||
25 | } | ||
26 | |||
27 | def configureLoggerImplementation(Binder binder) { | ||
28 | binder.bind(Logger).toInstance(Logger.getLogger(ApplicationConfigurationStandaloneRuntimeModule)) | ||
29 | } | ||
30 | |||
31 | def Class<? extends IMetamodelProvider> bindIMetamodelProvider() { | ||
32 | CompoundMetamodelProviderService | ||
33 | } | ||
34 | |||
35 | def configureMetamodelProviderInstance(Binder binder) { | ||
36 | val metamodelProviderBinder = Multibinder.newSetBinder(binder, IMetamodelProviderInstance) | ||
37 | metamodelProviderBinder.addBinding.to(MetamodelProviderService) | ||
38 | metamodelProviderBinder.addBinding.to(ResourceSetMetamodelProviderService) | ||
39 | //metamodelProviderBinder.addBinding.to(TargetPlatformMetamodelProviderService) | ||
40 | } | ||
41 | |||
42 | |||
43 | |||
44 | override bindIValueConverterService() { | ||
45 | ApplicationConfigurationValueConverterService | ||
46 | } | ||
47 | def Class<? extends IGenmodelMappingLoader> bindIGenmodelMappingLoader() { | ||
48 | GenmodelExtensionLoader | ||
49 | } | ||
50 | // def Class<? extends ITargetPlatformMetamodelLoader> bindITargetPlatformMetamodelLoader() { | ||
51 | // TargetPlatformMetamodelsIndex | ||
52 | // } | ||
53 | } \ No newline at end of file | ||
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 | ||
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/workspace/URIBasedWorkspace.xtend b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/workspace/URIBasedWorkspace.xtend new file mode 100644 index 00000000..37db4c3f --- /dev/null +++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/workspace/URIBasedWorkspace.xtend | |||
@@ -0,0 +1,65 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.workspace | ||
2 | |||
3 | import org.eclipse.emf.common.util.URI | ||
4 | |||
5 | class URIBasedWorkspace extends ReasonerWorkspace{ | ||
6 | val ReasonerWorkspace delegatedWorkspace; | ||
7 | |||
8 | new(String targetFolder, String prefix) { | ||
9 | super(targetFolder, prefix) | ||
10 | val targetFolderURI = URI.createURI(targetFolder) | ||
11 | if(targetFolderURI.isFile) { | ||
12 | delegatedWorkspace = new FileSystemWorkspace(targetFolder,prefix) | ||
13 | } else if(targetFolderURI.isPlatformResource){ | ||
14 | delegatedWorkspace = new ProjectWorkspace(targetFolder,prefix) | ||
15 | } else { | ||
16 | delegatedWorkspace = null | ||
17 | throw new UnsupportedOperationException('''Unknown URI: «targetFolder»''') | ||
18 | } | ||
19 | } | ||
20 | |||
21 | override subWorkspace(String targetFolder, String prefix) { | ||
22 | delegatedWorkspace.subWorkspace(targetFolder,prefix) | ||
23 | } | ||
24 | |||
25 | override getWorkspaceURI() { | ||
26 | delegatedWorkspace.getWorkspaceURI | ||
27 | } | ||
28 | |||
29 | override init() { | ||
30 | delegatedWorkspace.init | ||
31 | } | ||
32 | |||
33 | override clear() { | ||
34 | delegatedWorkspace.clear | ||
35 | } | ||
36 | |||
37 | override protected getURI(String name) { | ||
38 | delegatedWorkspace.getURI(name) | ||
39 | } | ||
40 | |||
41 | override getFile(String name) { | ||
42 | delegatedWorkspace.getFile(name) | ||
43 | } | ||
44 | |||
45 | override refreshFile(String name) { | ||
46 | delegatedWorkspace.refreshFile(name) | ||
47 | } | ||
48 | |||
49 | override protected renameFile(String name) { | ||
50 | delegatedWorkspace.renameFile(name) | ||
51 | } | ||
52 | |||
53 | override allFiles() { | ||
54 | delegatedWorkspace.allFiles | ||
55 | } | ||
56 | |||
57 | override writeText(String name, CharSequence content) { | ||
58 | delegatedWorkspace.writeText(name, content) | ||
59 | } | ||
60 | |||
61 | override readText(String name) { | ||
62 | delegatedWorkspace.readText(name) | ||
63 | } | ||
64 | |||
65 | } \ No newline at end of file | ||