Skip to content

Commit

Permalink
improved the -src option to also accpet source directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Schaef committed Jan 19, 2018
1 parent b71730c commit dbd3c65
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 16 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/bixie/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
33 changes: 29 additions & 4 deletions src/main/java/bixie/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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<String> sourceFiles = null;
public Set<String> getSrcFilesString() {
Expand All @@ -73,15 +76,37 @@ public Set<String> getSrcFilesString() {
sourceFiles = new HashSet<String>();
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<String> findFilesRecursively(File f, String ending) {
List<String> res = new ArrayList<String>();
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public String printSummary() {
bodyText.append("<p>Nothing found</p>\n");
}
cirtical += count;
if (bixie.Options.v().serverityLimit > 0) {
if (bixie.Options.v().severityLimit > 0) {
bodyText.append("<h6>Unreachability warnings</h6>\n");
count = createSnippet(fname, bodyText, jsText, 1);
if (count == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public String printSummary() {

protected void consumeReport(Report r) {
for (Entry<Integer, List<Report.FaultExplanation>> entry : r.getReports().entrySet()) {
if (entry.getKey()>bixie.Options.v().serverityLimit) {
if (entry.getKey()>bixie.Options.v().severityLimit) {
// suppress warnings above threshold.
continue;
}
Expand Down

0 comments on commit dbd3c65

Please sign in to comment.