Skip to content

Commit

Permalink
Merge pull request #376 from uhafner/cleanup
Browse files Browse the repository at this point in the history
Apply some additional OpenRewrite migrations
  • Loading branch information
uhafner authored Sep 25, 2024
2 parents 10fba30 + 46b00d1 commit b9cc862
Show file tree
Hide file tree
Showing 33 changed files with 268 additions and 192 deletions.
48 changes: 16 additions & 32 deletions src/main/java/edu/hm/hafner/grading/AggregatedScore.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
Expand All @@ -23,6 +24,7 @@
import edu.hm.hafner.grading.CoverageScore.CoverageScoreBuilder;
import edu.hm.hafner.grading.TestScore.TestScoreBuilder;
import edu.hm.hafner.util.FilteredLog;
import edu.hm.hafner.util.Generated;

/**
* Stores the scores of an autograding run. Persists the configuration and the scores for each metric.
Expand Down Expand Up @@ -343,53 +345,35 @@ public List<AnalysisScore> getAnalysisScores() {
return List.copyOf(analysisScores);
}

@Override @SuppressWarnings("PMD.NPathComplexity")
@Override
@Generated
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

AggregatedScore that = (AggregatedScore) o;

if (!Objects.equals(log, that.log)) {
return false;
}
if (!testScores.equals(that.testScores)) {
return false;
}
if (!coverageScores.equals(that.coverageScores)) {
return false;
}
if (!analysisScores.equals(that.analysisScores)) {
return false;
}
if (!Objects.equals(testConfigurations, that.testConfigurations)) {
return false;
}
if (!Objects.equals(coverageConfigurations, that.coverageConfigurations)) {
return false;
}
return Objects.equals(analysisConfigurations, that.analysisConfigurations);
var that = (AggregatedScore) o;
return Objects.equals(log, that.log)
&& Objects.equals(testScores, that.testScores)
&& Objects.equals(coverageScores, that.coverageScores)
&& Objects.equals(analysisScores, that.analysisScores)
&& Objects.equals(testConfigurations, that.testConfigurations)
&& Objects.equals(coverageConfigurations, that.coverageConfigurations)
&& Objects.equals(analysisConfigurations, that.analysisConfigurations);
}

@Override
@Generated
public int hashCode() {
int result = log != null ? log.hashCode() : 0;
result = 31 * result + testScores.hashCode();
result = 31 * result + coverageScores.hashCode();
result = 31 * result + analysisScores.hashCode();
result = 31 * result + (testConfigurations != null ? testConfigurations.hashCode() : 0);
result = 31 * result + (coverageConfigurations != null ? coverageConfigurations.hashCode() : 0);
result = 31 * result + (analysisConfigurations != null ? analysisConfigurations.hashCode() : 0);
return result;
return Objects.hash(log, testScores, coverageScores, analysisScores, testConfigurations, coverageConfigurations,
analysisConfigurations);
}

@Override
public String toString() {
return String.format("Score: %d / %d", getAchievedScore(), getMaxScore());
return String.format(Locale.ENGLISH, "Score: %d / %d", getAchievedScore(), getMaxScore());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import com.fasterxml.jackson.annotation.JsonIgnore;

import edu.hm.hafner.util.Generated;

/**
* Configuration to grade static analysis results. The configuration specifies the impact of the static analysis results
* on the score. This class is intended to be deserialized from JSON, there is no public constructor available.
Expand Down Expand Up @@ -72,6 +74,7 @@ public int getLowImpact() {
}

@Override
@Generated
public boolean equals(final Object o) {
if (this == o) {
return true;
Expand All @@ -82,14 +85,15 @@ public boolean equals(final Object o) {
if (!super.equals(o)) {
return false;
}
AnalysisConfiguration that = (AnalysisConfiguration) o;
var that = (AnalysisConfiguration) o;
return errorImpact == that.errorImpact
&& highImpact == that.highImpact
&& normalImpact == that.normalImpact
&& lowImpact == that.lowImpact;
}

@Override
@Generated
public int hashCode() {
return Objects.hash(super.hashCode(), errorImpact, highImpact, normalImpact, lowImpact);
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/edu/hm/hafner/grading/AnalysisMarkdown.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected String extractSeverities(final AnalysisScore score) {
return "No warnings";
}
else {
return String.format("%d warning%s (%d error%s, %d high, %d normal, %d low)",
return format("%d warning%s (%d error%s, %d high, %d normal, %d low)",
score.getTotalSize(), AnalysisScore.plural(score.getTotalSize()),
score.getErrorSize(), AnalysisScore.plural(score.getErrorSize()),
score.getHighSeveritySize(),
Expand All @@ -114,7 +114,7 @@ protected String createSummary(final AnalysisScore score) {
}

private String getIconAndName(final AnalysisScore analysisScore) {
return " %s &nbsp; %s".formatted(extractParserIcon(analysisScore), analysisScore.getName())
return format(" %s &nbsp; %s", extractParserIcon(analysisScore), analysisScore.getName())
+ createScoreTitle(analysisScore);
}

Expand All @@ -124,8 +124,8 @@ private String extractParserIcon(final AnalysisScore analysisScore) {
return getIcon(analysisScore);
}
else {
return "<img src=\"%s\" alt=\"%s\" height=\"%d\" width=\"%d\">"
.formatted(descriptor.getIconUrl(), analysisScore.getName(), ICON_SIZE, ICON_SIZE);
return format("<img src=\"%s\" alt=\"%s\" height=\"%d\" width=\"%d\">",
descriptor.getIconUrl(), analysisScore.getName(), ICON_SIZE, ICON_SIZE);
}
}
}
5 changes: 2 additions & 3 deletions src/main/java/edu/hm/hafner/grading/AnalysisScore.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected String createSummary() {
return "No warnings";

Check warning on line 122 in src/main/java/edu/hm/hafner/grading/AnalysisScore.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Not covered line

Line 122 is not covered by tests

Check warning on line 122 in src/main/java/edu/hm/hafner/grading/AnalysisScore.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Not covered line

Line 122 is not covered by tests
}
else {
return String.format("%d warning%s (%d error%s, %d high, %d normal, %d low)",
return format("%d warning%s (%d error%s, %d high, %d normal, %d low)",
getTotalSize(), plural(getTotalSize()),
getErrorSize(), plural(getErrorSize()),
getHighSeveritySize(), getNormalSeveritySize(), getLowSeveritySize());
Expand All @@ -144,7 +144,7 @@ public boolean equals(final Object o) {
if (!super.equals(o)) {
return false;
}
AnalysisScore that = (AnalysisScore) o;
var that = (AnalysisScore) o;
return errorSize == that.errorSize
&& highSeveritySize == that.highSeveritySize
&& normalSeveritySize == that.normalSeveritySize
Expand Down Expand Up @@ -273,4 +273,3 @@ public AnalysisScore build() {
}
}
}

2 changes: 1 addition & 1 deletion src/main/java/edu/hm/hafner/grading/AutoGradingRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ protected String createErrorMessageMarkdown(final FilteredLog log) {

@VisibleForTesting
String getConfiguration(final FilteredLog log) {
String configuration = System.getenv("CONFIG");
var configuration = System.getenv("CONFIG");
if (StringUtils.isBlank(configuration)) {
log.logInfo("No configuration provided (environment variable CONFIG not set), using default configuration");

Expand Down
54 changes: 47 additions & 7 deletions src/main/java/edu/hm/hafner/grading/CommentBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;

import com.google.errorprone.annotations.FormatMethod;

import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.registry.ParserRegistry;
import edu.hm.hafner.coverage.FileNode;
Expand Down Expand Up @@ -229,9 +232,9 @@ private String getMissedLinesMessage(final LineRange range) {

private String getMissedLinesDescription(final LineRange range) {
if (range.getStart() == range.getEnd()) {

Check warning on line 234 in src/main/java/edu/hm/hafner/grading/CommentBuilder.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Mutation survived

One mutation survived in line 234 (NegateConditionalsMutator)
Raw output
Survived mutations:
- negated conditional (org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator)
return String.format("Line %d is not covered by tests", range.getStart());
return format("Line %d is not covered by tests", range.getStart());

Check warning on line 235 in src/main/java/edu/hm/hafner/grading/CommentBuilder.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Mutation survived

One mutation survived in line 235 (EmptyObjectReturnValsMutator)
Raw output
Survived mutations:
- replaced return value with "" for edu/hm/hafner/grading/CommentBuilder::getMissedLinesDescription (org.pitest.mutationtest.engine.gregor.mutators.returns.EmptyObjectReturnValsMutator)
}
return String.format("Lines %d-%d are not covered by tests", range.getStart(), range.getEnd());
return format("Lines %d-%d are not covered by tests", range.getStart(), range.getEnd());

Check warning on line 237 in src/main/java/edu/hm/hafner/grading/CommentBuilder.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Mutation survived

One mutation survived in line 237 (EmptyObjectReturnValsMutator)
Raw output
Survived mutations:
- replaced return value with "" for edu/hm/hafner/grading/CommentBuilder::getMissedLinesDescription (org.pitest.mutationtest.engine.gregor.mutators.returns.EmptyObjectReturnValsMutator)
}

private void createAnnotationsForPartiallyCoveredLines(final AggregatedScore score,
Expand All @@ -257,9 +260,9 @@ private void createAnnotationForMissedBranches(final FileNode file,

private String createBranchMessage(final int line, final int missed) {
if (missed == 1) {
return String.format("Line %d is only partially covered, one branch is missing", line);
return format("Line %d is only partially covered, one branch is missing", line);
}
return String.format("Line %d is only partially covered, %d branches are missing", line, missed);
return format("Line %d is only partially covered, %d branches are missing", line, missed);

Check warning on line 265 in src/main/java/edu/hm/hafner/grading/CommentBuilder.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Not covered lines

Lines 248-265 are not covered by tests

Check warning on line 265 in src/main/java/edu/hm/hafner/grading/CommentBuilder.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Not covered lines

Lines 243-265 are not covered by tests
}

private String createRelativeRepositoryPath(final String fileName, final Set<String> sourcePaths) {
Expand Down Expand Up @@ -303,9 +306,9 @@ private void createAnnotationForSurvivedMutation(final FileNode file,

private String createMutationMessage(final int line, final List<Mutation> survived) {
if (survived.size() == 1) {
return String.format("One mutation survived in line %d (%s)", line, formatMutator(survived));
return format("One mutation survived in line %d (%s)", line, formatMutator(survived));
}
return String.format("%d mutations survived in line %d", survived.size(), line);
return format("%d mutations survived in line %d", survived.size(), line);
}

private String formatMutator(final List<Mutation> survived) {
Expand All @@ -314,7 +317,44 @@ private String formatMutator(final List<Mutation> survived) {

private String createMutationDetails(final List<Mutation> mutations) {
return mutations.stream()
.map(mutation -> String.format("- %s (%s)", mutation.getDescription(), mutation.getMutator()))
.map(mutation -> format("- %s (%s)", mutation.getDescription(), mutation.getMutator()))

Check warning on line 320 in src/main/java/edu/hm/hafner/grading/CommentBuilder.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Not covered lines

Lines 299-320 are not covered by tests
.collect(Collectors.joining("\n", "Survived mutations:\n", ""));

Check warning on line 321 in src/main/java/edu/hm/hafner/grading/CommentBuilder.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Not covered lines

Lines 298-321 are not covered by tests
}

/**
* Returns a formatted string using the specified format string and
* arguments. The English locale is always used to format the string.
*
* @param format
* A <a href="../util/Formatter.html#syntax">format string</a>
*
* @param args
* Arguments referenced by the format specifiers in the format
* string. If there are more arguments than format specifiers, the
* extra arguments are ignored. The number of arguments is
* variable and may be zero. The maximum number of arguments is
* limited by the maximum dimension of a Java array as defined by
* <cite>The Java Virtual Machine Specification</cite>.
* The behaviour on a
* {@code null} argument depends on the <a
* href="../util/Formatter.html#syntax">conversion</a>.
*
* @throws java.util.IllegalFormatException
* If a format string contains an illegal syntax, a format
* specifier that is incompatible with the given arguments,
* insufficient arguments given the format string, or other
* illegal conditions. For specification of all possible
* formatting errors, see the <a
* href="../util/Formatter.html#detail">Details</a> section of the
* formatter class specification.
*
* @return A formatted string
*
* @see java.util.Formatter
* @since 1.5
*/
@FormatMethod
protected String format(final String format, final Object... args) {
return String.format(Locale.ENGLISH, format, args);

Check warning on line 358 in src/main/java/edu/hm/hafner/grading/CommentBuilder.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Mutation survived

One mutation survived in line 358 (EmptyObjectReturnValsMutator)
Raw output
Survived mutations:
- replaced return value with "" for edu/hm/hafner/grading/CommentBuilder::format (org.pitest.mutationtest.engine.gregor.mutators.returns.EmptyObjectReturnValsMutator)
}
}
32 changes: 10 additions & 22 deletions src/main/java/edu/hm/hafner/grading/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.JsonNode;

import edu.hm.hafner.util.Generated;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

Expand Down Expand Up @@ -130,39 +131,26 @@ private void validateDefaults() {
// protected abstract void validate();

@Override
@Generated
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

Configuration that = (Configuration) o;

if (maxScore != that.maxScore) {
return false;
}
if (!Objects.equals(id, that.id)) {
return false;
}
if (!Objects.equals(name, that.name)) {
return false;
}
if (!Objects.equals(icon, that.icon)) {
return false;
}
return Objects.equals(tools, that.tools);
var that = (Configuration) o;
return maxScore == that.maxScore
&& Objects.equals(id, that.id)
&& Objects.equals(name, that.name)
&& Objects.equals(icon, that.icon)
&& Objects.equals(tools, that.tools);
}

@Override
@Generated
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (icon != null ? icon.hashCode() : 0);
result = 31 * result + maxScore;
result = 31 * result + (tools != null ? tools.hashCode() : 0);
return result;
return Objects.hash(id, name, icon, maxScore, tools);
}

@Override
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/edu/hm/hafner/grading/CoverageConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import java.io.Serial;
import java.util.List;
import java.util.Objects;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonIgnore;

import edu.hm.hafner.util.Generated;

/**
* Configuration to grade code coverage results. The configuration specifies the impact of the coverage results on the
* score. This class is intended to be deserialized from JSON, there is no public constructor available.
Expand Down Expand Up @@ -80,6 +83,7 @@ public boolean isMutationCoverage() {
}

@Override
@Generated
public boolean equals(final Object o) {
if (this == o) {
return true;
Expand All @@ -90,20 +94,14 @@ public boolean equals(final Object o) {
if (!super.equals(o)) {
return false;
}

CoverageConfiguration that = (CoverageConfiguration) o;

if (coveredPercentageImpact != that.coveredPercentageImpact) {
return false;
}
return missedPercentageImpact == that.missedPercentageImpact;
var that = (CoverageConfiguration) o;
return coveredPercentageImpact == that.coveredPercentageImpact
&& missedPercentageImpact == that.missedPercentageImpact;
}

@Override
@Generated
public int hashCode() {
int result = super.hashCode();
result = 31 * result + coveredPercentageImpact;
result = 31 * result + missedPercentageImpact;
return result;
return Objects.hash(super.hashCode(), coveredPercentageImpact, missedPercentageImpact);
}
}
Loading

0 comments on commit b9cc862

Please sign in to comment.