public class AutoUpdateApp extends Object
It executes applications... both native or Java as specified in a Properties file that gets passed to it (via a filename on the commandline). All system output from the executed app is echoed to the System.out (both regular and error output).
Its main purpose is to provide a single entrypoint to execute applications that can be dynamically specified at runtime. This allows a single deployment of this class onto a client and then tell this class what to run and where to download an update from if needed.
If you want this class to have a the name of your app; just extend this class and name it what you want... like the JOggPlayeAutoUpdate.java file.
Features:
Usage:java AutoUpdateApp
<
propertiesFilename
> OR
java -jar AutoUpdateApp.jar
<propertiesFilename
>
The properties file describes the app to execute. It has both required and optional entries as follows:
An Example Properties file might look like:
# NATIVE Remote Application Description property file appType=0 remoteAppURL=file:/c:/progra~1/tn.bat #remoteAppURL=c:\\progra~1\\tn.bat remoteAppDownloadURL= remoteAppAutoDownload=false telnetHost=10.0.0.22 2020
OR
# Java Remote Application Description property file appType=1 remoteAppURL=SimpleExample remoteAppDownloadURL=http://somesite.com/updates/MySimpleExample.jar remoteAppAutoDownload=false remoteAppJvmParameters=-Xmx64m extraParm=myParm1 anotherExtraParm=myParm2OR
# Java Remote Application Description property file appType=1 remoteAppURL=TelnetApp.jar remoteAppDownloadURL=http://somesite.com/updates/TelnetApp.jar remoteAppAutoDownload=true remoteAppJvmClasspath=/usr/local/extraclasses.jar;/usr/moreextraclasses.jar telnetHost=10.0.0.22 2020
Author: Tom Gutwin P.Eng.
Copyright (C) 2002-2003 WebARTS
Design, North Vancouver Canada. All Rights Reserved.
Modifier and Type | Field and Description |
---|---|
static String |
APPLET_APP
Class Constant specifying that the app to run is a Java Applet
|
protected static String |
appName_
This var should be defined by an extending class (not required)
|
protected static String |
appPropertyFilename_
The default property filename to use.
|
private static String |
appType_
Remote Launch Parm specifying the remote lauch app type (required).
|
private static boolean |
archiveDownload_
A class var to indicate if the download URL is pointing to an archive file
(ie jar file) instead of the actual executable file.
|
private static String |
archiveFilePath_
The system dependant file path for the downloaded archive file.
|
(package private) static String |
CLASSPATH
this VM classpath
|
private static Vector |
cmdLineParms_
A table of strings holding any extra parameter properties that were passed
in the properties file.
|
private static String |
DEFAULT_SAVE_LOCATION
A holder for the directory location to save downloaded apps.
|
private static Vector |
definedPropertyKeys
A helper Vector that keeps a table of the Defined Properties.
|
private static String |
errorMsg_
A class var to record and error message to print out if any of the
validation checks on the properties fail.
|
private static String |
filePath_
The system dependant file path to execute.
|
static String |
HTTPURL_APP
Class Constant specifying that the app to run is a URL Locationto view
using the native webbrowser.
|
static String |
JAVA_APP
Class Constant specifying that the app to run is a Java application
|
private static String |
jvmClasspath_
Remote Launch Parm specifying the any extra classpath parms to put at the
front of the classpath when the calling the jvm.
|
private static String |
jvmParameters_
Remote Launch Parm specifying the any extra commandline parms to send
directly to the jvm.
|
static String |
NATIVE_APP
Class Constant specifying that the app to run is a native application
|
private static boolean |
remoteAppAutoDownload_
Remote Launch Parm specifying the flag (boolean string val) that specifies
if the RemoteLaunchOperation Operation should query the
download server for updated app files.
|
private static URL |
remoteAppDownloadURL_
Remote Launch Parm specifying the URL of the download for the Remote Launch
APP.
|
private static URL |
remoteAppURL_
Remote Launch Parm specifying the remote lauched application in the form of
a URL.
|
static String |
RMT_APP_AUTODOWNLOAD
Remote Launch Property Key specifying the flag (boolean string value) that
specifies if the RemoteLaunchOperation Operation should query the
download server for updated app files.
|
static String |
RMT_APP_DOWNLOADURL
Remote Launch Property Key specifying the URL of the download for the
Remote Launch APP.
|
static String |
RMT_APP_JVM_CLASSPATH
Remote Launch Property Key specifying any parameters that should be added
to the FRONT of the classpath when executing a Java App.
|
static String |
RMT_APP_JVM_PARAMETERS
Remote Launch Property Key specifying any parameters that should go to the
JVM when executing a Java App.
|
static String |
RMT_APP_TYPE
Remote Launch Property Key specifying the remote lauch app type.
|
static String |
RMT_APP_URL
Remote Launch Property Key specifying the remote lauch
URL for the RemoteLaunchOperation.HTTPURL_APP app type.
|
private static boolean |
soFarSoGood_
A class var to track the progress of the various validation checks that
are performed.
|
private static String |
SYSTEM_FILE_SEPERATOR
A holder for the NA Clients System File Separator.
|
Modifier | Constructor and Description |
---|---|
protected |
AutoUpdateApp()
Basic constructor for the application.
|
Modifier and Type | Method and Description |
---|---|
private static boolean |
checkAndUpdateApp(URL urlToGet)
Checks the specified remoteAppDownloadURL_ to see if there is a newer
version of the remoteAppURL_ AND then goes out and updates the app
if a newer one is available.
|
private static boolean |
checkForUpdatedApp()
Checks the specified remoteAppDownloadURL_ to see if there is a newer
version of the remoteAppURL_.
|
static String |
convertSystemDependantPath(URL url)
Converts the path component of a URL to the native relative file path.
|
private static boolean |
ensureTheAppIsAvailable(String filePath)
This helper method checks that the specified file exists, if not it
downloads it from the download URL.
|
private static int |
execute()
Determines the app type that has been assigned to the class variables and
calls the correct helper method that Executes the class defined remote app.
|
protected static int |
executeJavaApp(String classLocation,
Vector appParms)
Executes the Specified Java appilcation with the provided commandline
parameters.
|
protected static int |
executeJavaApp(String classLocation,
Vector jvmParms,
Vector appParms)
Executes the Specified Java appilcation with the provided JVM parameters
and executableApp commandline parameters.
|
static int |
executeNativeApp(String executableLocation,
String[] cmdParms)
Executes the Specified Native OS application with the provided commandline
parameters.
|
static int |
executeNativeApp(String executableLocation,
String[] cmdParms,
String outputFilename)
Executes the Specified Native OS application with the provided commandline
parameters.
|
protected static int |
executeNativeApp(String executableLocation,
Vector appParms)
Executes the Specified Native OS application with the provided commandline
parameters.
|
private static String |
getFilePathFromClasspath(String filename)
Searches the classpath for the specified filename and then returns the full
path that is used for it.
|
private static boolean |
initialize(Properties props)
Initializes the apps vars (based on the passed in properties file)
and gets ready to start.
|
protected static Properties |
loadAutoAppPropertiesFile()
Loads the AutoDownload app information from the properties file so this
wrapped app can execute.
|
protected static Properties |
loadPropertiesFile(String propFilename)
Loads the passed Properties file and returns a Properties object.
|
static void |
main(String[] args)
The main entry for this app.
|
private static URL |
parseAppExecutableUrl(String value)
Parses a String representation of a URL or absolute file path and converts
it into a URL.
|
private static boolean |
parseProperties(Properties props)
Parses the passed in Properties and pulls out all the name/value pairs
and assigns them to the class vars as needed.
|
static int |
runApp(Properties props)
The entry point for running an app defined by the passed in properties.
|
private static boolean |
updateAppFromServer(URL urlToGet)
Downloads the requested URL and replaces any existing version.
|
protected static String appName_
protected static String appPropertyFilename_
public static final String NATIVE_APP
public static final String JAVA_APP
public static final String APPLET_APP
public static final String HTTPURL_APP
public static final String RMT_APP_TYPE
This is a required property in the supplied properties file.
public static final String RMT_APP_URL
This is a required property in the supplied properties file.
public static final String RMT_APP_DOWNLOADURL
This is an optional property in the supplied properties file.
public static final String RMT_APP_AUTODOWNLOAD
This is an optional property in the supplied properties file. (default=true)
public static final String RMT_APP_JVM_PARAMETERS
This is an optional property in the supplied properties file. (default="")
public static final String RMT_APP_JVM_CLASSPATH
This is an optional property in the supplied properties file. (default="")
A StringTokenizer is used to parse this property value and usessemi colons or colons as delimiters. Note that spaces are NOT used as delimeters so they can be used in the paths.
private static Vector definedPropertyKeys
private static final String SYSTEM_FILE_SEPERATOR
private static final String DEFAULT_SAVE_LOCATION
Default = ./RemoteApps/
(or the DOS Equiv.
.\RemoteApps\
).
private static String appType_
private static URL remoteAppURL_
It gets assigned from the required property RMT_APP_URL in the supplied properties file.
private static String archiveFilePath_
private static URL remoteAppDownloadURL_
private static boolean remoteAppAutoDownload_
(default=true)
private static String jvmParameters_
(default="")
private static String jvmClasspath_
(default="")
A StringTokenizer is used to parse this property value. So commas or a space delimited list of entries will work.
private static boolean soFarSoGood_
private static boolean archiveDownload_
This field gets used by the updateAppFromServer method to determine where to save the file.
updateAppFromServer(java.net.URL)
private static String errorMsg_
private static Vector cmdLineParms_
protected AutoUpdateApp()
public static int runApp(Properties props)
This method blocks until the Executed app is complete
props
- the Properties defining the app to run as defined in the main
class description.main(java.lang.String[])
public static void main(String[] args)
args
- are the commandline parameters.This app expects ONLY 1
parameter... the absolute file path to the properties file
containing all the info for the Remote App to execute.runApp(java.util.Properties)
private static boolean initialize(Properties props)
private static boolean ensureTheAppIsAvailable(String filePath)
private static String getFilePathFromClasspath(String filename)
public static String convertSystemDependantPath(URL url)
url
- the url to use to convert.private static int execute()
private static URL parseAppExecutableUrl(String value) throws MalformedURLException
This method is a bit forgiving... if the string is not a correctlty formatted http, ftp, or file URL it will assume it is a file URL and create the returned URL as such.
value
- is the String to convert into a URL.MalformedURLException
- if the passed in String is not a URLprivate static boolean checkAndUpdateApp(URL urlToGet)
urlToGet
- is the place to go to get the updated app.remoteAppDownloadURL_
,
remoteAppURL_
private static boolean checkForUpdatedApp()
checkAndUpdateApp(java.net.URL)
,
remoteAppDownloadURL_
,
remoteAppURL_
private static boolean updateAppFromServer(URL urlToGet)
The place for saving this downloaded file is determined based on the archiveDownload_ flag. If archiveDownload_is true then dowloaded file is saved as a new /updated file with its own filename. This is done when an archive file is used as the download that is not the same as the executable name found in the remoteAppURL_ field. For example: if remoteAppURL_ points to ca.bc.webarts.SomeClass and the remoteAppDownloadURL_ points to SomeClass.jar we need to save the downloaded file to SomeClass.jar and then assume the commandline parameters will take care of the running/classpath issues.
urlToGet
- is the place to go to get the updated app.archiveDownload_
protected static int executeNativeApp(String executableLocation, Vector appParms)
executableLocation
- is the path to the executable to runappParms
- and extra commandline parameters to tag onto the end of the
commandline that gets executed.executeNativeApp(java.lang.String, java.lang.String[])
,
StreamGobbler
,
Runtime.getRuntime()
public static int executeNativeApp(String executableLocation, String[] cmdParms)
executableLocation
- is the path to the executable to runcmdParms
- and extra commandline parameters to tag onto the end of the
commandline that gets executed.StreamGobbler
,
Runtime.getRuntime()
public static int executeNativeApp(String executableLocation, String[] cmdParms, String outputFilename)
executableLocation
- is the path to the executable to runcmdParms
- and extra commandline parameters to tag onto the end of the
commandline that gets executed.outputFilename
- a filename to send the output to.StreamGobbler
,
Runtime.getRuntime()
protected static int executeJavaApp(String classLocation, Vector appParms)
classLocation
- is the path to the executable to runappParms
- and extra commandline parameters to tag onto the end of the
commandline that gets executed.protected static int executeJavaApp(String classLocation, Vector jvmParms, Vector appParms)
classLocation
- is the path to the executable to runjvmParms
- holds any cmdline parms to send directly to the jvmappParms
- and extra commandline parameters to tag onto the end of the
commandline that gets executed.private static boolean parseProperties(Properties props)
props
- the Properties to parseprotected static Properties loadAutoAppPropertiesFile()
protected static Properties loadPropertiesFile(String propFilename)
propFilename
- the filename for the Properties file to parseWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses