From 5c27d5800d7c4a9c1a5d41c6ce427156652b74b0 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 25 Feb 2020 14:21:39 +0100 Subject: Move Environment class to API, fix loading from file --- .../src/main/java/org/openslx/taskmanager/App.java | 1 + .../java/org/openslx/taskmanager/Environment.java | 67 ---------------------- 2 files changed, 1 insertion(+), 67 deletions(-) delete mode 100644 daemon/src/main/java/org/openslx/taskmanager/Environment.java (limited to 'daemon') diff --git a/daemon/src/main/java/org/openslx/taskmanager/App.java b/daemon/src/main/java/org/openslx/taskmanager/App.java index d64929d..3b8eb66 100644 --- a/daemon/src/main/java/org/openslx/taskmanager/App.java +++ b/daemon/src/main/java/org/openslx/taskmanager/App.java @@ -6,6 +6,7 @@ import java.util.List; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Logger; +import org.openslx.taskmanager.api.Environment; import org.openslx.taskmanager.main.Taskmanager; import org.openslx.taskmanager.network.NetworkHandlerTcp; import org.openslx.taskmanager.network.NetworkHandlerUdp; diff --git a/daemon/src/main/java/org/openslx/taskmanager/Environment.java b/daemon/src/main/java/org/openslx/taskmanager/Environment.java deleted file mode 100644 index acbfad4..0000000 --- a/daemon/src/main/java/org/openslx/taskmanager/Environment.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.openslx.taskmanager; - -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Map.Entry; - -import org.apache.log4j.Logger; - -/** - * Holds the environment that tasks running a system command *should* - * use. The environment is read from a config file. - */ -public class Environment -{ - - private static final Logger log = Logger.getLogger( Environment.class ); - - private static Map env = new LinkedHashMap<>(); - - public static boolean load( String fileName ) - { - try { - FileReader fileReader = new FileReader( fileName ); - BufferedReader bufferedReader = new BufferedReader( fileReader ); - - Map env = new LinkedHashMap<>(); - String line = null; - while ( ( line = bufferedReader.readLine() ) != null ) { - if ( !line.matches( "^[a-zA-Z0-9_]+=" ) ) - continue; - String[] part = line.split( "=", 2 ); - env.put( part[0], part[1] ); - } - - bufferedReader.close(); - - Environment.env = env; - log.info( "Loaded " + env.size() + " environment lines." ); - } catch ( IOException e ) { - log.info( "Could not load environment definition from " + fileName + ". Processes might use the same environment as this thread." ); - return false; - } - return true; - } - - public static void set( Map environment ) - { - environment.clear(); - environment.putAll( env ); - } - - public static String[] get() - { - // Get reference to env so it doesn't change while in this function (load() from other thread) - Map env = Environment.env; - String ret[] = new String[ env.size() ]; - int i = 0; - for ( Entry it : env.entrySet() ) { - ret[i++] = it.getKey() + "=" + it.getValue(); - } - return ret; - } - -} -- cgit v1.2.3-55-g7522