From 877a2f758cff938055d759d93890efb21606eef5 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Tue, 27 Feb 2024 10:33:13 +0100 Subject: [PATCH] Fix warnings. --- .../core/model/AggregationAction.java | 1 - .../core/model/FixedWarningsDetail.java | 1 - .../analysis/core/steps/IssuesPublisher.java | 1 + .../util/WarningsQualityGateEvaluator.java | 8 ++++++ .../analysis/warnings/CodeGenerator.java | 3 +-- .../warnings/CrossCoreEmbeddedStudio.java | 1 - .../analysis/warnings/EmbeddedEngineer.java | 1 - .../warnings/OwaspDependencyCheck.java | 1 - .../plugins/analysis/warnings/RfLint.java | 1 - .../analysis/warnings/SimulinkCheck.java | 1 - .../warnings/axivion/AxivionSuite.java | 3 --- .../axivion/RemoteAxivionDashboard.java | 5 ++-- .../groovy/DynamicDocumentParser.java | 3 +-- .../core/model/TabLabelProviderTest.java | 1 - .../AxivionSuiteSerializationTest.java | 1 - .../warnings/axivion/AxivionSuiteTest.java | 5 ++-- .../warnings/groovy/GroovyScriptITest.java | 1 - .../groovy/ParserConfigurationITest.java | 1 - .../groovy/ParserConfigurationTest.java | 2 +- .../warnings/tasks/TaskScannerBenchmark.java | 1 - .../plugins/analysis/warnings/SmokeTests.java | 25 +++++++++---------- .../plugins/analysis/warnings/UiTest.java | 14 +++++------ 22 files changed, 35 insertions(+), 46 deletions(-) diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/AggregationAction.java b/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/AggregationAction.java index 582b8121fb..5d3530b4ac 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/AggregationAction.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/AggregationAction.java @@ -82,5 +82,4 @@ public void onAttached(final Run r) { public void onLoad(final Run r) { owner = r; } - } diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/FixedWarningsDetail.java b/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/FixedWarningsDetail.java index 012cc11e1b..01ffaa516a 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/FixedWarningsDetail.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/FixedWarningsDetail.java @@ -56,7 +56,6 @@ public boolean canDisplayFile(final Issue issue) { Optional> referenceBuild = getResult().getReferenceBuild(); return referenceBuild.filter(run -> ConsoleLogHandler.isInConsoleLog(issue.getFileName()) || AffectedFilesResolver.hasAffectedFile(run, issue)).isPresent(); - } /** diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/core/steps/IssuesPublisher.java b/plugin/src/main/java/io/jenkins/plugins/analysis/core/steps/IssuesPublisher.java index 90173aea21..b89f22d679 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/core/steps/IssuesPublisher.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/core/steps/IssuesPublisher.java @@ -230,6 +230,7 @@ private QualityGateResult evaluateQualityGate(final Report issues, final DeltaRe return Optional.empty(); } + @SuppressWarnings("PMD.CognitiveComplexity") private Optional> refineReferenceBasedOnQualityGate(final ResultSelector selector, final Report issues, final Run reference) { boolean isSkipped = false; diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/core/util/WarningsQualityGateEvaluator.java b/plugin/src/main/java/io/jenkins/plugins/analysis/core/util/WarningsQualityGateEvaluator.java index c7a4f721eb..33c41b40c4 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/core/util/WarningsQualityGateEvaluator.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/core/util/WarningsQualityGateEvaluator.java @@ -14,6 +14,14 @@ public class WarningsQualityGateEvaluator extends QualityGateEvaluator { private final IssuesStatistics statistics; + /** + * Creates a new instance of {@link WarningsQualityGateEvaluator}. + * + * @param qualityGates + * the quality gates to evaluate + * @param statistics + * the statistics to evaluate + */ public WarningsQualityGateEvaluator(final Collection qualityGates, final IssuesStatistics statistics) { super(qualityGates); diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/CodeGenerator.java b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/CodeGenerator.java index 0068b82301..c76f784fec 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/CodeGenerator.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/CodeGenerator.java @@ -31,5 +31,4 @@ public Descriptor() { super(ID); } } - -} \ No newline at end of file +} diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/CrossCoreEmbeddedStudio.java b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/CrossCoreEmbeddedStudio.java index 75c25c895c..c7d8c4396f 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/CrossCoreEmbeddedStudio.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/CrossCoreEmbeddedStudio.java @@ -29,5 +29,4 @@ public Descriptor() { super(ID); } } - } diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/EmbeddedEngineer.java b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/EmbeddedEngineer.java index 062c569456..cf4d48b6e9 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/EmbeddedEngineer.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/EmbeddedEngineer.java @@ -31,5 +31,4 @@ public Descriptor() { super(ID); } } - } diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/OwaspDependencyCheck.java b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/OwaspDependencyCheck.java index ecb6579a94..6473752a45 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/OwaspDependencyCheck.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/OwaspDependencyCheck.java @@ -25,7 +25,6 @@ public OwaspDependencyCheck() { @Symbol("owaspDependencyCheck") @Extension public static class Descriptor extends AnalysisModelParserDescriptor { - /** Create instance. **/ public Descriptor() { super(ID); diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/RfLint.java b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/RfLint.java index 6cef617b1c..dbd4b77371 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/RfLint.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/RfLint.java @@ -38,6 +38,5 @@ public Descriptor() { public StaticAnalysisLabelProvider getLabelProvider() { return new IconLabelProvider(getId(), getDisplayName(), getDescriptionProvider(), ICON_NAME); } - } } diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/SimulinkCheck.java b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/SimulinkCheck.java index 2ddade5dc5..f8e59cad28 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/SimulinkCheck.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/SimulinkCheck.java @@ -31,5 +31,4 @@ public Descriptor() { super(ID); } } - } diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/axivion/AxivionSuite.java b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/axivion/AxivionSuite.java index 7c414ca859..f8e6f748d1 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/axivion/AxivionSuite.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/axivion/AxivionSuite.java @@ -187,7 +187,6 @@ protected Object readResolve() { @Override public Report scan(final Run run, final FilePath workspace, final Charset sourceCodeEncoding, final LogHandler logger) throws ParsingException, ParsingCanceledException { - final UsernamePasswordCredentials httpClientCredentials = withValidCredentials(run.getParent()); final AxivionDashboard dashboard = new RemoteAxivionDashboard(projectUrl, httpClientCredentials, namedFilter); final AxivionParser.Config config = new Config(projectUrl, expandBaseDir(run, basedir), @@ -246,7 +245,6 @@ private static String expandBaseDir(final Run run, final String baseDir) { /** Provides the Axivion icons. */ private static class LabelProvider extends IconLabelProvider { - LabelProvider() { super(ID, "Axivion Suite", EMPTY_DESCRIPTION, "axivion"); } @@ -256,7 +254,6 @@ private static class LabelProvider extends IconLabelProvider { @Symbol({"axivionSuite", "axivion"}) @Extension public static class AxivionSuiteToolDescriptor extends ToolDescriptor { - private static final JenkinsFacade JENKINS = new JenkinsFacade(); /** Creates the descriptor instance. */ diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/axivion/RemoteAxivionDashboard.java b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/axivion/RemoteAxivionDashboard.java index 17b7d3cfc2..b225dbe925 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/axivion/RemoteAxivionDashboard.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/axivion/RemoteAxivionDashboard.java @@ -55,9 +55,8 @@ public JsonObject getIssues(final AxIssueKind kind) { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, credentials); - try (CloseableHttpClient client = - HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build()) { - + try (CloseableHttpClient client + = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build()) { URIBuilder uriBuilder = new URIBuilder(projectUrl + "/issues"); uriBuilder.setParameter("kind", kind.toString()); if (!namedFilter.isEmpty()) { diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/groovy/DynamicDocumentParser.java b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/groovy/DynamicDocumentParser.java index fe4b1d7cfa..9c859da613 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/groovy/DynamicDocumentParser.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/groovy/DynamicDocumentParser.java @@ -19,7 +19,7 @@ class DynamicDocumentParser extends IssueParser { private static final long serialVersionUID = -690643673847390322L; private final Pattern pattern; private static final int NO_LINE_NUMBER_AVAILABLE = 0; - + private final GroovyExpressionMatcher expressionMatcher; /** @@ -35,7 +35,6 @@ class DynamicDocumentParser extends IssueParser { pattern = Pattern.compile(regexp, Pattern.MULTILINE); expressionMatcher = new GroovyExpressionMatcher(script); - } @Override diff --git a/plugin/src/test/java/io/jenkins/plugins/analysis/core/model/TabLabelProviderTest.java b/plugin/src/test/java/io/jenkins/plugins/analysis/core/model/TabLabelProviderTest.java index 0d2d31b743..935668b3ae 100644 --- a/plugin/src/test/java/io/jenkins/plugins/analysis/core/model/TabLabelProviderTest.java +++ b/plugin/src/test/java/io/jenkins/plugins/analysis/core/model/TabLabelProviderTest.java @@ -57,7 +57,6 @@ void shouldReturnPackagesJava() { TabLabelProvider tabLabelProvider = createTabLabelProvider("Testfile.java"); assertThat(tabLabelProvider).hasPackages(Messages.Tab_Packages()); - } @Test diff --git a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/axivion/AxivionSuiteSerializationTest.java b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/axivion/AxivionSuiteSerializationTest.java index 6503c430d9..d210d48b35 100644 --- a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/axivion/AxivionSuiteSerializationTest.java +++ b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/axivion/AxivionSuiteSerializationTest.java @@ -3,7 +3,6 @@ import edu.hm.hafner.util.SerializableTest; class AxivionSuiteSerializationTest extends SerializableTest { - @Override protected AxivionSuite createSerializable() { return restore(readAllBytes("axivion-suite-9.0.1.ser")); diff --git a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/axivion/AxivionSuiteTest.java b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/axivion/AxivionSuiteTest.java index ae352fd8aa..7ddab4b707 100644 --- a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/axivion/AxivionSuiteTest.java +++ b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/axivion/AxivionSuiteTest.java @@ -1,11 +1,10 @@ package io.jenkins.plugins.analysis.warnings.axivion; -import static org.assertj.core.api.Assertions.assertThat; - import org.junit.jupiter.api.Test; -class AxivionSuiteTest { +import static org.assertj.core.api.Assertions.*; +class AxivionSuiteTest { private static AxivionSuite newTool(final String projectUrl) { return new AxivionSuite(projectUrl, "", ""); } diff --git a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/groovy/GroovyScriptITest.java b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/groovy/GroovyScriptITest.java index 23b13f3fa5..550e84adf5 100644 --- a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/groovy/GroovyScriptITest.java +++ b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/groovy/GroovyScriptITest.java @@ -14,7 +14,6 @@ * Tests the class {@link GroovyScript}. */ class GroovyScriptITest extends IntegrationTestWithJenkinsPerSuite { - /** Tests that the descriptor's canScanConsoleLog method returns the same as the configured permission ... for the "true" case */ @Test void descriptorMethodCanScanConsoleLogReturnsTrueIfConfigurationSaysConsoleLogScanningPermittedIsTrue() { diff --git a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/groovy/ParserConfigurationITest.java b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/groovy/ParserConfigurationITest.java index 9969eba69d..8a55aa5a09 100644 --- a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/groovy/ParserConfigurationITest.java +++ b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/groovy/ParserConfigurationITest.java @@ -64,5 +64,4 @@ private StaticAnalysisToolFactory getToolProvider() { private GroovyParser createParser() { return new GroovyParser(ID, NAME, "regexp", "script", "example"); } - } diff --git a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/groovy/ParserConfigurationTest.java b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/groovy/ParserConfigurationTest.java index d3c89100c0..2430e571a9 100644 --- a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/groovy/ParserConfigurationTest.java +++ b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/groovy/ParserConfigurationTest.java @@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test; import hudson.util.FormValidation; + import io.jenkins.plugins.util.GlobalConfigurationFacade; import static io.jenkins.plugins.analysis.core.testutil.Assertions.*; @@ -107,6 +108,5 @@ void deleteShouldRemoveOnlySpecifiedParser() { configuration.deleteParser(firstTestParser.getId()); assertThat(configuration.getParsers()).containsExactly(secondTestParser); - } } diff --git a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/tasks/TaskScannerBenchmark.java b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/tasks/TaskScannerBenchmark.java index 69c1a08764..eed3f1b327 100644 --- a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/tasks/TaskScannerBenchmark.java +++ b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/tasks/TaskScannerBenchmark.java @@ -84,7 +84,6 @@ public void doSetup() { .setCaseMode(CaseMode.CASE_SENSITIVE) .setMatcherMode(MatcherMode.STRING_MATCH) .build(); - } public TaskScanner getScanner() { diff --git a/ui-tests/src/test/java/io/jenkins/plugins/analysis/warnings/SmokeTests.java b/ui-tests/src/test/java/io/jenkins/plugins/analysis/warnings/SmokeTests.java index f3ead3427c..195fde03ea 100644 --- a/ui-tests/src/test/java/io/jenkins/plugins/analysis/warnings/SmokeTests.java +++ b/ui-tests/src/test/java/io/jenkins/plugins/analysis/warnings/SmokeTests.java @@ -1,7 +1,6 @@ package io.jenkins.plugins.analysis.warnings; import java.util.List; -import java.util.Map; import org.junit.Test; import org.openqa.selenium.By; @@ -14,7 +13,6 @@ import org.jenkinsci.test.acceptance.po.WorkflowJob; import io.jenkins.plugins.analysis.warnings.AnalysisResult.Tab; -import io.jenkins.plugins.analysis.warnings.DashboardTable.DashboardTableEntry; import static io.jenkins.plugins.analysis.warnings.Assertions.*; import static io.jenkins.plugins.analysis.warnings.IssuesColumnConfiguration.*; @@ -134,17 +132,18 @@ private void verifyColumnCount(final Build build) { assertThat(column).hasTotalCount("33"); } - private void verifyDashboardTablePortlet(final DashboardTable dashboardTable, final String jobName) { - assertThat(dashboardTable.getHeaders()).containsExactly( - "Job", CHECKSTYLE_ICON, DRY_ICON, FINDBUGS_ICON, ANALYSIS_ICON, PMD_ICON); - - Map> table = dashboardTable.getTable(); - assertThat(table.get(jobName).get(FINDBUGS_ICON)).hasWarningsCount(0); - assertThat(table.get(jobName).get(CHECKSTYLE_ICON)).hasWarningsCount(3); - assertThat(table.get(jobName).get(ANALYSIS_ICON)).hasWarningsCount(8); - assertThat(table.get(jobName).get(PMD_ICON)).hasWarningsCount(2); - assertThat(table.get(jobName).get(DRY_ICON)).hasWarningsCount(20); - } +// FIXME: re-enable dashboard view tests +// private void verifyDashboardTablePortlet(final DashboardTable dashboardTable, final String jobName) { +// assertThat(dashboardTable.getHeaders()).containsExactly( +// "Job", CHECKSTYLE_ICON, DRY_ICON, FINDBUGS_ICON, ANALYSIS_ICON, PMD_ICON); +// +// Map> table = dashboardTable.getTable(); +// assertThat(table.get(jobName).get(FINDBUGS_ICON)).hasWarningsCount(0); +// assertThat(table.get(jobName).get(CHECKSTYLE_ICON)).hasWarningsCount(3); +// assertThat(table.get(jobName).get(ANALYSIS_ICON)).hasWarningsCount(8); +// assertThat(table.get(jobName).get(PMD_ICON)).hasWarningsCount(2); +// assertThat(table.get(jobName).get(DRY_ICON)).hasWarningsCount(20); +// } private void createRecordIssuesStep(final WorkflowJob job, final int buildNumber) { job.script.set("node {\n" diff --git a/ui-tests/src/test/java/io/jenkins/plugins/analysis/warnings/UiTest.java b/ui-tests/src/test/java/io/jenkins/plugins/analysis/warnings/UiTest.java index c710af625b..4df757ab99 100644 --- a/ui-tests/src/test/java/io/jenkins/plugins/analysis/warnings/UiTest.java +++ b/ui-tests/src/test/java/io/jenkins/plugins/analysis/warnings/UiTest.java @@ -92,14 +92,14 @@ protected String readFileToString(final String fileName) { } /** - * Reads all the bytes from a file. The method ensures that the file is - * closed when all bytes have been read or an I/O error, or other runtime - * exception, is thrown. + * Reads all the bytes from a file. The method ensures that the file is closed when all bytes have been read or an + * I/O error, or other runtime exception, is thrown. + * + *

+ * Note that this method is intended for simple cases where it is convenient to read all bytes into a byte array. It + * is not intended for reading in large files. + *

* - *

Note that this method is intended for simple cases where it is - * convenient to read all bytes into a byte array. It is not intended for - * reading in large files. - ** * @param fileName * name of the desired resource *