Skip to content

Commit

Permalink
#19 removed bugs.add()
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaneberly committed Sep 1, 2014
1 parent 6984217 commit 206961b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/main/java/com/cflint/CFLint.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.cflint.plugins.core.QueryParamChecker;
import com.cflint.plugins.core.TypedQueryNew;
import com.cflint.plugins.core.VarScoper;
import com.cflint.plugins.exceptions.CFLintExceptionListener;
import com.cflint.plugins.exceptions.DefaultCFLintExceptionListener;
import com.cflint.tools.CFLintFilter;

import net.htmlparser.jericho.Element;
Expand Down Expand Up @@ -56,6 +58,9 @@

public class CFLint implements IErrorReporter {

private static final String FILE_ERROR = "FILE_ERROR";
private static final String PARSE_ERROR = "PARSE_ERROR";

StackHandler handler = new StackHandler();
boolean inFunction = false;
boolean inAssignment = false;
Expand All @@ -77,10 +82,12 @@ public class CFLint implements IErrorReporter {

private String currentFile;
List<ScanProgressListener> scanProgressListeners = new ArrayList<ScanProgressListener>();
List<CFLintExceptionListener> exceptionListeners = new ArrayList<CFLintExceptionListener>();

public CFLint() {
this(new NestedCFOutput(), new TypedQueryNew(), new VarScoper(), new ArgVarChecker(), new ArgDefChecker(),
new OutputParmMissing(), new GlobalVarChecker(), new QueryParamChecker());
addExceptionListener(new DefaultCFLintExceptionListener());
}

public CFLint(final CFLintScanner... bugsScanners) {
Expand Down Expand Up @@ -151,10 +158,17 @@ public void scan(final File folderOrFile) {
try {
process(src, folderOrFile.getAbsolutePath());
} catch (final Exception e) {
e.printStackTrace();
bugs.add(new BugInfo.BugInfoBuilder().setMessageCode("FILE_ERROR")
if (!quiet) {
if (verbose) {
e.printStackTrace(System.err);
}else{
System.err.println(e.getMessage());
}
}
/*bugs.add(new BugInfo.BugInfoBuilder().setMessageCode("FILE_ERROR")
.setFilename(folderOrFile.getAbsolutePath()).setMessage(e.getMessage()).setSeverity("ERROR")
.build());
.build());*/
fireCFLintException(e,FILE_ERROR,folderOrFile.getAbsolutePath(),null,null,null,null);
}
}
}
Expand Down Expand Up @@ -235,9 +249,10 @@ private void process(final Element elem, final String space, final String filena
npe.printStackTrace(System.err);
}
}
bugs.add(new BugInfo.BugInfoBuilder().setLine(elemLine).setColumn(elemColumn + column)
/*bugs.add(new BugInfo.BugInfoBuilder().setLine(elemLine).setColumn(elemColumn + column)
.setMessageCode("PARSE_ERROR").setSeverity("ERROR").setExpression(m.group(1))
.setFilename(filename).setFunction(functionName).setMessage("Unable to parse").build());
.setFilename(filename).setFunction(functionName).setMessage("Unable to parse").build());*/
fireCFLintException(npe,PARSE_ERROR,filename,elemLine,elemColumn + column,functionName,m.group(1));
}
}
} else if (elem.getName().equals("cfargument")) {
Expand Down Expand Up @@ -490,6 +505,17 @@ protected void fireClose() {
}
}

public void addExceptionListener(final CFLintExceptionListener exceptionListener) {
exceptionListeners.add(exceptionListener);
}

protected void fireCFLintException(final Exception e, final String messageCode, final String filename,
final Integer line, final Integer column,final String functionName, final String expression) {
for (final CFLintExceptionListener p : exceptionListeners) {
p.exceptionOccurred(e, messageCode, filename, line, column, functionName, expression);
}
}

public void setShowProgress(final boolean showProgress) {
this.showProgress = showProgress;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/cflint/ant/CFLintTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.cflint.HTMLOutput;
import com.cflint.TextOutput;
import com.cflint.XMLOutput;
import com.cflint.plugins.exceptions.DefaultCFLintExceptionListener;
import com.cflint.tools.CFLintFilter;

public class CFLintTask extends Task {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/cflint/main/CFLintMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.cflint.TextOutput;
import com.cflint.Version;
import com.cflint.XMLOutput;
import com.cflint.plugins.exceptions.DefaultCFLintExceptionListener;
import com.cflint.tools.CFLintFilter;

public class CFLintMain {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.cflint.plugins.exceptions;

public interface CFLintExceptionListener {

public void exceptionOccurred(Exception exception, String messageCode, String filename, Integer line,
Integer column, String functionName, String expression);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.cflint.plugins.exceptions;

import com.cflint.BugInfo;
import com.cflint.BugList;
import com.cflint.BugInfo.BugInfoBuilder;

/**
* Default listener which treats Linter errors (file reading, and parsing) as bugs.
* @author ryaneberly
*
*/
public class DefaultCFLintExceptionListener implements CFLintExceptionListener {

BugList bugs;

public void exceptionOccurred(final Exception exception, final String messageCode, final String filename,
final Integer line, final Integer column, final String functionName, final String expression) {
final BugInfoBuilder bugInfoBuilder = new BugInfo.BugInfoBuilder();
bugInfoBuilder.setMessageCode(messageCode).setFilename(filename)
.setSeverity("ERROR");
if("PARSE_ERROR".equals(messageCode)){
bugInfoBuilder.setMessage("Unable to parse");
}else{
bugInfoBuilder.setMessage(exception.getMessage());
}
bugInfoBuilder.setExpression(expression);
bugInfoBuilder.setFunction(functionName);
bugs.add(bugInfoBuilder.build());
}

}

0 comments on commit 206961b

Please sign in to comment.