Skip to content

Commit

Permalink
Sync at end, call GC, start event log
Browse files Browse the repository at this point in the history
  • Loading branch information
Griefed committed Dec 24, 2023
1 parent cf20b8a commit 7f0c78f
Show file tree
Hide file tree
Showing 24 changed files with 531 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/* Copyright (C) 2023 Griefed
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
* The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE
*/
package de.griefed.serverpackcreator.web.customizing

import org.springframework.data.jpa.repository.JpaRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package de.griefed.serverpackcreator.web.customizing

import de.griefed.serverpackcreator.web.data.ClientMod
import de.griefed.serverpackcreator.web.data.RunConfiguration
import de.griefed.serverpackcreator.web.data.StartArgument
import de.griefed.serverpackcreator.web.data.WhitelistedMod
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
Expand All @@ -29,11 +30,11 @@ import java.util.*
@Repository
interface RunConfigurationRepository : JpaRepository<RunConfiguration, Int> {
// lol, dat method name
fun findByMinecraftVersionAndModloaderAndModloaderVersionAndStartArgsAndClientModsInAndWhitelistedModsIn(
fun findByMinecraftVersionAndModloaderAndModloaderVersionAndStartArgsInAndClientModsInAndWhitelistedModsIn(
minecraftVersion: String,
modloader: String,
modloaderVersion: String,
startArgs: String,
startArgs: Collection<StartArgument>,
clientMods: Collection<ClientMod>,
whitelistedMods: Collection<WhitelistedMod>
): Optional<RunConfiguration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package de.griefed.serverpackcreator.web.customizing
import de.griefed.serverpackcreator.api.ApiProperties
import de.griefed.serverpackcreator.web.data.ClientMod
import de.griefed.serverpackcreator.web.data.RunConfiguration
import de.griefed.serverpackcreator.web.data.StartArgument
import de.griefed.serverpackcreator.web.data.WhitelistedMod
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
Expand All @@ -32,8 +33,13 @@ class RunConfigurationService @Autowired constructor(
private val runConfigurationRepository: RunConfigurationRepository,
private val apiProperties: ApiProperties,
private val clientModRepository: ClientModRepository,
private val whitelistedModRepository: WhitelistedModRepository
private val whitelistedModRepository: WhitelistedModRepository,
private val startArgumentRepository: StartArgumentRepository
) {
private val spaces : Regex = "\\s+".toRegex()
private val commaSpace: String = ", "
private val comma: String = ","
private val space: String = " "

fun createRunConfig(
minecraftVersion: String,
Expand All @@ -47,12 +53,24 @@ class RunConfigurationService @Autowired constructor(
config.minecraftVersion = minecraftVersion
config.modloader = modloader
config.modloaderVersion = modloaderVersion
config.startArgs = startArgs
if (config.startArgs.isBlank()) {
config.startArgs = apiProperties.aikarsFlags

if (startArgs.isNotBlank()) {
for (argument in startArgs.replace(spaces, space).split(space)) {
config.startArgs.add(StartArgument(argument))
}
} else {
config.startArgs.addAll(apiProperties.aikarsFlags.replace(spaces, space).split(space).map { StartArgument(it) })
}
for (i in 0 until config.startArgs.size) {
if (startArgumentRepository.findByArgument(config.startArgs[i].argument).isPresent) {
config.startArgs[i] = startArgumentRepository.findByArgument(config.startArgs[i].argument).get()
} else {
config.startArgs[i] = startArgumentRepository.save(config.startArgs[i])
}
}

if (clientMods.isNotBlank()) {
for (mod in clientMods.replace(", ", ",").split(",")) {
for (mod in clientMods.replace(commaSpace, comma).split(comma)) {
config.clientMods.add(ClientMod(mod))
}
} else {
Expand All @@ -65,8 +83,9 @@ class RunConfigurationService @Autowired constructor(
config.clientMods[i] = clientModRepository.save(config.clientMods[i])
}
}

if (whitelistedMods.isNotBlank()) {
for (mod in whitelistedMods.replace(", ", ",").split(",")) {
for (mod in whitelistedMods.replace(commaSpace, comma).split(comma)) {
config.whitelistedMods.add(WhitelistedMod(mod))
}
} else {
Expand All @@ -80,12 +99,13 @@ class RunConfigurationService @Autowired constructor(
config.whitelistedMods[i] = whitelistedModRepository.save(config.whitelistedMods[i])
}
}

return save(config)
}

fun save(runConfiguration: RunConfiguration): RunConfiguration {
val fromRepo =
runConfigurationRepository.findByMinecraftVersionAndModloaderAndModloaderVersionAndStartArgsAndClientModsInAndWhitelistedModsIn(
runConfigurationRepository.findByMinecraftVersionAndModloaderAndModloaderVersionAndStartArgsInAndClientModsInAndWhitelistedModsIn(
minecraftVersion = runConfiguration.minecraftVersion,
modloader = runConfiguration.modloader,
modloaderVersion = runConfiguration.modloaderVersion,
Expand All @@ -104,7 +124,7 @@ class RunConfigurationService @Autowired constructor(
minecraftVersion: String,
modloader: String,
modloaderVersion: String,
startArgs: String,
startArgs: MutableList<StartArgument>,
clientMods: MutableList<ClientMod>,
whitelistedMods: MutableList<WhitelistedMod>
): RunConfiguration {
Expand All @@ -126,11 +146,11 @@ class RunConfigurationService @Autowired constructor(
minecraftVersion: String,
modloader: String,
modloaderVersion: String,
startArgs: String,
startArgs: MutableList<StartArgument>,
clientMods: MutableList<ClientMod>,
whitelistedMods: MutableList<WhitelistedMod>
): Optional<RunConfiguration> {
return runConfigurationRepository.findByMinecraftVersionAndModloaderAndModloaderVersionAndStartArgsAndClientModsInAndWhitelistedModsIn(
return runConfigurationRepository.findByMinecraftVersionAndModloaderAndModloaderVersionAndStartArgsInAndClientModsInAndWhitelistedModsIn(
minecraftVersion = minecraftVersion,
modloader = modloader,
modloaderVersion = modloaderVersion,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright (C) 2023 Griefed
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
* The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE
*/
package de.griefed.serverpackcreator.web.customizing

import de.griefed.serverpackcreator.web.data.StartArgument
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
import java.util.*

@Repository
interface StartArgumentRepository : JpaRepository<StartArgument, Int> {
fun findByArgument(argument: String): Optional<StartArgument>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* Copyright (C) 2023 Griefed
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
* The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE
*/
package de.griefed.serverpackcreator.web.data

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.GeneratedValue
import jakarta.persistence.Id

@Entity
class ErrorEntry {

@Id
@GeneratedValue
@Column(updatable = false, nullable = false)
var id: Int = 0

@Column
var error: String

constructor(error: String) {
this.error = error
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as ErrorEntry

return error == other.error
}

override fun hashCode(): Int {
return error.hashCode()
}

override fun toString(): String {
return "ErrorEntry(id=$id, error='$error')"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ModPack {
var name: String = ""//TODO set from archive, or mainfest in ZIP, or Modrinth Project name & version name

@Column
var size: Double = 0.0
var size: Int = 0

@Column
var status: ModpackStatus = ModpackStatus.QUEUED
Expand All @@ -59,10 +59,35 @@ class ModPack {
var fileID: Long? = null

@Column
var fileHash: String? = null
var sha256: String? = null

@OneToMany(fetch = FetchType.EAGER)
var serverPacks: MutableList<ServerPack> = mutableListOf()
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

//TODO equals, hash, toString
other as ModPack

if (projectID != other.projectID) return false
if (versionID != other.versionID) return false
if (name != other.name) return false
if (source != other.source) return false
if (sha256 != other.sha256) return false

return true
}

override fun hashCode(): Int {
var result = projectID.hashCode()
result = 31 * result + versionID.hashCode()
result = 31 * result + name.hashCode()
result = 31 * result + source.hashCode()
result = 31 * result + (sha256?.hashCode() ?: 0)
return result
}

override fun toString(): String {
return "ModPack(id=$id, projectID='$projectID', versionID='$versionID', dateCreated=$dateCreated, name='$name', size=$size, status=$status, source=$source, fileID=$fileID, sha256=$sha256, serverPacks=$serverPacks)"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ interface ModPackView {
var size: Double
var status: ModpackStatus
var source: ModpackSource
var fileHash: String
var sha256: String
var serverPacks: MutableList<ServerPack>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* Copyright (C) 2023 Griefed
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
* The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE
*/
package de.griefed.serverpackcreator.web.data

import de.griefed.serverpackcreator.web.modpack.ModpackStatus
import jakarta.persistence.*
import org.hibernate.annotations.CreationTimestamp
import java.sql.Timestamp

@Entity
class QueueEvent {

@Id
@GeneratedValue
@Column(updatable = false, nullable = false)
var id: Int = 0

@Column
var modPackId: Int = 0

@Column
var serverPackId: Int? = null

@Column
var status: ModpackStatus? = null

@Column
var message: String = ""

@CreationTimestamp
@Column
var timestamp: Timestamp? = null

@ManyToMany
var errors: MutableList<ErrorEntry> = mutableListOf()
}
Loading

0 comments on commit 7f0c78f

Please sign in to comment.