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

Switch to spotless maven plugin with palantir formatting #561

Merged
merged 2 commits into from
Nov 29, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 4 additions & 2 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ jobs:
java-version: '21'
cache: 'maven'

- name: Validate pom formatting
run: make lint-pom

- name: Validate source code formatting
run: |
make lint
run: make lint-java

- name: Test
run: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ docker-compose_datadir*
.env.yjp

hs_err_pid*.log

.spotless-index
22 changes: 18 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,26 @@ clean:
./mvnw clean

.PHONY: lint
lint:
./mvnw fmt:check sortpom:verify -Dsort.verifyFailOn=strict -Dsort.verifyFail=stop -ntp -T1C
lint: lint-pom lint-java

.PHONY: lint-pom
lint-pom:
./mvnw sortpom:verify -Dsort.verifyFailOn=strict -Dsort.verifyFail=stop -ntp -T1C

.PHONY: lint-java
lint-java:
./mvnw spotless:check -ntp -T1C

.PHONY: format
format:
./mvnw sortpom:sort fmt:format -ntp -T1C
format: format-pom format-java

.PHONY: format-pom
format-pom:
./mvnw sortpom:sort -ntp -T1C

.PHONY: format-java
format-java:
./mvnw spotless:apply -ntp -T1C

.PHONY: install
install:
Expand Down
41 changes: 25 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
</modules>
<properties>
<revision>1.9-SNAPSHOT</revision>
<fmt.action>format</fmt.action>
<fmt.skip>false</fmt.skip>
<spotless.action>apply</spotless.action>
<spotless.apply.skip>${fmt.skip}</spotless.apply.skip>
<pom.fmt.action>sort</pom.fmt.action>
<pom.fmt.skip>${fmt.skip}</pom.fmt.skip>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>
Expand Down Expand Up @@ -215,9 +218,9 @@
<pluginManagement>
<plugins>
<plugin>
<groupId>com.spotify.fmt</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<version>2.21.1</version>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.43.0</version>
</plugin>
<plugin>
<groupId>com.github.ekryd.sortpom</groupId>
Expand All @@ -242,37 +245,43 @@
<artifactId>sortpom-maven-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<keepBlankLines>true</keepBlankLines>
<spaceBeforeCloseEmptyElement>false</spaceBeforeCloseEmptyElement>
<createBackupFile>false</createBackupFile>
<lineSeparator>\n</lineSeparator>
<nrOfIndentSpace>2</nrOfIndentSpace>
<verifyFail>stop</verifyFail>
<verifyFailOn>strict</verifyFailOn>
<skip>${fmt.skip}</skip>
<skip>${pom.fmt.skip}</skip>
</configuration>
<executions>
<execution>
<id>sort</id>
<goals>
<goal>sort</goal>
<goal>${pom.fmt.action}</goal>
</goals>
<phase>validate</phase>
<phase>verify</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify.fmt</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<configuration>
<verbose>false</verbose>
<filesNamePattern>.*\.java</filesNamePattern>
<skip>${fmt.skip}</skip>
<style>aosp</style>
<java>
<palantirJavaFormat>
<version>2.50.0</version>
</palantirJavaFormat>
</java>
<upToDateChecking>
<enabled>true</enabled>
<indexFile>${project.basedir}/.spotless-index</indexFile>
</upToDateChecking>
</configuration>
<executions>
<execution>
<goals>
<goal>${fmt.action}</goal>
<goal>${spotless.action}</goal>
</goals>
<phase>validate</phase>
</execution>
</executions>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public static void main(String[] args) {
SpringApplication.run(GeoWebCacheApplication.class, args);
} catch (RuntimeException e) {
try {
LoggerFactory.getLogger(GeoWebCacheApplication.class)
.error("Application run failed", e);
LoggerFactory.getLogger(GeoWebCacheApplication.class).error("Application run failed", e);
} finally {
System.exit(-1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
*/
package org.geoserver.cloud.gwc.app;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import org.geoserver.catalog.Catalog;
import org.geoserver.cloud.gwc.config.core.WebMapServiceMinimalConfiguration;
import org.geoserver.gwc.layer.GeoServerTileLayer;
Expand All @@ -22,16 +30,6 @@
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.servlet.resource.ResourceUrlProvider;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

@Configuration
public class GeoWebCacheApplicationConfiguration extends RestConfiguration {

Expand All @@ -44,8 +42,7 @@ public class GeoWebCacheApplicationConfiguration extends RestConfiguration {
*/
@Bean
@ConditionalOnMissingBean
LegendSample legendSample(
@Qualifier("rawCatalog") Catalog catalog, GeoServerResourceLoader loader) {
LegendSample legendSample(@Qualifier("rawCatalog") Catalog catalog, GeoServerResourceLoader loader) {
return new LegendSampleImpl(catalog, loader);
}

Expand All @@ -64,14 +61,12 @@ public void configureContentNegotiation(ContentNegotiationConfigurer configurer)
@Bean
@Override
public RequestMappingHandlerMapping requestMappingHandlerMapping(
@Qualifier("mvcContentNegotiationManager")
ContentNegotiationManager contentNegotiationManager,
@Qualifier("mvcContentNegotiationManager") ContentNegotiationManager contentNegotiationManager,
@Qualifier("mvcConversionService") FormattingConversionService conversionService,
@Qualifier("mvcResourceUrlProvider") ResourceUrlProvider resourceUrlProvider) {

RequestMappingHandlerMapping handlerMapping =
super.requestMappingHandlerMapping(
contentNegotiationManager, conversionService, resourceUrlProvider);
super.requestMappingHandlerMapping(contentNegotiationManager, conversionService, resourceUrlProvider);

handlerMapping.setUseSuffixPatternMatch(true);
handlerMapping.setUseRegisteredSuffixPatternMatch(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import com.google.gson.JsonElement;
import com.google.gson.JsonParser;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -26,7 +25,8 @@
@ActiveProfiles("test")
class GeoWebCacheApplicationTest {

@Autowired private TestRestTemplate restTemplate;
@Autowired
private TestRestTemplate restTemplate;

@BeforeEach
void before() {
Expand All @@ -37,16 +37,14 @@ void before() {

@Test
void testRESTDefaultContentType() {
ResponseEntity<String> response =
testGetRequestContentType("/gwc/rest/layers", APPLICATION_JSON);
ResponseEntity<String> response = testGetRequestContentType("/gwc/rest/layers", APPLICATION_JSON);
JsonElement parsed = JsonParser.parseString(response.getBody());
assertThat(parsed.isJsonArray()).isTrue();
}

@Test
void testRESTPathExtensionContentNegotiation() {
ResponseEntity<String> response =
testGetRequestContentType("/gwc/rest/layers.json", APPLICATION_JSON);
ResponseEntity<String> response = testGetRequestContentType("/gwc/rest/layers.json", APPLICATION_JSON);
JsonElement parsed = JsonParser.parseString(response.getBody());
assertThat(parsed.isJsonArray()).isTrue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public static void main(String[] args) {
SpringApplication.run(RestConfigApplication.class, args);
} catch (RuntimeException e) {
try {
LoggerFactory.getLogger(RestConfigApplication.class)
.error("Application run failed", e);
LoggerFactory.getLogger(RestConfigApplication.class).error("Application run failed", e);
} finally {
System.exit(-1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
*/
package org.geoserver.cloud.restconfig;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import org.geoserver.rest.RequestInfo;
import org.geoserver.rest.RestConfiguration;
import org.geoserver.rest.catalog.AdminRequestCallback;
Expand All @@ -19,16 +27,6 @@
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.servlet.resource.ResourceUrlProvider;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

@Configuration
@ComponentScan(basePackageClasses = org.geoserver.rest.AbstractGeoServerController.class)
@SuppressWarnings("deprecation")
Expand All @@ -53,14 +51,12 @@ AdminRequestCallback adminRequestCallback() {
@Bean
@Override
public RequestMappingHandlerMapping requestMappingHandlerMapping(
@Qualifier("mvcContentNegotiationManager")
ContentNegotiationManager contentNegotiationManager,
@Qualifier("mvcContentNegotiationManager") ContentNegotiationManager contentNegotiationManager,
@Qualifier("mvcConversionService") FormattingConversionService conversionService,
@Qualifier("mvcResourceUrlProvider") ResourceUrlProvider resourceUrlProvider) {

RequestMappingHandlerMapping handlerMapping =
super.requestMappingHandlerMapping(
contentNegotiationManager, conversionService, resourceUrlProvider);
super.requestMappingHandlerMapping(contentNegotiationManager, conversionService, resourceUrlProvider);

handlerMapping.setUseSuffixPatternMatch(true);
handlerMapping.setUseRegisteredSuffixPatternMatch(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
@ActiveProfiles("test")
class RestConfigApplicationTest {

@Autowired private TestRestTemplate restTemplate;
@Autowired
private TestRestTemplate restTemplate;

@BeforeEach
void before() {
Expand All @@ -45,8 +46,7 @@ void testPathExtensionContentNegotiation() {
testPathExtensionContentType("/rest/styles/line.json", APPLICATION_JSON);
testPathExtensionContentType("/rest/styles/line.xml", APPLICATION_XML);
testPathExtensionContentType("/rest/styles/line.html", TEXT_HTML);
testPathExtensionContentType(
"/rest/styles/line.sld", MediaType.valueOf(SLDHandler.MIMETYPE_10));
testPathExtensionContentType("/rest/styles/line.sld", MediaType.valueOf(SLDHandler.MIMETYPE_10));

testPathExtensionContentType("/rest/workspaces.html", TEXT_HTML);
testPathExtensionContentType("/rest/workspaces.xml", APPLICATION_XML);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
*/
package org.geoserver.cloud.wcs;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

import org.geoserver.cloud.virtualservice.VirtualServiceVerifier;
import org.geoserver.ows.Dispatcher;
import org.springframework.stereotype.Controller;
Expand All @@ -15,9 +16,6 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.view.RedirectView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RequiredArgsConstructor
public @Controller class WCSController {

Expand All @@ -34,20 +32,17 @@ public RedirectView redirectRootToGetCapabilities() {

/** Serve only WCS schemas from classpath (e.g. {@code /schemas/wcs/1.1.1/wcsAll.xsd}) */
@GetMapping(path = "/schemas/wcs/**")
public void getSchema(HttpServletRequest request, HttpServletResponse response)
throws Exception {
public void getSchema(HttpServletRequest request, HttpServletResponse response) throws Exception {
classPathPublisher.handleRequest(request, response);
}

@GetMapping(path = {"/wcs", "/ows"})
public void handleGet(HttpServletRequest request, HttpServletResponse response)
throws Exception {
public void handleGet(HttpServletRequest request, HttpServletResponse response) throws Exception {
dispatch(request, response);
}

@PostMapping(path = {"/wcs", "/ows"})
public void handlePost(HttpServletRequest request, HttpServletResponse response)
throws Exception {
public void handlePost(HttpServletRequest request, HttpServletResponse response) throws Exception {
dispatch(request, response);
}

Expand Down Expand Up @@ -97,8 +92,7 @@ public void handleVirtualServiceLayerPost(
dispatch(request, response);
}

private void dispatch(HttpServletRequest request, HttpServletResponse response)
throws Exception {
private void dispatch(HttpServletRequest request, HttpServletResponse response) throws Exception {
geoserverDispatcher.handleRequest(request, response);
}
}
Loading
Loading