Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaneberly committed Jan 7, 2017
1 parent 7b27abd commit e45d61c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 32 deletions.
20 changes: 20 additions & 0 deletions src/main/java/com/cflint/config/CFLintConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.cflint.config.CFLintPluginInfo.PluginInfoRule;
import com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginMessage;
import com.cflint.plugins.CFLintScanner;

@XmlRootElement(name = "config")
public class CFLintConfig {
Expand Down Expand Up @@ -152,4 +154,22 @@ public boolean excludes(PluginMessage pluginMessage) {
return (!getExcludes().isEmpty() && getExcludes().contains(pluginMessage));
}

public PluginInfoRule getRuleByClass(final Class<?> clazz) {
final String className = clazz.getSimpleName();
for (final PluginInfoRule rule : getRules()) {
if (rule.getName().equals(className) || className.equals(rule.getClassName())) {
return rule;
}
}
return null;
}

public PluginInfoRule getRuleForPlugin(final CFLintScanner plugin) {
for (final PluginInfoRule rule : getRules()) {
if (rule.getPluginInstance() == plugin) {
return rule;
}
}
return getRuleByClass(plugin.getClass());
}
}
34 changes: 2 additions & 32 deletions src/main/java/com/cflint/config/ConfigRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.cflint.config.CFLintPluginInfo.PluginInfoRule;
import com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginMessage;
import com.cflint.plugins.CFLintScanner;
import com.cflint.tools.CFTool;

/**
* Combines information from the config.xml and the core CFLint information and
Expand Down Expand Up @@ -44,7 +45,7 @@ public ConfigRuntime(final CFLintConfig config, final CFLintPluginInfo pluginInf
if (config.getIncludes().contains(msg)) {
for (final PluginMessage cfgMsg : config.getIncludes()) {
if (cfgMsg.equals(msg)) {
merge(cfgMsg, msg);
CFTool.merge(cfgMsg, msg);
}
}

Expand All @@ -70,38 +71,7 @@ public ConfigRuntime(final CFLintConfig config, final CFLintPluginInfo pluginInf
}
}

/*
* Apply the configuration to the existing rule. Overlay it.
*/
private void merge(final PluginMessage cfgMsg, final PluginMessage msg) {
if (!isEmpty(cfgMsg.getMessageText())) {
msg.setMessageText(cfgMsg.getMessageText());
}
if (!isEmpty(cfgMsg.getSeverity())) {
msg.setSeverity(cfgMsg.getSeverity());
}
}

private boolean isEmpty(final String messageText) {
return messageText == null || messageText.trim().length() == 0;
}

public PluginInfoRule getRuleByClass(final Class<?> clazz) {
final String className = clazz.getSimpleName();
for (final PluginInfoRule rule : getRules()) {
if (rule.getName().equals(className) || className.equals(rule.getClassName())) {
return rule;
}
}
return null;
}

public PluginInfoRule getRuleForPlugin(final CFLintScanner plugin) {
for (final PluginInfoRule rule : getRules()) {
if (rule.getPluginInstance() == plugin) {
return rule;
}
}
return getRuleByClass(plugin.getClass());
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/cflint/tools/CFTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.Map;
import java.util.Map.Entry;

import com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginMessage;

import cfml.parsing.cfscript.CFExpression;
import net.htmlparser.jericho.Element;

Expand Down Expand Up @@ -40,4 +42,19 @@ public static Map<String, CFExpression> convertMap(Map<? extends CFExpression, C
return retval;
}

/*
* Apply the configuration to the existing rule. Overlay it.
*/
public static void merge(final PluginMessage cfgMsg, final PluginMessage msg) {
if (!isEmpty(cfgMsg.getMessageText())) {
msg.setMessageText(cfgMsg.getMessageText());
}
if (!isEmpty(cfgMsg.getSeverity())) {
msg.setSeverity(cfgMsg.getSeverity());
}
}

private static boolean isEmpty(final String messageText) {
return messageText == null || messageText.trim().length() == 0;
}
}

0 comments on commit e45d61c

Please sign in to comment.