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

Reformatted Java code and added .editorconfig #500

Merged
merged 1 commit into from
Apr 11, 2023
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
627 changes: 627 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

60 changes: 34 additions & 26 deletions src/main/java/kafdrop/Kafdrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,38 @@

package kafdrop;

import com.google.common.base.*;
import io.undertow.server.*;
import com.google.common.base.Strings;
import io.undertow.server.DefaultByteBufferPool;
import io.undertow.server.HandlerWrapper;
import io.undertow.server.HttpHandler;
import io.undertow.server.handlers.DisallowedMethodsHandler;
import io.undertow.util.HttpString;
import io.undertow.websockets.jsr.*;
import kafdrop.config.ini.*;
import org.slf4j.*;
import io.undertow.websockets.jsr.WebSocketDeploymentInfo;
import kafdrop.config.ini.IniFilePropertySource;
import kafdrop.config.ini.IniFileReader;
import org.slf4j.Logger;
import org.springframework.boot.Banner.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.boot.builder.*;
import org.springframework.boot.context.event.*;
import org.springframework.boot.web.embedded.undertow.*;
import org.springframework.boot.web.server.*;
import org.springframework.context.*;
import org.springframework.context.annotation.*;
import org.springframework.core.*;
import org.springframework.core.env.*;
import org.springframework.web.servlet.config.annotation.*;

import java.io.*;
import java.nio.charset.*;
import org.slf4j.LoggerFactory;
import org.springframework.boot.Banner.Mode;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.web.embedded.undertow.UndertowDeploymentInfoCustomizer;
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.springframework.core.env.Environment;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.stream.*;
import java.util.stream.Stream;

@SpringBootApplication
public class Kafdrop {
Expand All @@ -56,7 +64,7 @@ public static SpringApplicationBuilder createApplicationBuilder() {
return new SpringApplicationBuilder(Kafdrop.class)
.bannerMode(Mode.OFF)
.listeners(new EnvironmentSetupListener(),
new LoggingConfigurationListener());
new LoggingConfigurationListener());
}

@Bean
Expand Down Expand Up @@ -116,7 +124,7 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
}
}
if (environment.containsProperty("debug") &&
!"false".equalsIgnoreCase(environment.getProperty("debug", String.class))) {
!"false".equalsIgnoreCase(environment.getProperty("debug", String.class))) {
System.setProperty(PROP_SPRING_BOOT_LOG_LEVEL, "DEBUG");
}
}
Expand Down Expand Up @@ -154,10 +162,10 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {

if (environment.containsProperty(SM_CONFIG_DIR)) {
Stream.of("kafdrop", "global")
.map(name -> readProperties(environment, name))
.filter(Objects::nonNull)
.forEach(iniPropSource -> environment.getPropertySources()
.addBefore("applicationConfigurationProperties", iniPropSource));
.map(name -> readProperties(environment, name))
.filter(Objects::nonNull)
.forEach(iniPropSource -> environment.getPropertySources()
.addBefore("applicationConfigurationProperties", iniPropSource));
}
}

Expand Down
26 changes: 17 additions & 9 deletions src/main/java/kafdrop/config/CorsConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,24 @@

package kafdrop.config;

import org.springframework.beans.factory.annotation.*;
import org.springframework.boot.autoconfigure.condition.*;
import org.springframework.context.annotation.*;
import org.springframework.core.*;
import org.springframework.core.annotation.*;
import org.springframework.http.*;
import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import java.io.*;
import java.io.IOException;

/**
* Auto configuration for enabling CORS support. Can override behavior with
Expand Down
34 changes: 19 additions & 15 deletions src/main/java/kafdrop/config/HealthCheckConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@

package kafdrop.config;

import org.springframework.boot.actuate.health.*;
import org.springframework.context.annotation.*;
import org.springframework.jmx.export.annotation.*;
import org.springframework.stereotype.*;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthEndpoint;
import org.springframework.boot.actuate.health.Status;
import org.springframework.context.annotation.Configuration;
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.stream.*;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;

@Configuration
public class HealthCheckConfiguration {
Expand All @@ -48,15 +52,15 @@ public Map<String, Object> getHealth() {

private Map<String, Object> getDetails(Map<String, Object> details) {
return details.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey,
e -> {
final var health = (Health) e.getValue();
final var detail = new LinkedHashMap<String, Object>();
final var healthy = Status.UP.equals(health.getStatus());
detail.put("healthy", healthy);
detail.put("message", health.getDetails().toString());
return detail;
}));
.collect(Collectors.toMap(Map.Entry::getKey,
e -> {
final var health = (Health) e.getValue();
final var detail = new LinkedHashMap<String, Object>();
final var healthy = Status.UP.equals(health.getStatus());
detail.put("healthy", healthy);
detail.put("message", health.getDetails().toString());
return detail;
}));
}

private String getStatus(Health health) {
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/kafdrop/config/InterceptorConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

package kafdrop.config;

import org.springframework.core.env.*;
import org.springframework.stereotype.*;
import org.springframework.web.servlet.*;
import org.springframework.web.servlet.config.annotation.*;

import jakarta.servlet.http.*;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.AsyncHandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Component
public class InterceptorConfiguration implements WebMvcConfigurer {
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/kafdrop/config/KafkaConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package kafdrop.config;

import java.io.*;
import java.util.*;
import lombok.*;
import org.apache.kafka.clients.*;
import org.apache.kafka.common.config.*;
import org.slf4j.*;
import org.springframework.boot.context.properties.*;
import org.springframework.stereotype.*;
import lombok.Data;
import org.apache.kafka.clients.CommonClientConfigs;
import org.apache.kafka.common.config.SaslConfigs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;


@Component
Expand All @@ -31,7 +36,7 @@ public void applyCommon(Properties properties) {
properties.put(SaslConfigs.SASL_MECHANISM, saslMechanism);
}

if(isSecured || securityProtocol.equals("SSL")) {
if (isSecured || securityProtocol.equals("SSL")) {
properties.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, securityProtocol);
}

Expand Down
11 changes: 5 additions & 6 deletions src/main/java/kafdrop/config/MessageFormatConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package kafdrop.config;

import kafdrop.util.*;
import org.springframework.boot.context.properties.*;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.*;

import jakarta.annotation.*;
import jakarta.annotation.PostConstruct;
import kafdrop.util.MessageFormat;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;


@Configuration
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/kafdrop/config/OASConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
import org.springframework.context.annotation.Configuration;

/**
* Autoconfiguration for OpenAPI Specification (OAS).
* Can be disabled by setting {@code springdoc.api-docs.enabled=false}.
* Autoconfiguration for OpenAPI Specification (OAS).
* Can be disabled by setting {@code springdoc.api-docs.enabled=false}.
*/
@Configuration
public class OASConfiguration {

@Bean
public OpenAPI httpApi() {
return new OpenAPI().info(new Info()
.title("Kafdrop API")
.description("JSON APIs for Kafdrop"));
.title("Kafdrop API")
.description("JSON APIs for Kafdrop"));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package kafdrop.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.FilenameFilter;
import java.nio.file.Files;
Expand All @@ -9,12 +15,6 @@
import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Configuration
public class ProtobufDescriptorConfiguration {
@Component
Expand Down
26 changes: 15 additions & 11 deletions src/main/java/kafdrop/config/SchemaRegistryConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package kafdrop.config;

import org.springframework.boot.context.properties.*;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.*;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.regex.*;
import java.util.stream.*;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;


@Configuration
Expand All @@ -27,15 +27,19 @@ public void setConnect(String connect) {
this.connect = connect;
}

public String getAuth() { return auth; }
public String getAuth() {
return auth;
}

public void setAuth(String auth) { this.auth = auth; }
public void setAuth(String auth) {
this.auth = auth;
}

public List<String> getConnectList() {
return CONNECT_SEPARATOR.splitAsStream(this.connect)
.map(String::trim)
.filter(s -> s.length() > 0)
.collect(Collectors.toList());
.map(String::trim)
.filter(s -> s.length() > 0)
.collect(Collectors.toList());
}
}
}
6 changes: 4 additions & 2 deletions src/main/java/kafdrop/config/ini/IniFileProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

package kafdrop.config.ini;

import com.google.common.collect.*;
import com.google.common.collect.Maps;

import java.util.*;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;

public final class IniFileProperties {
private Map<String, Map<String, String>> sectionProperties = Maps.newLinkedHashMap();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/kafdrop/config/ini/IniFilePropertySource.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

package kafdrop.config.ini;

import com.google.common.collect.*;
import org.springframework.core.env.*;
import com.google.common.collect.Maps;
import org.springframework.core.env.MapPropertySource;

import java.util.*;
import java.util.Map;

public class IniFilePropertySource extends MapPropertySource {
public IniFilePropertySource(String name, IniFileProperties source, String[] activeProfiles) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/kafdrop/config/ini/IniFileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

package kafdrop.config.ini;

import org.apache.commons.lang3.*;
import org.apache.commons.lang3.StringUtils;

import java.io.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;

public class IniFileReader {
private static final String COMMENT_CHARS = "#;";
Expand Down
Loading