From dbd3c6544aee03280a0d6dcfbdc4d9cc86e71197 Mon Sep 17 00:00:00 2001 From: Schaef Date: Fri, 19 Jan 2018 12:50:20 -0500 Subject: [PATCH] improved the -src option to also accpet source directories --- build.gradle | 3 ++ src/main/java/bixie/Main.java | 20 ++++++----- src/main/java/bixie/Options.java | 33 ++++++++++++++++--- .../reportprinter/BasicReportPrinter.java | 2 +- .../reportprinter/HtmlReportPrinter.java | 2 +- .../reportprinter/JSONReportPrinter.java | 2 +- 6 files changed, 46 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index 0d52d1c..a32cfcb 100644 --- a/build.gradle +++ b/build.gradle @@ -89,6 +89,9 @@ dependencies { compile 'net.sourceforge.findbugs:annotations:1.3.2' compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.7.5' + // https://mvnrepository.com/artifact/org.checkerframework/checker-qual + compile group: 'org.checkerframework', name: 'checker-qual', version: '2.1.10' + compile fileTree(dir: 'lib', include: '*.jar') testCompile "junit:junit:4.11" // Or whatever version } diff --git a/src/main/java/bixie/Main.java b/src/main/java/bixie/Main.java index 4a93e23..0c0a8dd 100644 --- a/src/main/java/bixie/Main.java +++ b/src/main/java/bixie/Main.java @@ -9,6 +9,8 @@ import java.io.PrintWriter; import bixie.checker.reportprinter.JSONReportPrinter; + +import org.checkerframework.checker.nullness.qual.NonNull; import org.kohsuke.args4j.CmdLineException; import org.kohsuke.args4j.CmdLineParser; @@ -74,7 +76,7 @@ public void run(String input, String output) { if (input != null && input.endsWith(".bpl")) { try { ProgramFactory pf = new ProgramFactory(input); - ReportPrinter jp = runChecker(pf); + @NonNull ReportPrinter jp = runChecker(pf); report2File(jp); } catch (Exception e) { // TODO Auto-generated catch block @@ -112,7 +114,7 @@ public void translateAndRun(String input, String classpath, String output) { private ReportPrinter reportPrinter = null; - protected ReportPrinter getReportPrinter() { + protected @NonNull ReportPrinter getReportPrinter() { if (reportPrinter==null) { if (bixie.Options.v().getHtmlDir()!=null) { File dir = new File(bixie.Options.v().getHtmlDir()); @@ -149,12 +151,12 @@ protected ReportPrinter getReportPrinter() { return reportPrinter; } - public ReportPrinter translateAndRun(String input, String classpath) { + public @NonNull ReportPrinter translateAndRun(String input, String classpath) { return translateAndRun(input, classpath, getReportPrinter()); } - public ReportPrinter translateAndRun(String input, String classpath, - ReportPrinter reportPrinter) { + public @NonNull ReportPrinter translateAndRun(String input, String classpath, + @NonNull ReportPrinter reportPrinter) { bixie.util.Log.info("Translating. This may take a while."); bixie.translation.Main.setClassPath(classpath); @@ -164,18 +166,18 @@ public ReportPrinter translateAndRun(String input, String classpath, bixie.util.Log.info("... translation finished."); if (pf == null) { bixie.util.Log.error("Internal Error: Parsing failed"); - return null; + return reportPrinter; } ReportPrinter jp = runChecker(pf, reportPrinter); return jp; } - public ReportPrinter runChecker(ProgramFactory pf) { + public @NonNull ReportPrinter runChecker(ProgramFactory pf) { return runChecker(pf, getReportPrinter()); } - public ReportPrinter runChecker(ProgramFactory pf, - ReportPrinter reportPrinter) { + public @NonNull ReportPrinter runChecker(ProgramFactory pf, + @NonNull ReportPrinter reportPrinter) { bixie.util.Log.info("Checking"); try { ProgramAnalysis.runFullProgramAnalysis(pf, reportPrinter); diff --git a/src/main/java/bixie/Options.java b/src/main/java/bixie/Options.java index a70f6b8..d2e62e9 100644 --- a/src/main/java/bixie/Options.java +++ b/src/main/java/bixie/Options.java @@ -9,6 +9,9 @@ import java.util.HashSet; import java.util.Set; +import java.util.ArrayList; +import java.util.List; + import org.kohsuke.args4j.Option; /** @@ -64,7 +67,7 @@ public String getJSONDir() { /** * Location of the source files for reporting. */ - @Option(name = "-src", usage = "List of all source files") + @Option(name = "-src", usage = "List of all source files separated by colon, or list of root folders.") private String srcFilesString=null; private Set sourceFiles = null; public Set getSrcFilesString() { @@ -73,15 +76,37 @@ public Set getSrcFilesString() { sourceFiles = new HashSet(); if (files!=null) { for (String s : files) { - sourceFiles.add(s); + File f = new File(s); + if (f.exists()) { + if (f.isFile()) { + sourceFiles.add(f.getAbsolutePath()); + } else if (f.isDirectory()) { + sourceFiles.addAll(findFilesRecursively(f, ".java")); + } + } else { + //log error + } } } } return sourceFiles; } - @Option(name = "-serverityLimit", usage = "Maximum serverity level for warnings.") - public int serverityLimit = 2; + private List findFilesRecursively(File f, String ending) { + List res = new ArrayList(); + if (f.isDirectory()) { + for (File c : f.listFiles()) { + res.addAll(findFilesRecursively(c, ending)); + } + } else if (f.isFile() && f.getAbsolutePath().endsWith(ending)) { + res.add(f.getAbsolutePath()); + } + return res; + } + + + @Option(name = "-severityLimit", usage = "Maximum severity level for warnings.") + public int severityLimit = 2; @Option(name = "-exportStubs", usage = "Write all used stubs to file") diff --git a/src/main/java/bixie/checker/reportprinter/BasicReportPrinter.java b/src/main/java/bixie/checker/reportprinter/BasicReportPrinter.java index 8615dde..9f951db 100644 --- a/src/main/java/bixie/checker/reportprinter/BasicReportPrinter.java +++ b/src/main/java/bixie/checker/reportprinter/BasicReportPrinter.java @@ -73,7 +73,7 @@ public String printSummary() { //TODO: don't hard code the keys. sb.append("In File: " + fname+"\n"); cirtical+= printReportForFileBySeverity(sb, fname, 0, "** Critical **"); - if (bixie.Options.v().serverityLimit>0){ + if (bixie.Options.v().severityLimit>0){ unreachable += printReportForFileBySeverity(sb, fname, 1, " - Unreachable -"); } } diff --git a/src/main/java/bixie/checker/reportprinter/HtmlReportPrinter.java b/src/main/java/bixie/checker/reportprinter/HtmlReportPrinter.java index 769ab71..bb78226 100644 --- a/src/main/java/bixie/checker/reportprinter/HtmlReportPrinter.java +++ b/src/main/java/bixie/checker/reportprinter/HtmlReportPrinter.java @@ -107,7 +107,7 @@ public String printSummary() { bodyText.append("

Nothing found

\n"); } cirtical += count; - if (bixie.Options.v().serverityLimit > 0) { + if (bixie.Options.v().severityLimit > 0) { bodyText.append("
Unreachability warnings
\n"); count = createSnippet(fname, bodyText, jsText, 1); if (count == 0) { diff --git a/src/main/java/bixie/checker/reportprinter/JSONReportPrinter.java b/src/main/java/bixie/checker/reportprinter/JSONReportPrinter.java index b49b4b7..c837c0d 100644 --- a/src/main/java/bixie/checker/reportprinter/JSONReportPrinter.java +++ b/src/main/java/bixie/checker/reportprinter/JSONReportPrinter.java @@ -64,7 +64,7 @@ public String printSummary() { protected void consumeReport(Report r) { for (Entry> entry : r.getReports().entrySet()) { - if (entry.getKey()>bixie.Options.v().serverityLimit) { + if (entry.getKey()>bixie.Options.v().severityLimit) { // suppress warnings above threshold. continue; }