Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaneberly committed Jan 17, 2017
1 parent c3427f1 commit 0e81b55
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
37 changes: 20 additions & 17 deletions src/main/java/com/cflint/CFLint.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.antlr.v4.runtime.dfa.DFA;

import com.cflint.BugInfo.BugInfoBuilder;
import com.cflint.config.CFLintChainedConfig;
import com.cflint.config.CFLintConfig;
import com.cflint.config.CFLintConfiguration;
import com.cflint.config.CFLintPluginInfo;
Expand Down Expand Up @@ -163,23 +164,25 @@ public void scan(final File folderOrFile) {
return;
}
if (folderOrFile.isDirectory()) {
boolean newConfigFlag = false;
for (final File file : folderOrFile.listFiles()) {
if(file.getName().equalsIgnoreCase(".cflintrc.xml")){
try {
CFLintConfiguration newConfig = com.cflint.config.ConfigUtils.unmarshal(new FileInputStream(file), CFLintConfig.class);
System.out.println("read config " + file);
newConfigFlag =true;
} catch (Exception e) {
System.err.println("Could not read config file " + file);
}
final CFLintConfiguration saveConfig = configuration;
try{
for (final File file : folderOrFile.listFiles()) {
if(file.getName().equalsIgnoreCase(".cflintrc.xml")){
try {
CFLintConfiguration newConfig = com.cflint.config.ConfigUtils.unmarshal(new FileInputStream(file), CFLintConfig.class);
System.out.println("read config " + file);
configuration = new CFLintChainedConfig(newConfig, configuration);
} catch (Exception e) {
System.err.println("Could not read config file " + file);
}
}
}
for (final File file : folderOrFile.listFiles()) {
scan(file);
}
}
for (final File file : folderOrFile.listFiles()) {
scan(file);
}
if(newConfigFlag){
//TODO unwrap
finally{
configuration = saveConfig;
}
} else if (!folderOrFile.isHidden() && FileUtil.checkExtension(folderOrFile, allowedExtensions)) {
final String src = FileUtil.loadFile(folderOrFile);
Expand Down Expand Up @@ -819,8 +822,8 @@ protected void reportRule(final Element elem, final Object expression, final Con
bldr.setSeverity(msgInfo.getSeverity());
bldr.setMessage(msgInfo.getMessageText());
} else {
String errMessage = "Message code: " + msgcode + " is not configured correctly.";
fireCFLintException(new NullPointerException(errMessage), PLUGIN_ERROR, "", null, null, null, null);
String errMessage = "Message code: " + msgcode + " is not configured correctly.";
fireCFLintException(new NullPointerException(errMessage), PLUGIN_ERROR, "", null, null, null, null);
bldr.setSeverity("WARNING");
bldr.setMessage(msgcode);
}
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/cflint/config/CFLintChainedConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
public class CFLintChainedConfig implements CFLintConfiguration{

final CFLintConfig config;
final CFLintChainedConfig parent;
final CFLintConfiguration parent;

public CFLintChainedConfig(CFLintConfiguration config) {
super();
this.config = (CFLintConfig)config;
parent = null;
}
public CFLintChainedConfig(CFLintConfiguration config,CFLintChainedConfig parent) {
public CFLintChainedConfig(CFLintConfiguration config,CFLintConfiguration parent) {
super();
this.config = (CFLintConfig)config;
this.parent = parent;
Expand All @@ -41,7 +41,7 @@ public boolean excludes(PluginMessage pluginMessage) {
(config.isInheritParent() && parent!=null && parent.excludes(pluginMessage));
}

public CFLintChainedConfig getParent() {
public CFLintConfiguration getParent() {
return parent;
}

Expand Down Expand Up @@ -88,7 +88,12 @@ public Collection<PluginInfoRule> getAllRules() {
if(parent==null || !config.isInheritPlugins()){
return config.getRules();
}
final HashSet<PluginInfoRule> retval = new HashSet<PluginInfoRule>(parent.getAllRules());
final HashSet<PluginInfoRule> retval = new HashSet<PluginInfoRule>();
if(parent instanceof CFLintChainedConfig){
retval.addAll(((CFLintChainedConfig) parent).getAllRules());
}else{
retval.addAll(parent.getRules());
}
//Override any rules from the parent configuration
retval.addAll(config.getRules());
return retval;
Expand Down

0 comments on commit 0e81b55

Please sign in to comment.