Class ApiProperties

  • All Implemented Interfaces:

    @Plugin(name = "ServerPackCreatorConfigFactory", category = "Core") 
    public final class ApiProperties
    extends ConfigurationFactory
                        

    Base settings of ServerPackCreator, such as working directories, default list of clientside-only mods, default list of directories to include in a server pack, script templates, java paths and much more.

    Author:

    Griefed

    • Constructor Detail

      • ApiProperties

        ApiProperties(File propertiesFile)
        Parameters:
        propertiesFile - serverpackcreator.properties-file containing settings and configurations to load the API with.
    • Method Detail

      • getHome

         final File getHome()

        Default home-directory for ServerPackCreator. The directory containing the ServerPackCreator JAR.

      • getGenerationConfig

         final GenerationConfig getGenerationConfig()

        Settings-group for server pack generation: mod-lists, directory in-/exclusions, cleanup-files, ZIP-exclusions, exclusion-filter, generation-flags and Aikar's flags. Prefer accessing these values through this group; the individual properties on ApiProperties remain as facade.

      • getNetworkConfig

         final NetworkConfig getNetworkConfig()

        Settings-group for the timeouts applied to every outbound HTTP call. Prefer accessing these values through this group; the individual properties on ApiProperties remain as facade.

        Declared here because it depends on nothing but store — and note that nothing in ApiProperties itself reads it, so the declaration-order landmine (Kotlin initialises properties in declaration order) does not bite: the only consumer is WebUtilities, which reads it per call, long after construction.

      • getFallbackUpdateURL

         final String getFallbackUpdateURL()

        Shipped default for the update-check URL, used when no property overrides it.

        Every fallback* member below is the same idea: the value SPC falls back on when the corresponding property is unset or invalid, delegated to whichever settings group owns it. They exist so a broken or missing serverpackcreator.properties still yields a working configuration rather than an error.

      • getI18n4kConfig

         final I18n4kConfigDefault getI18n4kConfig()

        i18n4k's mutable configuration, held here because the locale setting is applied through it.

      • getUpdateConfig

         final UpdateConfig getUpdateConfig()

        Settings-group for update- and release-tracking. Prefer accessing these values through this group; the individual properties on ApiProperties remain as facade.

      • getI18nConfig

         final I18nConfig getI18nConfig()

        Settings-group for ServerPackCreators language. Prefer accessing these values through this group; the individual properties on ApiProperties remain as facade.

      • getLoggingConfig

         final LoggingConfig getLoggingConfig()

        Settings-group for ServerPackCreators log-level. The log4j-XML machinery stays with ApiProperties, which acts as log4j's ConfigurationFactory.

      • getApiVersion

         final String getApiVersion()

        This build's version from the jar manifest, or dev when running from a source build.

      • getDevBuild

         final Boolean getDevBuild()

        Whether this is a source build. Widely consequential, not cosmetic: it turns on DEBUG logging, rewrites log4j2.xml on every start, and makes the home directory fall back to the working directory.

      • getConfigVersion

         final String getConfigVersion()

        Config-format version stamped into generated .conf files, so migrations know what they are reading.

      • getFirstRun

         final Boolean getFirstRun()

        Only the first call to this property will return true if this is the first time ServerPackCreator is being run on a given host. Any subsequent call will return false. Handle with care!

      • getLogLevel

         final String getLogLevel()

        Log level SPC runs at. Setting it rewrites log4jXml, so it takes effect without a restart.

      • getZipArchiveExclusions

         final TreeSet<String> getZipArchiveExclusions()

        List of files to be excluded from ZIP-archives. Current filters are:

        • MINECRAFT_VERSION - Will be replaced with the Minecraft version of the server pack

        • MODLOADER - Will be replaced with the modloader of the server pack

        • MODLOADER_VERSION - Will be replaced with the modloader version of the server pack

        Should you want these filters to be expanded, open an issue on GitHub

      • setZipArchiveExclusions

         final Unit setZipArchiveExclusions(TreeSet<String> value)

        List of files to be excluded from ZIP-archives. Current filters are:

        • MINECRAFT_VERSION - Will be replaced with the Minecraft version of the server pack

        • MODLOADER - Will be replaced with the modloader of the server pack

        • MODLOADER_VERSION - Will be replaced with the modloader version of the server pack

        Should you want these filters to be expanded, open an issue on GitHub

      • getJavaConfig

         final JavaConfig getJavaConfig()

        Settings-group for Java-installations: the Java used for modloader-server installs, the per-version java-paths for script-variables, path-validation and the script-autoupdate flag. Prefer accessing these values through this group; the individual properties on ApiProperties remain as facade.

      • getJavaPaths

         final HashMap<String, String> getJavaPaths()

        Paths to Java installations available to SPC for automatically updating the script variables of a given server pack configuration. Key: Java version, value: path.

      • setJavaPaths

         final Unit setJavaPaths(HashMap<String, String> value)

        Paths to Java installations available to SPC for automatically updating the script variables of a given server pack configuration. Key: Java version, value: path.

      • getUpdateUrl

         final URL getUpdateUrl()

        The URL from which a .properties-file is read during updating of the fallback clientside-mods list.

      • setUpdateUrl

         final Unit setUpdateUrl(URL value)

        The URL from which a .properties-file is read during updating of the fallback clientside-mods list.

      • isCheckingForPreReleasesEnabled

         final Boolean isCheckingForPreReleasesEnabled()

        Whether the search for available PreReleases is enabled or disabled. Depending on de.griefed.serverpackcreator.versioncheck.prerelease, returns true if checks for available PreReleases are enabled, false if no checks for available PreReleases should be made.

      • setCheckingForPreReleasesEnabled

         final Unit setCheckingForPreReleasesEnabled(Boolean value)

        Whether the search for available PreReleases is enabled or disabled. Depending on de.griefed.serverpackcreator.versioncheck.prerelease, returns true if checks for available PreReleases are enabled, false if no checks for available PreReleases should be made.

      • isJavaScriptAutoupdateEnabled

         final Boolean isJavaScriptAutoupdateEnabled()

        Whether to automatically update the SPC_JAVA_SPC-placeholder in the script variables table with a Java path matching the required Java version for the Minecraft server.

      • setJavaScriptAutoupdateEnabled

         final Unit setJavaScriptAutoupdateEnabled(Boolean value)

        Whether to automatically update the SPC_JAVA_SPC-placeholder in the script variables table with a Java path matching the required Java version for the Minecraft server.

      • getAikarsFlags

         final String getAikarsFlags()

        Aikars Flags commonly used for Minecraft servers to improve performance in various places.

      • setAikarsFlags

         final Unit setAikarsFlags(String value)

        Aikars Flags commonly used for Minecraft servers to improve performance in various places.

      • getWebserviceConfig

         final WebserviceConfig getWebserviceConfig()

        Web-service settings-group: database-URI and webservice-schedules. Prefer accessing these through this group; the individual properties on ApiProperties remain as facade.

      • getDatabaseUri

         final String getDatabaseUri()

        Path to the database used by the webservice-side of ServerPackCreator.

      • setDatabaseUri

         final Unit setDatabaseUri(String value)

        Path to the database used by the webservice-side of ServerPackCreator.

      • getJavaPath

         final String getJavaPath()

        Java installation used for installing the modloader server during server pack creation.

      • setJavaPath

         final Unit setJavaPath(String value)

        Java installation used for installing the modloader server during server pack creation.

      • getPathsConfig

         final PathsConfig getPathsConfig()

        Settings-group for ServerPackCreators home-directory and every directory and file derived from it. Prefer accessing these values through this group; the individual properties on ApiProperties remain as facade.

      • getScriptTemplatesConfig

         final ScriptTemplatesConfig getScriptTemplatesConfig()

        Settings-group for the start- and java-script-templates. Prefer accessing these values through this group; the individual properties on ApiProperties remain as facade.

      • getHomeDirectory

         final File getHomeDirectory()

        ServerPackCreators home-directory, in which all important files and folders are stored in.

      • setHomeDirectory

         final Unit setHomeDirectory(File value)

        ServerPackCreators home-directory, in which all important files and folders are stored in.

      • getDefaultConfig

         final File getDefaultConfig()

        Default configuration-file for a server pack generation in the home-directory.

      • getConfigsDirectory

         final File getConfigsDirectory()

        Directory in which GUI-created configurations are saved by default.

      • getTomcatBaseDirectory

         final File getTomcatBaseDirectory()

        Base-directory for Tomcat, used by the webservice-side of ServerPackCreator.

      • getServerPacksDirectory

         final File getServerPacksDirectory()

        Directory in which generated server packs and their ZIP-archives are stored.

      • getLogsDirectory

         final File getLogsDirectory()

        Storage-location for logs created by ServerPackCreator.

      • getTomcatLogsDirectory

         final File getTomcatLogsDirectory()

        Logs-directory for Tomcat, used by the webservice-side of ServerPackCreator.

      • getManifestsDirectory

         final File getManifestsDirectory()

        Directory to which default/fallback version-manifests are copied during startup.

      • getWorkDirectory

         final File getWorkDirectory()

        Work-directory for storage of files and folders required temporarily during any operation.

      • getTempDirectory

         final File getTempDirectory()

        Temp-directory storing files and folders required temporarily during a run.

      • getModpacksDirectory

         final File getModpacksDirectory()

        Modpacks-directory in which uploaded modpack-archives and extracted modpacks are stored.

      • getPropertiesDirectory

         final File getPropertiesDirectory()

        Directory in which properties for quick selection are stored and retrieved.

      • getIconsDirectory

         final File getIconsDirectory()

        Directory in which icons for quick selection are stored and retrieved.

      • getDefaultVariablesTemplate

         final File getDefaultVariablesTemplate()

        The shipped variables.txt template that server-pack generation fills in. Lives in the server_files-directory inside ServerPackCreator's home-directory, like the start-script templates.

      • getPluginsDirectory

         final File getPluginsDirectory()

        Directory in which plugins for ServerPackCreator are to be placed in.

      • getFallbackUpdated

         final Boolean getFallbackUpdated()

        Whether the fallback lists for clientside-mods and whitelisted mods have been updated.

        true if either was updated.

      • getInstallLocationXml

         final File getInstallLocationXml()

        log4j2.xml beside the jar rather than in the home directory — home is the jar folder, not SPC's home. Legacy install-location copy; log4jXml is the one logging actually reads.

      • getLog4jXml

         final File getLog4jXml()

        The log4j2.xml in SPC's home that logging is configured from; rewritten on a dev or pre-release build.

      • getJarFolder

         final File getJarFolder()

        The folder containing the ServerPackCreator.exe or JAR-file.

        Returns:

        Folder containing the ServerPackCreator.exe or JAR-file.

      • isExe

         final Boolean isExe()

        Whether a .exe or JAR-file was used for running ServerPackCreator.

        Returns:

        true if a .exe was/is used.

      • getJarFile

         final File getJarFile()

        The .exe or JAR-file of ServerPackCreator.

        Returns:

        The .exe or JAR-file of ServerPackCreator.

      • getJarName

         final String getJarName()

        The name of the .exe or JAR-file.

        Returns:

        The name of the .exe or JAR-file.

      • getJavaVersion

         final String getJavaVersion()

        The Java version used to run ServerPackCreator.

        Returns:

        Java version.

      • getOSArch

         final String getOSArch()

        Architecture of the operating system on which ServerPackCreator is running on.

        Returns:

        Arch.

      • getOSName

         final String getOSName()

        The name of the operating system on which ServerPackCreator is running on.

        Returns:

        OS name.

      • getOSVersion

         final String getOSVersion()

        The version of the OS on which ServerPackCreator is running on.

        Returns:

        Version of the OS.

      • getPreference

         final Optional<String> getPreference(String pref, String def)

        Read one value from SPC's Preferences node, or def when unset.

        Landmine: which node that is depends on resolvePreferencesNode — a host claiming its own node (the grinder daemon, every test JVM) reads and writes a different store than the default installation, deliberately.

      • defaultWebserviceDatabase

         final String defaultWebserviceDatabase()

        The default webservice database-URI, for resetting the configuration to factory-state.

      • loadOverrides

         final Unit loadOverrides(File properties)

        Loads the overrides-properties directly into the store, replacing already-loaded values.

      • loadProperties

         final Unit loadProperties(Boolean saveProps)

        Load properties using the default file path. Only call this method on an already initialized ApiProperties-object.

      • loadProperties

         final Unit loadProperties(File propertiesFile, Boolean saveProps)

        Reload from a specific properties-file.

        Parameters:
        propertiesFile - The properties-file with which to loadProperties the settings and configuration.
      • acquireJavaPath

         final String acquireJavaPath(String pathToJava)

        Check the given path to a Java installation for validity and return it, if it is valid. Invalid paths yield the automatically acquired system-Java.

      • saveProperties

         final Unit saveProperties(File propertiesFile)

        Store the ApplicationProperties to disk, overwriting the existing one.

        Parameters:
        propertiesFile - The file to store the properties to.
      • javaAvailable

         final Boolean javaAvailable()

        Whether a viable path to a Java executable or binary has been configured for ServerPackCreator.

      • changeLocale

         final Unit changeLocale(Locale locale)

        Writes the specified locale from -lang your_locale to a lang.properties file to ensure every subsequent start of serverpackcreator is executed using said locale.

        Parameters:
        locale - The locale the user specified when they ran serverpackcreator with -lang -your_locale.
      • clientSideMods

         final List<String> clientSideMods()

        Acquire the default fallback list of clientside-only mods. If de.griefed.serverpackcreator.serverpack.autodiscovery.filter is set to ExclusionFilter.REGEX, a regex fallback list is returned.

        Returns:

        The fallback list of clientside-only mods.

      • whitelistedMods

         final List<String> whitelistedMods()

        Acquire the default fallback list of whitelisted mods. If de.griefed.serverpackcreator.serverpack.autodiscovery.filter is set to ExclusionFilter.REGEX, a regex fallback list is returned.

        Returns:

        The fallback list of whitelisted mods.

      • updateFallback

         final Boolean updateFallback()

        Update the fallback clientside-only mod-list and whitelist from the configured update-URL.

        Returns:

        true if either fallback-list was updated.

      • storeCustomProperty

         final String storeCustomProperty(String property, String value)

        Store a custom property in the serverpackcreator.properties-file. Beware that every property you add receives a prefix, to prevent clashes with any other properties.

        Said prefix consists of custom.property. followed by the property you specified coming in last.

        Say you have a value in the property saved, then the resulting property in the serverpackcreator.properties would be:

        • custom.property.saved

      • retrieveCustomProperty

         final String retrieveCustomProperty(String property)

        Retrieve a custom property in the serverpackcreator.properties-file. Beware that every property you retrieve this way contains a prefix, to prevent clashes with any other properties.

        Said prefix consists of custom.property. followed by the property you specified coming in last.

        Say you have a property saved, then the resulting property in the serverpackcreator.properties would be: custom.property.saved

      • setOldVersion

         final Unit setOldVersion(String version)

        Set the old version of ServerPackCreator used to perform necessary migrations between the old and the current version.

        Parameters:
        version - Old version used before upgrading to the current version.
      • oldVersion

         final String oldVersion()

        Get the old version of ServerPackCreator used to perform necessary migrations between the old and the current version.

        Returns:

        Old version used before updating. Empty if this is the first run of ServerPackCreator.

      • clearPropertyFileList

         final Unit clearPropertyFileList()

        Forget every properties file the store has loaded from.

        PropertyStore writes to all tracked files on every save, so a file loaded once keeps being rewritten for the life of the process — which is how a daemon started from a checkout dropped a settings file into the repository root. Call this when a host wants its saves confined to the file it just pointed SPC at.

      • getConfiguration

         Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source)

        Depending on whether this is the first run of ServerPackCreator on a users machine, the default log4j2 configuration may be present at different locations. The default one is the config inside the home-directory of SPC, of which we will try to set up our logging with. If said file fails for whatever reason, we will try to use a config inside the directory from which SPC was executed. Should that fail, too, the config from the classpath is used, to ensure we always have default configs available. Should that fail, too, though, log4j is set up with its own default settings.

        Parameters:
        loggerContext - logger context passed from log4j itself
        source - configuration source passed from log4j itself.
        Returns:

        Custom configuration with proper logs-directory set.

      • resolvePreferencesNode

        @JvmOverloads() final static String resolvePreferencesNode(String property, String environment)

        Decide which Preferences node to store settings in: the PREFERENCES_NODE_PROPERTY system property first, then the PREFERENCES_NODE_ENV environment variable, else DEFAULT_PREFERENCES_NODE.

        Why this is overridable at all: the node is per-user and machine-wide, and PathsConfig.homeDirectory re-reads it on every access while writing back what it resolved. With a single hard-coded node, any SPC process could relocate any other running process's home directory — a test suite moved a live grinder daemon's home into its own scratch directory and then deleted it, and equally, running the suites moved the developer's own GUI home. Giving each host its own node makes that impossible.

        A blank override falls back to the default rather than being honoured: userRoot().node("") is the root node, shared with every other Java application on the account.

        Parameters:
        property - The system-property value (injectable for tests).
        environment - The environment-variable value (injectable for tests).
      • resolvePreferencesNode

        @JvmOverloads() final static String resolvePreferencesNode(String property)

        Decide which Preferences node to store settings in: the PREFERENCES_NODE_PROPERTY system property first, then the PREFERENCES_NODE_ENV environment variable, else DEFAULT_PREFERENCES_NODE.

        Why this is overridable at all: the node is per-user and machine-wide, and PathsConfig.homeDirectory re-reads it on every access while writing back what it resolved. With a single hard-coded node, any SPC process could relocate any other running process's home directory — a test suite moved a live grinder daemon's home into its own scratch directory and then deleted it, and equally, running the suites moved the developer's own GUI home. Giving each host its own node makes that impossible.

        A blank override falls back to the default rather than being honoured: userRoot().node("") is the root node, shared with every other Java application on the account.

        Parameters:
        property - The system-property value (injectable for tests).
      • resolvePreferencesNode

        @JvmOverloads() final static String resolvePreferencesNode()

        Decide which Preferences node to store settings in: the PREFERENCES_NODE_PROPERTY system property first, then the PREFERENCES_NODE_ENV environment variable, else DEFAULT_PREFERENCES_NODE.

        Why this is overridable at all: the node is per-user and machine-wide, and PathsConfig.homeDirectory re-reads it on every access while writing back what it resolved. With a single hard-coded node, any SPC process could relocate any other running process's home directory — a test suite moved a live grinder daemon's home into its own scratch directory and then deleted it, and equally, running the suites moved the developer's own GUI home. Giving each host its own node makes that impossible.

        A blank override falls back to the default rather than being honoured: userRoot().node("") is the root node, shared with every other Java application on the account.