Compare commits

...

5 Commits

Author SHA1 Message Date
renovate[bot] d606b25ea9
fix(deps): update dependency org.jsoup:jsoup to v1.20.1 2025-05-13 06:58:37 +00:00
usbharu 0583909749
Merge pull request #710 from usbharu/fix/message-source
fix: 言語ファイルが読み込めない問題を修正
2025-05-13 15:56:42 +09:00
usbharu e95c5078a3 style: fix lint (CI) 2025-05-13 06:52:32 +00:00
usbharu 8b4167d847
fix: 言語ファイルが読み込めない問題を修正
MessageSourceが正常に構成されず、言語ファイルが読み込めずに表示される問題を修正
2025-05-13 15:45:43 +09:00
usbharu 98385c6b82
Revert "wip"
This reverts commit e28b8f0d6c.
2025-05-13 14:54:40 +09:00
6 changed files with 66 additions and 48 deletions

View File

@ -57,29 +57,8 @@ subprojects {
kotlin {
jvmToolchain(21)
}
}
val mergeChildResources by tasks.registering(Copy::class) {
// 各子プロジェクトの resources を処理後に取得
dependsOn(subprojects.map { it.tasks.named("processResources") })
subprojects.forEach { sub ->
// 各サブプロジェクトの 'bootBuildInfo' タスクを待機するように設定
dependsOn(sub.tasks.named("bootBuildInfo"))
// サブプロジェクトの 'resources/main' をマージ
from(sub.layout.buildDirectory.dir("resources/main"))
}
into(layout.buildDirectory.dir("resources/main"))
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
tasks.named<ProcessResources>("processResources") {
dependsOn(mergeChildResources)
}
tasks {
register("run") {
dependsOn(gradle.includedBuild("hideout-core").task(":run"))
@ -104,7 +83,7 @@ tasks {
}
named<BootJar>("bootJar") {
layered {
enabled = false
enabled.set(false)
}
}
}

View File

@ -21,7 +21,6 @@ import com.github.jk1.license.importer.XmlReportImporter
import com.github.jk1.license.render.*
import kotlinx.kover.gradle.plugin.dsl.CoverageUnit
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.springframework.boot.gradle.tasks.bundling.BootJar
plugins {
alias(libs.plugins.kotlin.jvm)
@ -139,18 +138,8 @@ tasks {
).toMutableList()
}
}
named<BootJar>("bootJar") {
layered {
// enabled.set(false)
}
}
}
springBoot {
buildInfo()
}
kover {

View File

@ -16,27 +16,17 @@
package dev.usbharu.hideout.core.config
import org.springframework.boot.autoconfigure.context.MessageSourceProperties
import org.springframework.boot.context.properties.ConfigurationProperties
import dev.usbharu.hideout.core.infrastructure.springframework.MergedPropertiesMessageSource
import org.springframework.context.MessageSource
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Profile
import org.springframework.context.support.ReloadableResourceBundleMessageSource
@Configuration
@Profile("dev")
class MessageSourceConfig {
@Bean
fun messageSource(messageSourceProperties: MessageSourceProperties): MessageSource {
val reloadableResourceBundleMessageSource = ReloadableResourceBundleMessageSource()
reloadableResourceBundleMessageSource.setBasename("classpath:" + messageSourceProperties.basename)
reloadableResourceBundleMessageSource.setCacheSeconds(0)
return reloadableResourceBundleMessageSource
fun messageSource(): MessageSource {
return MergedPropertiesMessageSource()
}
@Bean
@Profile("dev")
@ConfigurationProperties(prefix = "spring.messages")
fun messageSourceProperties(): MessageSourceProperties = MessageSourceProperties()
}

View File

@ -0,0 +1,60 @@
package dev.usbharu.hideout.core.infrastructure.springframework
import org.springframework.context.support.AbstractMessageSource
import org.springframework.core.io.support.PathMatchingResourcePatternResolver
import java.io.InputStreamReader
import java.nio.charset.StandardCharsets
import java.text.MessageFormat
import java.util.*
import java.util.concurrent.ConcurrentHashMap
class MergedPropertiesMessageSource : AbstractMessageSource() {
private val messages: MutableMap<Locale, Properties> = ConcurrentHashMap()
init {
loadAllLocaleProperties("classpath*:/messages/hideout-web-messages*.properties")
}
private fun loadAllLocaleProperties(locationPattern: String) {
val resolver = PathMatchingResourcePatternResolver()
val resources = resolver.getResources(locationPattern)
for (resource in resources) {
val filename = resource.filename ?: continue
val localeSuffix = filename
.removePrefix("hideout-web-messages")
.removeSuffix(".properties")
.takeIf { it.isNotBlank() }
?: "default"
val locale = if (localeSuffix == "default") {
Locale.ROOT
} else {
Locale.forLanguageTag(localeSuffix.replace('_', '-'))
}
val props = messages.getOrPut(locale) { Properties() }
resource.inputStream.use { stream ->
InputStreamReader(stream, StandardCharsets.UTF_8).use { reader ->
val newProps = Properties()
newProps.load(reader)
props.putAll(newProps) // 上書きあり
}
}
}
}
override fun resolveCode(code: String, locale: Locale): MessageFormat? {
val props = messages[locale] ?: messages[Locale.ROOT] ?: return null
val msg = props.getProperty(code) ?: return null
return MessageFormat(msg, locale)
}
override fun resolveCodeWithoutArguments(code: String, locale: Locale): String? {
val props = messages[locale] ?: messages[Locale.ROOT] ?: return null
return props.getProperty(code)
}
}

View File

@ -17,7 +17,7 @@
<configuration>
<property name="LOG_FILE" value="logs/logFile.log"/>
<property name="CONSOLE_LOG_THRESHOLD" value="${CONSOLE_LOG_THRESHOLD:-TRACE}"/>
<property name="CONSOLE_LOG_THRESHOLD" value="${CONSOLE_LOG_THRESHOLD:-INFO}"/>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<include resource="org/springframework/boot/logging/logback/file-appender.xml"/>

View File

@ -67,7 +67,7 @@ blurhash = { module = "io.trbl:blurhash", version = "1.0.0" }
aws-s3 = { module = "software.amazon.awssdk:s3", version = "2.27.22" }
jsoup = { module = "org.jsoup:jsoup", version = "1.18.3" }
jsoup = { module = "org.jsoup:jsoup", version = "1.20.1" }
owasp-java-html-sanitizer = { module = "com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer", version = "20240325.1" }