|
1 | | -package liquidjava.api; |
2 | | - |
3 | | -import static liquidjava.diagnostics.LJDiagnostics.diagnostics; |
4 | | - |
5 | | -import java.io.File; |
6 | | -import java.util.Arrays; |
7 | | -import java.util.List; |
8 | | - |
9 | | -import liquidjava.diagnostics.errors.CustomError; |
10 | | -import liquidjava.processor.RefinementProcessor; |
11 | | -import spoon.Launcher; |
12 | | -import spoon.processing.ProcessingManager; |
13 | | -import spoon.reflect.declaration.CtPackage; |
14 | | -import spoon.reflect.factory.Factory; |
15 | | -import spoon.support.QueueProcessingManager; |
16 | | - |
17 | | -public class CommandLineLauncher { |
18 | | - public static void main(String[] args) { |
19 | | - if (args.length == 0) { |
20 | | - System.out.println("No input paths provided"); |
21 | | - System.out.println("\nUsage: ./liquidjava <...paths>"); |
22 | | - System.out.println(" <...paths>: Paths to be verified by LiquidJava"); |
23 | | - System.out.println( |
24 | | - "\nExample: ./liquidjava liquidjava-example/src/main/java/test liquidjava-example/src/main/java/testingInProgress/Account.java"); |
25 | | - return; |
26 | | - } |
27 | | - List<String> paths = Arrays.asList(args); |
28 | | - launch(paths.toArray(new String[0])); |
29 | | - if (diagnostics.foundError()) { |
30 | | - System.out.println(diagnostics.getErrorOutput()); |
31 | | - } else { |
32 | | - System.out.println(diagnostics.getWarningOutput()); |
33 | | - System.out.println("Correct! Passed Verification."); |
34 | | - } |
35 | | - } |
36 | | - |
37 | | - public static void launch(String... paths) { |
38 | | - System.out.println("Running LiquidJava on: " + Arrays.toString(paths).replaceAll("[\\[\\]]", "")); |
39 | | - |
40 | | - Launcher launcher = new Launcher(); |
41 | | - for (String path : paths) { |
42 | | - if (!new File(path).exists()) { |
43 | | - diagnostics.add(new CustomError("The path " + path + " was not found")); |
44 | | - return; |
45 | | - } |
46 | | - launcher.addInputResource(path); |
47 | | - } |
48 | | - |
49 | | - launcher.getEnvironment().setNoClasspath(true); |
50 | | - launcher.getEnvironment().setComplianceLevel(8); |
51 | | - launcher.run(); |
52 | | - diagnostics.clear(); |
53 | | - |
54 | | - final Factory factory = launcher.getFactory(); |
55 | | - final ProcessingManager processingManager = new QueueProcessingManager(factory); |
56 | | - final RefinementProcessor processor = new RefinementProcessor(factory); |
57 | | - processingManager.addProcessor(processor); |
58 | | - |
59 | | - try { |
60 | | - // analyze all packages |
61 | | - CtPackage root = factory.Package().getRootPackage(); |
62 | | - if (root != null) |
63 | | - processingManager.process(root); |
64 | | - } catch (Exception e) { |
65 | | - e.printStackTrace(); |
66 | | - throw e; |
67 | | - } |
68 | | - |
69 | | - return; |
70 | | - } |
71 | | -} |
| 1 | +package liquidjava.api; |
| 2 | + |
| 3 | +import static liquidjava.diagnostics.LJDiagnostics.diagnostics; |
| 4 | + |
| 5 | +import java.io.File; |
| 6 | +import java.util.Arrays; |
| 7 | +import java.util.List; |
| 8 | + |
| 9 | +import liquidjava.diagnostics.errors.CustomError; |
| 10 | +import liquidjava.processor.RefinementProcessor; |
| 11 | +import spoon.Launcher; |
| 12 | +import spoon.processing.ProcessingManager; |
| 13 | +import spoon.reflect.declaration.CtPackage; |
| 14 | +import spoon.reflect.factory.Factory; |
| 15 | +import spoon.support.QueueProcessingManager; |
| 16 | + |
| 17 | +public class CommandLineLauncher { |
| 18 | + public static void main(String[] args) { |
| 19 | + if (args.length == 0) { |
| 20 | + System.out.println("No input paths provided"); |
| 21 | + System.out.println("\nUsage: ./liquidjava <...paths>"); |
| 22 | + System.out.println(" <...paths>: Paths to be verified by LiquidJava"); |
| 23 | + System.out.println( |
| 24 | + "\nExample: ./liquidjava liquidjava-example/src/main/java/test liquidjava-example/src/main/java/testingInProgress/Account.java"); |
| 25 | + return; |
| 26 | + } |
| 27 | + List<String> paths = Arrays.asList(args); |
| 28 | + launch(paths.toArray(new String[0])); |
| 29 | + if (diagnostics.foundError()) { |
| 30 | + System.out.println(diagnostics.getErrorOutput()); |
| 31 | + } else { |
| 32 | + System.out.println(diagnostics.getWarningOutput()); |
| 33 | + System.out.println("Correct! Passed Verification."); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + public static void launch(String... paths) { |
| 38 | + System.out.println("Running LiquidJava on: " + Arrays.toString(paths).replaceAll("[\\[\\]]", "")); |
| 39 | + |
| 40 | + Launcher launcher = new Launcher(); |
| 41 | + for (String path : paths) { |
| 42 | + if (!new File(path).exists()) { |
| 43 | + diagnostics.add(new CustomError("The path " + path + " was not found")); |
| 44 | + return; |
| 45 | + } |
| 46 | + launcher.addInputResource(path); |
| 47 | + } |
| 48 | + |
| 49 | + launcher.getEnvironment().setNoClasspath(true); |
| 50 | + launcher.getEnvironment().setComplianceLevel(8); |
| 51 | + launcher.run(); |
| 52 | + diagnostics.clear(); |
| 53 | + |
| 54 | + final Factory factory = launcher.getFactory(); |
| 55 | + final ProcessingManager processingManager = new QueueProcessingManager(factory); |
| 56 | + final RefinementProcessor processor = new RefinementProcessor(factory); |
| 57 | + processingManager.addProcessor(processor); |
| 58 | + |
| 59 | + try { |
| 60 | + // analyze all packages |
| 61 | + CtPackage root = factory.Package().getRootPackage(); |
| 62 | + if (root != null) |
| 63 | + processingManager.process(root); |
| 64 | + } catch (Exception e) { |
| 65 | + e.printStackTrace(); |
| 66 | + throw e; |
| 67 | + } |
| 68 | + |
| 69 | + return; |
| 70 | + } |
| 71 | +} |
0 commit comments