use of com.cflint.exception.CFLintConfigurationException in project CFLint by cflint.
the class CFLintAPI method createFilter.
protected CFLintFilter createFilter() throws CFLintConfigurationException {
try {
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()];
IOUtils.read(fis, b);
fis.close();
return CFLintFilter.createFilter(new String(b), verbose);
}
}
return CFLintFilter.createFilter(verbose);
} catch (final Exception e) {
throw new CFLintConfigurationException(e);
}
}
use of com.cflint.exception.CFLintConfigurationException in project CFLint by cflint.
the class CFLintAPI method createCFLintInstance.
private CFLint createCFLintInstance() throws CFLintConfigurationException {
try {
final CFLint cflint = new CFLint(configuration);
cflint.setVerbose(verbose);
cflint.setLogError(logError);
cflint.setQuiet(quiet);
cflint.setStrictIncludes(strictInclude);
cflint.setAllowedExtensions(extensions);
cflint.getBugs().setFilter(createFilter());
return cflint;
} catch (final Exception e) {
throw new CFLintConfigurationException(e);
}
}
use of com.cflint.exception.CFLintConfigurationException 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());
}
}
use of com.cflint.exception.CFLintConfigurationException in project CFLint by cflint.
the class ConfigFileLoader method loadConfig.
/**
* Load the configuration from a file, ignore a null configuration filename.
* bubble up any exceptions.
*
* @param configfile the config file
* @return the configuration
* @throws CFLintConfigurationException exception thrown when there is an issue with the configuration
*/
public static CFLintConfig loadConfig(final String configfile) throws CFLintConfigurationException {
if (configfile != null) {
try {
CFLintPluginInfo pluginInfo = null;
if (configfile.toLowerCase().endsWith(".xml")) {
@SuppressWarnings("deprecation") final Object configObj = ConfigUtils.unmarshal(new File(configfile));
if (configObj instanceof CFLintPluginInfo) {
pluginInfo = (CFLintPluginInfo) configObj;
} else if (configObj instanceof CFLintConfig) {
return (CFLintConfig) configObj;
}
} else {
pluginInfo = ConfigUtils.unmarshalJson(new FileInputStream(configfile), CFLintPluginInfo.class);
}
final CFLintConfig returnVal = new CFLintConfig();
returnVal.setRules(pluginInfo.getRules());
return returnVal;
} catch (final Exception e) {
throw new CFLintConfigurationException(e);
}
}
return null;
}
Aggregations