[Mathlib-commitlog] SF.net SVN: mathlib:[849] JMathLib/trunk/src/jmathlib/toolbox/jmathlib/ system
Status: Beta
Brought to you by:
st_mueller
|
From: <st_...@us...> - 2009-02-15 10:20:35
|
Revision: 849
http://mathlib.svn.sourceforge.net/mathlib/?rev=849&view=rev
Author: st_mueller
Date: 2009-02-15 10:20:32 +0000 (Sun, 15 Feb 2009)
Log Message:
-----------
new update manager
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/toolbox/jmathlib/system/checkforupdates.java
JMathLib/trunk/src/jmathlib/toolbox/jmathlib/system/update.java
Modified: JMathLib/trunk/src/jmathlib/toolbox/jmathlib/system/checkforupdates.java
===================================================================
--- JMathLib/trunk/src/jmathlib/toolbox/jmathlib/system/checkforupdates.java 2009-02-15 05:12:08 UTC (rev 848)
+++ JMathLib/trunk/src/jmathlib/toolbox/jmathlib/system/checkforupdates.java 2009-02-15 10:20:32 UTC (rev 849)
@@ -3,6 +3,7 @@
import jmathlib.core.tokens.*;
import jmathlib.core.functions.ExternalFunction;
import jmathlib.core.interpreter.GlobalValues;
+import jmathlib.core.interpreter.ErrorLogger;
import java.net.*;
import java.util.*;
@@ -18,11 +19,12 @@
public OperandToken evaluate(Token[] operands, GlobalValues _globals)
{
+ // copy pointer to globals
globals = _globals;
String s = "";
String lineFile = "";
- String updateSiteS = "http://www.jmathlib.de/checkForUpdates/";
+ String updateSiteS = "http://www.jmathlib.de/updates/";
boolean silentB = false;
s = globals.getProperty("update.site.primary");
@@ -42,8 +44,8 @@
}
else
{
- updateSiteS = s;
- globals.getInterpreter().displayText("Update Site "+updateSiteS);
+ updateSiteS = st;
+ globals.getInterpreter().displayText("New Update Site "+updateSiteS);
}
}
}
@@ -75,10 +77,6 @@
//getInterpreter().displayText("calCur "+calCur);
- //if (calCur.after(calFile))
- // getInterpreter().displayText("AFTER: TRUE" );
- //else
- // getInterpreter().displayText("AFTER: FALSE" );
if (silentB)
{
@@ -115,16 +113,24 @@
System.out.println("checkForUpdates: constructor");
}
+ /**
+ * separate thread which checks the update site
+ * It is a thread in order to cause no time delay for the user.
+ */
public synchronized void run()
{
String s;
+
// open URL
URL url = null;
try
{
- url = new URL(updateSiteS);
+ // get local version of jmathlib
+ String localVersionS = globals.getProperty("jmathlib.version").replaceAll("/", ".");
+
+ url = new URL(updateSiteS+"?jmathlib_version="+localVersionS+"&command=check");
}
catch (Exception e)
{
@@ -142,77 +148,50 @@
System.out.println("checkForUpdates: Properties error");
}
- String[] localVersionS = globals.getProperty("jmathlib.version").replace("/",".").split("\\.");
- String[] webVersionS = props.getProperty("jmathlib.version").replace("/",".").split("\\.");
+ String localVersionS = globals.getProperty("jmathlib.version");
+ String updateVersionS = props.getProperty("update.toversion");
+ String updateActionS = props.getProperty("update.action");
- // build version number of local version
- // e.g. 2.6.7 -> 20607
- int localVersion =0;
-
- if (localVersionS.length==3)
- {
- localVersion += Integer.parseInt(localVersionS[0]) * 100 * 100;
- localVersion += Integer.parseInt(localVersionS[1]) * 100;
- localVersion += Integer.parseInt(localVersionS[2]);
- }
-
- // build version number of web version
- // e.g. 2.6.7 -> 20607
- int webVersion=0;
-
- if (webVersionS.length==3)
+ // evaluate the response from the web server
+ if (updateActionS.equals("INCREMENTAL_DOWNLOAD"))
{
- webVersion += Integer.parseInt(webVersionS[0]) * 100 * 100;
- webVersion += Integer.parseInt(webVersionS[1]) * 100;
- webVersion += Integer.parseInt(webVersionS[2]);
- }
-
- // check version number of web version against local version
- if (webVersion > localVersion)
- {
-
- // set marker for next startup
- globals.setProperty("update.newversionavailable","yes");
- s = props.getProperty("update.newversionavailable.message01");
- if (s!=null)
+ if (!silentB)
{
- globals.setProperty("update.newversionavailable.message01", s);
- globals.getInterpreter().displayText(s);
+ globals.getInterpreter().displayText("A full download ist required");
+ globals.getInterpreter().displayText("A new version "+ updateVersionS +" is available");
+ globals.getInterpreter().displayText("\n Just type update at the prompt.");
}
- else
- globals.getInterpreter().displayText("There is a new version of JMathLib available");
-
- s = props.getProperty("update.newversionavailable.message02");
- if (s!=null)
+ }
+ else if (updateActionS.equals("FULL_DOWNLOAD_REQUIRED"))
+ {
+ if (!silentB)
{
- globals.setProperty("update.newversionavailable.message02", s);
- globals.getInterpreter().displayText(s);
+ globals.getInterpreter().displayText("A full download ist required");
+ globals.getInterpreter().displayText("A new version "+ updateVersionS +" is available");
+ globals.getInterpreter().displayText("Go to www.jmathlib.de and download the latest version");
}
}
- else if (webVersion < localVersion)
+ else if (updateActionS.equals("NO_ACTION"))
{
- globals.getInterpreter().displayText("Funny! The version of JMathLib on the web is older than your local version");
+ if (!silentB)
+ globals.getInterpreter().displayText("The local version of JMathLib is up to date");
+
}
- else
+ else if (updateActionS.equals("VERSION_UNKNOWN"))
{
if (!silentB)
- {
- globals.getInterpreter().displayText("The local version of JMathLib is up to date");
+ globals.getInterpreter().displayText("The local version of JMathLib ist not recognized by the server");
- s=props.getProperty("update.uptodate.message01");
- if (s!=null)
- globals.getInterpreter().displayText(s);
-
- s=props.getProperty("update.uptodate.message02");
- if (s!=null)
- globals.getInterpreter().displayText(s);
- }
}
+ else
+ {
+ // wrong or unknown or empty "action"-command
+ globals.getInterpreter().displayText("check for updates encountered an error.");
+ }
-
- debugLine("checkForUpdates: web:" +webVersion +" local:"+ localVersion);
+ debugLine("checkForUpdates: web:" + updateVersionS +" local:"+ localVersionS);
// set current date for property "update.date.last"
Calendar cal = Calendar.getInstance();
@@ -222,21 +201,18 @@
globals.setProperty("update.date.last", checkedDate);
- // update link to primary update-site
- s= props.getProperty("update.site.primary");
- if (s!=null)
- globals.setProperty("update.site.primary",s);
+
+ // copy properties from webserver to global properties
+ Enumeration propnames = props.propertyNames();
+ while (propnames.hasMoreElements())
+ {
+ String propName = (String)propnames.nextElement();
+ String propValue = (String)props.getProperty(propName);
+ ErrorLogger.debugLine("Property: "+propName+" = "+propValue);
+ globals.setProperty(propName, propValue);
+ }
- // update link to backup update-site
- s= props.getProperty("update.site.backup");
- if (s!=null)
- globals.setProperty("update.site.backup",s);
- // update message of the day
- s= props.getProperty("message.of.the.day");
- if (s!=null)
- globals.setProperty("message.of.the.day",s);
-
}
}
Modified: JMathLib/trunk/src/jmathlib/toolbox/jmathlib/system/update.java
===================================================================
--- JMathLib/trunk/src/jmathlib/toolbox/jmathlib/system/update.java 2009-02-15 05:12:08 UTC (rev 848)
+++ JMathLib/trunk/src/jmathlib/toolbox/jmathlib/system/update.java 2009-02-15 10:20:32 UTC (rev 849)
@@ -25,7 +25,6 @@
// get local version of jmathlib
String localVersionS = globals.getProperty("jmathlib.version");
- localVersionS = localVersionS.replaceAll("/", ".");
globals.getInterpreter().displayText("current version: "+localVersionS);
@@ -33,12 +32,11 @@
globals.getInterpreter().displayText("Checking to which version an update is possible");
- // url of the update site including the request for the version
- // to update to
+ // url of the update site including the request for the version to update to
URL url = null;
try
{
- url = new URL(updateSiteS+"updates/?jmathlib_version="+localVersionS);
+ url = new URL(updateSiteS+"?jmathlib_version="+localVersionS+"&command=update");
}
catch (Exception e)
{
@@ -58,148 +56,217 @@
successB = false;
}
-
+
// Check return properties for "update-to-version"
// Update site could send a lot of properties
String updateVersionS = props.getProperty("update.toversion");
- if (updateVersionS.equals("no_update_available"))
+ String updateActionS = props.getProperty("update.action");
+
+ // reaction on the response from the update server
+ if (updateActionS.equals("VERSION_UNKNOWN"))
{
+ globals.getInterpreter().displayText("Your version of JMathLib is not known by the update server.");
+ return null;
+ }
+ else if (updateVersionS.equals("NO_UPDATE_AVAILABLE") ||
+ updateActionS.equals("NO_ACTION") )
+ {
globals.getInterpreter().displayText("No update available right now.");
return null;
}
-
- if (updateVersionS.equals("full_download_required"))
+ else if (updateActionS.equals("FULL_DOWNLOAD_REQUIRED"))
{
globals.getInterpreter().displayText("\n");
globals.getInterpreter().displayText("Full download required in order to update!");
globals.getInterpreter().displayText("Please visit www.jmathlib.de for details.");
globals.getInterpreter().displayText("\n");
+ String urlS = props.getProperty("update.full_file_url");
+ String fileS = props.getProperty("update.file_name");
+ globals.getInterpreter().displayText("url: "+urlS);
+ globals.getInterpreter().displayText("file: "+fileS);
+
+ if ((urlS==null) || (fileS==null))
+ return null;
+
+
+ // put a message box here
+
+ // open URL to file on update server
+ try
+ {
+ globals.getInterpreter().displayText("Downloading ...");
+ URL fileURL = new URL(urlS);
+ InputStream in = fileURL.openStream();
+
+ // open file on local disc
+ File file = new File(globals.getWorkingDirectory(),fileS);
+ OutputStream out = new FileOutputStream(file);
+ byte[] cbuf = new byte[4096];
+ int len = -1;
+
+ while ((len = in.read(cbuf)) != -1)
+ {
+ out.write(cbuf,0,len);
+ }
+
+ in.close();
+ out.close();
+ globals.getInterpreter().displayText("Downloading done.");
+ }
+ catch (Exception e)
+ {
+ successB = false;
+ globals.getInterpreter().displayText("update: problem downloading "+fileS);
+ }
+
+
+ // run the downloaded file
+ try
+ {
+ globals.getInterpreter().displayText("Running installer ...");
+ Runtime.getRuntime().exec(fileS);
+ globals.getInterpreter().displayText("Please exit JMathLib");
+ }
+ catch(IOException exception)
+ {
+ throwMathLibException("SystemCommand");
+ }
+
+
return null;
}
+ else if (updateActionS.equals("INCREMENTAL_DOWNLOAD"))
+ {
- globals.getInterpreter().displayText("updating to version >"+updateVersionS+"< \n");
+ globals.getInterpreter().displayText("updating to version >"+updateVersionS+"< \n");
- // download new files from server
- updateSiteS += "updates/jmathlib_" + updateVersionS + "/";
- try
- {
- url = new URL(updateSiteS);
- }
- catch (Exception e)
- {
- throwMathLibException("update: malformed url");
- successB = false;
- }
-
- BufferedReader inR = null;
- try
- {
- inR = new BufferedReader(new InputStreamReader(url.openStream()));
- String s = null;
-
- // read next line from server
- while ((s = inR.readLine()) != null )
+ // download new files from server
+ updateSiteS += "jmathlib_" + updateVersionS + "/";
+ try
{
- //getInterpreter().displayText("update "+s);
+ url = new URL(updateSiteS);
+ }
+ catch (Exception e)
+ {
+ throwMathLibException("update: malformed url");
+ successB = false;
+ }
+
+ try
+ {
+ BufferedReader inR = new BufferedReader(new InputStreamReader(url.openStream()));
+ String s = null;
- if (s.startsWith("file"))
+ // read next line from server
+ while ((s = inR.readLine()) != null )
{
- // read a file from the server and place it on the local disc
- String fileS = s.substring(5).trim();
- globals.getInterpreter().displayText("new file: >"+fileS+"<");
+ //getInterpreter().displayText("update "+s);
- // open URL to file on update server
- try
+ if (s.startsWith("file"))
{
- URL fileURL = new URL(updateSiteS+fileS);
- InputStream in = fileURL.openStream();
-
- // open file on local disc
- File file = new File(globals.getWorkingDirectory(),fileS);
- OutputStream out = new FileOutputStream(file);
-
- byte[] cbuf = new byte[4096];
- int len;
- while ((len = in.read(cbuf)) != -1)
+ // read a file from the server and place it on the local disc
+ String fileS = s.substring(5).trim();
+ globals.getInterpreter().displayText("new file: >"+fileS+"<");
+
+ // open URL to file on update server
+ try
{
- out.write(cbuf,0,len);
+ URL fileURL = new URL(updateSiteS+fileS);
+ InputStream in = fileURL.openStream();
+
+ // open file on local disc
+ File file = new File(globals.getWorkingDirectory(),fileS);
+ OutputStream out = new FileOutputStream(file);
+ byte[] cbuf = new byte[4096];
+ int len = -1;
+
+ while ((len = in.read(cbuf)) != -1)
+ {
+ out.write(cbuf,0,len);
+ }
+
+ in.close();
+ out.close();
}
+ catch (Exception e)
+ {
+ successB = false;
+ globals.getInterpreter().displayText("update: problem downloading "+fileS);
+ }
- in.close();
- out.close();
}
- catch (Exception e)
+ else if (s.startsWith("dir"))
{
- successB = false;
- globals.getInterpreter().displayText("update: problem downloading "+fileS);
+ // create a directory on the local disc
+ String dirS = s.substring(4).trim();
+ globals.getInterpreter().displayText("new directory: >"+dirS+"<");
+ try
+ {
+ File file = new File(globals.getWorkingDirectory(),dirS);
+ file.mkdir();
+ }
+ catch (Exception e)
+ {
+ successB = false;
+ globals.getInterpreter().displayText("update: problem creating directory "+dirS);
+ }
+
}
-
- }
- else if (s.startsWith("dir"))
- {
- // create a directory on the local disc
- String dirS = s.substring(4).trim();
- globals.getInterpreter().displayText("new directory: >"+dirS+"<");
- try
+ else if (s.startsWith("del"))
{
- File file = new File(globals.getWorkingDirectory(),dirS);
- file.mkdir();
+ // delete a file/directory on the local disc
+ String delS = s.substring(4).trim();
+ globals.getInterpreter().displayText("delete file/dir: >"+delS+"<");
+ try
+ {
+ File file = new File(globals.getWorkingDirectory(),delS);
+ file.delete();
+ }
+ catch (Exception e)
+ {
+ successB = false;
+ globals.getInterpreter().displayText("update: problem deleting "+delS);
+ }
}
- catch (Exception e)
+ else if (s.startsWith("prop"))
{
- successB = false;
- globals.getInterpreter().displayText("update: problem creating directory "+dirS);
+ // delete a file/directory on the local disc
+ String propS = s.substring(5).trim();
+ globals.getInterpreter().displayText("new property: >"+propS+"<");
+ String[] p = propS.split("=");
+ globals.setProperty(p[0],p[1]);
}
-
- }
- else if (s.startsWith("del"))
- {
- // delete a file/directory on the local disc
- String delS = s.substring(4).trim();
- globals.getInterpreter().displayText("delete file/dir: >"+delS+"<");
- try
+ else
{
- File file = new File(globals.getWorkingDirectory(),delS);
- file.delete();
+ // empty line or unknown command or comment
}
- catch (Exception e)
- {
- successB = false;
- globals.getInterpreter().displayText("update: problem deleting "+delS);
- }
+
+ // in case something went wrong terminate
+ if (!successB)
+ break;
+
}
- else if (s.startsWith("prop"))
- {
- // delete a file/directory on the local disc
- String propS = s.substring(5).trim();
- globals.getInterpreter().displayText("new property: >"+propS+"<");
- String[] p = propS.split("=");
- globals.setProperty(p[0],p[1]);
- }
- else
- {
- // empty line or unknown command or comment
- }
-
- // in case something went wrong terminate
- if (!successB)
- break;
-
+
}
+ catch (Exception e)
+ {
+ throwMathLibException("update: open or reading stream");
+ }
+
+
+ }
+ else
+ {
+ throwMathLibException("update: unknown action");
+ }
- }
- catch (Exception e)
- {
- throwMathLibException("update: open or reading stream");
- }
-
-
// notifiy user
if (!successB)
globals.getInterpreter().displayText("\n Update was not successful. Repeat again later on or inform the admin.");
- return null;
+ return null;
+
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|