Skip to content

Commit

Permalink
Add spotless check
Browse files Browse the repository at this point in the history
  • Loading branch information
matchilling committed Jun 19, 2024
1 parent 8520048 commit b6ebac7
Show file tree
Hide file tree
Showing 45 changed files with 1,344 additions and 1,609 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
ref: ${{ inputs.version }}
- run: ./gradlew test
- run: ./gradlew test spotlessCheck
137 changes: 72 additions & 65 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
plugins {
id 'com.palantir.docker' version '0.36.0'
id 'io.spring.dependency-management' version '1.1.5'
id 'java'
id 'org.springframework.boot' version '2.7.18'
id 'com.diffplug.spotless' version '7.0.0.BETA1'
id 'com.palantir.docker' version '0.36.0'
id 'io.spring.dependency-management' version '1.1.5'
id 'java'
id 'org.springframework.boot' version '2.7.18'
}

def gitRev = { ->
def stdout = new ByteArrayOutputStream()
def stdout = new ByteArrayOutputStream()

exec {
commandLine 'git', 'rev-parse', 'HEAD'
standardOutput = stdout
}
exec {
commandLine 'git', 'rev-parse', 'HEAD'
standardOutput = stdout
}

return stdout.toString().trim()
return stdout.toString().trim()
}

String appName = "api"
Expand All @@ -24,68 +25,74 @@ version = appVer
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
mavenCentral()
mavenCentral()
}

// versions
def lombokVersion = "1.18.30"

dependencies {
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"

implementation "com.amazonaws:aws-java-sdk:1.11.561"
implementation "com.fasterxml.jackson.core:jackson-core:2.17.1"
implementation "com.rometools:rome:1.12.0"
implementation "com.vladmihalcea:hibernate-types-52:2.4.0"
implementation "nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:2.3.0"
implementation "org.hibernate:hibernate-validator:6.0.16.Final"
implementation "org.postgresql:postgresql:42.2.9"
implementation "org.projectlombok:lombok:${lombokVersion}"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
implementation "org.springframework.boot:spring-boot-starter-thymeleaf"
implementation "org.springframework.boot:spring-boot-starter-web"
implementation 'com.google.guava:guava:33.2.1-jre'

testImplementation "org.springframework.boot:spring-boot-starter-test"
testImplementation 'junit:junit:4.12'
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"

implementation "com.amazonaws:aws-java-sdk:1.11.561"
implementation "com.fasterxml.jackson.core:jackson-core:2.17.1"
implementation "com.rometools:rome:1.12.0"
implementation "com.vladmihalcea:hibernate-types-52:2.4.0"
implementation "nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:2.3.0"
implementation "org.hibernate:hibernate-validator:6.0.16.Final"
implementation "org.postgresql:postgresql:42.2.9"
implementation "org.projectlombok:lombok:${lombokVersion}"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
implementation "org.springframework.boot:spring-boot-starter-thymeleaf"
implementation "org.springframework.boot:spring-boot-starter-web"
implementation 'com.google.guava:guava:33.2.1-jre'

testImplementation "org.springframework.boot:spring-boot-starter-test"
testImplementation 'junit:junit:4.12'
}

tasks {
bootJar {
manifest.attributes(
'Multi-Release': 'true'
)

archiveBaseName.set(appName)
archiveVersion.set(appVer)

if (project.hasProperty("archiveName")) {
archiveFileName.set(project.properties["archiveName"] as String)
}
}

docker {
dependsOn bootJar

def imageName = "${project.properties.group}/${appName}"
name = "${imageName}:latest"

tag("current", "${imageName}:${appVer}")
tag("latest", "${imageName}:latest")
tag("herokuProduction", "registry.heroku.com/chucky/web")

dockerfile file("${projectDir}/src/main/docker/Dockerfile")
files tasks.bootJar.outputs
buildArgs([JAR_FILE: bootJar.getArchiveFileName().get()])
}

springBoot {
buildInfo {
properties {
artifact = "${appName}-${appVer}.jar"
version = appVer
name = appName
}
}
}
bootJar {
manifest.attributes(
'Multi-Release': 'true'
)

archiveBaseName.set(appName)
archiveVersion.set(appVer)

if (project.hasProperty("archiveName")) {
archiveFileName.set(project.properties["archiveName"] as String)
}
}

docker {
dependsOn bootJar

def imageName = "${project.properties.group}/${appName}"
name = "${imageName}:latest"

tag("current", "${imageName}:${appVer}")
tag("latest", "${imageName}:latest")
tag("herokuProduction", "registry.heroku.com/chucky/web")

dockerfile file("${projectDir}/src/main/docker/Dockerfile")
files tasks.bootJar.outputs
buildArgs([JAR_FILE: bootJar.getArchiveFileName().get()])
}

springBoot {
buildInfo {
properties {
artifact = "${appName}-${appVer}.jar"
version = appVer
name = appName
}
}
}

spotless {
java {
googleJavaFormat()
}
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = 'io.chucknorris.api'
rootProject.name = 'io.chucknorris.api'
4 changes: 1 addition & 3 deletions src/main/java/io/chucknorris/api/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@ComponentScan(basePackages = {
"io.chucknorris"
})
@ComponentScan(basePackages = {"io.chucknorris"})
@EnableJpaAuditing
@SpringBootApplication
public class Application {
Expand Down
20 changes: 5 additions & 15 deletions src/main/java/io/chucknorris/api/ApplicationExceptionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,25 @@ public class ApplicationExceptionHandler extends ResponseEntityExceptionHandler

@ExceptionHandler(value = {ConstraintViolationException.class})
protected ResponseEntity<Object> handleConstraintViolationException(
ConstraintViolationException exception, ServletWebRequest request
) {
ConstraintViolationException exception, ServletWebRequest request) {
switch (request.getHeader(HttpHeaders.ACCEPT)) {
case MediaType.TEXT_PLAIN_VALUE:
StringBuilder stringBuilder = new StringBuilder();
for (ConstraintViolation violation : exception.getConstraintViolations()) {
stringBuilder.append(
violation.getPropertyPath().toString() + ": " + violation.getMessage()
+ '\n'
);
violation.getPropertyPath().toString() + ": " + violation.getMessage() + '\n');
}

return handleExceptionInternal(
exception,
stringBuilder.toString(),
new HttpHeaders(),
HttpStatus.BAD_REQUEST,
request
);
request);
default:
LinkedHashMap<String, Object> constraintViolations = new LinkedHashMap<>();
for (ConstraintViolation violation : exception.getConstraintViolations()) {
constraintViolations
.put(violation.getPropertyPath().toString(), violation.getMessage());
constraintViolations.put(violation.getPropertyPath().toString(), violation.getMessage());
}

LinkedHashMap<String, Object> body = new LinkedHashMap<>();
Expand All @@ -52,12 +47,7 @@ protected ResponseEntity<Object> handleConstraintViolationException(
body.put("violations", constraintViolations);

return handleExceptionInternal(
exception,
body,
new HttpHeaders(),
HttpStatus.BAD_REQUEST,
request
);
exception, body, new HttpHeaders(), HttpStatus.BAD_REQUEST, request);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,17 @@ public class AmazonWebServicesConfig {
@Value("${aws.region}")
private String region;

/**
* Returns a new {@link AmazonS3} instance.
*/
/** Returns a new {@link AmazonS3} instance. */
public @Bean AmazonS3 amazonS3() {
AWSCredentials credentials = new BasicAWSCredentials(accessKeyId, accessKeySecret);

return AmazonS3ClientBuilder
.standard()
return AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withRegion(region)
.build();
}

/**
* Returns a new {@link AmazonSNSClient} instance.
*/
/** Returns a new {@link AmazonSNSClient} instance. */
public @Bean AmazonSNSClient snsClient() {
AWSCredentials credentials = new BasicAWSCredentials(accessKeyId, accessKeySecret);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
@Configuration
public class CrossOriginResourceSharingConfig {

/**
* Returns cors filter registration bean {@link CorsConfiguration}.
*/
/** Returns cors filter registration bean {@link CorsConfiguration}. */
public @Bean FilterRegistrationBean corsFilter() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
Expand All @@ -27,4 +25,4 @@ public class CrossOriginResourceSharingConfig {

return bean;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
package io.chucknorris.api.configuration;

import com.zaxxer.hikari.HikariDataSource;
import javax.sql.DataSource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

@Configuration
@EnableJpaRepositories(basePackages = "io.chucknorris")
@EnableTransactionManagement
@Slf4j
public class DataSourceConfiguration {

@Bean
public DataSource dataSource(DataSourceProperties dataSourceProperties) {
log.info("Loading data source properties from {}", dataSourceProperties.getClass().getSimpleName());
@Bean
public DataSource dataSource(DataSourceProperties dataSourceProperties) {
log.info(
"Loading data source properties from {}", dataSourceProperties.getClass().getSimpleName());

DataSource datasource = DataSourceBuilder.create()
.driverClassName(dataSourceProperties.getDriverClassName())
.password(dataSourceProperties.getPassword())
.type(HikariDataSource.class)
.url(dataSourceProperties.getUrl())
.username(dataSourceProperties.getUsername())
.build();
DataSource datasource =
DataSourceBuilder.create()
.driverClassName(dataSourceProperties.getDriverClassName())
.password(dataSourceProperties.getPassword())
.type(HikariDataSource.class)
.url(dataSourceProperties.getUrl())
.username(dataSourceProperties.getUsername())
.build();

log.info(String.format("DataSource({url=%s})", dataSourceProperties.getUrl()));
log.info(String.format("DataSource({url=%s})", dataSourceProperties.getUrl()));

return datasource;
}
return datasource;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
@Configuration
public abstract class DataSourceProperties {

abstract String getDriverClassName();
abstract String getDriverClassName();

abstract String getPassword();
abstract String getPassword();

abstract String getUrl();
abstract String getUrl();

abstract String getUsername();
abstract String getUsername();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@
@Getter
public class DefaultDataSourceProperties extends DataSourceProperties {

private String driverClassName;
private String password;
private String url;
private String username;
private String driverClassName;
private String password;
private String url;
private String username;

public DefaultDataSourceProperties(
@Value("${spring.datasource.driver-class-name}") String driverClassName,
@Value("${spring.datasource.password}") String password,
@Value("${spring.datasource.url}") String url,
@Value("${spring.datasource.username}") String username
) {
this.driverClassName = driverClassName;
this.password = password;
this.url = url;
this.username = username;
}
public DefaultDataSourceProperties(
@Value("${spring.datasource.driver-class-name}") String driverClassName,
@Value("${spring.datasource.password}") String password,
@Value("${spring.datasource.url}") String url,
@Value("${spring.datasource.username}") String username) {
this.driverClassName = driverClassName;
this.password = password;
this.url = url;
this.username = username;
}
}
Loading

0 comments on commit b6ebac7

Please sign in to comment.