use of com.cflint.tools.CFLintFilter in project CFLint by cflint.
the class TestCFBugsFilter method testInclude1.
@Test
public void testInclude1() throws IOException {
BugInfo bugInfo = new BugInfo.BugInfoBuilder().setFunction("testf").setMessageCode("PARSE_ERROR").build();
CFLintFilter filter = CFLintFilter.createFilter("[{\"code\":\"OTH_ERROR\"}]");
assertTrue(filter.include(bugInfo));
}
use of com.cflint.tools.CFLintFilter in project CFLint by cflint.
the class CFLintMain method execute.
private void execute() throws IOException, TransformerException, JAXBException, MarshallerException {
final CFLint cflint = new CFLint(buildConfigChain());
cflint.setVerbose(verbose);
cflint.setLogError(logerror);
cflint.setQuiet(quiet);
cflint.setShowProgress(showprogress);
cflint.setProgressUsesThread(progressUsesThread);
if (extensions != null && extensions.trim().length() > 0) {
try {
cflint.setAllowedExtensions(Arrays.asList(extensions.trim().split(",")));
} catch (final Exception e) {
System.err.println("Unable to use extensions (" + extensions + ") using default instead. " + e.getMessage());
}
}
final CFLintFilter filter = createBaseFilter();
cflint.getBugs().setFilter(filter);
for (final String scanfolder : folder) {
cflint.scan(scanfolder);
}
if (stdIn) {
final StringBuilder source = new StringBuilder();
final Scanner scanner = new Scanner(System.in);
while (scanner.hasNextLine()) {
final String nextLine = scanner.nextLine();
source.append(nextLine);
source.append(System.lineSeparator());
}
scanner.close();
cflint.process(source.toString(), stdInFile);
}
if (xmlOutput) {
final Writer xmlwriter = stdOut ? new OutputStreamWriter(System.out) : createWriter(xmlOutFile, StandardCharsets.UTF_8);
if ("findbugs".equalsIgnoreCase(xmlstyle)) {
if (verbose) {
display("Writing XML findbugs style" + (stdOut ? "." : " to " + xmlOutFile));
}
new XMLOutput().outputFindBugs(cflint.getBugs(), xmlwriter, showStats);
} else {
if (verbose) {
display("Writing XML" + (stdOut ? "." : " to " + xmlOutFile));
}
new DefaultCFlintResultMarshaller().output(cflint.getBugs(), xmlwriter, showStats);
}
}
if (textOutput) {
if (textOutFile != null && verbose) {
display("Writing text" + (stdOut ? "." : " to " + textOutFile));
}
final Writer textwriter = stdOut || textOutFile == null ? new OutputStreamWriter(System.out) : new FileWriter(textOutFile);
new TextOutput().output(cflint.getBugs(), textwriter, showStats);
}
if (htmlOutput) {
try {
if (verbose) {
display("Writing HTML" + (stdOut ? "." : " to " + htmlOutFile));
}
final Writer htmlwriter = stdOut ? new OutputStreamWriter(System.out) : new FileWriter(htmlOutFile);
new HTMLOutput(htmlStyle).output(cflint.getBugs(), htmlwriter, showStats);
} catch (final TransformerException e) {
throw new IOException(e);
}
}
if (jsonOutput) {
if (verbose) {
display("Writing JSON" + (stdOut ? "." : " to " + jsonOutFile));
}
final Writer jsonwriter = stdOut ? new OutputStreamWriter(System.out) : new FileWriter(jsonOutFile);
new JSONOutput().output(cflint.getBugs(), jsonwriter, showStats);
}
}
use of com.cflint.tools.CFLintFilter in project CFLint by cflint.
the class CFLintMain method createBaseFilter.
protected CFLintFilter createBaseFilter() throws IOException, FileNotFoundException {
CFLintFilter filter = CFLintFilter.createFilter(verbose);
if (filterFile != null) {
final File ffile = new File(filterFile);
if (ffile.exists()) {
final FileInputStream fis = new FileInputStream(ffile);
final byte[] b = new byte[fis.available()];
fis.read(b);
fis.close();
filter = CFLintFilter.createFilter(new String(b), verbose);
}
}
return filter;
}
use of com.cflint.tools.CFLintFilter in project CFLint by cflint.
the class TestCFBugsFilter method testIncludeSeverity.
@Test
public void testIncludeSeverity() throws IOException {
BugInfo bugInfo = new BugInfo.BugInfoBuilder().setFunction("testf").setMessageCode("PARSE_ERROR").setSeverity(Levels.INFO).build();
CFLintFilter filter = CFLintFilter.createFilter("[{\"severity\":\"INFO\"}]");
assertFalse(filter.include(bugInfo));
}
use of com.cflint.tools.CFLintFilter in project CFLint by cflint.
the class TestCFBugsFilter method testIncludeCompound2.
@Test
public void testIncludeCompound2() throws IOException {
BugInfo bugInfo = new BugInfo.BugInfoBuilder().setFunction("testf").setMessageCode("PARSE_ERROR").setSeverity(Levels.WARNING).build();
CFLintFilter filter = CFLintFilter.createFilter("[{\"severity\":\"INFO\",\"code\":\"PARSE_ERROR\"}]");
assertTrue(filter.include(bugInfo));
}
Aggregations