Search in sources :

Example 36 with CFLintAPI

use of com.cflint.api.CFLintAPI in project CFLint by cflint.

the class TestCFBugs_ArgsUse method setUp.

@Before
public void setUp() throws Exception {
    final ConfigBuilder configBuilder = new ConfigBuilder().include("ARG_VAR_CONFLICT", "ARG_VAR_MIXED");
    cfBugs = new CFLintAPI(configBuilder.build());
}
Also used : CFLintAPI(com.cflint.api.CFLintAPI) ConfigBuilder(com.cflint.config.ConfigBuilder) Before(org.junit.Before)

Example 37 with CFLintAPI

use of com.cflint.api.CFLintAPI in project CFLint by cflint.

the class TestCFBugs_ComponentHint method setUp.

@Before
public void setUp() throws Exception {
    final ConfigBuilder configBuilder = new ConfigBuilder().include("COMPONENT_HINT_MISSING");
    cfBugs = new CFLintAPI(configBuilder.build());
}
Also used : CFLintAPI(com.cflint.api.CFLintAPI) ConfigBuilder(com.cflint.config.ConfigBuilder) Before(org.junit.Before)

Example 38 with CFLintAPI

use of com.cflint.api.CFLintAPI in project CFLint by cflint.

the class TestCFBugs_ComponentName method setUp.

@Before
public void setUp() throws Exception {
    final ConfigBuilder configBuilder = new ConfigBuilder().include("USE_DISPLAY_NAME");
    cfBugs = new CFLintAPI(configBuilder.build());
}
Also used : CFLintAPI(com.cflint.api.CFLintAPI) ConfigBuilder(com.cflint.config.ConfigBuilder) Before(org.junit.Before)

Example 39 with CFLintAPI

use of com.cflint.api.CFLintAPI in project CFLint by cflint.

the class TestCFBugs_FunctionHint method setUp.

@Before
public void setUp() throws Exception {
    final ConfigBuilder configBuilder = new ConfigBuilder().include("FUNCTION_HINT_MISSING");
    cfBugs = new CFLintAPI(configBuilder.build());
}
Also used : CFLintAPI(com.cflint.api.CFLintAPI) ConfigBuilder(com.cflint.config.ConfigBuilder) Before(org.junit.Before)

Example 40 with CFLintAPI

use of com.cflint.api.CFLintAPI in project CFLint by cflint.

the class CFLintCLI method execute.

private void execute(final CFLintConfiguration cfLintConfig) throws IOException, TransformerException, MarshallerException, JAXBException, CFLintScanException, CFLintConfigurationException {
    final CFLintAPI api = new CFLintAPI(cfLintConfig);
    api.setVerbose(verbose);
    api.setLogError(logerror);
    api.setQuiet(quiet);
    api.setStrictInclude(strictInclude);
    if (extensions != null && extensions.trim().length() > 0) {
        try {
            api.setExtensions(Arrays.asList(extensions.trim().split(",")));
        } catch (final Exception e) {
            System.err.println("Unable to use extensions (" + extensions + ") using default instead. " + e.getMessage());
        }
    }
    api.setFilterFile(filterFile);
    CFLintResult lintResult = null;
    if (stdIn) {
        final StringWriter source = new StringWriter();
        IOUtils.copy(new InputStreamReader(System.in), source);
        lintResult = api.scan(source.toString(), stdInFile);
    } else {
        lintResult = api.scan(folder);
    }
    if (xmlOutput) {
        try (final Writer xmlwriter = stdOut ? new OutputStreamWriter(System.out) : createXMLWriter(xmlOutFile, StandardCharsets.UTF_8)) {
            if (FINDBUGS.equalsIgnoreCase(xmlstyle)) {
                if (verbose) {
                    display("Writing XML (style: findbugs)" + (stdOut ? "." : " to " + xmlOutFile));
                }
                lintResult.writeFindBugsXml(xmlwriter);
            } else {
                if (verbose) {
                    display("Writing XML" + (stdOut ? "." : " to " + xmlOutFile));
                }
                lintResult.writeXml(xmlwriter);
            }
        }
    }
    if (textOutput) {
        try (final Writer textwriter = stdOut || textOutFile == null ? new OutputStreamWriter(System.out) : new FileWriter(textOutFile)) {
            if (textOutFile != null && verbose) {
                display("Writing text" + (stdOut ? "." : " to " + textOutFile));
            }
            lintResult.writeText(textwriter);
        }
    }
    if (htmlOutput) {
        try (final Writer htmlwriter = stdOut ? new OutputStreamWriter(System.out) : new FileWriter(htmlOutFile)) {
            if (verbose) {
                display("Writing HTML (style: " + htmlStyle + ")" + (stdOut ? "." : " to " + htmlOutFile));
            }
            lintResult.writeHTML(htmlStyle, htmlwriter);
        }
    }
    if (jsonOutput) {
        try (final Writer jsonwriter = stdOut ? new OutputStreamWriter(System.out) : new FileWriter(jsonOutFile)) {
            if (verbose) {
                display("Writing JSON" + (stdOut ? "." : " to " + jsonOutFile));
            }
            lintResult.writeJSON(jsonwriter);
        }
    }
    if (verbose) {
        display("Total files scanned: " + lintResult.getStats().getFileCount());
        display("Total LOC scanned: " + lintResult.getStats().getTotalLines());
    }
}
Also used : CFLintAPI(com.cflint.api.CFLintAPI) StringWriter(java.io.StringWriter) InputStreamReader(java.io.InputStreamReader) FileWriter(java.io.FileWriter) OutputStreamWriter(java.io.OutputStreamWriter) TransformerException(javax.xml.transform.TransformerException) CFLintConfigurationException(com.cflint.exception.CFLintConfigurationException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) CFLintScanException(com.cflint.exception.CFLintScanException) MarshallerException(com.cflint.xml.MarshallerException) CFLintResult(com.cflint.api.CFLintResult) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter) StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Aggregations

CFLintAPI (com.cflint.api.CFLintAPI)55 ConfigBuilder (com.cflint.config.ConfigBuilder)53 Before (org.junit.Before)53 CFLintConfig (com.cflint.config.CFLintConfig)3 CFLintPluginInfo (com.cflint.config.CFLintPluginInfo)3 PluginInfoRule (com.cflint.config.CFLintPluginInfo.PluginInfoRule)3 PluginMessage (com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginMessage)3 CFLintResult (com.cflint.api.CFLintResult)2 StringWriter (java.io.StringWriter)2 CFLintConfiguration (com.cflint.config.CFLintConfiguration)1 CFLintConfigurationException (com.cflint.exception.CFLintConfigurationException)1 CFLintScanException (com.cflint.exception.CFLintScanException)1 MarshallerException (com.cflint.xml.MarshallerException)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1