From: Steve L. <st...@us...> - 2005-03-02 18:39:54
|
Update of /cvsroot/smartfrog/core/extras/wrapper/src/org/smartfrog/extras/wrapper In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26125/extras/wrapper/src/org/smartfrog/extras/wrapper Modified Files: Launcher.java ServiceWrapper.java WrappedEntryPoint.java Log Message: Updated wrapper. Loading and running now, but failing with some classcast exception in the parser. Index: Launcher.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/wrapper/src/org/smartfrog/extras/wrapper/Launcher.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Launcher.java 28 Feb 2005 17:55:06 -0000 1.2 --- Launcher.java 2 Mar 2005 18:39:44 -0000 1.3 *************** *** 23,51 **** import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.StringTokenizer; /** * Taken from the ant launcher and reworked */ public class Launcher { /** ! * The Ant Home property */ public static final String SFHOME_PROPERTY = "sf.home"; /** ! * The Ant Home property */ public static final String SFHOME_ENV_VARIABLE = "SFHOME"; /** ! * The startup class that is to be run */ public static final String MAIN_CLASS = "org.smartfrog.extras.wrapper.launcher.WrappedSFSystem"; /** * Entry point for starting command line; only here for debug purposes. * --- 23,77 ---- import java.net.URLClassLoader; import java.util.ArrayList; + import java.util.Enumeration; import java.util.Iterator; import java.util.List; + import java.util.Properties; import java.util.StringTokenizer; + import java.util.logging.Level; + import java.util.logging.Logger; /** * Taken from the ant launcher and reworked + * <p/> + * This class 1. extracts SFHOME from the command line or the environment 2. + * executes any -lib operations 3. */ public class Launcher { /** ! * The SF Home property {@value} */ public static final String SFHOME_PROPERTY = "sf.home"; /** ! * The SF Home env variable {@value} */ public static final String SFHOME_ENV_VARIABLE = "SFHOME"; /** ! * The startup class that is to be run: {@value} */ public static final String MAIN_CLASS = "org.smartfrog.extras.wrapper.launcher.WrappedSFSystem"; /** + * the name of the 2ary JAR to load, the one that contains WrappedSFSystem; + * {@value} + */ + public static final String SECONDARY_JAR = "sf-wrapper-launched.jar"; + + public static final String JAVA_CLASSPATH = "java.class.path"; + + /** + * name of the subdir to look for lib files in {@lib} + */ + public static final String LIB_SUBDIR = "/lib"; + + public static final String LOG_NAME = "org.smartfrog.extras.wrapper"; + /** + * a log + */ + private static Logger log = Logger.getLogger(LOG_NAME); + + /** * Entry point for starting command line; only here for debug purposes. * *************** *** 58,61 **** --- 84,88 ---- WrappedEntryPoint wrappedEntryPoint = info.load(); } catch (LaunchException e) { + log.log(Level.SEVERE, "no launch", e); System.err.println(e.getMessage()); } catch (Throwable t) { *************** *** 64,67 **** --- 91,104 ---- } + private static Level level = Level.INFO; + + public static void log(String message) { + log.log(level, message); + } + + public static void log(String message, Throwable t) { + log.log(Level.SEVERE, message, t); + } + /** * Add a CLASSPATH or -lib to lib path urls. *************** *** 97,101 **** /** ! * Run the launcher to launch Ant * * @param args the command line arguments --- 134,142 ---- /** ! * Run the launcher to launch Ant. Adds some extra arguments to the command ! * line <ul> <li> -lib dir : set a directory of JAR files <li> -libclasses ! * dir : set a directory of classes to add to the classpath <li> -cp ! * classpath : any classpath <li> --noclasspath: no classpath <li> -debug ! * extra logging of the launcher </ul> * * @param args the command line arguments *************** *** 105,127 **** public LauncherInfo prelaunch(String[] args) throws LaunchException, MalformedURLException { - String antHomeProperty = System.getProperty(SFHOME_PROPERTY); - File antHome = null; - - File sourceJar = Locator.getClassSource(getClass()); - File jarDir = sourceJar.getParentFile(); - - if (antHomeProperty != null) { - antHome = new File(antHomeProperty); - } - - if (antHome == null || !antHome.exists()) { - antHome = jarDir.getParentFile(); - System.setProperty(SFHOME_PROPERTY, antHome.getAbsolutePath()); - } - - if (!antHome.exists()) { - throw new LaunchException("SF home is set incorrectly or " - + "ant could not be located"); - } List libPaths = new ArrayList(); --- 146,149 ---- *************** *** 129,135 **** List argList = new ArrayList(); String[] newArgs; - boolean noUserLib = false; boolean noClassPath = false; for (int i = 0; i < args.length; ++i) { if (args[i].equals("-lib")) { --- 151,158 ---- List argList = new ArrayList(); String[] newArgs; boolean noClassPath = false; + List libPathURLs = new ArrayList(); + //crack the arguments, stripping out our specials for (int i = 0; i < args.length; ++i) { if (args[i].equals("-lib")) { *************** *** 139,142 **** --- 162,175 ---- } libPaths.add(args[++i]); + } else if ("-libclasses".equals(args[i])) { + if (i == args.length - 1) { + throw new LaunchException("The -libclasses argument must " + + "be followed by a directory"); + } + File dir = new File(args[++i]); + if (!dir.exists()) { + throw new LaunchException("Missing libclasses :" + dir); + } + libPathURLs.add(dir.toURL()); } else if ("-cp".equals(args[i])) { if (i == args.length - 1) { *************** *** 152,155 **** --- 185,191 ---- "-noclasspath".equals(args[i])) { noClassPath = true; + } else if ("-debug".equals(args[i])) { + //debugging otions + level = Level.FINEST; } else { argList.add(args[i]); *************** *** 157,170 **** } ! //decide whether to copy the existing arg set, or ! //build a new one from the list of all args excluding the special ! //operations that only we handle ! if (libPaths.size() == 0 && cpString == null) { ! newArgs = args; } else { ! newArgs = (String[]) argList.toArray(new String[0]); } ! List libPathURLs = new ArrayList(); if (cpString != null && !noClassPath) { --- 193,240 ---- } ! String sfHomeProperty = System.getProperty(SFHOME_PROPERTY); ! if (sfHomeProperty == null) { ! sfHomeProperty = System.getenv(SFHOME_ENV_VARIABLE); ! } ! File home = null; ! ! File sourceJar = Locator.getClassSource(getClass()); ! ! //get the dir we came from too. ! File jarDir; ! if (sourceJar.isDirectory()) { ! jarDir = sourceJar; } else { ! jarDir = sourceJar.getParentFile(); } ! if (sfHomeProperty != null) { ! home = new File(sfHomeProperty); ! } ! /* ! if (home == null || !home.exists()) { ! home = jarDir.getParentFile(); ! System.setProperty(SFHOME_PROPERTY, home.getAbsolutePath()); ! } ! */ ! ! if (!home.exists()) { ! throw new LaunchException("SFHOME environment variable or sf.home property is not set correctly; " ! + "SmartFrog could not be located"); ! } ! ! ! //add in the 2ary file if it exists, bail out if not ! File secondary = new File(jarDir, SECONDARY_JAR); ! if (!secondary.exists()) { ! //throw new LaunchException("No secondary JAR found at "+secondary); ! log.warning("No secondary JAR found at " + secondary); ! } ! libPaths.add(secondary); ! ! //build a new set of params from the list of all args excluding the special ! //operations that only we handle ! newArgs = (String[]) argList.toArray(new String[0]); ! if (cpString != null && !noClassPath) { *************** *** 173,177 **** for (Iterator i = libPaths.iterator(); i.hasNext();) { ! String libPath = (String) i.next(); addPath(libPath, true, libPathURLs); } --- 243,247 ---- for (Iterator i = libPaths.iterator(); i.hasNext();) { ! String libPath = i.next().toString(); addPath(libPath, true, libPathURLs); } *************** *** 179,199 **** URL[] libJars = (URL[]) libPathURLs.toArray(new URL[0]); ! // determine ant library directory for system jars: use property ! // or default using location of ant-launcher.jar ! File antLibDir = null; ! String antLibDirProperty = System.getProperty(SFHOME_PROPERTY); ! if (antLibDirProperty != null) { ! antLibDir = new File(antLibDirProperty); ! } ! if ((antLibDir == null) || !antLibDir.exists()) { ! antLibDir = jarDir; ! System.setProperty(SFHOME_PROPERTY, ! antLibDir.getAbsolutePath()); } ! URL[] systemJars = Locator.getLocationURLs(antLibDir); ! int numJars = libJars.length + systemJars.length; URL[] jars = new URL[numJars]; System.arraycopy(libJars, 0, jars, 0, libJars.length); --- 249,265 ---- URL[] libJars = (URL[]) libPathURLs.toArray(new URL[0]); + //fetch all JARs in the SFHOME dir ! File libdir = new File(home + LIB_SUBDIR); ! if (!libdir.exists()) { ! throw new LaunchException("No library directory " + libdir); } ! URL[] systemJars = Locator.getLocationURLs(libdir); int numJars = libJars.length + systemJars.length; + if (numJars == 0) { + throw new LaunchException( + "No JARs found in " + home + " or on the command line"); + } URL[] jars = new URL[numJars]; System.arraycopy(libJars, 0, jars, 0, libJars.length); *************** *** 204,208 **** // now update the class.path property StringBuffer baseClassPath ! = new StringBuffer(System.getProperty("java.class.path")); if (baseClassPath.charAt(baseClassPath.length() - 1) == File.pathSeparatorChar) { --- 270,274 ---- // now update the class.path property StringBuffer baseClassPath ! = new StringBuffer(System.getProperty(JAVA_CLASSPATH)); if (baseClassPath.charAt(baseClassPath.length() - 1) == File.pathSeparatorChar) { *************** *** 215,229 **** } ! System.setProperty("java.class.path", baseClassPath.toString()); URLClassLoader loader = new URLClassLoader(jars); Thread.currentThread().setContextClassLoader(loader); ! LauncherInfo info = new LauncherInfo(); ! info.jars = jars; ! info.classloader = loader; ! info.processedArgs = newArgs; ! return info; } /** * this is the launcher info that we return --- 281,313 ---- } ! LauncherInfo subprocess = new LauncherInfo(); ! ! String newClasspath = baseClassPath.toString(); ! subprocess.setProperty(JAVA_CLASSPATH, newClasspath); ! subprocess.setProperty(SFHOME_PROPERTY, home.getAbsolutePath()); URLClassLoader loader = new URLClassLoader(jars); Thread.currentThread().setContextClassLoader(loader); ! subprocess.jars = jars; ! log("jars = " + makeString(jars)); ! subprocess.classloader = loader; ! log("args = " + makeString(newArgs)); ! subprocess.processedArgs = newArgs; ! return subprocess; ! } ! ! public static String makeString(Object[] array) { ! StringBuffer buffer = new StringBuffer(); ! buffer.append('['); ! if (array != null) { ! for (int i = 0; i < array.length; i++) { ! buffer.append(array[i].toString()); ! } ! } ! buffer.append(']'); ! return buffer.toString(); } + /** * this is the launcher info that we return *************** *** 242,245 **** --- 326,335 ---- public ClassLoader classloader; + public Properties properties = new Properties(); + + public void setProperty(String name, String value) { + properties.setProperty(name, value); + } + /** * construct a new classloader and create an isntance of our process *************** *** 251,259 **** */ WrappedEntryPoint load() throws IllegalAccessException, ! InstantiationException, ClassNotFoundException { URLClassLoader loader = new URLClassLoader(jars); //Thread.currentThread().setContextClassLoader(loader); ! Class mainClass = loader.loadClass(MAIN_CLASS); ! return (WrappedEntryPoint) mainClass.newInstance(); } } --- 341,397 ---- */ WrappedEntryPoint load() throws IllegalAccessException, ! InstantiationException, ClassNotFoundException, ! LaunchException { ! log("loading \n" + this); URLClassLoader loader = new URLClassLoader(jars); //Thread.currentThread().setContextClassLoader(loader); ! Class mainClass = null; ! try { ! mainClass = loader.loadClass(MAIN_CLASS); ! } catch (ClassNotFoundException e) { ! log("Class not found " + MAIN_CLASS, e); ! throw e; ! } catch (NoClassDefFoundError e) { ! log("No class Def found" + e.getMessage(), e); ! throw e; ! } ! //set the system properties ! Enumeration it = properties.keys(); ! while (it.hasMoreElements()) { ! String key = (String) it.nextElement(); ! String value = (String) properties.get(key); ! log("Property " + key + " = " + value); ! System.setProperty(key, value); ! } ! ! WrappedEntryPoint entryPoint = (WrappedEntryPoint) mainClass.newInstance(); ! entryPoint.setArgs(processedArgs); ! return entryPoint; ! } ! ! /** ! * for debugging ! * ! * @return args and jars ! */ ! public String toString() { ! return "Args :" + ! makeString(processedArgs) ! + "\nJARS:" + makeString(jars); ! } ! ! /** ! * declare that we are a root process ! */ ! public void addRootProcessProperty() { ! setProperty("org.smartfrog.sfcore.processcompound.sfProcessName;", ! "rootProcess"); ! } ! ! /** ! * force security on ! */ ! public void forceSecurity() { ! setProperty("org.smartfrog.sfcore.security.required", "true"); } } Index: WrappedEntryPoint.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/wrapper/src/org/smartfrog/extras/wrapper/WrappedEntryPoint.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WrappedEntryPoint.java 8 Dec 2004 17:31:01 -0000 1.1 --- WrappedEntryPoint.java 2 Mar 2005 18:39:45 -0000 1.2 *************** *** 41,46 **** int getExitCode(); - String[] getArgs(); - boolean isSystemExitOnRootProcessTermination(); --- 41,44 ---- *************** *** 57,59 **** --- 55,61 ---- */ int getExpectedShutdownTime(); + + String[] getArgs(); + + void setArgs(String[] args); } Index: ServiceWrapper.java =================================================================== RCS file: /cvsroot/smartfrog/core/extras/wrapper/src/org/smartfrog/extras/wrapper/ServiceWrapper.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ServiceWrapper.java 28 Feb 2005 17:55:06 -0000 1.4 --- ServiceWrapper.java 2 Mar 2005 18:39:45 -0000 1.5 *************** *** 115,119 **** out.println("\n\n"); //env variables are only valid on Java1.5+ ! printEnvVar("SFHOME", out); printEnvVar("CLASSPATH", out); printEnvVar("PATH", out); --- 115,119 ---- out.println("\n\n"); //env variables are only valid on Java1.5+ ! printEnvVar(Launcher.SFHOME_ENV_VARIABLE, out); printEnvVar("CLASSPATH", out); printEnvVar("PATH", out); *************** *** 145,148 **** --- 145,150 ---- Launcher.LauncherInfo info = launcher.prelaunch(args); wrappedEntryPoint = info.load(); + } catch (LaunchException exception) { + throw exception; } catch (Exception exception) { throw new LaunchException(WRAPPER_FAILURE_EXIT_CODE, |