Skip to content

Commit

Permalink
Added support for Matrix Jobs for the new IssuesRecorder.
Browse files Browse the repository at this point in the history
Uses the new pattern MatrixBridge pattern, see
jenkinsci/analysis-core-plugin#47
  • Loading branch information
uhafner committed May 14, 2018
1 parent 52c9135 commit cb183f0
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 66 deletions.
23 changes: 15 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,21 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${maven-pmd-plugin.version}</version>
<configuration>
<rulesets>
<ruleset>etc/pmd-configuration.xml</ruleset>
</rulesets>
<targetJdk>${java.version}</targetJdk>
<includeTests>true</includeTests>
<minimumTokens>50</minimumTokens>
</configuration>
<executions>
<execution>
<goals>
<goal>cpd</goal>
</goals>
<configuration>
<includeTests>true</includeTests>
<minimumTokens>50</minimumTokens>
<excludes>
<exclude>**/parser/**/*Test.java</exclude>
<exclude>**/parser/*Test.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
Expand Down
104 changes: 69 additions & 35 deletions src/main/java/edu/hm/hafner/analysis/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

/**
* A report contains a set of unique {@link Issue issues}: it contains no duplicate elements, i.e. it models the
* mathematical <i>set</i> abstraction. Furthermore, this report provides a <i>total ordering</i> on its elements. I.e.,
* the issues in this report are ordered by their index: the first added issue is at position 0, the second added issues
* is at position 1, and so on.
* mathematical <i>set</i> abstraction. This report provides a <i>total ordering</i> on its elements. I.e., the issues
* in this report are ordered by their index: the first added issue is at position 0, the second added issues is at
* position 1, and so on.
* <p>
* Additionally, this report provides methods to find and filter issues based on different properties. In order to
* create issues use the provided {@link IssueBuilder builder} class.
Expand Down Expand Up @@ -63,84 +63,113 @@ public Report() {
}

/**
* Creates a new {@link Report} that will be initialized with the specified collection of {@link Issue} instances.
* Creates a new {@link Report} that is an aggregation of the specified {@link Report reports}. The created report
* will contain the issues of all specified reports, in the same order. The properties of the specified reports will
* also be copied.
*
* @param issues
* the initial set of issues
* @param report
* the first report of issues
* @param additionalReports
* the additional reports to append
*
* @see #add(Issue)
* @see #copyIssuesAndProperties(Report, Report)
*/
public Report(final Collection<? extends Issue> issues) {
issues.forEach(this::add);
public Report(final Report report, final Report... additionalReports) {
addAll(report, additionalReports);
}

/**
* Creates a new {@link Report} that will be initialized with the specified stream of {@link Issue} instances.
* Creates a new {@link Report} that is an aggregation of the specified {@link Report reports}. The created report
* will contain the issues of all specified reports, in the same order. The properties of the specified reports will
* also be copied.
*
* @param issues
* @param reports
* the initial set of issues
*
* @see #add(Issue)
* @see #copyIssuesAndProperties(Report, Report)
*/
public Report(final Stream<? extends Issue> issues) {
issues.forEach(this::add);
public Report(final Collection<Report> reports) {
for (Report other : reports) {
copyIssuesAndProperties(other, this);
}
}

private void add(final Issue issue) {
/**
* Appends the specified issue to the end of this report. Duplicates will be skipped (the number of skipped elements
* is available using the method {@link #getDuplicatesSize()}.
*
* @param issue
* the issue to append
*
* @return this
*/
public Report add(final Issue issue) {
if (elements.contains(issue)) {
duplicatesSize++; // elements are marked as duplicate if the fingerprint is different
}
else {
elements.add(issue);
}
return this;
}

/**
* Appends all of the specified elements to the end of this container, preserving the order of the array elements.
* Appends all of the specified issues to the end of this report, preserving the order of the array elements.
* Duplicates will be skipped (the number of skipped elements is available using the method {@link
* #getDuplicatesSize()}.
*
* @param issue
* the issue to append
* the first issue to append
* @param additionalIssues
* the additional issue to append
*
* @return this
* @see #add(Issue)
*/
public void add(final Issue issue, final Issue... additionalIssues) {
public Report addAll(final Issue issue, final Issue... additionalIssues) {
add(issue);
for (Issue additional : additionalIssues) {
add(additional);
}
return this;
}

/**
* Appends all of the elements in the specified collection to the end of this container, in the order that they are
* returned by the specified collection's iterator. Duplicates will be skipped (the number of skipped elements is
* available using the method {@link #getDuplicatesSize()}.
* Appends all of the specified issues to the end of this report, preserving the order of the array elements.
* Duplicates will be skipped (the number of skipped elements is available using the method {@link
* #getDuplicatesSize()}.
*
* @param issues
* the issues to append
*
* @return this
* @see #add(Issue)
*/
public void addAll(final Collection<? extends Issue> issues) {
for (Issue issue : issues) {
add(issue);
public Report addAll(final Collection<? extends Issue> issues) {
for (Issue additional : issues) {
add(additional);
}
return this;
}

/**
* Appends all of the elements in the specified array of issues to the end of this container, in the order that they
* are returned by the specified collection's iterator. Duplicates will be skipped (the number of skipped elements
* is available using the method {@link #getDuplicatesSize()}.
* Appends the specified {@link Report reports} to this report. This report will then contain the issues
* of all specified reports, in the same order. The properties of the specified reports will also be copied.
*
* @param report
* the issues to append
* @param additionalIssues
* the additional issue to append
* the first report of issues
* @param additionalReports
* the additional reports to append
* @return this
*
* @see #copyIssuesAndProperties(Report, Report)
*/
public void addAll(final Report report, final Report... additionalIssues) {
public Report addAll(final Report report, final Report... additionalReports) {
copyIssuesAndProperties(report, this);
for (Report other : additionalIssues) {
for (Report other : additionalReports) {
copyIssuesAndProperties(other, this);
}
return this;
}

/**
Expand Down Expand Up @@ -268,8 +297,7 @@ public int getSize() {

/**
* Returns the number of duplicates. Every issue that has been added to this report, but already is part of this
* report (based on {@link #equals(Object)}) is counted as a duplicate. Duplicates are not stored in this
* report.
* report (based on {@link #equals(Object)}) is counted as a duplicate. Duplicates are not stored in this report.
*
* @return total number of duplicates
*/
Expand Down Expand Up @@ -435,7 +463,13 @@ public Map<String, Report> groupByProperty(final String propertyName) {
.collect(groupingBy(Issue.getPropertyValueGetter(propertyName)));

return issues.entrySet().stream()
.collect(toMap(Entry::getKey, e -> new Report(e.getValue())));
.collect(toMap(
Entry::getKey,
e -> {
Report report = new Report();
report.addAll(e.getValue());
return report;
}));
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/edu/hm/hafner/analysis/IssueFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ private void applyFilterAndCheckResult(final Predicate<? super Issue> criterion,
* @return issues.
*/
private Report getIssues() {
Report report = new Report();
report.add(ISSUE1, ISSUE2, ISSUE3);
return report;
return new Report().addAll(ISSUE1, ISSUE2, ISSUE3);
}
}
35 changes: 15 additions & 20 deletions src/test/java/edu/hm/hafner/analysis/ReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void shouldGroupIssuesByProperty() {
@Test
void shouldProvideNoWritingIterator() {
Report report = new Report();
report.add(HIGH, NORMAL_1, NORMAL_2, LOW_2_A, LOW_2_B, LOW_FILE_3);
report.addAll(HIGH, NORMAL_1, NORMAL_2, LOW_2_A, LOW_2_B, LOW_FILE_3);
Iterator<Issue> iterator = report.iterator();
iterator.next();
assertThatThrownBy(iterator::remove).isInstanceOf(UnsupportedOperationException.class);
Expand All @@ -92,7 +92,7 @@ void shouldProvideNoWritingIterator() {
@Test
void shouldCopyProperties() {
Report expected = new Report();
expected.add(HIGH, NORMAL_1, NORMAL_2, LOW_2_A, LOW_2_B, LOW_FILE_3);
expected.addAll(HIGH, NORMAL_1, NORMAL_2, LOW_2_A, LOW_2_B, LOW_FILE_3);
expected.setOrigin(ID);
expected.logInfo("Hello");
expected.logInfo("World!");
Expand Down Expand Up @@ -122,12 +122,9 @@ void shouldCopyProperties() {
/** Verifies some additional variants of the {@link Report#addAll(Report, Report[])}. */
@Test
void shouldVerifyPathInteriorCoverageOfAddAll() {
Report first = new Report();
first.add(HIGH);
Report second = new Report();
second.add(NORMAL_1, NORMAL_2);
Report third = new Report();
third.add(LOW_2_A, LOW_2_B, LOW_FILE_3);
Report first = new Report().add(HIGH);
Report second = new Report().addAll(NORMAL_1, NORMAL_2);
Report third = new Report().addAll(LOW_2_A, LOW_2_B, LOW_FILE_3);

Report report = new Report();
report.addAll(first);
Expand All @@ -151,12 +148,12 @@ void shouldVerifyOriginAndReferenceOfFirstRemains() {
String otherId = "otherId";
second.setOrigin(otherId);
second.setReference(otherId);
second.add(NORMAL_1, NORMAL_2);
second.addAll(NORMAL_1, NORMAL_2);
Report third = new Report();
String idOfThird = "yetAnotherId";
third.setOrigin(idOfThird);
third.setReference(idOfThird);
third.add(LOW_2_A, LOW_2_B, LOW_FILE_3);
third.addAll(LOW_2_A, LOW_2_B, LOW_FILE_3);

Report report = new Report();
report.addAll(first);
Expand Down Expand Up @@ -241,8 +238,8 @@ void shouldIterateOverAllElementsInCorrectOrder() {
Report report = new Report();

report.add(HIGH);
report.add(NORMAL_1, NORMAL_2);
report.add(LOW_2_A, LOW_2_B, LOW_FILE_3);
report.addAll(NORMAL_1, NORMAL_2);
report.addAll(LOW_2_A, LOW_2_B, LOW_FILE_3);
Iterator<Issue> iterator = report.iterator();
assertThat(iterator.next()).isSameAs(HIGH);
assertThat(iterator.next()).isSameAs(NORMAL_1);
Expand All @@ -254,7 +251,7 @@ void shouldIterateOverAllElementsInCorrectOrder() {

@Test
void shouldSkipAddedElements() {
Report report = new Report(allIssuesAsList());
Report report = new Report().addAll(allIssuesAsList());

Report fromEmpty = new Report();

Expand All @@ -265,8 +262,8 @@ void shouldSkipAddedElements() {
.hasDuplicatesSize(6)
.hasPriorities(1, 2, 3);

Report left = new Report(asList(HIGH, NORMAL_1, NORMAL_2));
Report right = new Report(asList(LOW_2_A, LOW_2_B, LOW_FILE_3));
Report left = new Report().addAll(HIGH, NORMAL_1, NORMAL_2);
Report right = new Report().addAll(LOW_2_A, LOW_2_B, LOW_FILE_3);

Report everything = new Report();
everything.addAll(left, right);
Expand Down Expand Up @@ -528,9 +525,7 @@ void shouldStoreAndRetrieveLogAndErrorMessagesInCorrectOrder() {

@Override
protected Report createSerializable() {
Report report = new Report();
report.add(HIGH, NORMAL_1, NORMAL_2, LOW_2_A, LOW_2_B, LOW_FILE_3);
return report;
return new Report().addAll(HIGH, NORMAL_1, NORMAL_2, LOW_2_A, LOW_2_B, LOW_FILE_3);
}

/**
Expand All @@ -548,11 +543,11 @@ void shouldReadIssueFromOldSerialization() {
@Test
void shouldBeNotEqualsAPropertyChanges() {
Report report = new Report();
report.add(HIGH, NORMAL_1, NORMAL_2, LOW_2_A, LOW_2_B, LOW_FILE_3);
report.addAll(HIGH, NORMAL_1, NORMAL_2, LOW_2_A, LOW_2_B, LOW_FILE_3);

Report other = new Report();
other.addAll(report);
other.add(HIGH, NORMAL_1, NORMAL_2, LOW_2_A, LOW_2_B, LOW_FILE_3);
other.addAll(HIGH, NORMAL_1, NORMAL_2, LOW_2_A, LOW_2_B, LOW_FILE_3);

assertThat(report).isNotEqualTo(other); // there should be duplicates
assertThat(report).hasDuplicatesSize(0);
Expand Down

0 comments on commit cb183f0

Please sign in to comment.