Skip to content

Commit 9e59f9e

Browse files
authored
Merge pull request #33 from FredPraca/feat/refactor-application-properties
Feat/refactor application properties
2 parents 9035884 + 20711a0 commit 9e59f9e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+590
-429
lines changed

build.gradle

Lines changed: 110 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,70 @@
11
plugins {
2-
3-
id "org.springframework.boot" version "3.5.4"
4-
id "io.spring.dependency-management" version "1.1.7"
5-
id "java-library"
6-
id "maven-publish"
7-
id "com.diffplug.spotless" version "7.2.1"
2+
id "org.springframework.boot" version "3.5.4"
3+
id "io.spring.dependency-management" version "1.1.7"
4+
id "java-library"
5+
id "maven-publish"
6+
id "com.diffplug.spotless" version "7.2.1"
87
}
98

109
repositories {
11-
mavenLocal()
12-
maven {
13-
url = uri("https://repo.maven.apache.org/maven2/")
14-
}
15-
16-
maven {
17-
url = uri("https://repo.e-iceblue.com/nexus/content/groups/public/")
18-
content {
19-
includeGroup "e-iceblue"
20-
}
21-
}
10+
maven {
11+
url = uri("https://repo.maven.apache.org/maven2/")
12+
}
13+
14+
maven {
15+
url = uri("https://repo.e-iceblue.com/nexus/content/groups/public/")
16+
content {
17+
includeGroup "e-iceblue"
18+
}
19+
}
20+
mavenLocal()
2221
}
2322

2423
dependencyManagement {
25-
imports {
26-
mavenBom 'org.springframework.modulith:spring-modulith-bom:1.4.2'
27-
}
24+
imports {
25+
mavenBom 'org.springframework.modulith:spring-modulith-bom:1.4.2'
26+
}
2827
}
2928

3029

3130
dependencies {
3231

33-
testImplementation platform("org.junit:junit-bom:${junit_ver}")
34-
testImplementation "org.junit.jupiter:junit-jupiter"
35-
testImplementation "org.springframework.modulith:spring-modulith-starter-test"
36-
testImplementation "org.springframework.boot:spring-boot-starter-test"
37-
testCompileOnly "org.projectlombok:lombok:${lombok_ver}"
38-
testAnnotationProcessor "org.projectlombok:lombok:${lombok_ver}"
39-
40-
41-
implementation "org.springframework.modulith:spring-modulith-starter-core"
42-
implementation "org.springframework.modulith:spring-modulith-events-api"
43-
implementation "org.springframework:spring-tx"
44-
implementation "org.springframework.boot:spring-boot-starter-web"
45-
implementation api("e-iceblue:spire.office.free:${iceblue_ver}@pom") {
46-
transitive = true
47-
}
48-
implementation "org.apache.poi:poi:${apachepoi_ver}"
49-
implementation "org.apache.poi:poi-scratchpad:${apachepoi_ver}"
50-
implementation "commons-io:commons-io:${commonsio_ver}"
51-
implementation "org.slf4j:slf4j-api:${slf4j_ver}"
52-
implementation "org.jodconverter:jodconverter-local:${jod_ver}"
53-
implementation "org.bytedeco:javacv:${javacv_ver}"
54-
implementation "org.bytedeco:opencv:${opencv_ver}"
55-
implementation "net.coobird:thumbnailator:${thumb_ver}"
56-
implementation "com.mpatric:mp3agic:${mp3agic_ver}"
57-
implementation "org.bytedeco.javacpp-presets:opencv-platform:${opencvplat_ver}"
58-
implementation "commons-cli:commons-cli:${commonscli_ver}"
59-
implementation "org.apache.tika:tika-core:${tika_ver}"
60-
implementation "org.springframework.boot:spring-boot-starter"
61-
implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:${springdoc_ver}"
62-
implementation ("org.apache.pdfbox:pdfbox:${pdfbox_ver}") {
63-
exclude group: "commons-logging", module: "commons-logging"
64-
}
65-
66-
compileOnly "org.projectlombok:lombok:${lombok_ver}"
67-
annotationProcessor "org.projectlombok:lombok:${lombok_ver}"
32+
testImplementation platform("org.junit:junit-bom:${junit_ver}")
33+
testImplementation "org.junit.jupiter:junit-jupiter"
34+
testImplementation "org.springframework.modulith:spring-modulith-starter-test"
35+
testImplementation "org.springframework.boot:spring-boot-starter-test"
36+
testCompileOnly "org.projectlombok:lombok:${lombok_ver}"
37+
testAnnotationProcessor "org.projectlombok:lombok:${lombok_ver}"
38+
39+
implementation "org.springframework.modulith:spring-modulith-starter-core"
40+
implementation "org.springframework.modulith:spring-modulith-events-api"
41+
implementation "org.springframework:spring-tx"
42+
implementation "org.springframework.boot:spring-boot-starter-web"
43+
implementation api("e-iceblue:spire.office.free:${iceblue_ver}@pom") {
44+
transitive = true
45+
}
46+
implementation "org.springframework.boot:spring-boot-starter-validation"
47+
implementation "org.apache.poi:poi:${apachepoi_ver}"
48+
implementation "org.apache.poi:poi-scratchpad:${apachepoi_ver}"
49+
implementation "commons-io:commons-io:${commonsio_ver}"
50+
implementation "org.slf4j:slf4j-api:${slf4j_ver}"
51+
implementation "org.jodconverter:jodconverter-local:${jod_ver}"
52+
implementation "org.bytedeco:javacv:${javacv_ver}"
53+
implementation "org.bytedeco:opencv:${opencv_ver}"
54+
implementation "net.coobird:thumbnailator:${thumb_ver}"
55+
implementation "com.mpatric:mp3agic:${mp3agic_ver}"
56+
implementation "org.bytedeco.javacpp-presets:opencv-platform:${opencvplat_ver}"
57+
implementation "commons-cli:commons-cli:${commonscli_ver}"
58+
implementation "org.apache.tika:tika-core:${tika_ver}"
59+
implementation "org.springframework.boot:spring-boot-starter"
60+
implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:${springdoc_ver}"
61+
implementation ("org.apache.pdfbox:pdfbox:${pdfbox_ver}") {
62+
exclude group: "commons-logging", module: "commons-logging"
63+
}
64+
65+
compileOnly "org.projectlombok:lombok:${lombok_ver}"
66+
annotationProcessor "org.projectlombok:lombok:${lombok_ver}"
67+
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
6868
}
6969

7070
group = 'io.github.makbn'
@@ -73,31 +73,31 @@ description = 'JThumbnail is a Java library for creating Thumbnails of common ty
7373
java.sourceCompatibility = JavaVersion.VERSION_21
7474

7575
java {
76-
toolchain {
77-
languageVersion = JavaLanguageVersion.of(21)
78-
}
76+
toolchain {
77+
languageVersion = JavaLanguageVersion.of(21)
78+
}
7979
}
8080
publishing {
81-
publications {
82-
mavenJava(MavenPublication) {
83-
from components.java
84-
85-
groupId = 'io.github.makbn'
86-
artifactId = 'jthumbnail'
87-
version = '2.2.1'
88-
}
89-
}
90-
91-
repositories {
92-
maven {
93-
name = "GitHubPackages"
94-
url = "https://maven.pkg.github.com/makbn/jthumbnail"
95-
credentials {
96-
username = System.getenv("GITHUB_ACTOR")
97-
password = System.getenv("GITHUB_TOKEN")
98-
}
99-
}
100-
}
81+
publications {
82+
mavenJava(MavenPublication) {
83+
from components.java
84+
85+
groupId = 'io.github.makbn'
86+
artifactId = 'jthumbnail'
87+
version = '2.2.1'
88+
}
89+
}
90+
91+
repositories {
92+
maven {
93+
name = "GitHubPackages"
94+
url = "https://maven.pkg.github.com/makbn/jthumbnail"
95+
credentials {
96+
username = System.getenv("GITHUB_ACTOR")
97+
password = System.getenv("GITHUB_TOKEN")
98+
}
99+
}
100+
}
101101
}
102102

103103
jar {
@@ -106,41 +106,41 @@ archiveClassifier = '' //use empty string
106106
}
107107

108108
test {
109-
useJUnitPlatform()
110-
testLogging {
111-
events "passed", "skipped", "failed"
112-
}
109+
useJUnitPlatform()
110+
testLogging {
111+
events "passed", "skipped", "failed"
112+
}
113113

114-
maxHeapSize = '1G'
114+
maxHeapSize = '1G'
115115
}
116116

117117
spotless {
118118

119-
format 'misc', {
120-
// define the files to apply `misc` to
121-
target '*.gradle', '.gitattributes', '.gitignore'
122-
123-
// define the steps to apply to those files
124-
trimTrailingWhitespace()
125-
leadingSpacesToTabs() // or leadingTabsToSpaces. Takes an integer argument if you don't like 4
126-
endWithNewline()
127-
}
128-
129-
java {
130-
// clean and format imports
131-
removeUnusedImports()
132-
removeWildcardImports()
133-
importOrder()
134-
135-
// fix formatting of type annotations
136-
formatAnnotations()
137-
138-
// Format sources and javadocs according to Palantir formatter
139-
palantirJavaFormat()
140-
141-
// make sure every file has the following copyright header.
142-
// optionally, Spotless can set copyright years by digging
143-
// through git history (see "license" section below)
144-
// licenseHeader '/* (C)$YEAR */'
145-
}
119+
format 'misc', {
120+
// define the files to apply `misc` to
121+
target '*.gradle', '.gitattributes', '.gitignore'
122+
123+
// define the steps to apply to those files
124+
trimTrailingWhitespace()
125+
leadingTabsToSpaces() // or leadingTabsToSpaces. Takes an integer argument if you don't like 4
126+
endWithNewline()
127+
}
128+
129+
java {
130+
// clean and format imports
131+
removeUnusedImports()
132+
removeWildcardImports()
133+
importOrder()
134+
135+
// fix formatting of type annotations
136+
formatAnnotations()
137+
138+
// Format sources and javadocs according to Palantir formatter
139+
palantirJavaFormat()
140+
141+
// make sure every file has the following copyright header.
142+
// optionally, Spotless can set copyright years by digging
143+
// through git history (see "license" section below)
144+
// licenseHeader '/* (C)$YEAR */'
145+
}
146146
}

src/main/java/io/github/makbn/jthumbnail/JThumbnailerStarter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import org.springframework.boot.Banner;
66
import org.springframework.boot.SpringApplication;
77
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
89
import org.springframework.context.ConfigurableApplicationContext;
910

1011
@SpringBootApplication
12+
@ConfigurationPropertiesScan
1113
public class JThumbnailerStarter {
1214
private static JThumbnailer mInstance;
1315

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
package io.github.makbn.jthumbnail.api;
22

3+
import io.github.makbn.jthumbnail.core.properties.OpenAPIProperties;
34
import io.swagger.v3.oas.models.Components;
45
import io.swagger.v3.oas.models.OpenAPI;
56
import io.swagger.v3.oas.models.info.Info;
67
import io.swagger.v3.oas.models.info.License;
7-
import org.springframework.beans.factory.annotation.Value;
8+
import lombok.RequiredArgsConstructor;
89
import org.springframework.context.annotation.Bean;
910
import org.springframework.context.annotation.Configuration;
1011

12+
@RequiredArgsConstructor
1113
@Configuration
1214
public class OpenAPIDocumentConfiguration {
15+
1316
@Bean
14-
public OpenAPI customOpenAPI(
15-
@Value("${jthumbnailer.name}") String title, @Value("${jthumbnailer.desc}") String desc) {
17+
OpenAPI customOpenAPI(OpenAPIProperties apiProperties) {
1618
return new OpenAPI()
1719
.components(new Components())
1820
.info(new Info()
19-
.summary(desc)
20-
.title(title)
21+
.summary(apiProperties.desc())
22+
.title(apiProperties.name())
2123
.license(new License()
22-
.name("GPL-2.0")
23-
.url("https://github.com/makbn/JThumbnail/blob/master/LICENSE")));
24+
.name(apiProperties.license())
25+
.url(apiProperties.licenseURL().toString())));
2426
}
2527
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
@org.springframework.modulith.ApplicationModule(allowedDependencies = {"core", "core::config", "core::model"})
1+
@org.springframework.modulith.ApplicationModule(
2+
allowedDependencies = {"core", "core::config", "core::model", "core::properties"})
23
package io.github.makbn.jthumbnail.api;

src/main/java/io/github/makbn/jthumbnail/api/service/ThumbnailService.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,9 @@
22

33
import io.github.makbn.jthumbnail.api.model.Thumbnail;
44
import io.github.makbn.jthumbnail.core.JThumbnailer;
5-
import io.github.makbn.jthumbnail.core.config.AppSettings;
5+
import io.github.makbn.jthumbnail.core.config.ThumbnailServerConfiguration;
66
import io.github.makbn.jthumbnail.core.model.ThumbnailCandidate;
77
import io.github.makbn.jthumbnail.core.model.ThumbnailEvent;
8-
import lombok.AccessLevel;
9-
import lombok.NonNull;
10-
import lombok.experimental.FieldDefaults;
11-
import lombok.extern.log4j.Log4j2;
12-
import org.springframework.context.event.EventListener;
13-
import org.springframework.stereotype.Service;
14-
import org.springframework.web.multipart.MultipartFile;
15-
168
import java.io.File;
179
import java.io.IOException;
1810
import java.nio.file.Files;
@@ -22,22 +14,30 @@
2214
import java.util.UUID;
2315
import java.util.concurrent.CompletableFuture;
2416
import java.util.concurrent.ExecutionException;
25-
17+
import lombok.AccessLevel;
18+
import lombok.NonNull;
19+
import lombok.experimental.FieldDefaults;
20+
import lombok.extern.log4j.Log4j2;
21+
import org.springframework.context.event.EventListener;
22+
import org.springframework.stereotype.Service;
23+
import org.springframework.web.multipart.MultipartFile;
2624

2725
@Log4j2
2826
@Service
2927
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
3028
public class ThumbnailService {
3129
JThumbnailer thumbnailer;
32-
AppSettings settings;
30+
31+
private final ThumbnailServerConfiguration thumbnailServerConfiguration;
32+
3333
// can be replaced with LoadingCache to prevent OOM
3434
Map<String, CompletableFuture<Thumbnail>> waitingMap;
3535
// can be replaced with LoadingCache to prevent OOM
3636
Map<String, File> temporaryFilesMap;
3737

38-
public ThumbnailService(JThumbnailer thumbnailer, AppSettings settings) {
38+
public ThumbnailService(JThumbnailer thumbnailer, ThumbnailServerConfiguration settings) {
3939
this.thumbnailer = thumbnailer;
40-
this.settings = settings;
40+
this.thumbnailServerConfiguration = settings;
4141
this.waitingMap = new HashMap<>();
4242
this.temporaryFilesMap = new HashMap<>();
4343
}
@@ -141,7 +141,7 @@ private void removeTemporaryUploadedFile(@NonNull String uid) {
141141
*/
142142
private File createTempFile(@NonNull MultipartFile multipartFile) throws IOException {
143143
File tempFile = Files.createTempFile(
144-
settings.getUploadDirectory().toPath(),
144+
thumbnailServerConfiguration.getUploadDirectory().toPath(),
145145
UUID.randomUUID().toString(),
146146
multipartFile.getOriginalFilename())
147147
.toFile();

0 commit comments

Comments
 (0)