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