Skip to content

Commit

Permalink
check_name and engine_name in CodeClimate #112
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Oct 4, 2020
1 parent 30c75a3 commit 18f8681
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,35 @@ public class CodeClimate {
private final CodeClimateSeverity severity;
private final String type;
private final List<String> categories;
/** Name of tool. */
/** Rule within the tool. */
private final String check_name;
/** Name of tool. */
private final String engine_name;

public CodeClimate(
final String description,
final String fingerprint,
final CodeClimateLocation location,
final CodeClimateSeverity severity,
final String check_name,
final String engine_name,
final List<CodeClimateCategory> categories) {
this.description = checkNotNull(emptyToNull(description), "description");
this.fingerprint = checkNotNull(emptyToNull(fingerprint), "fingerprint");
this.location = checkNotNull(location, "location");
this.severity = severity;
this.type = "issue";
this.check_name = check_name;
this.engine_name = engine_name;
this.categories = categories.stream().map((it) -> it.getName()).collect(Collectors.toList());
}

public String getCheck_name() {
return check_name;
return this.check_name;
}

public String getEngine_name() {
return this.engine_name;
}

public List<CodeClimateCategory> getCategories() {
Expand All @@ -45,55 +53,58 @@ public List<CodeClimateCategory> getCategories() {
}

public String getType() {
return type;
return this.type;
}

public CodeClimateSeverity getSeverity() {
return severity;
return this.severity;
}

public String getDescription() {
return description;
return this.description;
}

public String getFingerprint() {
return fingerprint;
return this.fingerprint;
}

public CodeClimateLocation getLocation() {
return location;
return this.location;
}

@Override
public String toString() {
return "CodeClimate [description="
+ description
+ this.description
+ ", fingerprint="
+ fingerprint
+ this.fingerprint
+ ", location="
+ location
+ this.location
+ ", severity="
+ severity
+ this.severity
+ ", type="
+ type
+ this.type
+ ", categories="
+ categories
+ this.categories
+ ", check_name="
+ check_name
+ this.check_name
+ ", engine_name="
+ this.engine_name
+ "]";
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (categories == null ? 0 : categories.hashCode());
result = prime * result + (check_name == null ? 0 : check_name.hashCode());
result = prime * result + (description == null ? 0 : description.hashCode());
result = prime * result + (fingerprint == null ? 0 : fingerprint.hashCode());
result = prime * result + (location == null ? 0 : location.hashCode());
result = prime * result + (severity == null ? 0 : severity.hashCode());
result = prime * result + (type == null ? 0 : type.hashCode());
result = prime * result + (this.categories == null ? 0 : this.categories.hashCode());
result = prime * result + (this.check_name == null ? 0 : this.check_name.hashCode());
result = prime * result + (this.engine_name == null ? 0 : this.engine_name.hashCode());
result = prime * result + (this.description == null ? 0 : this.description.hashCode());
result = prime * result + (this.fingerprint == null ? 0 : this.fingerprint.hashCode());
result = prime * result + (this.location == null ? 0 : this.location.hashCode());
result = prime * result + (this.severity == null ? 0 : this.severity.hashCode());
result = prime * result + (this.type == null ? 0 : this.type.hashCode());
return result;
}

Expand All @@ -105,53 +116,60 @@ public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
if (this.getClass() != obj.getClass()) {
return false;
}
final CodeClimate other = (CodeClimate) obj;
if (categories == null) {
if (this.categories == null) {
if (other.categories != null) {
return false;
}
} else if (!categories.equals(other.categories)) {
} else if (!this.categories.equals(other.categories)) {
return false;
}
if (check_name == null) {
if (this.check_name == null) {
if (other.check_name != null) {
return false;
}
} else if (!check_name.equals(other.check_name)) {
} else if (!this.check_name.equals(other.check_name)) {
return false;
}
if (this.engine_name == null) {
if (other.engine_name != null) {
return false;
}
} else if (!this.engine_name.equals(other.engine_name)) {
return false;
}
if (description == null) {
if (this.description == null) {
if (other.description != null) {
return false;
}
} else if (!description.equals(other.description)) {
} else if (!this.description.equals(other.description)) {
return false;
}
if (fingerprint == null) {
if (this.fingerprint == null) {
if (other.fingerprint != null) {
return false;
}
} else if (!fingerprint.equals(other.fingerprint)) {
} else if (!this.fingerprint.equals(other.fingerprint)) {
return false;
}
if (location == null) {
if (this.location == null) {
if (other.location != null) {
return false;
}
} else if (!location.equals(other.location)) {
} else if (!this.location.equals(other.location)) {
return false;
}
if (severity != other.severity) {
if (this.severity != other.severity) {
return false;
}
if (type == null) {
if (this.type == null) {
if (other.type != null) {
return false;
}
} else if (!type.equals(other.type)) {
} else if (!this.type.equals(other.type)) {
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ private static CodeClimate toCodeClimate(final Violation v) {
final CodeClimateLines lines = new CodeClimateLines(v.getStartLine());
final CodeClimateLocation location = new CodeClimateLocation(v.getFile(), lines, null);
final CodeClimateSeverity severity = toSeverity(v.getSeverity());
final String check_name = v.getReporter();
final String check_name = v.getRule() == null ? v.getReporter() : v.getRule();
final String engine_name = v.getReporter();
final List<CodeClimateCategory> categories = new ArrayList<CodeClimateCategory>();
categories.add(CodeClimateCategory.BUGRISK);
return new CodeClimate(description, fingerprint, location, severity, check_name, categories);
return new CodeClimate(
description, fingerprint, location, severity, check_name, engine_name, categories);
}

private static CodeClimateSeverity toSeverity(final SEVERITY severity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static se.bjurr.violations.lib.model.Violation.violationBuilder;

import com.google.gson.GsonBuilder;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
Expand All @@ -17,14 +18,15 @@ public class CodeClimateTransformerTest {
@Test
public void testThatViolationsCanBeTransformed() {
final String description = "asdasd";
final String fingerprint = "bd32817c5f595be914cf1d765fe0c3ac53cb6ec4648fc27e9d2529fbb9fa8af5";
final String fingerprint = "287f089bbb587fbb815c35558f2053564c792d5add0f19cfd38fc6ffea3454fc";
final Integer begin = 123;
final String path = "/whatever/path.c";
final Violation violation =
violationBuilder() //
.setFile(path) //
.setMessage(description) //
.setParser(Parser.CHECKSTYLE) //
.setRule("Cyclomatic complexity") //
.setSeverity(SEVERITY.ERROR) //
.setStartLine(begin) //
.build();
Expand All @@ -34,11 +36,24 @@ public void testThatViolationsCanBeTransformed() {
final CodeClimateLines lines = new CodeClimateLines(begin);
final CodeClimateLocation location = new CodeClimateLocation(path, lines, null);
final CodeClimateSeverity severity = CodeClimateSeverity.critical;
final String check_name = Parser.CHECKSTYLE.name();
final String check_name = "Cyclomatic complexity";
final String engine_name = Parser.CHECKSTYLE.name();
final List<CodeClimateCategory> categories = Arrays.asList(CodeClimateCategory.BUGRISK);
assertThat(transformed) //
.hasSize(1) //
.containsOnly(
new CodeClimate(description, fingerprint, location, severity, check_name, categories));
assertThat(transformed).hasSize(1);
assertThat(this.toJson(transformed.get(0))) //
.isEqualTo(
this.toJson(
new CodeClimate(
description,
fingerprint,
location,
severity,
check_name,
engine_name,
categories)));
}

private String toJson(final Object o) {
return new GsonBuilder().setPrettyPrinting().create().toJson(o);
}
}

0 comments on commit 18f8681

Please sign in to comment.