Skip to content

Commit

Permalink
Fix quality flaw
Browse files Browse the repository at this point in the history
  • Loading branch information
Wohops committed Aug 27, 2015
1 parent fe8f614 commit 172ce06
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public static List<PropertyDefinition> getPropertyDefinitions() {
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.build(),
PropertyDefinition.builder(FindbugsConstants.TIMEOUT_PROPERTY)
.defaultValue(FindbugsConstants.TIMEOUT_DEFAULT_VALUE + "")
.defaultValue(Long.toString(FindbugsConstants.TIMEOUT_DEFAULT_VALUE))
.category(CoreProperties.CATEGORY_JAVA)
.subCategory(subCategory)
.name("Timeout")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,12 @@ private Collection<Plugin> loadFindbugsPlugins(boolean useFbContrib,boolean useF
}
} catch (PluginException e) {
LOG.warn("Failed to load plugin for custom detector: " + path);
LOG.debug("Cause of failure", e);
} catch (DuplicatePluginIdException e) {
// FB Core plugin is always loaded, so we'll get an exception for it always
if (!FINDBUGS_CORE_PLUGIN_ID.equals(e.getPluginId())) {
// log only if it's not the FV Core plugin
LOG.debug("Plugin already loaded: exception ignored: " + e.getMessage());
LOG.debug("Plugin already loaded: exception ignored: " + e.getMessage(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public final class FindbugsRulesDefinition implements RulesDefinition {
public static final String REPOSITORY_KEY = "findbugs";
public static final String REPOSITORY_NAME = "FindBugs";

public FindbugsRulesDefinition() {
}

@Override
public void define(Context context) {
NewRepository repository = context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private FindbugsVersion() {

} catch (IOException e) {
LoggerFactory.getLogger(getClass()).warn("Can not load the Findbugs version from the file " + PROPERTIES_PATH);
LoggerFactory.getLogger(getClass()).debug("Error while loading propoerties", e);
this.version = "";

} finally {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/sonar/plugins/findbugs/xml/Bug.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Bug {
private String pattern;

public Bug() {
// Empty constructor required by XStream converters
}

public Bug(String pattern) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class ClassFilter {
private String name;

public ClassFilter() {
// Empty constructor required by XStream converters
}

public ClassFilter(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class FieldFilter {
private String type;

public FieldFilter() {
// Empty constructor required by XStream converters
}

public FieldFilter(String name) {
Expand Down
95 changes: 46 additions & 49 deletions src/main/java/org/sonar/plugins/findbugs/xml/FindBugsFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,48 +64,15 @@ public void addMatch(Match child) {
}

public Map<String, String> getPatternLevels(FindbugsLevelUtils priorityMapper) {
BugInfoSplitter splitter = new BugInfoSplitter() {
@Override
public String getSeparator() {
return PATTERN_SEPARATOR;
}

@Override
public String getVar(Bug bug) {
return bug.getPattern();
}
};
return processMatches(priorityMapper, splitter);
return processMatches(priorityMapper, new PatternSplitter());
}

public Map<String, String> getCodeLevels(FindbugsLevelUtils priorityMapper) {
BugInfoSplitter splitter = new BugInfoSplitter() {
@Override
public String getSeparator() {
return CODE_SEPARATOR;
}

@Override
public String getVar(Bug bug) {
return bug.getCode();
}
};
return processMatches(priorityMapper, splitter);
return processMatches(priorityMapper, new CodeSplitter());
}

public Map<String, String> getCategoryLevels(FindbugsLevelUtils priorityMapper) {
BugInfoSplitter splitter = new BugInfoSplitter() {
@Override
public String getSeparator() {
return CATEGORY_SEPARATOR;
}

@Override
public String getVar(Bug bug) {
return bug.getCategory();
}
};
return processMatches(priorityMapper, splitter);
return processMatches(priorityMapper, new CategorySplitter());
}

private static String getRuleSeverity(Priority priority, FindbugsLevelUtils priorityMapper) {
Expand Down Expand Up @@ -143,12 +110,6 @@ private static void completeLevels(Map<String, String> result, List<Bug> bugs, P
}
}

private interface BugInfoSplitter {
String getVar(Bug bug);

String getSeparator();
}

private static void mapRuleSeverity(Map<String, String> severityByRule, String severity, String key) {
if (severityByRule.containsKey(key) && severityByRule.get(key) != null) {
severityByRule.put(key, getHighestSeverity(severityByRule.get(key), severity));
Expand All @@ -158,13 +119,7 @@ private static void mapRuleSeverity(Map<String, String> severityByRule, String s
}

private static String getHighestSeverity(String s1, String s2) {
if (s1.equals(s2)) {
return s1;
} else if (Severity.INFO.equals(s1)) {
return s2;
} else if (Severity.MAJOR.equals(s1) && Severity.INFO.equals(s2)) {
return s1;
} else if (Severity.BLOCKER.equals(s1)) {
if (s1.equals(s2) || (Severity.MAJOR.equals(s1) && Severity.INFO.equals(s2)) || Severity.BLOCKER.equals(s1)) {
return s1;
}
return s2;
Expand All @@ -185,4 +140,46 @@ public static XStream createXStream() {
xstream.processAnnotations(OrFilter.class);
return xstream;
}

private interface BugInfoSplitter {
String getVar(Bug bug);

String getSeparator();
}

private static class PatternSplitter implements BugInfoSplitter {
@Override
public String getSeparator() {
return PATTERN_SEPARATOR;
}

@Override
public String getVar(Bug bug) {
return bug.getPattern();
}
}

private static class CodeSplitter implements BugInfoSplitter {
@Override
public String getSeparator() {
return CODE_SEPARATOR;
}

@Override
public String getVar(Bug bug) {
return bug.getCode();
}
}

private static class CategorySplitter implements BugInfoSplitter {
@Override
public String getSeparator() {
return CATEGORY_SEPARATOR;
}

@Override
public String getVar(Bug bug) {
return bug.getCategory();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class LocalFilter {
private String name;

public LocalFilter() {
// Empty constructor required by XStream converters
}

public LocalFilter(String name) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/sonar/plugins/findbugs/xml/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
*/
package org.sonar.plugins.findbugs.xml;

import java.util.List;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;

import java.util.List;

@XStreamAlias("Match")
public class Match {

Expand Down Expand Up @@ -52,6 +52,7 @@ public class Match {
private List<OrFilter> ors;

public Match() {
// Empty constructor required by XStream converters
}

public Match(Bug bug, Priority priority) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class MethodFilter {
private String returns;

public MethodFilter() {
// Empty constructor required by XStream converters
}

public MethodFilter(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class PackageFilter {
private String name;

public PackageFilter() {
// Empty constructor required by XStream converters
}

public PackageFilter(String name) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/sonar/plugins/findbugs/xml/Priority.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Priority {
private String value;

public Priority() {
// Empty constructor required by XStream converters
}

public Priority(String value) {
Expand Down

0 comments on commit 172ce06

Please sign in to comment.