Skip to content

Commit

Permalink
build: Migrate to Spring Boot 3.x and PostgreSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
Griefed committed Dec 8, 2023
1 parent 154ec8f commit e0a2335
Show file tree
Hide file tree
Showing 17 changed files with 111 additions and 64 deletions.
6 changes: 3 additions & 3 deletions .runConfigurations/Debug Fat Jar.run.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Debug Fat Jar" type="JarApplication">
<option name="JAR_PATH" value="$PROJECT_DIR$/serverpackcreator-app/build/libs/serverpackcreator-app-dev.jar" />
<option name="WORKING_DIRECTORY" value="D:\GitLab\ServerPackCreator - MS4" />
<option name="PROGRAM_PARAMETERS" value="-web" />
<option name="WORKING_DIRECTORY" value="F:\GitLab\ServerPackCreator\serverpackcreator-app\tests" />
<option name="ALTERNATIVE_JRE_PATH" />
<module name="ServerPackCreator" />
<method v="2">
<option name="Gradle.BeforeRunTask" enabled="false" tasks="build" externalProjectPath="$PROJECT_DIR$" vmOptions="" scriptParameters="-x test --info --stacktrace" />
<option name="Gradle.BeforeRunTask" enabled="false" tasks="clean cleanAllTests build" externalProjectPath="$PROJECT_DIR$" vmOptions="" scriptParameters=" --info --full-stacktrace -x :serverpackcreator-api:jvmTest -x :serverpackcreator-web:test" />
</method>
</configuration>
</component>
1 change: 0 additions & 1 deletion .runConfigurations/MainSpringBoot.run.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="MainSpringBoot" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
<option name="ACTIVE_PROFILES" />
<module name="serverpackcreator.serverpackcreator-app.main" />
<option name="SPRING_BOOT_MAIN_CLASS" value="de.griefed.serverpackcreator.web.WebService" />
<method v="2">
Expand Down
4 changes: 3 additions & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ FileInputStream(file("../gradle.properties")).use {

dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${props.getProperty("kotlinVersion")}")
implementation("org.springframework.boot:spring-boot-gradle-plugin:2.7.10")
implementation("org.springframework.boot:spring-boot-gradle-plugin:3.2.0")
implementation("io.spring.gradle:dependency-management-plugin:1.1.4")
implementation("org.jetbrains.kotlin:kotlin-allopen:1.9.10")
implementation("org.jetbrains.kotlin.plugin.jpa:org.jetbrains.kotlin.plugin.jpa.gradle.plugin:1.9.21")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.9.10")
implementation("org.panteleyev:jpackage-gradle-plugin:1.5.2")
implementation("com.github.jk1:gradle-license-report:2.5")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.github.jk1.license.render.ReportRenderer
import com.github.jk1.license.util.Files
import org.gradle.api.Project
import java.io.File
import java.net.URI
import java.net.URL

/**
Expand Down Expand Up @@ -140,7 +141,7 @@ class LicenseAgreementRenderer(private val fileName: String = "LICENSE-AGREEMENT
text = append(text,"URL: ${license.url}\n\n")
if (!license.url.isNullOrBlank() && license.url.endsWith(".txt",ignoreCase = true) && Files.maybeLicenseUrl(license.url)) {
try {
text = append(text, URL(license.url).readText() + "\n")
text = append(text, URI(license.url).toURL().readText() + "\n")
} catch (_: Exception) {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ plugins {
// https://kotlinlang.org/docs/reference/compiler-plugins.html#spring-support
kotlin("plugin.spring")
kotlin("plugin.allopen")
kotlin("plugin.jpa")
}

apply(plugin = "org.springframework.boot")
Expand Down
3 changes: 2 additions & 1 deletion serverpackcreator-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ kotlin {
implementation("org.jetbrains.kotlin:kotlin-bom")
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation(files("${layout.buildDirectory.asFile.get()}/resources/"))
api("org.springframework.boot:spring-boot-loader:3.2.0")
api("de.comahe.i18n4k:i18n4k-core-jvm:0.6.2")
api("com.electronwill.night-config:toml:3.6.7")
api("com.fasterxml.jackson.core:jackson-databind:2.15.3")
Expand Down Expand Up @@ -118,4 +119,4 @@ tasks.build {

tasks.withType(PublishToMavenRepository::class) {
dependsOn(tasks.signKotlinMultiplatformPublication,tasks.signJvmPublication)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1182,14 +1182,14 @@ actual class ApiProperties(
}

/**
* Path to the SQLite database used by the webservice-side of ServerPackCreator.
* Path to the PostgreSQL database used by the webservice-side of ServerPackCreator.
*/
@Suppress("MemberVisibilityCanBePrivate")
var jdbcDatabaseUrl: String = "jdbc:sqlite:serverpackcreator.db"
var jdbcDatabaseUrl: String = "jdbc:postgresql://localhost:5432/serverpackcreator"
get() {
var dbPath = internalProps.getProperty(pSpringDatasourceUrl, "").replace("jdbc:sqlite:", "")
var dbPath = internalProps.getProperty(pSpringDatasourceUrl, "")
if (dbPath.isEmpty()) {
dbPath = "jdbc:sqlite:${File(homeDirectory, "serverpackcreator.db").absoluteFile}"
dbPath = "jdbc:postgresql://localhost:5432/serverpackcreator"
}
internalProps.setProperty(pSpringDatasourceUrl, dbPath)
field = dbPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@
package de.griefed.serverpackcreator.api.utilities.common

import net.lingala.zip4j.ZipFile
import org.springframework.boot.loader.jar.NestedJarFile
import java.io.File
import java.net.JarURLConnection
import java.net.URI
import java.net.URL
import java.nio.file.Paths
import java.util.*

private val jar = "^jar:(file:.*[.]jar)!/.*".toRegex()
private val jarJar = "^(file:.*[.]jar)!.*[.]jar".toRegex()
private val jarNested = "^jar:nested:(.*[.]jar)!/.*".toRegex()
private val jarJarNEsted = "^(file:.*[.]jar)!.*[.]jar".toRegex()
private val nested = ".*[.]jar!.*[.]jar".toRegex()
private val tmpDir = System.getProperty("java.io.tmpdir")
private const val JAR_FILE = "jar:file:"
private const val JAR_NESTED = "jar:nested"
private const val JAR = "file:"

/**
Expand All @@ -46,35 +52,24 @@ private const val JAR = "file:"
*/
@Throws(JarAccessException::class)
fun <T : Any> Class<T>.source(
rootOnly: Boolean = false,
tempDir: File = File(tmpDir)
): File {
val clazz = this.simpleName + ".class"
val classResource: URL = this.getResource(clazz) ?: throw JarAccessException("Class resource is null")
val clazz = "$simpleName.class"
val classResource: URL = getResource(clazz) ?: throw JarAccessException("Class resource is null")
val url = classResource.toString()
var source: File? = null
if (url.startsWith(JAR_FILE)) {

var path = url.replace(jar, "$1")
if (rootOnly && path.matches(jarJar)) {
path = path.replace(jarJar, "$1")
}

try {
val uri = URI(path)
source = Paths.get(uri).toFile()
} catch (e: Exception) {
throw JarAccessException("Invalid Jar File URL String")
}

} else if (url.startsWith(JAR)) {
val source: File?
if (url.startsWith(JAR)) {
try {
val uri = URI(url)
val file = Paths.get(uri).toFile()
source = file.parentFile
} catch (e: Exception) {
throw JarAccessException("Invalid Jar File URL String")
throw JarAccessException("Invalid Jar File URL String at JAR: $url")
}
} else {
val jar = (classResource.openConnection() as JarURLConnection).jarFile as NestedJarFile
source = File(jar.name)
}

if (source != null) {
Expand All @@ -95,5 +90,5 @@ fun <T : Any> Class<T>.source(
}
}

throw JarAccessException("Invalid Jar File URL String.")
throw JarAccessException("Invalid Jar File URL String: clazz: $clazz, classResource: $classResource, url: $url")
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ actual class JarUtilities {
fileEnding
)
} else {
JarFile(classToRetrieveHomeFor.source(false, tempDir)).use {
JarFile(classToRetrieveHomeFor.source(tempDir)).use {
// Production
copyFolderFromJar(
it,
Expand Down Expand Up @@ -361,8 +361,8 @@ actual class JarUtilities {
*/
fun jarInformation(classInJar: Class<*>): HashMap<String, String> {
val sysInfo = HashMap<String, String>(10)
sysInfo["jarPath"] = classInJar.source(true).path
sysInfo["jarName"] = classInJar.source(true).name
sysInfo["jarPath"] = classInJar.source().path
sysInfo["jarName"] = classInJar.source().name
sysInfo["javaVersion"] = System.getProperty("java.version")
sysInfo["osArch"] = System.getProperty("os.arch")
sysInfo["osName"] = System.getProperty("os.name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ServerPackCreator(private val args: Array<String>) {
)
}

fun run(mode: Mode = Mode.GUI) {
fun run(mode: Mode) {
log.info("App information:")
log.info("App Folder: ${appInfo.jarFolder}")
log.info("App Path: ${appInfo.jarFile.absolutePath}")
Expand Down
19 changes: 11 additions & 8 deletions serverpackcreator-web/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ dependencies {
api("org.jetbrains.kotlin:kotlin-reflect:1.9.10")
api("org.apache.activemq:artemis-jms-server:2.28.0")
api("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.2")
api("org.springframework.boot:spring-boot-starter-web:2.7.10")
api("org.springframework.boot:spring-boot-starter-log4j2:2.7.10")
api("org.springframework.boot:spring-boot-starter-data-jpa:2.7.10")
api("org.springframework.boot:spring-boot-starter-artemis:2.7.10")
api("com.github.gwenn:sqlite-dialect:0.1.4")
api("org.xerial:sqlite-jdbc:3.43.2.1")
api("org.springframework.boot:spring-boot-starter-web:3.1.0")
api("org.springframework.boot:spring-boot-starter-log4j2:3.0.4")
api("org.springframework.boot:spring-boot-starter-data-jpa:3.0.4")
api("org.springframework.boot:spring-boot-starter-artemis:3.0.4")
api("org.postgresql:postgresql:42.6.0")
//api("org.hibernate.orm:hibernate-community-dialects:6.1.7.Final")
//api("com.github.gwenn:sqlite-dialect:0.1.4")
//api("org.xerial:sqlite-jdbc:3.43.2.1")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.3")
testImplementation("org.springframework.boot:spring-boot-starter-test:2.7.10")
developmentOnly("org.springframework.boot:spring-boot-devtools:2.7.10")
testRuntimeOnly("com.h2database:h2")
testImplementation("org.springframework.boot:spring-boot-starter-test:3.1.0")
developmentOnly("org.springframework.boot:spring-boot-devtools:3.0.4")
}

tasks.clean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ import de.griefed.serverpackcreator.api.versionmeta.VersionMeta
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.env.Environment
import org.springframework.jdbc.datasource.DriverManagerDataSource
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter
import java.io.File
import java.util.*
import javax.sql.DataSource
import javax.xml.parsers.DocumentBuilderFactory


/**
* Bean configuration for running ServerPackCreator as a webservice. This class provides beans for a
* couple or properties which can not otherwise be provided.
Expand Down Expand Up @@ -220,4 +227,39 @@ class BeanConfiguration @Autowired constructor() {
fun documentBuilder(): DocumentBuilderFactory {
return apiWrapper().documentBuilderFactory
}

@Autowired
var env: Environment? = null

/*@Bean
fun dataSource(): DataSource {
val dataSource = DriverManagerDataSource()
env!!.getProperty("spring.datasource.driver-class-name")?.let { dataSource.setDriverClassName(it) }
dataSource.url = env!!.getProperty("spring.datasource.url")
return dataSource
}
@Bean
fun entityManagerFactory(): LocalContainerEntityManagerFactoryBean {
val em = LocalContainerEntityManagerFactoryBean()
em.setDataSource(dataSource())
em.setPackagesToScan(*arrayOf("de.griefed.serverpackcreator.web"))
em.jpaVendorAdapter = HibernateJpaVendorAdapter()
em.setJpaProperties(additionalProperties())
return em
}
fun additionalProperties(): Properties {
val hibernateProperties = Properties()
if (env!!.getProperty("spring.jpa.hibernate.ddl-auto") != null) {
hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env!!.getProperty("spring.jpa.hibernate.ddl-auto"))
}
if (env!!.getProperty("spring.jpa.database-platform") != null) {
hibernateProperties.setProperty("hibernate.dialect", env!!.getProperty("spring.jpa.database-platform"))
}
if (env!!.getProperty("hibernate.show_sql") != null) {
hibernateProperties.setProperty("hibernate.show_sql", env!!.getProperty("hibernate.show_sql"))
}
return hibernateProperties
}*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package de.griefed.serverpackcreator.web

import de.griefed.serverpackcreator.api.ApiWrapper
import org.apache.logging.log4j.kotlin.cachedLoggerOf
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.ConfigurableApplicationContext
Expand All @@ -32,7 +31,7 @@ import java.sql.SQLException

@SpringBootApplication
@EnableScheduling
class WebService @Autowired constructor(private val api: ApiWrapper) {
class WebService(private val api: ApiWrapper) {
private val log = cachedLoggerOf(this.javaClass)
private var springBootApplicationContext: ConfigurableApplicationContext? = null

Expand All @@ -48,7 +47,8 @@ class WebService @Autowired constructor(private val api: ApiWrapper) {
temp[temp.lastIndex] = lastIndex
temp.toList().toTypedArray()
}
checkDatabase()

//checkDatabase()
log.debug("Running webservice with args:${springArgs.contentToString()}")
log.debug("Application name: ${getSpringBootApplicationContext(springArgs).applicationName}")
log.debug("Property sources:")
Expand Down Expand Up @@ -92,7 +92,7 @@ class WebService @Autowired constructor(private val api: ApiWrapper) {
var connection: Connection? = null
try {
connection = DriverManager.getConnection(
"jdbc:sqlite:${api.apiProperties.serverPackCreatorDatabase}"
"jdbc\\:postgresql:${api.apiProperties.serverPackCreatorDatabase}"
)
val databaseMetaData = connection.metaData
log.debug("Database driver name: ${databaseMetaData.driverName}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
package de.griefed.serverpackcreator.web.serverpack

import de.griefed.serverpackcreator.api.PackConfig
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.GeneratedValue
import jakarta.persistence.Id
import org.hibernate.annotations.CreationTimestamp
import org.hibernate.annotations.UpdateTimestamp
import java.sql.Timestamp
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.Id


/**
* Class containing all fields and therefore all information gathered from a submitted CurseForge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
*/
package de.griefed.serverpackcreator.web.zip

import com.google.common.net.HttpHeaders
import de.griefed.serverpackcreator.api.ApiProperties
import de.griefed.serverpackcreator.api.ConfigCheck
import de.griefed.serverpackcreator.api.ConfigurationHandler
import de.griefed.serverpackcreator.api.utilities.common.Utilities
import de.griefed.serverpackcreator.api.utilities.common.deleteQuietly
import de.griefed.serverpackcreator.web.NotificationResponse
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpHeaders
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile
Expand Down
12 changes: 6 additions & 6 deletions serverpackcreator-web/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ spring.output.ansi.enabled=ALWAYS
server.error.include-message=ALWAYS
server.error.include-stacktrace=ALWAYS
spring.application.name=ServerPackCreator
spring.datasource.url=jdbc:sqlite:serverpackcreator.db
spring.datasource.driver-class-name=org.sqlite.JDBC
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.sqlite.hibernate.dialect.SQLiteDialect
spring.jpa.open-in-view=false
spring.jdbc.template.query-timeout=3600
spring.datasource.tomcat.max-active=50
spring.datasource.tomcat.max-idle=15
spring.datasource.tomcat.min-idle=8
spring.transaction.default-timeout=3600
spring.artemis.mode=embedded
spring.artemis.embedded.persistent=true
spring.artemis.embedded.data-directory=work/artemis
spring.datasource.tomcat.max-active=50
spring.datasource.tomcat.max-idle=15
spring.datasource.tomcat.min-idle=8
spring.servlet.multipart.max-file-size=500MB
spring.servlet.multipart.max-request-size=500MB
spring.config.import=classpath:application.properties,classpath:serverpackcreator.properties,optional:file:./serverpackcreator.properties
Loading

0 comments on commit e0a2335

Please sign in to comment.