From 4f71d4ff0d1e7ff4607b58eb7d030bd860e44f3a Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Sat, 4 Apr 2020 03:02:28 +0000 Subject: CTAN sync 202004040302 --- .../kotlin/org/islandoftex/arara/model/Session.kt | 119 --------------------- 1 file changed, 119 deletions(-) delete mode 100644 support/arara/source/src/main/kotlin/org/islandoftex/arara/model/Session.kt (limited to 'support/arara/source/src/main/kotlin/org/islandoftex/arara/model/Session.kt') diff --git a/support/arara/source/src/main/kotlin/org/islandoftex/arara/model/Session.kt b/support/arara/source/src/main/kotlin/org/islandoftex/arara/model/Session.kt deleted file mode 100644 index c2093429e1..0000000000 --- a/support/arara/source/src/main/kotlin/org/islandoftex/arara/model/Session.kt +++ /dev/null @@ -1,119 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -package org.islandoftex.arara.model - -import org.islandoftex.arara.localization.LanguageController -import org.islandoftex.arara.localization.Messages - -/** - * Implements the session. - * - * This class wraps a map that holds the execution session, that is, a dirty - * maneuver to exchange pretty much any data between commands and even rules. - * - * @author Island of TeX - * @version 5.0 - * @since 4.0 - */ -object Session { - // the application messages obtained from the - // language controller - private val messages = LanguageController - - // the session map which holds the execution session; - // the idea here is to provide wrappers to the map - // methods, so it could be easily manipulated - private val map = mutableMapOf() - - /** - * Gets the object indexed by the provided key from the session. This method - * holds the map method of the very same name. - * - * @param key The provided key. - * @return The object indexed by the provided key. - * @throws AraraException Something wrong happened, to be caught in the - * higher levels. - */ - @Throws(AraraException::class) - operator fun get(key: String): Any { - return if (contains(key)) { - map.getValue(key) - } else { - throw AraraException( - messages.getMessage( - Messages.ERROR_SESSION_OBTAIN_UNKNOWN_KEY, - key - ) - ) - } - } - - /** - * Inserts (or overwrites) the object indexed by the provided key into the - * session. This method holds the map method of the very same name. - * - * @param key The provided key. - * @param value The value to be inserted. - */ - fun put(key: String, value: Any) { - map[key] = value - } - - /** - * Removes the entry indexed by the provided key from the session. This method - * holds the map method of the same name. - * - * @param key The provided key. - * @throws AraraException Something wrong happened, to be caught in the - * higher levels. - */ - @Throws(AraraException::class) - fun remove(key: String) { - if (contains(key)) { - map.remove(key) - } else { - throw AraraException( - messages.getMessage( - Messages.ERROR_SESSION_REMOVE_UNKNOWN_KEY, - key - ) - ) - } - } - - /** - * Checks if the provided key exists in the session. - * - * @param key The provided key. - * @return A boolean value indicating if the provided key exists in the - * session. - */ - operator fun contains(key: String): Boolean = map.containsKey(key) - - /** - * Clears the session (map). This method, as usual, holds the map method of - * the same name. - */ - fun clear() = map.clear() - - /** - * Update the environment variables stored in the session. - * - * @param additionFilter Which environment variables to include. You can - * filter their names (the string parameter) but not their values. By - * default all values will be added. - * @param removalFilter Which environment variables to remove beforehand. - * By default all values will be removed. - */ - fun updateEnvironmentVariables( - additionFilter: (String) -> Boolean = { true }, - removalFilter: (String) -> Boolean = { true } - ) { - // remove all current environment variables to clean up the session - map.filterKeys { it.startsWith("environment:") } - .filterKeys(removalFilter) - .forEach { remove(it.key) } - // add all relevant new environment variables - System.getenv().filterKeys(additionFilter) - .forEach { map["environment:${it.key}"] = it.value } - } -} -- cgit v1.2.3