Skip to content

Commit 80a9dc5

Browse files
authored
Merge pull request #406 from fo-code/delta-api-extension
Expanded code delta API
2 parents 8c9f03d + 1222adc commit 80a9dc5

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@
170170
<classSimpleName>Change</classSimpleName>
171171
<justification>This API is not finally in use yet.</justification>
172172
</item>
173+
<item>
174+
<code>java.method.abstractMethodAdded</code>
175+
<classSimpleName>DeltaCalculator</classSimpleName>
176+
<method>calculateDelta</method>
177+
<justification>The new method is required when no commit IDs are accessible.</justification>
178+
</item>
173179
</differences>
174180
</revapi.differences>
175181
</analysisConfiguration>

src/main/java/io/jenkins/plugins/forensics/delta/DeltaCalculator.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import edu.hm.hafner.util.FilteredLog;
77

8+
import hudson.model.Run;
9+
810
import io.jenkins.plugins.forensics.delta.model.Delta;
911

1012
/**
@@ -31,6 +33,21 @@ public abstract class DeltaCalculator implements Serializable {
3133
public abstract Optional<Delta> calculateDelta(String currentCommitId, String referenceCommitId,
3234
FilteredLog logger);
3335

36+
/**
37+
* Calculates the {@link Delta} between two passed Jenkins builds.
38+
*
39+
* @param build
40+
* The currently processed build
41+
* @param referenceBuild
42+
* The reference build
43+
* @param logger
44+
* The used log
45+
*
46+
* @return the delta if it could be calculated
47+
*/
48+
public abstract Optional<Delta> calculateDelta(Run<?, ?> build, Run<?, ?> referenceBuild,
49+
FilteredLog logger);
50+
3451
/**
3552
* A delta calculator that does nothing.
3653
*/
@@ -43,5 +60,11 @@ public Optional<Delta> calculateDelta(final String currentCommitId, final String
4360
final FilteredLog logger) {
4461
return Optional.empty();
4562
}
63+
64+
@Override
65+
public Optional<Delta> calculateDelta(final Run<?, ?> build, final Run<?, ?> referenceBuild,
66+
final FilteredLog logger) {
67+
return Optional.empty();
68+
}
4669
}
4770
}

src/test/java/io/jenkins/plugins/forensics/delta/DeltaCalculatorFactoryITest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public void shouldSelectNullDeltaCalculator() {
5050

5151
assertThat(nullCalculator).isInstanceOf(NullDeltaCalculator.class);
5252
assertThat(nullCalculator.calculateDelta("", "", log)).isEmpty();
53+
assertThat(nullCalculator.calculateDelta(mock(Run.class), mock(Run.class), log)).isEmpty();
5354
assertThat(log.getInfoMessages()).containsOnly(NO_SUITABLE_DELTA_CALCULATOR_FOUND,
5455
ACTUAL_FACTORY_NULL_DELTA_CALCULATOR, EMPTY_FACTORY_NULL_DELTA_CALCULATOR);
5556
assertThat(log.getErrorMessages()).isEmpty();
@@ -104,6 +105,12 @@ public Optional<Delta> calculateDelta(final String currentCommitId, final String
104105
final FilteredLog logger) {
105106
return Optional.empty();
106107
}
108+
109+
@Override
110+
public Optional<Delta> calculateDelta(final Run<?, ?> build, final Run<?, ?> referenceBuild,
111+
final FilteredLog logger) {
112+
return Optional.empty();
113+
}
107114
}
108115

109116
/**

0 commit comments

Comments
 (0)