forked from typetools/checker-framework-inference
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathInferenceCli.java
More file actions
129 lines (100 loc) · 3.68 KB
/
Copy pathInferenceCli.java
File metadata and controls
129 lines (100 loc) · 3.68 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package checkers.inference;
import org.plumelib.options.Option;
import org.plumelib.options.Options;
import java.io.IOException;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Command line launcher for Checker-Framework-Inference.
*
* <p>Parses command line options and creates InferenceMain instance to start inference system.
*/
public class InferenceCli {
private static Logger logger = Logger.getLogger(InferenceCli.class.getName());
public static final String VERSION = "2";
public static final String DEFAULT_JAIF = "default.jaif";
// Modes
@Option("-v print version")
public static boolean version;
@Option("-h print help")
public static boolean help;
// Required
@Option("[InferrableChecker] the checker to run")
public static String checker;
@Option("[Level] set the log level")
public static String log_level;
@Option("[InferenceSolver] solver to use on constraints")
public static String solver;
@Option("[path] path to write jaif")
public static String jaiffile = DEFAULT_JAIF;
@Option("encoding")
public static String encoding;
@Option("[dir] directory to write dataflow diagrams")
public static String flowdotdir;
@Option("Args to pass to javac compiler")
public static String javac_args;
@Option("Args to pass to solver")
public static String solver_args;
@Option("bootclasspath to use for compiling")
public static String bootclasspath;
@Option("showchecks")
public static boolean showchecks;
@Option("ignore logs of exceptions")
public static boolean hackmode;
@Option("only perform type checking -- don't generate class files")
public static boolean proconly = true;
@Option("[path] stubfiles to use for type checking")
public static String stubs;
// All other options passed in.
public static String[] otherOptions;
public static void main(String[] args) throws IOException {
initCli(args);
InferenceMain inferenceMain = new InferenceMain();
inferenceMain.run();
}
public static void initCli(String[] args) {
Options options = new Options("InferenceCli [options]", InferenceCli.class);
otherOptions = options.parse(true, args);
if (help) {
options.printUsage();
System.exit(0);
}
if (version) {
System.out.println("Checker-framework-inference version: " + VERSION);
System.exit(0);
}
if (log_level == null) {
setLoggingLevel(Level.INFO);
} else {
setLoggingLevel(Level.parse(log_level));
}
String optionsStr = "";
for (String arg : args) {
optionsStr += arg + " ";
}
}
/** Set the root logging level and handler level. */
public static void setLoggingLevel(Level level) {
Logger root = Logger.getLogger("");
root.setLevel(level);
// Handler for console (reuse it if it already exists)
Handler consoleHandler = null;
// see if there is already a console handler
for (Handler handler : root.getHandlers()) {
if (handler instanceof ConsoleHandler) {
// found the console handler
consoleHandler = handler;
break;
}
}
if (consoleHandler == null) {
// there was no console handler found, create a new one
consoleHandler = new ConsoleHandler();
root.addHandler(consoleHandler);
}
// set the console handler to fine:
consoleHandler.setLevel(level);
}
}