X-Git-Url: http://dolda2000.com/gitweb/?p=jsvc.git;a=blobdiff_plain;f=src%2Fdolda%2Fjsvc%2Fscgi%2FEnvironment.java;fp=src%2Fdolda%2Fjsvc%2Fscgi%2FEnvironment.java;h=e91f57a3dbecc3a8d2633867df606de2187ebbb5;hp=0000000000000000000000000000000000000000;hb=22779185ec3cd3ab6fafdbcbe675161ceae9ce7d;hpb=a13bfa2c65aa523f9981531f3db1f125fbcfc19e diff --git a/src/dolda/jsvc/scgi/Environment.java b/src/dolda/jsvc/scgi/Environment.java new file mode 100644 index 0000000..e91f57a --- /dev/null +++ b/src/dolda/jsvc/scgi/Environment.java @@ -0,0 +1,87 @@ +package dolda.jsvc.scgi; + +import java.io.*; +import java.net.*; +import java.util.*; + +public class Environment { + public final File root; + public final Properties sysconfig = new Properties(); + private ClassLoader lib = null; + + public Environment(File root) { + this.root = root; + if(root != null) + loadconfig(); + } + + private static File defroot() { + File root = new File(System.getProperty("user.home"), ".jsvc"); + if(root.exists() && root.isDirectory()) + return(root); + return(null); + } + + public Environment() { + this(defroot()); + } + + private void loadconfig() { + File conf = new File(root, "jsvc.properties"); + if(conf.exists()) { + try { + InputStream in = new FileInputStream(conf); + try { + sysconfig.load(in); + } finally { + in.close(); + } + } catch(IOException e) { + throw(new RuntimeException(e)); + } + } + File lib = new File(root, "lib"); + if(lib.exists() && lib.isDirectory()) { + List jars = new ArrayList(); + for(File f : lib.listFiles()) { + if(f.isDirectory()) + continue; + if(!f.canRead()) + continue; + String nm = f.getName(); + if((nm.length() < 4) || !nm.substring(nm.length() - 4).equals(".jar")) + continue; + try { + jars.add(f.toURI().toURL()); + } catch(MalformedURLException e) { + throw(new Error(e)); + } + } + this.lib = URLClassLoader.newInstance(jars.toArray(new URL[0]), Environment.class.getClassLoader()); + } + } + + public ClassLoader libloader() { + if(this.lib == null) + return(Environment.class.getClassLoader()); + return(this.lib); + } + + public void initvm() { + if(root == null) + return; + File logging = new File(root, "logging.properties"); + if(logging.exists() && logging.canRead()) { + try { + InputStream in = new FileInputStream(logging); + try { + java.util.logging.LogManager.getLogManager().readConfiguration(in); + } finally { + in.close(); + } + } catch(IOException e) { + throw(new RuntimeException(e)); + } + } + } +}