Skip to content

Commit

Permalink
docs: Add and expand existing docs in the API
Browse files Browse the repository at this point in the history
  • Loading branch information
Griefed committed Jul 18, 2024
1 parent 3081d70 commit 0328871
Show file tree
Hide file tree
Showing 20 changed files with 286 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,66 +28,135 @@ import de.griefed.serverpackcreator.api.utilities.common.concatenate
*/
class ConfigCheck {

/**
* List of errors encountered during the config checks of the configuration.
*/
val configErrors: MutableList<String> = mutableListOf()

/**
* Whether the config checks passed. Only true if all checks passed.
*/
val configChecksPassed: Boolean
get() {
return configErrors.isEmpty()
}

/**
* List of errors encountered during the modpack checks of the configuration.
*/
val modpackErrors: MutableList<String> = mutableListOf()

/***
* Whether the modpack checks passed. Only true if all checks passed.
*/
val modpackChecksPassed: Boolean
get() {
return modpackErrors.isEmpty()
}

/**
* List of errors encountered during the inclusion checks of the configuration.
*/
val inclusionErrors: MutableList<String> = mutableListOf()

/**
* Whether the inclusion checks passed. Only true if all checks passed.
*/
val inclusionsChecksPassed: Boolean
get() {
return inclusionErrors.isEmpty()
}

/**
* List of errors encountered during the Minecraft-version checks of the configuration.
*/
val minecraftVersionErrors: MutableList<String> = mutableListOf()

/**
* Whether the Minecraft-version checks passed. Only true if all checks passed.
*/
val minecraftVersionChecksPassed: Boolean
get() {
return minecraftVersionErrors.isEmpty()
}

/**
* List of errors encountered during the modloader checks of the configuration.
*/
val modloaderErrors: MutableList<String> = mutableListOf()

/**
* Whether the modloader checks passed. Only true if all checks passed.
*/
val modloaderChecksPassed: Boolean
get() {
return modloaderErrors.isEmpty()
}

/**
* List of errors encountered during the modloader-version checks of the configuration.
*/
val modloaderVersionErrors: MutableList<String> = mutableListOf()

/**
* Whether the modloader-version checks passed. Only true if all checks passed.
*/
val modloaderVersionChecksPassed: Boolean
get() {
return modloaderVersionErrors.isEmpty()
}

/**
* List of errors encountered during the server-icon checks of the configuration.
*/
val serverIconErrors: MutableList<String> = mutableListOf()

/**
* Whether the server-icon checks passed. Only true if all checks passed.
*/
val serverIconChecksPassed: Boolean
get() {
return serverIconErrors.isEmpty()
}

/**
* List of errors encountered during the server.properties checks of the configuration.
*/
val serverPropertiesErrors: MutableList<String> = mutableListOf()

/**
* Whether the server.properties checks passed. Only true if all checks passed.
*/
val serverPropertiesChecksPassed: Boolean
get() {
return serverPropertiesErrors.isEmpty()
}

/**
* List of errors encountered in plugin-provided checks of the configuration.
*/
val pluginsErrors: MutableList<String> = mutableListOf()

/**
* Whether all plugin-provided checks passed. Only true if all passed.
*/
val pluginsChecksPassed: Boolean
get() {
return pluginsErrors.isEmpty()
}

/**
* List of errors which didn't fit any of the other categories.
*/
val otherErrors: MutableList<String> = mutableListOf()
val otherChecksPassed: Boolean
get() {
return otherErrors.isEmpty()
}

/**
* List of all errors encountered during the check of this configuration.
*/
val encounteredErrors: MutableList<String>
get() {
return concatenate(
Expand All @@ -103,6 +172,11 @@ class ConfigCheck {
otherErrors
).toMutableList()
}

/**
* Whether all checks were passed for this configuration. Only true if every single check, including those of any
* installed plugins, passed.
*/
val allChecksPassed: Boolean
get() {
return encounteredErrors.isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ConfigurationHandler(
*/
fun checkConfiguration(configFile: File, packConfig: PackConfig = PackConfig(), configCheck: ConfigCheck = ConfigCheck(), quietCheck: Boolean = false): ConfigCheck {
try {
val fileConf = PackConfig(utilities, configFile)
val fileConf = PackConfig(configFile)
packConfig.setClientMods(fileConf.clientMods)
packConfig.setInclusions(fileConf.inclusions)
packConfig.setModsWhitelist(fileConf.modsWhitelist)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,38 @@ class InclusionSpecification(
var exclusionFilter: String? = null
) {

/**
* Whether this inclusion-spec has an Inclusion-Filter present.
*/
fun hasInclusionFilter(): Boolean {
return inclusionFilter != null && inclusionFilter!!.isNotBlank()
}

/**
* Whether this inclusion-spec has an Exclusion-Filter present.
*/
fun hasExclusionFilter(): Boolean {
return exclusionFilter != null && exclusionFilter!!.isNotBlank()
}

/**
* Whether this inclusion-spec has a destination in the server-pack-to-be set.
*/
fun hasDestination(): Boolean {
return !destination.isNullOrBlank()
}

/**
* Whether this inclusion-spec is a global filter to be applied to every inclusion.
* A global filter requires the source to be empty and/or blank and an inclusion- or exclusion-filter to be set.
*/
fun isGlobalFilter(): Boolean {
return (source.isBlank() && hasInclusionFilter()) || (source.isBlank() && hasExclusionFilter())
}

/**
* Get this inclusion-spec as a hashmap.
*/
fun asHashMap(): HashMap<String,String> {
val map = HashMap<String,String>()
map["source"] = source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*/
package de.griefed.serverpackcreator.api.config

/**
* Source-indicator for where the modpack came from. Entries are self-explanatory.
*/
enum class ModpackSource {
ZIP, MODRINTH, CURSEFORGE, DIRECTORY
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import com.electronwill.nightconfig.core.io.WritingMode
import com.electronwill.nightconfig.toml.TomlFormat
import com.fasterxml.jackson.databind.JsonNode
import de.griefed.serverpackcreator.api.ApiProperties
import de.griefed.serverpackcreator.api.ApiWrapper
import de.griefed.serverpackcreator.api.utilities.common.StringUtilities
import de.griefed.serverpackcreator.api.utilities.common.Utilities
import org.apache.logging.log4j.kotlin.cachedLoggerOf
import java.io.File
import java.io.FileNotFoundException
Expand Down Expand Up @@ -314,7 +314,6 @@ open class PackConfig() {
/**
* Create a new configuration model from a config file.
*
* @param utilities Instance of our SPC utilities.
* @param configFile Configuration file to load.
* @throws FileNotFoundException if the specified file can not be found.
* @throws NoFormatFoundException if the configuration format could not be determined by
Expand All @@ -323,7 +322,7 @@ open class PackConfig() {
*/
@Throws(NoFormatFoundException::class, FileNotFoundException::class)
@Suppress("UNCHECKED_CAST")
constructor(utilities: Utilities, configFile: File) : this() {
constructor(configFile: File) : this() {
if (!configFile.exists()) {
throw FileNotFoundException("Couldn't find file: $configFile")
}
Expand Down Expand Up @@ -435,8 +434,11 @@ open class PackConfig() {
config.set<Any>(inclusionsKey, newInclusionsList)
}

/**
* Save this configuration to disk.
*/
@Suppress("DuplicatedCode")
fun save(destination: File, apiProperties: ApiProperties): PackConfig {
fun save(destination: File, apiProperties: ApiProperties = ApiWrapper.api().apiProperties): PackConfig {
val conf = TomlFormat.instance().createConfig()

conf.setComment(configVersionKey, configVersionComment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class FabricScanner(
private val client = "client"
private val environment = "environment"
private val depends = "depends"

val dependencyExclusions: Regex
private val dependencyExclusions: Regex
get() = "(fabric|fabricloader|java|minecraft)".toRegex()

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import java.util.*
import java.util.jar.JarFile

/**
* `mods.toml`-based scanning of Fabric-Minecraft mods for Minecraft 1.16.5 and newer.
* `mods.toml`-based scanning of Forge-Minecraft mods for Minecraft 1.16.5 and newer.
*
* @param tomlParser To parse .toml-files.
* @Griefed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
/* Copyright (C) 2024 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.api.modscanning

import com.electronwill.nightconfig.toml.TomlParser

/**
* `neoforge.mods.toml`-based scanning of NeoForge-Minecraft mods for Minecraft 1.16.5 and newer.
*
* @param tomlParser To parse .toml-files.
* @Griefed
*/
class NeoForgeTomlScanner(tomlParser: TomlParser): ForgeTomlScanner(tomlParser) {
override val modsToml: String
get() = "META-INF/neoforge.mods.toml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,37 @@ import de.griefed.serverpackcreator.api.config.PackConfig
import java.io.File
import java.util.*

/**
* Returned by [de.griefed.serverpackcreator.api.serverpack.ServerPackHandler.run]. Contains information about the
* generated server pack, or the server pack which was attempted to be generated.
*
* @author Griefed
*/
class ServerPackGeneration(
/**
* Whether the generation was successful.
*/
val success: Boolean,

/**
* The generated server pack as a file. This usually points towards a directory on the file-system.
*/
val serverPack: File,

/**
* The server pack ZIP-archive, if one was generated. [Optional] for ease of use, as not every server pack generation
* also creates a ZIP-archive.
*/
val serverPackZip: Optional<File>,

/**
* The configuration used in the generation of this server pack.
*/
val packConfig: PackConfig,

/**
* A list of all files in the server pack. These are absolute files, mind you. If you need relative-files, iterate
* through this list and remove the path to the server pack from each entry to receive a list of relative paths.
*/
val files: List<File>
)
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,7 @@ class ServerPackHandler(
relativeFiles,
packConfig.minecraftVersion,
packConfig.modloader,
packConfig.modloaderVersion,
apiProperties.apiVersion
packConfig.modloaderVersion
)
serverPackManifest.writeToFile(serverPack, utilities.jsonUtilities.objectMapper)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,37 @@
package de.griefed.serverpackcreator.api.serverpack

import com.fasterxml.jackson.databind.ObjectMapper
import de.griefed.serverpackcreator.api.ApiWrapper
import java.io.File

/**
* The server pack manifest shipped with every modpack. It includes information about the
* * Minecraft version
* * Modloader
* * Modloader version
* * ServerPackCreator version used in the generation of this server pack
* * A list of relative files included in a server pack
*
* @author Griefed
*/
@Suppress("unused")
class ServerPackManifest {
var files: List<String> = ArrayList(10000)
var minecraftVersion: String = ""
var modloader: String = ""
var modloaderVersion: String = ""
var serverPackCreatorVersion: String = ""
val serverPackCreatorVersion: String = ApiWrapper.api().apiProperties.apiVersion

constructor(
files: List<String>,
minecraftVersion: String,
modloader: String,
modloaderVersion: String,
serverPackCreatorVersion: String
) {
this.files = files
this.minecraftVersion = minecraftVersion
this.modloader = modloader
this.modloaderVersion = modloaderVersion
this.serverPackCreatorVersion = serverPackCreatorVersion
}

constructor()
Expand Down
Loading

0 comments on commit 0328871

Please sign in to comment.