This is an automated email from the ASF dual-hosted git repository. bossenti pushed a commit to branch add-checkstyle-streampipes-service in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit 1665c90bcff45ed96d919d90dcaa47cfb01bb81d Author: bossenti <[email protected]> AuthorDate: Sun Dec 4 16:58:12 2022 +0100 add checkstyle to streampipes-service-base --- streampipes-service-base/pom.xml | 24 +++++++++++++++++++++- .../service/base/BaseNetworkingConfig.java | 12 +++++------ .../service/base/StreamPipesServiceBase.java | 22 ++++++++++---------- .../service/base/rest/BaseResourceConfig.java | 2 +- .../security/UnauthorizedRequestEntryPoint.java | 14 +++++++------ .../src/main/resources/logback-spring.xml | 2 +- 6 files changed, 50 insertions(+), 26 deletions(-) diff --git a/streampipes-service-base/pom.xml b/streampipes-service-base/pom.xml index 4c5811a3a..eda5680f4 100644 --- a/streampipes-service-base/pom.xml +++ b/streampipes-service-base/pom.xml @@ -17,7 +17,8 @@ ~ --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>streampipes-parent</artifactId> <groupId>org.apache.streampipes</groupId> @@ -113,4 +114,25 @@ <artifactId>hibernate-validator</artifactId> </dependency> </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-checkstyle-plugin</artifactId> + <executions> + <execution> + <id>validate</id> + <phase>validate</phase> + <goals> + <goal>check</goal> + </goals> + </execution> + </executions> + <configuration> + <logViolationsToConsole>true</logViolationsToConsole> + <failOnViolation>true</failOnViolation> + </configuration> + </plugin> + </plugins> + </build> </project> diff --git a/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/BaseNetworkingConfig.java b/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/BaseNetworkingConfig.java index bfcd1048f..5cec0724a 100644 --- a/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/BaseNetworkingConfig.java +++ b/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/BaseNetworkingConfig.java @@ -26,6 +26,12 @@ public class BaseNetworkingConfig { private final String host; private final Integer port; + public BaseNetworkingConfig(String host, + Integer port) { + this.host = host; + this.port = port; + } + public static BaseNetworkingConfig defaultResolution(Integer defaultPort) throws UnknownHostException { String host = Networking.getHostname(); Integer port = Networking.getPort(defaultPort); @@ -33,12 +39,6 @@ public class BaseNetworkingConfig { return new BaseNetworkingConfig(host, port); } - public BaseNetworkingConfig(String host, - Integer port) { - this.host = host; - this.port = port; - } - public String getHost() { return host; } diff --git a/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/StreamPipesServiceBase.java b/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/StreamPipesServiceBase.java index 593e14258..f733921a2 100644 --- a/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/StreamPipesServiceBase.java +++ b/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/StreamPipesServiceBase.java @@ -17,10 +17,11 @@ */ package org.apache.streampipes.service.base; -import org.apache.commons.lang3.RandomStringUtils; import org.apache.streampipes.svcdiscovery.SpServiceDiscovery; import org.apache.streampipes.svcdiscovery.api.model.SpServiceRegistrationRequest; import org.apache.streampipes.svcdiscovery.api.model.SpServiceTag; + +import org.apache.commons.lang3.RandomStringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; @@ -31,9 +32,8 @@ import java.util.List; public abstract class StreamPipesServiceBase { - private static final Logger LOG = LoggerFactory.getLogger(StreamPipesServiceBase.class); - public static final String AUTO_GENERATED_SERVICE_ID = RandomStringUtils.randomAlphanumeric(6); + private static final Logger LOG = LoggerFactory.getLogger(StreamPipesServiceBase.class); protected void startStreamPipesService(Class<?> serviceClass, String serviceGroup, @@ -54,16 +54,16 @@ public abstract class StreamPipesServiceBase { String serviceId, BaseNetworkingConfig networkingConfig) { SpServiceRegistrationRequest req = SpServiceRegistrationRequest.from( - serviceGroup, - serviceId, - networkingConfig.getHost(), - networkingConfig.getPort(), - getServiceTags(), - getHealthCheckPath()); + serviceGroup, + serviceId, + networkingConfig.getHost(), + networkingConfig.getPort(), + getServiceTags(), + getHealthCheckPath()); SpServiceDiscovery - .getServiceDiscovery() - .registerService(req); + .getServiceDiscovery() + .registerService(req); } protected abstract List<SpServiceTag> getServiceTags(); diff --git a/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/rest/BaseResourceConfig.java b/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/rest/BaseResourceConfig.java index 7e5d1d77d..3eb8c9279 100644 --- a/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/rest/BaseResourceConfig.java +++ b/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/rest/BaseResourceConfig.java @@ -27,7 +27,7 @@ public abstract class BaseResourceConfig extends ResourceConfig { public BaseResourceConfig() { property(ServletProperties.FILTER_FORWARD_ON_404, true); getClassesToRegister() - .forEach(set -> set.forEach(this::register)); + .forEach(set -> set.forEach(this::register)); register(ServiceHealthResource.class); } diff --git a/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/security/UnauthorizedRequestEntryPoint.java b/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/security/UnauthorizedRequestEntryPoint.java index 91528c8ee..50cb7eafd 100644 --- a/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/security/UnauthorizedRequestEntryPoint.java +++ b/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/security/UnauthorizedRequestEntryPoint.java @@ -25,16 +25,18 @@ import org.springframework.security.web.AuthenticationEntryPoint; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import java.io.IOException; public class UnauthorizedRequestEntryPoint implements AuthenticationEntryPoint { - private static final Logger LOG = LoggerFactory.getLogger(UnauthorizedRequestEntryPoint.class); + private static final Logger LOG = LoggerFactory.getLogger(UnauthorizedRequestEntryPoint.class); - @Override - public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException { - LOG.error("Unauthorized request to {}", httpServletRequest.getPathInfo()); + @Override + public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, + AuthenticationException e) throws IOException { + LOG.error("Unauthorized request to {}", httpServletRequest.getPathInfo()); - httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getLocalizedMessage()); - } + httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getLocalizedMessage()); + } } diff --git a/streampipes-service-base/src/main/resources/logback-spring.xml b/streampipes-service-base/src/main/resources/logback-spring.xml index b2e2e8a1b..1331d020d 100644 --- a/streampipes-service-base/src/main/resources/logback-spring.xml +++ b/streampipes-service-base/src/main/resources/logback-spring.xml @@ -33,6 +33,6 @@ <root level="INFO"> - <appender-ref ref="CONSOLE" /> + <appender-ref ref="CONSOLE"/> </root> </configuration>
