From f8c26ba34bd68bba8c35d7f1071f4f2e83b4ae36 Mon Sep 17 00:00:00 2001 From: Waschndolos Date: Sun, 21 Apr 2024 16:58:27 +0200 Subject: [PATCH] Removed some codacy issues (#656) * Removed some codacy issues * Update slf4j version --- pom.xml | 2 +- .../plugins/prometheus/DiskUsageCollector.java | 2 +- .../plugins/prometheus/ExecutorCollector.java | 3 --- .../plugins/prometheus/JobCollector.java | 8 +++----- .../collectors/builds/BuildCollectorFactory.java | 4 ---- .../collectors/disk/DiskCollectorFactory.java | 4 ---- .../executors/ExecutorCollectorFactory.java | 4 ---- .../jenkins/JenkinsCollectorFactory.java | 4 ---- .../collectors/jobs/JobCollectorFactory.java | 4 ---- .../builds/BuildLikelyStuckGaugeTest.java | 14 +++++++------- .../collectors/builds/CounterManagerTest.java | 16 ++++++++-------- .../util/JenkinsNodeBuildsSampleBuilderTest.java | 6 +++--- 12 files changed, 23 insertions(+), 48 deletions(-) diff --git a/pom.xml b/pom.xml index 272938727..620137c77 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ 2.387.3 0.16.0 - 2.0.12 + 2.0.13 203.v3f46a_7462b_1a_ 1.10.0 diff --git a/src/main/java/org/jenkinsci/plugins/prometheus/DiskUsageCollector.java b/src/main/java/org/jenkinsci/plugins/prometheus/DiskUsageCollector.java index 8236b391b..d5ce11669 100644 --- a/src/main/java/org/jenkinsci/plugins/prometheus/DiskUsageCollector.java +++ b/src/main/java/org/jenkinsci/plugins/prometheus/DiskUsageCollector.java @@ -37,7 +37,7 @@ public List collect() { } catch (final IOException | RuntimeException e) { LOGGER.warn("Failed to get disk usage data due to an unexpected error.", e); return Collections.emptyList(); - } catch (final java.lang.NoClassDefFoundError e) { + } catch (final NoClassDefFoundError e) { LOGGER.warn("Cannot collect disk usage data because plugin CloudBees Disk Usage Simple is not installed: {}", e.toString()); LOGGER.info("You can remove this warning if you disable Collect Disk Usage in Prometheus Configuration."); return Collections.emptyList(); diff --git a/src/main/java/org/jenkinsci/plugins/prometheus/ExecutorCollector.java b/src/main/java/org/jenkinsci/plugins/prometheus/ExecutorCollector.java index 1ddfbd793..137376fab 100644 --- a/src/main/java/org/jenkinsci/plugins/prometheus/ExecutorCollector.java +++ b/src/main/java/org/jenkinsci/plugins/prometheus/ExecutorCollector.java @@ -19,9 +19,6 @@ public class ExecutorCollector extends Collector { private static final Logger LOGGER = LoggerFactory.getLogger(ExecutorCollector.class); - public ExecutorCollector() { - } - @Override public List collect() { LOGGER.debug("Collecting executor metrics for prometheus"); diff --git a/src/main/java/org/jenkinsci/plugins/prometheus/JobCollector.java b/src/main/java/org/jenkinsci/plugins/prometheus/JobCollector.java index 6e494c600..a35db0b66 100644 --- a/src/main/java/org/jenkinsci/plugins/prometheus/JobCollector.java +++ b/src/main/java/org/jenkinsci/plugins/prometheus/JobCollector.java @@ -25,6 +25,9 @@ public class JobCollector extends Collector { private static final Logger LOGGER = LoggerFactory.getLogger(JobCollector.class); + private final BuildMetrics lastBuildMetrics = new BuildMetrics("last"); + private final BuildMetrics perBuildMetrics = new BuildMetrics(""); + private MetricCollector, ? extends Collector> summary; private MetricCollector, ? extends Collector> jobHealthScoreGauge; private MetricCollector, ? extends Collector> nbBuildsGauge; @@ -65,11 +68,6 @@ public void initCollectors(String[] labelNameArray) { } } - private final BuildMetrics lastBuildMetrics = new BuildMetrics("last"); - private final BuildMetrics perBuildMetrics = new BuildMetrics(""); - - public JobCollector() {} - @Override public List collect() { LOGGER.debug("Collecting metrics for prometheus"); diff --git a/src/main/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildCollectorFactory.java b/src/main/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildCollectorFactory.java index 9888c20f5..692563760 100644 --- a/src/main/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildCollectorFactory.java +++ b/src/main/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildCollectorFactory.java @@ -9,10 +9,6 @@ public class BuildCollectorFactory extends BaseCollectorFactory { - public BuildCollectorFactory() { - super(); - } - public MetricCollector, ? extends Collector> createCollector(CollectorType type, String[] labelNames, String prefix) { switch (type) { case BUILD_DURATION_GAUGE: diff --git a/src/main/java/org/jenkinsci/plugins/prometheus/collectors/disk/DiskCollectorFactory.java b/src/main/java/org/jenkinsci/plugins/prometheus/collectors/disk/DiskCollectorFactory.java index 947b1b366..c26a5c7cd 100644 --- a/src/main/java/org/jenkinsci/plugins/prometheus/collectors/disk/DiskCollectorFactory.java +++ b/src/main/java/org/jenkinsci/plugins/prometheus/collectors/disk/DiskCollectorFactory.java @@ -15,10 +15,6 @@ public class DiskCollectorFactory extends BaseCollectorFactory { - public DiskCollectorFactory() { - super(); - } - public MetricCollector createDiskItemCollector(CollectorType type, String[] labelNames) { if (Objects.requireNonNull(type) == DISK_USAGE_BYTES_GAUGE) { return saveBuildCollector(new DiskUsageBytesGauge(labelNames, namespace, subsystem)); diff --git a/src/main/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorCollectorFactory.java b/src/main/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorCollectorFactory.java index 47e6c871c..80d341ce8 100644 --- a/src/main/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorCollectorFactory.java +++ b/src/main/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorCollectorFactory.java @@ -9,10 +9,6 @@ public class ExecutorCollectorFactory extends BaseCollectorFactory { - public ExecutorCollectorFactory() { - super(); - } - public MetricCollector createCollector(CollectorType type, String[] labelNames, String prefix) { switch (type) { case EXECUTORS_AVAILABLE_GAUGE: diff --git a/src/main/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/JenkinsCollectorFactory.java b/src/main/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/JenkinsCollectorFactory.java index f6af9a2f2..f568130b8 100644 --- a/src/main/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/JenkinsCollectorFactory.java +++ b/src/main/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/JenkinsCollectorFactory.java @@ -13,10 +13,6 @@ */ public class JenkinsCollectorFactory extends BaseCollectorFactory { - public JenkinsCollectorFactory() { - super(); - } - public MetricCollector createCollector(CollectorType type, String[] labelNames) { switch (type) { case JENKINS_UP_GAUGE: diff --git a/src/main/java/org/jenkinsci/plugins/prometheus/collectors/jobs/JobCollectorFactory.java b/src/main/java/org/jenkinsci/plugins/prometheus/collectors/jobs/JobCollectorFactory.java index 276e354a8..966ded5f5 100644 --- a/src/main/java/org/jenkinsci/plugins/prometheus/collectors/jobs/JobCollectorFactory.java +++ b/src/main/java/org/jenkinsci/plugins/prometheus/collectors/jobs/JobCollectorFactory.java @@ -9,10 +9,6 @@ public class JobCollectorFactory extends BaseCollectorFactory { - public JobCollectorFactory() { - super(); - } - public MetricCollector, ? extends Collector> createCollector(CollectorType type, String[] labelNames) { switch (type) { case HEALTH_SCORE_GAUGE: diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildLikelyStuckGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildLikelyStuckGaugeTest.java index 314cab584..fbef6d78c 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildLikelyStuckGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildLikelyStuckGaugeTest.java @@ -31,7 +31,7 @@ public void testNothingCalculatedWhenRunIsNull() { @Test public void testNothingCalculatedWhenJobIsNotBuilding() { - Mockito.when(mock.isBuilding()).thenReturn(false); + when(mock.isBuilding()).thenReturn(false); BuildLikelyStuckGauge sut = new BuildLikelyStuckGauge(getLabelNames(), getNamespace(), getSubSystem(), ""); @@ -46,8 +46,8 @@ public void testNothingCalculatedWhenJobIsNotBuilding() { @Test public void testNothingCalculatedWhenNoExecutorFound() { - Mockito.when(mock.isBuilding()).thenReturn(true); - Mockito.when(mock.getExecutor()).thenReturn(null); + when(mock.isBuilding()).thenReturn(true); + when(mock.getExecutor()).thenReturn(null); BuildLikelyStuckGauge sut = new BuildLikelyStuckGauge(getLabelNames(), getNamespace(), getSubSystem(), ""); @@ -61,10 +61,10 @@ public void testNothingCalculatedWhenNoExecutorFound() { @Test public void testBuildIsLikelyStuck() { - Mockito.when(mock.isBuilding()).thenReturn(true); + when(mock.isBuilding()).thenReturn(true); Executor mockedExecutor = mock(Executor.class); when(mockedExecutor.isLikelyStuck()).thenReturn(true); - Mockito.when(mock.getExecutor()).thenReturn(mockedExecutor); + when(mock.getExecutor()).thenReturn(mockedExecutor); BuildLikelyStuckGauge sut = new BuildLikelyStuckGauge(getLabelNames(), getNamespace(), getSubSystem(), ""); @@ -79,10 +79,10 @@ public void testBuildIsLikelyStuck() { @Test public void testBuildIsNotLikelyStuck() { - Mockito.when(mock.isBuilding()).thenReturn(true); + when(mock.isBuilding()).thenReturn(true); Executor mockedExecutor = mock(Executor.class); when(mockedExecutor.isLikelyStuck()).thenReturn(false); - Mockito.when(mock.getExecutor()).thenReturn(mockedExecutor); + when(mock.getExecutor()).thenReturn(mockedExecutor); BuildLikelyStuckGauge sut = new BuildLikelyStuckGauge(getLabelNames(), getNamespace(), getSubSystem(), ""); diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/CounterManagerTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/CounterManagerTest.java index d1fa20f22..669a07d56 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/CounterManagerTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/CounterManagerTest.java @@ -3,8 +3,8 @@ import org.jenkinsci.plugins.prometheus.collectors.CollectorType; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedRunCollectorTest; import org.jenkinsci.plugins.prometheus.config.PrometheusConfiguration; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; import java.util.Arrays; @@ -12,7 +12,7 @@ import static org.mockito.Mockito.*; public class CounterManagerTest extends MockedRunCollectorTest { - private CounterManager manager; + private final CounterManager manager; public CounterManagerTest() { manager = CounterManager.getManager(); @@ -31,7 +31,7 @@ public void TestEquivalentEntryReturnsCounter() { // Should be a value reference comparison. They should be the exact same // MetricCollector. - Assert.assertEquals(retrievedCounter, retrievedCounter2); + Assertions.assertEquals(retrievedCounter, retrievedCounter2); } } @@ -52,7 +52,7 @@ public void TestNamespaceChangeReturnsNewCounter() { var retrievedCounter2 = manager.getCounter(CollectorType.BUILD_SUCCESSFUL_COUNTER, labels, null); // Should be a value reference comparison. They should not be the same metric since the namespace has changed. - Assert.assertNotEquals(retrievedCounter, retrievedCounter2); + Assertions.assertNotEquals(retrievedCounter, retrievedCounter2); } } @@ -68,7 +68,7 @@ public void TestLabelChangeReturnsNewCounter(){ var retrievedCounter2 = manager.getCounter(CollectorType.BUILD_SUCCESSFUL_COUNTER, label2, null); // Should be a value reference comparison. They should be different since labels differ. - Assert.assertNotEquals(retrievedCounter, retrievedCounter2); + Assertions.assertNotEquals(retrievedCounter, retrievedCounter2); } } @@ -83,7 +83,7 @@ public void TestPrefixChangeReturnsNewCounter(){ var retrievedCounter2 = manager.getCounter(CollectorType.BUILD_SUCCESSFUL_COUNTER, label1, null); // Should be a value reference comparison. They should not be the same since prefix changed - Assert.assertNotEquals(retrievedCounter, retrievedCounter2); + Assertions.assertNotEquals(retrievedCounter, retrievedCounter2); } } @@ -98,7 +98,7 @@ public void TestDifferentCounterReturnsUniqueCounter(){ var retrievedCounter2 = manager.getCounter(CollectorType.BUILD_SUCCESSFUL_COUNTER, label1, null); // Should be a value reference comparison. They should not be the same since the collector type differs. - Assert.assertNotEquals(retrievedCounter, retrievedCounter2); + Assertions.assertNotEquals(retrievedCounter, retrievedCounter2); } } diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/util/JenkinsNodeBuildsSampleBuilderTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/util/JenkinsNodeBuildsSampleBuilderTest.java index e38a830c0..c185d1757 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/util/JenkinsNodeBuildsSampleBuilderTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/util/JenkinsNodeBuildsSampleBuilderTest.java @@ -10,7 +10,7 @@ public class JenkinsNodeBuildsSampleBuilderTest { @Test - public void master_node_count_format() { + public void masterNodeCountFormat() { assertEquals( new Collector.MetricFamilySamples.Sample( "jenkins_node_builds_count", @@ -29,7 +29,7 @@ public void master_node_count_format() { } @Test - public void master_node_histogram_format() { + public void masterNodeHistogramFormat() { assertEquals( new Collector.MetricFamilySamples.Sample( "jenkins_node_builds", @@ -48,7 +48,7 @@ public void master_node_histogram_format() { } @Test - public void named_node_count_format() { + public void namedNodeCountFormat() { assertEquals( new Collector.MetricFamilySamples.Sample( "jenkins_node_builds_count",