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 fix current violation #18

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
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
100 changes: 100 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?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="120"/>
</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>

<!-- 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>
24 changes: 24 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
<name>Jakub Stejskal</name>
<email>[email protected]</email>
</developer>
<developer>
<id>obabec</id>
<name>Ondrej Babec</name>
<email>[email protected]</email>
</developer>
</developers>

<properties>
Expand All @@ -82,6 +87,7 @@
<maven.javadoc.version>3.4.1</maven.javadoc.version>
<maven.assembly.version>3.4.2</maven.assembly.version>
<maven.plugin.plugin.version>3.9.0</maven.plugin.plugin.version>
<checkstyle.config.location>checkstyle.xml</checkstyle.config.location>
<junit.jupiter.version>5.10.2</junit.jupiter.version>
</properties>

Expand Down Expand Up @@ -150,6 +156,24 @@
<!-- </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>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>${maven.source.plugin.version}</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
*/
package io.skodjob.testframe;

import java.util.Collections;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;

public class LoggerUtils {

private static final Logger LOGGER = LoggerFactory.getLogger(LoggerUtils.class);
Expand Down
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.skodjob.testframe;

import java.time.Duration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
*/
package io.skodjob.testframe;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -18,6 +14,10 @@
import java.util.Objects;
import java.util.function.Function;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;

/**
* Class which holds environment variables for system tests.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
package io.skodjob.testframe.clients;

import java.util.Arrays;

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
Expand All @@ -13,8 +15,6 @@
import io.skodjob.testframe.TestFrameEnv;
import io.skodjob.testframe.executor.Exec;

import java.util.Arrays;

public class KubeClient {

private KubernetesClient client;
Expand Down Expand Up @@ -73,13 +73,15 @@ private String createLocalKubeconfig() {
if (TestFrameEnv.KUBE_URL != null && TestFrameEnv.KUBE_TOKEN != null) {
createLocalOcKubeconfig(TestFrameEnv.KUBE_TOKEN, TestFrameEnv.KUBE_URL);
} else {
createLocalOcKubeconfig(TestFrameEnv.KUBE_USERNAME, TestFrameEnv.KUBE_PASSWORD, TestFrameEnv.KUBE_URL);
createLocalOcKubeconfig(TestFrameEnv.KUBE_USERNAME, TestFrameEnv.KUBE_PASSWORD,
TestFrameEnv.KUBE_URL);
}
} else {
if (TestFrameEnv.KUBE_URL != null && TestFrameEnv.KUBE_TOKEN != null) {
createLocalKubectlContext(TestFrameEnv.KUBE_TOKEN, TestFrameEnv.KUBE_URL);
} else {
createLocalKubectlContext(TestFrameEnv.KUBE_USERNAME, TestFrameEnv.KUBE_PASSWORD, TestFrameEnv.KUBE_URL);
createLocalKubectlContext(TestFrameEnv.KUBE_USERNAME, TestFrameEnv.KUBE_PASSWORD,
TestFrameEnv.KUBE_URL);
}
}
return TestFrameEnv.USER_PATH + "/test.kubeconfig";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
*/
package io.skodjob.testframe.clients.cmdClient;

import io.skodjob.testframe.clients.KubeClusterException;
import io.skodjob.testframe.executor.Exec;
import io.skodjob.testframe.executor.ExecResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.nio.file.NoSuchFileException;
import java.util.ArrayList;
Expand All @@ -21,6 +15,12 @@
import java.util.function.Consumer;
import java.util.stream.Collectors;

import io.skodjob.testframe.clients.KubeClusterException;
import io.skodjob.testframe.executor.Exec;
import io.skodjob.testframe.executor.ExecResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.lang.String.join;
import static java.util.Arrays.asList;

Expand Down Expand Up @@ -89,7 +89,8 @@ public String getEvents() {
@SuppressWarnings("unchecked")
public K create(File... files) {
try (Context context = defaultContext()) {
Map<File, ExecResult> execResults = execRecursive(CREATE, files, Comparator.comparing(File::getName).reversed());
Map<File, ExecResult> execResults = execRecursive(CREATE, files, Comparator.comparing(File::getName)
.reversed());
for (Map.Entry<File, ExecResult> entry : execResults.entrySet()) {
if (!entry.getValue().exitStatus()) {
LOGGER.warn("Failed to create {}!", entry.getKey().getAbsolutePath());
Expand All @@ -104,7 +105,8 @@ public K create(File... files) {
@SuppressWarnings("unchecked")
public K apply(File... files) {
try (Context context = defaultContext()) {
Map<File, ExecResult> execResults = execRecursive(APPLY, files, Comparator.comparing(File::getName).reversed());
Map<File, ExecResult> execResults = execRecursive(APPLY, files, Comparator.comparing(File::getName)
.reversed());
for (Map.Entry<File, ExecResult> entry : execResults.entrySet()) {
if (!entry.getValue().exitStatus()) {
LOGGER.warn("Failed to apply {}!", entry.getKey().getAbsolutePath());
Expand All @@ -119,7 +121,8 @@ public K apply(File... files) {
@SuppressWarnings("unchecked")
public K delete(File... files) {
try (Context context = defaultContext()) {
Map<File, ExecResult> execResults = execRecursive(DELETE, files, Comparator.comparing(File::getName).reversed());
Map<File, ExecResult> execResults = execRecursive(DELETE, files, Comparator.comparing(File::getName)
.reversed());
for (Map.Entry<File, ExecResult> entry : execResults.entrySet()) {
if (!entry.getValue().exitStatus()) {
LOGGER.warn("Failed to delete {}!", entry.getKey().getAbsolutePath());
Expand All @@ -135,7 +138,8 @@ private Map<File, ExecResult> execRecursive(String subcommand, File[] files, Com
for (File f : files) {
if (f.isFile()) {
if (f.getName().endsWith(".yaml")) {
execResults.put(f, Exec.exec(null, namespacedCommand(subcommand, "-f", f.getAbsolutePath()), 0, false, false));
execResults.put(f, Exec.exec(null, namespacedCommand(subcommand, "-f",
f.getAbsolutePath()), 0, false, false));
}
} else if (f.isDirectory()) {
File[] children = f.listFiles();
Expand Down Expand Up @@ -187,7 +191,8 @@ public K deleteContentInNamespace(String yamlContent) {
@SuppressWarnings("unchecked")
public K applyContent(String yamlContent) {
try (Context context = defaultContext()) {
Exec.exec(yamlContent, command(Arrays.asList(APPLY, "-f", "-"), false), 0, true, true);
Exec.exec(yamlContent, command(Arrays.asList(APPLY, "-f", "-"), false), 0,
true, true);
return (K) this;
}
}
Expand All @@ -196,7 +201,8 @@ public K applyContent(String yamlContent) {
@SuppressWarnings("unchecked")
public K deleteContent(String yamlContent) {
try (Context context = defaultContext()) {
Exec.exec(yamlContent, command(Arrays.asList(DELETE, "-f", "-"), false), 0, true, false);
Exec.exec(yamlContent, command(Arrays.asList(DELETE, "-f", "-"), false), 0,
true, false);
return (K) this;
}
}
Expand Down Expand Up @@ -280,7 +286,9 @@ public String toString() {

@Override
public List<String> list(String resourceType) {
return Arrays.stream(Exec.exec(namespacedCommand(GET, resourceType, "-o", "jsonpath={range .items[*]}{.metadata.name} ")).out().trim().split(" +"))
return Arrays.stream(Exec.exec(namespacedCommand(GET, resourceType,
"-o", "jsonpath={range .items[*]}{.metadata.name} "))
.out().trim().split(" +"))
.filter(s -> !s.trim().isEmpty()).collect(Collectors.toList());
}

Expand Down Expand Up @@ -330,8 +338,10 @@ public String logs(String pod, String container) {
@Override
public String searchInLog(String resourceType, String resourceName, long sinceSeconds, String... grepPattern) {
try {
return Exec.exec("bash", "-c", join(" ", namespacedCommand("logs", resourceType + "/" + resourceName, "--since=" + sinceSeconds + "s",
"|", "grep", " -e " + join(" -e ", grepPattern), "-B", "1"))).out();
return Exec.exec("bash", "-c", join(" ",
namespacedCommand("logs", resourceType + "/" + resourceName, "--since=" + sinceSeconds + "s",
"|", "grep", " -e " + join(" -e ", grepPattern), "-B", "1")))
.out();
} catch (KubeClusterException e) {
if (e.result != null && e.result.returnCode() == 1) {
LOGGER.info("{} not found", Arrays.stream(grepPattern).toList());
Expand All @@ -343,9 +353,11 @@ public String searchInLog(String resourceType, String resourceName, long sinceSe
}

@Override
public String searchInLog(String resourceType, String resourceName, String resourceContainer, long sinceSeconds, String... grepPattern) {
public String searchInLog(String resourceType, String resourceName, String resourceContainer,
long sinceSeconds, String... grepPattern) {
try {
return Exec.exec("bash", "-c", join(" ", namespacedCommand("logs", resourceType + "/" + resourceName, "-c " + resourceContainer, "--since=" + sinceSeconds + "s",
return Exec.exec("bash", "-c", join(" ", namespacedCommand("logs",
resourceType + "/" + resourceName, "-c " + resourceContainer, "--since=" + sinceSeconds + "s",
"|", "grep", " -e " + join(" -e ", grepPattern), "-B", "1"))).out();
} catch (KubeClusterException e) {
if (e.result != null && e.result.exitStatus()) {
Expand All @@ -359,7 +371,9 @@ public String searchInLog(String resourceType, String resourceName, String resou

@Override
public List<String> listResourcesByLabel(String resourceType, String label) {
return asList(Exec.exec(namespacedCommand(GET, resourceType, "-l", label, "-o", "jsonpath={range .items[*]}{.metadata.name} ")).out().split("\\s+"));
return asList(Exec.exec(namespacedCommand(GET, resourceType,
"-l", label, "-o", "jsonpath={range .items[*]}{.metadata.name} "))
.out().split("\\s+"));
}

private List<String> command(List<String> rest, boolean namespaced) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
*/
package io.skodjob.testframe.clients.cmdClient;

import io.skodjob.testframe.executor.ExecResult;

import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

import io.skodjob.testframe.executor.ExecResult;

import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toList;

Expand Down Expand Up @@ -192,7 +192,8 @@ default String logs(String pod) {
* @param grepPattern Grep patterns for search
* @return Grep result as string
*/
String searchInLog(String resourceType, String resourceName, String resourceContainer, long sinceSeconds, String... grepPattern);
String searchInLog(String resourceType, String resourceName, String resourceContainer,
long sinceSeconds, String... grepPattern);

String getResourceAsJson(String resourceType, String resourceName);

Expand Down
Loading
Loading