This repository has been archived by the owner on Apr 6, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-13056][JENKINS-31812] Added option to specify a reference job.
The reference results will now be obtained either a) from the current job b) from a specified reference job (given by the name) The reference job will be selected using the properties: - ignoreAnalysisResult: ignores the result of the previous analysis run - overallResultMustBeSuccess: picks only builds with overall SUCCESS
- Loading branch information
Showing
18 changed files
with
497 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/io/jenkins/plugins/analysis/core/history/OtherJobReferenceFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.jenkins.plugins.analysis.core.history; | ||
|
||
import java.util.Optional; | ||
|
||
import io.jenkins.plugins.analysis.core.views.ResultAction; | ||
|
||
import hudson.model.Result; | ||
import hudson.model.Run; | ||
|
||
import edu.hm.hafner.analysis.Issues; | ||
|
||
/** | ||
* Find the last available analysis run for the specified job. You can specify if the overall result of the run should | ||
* be {@link Result#SUCCESS} and if the sub-result of the static analysis run should be considered as well. | ||
* | ||
* @author Ullrich Hafner | ||
*/ | ||
public class OtherJobReferenceFinder extends ReferenceFinder { | ||
private final boolean ignoreAnalysisResult; | ||
private final boolean overallResultMustBeSuccess; | ||
|
||
/** | ||
* Creates a {@link ReferenceProvider} that obtains the reference results from another job. | ||
* | ||
* @param baseline | ||
* the run to use as baseline when searching for a reference | ||
* @param selector | ||
* selects the type of the result (to get a result for the same type of static analysis) | ||
* @param ignoreAnalysisResult | ||
* if {@code true} then the result of the previous analysis run is ignored when searching for the reference, | ||
* otherwise the result of the static analysis reference must be {@link Result#SUCCESS}. | ||
* @param overallResultMustBeSuccess | ||
* if {@code true} then only runs with an overall result of {@link Result#SUCCESS} are considered as a | ||
* reference, otherwise every run that contains results of the same static analysis configuration is | ||
* considered | ||
*/ | ||
public OtherJobReferenceFinder(final Run<?, ?> baseline, final ResultSelector selector, | ||
final boolean ignoreAnalysisResult, final boolean overallResultMustBeSuccess) { | ||
super(baseline, selector); | ||
|
||
this.ignoreAnalysisResult = ignoreAnalysisResult; | ||
this.overallResultMustBeSuccess = overallResultMustBeSuccess; | ||
} | ||
|
||
@Override | ||
protected Optional<ResultAction> getReferenceAction() { | ||
Optional<ResultAction> baseline = getBaselineAction(); | ||
if (baseline.isPresent()) { | ||
return baseline; | ||
} | ||
return getPreviousAction(ignoreAnalysisResult, overallResultMustBeSuccess); | ||
} | ||
|
||
@Override | ||
public Issues<?> getIssues() { | ||
return getReferenceAction() | ||
.map(resultAction -> resultAction.getResult().getIssues()) | ||
.orElse(new Issues<>()); | ||
} | ||
|
||
@Override | ||
public Optional<Run<?, ?>> getAnalysisRun() { | ||
return getReferenceAction().map(ResultAction::getOwner); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 12 additions & 14 deletions
26
src/main/java/io/jenkins/plugins/analysis/core/history/ReferenceProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,31 @@ | ||
package io.jenkins.plugins.analysis.core.history; | ||
|
||
import edu.hm.hafner.analysis.Issue; | ||
import edu.hm.hafner.analysis.Issues; | ||
import java.util.Optional; | ||
|
||
import hudson.model.Run; | ||
import hudson.plugins.analysis.core.IssueDifference; | ||
|
||
import edu.hm.hafner.analysis.Issues; | ||
|
||
/** | ||
* Provides the reference result for a new static analysis run. When old, new, and fixed issues are computed (see {@link | ||
* IssueDifference}) for a new static analysis run then an instance of this reference is used as a baseline. | ||
* Provides the reference result for a new static analysis run. When outstanding, new, and fixed issues are computed | ||
* (see {@link IssueDifference}) for a new static analysis run then an instance of this reference is used as a | ||
* baseline. | ||
* | ||
* @author Ullrich Hafner | ||
*/ | ||
public interface ReferenceProvider { | ||
/** Indicates that no reference has been found. */ | ||
int NO_REFERENCE_FOUND = -1; | ||
|
||
/** | ||
* Returns the issues of the reference build. | ||
* Returns the issues of the reference run. If there is no reference, then an empty set of issues is returned. | ||
* | ||
* @return the issues of the reference build | ||
* @return the issues of the reference run | ||
*/ | ||
Issues<Issue> getIssues(); | ||
Issues<?> getIssues(); | ||
|
||
/** | ||
* Returns the number of the reference run. | ||
* Returns the actual reference run. | ||
* | ||
* @return the number of the {@link Run} that is used as reference, or {@link #NO_REFERENCE_FOUND} | ||
* if no such run exists. | ||
* @return the {@link Run} that is used as reference | ||
*/ | ||
int getNumber(); | ||
Optional<Run<?, ?>> getAnalysisRun(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.