11package liquidjava .api ;
22
3+ import java .io .File ;
34import java .util .Arrays ;
45import java .util .List ;
5-
66import liquidjava .errors .ErrorEmitter ;
77import liquidjava .processor .RefinementProcessor ;
88import spoon .Launcher ;
99import spoon .processing .ProcessingManager ;
10+ import spoon .reflect .declaration .CtPackage ;
1011import spoon .reflect .factory .Factory ;
1112import spoon .support .QueueProcessingManager ;
1213
@@ -21,34 +22,35 @@ public static void main(String[] args) {
2122 System .out .println ("No input files or directories provided" );
2223 System .out .println ("\n Usage: ./liquidjava <...paths>" );
2324 System .out .println (" <...paths>: Paths to files or directories to be verified by LiquidJava" );
24- System .out .println ("\n Example: ./liquidjava liquidjava-example/src/main/java/test/currentlyTesting liquidjava-example/src/main/java/testingInProgress/Account.java" );
25+ System .out .println (
26+ "\n Example: ./liquidjava liquidjava-example/src/main/java/test/currentlyTesting liquidjava-example/src/main/java/testingInProgress/Account.java" );
2527 return ;
2628 }
27- List <String > files = Arrays .asList (args );
28- ErrorEmitter ee = launch (files .toArray (new String [0 ]));
29+ List <String > paths = Arrays .asList (args );
30+ ErrorEmitter ee = launch (paths .toArray (new String [0 ]));
2931 System .out .println (ee .foundError () ? (ee .getFullMessage ()) : ("Correct! Passed Verification." ));
3032 }
3133
3234 /**
33- * Launch the LiquidJava verifier on the given file (for testing purposes)
34- * @param file Path to the file to be verified
35+ * Launch the LiquidJava verifier on the given file or directory paths
36+ * @param paths Array of paths to be verified
3537 * @return ErrorEmitter containing any errors found during verification
3638 */
37- public static ErrorEmitter launchTest (String file ) {
38- ErrorEmitter ee = launch (file );
39- return ee ;
40- }
39+ public static ErrorEmitter launch (String ... paths ) {
40+ ErrorEmitter ee = new ErrorEmitter ();
4141
42- /**
43- * Launch the LiquidJava verifier on the given files
44- * @param files Array of file paths to be verified
45- * @return ErrorEmitter containing any errors found during verification
46- */
47- public static ErrorEmitter launch (String ... files ) {
48- System .out .println ("Running LiquidJava on: " + Arrays .toString (files ).replaceAll ("[\\ [\\ ]]" , "" ));
42+ // check if paths exist
43+ for (String path : paths ) {
44+ if (!new File (path ).exists ()) {
45+ ee .addError ("Path not found" , "The path " + path + " does not exist" , 1 );
46+ return ee ;
47+ }
48+ }
49+
50+ System .out .println ("Running LiquidJava on: " + Arrays .toString (paths ).replaceAll ("[\\ [\\ ]]" , "" ));
4951 Launcher launcher = new Launcher ();
50- for (String file : files ) {
51- launcher .addInputResource (file );
52+ for (String path : paths ) {
53+ launcher .addInputResource (path );
5254 }
5355 launcher .getEnvironment ().setNoClasspath (true );
5456
@@ -65,24 +67,28 @@ public static ErrorEmitter launch(String... files) {
6567
6668 final Factory factory = launcher .getFactory ();
6769 final ProcessingManager processingManager = new QueueProcessingManager (factory );
68-
69- ErrorEmitter ee = new ErrorEmitter ();
7070 final RefinementProcessor processor = new RefinementProcessor (factory , ee );
7171 processingManager .addProcessor (processor );
7272
7373 try {
74- // To only search the last package - less time spent
75- // CtPackage v = factory.Package().getAll().stream().reduce((first, second) ->
76- // second).orElse(null);
77- // if (v != null)
78- // processingManager.process(v);
79- // To search all previous packages
80- processingManager .process (factory .Package ().getRootPackage ());
74+ // analyze all packages
75+ CtPackage root = factory .Package ().getRootPackage ();
76+ if (root != null )
77+ processingManager .process (root );
8178 } catch (Exception e ) {
8279 e .printStackTrace ();
8380 throw e ;
8481 }
8582
8683 return ee ;
8784 }
85+
86+ /**
87+ * Launch the LiquidJava verifier on the given file or directory path (for testing purposes)
88+ * @param path Path to to be verified
89+ * @return ErrorEmitter containing any errors found during verification
90+ */
91+ public static ErrorEmitter launchTest (String path ) {
92+ return launch (path );
93+ }
8894}
0 commit comments