diff options
author | Norbert Preining <norbert@preining.info> | 2020-04-04 03:02:28 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2020-04-04 03:02:28 +0000 |
commit | 4f71d4ff0d1e7ff4607b58eb7d030bd860e44f3a (patch) | |
tree | d4e56c2a7dc233a34c572829037ac8fb346f14bc /support/arara/source/src/main/kotlin/org/islandoftex/arara/configuration/ConfigurationUtils.kt | |
parent | 6cacb7b2abf477262c442913f467f219649afb26 (diff) |
CTAN sync 202004040302
Diffstat (limited to 'support/arara/source/src/main/kotlin/org/islandoftex/arara/configuration/ConfigurationUtils.kt')
-rw-r--r-- | support/arara/source/src/main/kotlin/org/islandoftex/arara/configuration/ConfigurationUtils.kt | 157 |
1 files changed, 0 insertions, 157 deletions
diff --git a/support/arara/source/src/main/kotlin/org/islandoftex/arara/configuration/ConfigurationUtils.kt b/support/arara/source/src/main/kotlin/org/islandoftex/arara/configuration/ConfigurationUtils.kt deleted file mode 100644 index a48a6d0d3f..0000000000 --- a/support/arara/source/src/main/kotlin/org/islandoftex/arara/configuration/ConfigurationUtils.kt +++ /dev/null @@ -1,157 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -package org.islandoftex.arara.configuration - -import com.charleskorn.kaml.Yaml -import java.io.File -import java.io.UnsupportedEncodingException -import java.net.URLDecoder -import java.nio.file.Path -import java.nio.file.Paths -import org.islandoftex.arara.Arara -import org.islandoftex.arara.localization.LanguageController -import org.islandoftex.arara.localization.Messages -import org.islandoftex.arara.model.AraraException -import org.islandoftex.arara.model.FileType -import org.islandoftex.arara.utils.CommonUtils - -/** - * Implements configuration utilitary methods. - * - * @author Island of TeX - * @version 5.0 - * @since 4.0 - */ -object ConfigurationUtils { - // the application messages obtained from the - // language controller - private val messages = LanguageController - - /** - * This map contains all file types that arara accepts - * and their corresponding search patterns (for comments). - */ - val defaultFileTypePatterns = mapOf( - "tex" to "^\\s*%\\s+", - "dtx" to "^\\s*%\\s+", - "ltx" to "^\\s*%\\s+", - "drv" to "^\\s*%\\s+", - "ins" to "^\\s*%\\s+" - ) - - /** - * Set of default file types provided by arara. - * Initialization may throw AraraException if file types are wrong - */ - val defaultFileTypes: Set<FileType> by lazy { - defaultFileTypePatterns - .map { (extension, pattern) -> FileType(extension, pattern) } - .toSet() - } - - /** - * The configuration file in use. - * - * Look for configuration files in the user's working directory first - * if no configuration files are found in the user's working directory, - * try to look up in a global directory, that is, the user home. - */ - val configFile: File? - get() { - val names = listOf(".araraconfig.yaml", - "araraconfig.yaml", ".arararc.yaml", "arararc.yaml") - Arara.config[AraraSpec.Execution.workingDirectory] - .let { workingDir -> - val first = names - .map { workingDir.resolve(it).toFile() } - .firstOrNull { it.exists() } - if (first != null) - return first - } - CommonUtils.getSystemPropertyOrNull("user.home")?.let { userHome -> - return names.map { File(userHome).resolve(it) } - .firstOrNull { it.exists() } - } - return null - } - - /** - * The canonical absolute application path. - * - * @throws AraraException Something wrong happened, to be caught in the - * higher levels. - */ - val applicationPath: Path - @Throws(AraraException::class) - get() { - try { - var path = Arara::class.java.protectionDomain.codeSource - .location.path - path = URLDecoder.decode(path, "UTF-8") - return Paths.get(File(path).toURI()).parent.toAbsolutePath() - } catch (exception: UnsupportedEncodingException) { - throw AraraException( - messages.getMessage( - Messages.ERROR_GETAPPLICATIONPATH_ENCODING_EXCEPTION - ), - exception - ) - } - } - - /** - * Validates the configuration file. - * - * @param file The configuration file. - * @return The configuration file as a resource. - * @throws AraraException Something wrong happened, to be caught in the - * higher levels. - */ - @Throws(AraraException::class) - fun loadLocalConfiguration(file: File): LocalConfiguration { - return file.runCatching { - val text = readText() - if (!text.startsWith("!config")) - throw Exception("Configuration should start with !config") - Yaml.default.parse(LocalConfiguration.serializer(), - text) - }.getOrElse { - throw AraraException(messages.getMessage( - Messages.ERROR_CONFIGURATION_GENERIC_ERROR), it) - } - } - - /** - * Normalize a list of rule paths, removing all duplicates. - * - * @param paths The list of rule paths. - * @return A list of normalized paths, without duplicates. - * @throws AraraException Something wrong happened, to be caught in the - * higher levels. - */ - @Throws(AraraException::class) - fun normalizePaths(paths: Iterable<String>): Set<String> = - paths.union(AraraSpec.Execution.rulePaths.default) - - /** - * Normalize a list of file types, removing all duplicates. - * - * @param types The list of file types. - * @return A list of normalized file types, without duplicates. - * @throws AraraException Something wrong happened, to be caught in the - * higher levels. - */ - @Throws(AraraException::class) - fun normalizeFileTypes(types: Iterable<FileType>): Set<FileType> = - types.union(defaultFileTypes) - - /** - * Cleans the file name to avoid invalid entries. - * - * @param name The file name. - * @return A cleaned file name. - */ - fun cleanFileName(name: String): String { - val result = File(name).name.trim() - return if (result.isEmpty()) "arara" else result.trim() - } -} |