Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
iamabhishek-dubey committed Nov 26, 2020
2 parents dd18b44 + 92c802e commit e3e0f83
Show file tree
Hide file tree
Showing 32 changed files with 193 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ jobs:
run: mvn -V -ntp clean verify jacoco:prepare-agent test integration-test jacoco:report --file pom.xml '-Dgpg.skip'

- name: Upload coverage to Codecov
uses: codecov/[email protected].14
uses: codecov/[email protected].15
with:
token: ${{secrets.CODECOV_TOKEN}}
2 changes: 1 addition & 1 deletion etc/Jenkinsfile.reference
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ node {
}

stage ('Git mining') {
gitForensics()
discoverGitReferenceBuild()
mineRepository()
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>edu.hm.hafner</groupId>
<artifactId>codingstyle-pom</artifactId>
<version>1.5.1</version>
<version>1.6.0</version>
<relativePath />
</parent>

Expand Down
35 changes: 35 additions & 0 deletions src/main/java/edu/hm/hafner/analysis/IssueParser.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package edu.hm.hafner.analysis;

import java.io.Serializable;
import java.util.Locale;
import java.util.stream.Stream;

import org.apache.commons.lang3.StringUtils;

import edu.umd.cs.findbugs.annotations.CheckForNull;

/**
* Parses a file and returns the issues reported in this file.
*
Expand Down Expand Up @@ -76,5 +81,35 @@ protected boolean isXmlFile(final ReaderFactory readerFactory) {
return false;
}
}

/**
* <p>Compares two CharSequences, returning {@code true} if they represent
* equal sequences of characters, ignoring case.</p>
*
* <p>{@code null}s are handled without exceptions. Two {@code null}
* references are considered equal. The comparison is <strong>case insensitive</strong>.</p>
*
* <pre>
* StringUtils.equalsIgnoreCase(null, null) = true
* StringUtils.equalsIgnoreCase(null, "abc") = false
* StringUtils.equalsIgnoreCase("abc", null) = false
* StringUtils.equalsIgnoreCase("abc", "abc") = true
* StringUtils.equalsIgnoreCase("abc", "ABC") = true
* </pre>
*
* @param a
* the first CharSequence, may be {@code null}
* @param b
* the second CharSequence, may be {@code null}
*
* @return {@code true} if the CharSequences are equal (case-insensitive), or both {@code null}
*/
public static boolean equalsIgnoreCase(@CheckForNull final String a, @CheckForNull final String b) {
return StringUtils.equals(normalize(a), normalize(b));
}

private static String normalize(@CheckForNull final String input) {
return StringUtils.defaultString(input).toUpperCase(Locale.ENGLISH);
}
}

2 changes: 1 addition & 1 deletion src/main/java/edu/hm/hafner/analysis/Severity.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public String toString() {
* @return {@code true} if this instance has the same name, {@code false} otherwise
*/
public boolean equalsIgnoreCase(final String severityName) {
return getName().equalsIgnoreCase(severityName);
return IssueParser.equalsIgnoreCase(getName(), severityName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ else if (StringUtils.isBlank(matcher.group(6))) {
}

private Severity mapSeverity(final String type) {
return "error".equalsIgnoreCase(type) ? Severity.ERROR : Severity.WARNING_NORMAL;
return equalsIgnoreCase(type, "error") ? Severity.ERROR : Severity.WARNING_NORMAL;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected Optional<Issue> createIssue(final Matcher matcher, final IssueBuilder
String type = matcher.group(3);
Severity priority;

if ("error".equalsIgnoreCase(type)) {
if (equalsIgnoreCase(type, "error")) {
priority = Severity.WARNING_HIGH;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.analysis.RegexpLineParser;
import static edu.hm.hafner.util.IntegerParser.parseInt;
import edu.hm.hafner.analysis.Severity;

import static edu.hm.hafner.util.IntegerParser.*;

/**
* A parser for armcc compiler warnings.
Expand All @@ -32,7 +33,7 @@ protected Optional<Issue> createIssue(final Matcher matcher, final IssueBuilder
int errorCode = parseInt(matcher.group(4));
Severity priority;

if ("error".equalsIgnoreCase(type)) {
if (equalsIgnoreCase(type, "error")) {
priority = Severity.WARNING_HIGH;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ private Issue convertToIssue(final JSONObject warning) throws JSONException {
}

private Severity getSeverity(final String confidence) {
if ("Medium".equalsIgnoreCase(confidence)) {
if (equalsIgnoreCase(confidence, "Medium")) {
return Severity.WARNING_NORMAL;
}
else if ("High".equalsIgnoreCase(confidence)) {
else if (equalsIgnoreCase(confidence, "High")) {
return Severity.WARNING_HIGH;
}
else if ("Weak".equalsIgnoreCase(confidence)) {
else if (equalsIgnoreCase(confidence, "Weak")) {
return Severity.WARNING_LOW;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import java.util.Optional;
import java.util.regex.Matcher;

import static edu.hm.hafner.analysis.Categories.guessCategory;
import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.analysis.RegexpLineParser;
import edu.hm.hafner.analysis.Severity;

import static edu.hm.hafner.analysis.Categories.*;

/**
* A parser for Buckminster compiler warnings.
Expand All @@ -28,7 +29,7 @@ public BuckminsterParser() {

@Override
protected Optional<Issue> createIssue(final Matcher matcher, final IssueBuilder builder) {
Severity priority = "Error".equalsIgnoreCase(matcher.group(1)) ? Severity.WARNING_HIGH : Severity.WARNING_NORMAL;
Severity priority = equalsIgnoreCase(matcher.group(1), "Error") ? Severity.WARNING_HIGH : Severity.WARNING_NORMAL;
return builder.setFileName(matcher.group(2)).setLineStart(matcher.group(4))
.setCategory(guessCategory(matcher.group(5))).setMessage(matcher.group(5))
.setSeverity(priority).buildOptional();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ else if (matcher.group(21) != null) {
return Optional.empty(); /* Should never happen! */
}

if ("E".equalsIgnoreCase(type)) {
if (equalsIgnoreCase(type, "E")) {
priority = Severity.WARNING_HIGH;
category = "Error (" + tool + "): " + category;
}
Expand Down
21 changes: 10 additions & 11 deletions src/main/java/edu/hm/hafner/analysis/parser/ClairParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.IOException;
import java.io.Reader;
import java.util.Locale;

import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -79,16 +78,16 @@ private void appendIfNotEmpty(final JSONObject issue, final StringBuilder messag
}

private Severity toSeverity(@CheckForNull final String level) {
switch (String.valueOf(level).toLowerCase(Locale.ENGLISH)) {
case "defcon1":
return Severity.ERROR;
case "critical":
return Severity.WARNING_HIGH;
case "high":
return Severity.WARNING_NORMAL;
default:
return Severity.WARNING_LOW;
if (equalsIgnoreCase(level, "defcon1")) {
return Severity.ERROR;
}
else if (equalsIgnoreCase(level, "critical")) {
return Severity.WARNING_HIGH;
}
else if (equalsIgnoreCase(level, "high")) {
return Severity.WARNING_NORMAL;
}
return Severity.WARNING_LOW;
}

private JSONArray optJsonArrayIgnoreCase(final JSONObject json, final String searchKey) {
Expand All @@ -115,7 +114,7 @@ private Object optIgnoreCase(final JSONObject json, final String searchKey) {
private Object searchIgnoreCase(final JSONObject json, final String searchKey) {
Object result = null;
for (String key : json.keySet()) {
if (key.equalsIgnoreCase(searchKey)) {
if (equalsIgnoreCase(searchKey, key)) {
result = json.opt(key);
if (result != null) {
break;
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/edu/hm/hafner/analysis/parser/DiabCParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.analysis.RegexpLineParser;
import edu.hm.hafner.analysis.Severity;

/**
* A parser for the Diab C++ compiler warnings.
Expand Down Expand Up @@ -37,15 +37,13 @@ protected Optional<Issue> createIssue(final Matcher matcher, final IssueBuilder
}

private Severity mapPriority(final Matcher matcher) {
if ("info".equalsIgnoreCase(matcher.group(3))) {
if (equalsIgnoreCase(matcher.group(3), "info")) {
return Severity.WARNING_LOW;
}
else if ("warning".equalsIgnoreCase(matcher.group(3))) {
else if (equalsIgnoreCase(matcher.group(3), "warning")) {
return Severity.WARNING_NORMAL;
}
else {
return Severity.WARNING_HIGH;
}
return Severity.WARNING_HIGH;
}
}

4 changes: 2 additions & 2 deletions src/main/java/edu/hm/hafner/analysis/parser/ErlcParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.analysis.RegexpLineParser;
import edu.hm.hafner.analysis.Severity;

/**
* A parser for the erlc compiler warnings.
Expand All @@ -32,7 +32,7 @@ protected Optional<Issue> createIssue(final Matcher matcher, final IssueBuilder
String category;
String categoryMatch = matcher.group(3);

if ("warning: ".equalsIgnoreCase(categoryMatch)) {
if (equalsIgnoreCase(categoryMatch, "warning: ")) {
priority = Severity.WARNING_NORMAL;
category = categoryMatch.substring(0, categoryMatch.length() - 2);
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/edu/hm/hafner/analysis/parser/GccParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.analysis.RegexpLineParser;
import edu.hm.hafner.analysis.Severity;

/**
* A parser for the gcc compiler warnings.
Expand Down Expand Up @@ -49,13 +49,13 @@ protected Optional<Issue> createIssue(final Matcher matcher, final IssueBuilder
}

Severity priority;
if ("warning".equalsIgnoreCase(matcher.group(3))) {
if (equalsIgnoreCase(matcher.group(3), "warning")) {
priority = Severity.WARNING_NORMAL;
}
else if ("error".equalsIgnoreCase(matcher.group(3))) {
else if (equalsIgnoreCase(matcher.group(3), "error")) {
priority = Severity.WARNING_HIGH;
}
else if ("note".equalsIgnoreCase(matcher.group(3))) {
else if (equalsIgnoreCase(matcher.group(3), "note")) {
priority = Severity.WARNING_LOW;
}
else if (StringUtils.isNotBlank(matcher.group(4))) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/hm/hafner/analysis/parser/GnatParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ protected Optional<Issue> createIssue(final Matcher matcher, final IssueBuilder
Severity priority;
String category;

if ("warning:".equalsIgnoreCase(matcher.group(4))) {
if (equalsIgnoreCase(matcher.group(4), "warning:")) {
priority = Severity.WARNING_NORMAL;
category = "GNAT warning";
}
else if ("(style)".equalsIgnoreCase(matcher.group(4))) {
else if (equalsIgnoreCase(matcher.group(4), "(style)")) {
priority = Severity.WARNING_LOW;
category = "GNAT style";
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/edu/hm/hafner/analysis/parser/IarParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ protected Optional<Issue> createIssue(final Matcher matcher, final IssueBuilder

private Severity mapPriority(final Matcher matcher) {
Severity priority;
if ("Remark".equalsIgnoreCase(matcher.group(3))) {
if (equalsIgnoreCase(matcher.group(3), "Remark")) {
priority = Severity.WARNING_LOW;
}
else if ("Error".equalsIgnoreCase(matcher.group(3))) {
else if (equalsIgnoreCase(matcher.group(3), "Error")) {
priority = Severity.WARNING_HIGH;
}
else if ("Fatal error".equalsIgnoreCase(matcher.group(3))) {
else if (equalsIgnoreCase(matcher.group(3), "Fatal error")) {
priority = Severity.WARNING_HIGH;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ protected Optional<Issue> createIssue(final Matcher matcher, final IssueBuilder
Severity priority;
String category;

if ("error".equalsIgnoreCase(matcher.group(3))) {
if (equalsIgnoreCase(matcher.group(3), "error")) {
priority = Severity.WARNING_HIGH;
category = "ERROR";
}
else if ("information".equalsIgnoreCase(matcher.group(3))) {
else if (equalsIgnoreCase(matcher.group(3), "information")) {
priority = Severity.WARNING_LOW;
category = "Info";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.analysis.RegexpLineParser;
import edu.hm.hafner.analysis.Severity;

/**
* A parser for Metrowerks Codewarrior 4.x linker warnings.
Expand All @@ -33,11 +33,11 @@ protected Optional<Issue> createIssue(final Matcher matcher, final IssueBuilder

Severity priority;
String category;
if ("error".equalsIgnoreCase(messageCategory)) {
if (equalsIgnoreCase(messageCategory, "error")) {
priority = Severity.WARNING_HIGH;
category = "ERROR";
}
else if ("information".equalsIgnoreCase(messageCategory)) {
else if (equalsIgnoreCase(messageCategory, "information")) {
priority = Severity.WARNING_LOW;
category = "Info";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*
* @author Abhishek Dubey
*/

public class OTDockerLintParser extends IssueParser {
private static final long serialVersionUID = 42L;

Expand Down Expand Up @@ -56,7 +55,7 @@ Issue convertToIssue(final JSONObject jsonIssue) {
builder.setCategory(jsonIssue.getString("code"));
}
if (jsonIssue.has("severity")) {
builder.setSeverity(toSeverity(jsonIssue.getString("severity")));
builder.setSeverity(Severity.guessFromString(jsonIssue.getString("severity")));
}
if (jsonIssue.has("line")) {
builder.setLineStart(jsonIssue.getInt("line_number"));
Expand All @@ -75,19 +74,4 @@ Issue convertToIssue(final JSONObject jsonIssue) {
}
return builder.build();
}

private Severity toSeverity(final String level) {
switch (level) {
case "style":
return Severity.WARNING_LOW;
case "Info":
return Severity.WARNING_NORMAL;
case "Warning":
return Severity.WARNING_HIGH;
case "Error":
return Severity.ERROR;
default:
return Severity.WARNING_LOW;
}
}
}
Loading

0 comments on commit e3e0f83

Please sign in to comment.