]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics/src/org/simantics/SCLScriptRunnerApplication.java
Include acorn db in db.client feature and make it the default db driver
[simantics/platform.git] / bundles / org.simantics / src / org / simantics / SCLScriptRunnerApplication.java
1 package org.simantics;\r
2 \r
3 import java.io.BufferedReader;\r
4 import java.io.IOException;\r
5 import java.io.InputStreamReader;\r
6 \r
7 import org.eclipse.core.runtime.IProgressMonitor;\r
8 import org.eclipse.core.runtime.NullProgressMonitor;\r
9 import org.eclipse.equinox.app.IApplication;\r
10 import org.eclipse.equinox.app.IApplicationContext;\r
11 import org.simantics.application.arguments.Arguments;\r
12 import org.simantics.application.arguments.IArgumentFactory;\r
13 import org.simantics.application.arguments.IArguments;\r
14 import org.simantics.application.arguments.SimanticsArguments;\r
15 import org.simantics.scl.compiler.commands.CommandSession;\r
16 import org.simantics.scl.osgi.SCLOsgi;\r
17 import org.simantics.scl.runtime.reporting.SCLReportingHandler;\r
18 \r
19 public class SCLScriptRunnerApplication implements IApplication {\r
20 \r
21         @Override\r
22         public Object start(IApplicationContext context) throws Exception {\r
23                 try {\r
24             String[] args = (String[])context.getArguments().get("application.args");\r
25             IProgressMonitor progress = new NullProgressMonitor();\r
26             Simantics.startUpHeadless(parseArguments(args), progress);\r
27             runSCLFromStdin();\r
28             Simantics.shutdown(progress);\r
29             return IApplication.EXIT_OK;\r
30         } catch(Throwable t) {\r
31             t.printStackTrace();\r
32             throw (Exception)t;\r
33         } finally {\r
34             System.exit(0);\r
35         }\r
36         }\r
37         \r
38         private void runSCLFromStdin() throws Exception {\r
39                 BufferedReader input = new BufferedReader(new InputStreamReader(System.in));\r
40                 CommandSession commandSession = new CommandSession(SCLOsgi.MODULE_REPOSITORY,\r
41                         SCLReportingHandler.DEFAULT_WITHOUT_ECHO);\r
42                 try {\r
43                         while(true) {\r
44                                 String line = input.readLine();\r
45                                 if(line == null)\r
46                                         break;\r
47                                 if(line.isEmpty())\r
48                                         continue;\r
49                                 commandSession.execute(line);\r
50                         }\r
51                 } catch(IOException e) {\r
52                         e.printStackTrace();\r
53                 }               \r
54         }\r
55 \r
56         private IArguments parseArguments(String[] args) {\r
57                 IArgumentFactory<?>[] accepted = {\r
58                                 SimanticsArguments.RECOVERY_POLICY_FIX_ERRORS,\r
59                                 SimanticsArguments.ONTOLOGY_RECOVERY_POLICY_REINSTALL,\r
60                                 SimanticsArguments.SERVER,\r
61                                 SimanticsArguments.LOCAL_SERVER_PORT,\r
62                                 SimanticsArguments.DATABASE_ID,\r
63                 };\r
64                 IArguments result = Arguments.parse(args, accepted);\r
65                 return result;\r
66         }\r
67         \r
68         @Override\r
69         public void stop() {\r
70         }\r
71 \r
72 }\r