- private void compileSource() throws Exception {
- File srcdir = new File(this.path + File.separatorChar + "SRC");
- if (!srcdir.exists()) return;
- if (new File("/usr/bin/jikes").exists()) {
- File bindir = new File(this.path + File.separatorChar + "BIN"); bindir.mkdirs();
- File libdir = new File(this.path + File.separatorChar + "LIB");
- String classpath = System.getProperty("java.class.path");
- String [] l = new File("/jinetd/LIB/").list();
- for(int i=0; i<l.length; i++) {
- if (!l[i].endsWith(".jar")) continue;
- classpath += File.pathSeparatorChar;
- classpath += "/jinetd/LIB/" + l[i];
- }
- String bootclasspath = System.getProperty("sun.boot.class.path", "");
- Vec args = new Vec();
- args.addElement("/usr/bin/jikes");
- args.addElement("+E");
- args.addElement("-nowarn");
- args.addElement("-bootclasspath");
- args.addElement(bootclasspath);
- args.addElement("-extdirs");
- args.addElement(libdir.getAbsolutePath());
- args.addElement("-classpath");
- args.addElement(classpath);
- args.addElement("-sourcepath");
- args.addElement(srcdir.getAbsolutePath());
- args.addElement("-d");
- args.addElement(bindir.getAbsolutePath());
- fill(args, srcdir);
- String[] all = new String[args.size()];
- args.copyInto(all);
- Log.info(this, "invoking jikes");
- for(int i=0; i<all.length; i++) Log.info(this, " " + all[i]);
- final Process jikes = Runtime.getRuntime().exec(all);
- final BufferedReader out = new BufferedReader(new InputStreamReader(jikes.getInputStream()));
- final BufferedReader err = new BufferedReader(new InputStreamReader(jikes.getErrorStream()));
- new Thread() { public void run() {
- try { for(String s = out.readLine(); s != null; s = out.readLine()) Log.info("jikes[stdout]", s); }
- catch (Exception e) { Log.warn("jikes", e); } } }.start();
- new Thread() { public void run() {
- try { for(String s = err.readLine(); s != null; s = err.readLine()) Log.info("jikes[stderr]", s); }
- catch (Exception e) { Log.warn("jikes", e); } } }.start();
- jikes.waitFor();
- } else {
- Log.error(this, "ACK! jikes not found, javac not (yet) supported");
- }
- }
-
- // only watch SRC and LIB for changes
- public Watched slash(String path) {
- return (path.equals("LIB") ||
- path.equals("BIN") ||
- path.equals("SRC") ||
- path.endsWith(".jar") ) ? super.slash(path) : null; }
-
-
- // dump the classloader if anything changes
- public void changed(Watched w) {
- if (w.path.indexOf("BIN") != -1) return;
- if (classloader != null) {
- Log.info(this, "Reloading all classes: " + path);
- classloader = null;
- }
- }
-
- private class TreeClassLoader extends ClassLoader {
- private Hashtable cache = new Hashtable();