Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checkstyle and spotbugs #3

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions .checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version="1.0"?>
<!--
~ Copyright Skodjob Authors.
~
~ Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
-->
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">

<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<module name="FileTabCharacter"/>

<module name="LineLength">
<property name="max" value="140"/>
</module>

<module name="Header">
<property name="header"
value="/*\n * Copyright Skodjob authors.\n * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).\n */"/>
<property name="fileExtensions" value="java"/>
</module>

<module name="TreeWalker">
<!-- Checks for Javadoc comments. -->
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
<module name="MissingJavadocMethodCheck">
<property name="scope" value="public"/>
<property name="allowMissingPropertyJavadoc" value="true"/>
<property name="severity" value="warning" />
</module>
<module name="JavadocType">
<property name="scope" value="public"/>
<property name="severity" value="warning" />
</module>
<module name="JavadocStyle">
<property name="scope" value="public"/>
<property name="checkFirstSentence" value="false"/>
<property name="severity" value="warning" />
</module>

<module name="Indentation">
<property name="basicOffset" value="4"/>
<property name="braceAdjustment" value="0"/>
<property name="caseIndent" value="4"/>
<property name="lineWrappingIndentation" value="4"/>
<property name="tabWidth" value="4"/>
</module>

<!-- Checks for Naming Conventions. -->
<!-- See http://checkstyle.sf.net/config_naming.html -->
<module name="ConstantName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>

<!-- Checks for imports -->
<!-- See http://checkstyle.sf.net/config_import.html -->
<module name="AvoidStarImport">
<property name="severity" value="warning" />
</module>
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
<module name="RedundantImport"/>
<module name="UnusedImports"/>

<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sf.net/config_sizes.html -->

<module name="ParameterNumber"/>

<!-- Modifier Checks -->
<!-- See http://checkstyle.sf.net/config_modifier.html -->
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>

<!-- Checks for blocks. You know, those {}'s -->
<!-- See http://checkstyle.sf.net/config_blocks.html -->
<module name="AvoidNestedBlocks"/>
<module name="LeftCurly">
<property name="option" value="eol"/>
</module>
<module name="NeedBraces">
<property name="allowSingleLineStatement" value="true"/>
</module>
<module name="RightCurly"/>

<!-- Checks for common coding problems -->
<!-- See http://checkstyle.sf.net/config_coding.html -->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="MissingSwitchDefault"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>

<!-- Miscellaneous other checks. -->
<!-- See http://checkstyle.sf.net/config_misc.html -->
<module name="ArrayTypeStyle"/>

</module>
</module>
10 changes: 10 additions & 0 deletions .checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">

<suppressions>
<!-- Note that [/\\] must be used as the path separator for cross-platform support -->
<suppress checks="Javadoc" files="."/>
</suppressions>
3 changes: 3 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -31,3 +31,6 @@ jobs:

- name: Build
run: ./mvnw --batch-mode install -DskipITs=true

- name: Run spotbugs check
run: ./mvnw spotbugs:check
6 changes: 6 additions & 0 deletions .spotbugs/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
<Class name="~io\.skodjob\.datagenerator\.models\..+(\$.*)?" />
</Match>
</FindBugsFilter>
108 changes: 107 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -27,11 +27,18 @@
<test-frame.version>0.2.1</test-frame.version>
<fabric8.version>6.13.1</fabric8.version>
<log4j.version>2.23.1</log4j.version>
<slf4j.version>2.0.13</slf4j.version>

<junit.jupiter.version>5.10.3</junit.jupiter.version>
<junit.platform.version>1.10.3</junit.platform.version>
<maven.surefire.version>3.3.0</maven.surefire.version>
<maven.compile.plugin.version>3.13.0</maven.compile.plugin.version>
<maven.dependency.version>3.3.0</maven.dependency.version>

<!-- Build tools' properties -->
<spotbugs.version>4.8.6</spotbugs.version>
<maven.spotbugs.version>4.8.6.2</maven.spotbugs.version>
<maven.checkstyle.version>3.4.0</maven.checkstyle.version>
</properties>

<dependencies>
@@ -44,11 +51,13 @@
<groupId>io.skodjob</groupId>
<artifactId>test-frame-kubernetes</artifactId>
<version>${test-frame.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.skodjob</groupId>
<artifactId>test-frame-openshift</artifactId>
<version>${test-frame.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.skodjob</groupId>
@@ -70,6 +79,17 @@
<artifactId>kubernetes-model</artifactId>
<version>${fabric8.version}</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-core</artifactId>
<version>${fabric8.version}</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client-api</artifactId>
<version>${fabric8.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
@@ -107,11 +127,23 @@
<version>${maven.surefire.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>${log4j.version}</version>
</dependency>

<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
<version>${spotbugs.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
@@ -155,7 +187,81 @@
</properties>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven.dependency.version}</version>
<executions>
<execution>
<id>analyze</id>
<goals>
<goal>analyze-only</goal>
</goals>
<configuration>
<failOnWarning>true</failOnWarning>
<ignoredUnusedDeclaredDependencies>
<!-- Needed for logging in tests used by test-frame (uses SLF4J) -->
<ignoredUnusedDeclaredDependency>org.apache.logging.log4j:log4j-slf4j2-impl</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>io.fabric8:kubernetes-server-mock</ignoredUnusedDeclaredDependency>
<!-- Temporary exclusion as it will be needed when we start write something -->
<ignoredUnusedDeclaredDependency>io.skodjob:test-frame-metrics-collector</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>io.fabric8:openshift-client</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>io.fabric8:kubernetes-model</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>org.junit.jupiter:junit-jupiter-engine</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>org.junit.jupiter:junit-jupiter-params</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>org.junit.platform:junit-platform-commons</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>org.junit.platform:junit-platform-engine</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>org.apache.maven.plugins:maven-failsafe-plugin</ignoredUnusedDeclaredDependency>
</ignoredUnusedDeclaredDependencies>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven.checkstyle.version}</version>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<configLocation>.checkstyle/checkstyle.xml</configLocation>
<suppressionsLocation>.checkstyle/suppressions.xml</suppressionsLocation>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${maven.spotbugs.version}</version>
<dependencies>
<!-- overwrite dependency on spotbugs if you want to specify the version of˓→spotbugs -->
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>${spotbugs.version}</version>
</dependency>
</dependencies>
<configuration>
<effort>Max</effort>
<!-- Reports all bugs (other values are medium and max) -->
<threshold>Low</threshold>
<!-- Produces XML report -->
<xmlOutput>true</xmlOutput>
<!-- Configures the directory in which the XML report is created -->
<spotbugsXmlOutputDirectory>${project.build.directory}/spotbugs</spotbugsXmlOutputDirectory>
<!-- Configures the file for excluding warnings -->
<excludeFilterFile>${project.basedir}/.spotbugs/spotbugs-exclude.xml</excludeFilterFile>
</configuration>
</plugin>
</plugins>
</build>

</project>
</project>
4 changes: 4 additions & 0 deletions src/main/java/io/streams/Environment.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Copyright Skodjob authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.streams;

import io.skodjob.testframe.environment.TestEnvironmentVariables;
4 changes: 4 additions & 0 deletions src/main/java/io/streams/constants/TestConstants.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Copyright Skodjob authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.streams.constants;

public interface TestConstants {
4 changes: 4 additions & 0 deletions src/main/java/io/streams/constants/TestTags.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Copyright Skodjob authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.streams.constants;

public interface TestTags {
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
*/
package io.streams.listeners;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.fabric8.kubernetes.api.model.LabelSelectorBuilder;
import io.skodjob.testframe.LogCollector;
import io.skodjob.testframe.LogCollectorBuilder;
@@ -55,6 +56,7 @@ public void handleAfterAllMethodExecutionException(ExtensionContext context, Thr
saveKubernetesState(context, throwable);
}

@SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
private void saveKubernetesState(ExtensionContext context, Throwable throwable) throws Throwable {
LogCollector logCollector = new LogCollectorBuilder()
.withNamespacedResources("deployment", "subscription", "operatorgroup", "configmaps", "secret")
4 changes: 4 additions & 0 deletions src/main/java/io/streams/utils/TestUtils.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Copyright Skodjob authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.streams.utils;

import io.streams.Environment;
Loading