jwrapper.jwutils
Class JWSystem

java.lang.Object
  extended by jwrapper.jwutils.JWSystem

public class JWSystem
extends java.lang.Object

Utility APIs for virtual apps running inside JWrapper All methods in this class will run without using or requiring a graphical user interface (they will work OK in a headless system)


Constructor Summary
JWSystem()
           
 
Method Summary
static void addAppSpecificProxy(java.net.Proxy proxy)
          Include a proxy specified in the application in the list of proxies to be used when updating.
static void addAppSpecificProxy(java.net.Proxy proxy, java.lang.String username, java.lang.String password)
          Include a proxy specified in the application in the list of proxies to be used when updating, and use the provided credentials when authenticating.
static void clearPreparedFork()
          Remove any pre-prepared virtual app for quick launch (for example if the required version has changed)
static boolean detectAndSetProxyFor(java.net.URL url, int timeoutMS)
          Call this method to redetect the proxy settings for a given URL.
static void forkVirtualApp(java.lang.String virtualAppName)
          Launch a defined virtual app by name
static void forkVirtualApp(java.lang.String virtualAppName, java.util.Properties launchProperties, java.lang.String[] commandLineArgs)
          Launch a defined virtual app by name
static void forkVirtualApp(java.lang.String virtualAppName, java.util.Properties launchProperties, java.lang.String[] commandLineArgs, boolean elevateToAdmin, boolean checkForUpdateFirst)
          Launch a defined virtual app by name
static void forkVirtualApp(java.lang.String virtualAppName, java.lang.String staticUpdateURL, java.util.Properties launchProperties, java.lang.String[] commandLineArgs, boolean elevateToAdmin, boolean checkForUpdateFirst)
          Launch a defined virtual app by name
static java.io.File getAllAppLoggingFolder()
          Get the shared folder where all versions of this app bundle can store and retrieve data
static java.io.File getAllAppVersionsSharedFolder()
          Get the shared folder where all versions of this app bundle can store and retrieve data
static java.io.File getAllAppVersionsSharedFolder(java.io.File master)
          Get the shared folder where all versions of this app bundle can store and retrieve data
static java.lang.String getAppBundleName()
          Get the name of this app bundle
static byte[] getAppBundleSplashPNG()
          Get the splash image in PNG form for this app bundle
static byte[] getAppBundleUninstallerICO()
          Get the uninstaller image in Windows ICO form for this app bundle
static byte[] getAppBundleUninstallerPNG()
          Get the uninstaller image in PNG form for this app bundle
static java.lang.String getAppBundleVersion()
          Get the JWrapper version number for this app bundle - NOTE app code should not depend on this as there may be cases where the version number is altered from the original to force a re-update.
static java.io.File getAppFolder()
          Get the app bundle's installation folder (all included files will be extracted to this folder)
static java.lang.String getAppLaunchProperty(java.lang.String propertyName)
          Get a launch property set for this app bundle
static java.net.Proxy getDefaultDetectedProxy()
          Returns the current default proxy as detected by JWrapper.
static java.lang.String getInstallType()
          Get the install type as specified in the app bundle XML (NoInstall/CurrentUser/AllUsers)
static java.net.Proxy getJWrapperProxy()
          Returns the proxy details used.
static JWProxyCredentials.Credentials getJWrapperProxyCredentials()
          Return the proxy credentials for the default JWrapper detected proxy.
static java.io.File getLauncherLocationForVirtualApp(java.io.File dir, java.lang.String shortcutName)
           
static byte[] getMyAppLogoICO()
          Get the logo in Windows ICO form for this virtual app
static byte[] getMyAppLogoPNG()
          Get the logo in PNG form for this virtual app
static java.lang.String getMyAppName()
          Get the name of this virtual app
static java.io.File getMyJreHome()
          Get the current JRE home folder
static java.io.File getMyLogFile()
          Get the JW log file associated with this virtual app run
static java.io.File getNativeJavaLauncher()
          Return the JWrapper native Java launcher which can be used to spawn Java processes.
static java.lang.String getOsxAppDomainName()
          Get the OSX App Domain used for this app bundle.
static java.util.Properties getPreparedForkProperties()
           
static java.lang.String getSourceLauncherUpdateURL()
          Get the update URL from the launcher that launched this app, this is only to pick up overrides mid-app run
static java.lang.String[] getSupportedLanguages()
          Get all supported languages as an array of language codes
static java.lang.String getUpdateURL()
          Get the update URL for this app bundle
static void loadJWrapperProxies()
           
static void main(java.lang.String[] args)
           
static boolean matchingClientToServerVersion()
          Check to see if this app bundle version is matched to the server (update URL) version
static void overrideAppBundleUpdateURL(java.net.URL url)
          Set the update URL for this app bundle, note this will override any other settings from the original app bundle download or configuration
static void overrideSourceLauncherUpdateURL(java.net.URL url)
          Set the update URL for the launcher that launched this particular run.
static void prepareForkVirtualApp(java.lang.String virtualAppName, java.util.Properties launchProperties, java.lang.String[] commandLineArgs)
          Prepare to quickly launch a defined virtual app by name
static void prepareForkVirtualApp(java.lang.String virtualAppName, java.lang.String staticUpdateURL, java.util.Properties launchProperties, java.lang.String[] commandLineArgs, boolean elevateToAdmin, boolean checkForUpdateFirst)
          Prepare a virtual app for quick launch
static void removeOverrideAppBundleUpdateURL()
          Remove the override update URL for this app bundle
static java.io.File saveLauncherShortcutForVirtualApp(java.io.File dir, java.lang.String shortcutName, java.lang.String virtualAppName, java.util.Properties launchProperties, boolean elevateToAdmin)
          Save a JWrapper launcher (OS-native executable app) to launch a virtual app or the chooser with any set of preconfigured launch properties
static void setCircularLogAreaBytes(long b)
          Set the number of recent bytes this virtual app should log before wrapping, these will be retained at the end of the log file in a circular log format
static void setInitialLogAreaBytes(long b)
          Set the number of initial bytes this virtual app should log before curtailing, these will be retained at the top of the log file
static void setLastUsedProxyAsDefault()
          If the JWrapper build is configured with a valid update URL then JWrapper will automatically attempt to detect a proxy with which to access the update server.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JWSystem

public JWSystem()
Method Detail

addAppSpecificProxy

public static void addAppSpecificProxy(java.net.Proxy proxy)
                                throws java.io.IOException
Include a proxy specified in the application in the list of proxies to be used when updating.

Parameters:
proxy - the proxy to be added for this application.
Throws:
java.io.IOException

addAppSpecificProxy

public static void addAppSpecificProxy(java.net.Proxy proxy,
                                       java.lang.String username,
                                       java.lang.String password)
                                throws java.io.IOException
Include a proxy specified in the application in the list of proxies to be used when updating, and use the provided credentials when authenticating.

Parameters:
proxy - the proxy to be added for this application.
username - the proxy credential username
password - the proxy credential password
Throws:
java.io.IOException

clearPreparedFork

public static void clearPreparedFork()
Remove any pre-prepared virtual app for quick launch (for example if the required version has changed)


detectAndSetProxyFor

public static boolean detectAndSetProxyFor(java.net.URL url,
                                           int timeoutMS)
Call this method to redetect the proxy settings for a given URL. This should be called by applications if the JWrapper build has no update server configured, or if the proxy needs to be redetected for a different URL. This method blocks until a proxy is found or the detection times out.

Parameters:
url - the URL for which a proxy is required.
timeoutMS - the timeout period, in milliseconds, after which proxy detection should terminate.
Returns:
true if the detection was successful, false if the attempt timed out.

forkVirtualApp

public static void forkVirtualApp(java.lang.String virtualAppName)
                           throws java.lang.Exception
Launch a defined virtual app by name

Parameters:
virtualAppName - the name of the virtual app in this bundle to launch
Throws:
java.lang.Exception

forkVirtualApp

public static void forkVirtualApp(java.lang.String virtualAppName,
                                  java.util.Properties launchProperties,
                                  java.lang.String[] commandLineArgs)
                           throws java.lang.Exception
Launch a defined virtual app by name

Parameters:
virtualAppName - the name of the virtual app in this bundle to launch
launchProperties - the launch properties for the virtual app
commandLineArgs - any additional command line args for the virtual app
Throws:
java.lang.Exception

forkVirtualApp

public static void forkVirtualApp(java.lang.String virtualAppName,
                                  java.util.Properties launchProperties,
                                  java.lang.String[] commandLineArgs,
                                  boolean elevateToAdmin,
                                  boolean checkForUpdateFirst)
                           throws java.lang.Exception
Launch a defined virtual app by name

Parameters:
virtualAppName - the name of the virtual app in this bundle to launch
launchProperties - the launch properties for the virtual app
commandLineArgs - any additional command line args for the virtual app
elevateToAdmin - launch the app with elevated privileges (e.g. sudo on Linux/MacOS, elevated to admin on Windows)
Throws:
java.lang.Exception

forkVirtualApp

public static void forkVirtualApp(java.lang.String virtualAppName,
                                  java.lang.String staticUpdateURL,
                                  java.util.Properties launchProperties,
                                  java.lang.String[] commandLineArgs,
                                  boolean elevateToAdmin,
                                  boolean checkForUpdateFirst)
                           throws java.lang.Exception
Launch a defined virtual app by name

Parameters:
virtualAppName - the name of the virtual app in this bundle to launch
staticUpdateURL - the static update URL for this launch, set to "D" to allow dynamic update URLs (in the launch properties)
launchProperties - the launch properties for the virtual app
commandLineArgs - any additional command line args for the virtual app
elevateToAdmin - launch the app with elevated privileges (e.g. sudo on Linux/MacOS, elevated to admin on Windows)
Throws:
java.lang.Exception

getAllAppLoggingFolder

public static java.io.File getAllAppLoggingFolder()
Get the shared folder where all versions of this app bundle can store and retrieve data

Returns:

getAllAppVersionsSharedFolder

public static java.io.File getAllAppVersionsSharedFolder()
Get the shared folder where all versions of this app bundle can store and retrieve data

Returns:

getAllAppVersionsSharedFolder

public static java.io.File getAllAppVersionsSharedFolder(java.io.File master)
Get the shared folder where all versions of this app bundle can store and retrieve data

Returns:

getAppBundleName

public static java.lang.String getAppBundleName()
Get the name of this app bundle


getAppBundleSplashPNG

public static byte[] getAppBundleSplashPNG()
                                    throws java.io.IOException
Get the splash image in PNG form for this app bundle

Throws:
java.io.IOException

getAppBundleUninstallerICO

public static byte[] getAppBundleUninstallerICO()
                                         throws java.io.IOException
Get the uninstaller image in Windows ICO form for this app bundle

Throws:
java.io.IOException

getAppBundleUninstallerPNG

public static byte[] getAppBundleUninstallerPNG()
                                         throws java.io.IOException
Get the uninstaller image in PNG form for this app bundle

Throws:
java.io.IOException

getAppBundleVersion

public static java.lang.String getAppBundleVersion()
Get the JWrapper version number for this app bundle - NOTE app code should not depend on this as there may be cases where the version number is altered from the original to force a re-update.

Returns:

getAppFolder

public static java.io.File getAppFolder()
Get the app bundle's installation folder (all included files will be extracted to this folder)

Returns:

getAppLaunchProperty

public static java.lang.String getAppLaunchProperty(java.lang.String propertyName)
Get a launch property set for this app bundle

Parameters:
propertyName - the name of the property to fetch

getDefaultDetectedProxy

public static java.net.Proxy getDefaultDetectedProxy()
Returns the current default proxy as detected by JWrapper.

Returns:
the current default proxy if one was detected, or null if no proxy was detected.

getInstallType

public static java.lang.String getInstallType()
Get the install type as specified in the app bundle XML (NoInstall/CurrentUser/AllUsers)


getJWrapperProxy

public static java.net.Proxy getJWrapperProxy()
Returns the proxy details used.

Returns:
the proxy settings used, or null if no proxy was detected

getJWrapperProxyCredentials

public static JWProxyCredentials.Credentials getJWrapperProxyCredentials()
Return the proxy credentials for the default JWrapper detected proxy.

Returns:
null if no proxy is set or no credentials are required.

getLauncherLocationForVirtualApp

public static java.io.File getLauncherLocationForVirtualApp(java.io.File dir,
                                                            java.lang.String shortcutName)

getMyAppLogoICO

public static byte[] getMyAppLogoICO()
                              throws java.io.IOException
Get the logo in Windows ICO form for this virtual app

Throws:
java.io.IOException

getMyAppLogoPNG

public static byte[] getMyAppLogoPNG()
                              throws java.io.IOException
Get the logo in PNG form for this virtual app

Throws:
java.io.IOException

getMyAppName

public static java.lang.String getMyAppName()
Get the name of this virtual app

Returns:

getMyJreHome

public static java.io.File getMyJreHome()
Get the current JRE home folder

Returns:

getMyLogFile

public static java.io.File getMyLogFile()
Get the JW log file associated with this virtual app run

Returns:
the File where stdout and stderr are being logged

getNativeJavaLauncher

public static java.io.File getNativeJavaLauncher()
Return the JWrapper native Java launcher which can be used to spawn Java processes. An improvement over java / javaw.exe as it is signed by the developer, and contains customised metadata.

Returns:
null if no native launcher exists for this platform.

getOsxAppDomainName

public static java.lang.String getOsxAppDomainName()
Get the OSX App Domain used for this app bundle. Can be used in 'defaults' calls on OSX.

Returns:

getPreparedForkProperties

public static java.util.Properties getPreparedForkProperties()

getSourceLauncherUpdateURL

public static java.lang.String getSourceLauncherUpdateURL()
                                                   throws java.io.IOException
Get the update URL from the launcher that launched this app, this is only to pick up overrides mid-app run

Returns:
Throws:
java.io.IOException

getSupportedLanguages

public static java.lang.String[] getSupportedLanguages()
Get all supported languages as an array of language codes

Returns:

getUpdateURL

public static java.lang.String getUpdateURL()
Get the update URL for this app bundle

Returns:

loadJWrapperProxies

public static void loadJWrapperProxies()

main

public static void main(java.lang.String[] args)

matchingClientToServerVersion

public static boolean matchingClientToServerVersion()
Check to see if this app bundle version is matched to the server (update URL) version


overrideAppBundleUpdateURL

public static void overrideAppBundleUpdateURL(java.net.URL url)
                                       throws java.io.IOException
Set the update URL for this app bundle, note this will override any other settings from the original app bundle download or configuration

Throws:
java.io.IOException

overrideSourceLauncherUpdateURL

public static void overrideSourceLauncherUpdateURL(java.net.URL url)
                                            throws java.io.IOException
Set the update URL for the launcher that launched this particular run. Note that this changes the update URL only on this launcher.

Throws:
java.io.IOException

prepareForkVirtualApp

public static void prepareForkVirtualApp(java.lang.String virtualAppName,
                                         java.util.Properties launchProperties,
                                         java.lang.String[] commandLineArgs)
                                  throws java.lang.Exception
Prepare to quickly launch a defined virtual app by name

Parameters:
virtualAppName - the name of the virtual app in this bundle to launch
launchProperties - the launch properties for the virtual app
commandLineArgs - any additional command line args for the virtual app
Throws:
java.lang.Exception

prepareForkVirtualApp

public static void prepareForkVirtualApp(java.lang.String virtualAppName,
                                         java.lang.String staticUpdateURL,
                                         java.util.Properties launchProperties,
                                         java.lang.String[] commandLineArgs,
                                         boolean elevateToAdmin,
                                         boolean checkForUpdateFirst)
                                  throws java.lang.Exception
Prepare a virtual app for quick launch

Parameters:
virtualAppName -
staticUpdateURL -
launchProperties -
commandLineArgs -
elevateToAdmin -
checkForUpdateFirst -
Throws:
java.lang.Exception

removeOverrideAppBundleUpdateURL

public static void removeOverrideAppBundleUpdateURL()
Remove the override update URL for this app bundle


saveLauncherShortcutForVirtualApp

public static java.io.File saveLauncherShortcutForVirtualApp(java.io.File dir,
                                                             java.lang.String shortcutName,
                                                             java.lang.String virtualAppName,
                                                             java.util.Properties launchProperties,
                                                             boolean elevateToAdmin)
                                                      throws java.io.IOException
Save a JWrapper launcher (OS-native executable app) to launch a virtual app or the chooser with any set of preconfigured launch properties

Parameters:
dir - the folder to save the launcher in
shortcutName - the name of the app to save (excluding any extension)
virtualAppName - the virtual app to run or null if the launcher is to run the default or chooser
launchProperties - the launch properties to run the virtual app with
elevateToAdmin - whether the launcher should elevate before running the virtual app
Throws:
java.io.IOException

setCircularLogAreaBytes

public static void setCircularLogAreaBytes(long b)
Set the number of recent bytes this virtual app should log before wrapping, these will be retained at the end of the log file in a circular log format

Parameters:
b -

setInitialLogAreaBytes

public static void setInitialLogAreaBytes(long b)
Set the number of initial bytes this virtual app should log before curtailing, these will be retained at the top of the log file

Parameters:
b -

setLastUsedProxyAsDefault

public static void setLastUsedProxyAsDefault()
If the JWrapper build is configured with a valid update URL then JWrapper will automatically attempt to detect a proxy with which to access the update server. Subsequently spawned applications may be created in a separate process and will not automatically inherit the default proxy settings. Call this method to set the detected proxy settings as the default for this application.