-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathCommandLineLauncher.java
More file actions
74 lines (63 loc) · 2.75 KB
/
CommandLineLauncher.java
File metadata and controls
74 lines (63 loc) · 2.75 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
package liquidjava.api;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import liquidjava.diagnostics.Diagnostics;
import liquidjava.diagnostics.errors.CustomError;
import liquidjava.diagnostics.warnings.CustomWarning;
import liquidjava.processor.RefinementProcessor;
import spoon.Launcher;
import spoon.processing.ProcessingManager;
import spoon.reflect.declaration.CtPackage;
import spoon.reflect.factory.Factory;
import spoon.support.QueueProcessingManager;
public class CommandLineLauncher {
private static final Diagnostics diagnostics = Diagnostics.getInstance();
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("No input paths provided");
System.out.println("\nUsage: ./liquidjava <...paths>");
System.out.println(" <...paths>: Paths to be verified by LiquidJava");
System.out.println(
"\nExample: ./liquidjava liquidjava-example/src/main/java/test liquidjava-example/src/main/java/testingInProgress/Account.java");
return;
}
List<String> paths = Arrays.asList(args);
launch(paths.toArray(new String[0]));
// print diagnostics
if (diagnostics.foundWarning()) {
System.out.println(diagnostics.getWarningOutput());
}
if (diagnostics.foundError()) {
System.out.println(diagnostics.getErrorOutput());
} else {
System.out.println("Correct! Passed Verification.");
}
}
public static void launch(String... paths) {
System.out.println("Running LiquidJava on: " + Arrays.toString(paths).replaceAll("[\\[\\]]", ""));
diagnostics.clear();
Launcher launcher = new Launcher();
for (String path : paths) {
if (!new File(path).exists()) {
diagnostics.add(new CustomError("The path " + path + " was not found"));
return;
}
launcher.addInputResource(path);
}
launcher.getEnvironment().setNoClasspath(true);
launcher.getEnvironment().setComplianceLevel(8);
boolean buildSuccess = launcher.getModelBuilder().build();
if (!buildSuccess) {
diagnostics.add(new CustomWarning("Java compilation error detected. Verification might be affected."));
}
final Factory factory = launcher.getFactory();
final ProcessingManager processingManager = new QueueProcessingManager(factory);
final RefinementProcessor processor = new RefinementProcessor(factory);
processingManager.addProcessor(processor);
// analyze all packages
CtPackage root = factory.Package().getRootPackage();
if (root != null)
processingManager.process(root);
}
}