Skip to content

Commit

Permalink
Tweak checks publishing.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Jul 28, 2020
1 parent af01e60 commit ff27c99
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 63 deletions.
8 changes: 7 additions & 1 deletion plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<url>https://github.com/jenkinsci/warnings-ng-plugin</url>

<properties>
<revision>9.0.0</revision>
<revision>8.4.0</revision>
<changelist>-SNAPSHOT</changelist>

<module.name>${project.groupId}.warnings.ng</module.name>
Expand Down Expand Up @@ -608,6 +608,12 @@
<checkDependencies>false</checkDependencies>
<analysisConfiguration>
<revapi.ignore combine.children="append">
<item>
<regex>true</regex>
<code>java.field.serialVersionUIDUnchanged</code>
<classQualifiedName>io.jenkins.plugins.analysis.core.steps.*Step</classQualifiedName>
<justification>Serialization is only used in interprocess communication using the same classes</justification>
</item>
<item>
<regex>true</regex>
<code>java.missing.*</code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ public void setForensicsDisabled(final boolean forensicsDisabled) {
}

/**
* Returns whether publishing checks should be skip.
* Returns whether publishing checks should be skipped.
*
* @return {@code true} if publishing checks should be skipped
* @return {@code true} if publishing checks should be skipped, {@code false} otherwise
*/
public boolean isSkipPublishingChecks() {
return skipPublishingChecks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*/
@SuppressWarnings({"InstanceVariableMayNotBeInitialized", "PMD.ExcessiveImports", "PMD.ExcessivePublicCount", "PMD.DataClass"})
public class PublishIssuesStep extends Step implements Serializable {
private static final long serialVersionUID = 5754928934079561716L;
private static final long serialVersionUID = -1833335402353771148L;

private final List<AnnotatedReport> reports;

Expand Down Expand Up @@ -150,9 +150,9 @@ public boolean getFailOnError() {
}

/**
* Returns whether publishing checks should be skip.
* Returns whether publishing checks should be skipped.
*
* @return {@code true} if publising checks should be skipped
* @return {@code true} if publishing checks should be skipped, {@code false} otherwise
*/
public boolean isSkipPublishingChecks() {
return skipPublishingChecks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
*/
@SuppressWarnings({"PMD.ExcessivePublicCount", "PMD.ExcessiveImports", "PMD.TooManyFields", "PMD.DataClass"})
public class RecordIssuesStep extends Step implements Serializable {
private static final long serialVersionUID = 2L;
private static final long serialVersionUID = 1L;

private List<Tool> analysisTools = new ArrayList<>();

Expand Down Expand Up @@ -763,9 +763,9 @@ public void setForensicsDisabled(final boolean forensicsDisabled) {
}

/**
* Returns whether publishing checks should be skip.
* Returns whether publishing checks should be skipped.
*
* @return {@code true} if publishing checks should be skipped
* @return {@code true} if publishing checks should be skipped, {@code false} otherwise
*/
public boolean isSkipPublishingChecks() {
return skipPublishingChecks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class WarningChecksPublisher {
}

/**
* Publishes checks to platforms. Afterwards, all warnings are available in corresponding platform's UI,
* e.g. GitHub checks.
* Publishes checks to platforms. Afterwards, all warnings are available in corresponding platform's UI, e.g. GitHub
* checks.
*/
void publishChecks() {
ChecksPublisher publisher = ChecksPublisherFactory.fromRun(action.getOwner());
Expand Down Expand Up @@ -74,11 +74,20 @@ ChecksDetails extractChecksDetails() {
private String extractChecksTitle(final IssuesStatistics statistics) {
if (statistics.getTotalSize() == 0) {
return "No issues.";
} else if (statistics.getNewSize() == 0) {
}
else if (statistics.getNewSize() == 0) {
return String.format("No new issues, %d total.", statistics.getTotalSize());
} else if (statistics.getNewSize() == statistics.getTotalSize()) {
}
else if (statistics.getNewSize() == statistics.getTotalSize()) {
if (statistics.getNewSize() == 1) {
return "1 new issue.";
}
return String.format("%d new issues.", statistics.getNewSize());
} else {
}
else {
if (statistics.getNewSize() == 1) {
return String.format("1 new issue, %d total.", statistics.getTotalSize());
}
return String.format("%d new issues, %d total.", statistics.getNewSize(), statistics.getTotalSize());
}
}
Expand Down Expand Up @@ -156,7 +165,8 @@ private void parseHtml(final Element html, final Set<String> contents) {
for (Element child : html.children()) {
if (child.hasAttr("href")) {
contents.add(child.text().trim() + ":" + child.attr("href").trim());
} else {
}
else {
parseHtml(child, contents);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div>
If this option is unchecked, then the plugin automatically publishes the warnings to corresponding SCM platforms.
If this option is unchecked, then the plugin automatically publishes the issues to corresponding SCM hosting platforms.
For example, if you are using this feature for a GitHub organization project, the warnings will be published to
GitHub through the Checks API. If this operation slows down your build or you don't want to publish the warnings to
SCM platforms, you can use this option to deactivate this feature.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div>
If this option is checked, then the plugin automatically publishes the warnings to corresponding SCM platforms.
If this option is unchecked, then the plugin automatically publishes the issues to corresponding SCM hosting platforms.
For example, if you are using this feature for a GitHub organization project, the warnings will be published to
GitHub through the Checks API. If this operation slows down your build or you don't want to publish the warnings to
SCM platforms, you can use this option to deactivate this feature.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div>
If this option is checked, then the plugin automatically publishes the warnings to corresponding SCM platforms.
If this option is unchecked, then the plugin automatically publishes the issues to corresponding SCM hosting platforms.
For example, if you are using this feature for a GitHub organization project, the warnings will be published to
GitHub through the Checks API. If this operation slows down your build or you don't want to publish the warnings to
SCM platforms, you can use this option to deactivate this feature.
Expand Down
15 changes: 0 additions & 15 deletions plugin/src/main/resources/issues/checks-parameters.jelly

This file was deleted.

2 changes: 0 additions & 2 deletions plugin/src/main/resources/issues/checks-parameters.properties

This file was deleted.

4 changes: 4 additions & 0 deletions plugin/src/main/resources/issues/publish-parameters.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

<i:hr title="${%Miscellaneous options}"/>

<f:entry title="${%title.skipPublishingChecks}" description="${%description.skipPublishingChecks}"
field="skipPublishingChecks">
<f:checkbox />
</f:entry>
<f:entry title="${%title.failOnError}" description="${%description.failOnError}" field="failOnError">
<f:checkbox/>
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ qualityGates.description=You can define an arbitrary number of quality gates tha
If a quality gate is not passed then the build can be set to unstable or failed, respectively.
title.trendChartType=Trend chart type
description.trendChartType=Select trend charts and their position.

title.skipPublishingChecks=Skip Publishing Checks
description.skipPublishingChecks=If unchecked, then issues will be published to SCM provider platforms.
1 change: 0 additions & 1 deletion plugin/src/main/resources/issues/recorder.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
</f:entry>
<i:scan-parameters/>
<i:publish-parameters/>
<i:checks-parameters/>
</f:advanced>

</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import hudson.model.FreeStyleProject;
import hudson.model.Run;

import io.jenkins.plugins.analysis.core.testutil.IntegrationTestWithJenkinsPerTest;
import io.jenkins.plugins.analysis.core.testutil.IntegrationTestWithJenkinsPerSuite;
import io.jenkins.plugins.analysis.core.util.QualityGate.QualityGateResult;
import io.jenkins.plugins.analysis.core.util.QualityGate.QualityGateType;
import io.jenkins.plugins.analysis.warnings.PVSStudio;
Expand All @@ -28,7 +28,12 @@

import static io.jenkins.plugins.analysis.core.assertions.Assertions.*;

public class WarningChecksPublisherITest extends IntegrationTestWithJenkinsPerTest {
/**
* Tests the class {@link WarningChecksPublisher}.
*
* @author Kezhi Xiong
*/
public class WarningChecksPublisherITest extends IntegrationTestWithJenkinsPerSuite {
private static final String OLD_CHECKSTYLE_REPORT = "checkstyle.xml";
private static final String NEW_CHECKSTYLE_REPORT = "checkstyle1.xml";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,20 @@ public class IssuesRecorder extends AbstractStep implements PostBuildStep {
private final Control ignoreQualityGate = control("ignoreQualityGate");
private final Control overallResultMustBeSuccessCheckBox = control("overallResultMustBeSuccess");
private final Control referenceJobName = control("referenceJobName");
private final Control aggregatingResultsCheckBox = control("aggregatingResults");
private final Control aggregatingResults = control("aggregatingResults");
private final Control sourceCodeEncoding = control("sourceCodeEncoding");
private final Control sourceDirectory = control("sourceDirectory");
private final Control blameDisabled = control("blameDisabled");
private final Control forensicsDisabled = control("forensicsDisabled");
private final Control ignoreFailedBuilds = control("ignoreFailedBuilds");
private final Control failOnError = control("failOnError");
private final Control skipPublishingChecks = control("skipPublishingChecks");
private final Control reportFilePattern = control("/toolProxies/tool/pattern");
private final Control trendChartType = control("trendChartType");
private final Control healthyThreshold = control("healthy");
private final Control unhealthyThreshold = control("unhealthy");
private final Control healthSeverity = control("minimumSeverity");



/**
* Determines the result of the quality gate.
*/
Expand Down Expand Up @@ -177,7 +176,7 @@ public String getSourceCodeEncoding() {
* enabled for successful or unstable builds only
*/
public boolean getEnabledForFailure() {
return enabledForFailureCheckBox.resolve().isSelected();
return isChecked(enabledForFailureCheckBox);
}

/**
Expand All @@ -188,11 +187,11 @@ public boolean getEnabledForFailure() {
* {@code false} if every tool should get an individual result.
*/
public boolean getAggregatingResults() {
return aggregatingResultsCheckBox.resolve().isSelected();
return isChecked(aggregatingResults);
}

public boolean getIgnoreQualityGate() {
return ignoreQualityGate.resolve().isSelected();
return isChecked(ignoreQualityGate);
}

public String getOverallResultMustBeSuccess() {
Expand Down Expand Up @@ -222,7 +221,7 @@ public String getTrendChartType() {
* @return {@code true} if SCM blaming should be disabled
*/
public boolean getBlameDisabled() {
return blameDisabled.resolve().isSelected();
return isChecked(blameDisabled);
}

/**
Expand All @@ -231,16 +230,23 @@ public boolean getBlameDisabled() {
* @return {@code true} if SCM forensics should be disabled
*/
public boolean getForensicsDisabled() {
return forensicsDisabled.resolve().isSelected();
return isChecked(forensicsDisabled);
}

public boolean getIgnoreFailedBuilds() {
return ignoreFailedBuilds.resolve().isSelected();
return isChecked(ignoreFailedBuilds);
}

public boolean getSkipPublishingChecks() {
return isChecked(skipPublishingChecks);
}

private boolean isChecked(final Control control) {
return control.resolve().isSelected();
}

public boolean getFailOnError() {
return failOnError.resolve().isSelected();
return isChecked(failOnError);
}

public String getHealthThreshold() {
Expand Down Expand Up @@ -275,10 +281,9 @@ public String getQualityGateType() {
* Gets the quality gate result.
*
* @return the quality gate result
*
**/
public QualityGateBuildResult getQualityGateResult() {
if (qualityGateResult.resolve().isSelected()) {
if (isChecked(qualityGateResult)) {
return QualityGateBuildResult.UNSTABLE;
}
else {
Expand Down Expand Up @@ -313,7 +318,7 @@ public void setEnabledForFailure(final boolean isChecked) {
* determines if the checkbox should be checked or not
*/
public void setEnabledForAggregation(final boolean isChecked) {
aggregatingResultsCheckBox.check(isChecked);
aggregatingResults.check(isChecked);
}

/**
Expand Down Expand Up @@ -361,27 +366,32 @@ public void setSourceDirectory(final String sourceDirectory) {
}

/**
* Sets the Aggregate esult checkbox.
* Determines whether the results for each configured static analysis result should be aggregated into a single
* result or if every tool should get an individual result.
*
* @param isChecked
* @param aggregatingResults
* if {@code true} then the results of each static analysis tool should be aggregated into a single result,
* if {@code false} then every tool should get an individual result.
*/
public void setAggregatingResults(final boolean isChecked) {
aggregatingResultsCheckBox.check(isChecked);
public void setAggregatingResults(final boolean aggregatingResults) {
this.aggregatingResults.check(aggregatingResults);
}

/**
* Sets the Disable SCM Blames checkbox.
* Determines whether SCM blaming should be disabled or not.
*
* @param blameDisabled
* {@code true} if SCM blaming should be disabled, {@code false} otherwise
*/
public void setBlameDisabled(final boolean blameDisabled) {
this.blameDisabled.check(blameDisabled);
}

/**
* Sets the Disable SCM Forensics checkbox.
* Determines whether SCM forensics should be disabled or not.
*
* @param forensicsDisabled
* {@code true} if SCM forensics should be disabled, {@code false} otherwise
*/
public void setForensicsDisabled(final boolean forensicsDisabled) {
this.forensicsDisabled.check(forensicsDisabled);
Expand Down Expand Up @@ -410,9 +420,18 @@ public void setFailOnError(final boolean failOnError) {
this.failOnError.check(failOnError);
}

/**
* Determines whether skip publishing of checks.
*
* @param skipPublishingChecks
* if {@code true} then publishing checks should be skipped, {@code false} otherwise
*/
public void setSkipPublishingChecks(final boolean skipPublishingChecks) {
this.skipPublishingChecks.check(skipPublishingChecks);
}

/**
* Sets the report file pattern.
* @param pattern
*/
public void setReportFilePattern(final String pattern) {
reportFilePattern.set(pattern);
Expand Down Expand Up @@ -485,7 +504,8 @@ public void setToolWithPattern(final String toolName, final String pattern) {
* @param result
* determines whether the quality gate sets the build result to Unstable or Failed
*/
public void addQualityGateConfiguration(final int threshold, final QualityGateType type, final QualityGateBuildResult result) {
public void addQualityGateConfiguration(final int threshold, final QualityGateType type,
final QualityGateBuildResult result) {
String path = createPageArea("qualityGates", () -> qualityGatesRepeatable.click());
QualityGatePanel qualityGate = new QualityGatePanel(this, path);
qualityGate.setThreshold(threshold);
Expand Down Expand Up @@ -649,7 +669,8 @@ public void setType(final QualityGateType type) {
}

public void setUnstable(final boolean isUnstable) {
self().findElement(by.xpath(".//input[@type='radio' and contains(@path,'unstable[" + isUnstable + "]')]")).click();
self().findElement(by.xpath(".//input[@type='radio' and contains(@path,'unstable[" + isUnstable + "]')]"))
.click();
}
}

Expand Down
Loading

0 comments on commit ff27c99

Please sign in to comment.