Revision: 3822 http://vexi.svn.sourceforge.net/vexi/?rev=3822&view=rev Author: clrg Date: 2010-03-24 17:24:20 +0000 (Wed, 24 Mar 2010)
Log Message: ----------- - remove System.exit(0) call -> an attempt to fix launcher crashing browser - smarten up code, remove tabs Modified Paths: -------------- trunk/launch/org.vexi.launch/build_launcher.ent trunk/launch/org.vexi.launch/src/org/vexi/launcher/Launcher.java trunk/launch/org.vexi.launch/src_vexi/org/vexi/launcher/VexiLauncher.java Modified: trunk/launch/org.vexi.launch/build_launcher.ent =================================================================== --- trunk/launch/org.vexi.launch/build_launcher.ent 2010-03-23 01:48:51 UTC (rev 3821) +++ trunk/launch/org.vexi.launch/build_launcher.ent 2010-03-24 17:24:20 UTC (rev 3822) @@ -1,117 +1,116 @@ <project default="sign" name="Configurable Launcher Ant Build"> - <!-- IMPORT TASKS --> - <property name="build.common.dir" location="../build.vexi.common"/> - <import file="${build.common.dir}/build_common.ent"/> - - <!-- CONFIGURATION --> - <property name="src_crypto" location="../org.ibex.crypto/src"/> - <property name="src" location="../org.vexi.launcher/src"/> - - <target name="genconf"> - <fail unless="param.src_gen"/> - <fail unless="param.packagedir"/> - <fail unless="param.package"/> - <property name="gen" value="${param.src_gen}"/> - - </target> - - <target name="buildconf"> - <fail unless="param.build"/> - <fail unless="param.jarname"/> - <fail unless="param.src_conf"/> - <!-- optional param.noshrink --> - - <property name="jar.compiled" value="_${param.jarname}_compiled.jar" /> - <property name="jar.shrunk" value="_${param.jarname}_shrunk.jar" /> - <property name="build.dir" location="build_${param.build}"/> - <property name="class" location="${build.dir}/${param.jarname}/class" /> - <property name="param.src_gen" location="${build.dir}/${param.jarname}/pp"/> - - </target> - - <target name="clean"> - <delete dir="${build.dir}" /> - </target> - - <target name="init" depends="buildconf"> - <tstamp/> - <mkdir dir="${class}" /> - </target> + <!-- IMPORT TASKS --> + <property name="build.common.dir" location="../build.vexi.common"/> + <import file="${build.common.dir}/build_common.ent"/> + + <!-- CONFIGURATION --> + <property name="src_crypto" location="../org.ibex.crypto/src"/> + <property name="src" location="../org.vexi.launcher/src"/> + + <target name="genconf"> + <fail unless="param.src_gen"/> + <fail unless="param.packagedir"/> + <fail unless="param.package"/> + <property name="gen" value="${param.src_gen}"/> + + </target> + + <target name="buildconf"> + <fail unless="param.build"/> + <fail unless="param.jarname"/> + <fail unless="param.src_conf"/> + <!-- optional param.noshrink --> + + <property name="jar.compiled" value="_${param.jarname}_compiled.jar" /> + <property name="jar.shrunk" value="_${param.jarname}_shrunk.jar" /> + <property name="build.dir" location="build_${param.build}"/> + <property name="class" location="${build.dir}/${param.jarname}/class" /> + <property name="param.src_gen" location="${build.dir}/${param.jarname}/pp"/> + + </target> + + <target name="clean"> + <delete dir="${build.dir}" /> + </target> + + <target name="init" depends="buildconf"> + <tstamp/> + <mkdir dir="${class}" /> + </target> - <target name="generate" depends="genconf"> - - <mkdir dir="${gen}/${param.packagedir}" /> - <echo file="${gen}/${param.packagedir}/Version.java"> + <target name="generate" depends="genconf"> + + <mkdir dir="${gen}/${param.packagedir}" /> + <echo file="${gen}/${param.packagedir}/Version.java">// Automatically generated package ${param.package}; -public class Version{ + +public class Version { static public String version="${param.build}"; -} - </echo> - </target> +}</echo> + </target> - <target name="compile" depends="init,generate"> + <target name="compile" depends="init,generate"> - - <copy todir="${class}"> - <fileset dir="${param.src_conf}" includes="**/*.dat,**/*.txt"/> - </copy> - <javac destdir="${class}" - source="1.3" - target="1.3" > - <src path="${src_crypto}"/> - <src path="${src}"/> - <src path="${gen}"/> - <src path="${param.src_conf}"/> - <exclude name="org/ibex/net/ssl/*.*"/> - </javac> + + <copy todir="${class}"> + <fileset dir="${param.src_conf}" includes="**/*.dat,**/*.txt"/> + </copy> + <javac destdir="${class}" + source="1.3" + target="1.3" > + <src path="${src_crypto}"/> + <src path="${src}"/> + <src path="${gen}"/> + <src path="${param.src_conf}"/> + <exclude name="org/ibex/net/ssl/*.*"/> + </javac> - </target> + </target> - <target name="build" depends="compile"> - <property name="outdir" value="${build.dir}"/> - <jar destfile="${build.dir}/${jar.compiled}"> - <manifest> - <attribute name="Built-By" value="${user.name}"/> - <attribute name="Built-On" value="${DSTAMP}:${TSTAMP}"/> - </manifest> - <fileset dir="${class}" includes="**/*" /> - </jar> - </target> - - <target name="shrink" depends="build" unless="param.noshrink"> - - <!--optimize --> - <proguard> - -injars ${build.dir}/${jar.compiled} - -outjars ${build.dir}/${jar.shrunk} + <target name="build" depends="compile"> + <property name="outdir" value="${build.dir}"/> + <jar destfile="${build.dir}/${jar.compiled}"> + <manifest> + <attribute name="Built-By" value="${user.name}"/> + <attribute name="Built-On" value="${DSTAMP}:${TSTAMP}"/> + </manifest> + <fileset dir="${class}" includes="**/*" /> + </jar> + </target> + + <target name="shrink" depends="build" unless="param.noshrink"> + + <!--optimize --> + <proguard> + -injars ${build.dir}/${jar.compiled} + -outjars ${build.dir}/${jar.shrunk} - -libraryjars <java.home>/lib/rt.jar - -dontobfuscate - -allowaccessmodification + -libraryjars <java.home>/lib/rt.jar + -dontobfuscate + -allowaccessmodification - <!-- The entry point --> - -keep public class ${param.appletclass} - </proguard> - - <property name="jar.signee" value="${jar.shrunk}"/> - <property name="jar.signed" value="${param.jarname}.jar"/> - </target> - - <target name="sign" depends="build,shrink"> - <property name="jar.signee" value="${jar.compiled}"/> - <property name="jar.signed" value="${param.jarname}_noshrink.jar"/> - <property name="storepass" value="password"/> - <property name="keypass" value="password"/> - <signjar alias="launcher" - keypass="${keypass}" - storepass="${storepass}" - jar="${build.dir}/${jar.signee}" - signedjar="${outdir}/${jar.signed}"/> - </target> - - + <!-- The entry point --> + -keep public class ${param.appletclass} + </proguard> + + <property name="jar.signee" value="${jar.shrunk}"/> + <property name="jar.signed" value="${param.jarname}.jar"/> + </target> + + <target name="sign" depends="build,shrink"> + <property name="jar.signee" value="${jar.compiled}"/> + <property name="jar.signed" value="${param.jarname}_noshrink.jar"/> + <property name="storepass" value="password"/> + <property name="keypass" value="password"/> + <signjar alias="launcher" + keypass="${keypass}" + storepass="${storepass}" + jar="${build.dir}/${jar.signee}" + signedjar="${outdir}/${jar.signed}"/> + </target> + </project> Modified: trunk/launch/org.vexi.launch/src/org/vexi/launcher/Launcher.java =================================================================== --- trunk/launch/org.vexi.launch/src/org/vexi/launcher/Launcher.java 2010-03-23 01:48:51 UTC (rev 3821) +++ trunk/launch/org.vexi.launch/src/org/vexi/launcher/Launcher.java 2010-03-24 17:24:20 UTC (rev 3822) @@ -21,17 +21,17 @@ abstract public class Launcher extends Applet { // REMARK although a signed applet doesn't have any known securities - // we restrict it to running from domains that we control because in - // the event that it is compromised we can update the copy on these - // domains. In this way the fetching of the applet acts as the security - // check. - abstract public String[] getPermittedDomains(); - abstract public Map getCerts(); - abstract public String getVersion(); - - //////////////// - // INIT + // we restrict it to running from domains that we control because in + // the event that it is compromised we can update the copy on these + // domains. In this way the fetching of the applet acts as the security + // check. + abstract public String[] getPermittedDomains(); + abstract public Map getCerts(); + abstract public String getVersion(); + //////////////// + // INIT + DotVexi dotvexi; static protected void logflush() { @@ -64,9 +64,11 @@ p = Runtime.getRuntime().exec(cmd); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String s; - while ((s = br.readLine()) != null) - if (s.startsWith(name + "=")) + while ((s = br.readLine()) != null) { + if (s.startsWith(name + "=")) { return s.substring(name.length() + 1); + } + } } catch (Throwable t2) { log("Encountered an exception during fallback discovery of: '"+name+"'"); t2.printStackTrace(); @@ -79,8 +81,12 @@ static private String findInJavaHome(String os_name, String javaHome) { if (javaHome != null && !javaHome.equals("")) { String r = javaHome + File.separatorChar + "bin" + File.separatorChar + "java"; - if (os_name.indexOf("windows") != -1) { r += ".exe"; } - if (new File(r).exists()) return r; + if (os_name.indexOf("windows") != -1) { + r += ".exe"; + } + if (new File(r).exists()) { + return r; + } } return null; } @@ -94,27 +100,37 @@ log("Trying Environment Variable 'VEXI_JRE'"); jvmBinary = findInJavaHome(os_name,getEnv("VEXI_JRE")); - if (jvmBinary != null) return jvmBinary; + if (jvmBinary != null) { + return jvmBinary; + } log("Trying Environment Variable 'JAVA_HOME'"); jvmBinary = findInJavaHome(os_name,getEnv("JAVA_HOME")); - if (jvmBinary != null) return jvmBinary; + if (jvmBinary != null) { + return jvmBinary; + } log("Trying System Property 'java.home'"); jvmBinary = findInJavaHome(os_name,System.getProperty("java.home")); - if (jvmBinary != null) return jvmBinary; + if (jvmBinary != null) { + return jvmBinary; + } // check PATH log("Checking to see if java is on the PATH Environment Variable"); String path = getEnv("PATH"); - if (path == null) {path = getEnv("Path");} + if (path == null) { + path = getEnv("Path"); + } if (path!=null) { StringTokenizer st = new StringTokenizer(path, File.pathSeparatorChar + ""); - while(st.hasMoreTokens()) { + while (st.hasMoreTokens()) { String s = st.nextToken(); if (new File(s + File.separatorChar + "java").exists() || new File(s + File.separatorChar + "java.exe").exists() ) { jvmBinary = s + File.separatorChar + "java"; - if (os_name.indexOf("windows") != -1) {jvmBinary += ".exe";} + if (os_name.indexOf("windows") != -1) { + jvmBinary += ".exe"; + } return jvmBinary; } } @@ -125,29 +141,29 @@ - void initDotVexi(){ - dotvexi = new DotVexi(getCerts()){ - long lastDate = -1; - - protected void log(String s) { Launcher.log(s); } - - protected InputStream getInputStream(Object fountain, Object principal) throws IOException { - String url = (String)fountain; - final URLConnection uc = connect(url); - InputStream is = uc.getInputStream(); - int contentLength = uc.getContentLength(); - lastDate = uc.getLastModified(); - return progressInputStream(is, url, contentLength); - } - protected long getRemoteDate(Object fountain, Object principal) { - return lastDate; - } + void initDotVexi() { + dotvexi = new DotVexi(getCerts()) { + long lastDate = -1; + + protected void log(String s) { Launcher.log(s); } + + protected InputStream getInputStream(Object fountain, Object principal) throws IOException { + String url = (String)fountain; + final URLConnection uc = connect(url); + InputStream is = uc.getInputStream(); + int contentLength = uc.getContentLength(); + lastDate = uc.getLastModified(); + return progressInputStream(is, url, contentLength); + } + protected long getRemoteDate(Object fountain, Object principal) { + return lastDate; + } }; } /** applet entry point - this is where it all begins */ public final void init() { - initDotVexi(); + initDotVexi(); // the rest is initialized outside of the restrictive applet sandbox // as we need to download several files and start up a new process // REMARK: this requires the applet to be signed, an unsigned applet @@ -171,8 +187,8 @@ int percent = 0; private void display(){ double loaded = ((double)total) / ((double)contentLength); - int newpercent = ((int)Math.ceil(loaded * 100)); - if(newpercent!=percent){ + int newpercent = ((int)Math.ceil(loaded * 100)); + if (newpercent!=percent) { percent = newpercent; //log(percent + "%"); update((double)percent, "Downloading "+ displayname + " " + percent + "%"); @@ -181,13 +197,17 @@ public int read() throws IOException { int ret = super.read(); - if (ret != -1) total++; + if (ret != -1) { + total++; + } display(); return ret; } public int read(byte[] buf, int off, int len) throws IOException { int ret = super.read(buf, off, len); - if (ret != -1) total += ret; + if (ret != -1) { + total += ret; + } display(); return ret; } @@ -198,17 +218,23 @@ * @param url a string of an absolute url, must start with 'http://' or 'file://' * @return true iff url is permitted */ protected boolean checkUrl(String url) { - if (url.startsWith("file")) return true; + if (url.startsWith("file")) { + return true; + } if (url.startsWith("http")) { // remove the protocol url = url.substring(url.indexOf("//")+2); while (true) { - String[] permittedDomains = getPermittedDomains(); + String[] permittedDomains = getPermittedDomains(); for (int i=0; i<permittedDomains.length; i++) { - if (url.startsWith(permittedDomains[i])) return true; + if (url.startsWith(permittedDomains[i])) { + return true; + } } // if we are a subdomain remove leading part and recheck - if (url.indexOf('.')==-1) break; + if (url.indexOf('.')==-1) { + break; + } url = url.substring(url.indexOf('.')+1); } } @@ -218,55 +244,63 @@ static private String join(String[] ss) { String r = ""; for (int i=0; i<ss.length; i++) { - if (i>0) r+= ","; + if (i>0) { + r += ","; + } r += ss[i]; } return r; } - /** fetches a file from the distribution site, writing it to the appropriate place */ + /** fetches a file from the distribution site, writing it to the appropriate place */ public File fetch(String url) throws IOException { - File localfile = dotvexi.getLocalFile(url); - dotvexi.fetch(url, null, url, localfile); - return localfile; + File localfile = dotvexi.getLocalFile(url); + dotvexi.fetch(url, null, url, localfile); + return localfile; } protected File createLog(String logfile) throws IOException { - File dir = dotvexi.findSubDir("logs"); - dir.mkdirs(); - File f=null; - String fname = logfile; - for(int i=0; i<100; i++){ - f = new File(dir,fname); - if ((f.exists() && !f.delete())) { - fname = logfile+i; - continue; // file occupied! - } - if(!f.createNewFile()) break; - return f; - } - throw new RuntimeException("Could not create log file: " + f.getCanonicalPath()); + File dir = dotvexi.findSubDir("logs"); + dir.mkdirs(); + File f=null; + String fname = logfile; + for (int i=0; i<100; i++) { + f = new File(dir,fname); + if ((f.exists() && !f.delete())) { + fname = logfile+i; + continue; // file occupied! + } + if (!f.createNewFile()) { + break; + } + return f; + } + throw new RuntimeException("Could not create log file: " + f.getCanonicalPath()); } public void go() { try { - log("Launcher Build : "+getVersion()); - + log("Launcher Build : "+getVersion()); + // Check codebase is permitted String codebase = getCodeBase()+""; update(0.0, ""+codebase); //log("Codebase is "+url); - if (!checkUrl(codebase)) - permitAlternativeURL(codebase); + if (!checkUrl(codebase)) { + permitAlternativeURL(codebase); + } String core = getParameter("core"); - if (core==null) throw new Problem("Core property not set"); + if (core==null) { + throw new Problem("Core property not set"); + } String coreurl = core; - if (!coreurl.endsWith(".signed")) - permitUnsignedCore(coreurl); + if (!coreurl.endsWith(".signed")) { + permitUnsignedCore(coreurl); + } File corefile = fetch(coreurl); Vector command = new Vector(); @@ -279,19 +313,23 @@ String logfile = getParameter("logfile"); if (logfile!=null) { - createLog(logfile); - command.add("-l"); - command.add("logs/"+logfile); + createLog(logfile); + command.add("-l"); + command.add("logs/"+logfile); } for (int i = 0; i<100;i++) { - if (getParameter("option" + i) == null) break; + if (getParameter("option" + i) == null) { + break; + } command.add(getParameter("option" + i)); } for (int i = 0; i<100;i++) { String fetch = getParameter("vexi" + i); - if (fetch == null) break; + if (fetch == null) { + break; + } File f = fetch(fetch); command.add(f.getPath()); } @@ -326,39 +364,40 @@ /** spawns the Vexi core * @param command contains the full command - including java */ private void spawn(Vector command) throws IOException { - File dir = dotvexi.getBaseDir(); + File dir = dotvexi.getBaseDir(); String[] command_vec = new String[command.size()]; command.copyInto(command_vec); log("in directory : " + dir.getCanonicalPath()); log("executing : "); - for (int i=0; i<command_vec.length; i++) log(" \"" + command_vec[i] + "\""); + for (int i=0; i<command_vec.length; i++) { + log(" \"" + command_vec[i] + "\""); + } final Process p = Runtime.getRuntime().exec(command_vec,null,dir); new Thread(new Runnable() { - public void run() { - // catch output - StreamReader errorstream = new StreamReader(p.getErrorStream(), "ERROR"); + public void run() { + // catch output + StreamReader errorstream = new StreamReader(p.getErrorStream(), "ERROR"); StreamReader outputstream = new StreamReader(p.getInputStream(), "OUTPUT"); // kick off output streams errorstream.start(); outputstream.start(); - try { - update(1.0, "Vexi loaded"); - int exitValue = p.waitFor(); - if (exitValue != 0) { - update(-1,"Vexi exited abnormally with error code '"+exitValue+"', see log output"); - } else { - update(100,"Vexi has finished running"); - } - } catch (Throwable t) { - log("Error exiting... " + p.exitValue()); - t.printStackTrace(); - } - log("Exiting..."); - logflush(); - System.exit(0); - } + try { + update(1.0, "Vexi loaded"); + int exitValue = p.waitFor(); + if (exitValue != 0) { + update(-1,"Vexi exited abnormally with error code '"+exitValue+"', see log output"); + } else { + update(100,"Vexi has finished running"); + } + } catch (Throwable t) { + log("Error exiting... " + p.exitValue()); + t.printStackTrace(); + } + log("Exiting..."); + logflush(); + } }).start(); } @@ -382,8 +421,9 @@ InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line=null; - while ((line = br.readLine()) != null) + while ((line = br.readLine()) != null) { log(type + ">" + line); + } } catch (IOException ioe) { ioe.printStackTrace(); } @@ -403,9 +443,12 @@ public final void paint(Graphics g) { update(g); } public final void update(Graphics g2) { - if (backbuffer == null || backbuffer.getWidth(null) != getSize().width || backbuffer.getHeight(null) != getSize().height) + if (backbuffer == null || backbuffer.getWidth(null) != getSize().width || backbuffer.getHeight(null) != getSize().height) { backbuffer = createImage(getSize().width, getSize().height); - if (backbuffer == null) return; + } + if (backbuffer == null) { + return; + } Graphics g = backbuffer.getGraphics(); @@ -454,29 +497,27 @@ repaint(); } - static private URLConnection connect(String url) throws IOException{ - try{ - URL u = new URL(url); - final URLConnection uc = u.openConnection(); - uc.setUseCaches(false); // don't use the possibly short Java cache - uc.connect(); - return uc; - }catch(NullPointerException npe){ - // WORKAROUND - sun libraries throw a NPE rather than - // a more informative exception. - throw new IOException("Invalid url: "+url); - } + static private URLConnection connect(String url) throws IOException { + try { + URL u = new URL(url); + final URLConnection uc = u.openConnection(); + uc.setUseCaches(false); // don't use the possibly short Java cache + uc.connect(); + return uc; + } catch (NullPointerException npe) { + // WORKAROUND - sun libraries throw a NPE rather than + // a more informative exception. + throw new IOException("Invalid url: "+url); + } } ////////////// // Permission - void permitAlternativeURL(String url) throws Problem{ - throw new Problem("Applet can not be run from unknown domain " + url + "\nPermitted domains: " + join(getPermittedDomains())); + void permitAlternativeURL(String url) throws Problem { + throw new Problem("Applet can not be run from unknown domain " + url + "\nPermitted domains: " + join(getPermittedDomains())); } - void permitUnsignedCore(String file) throws Problem{ - throw new Problem("Applet will not run unsigned core file: "+ file); + void permitUnsignedCore(String file) throws Problem { + throw new Problem("Applet will not run unsigned core file: "+ file); } - - } Modified: trunk/launch/org.vexi.launch/src_vexi/org/vexi/launcher/VexiLauncher.java =================================================================== --- trunk/launch/org.vexi.launch/src_vexi/org/vexi/launcher/VexiLauncher.java 2010-03-23 01:48:51 UTC (rev 3821) +++ trunk/launch/org.vexi.launch/src_vexi/org/vexi/launcher/VexiLauncher.java 2010-03-24 17:24:20 UTC (rev 3822) @@ -6,26 +6,25 @@ import org.vexi.security.CryptoUtil; public class VexiLauncher extends Launcher { - public String getVersion() { return Version.version; } - - public String[] getPermittedDomains() { - return new String[]{"localhost", "127.0.0.1", "vexi.org", "vexi.sourceforge.net"}; - } + public String getVersion() { return Version.version; } + + public String[] getPermittedDomains() { + return new String[]{"localhost", "127.0.0.1", "vexi.org", "vexi.sourceforge.net"}; + } public Map getCerts() { - try{ - - Map organisationToPK = new HashMap(); - CryptoUtil.readCompactCADat(organisationToPK, getSignerCertsDat()); - return organisationToPK; - } catch (Throwable e) { - update(-1,"Error: applet unable to find signatory certificates"); - throw new Error(e); - } + try { + Map organisationToPK = new HashMap(); + CryptoUtil.readCompactCADat(organisationToPK, getSignerCertsDat()); + return organisationToPK; + } catch (Throwable e) { + update(-1, "Error: applet unable to find signatory certificates"); + throw new Error(e); + } } - public InputStream getSignerCertsDat() { - return getClass().getResourceAsStream ("sigcerts.dat"); - } + public InputStream getSignerCertsDat() { + return getClass().getResourceAsStream("sigcerts.dat"); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn