1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
5 package org.ibex.jinetd;
6 import org.ibex.util.*;
10 import java.util.zip.*;
14 // Bootup //////////////////////////////////////////////////////////////////////////////
17 System.setProperty("java.awt.headless", "true");
18 System.setProperty("ibex.log.stackTraces", "true");
19 System.setProperty("ibex.log.notes.on", "false");
20 System.setProperty("org.mortbay.xml.XmlParser.NotValidating", "true");
21 System.setProperty("STOP.PORT", "0");
24 public static String ROOT;
25 private static String LOGFILE;
26 private static PrintStream LOGSTREAM;
27 public static String defaultDomain;
29 public static void init() {
31 System.err.println("jinetd starting...");
32 ROOT = System.getProperty("jinetd.root", null);
33 if (ROOT == null) System.setProperty("jinetd.root", ROOT = autoDetectRoot());
34 System.err.println(" jinetd.root = " + ROOT);
35 defaultDomain = System.getProperty("jinetd.hostname", null);
36 if (defaultDomain==null) try {
37 java.net.InetAddress localMachine = java.net.InetAddress.getLocalHost();
38 defaultDomain = localMachine.getHostName();
39 } catch(java.net.UnknownHostException uhe) { defaultDomain = "localhost"; }
40 System.err.println(" jinetd.hostname = " + defaultDomain);
41 LOGFILE = System.getProperty("jinetd.logfile", /*ROOT + File.separatorChar+"log.txt"*/null);
42 if (LOGFILE != null) {
43 System.err.println(" jinetd.logfile = " + LOGFILE);
44 System.err.println(" redirecting stdout/stderr to logfile." + LOGFILE);
45 LOGSTREAM = new PrintStream(new FileOutputStream(LOGFILE, true));
46 System.setErr(LOGSTREAM);
47 System.setOut(LOGSTREAM);
51 } catch (Throwable e) {
56 private static void depend(String name, String url) throws Exception {
57 File f = new File(ROOT + File.separatorChar + "lib" + File.separatorChar + name);
58 if (f.exists()) return;
59 Log.warn(Main.class, "attempting to fetch " + name);
60 File fminus = new File(ROOT + File.separatorChar + "lib" + File.separatorChar + name + "-");
61 GetDep.fetch(fminus.getAbsolutePath(), url);
65 // FIXME: really need some hashes in here for security
66 private static void gatherDependencies() throws Exception {
67 depend("bcel-5.1.jar",
68 "tgz:http://apache.cs.utah.edu/jakarta/bcel/binaries/bcel-5.1.tar.gz!bcel-5.1/bcel-5.1.jar");
70 depend("commons-el.jar",
71 "tgz:http://www.signal42.com/mirrors/apache/jakarta/commons/el/binaries/commons-el-1.0.tar.gz!"+
72 "commons-el-1.0/commons-el.jar");
74 depend("commons-logging.jar",
75 "tgz:http://apache.towardex.com/jakarta/commons/logging/binaries/commons-logging-1.0.4.tar.gz!"+
76 "commons-logging-1.0.4/commons-logging.jar");
78 depend("org.mortbay.jetty.jar",
79 "zip:http://voxel.dl.sourceforge.net/sourceforge/jetty/jetty-5.1.2.zip!jetty-5.1.2/lib/org.mortbay.jetty.jar");
80 depend("javax.servlet.jar",
81 "zip:http://voxel.dl.sourceforge.net/sourceforge/jetty/jetty-5.1.2.zip!jetty-5.1.2/lib/javax.servlet.jar");
83 depend("prevayler-2.02.005.jar",
84 "tgz:http://unc.dl.sourceforge.net/sourceforge/prevayler/prevayler-2.02.005.tar.gz!"+
85 "prevayler-2.02.005/prevayler-2.02.005.jar");
87 depend("jasper-runtime.jar",
88 "tgz:http://www.reverse.net/pub/apache/jakarta/tomcat-5/v5.5.8/bin/jakarta-tomcat-5.5.8.tar.gz!"+
89 "jakarta-tomcat-5.5.8/common/lib/jasper-runtime.jar");
90 depend("jasper-compiler.jar",
91 "tgz:http://www.reverse.net/pub/apache/jakarta/tomcat-5/v5.5.8/bin/jakarta-tomcat-5.5.8.tar.gz!"+
92 "jakarta-tomcat-5.5.8/common/lib/jasper-compiler.jar");
93 depend("jasper-compiler-jdt.jar",
94 "tgz:http://www.reverse.net/pub/apache/jakarta/tomcat-5/v5.5.8/bin/jakarta-tomcat-5.5.8.tar.gz!"+
95 "jakarta-tomcat-5.5.8/common/lib/jasper-compiler-jdt.jar");
97 depend("xpp3_min-1.1.3.4.I.jar",
98 "http://www.extreme.indiana.edu/dist/java-repository/xpp3/jars/xpp3_min-1.1.3.4.I.jar");
100 "http://dist.codehaus.org/xstream/jars/xstream-1.1.1.jar");
101 depend("skaringa-r3p5.jar",
102 "tgz:http://unc.dl.sourceforge.net/sourceforge/skaringa/skaringa-r3p5.tar.gz!"+
103 "skaringa/lib/skaringa-r3p5.jar");
106 private static String autoDetectRoot() throws Exception {
107 if (!(Main.class.getClassLoader() instanceof URLClassLoader))
108 throw new Error("unable to detect jinetd.root because my ClassLoader is not an instanceof URLClassLoader");
109 URL[] urls = ((URLClassLoader)Main.class.getClassLoader()).getURLs();
110 for(int i=0; i<urls.length; i++) {
111 if (!urls[i].getProtocol().equals("file")) continue;
112 File file = new File(urls[i].getPath());
113 if (file.isDirectory()) {
114 if (new File(file.getAbsolutePath() +
116 Main.class.getName().replace('.', File.separatorChar)+".class").exists())
117 return file.getAbsolutePath();
118 } else if (file.getAbsolutePath().endsWith(".jar")) {
119 ZipFile zf = new ZipFile(file);
120 if (zf.getEntry(Main.class.getName().replace('.', File.separatorChar)+".class") != null)
121 return new File(file.getParent()).getAbsolutePath();
124 throw new Error("unable to detect jinetd.root because " +
125 Main.class.getName() +
126 " was not in any of the ClassLoader URLs");
129 public static void reboot() {
134 private static TreeClassLoader rootClassLoader;
135 public static TreeClassLoader getRootClassLoader() {
136 if (rootClassLoader==null)
137 rootClassLoader = new TreeClassLoader(new File(ROOT + File.separatorChar + "lib"),
138 Main.class.getClassLoader());
139 return rootClassLoader;
142 public static void main(String[] s) throws Exception {
144 Root root = new Root(ROOT);
146 if (root != null) { root.scan(); return; }
148 } catch (Exception e) { Log.error(Main.class, e); }