SWT Web Installer
What is it?
The SWT web installer is a Java library that helps to install Java applications based on SWT.It downloads from the internet the right version of the SWT GUI library for the PC where you are installing the application that uses it.
SWT is a GUI library that is based on native code, so there is a version of it for each platform (Windows, MacOSX, Linux, 32 or 64 bits...).
If you made an application based on SWT that is supposed to be installed on any platform you need therefore to either:
- make one setup file for each platform (they can be many).
- make one setup file for the most common platforms (Windows, MacOSX, Linux 32 bits?).
- use the SWT web installer.
How does it work?
When called, the SWT web installer does the following steps:.- it loads from the internet a file containing a list of links to download the SWT library from, one for each platform.
- It checks the platform in which it is running (two properties, os.type and os.arch).
- it gets the link to the SWT library for that platform from the downloaded list file.
- it downloads the SWT library (it is a zip file).
- it unzips the SWT library in a specific directory.
Principles.
- Always have an alternative.
Since the SWT web installer can run on any platform with different internet setups, it is possible
that something goes wrong. In this case it tries other solutions.
For example it can happen that the platform is not recognized. In this case, the SWT web installer lets the user choose the platform. - Maximum information. SWT web installer tries always to explain what it is doing. In this way the user can continue manually if for some reason the library is not able to continue (for example because it is not able to connect to the internet).
- Flexibility. To get data from the user and give feedback to the user the SWT web installer uses by default the console (i.e. command line, shell).
This is because the application that runs the library with high probability does not have a GUI, since it is a GUI library we are installing.
But this is only the default case: SWT web installer can be customized to use any kind of interface to interact with the user.
How do I use it for my application?
The library can be called from everywhere (it has also a main method), but the most reasonable ways to call it are:
- From the application installer, for example as last step in the wizard.
- By the application itself the first time it is started, before the GUI is showed.
To use the library, create an instance of WebDownloader and call its download method.
The flexibility comes from the WebDownloader's constructor, which allows to specify how it is supposed to acquire the information it needs to work. These are its parameters:
proxy source
- an instance of the a class implementing the IProxySource interface. This parameter is used to acquire the definition of a proxy to use to connect to the internet.authentication source
- an instance of a class implementing the IProxyAuthenticationSource interface. This interface is used in case a proxy is used to connect to the internet, to acquire the user id and password needed for the proxy authentication.external configuration chooser
- an instance of a class implementing the IConfigurationChooser interface. It is used to retrieve the platform if it was not possible to determine it automatically.site chooser
- an instance of a class implementing the ISiteChooser interface. It is used to determine from which site to download the SWT zip file (there are normally many mirror sites).listener
- an instance of a class implementing the IDownloadListener interface. It is used to report the progress of the downloading process. The SWT zip file can be of some MBytes, and it is useful to know how much of it has been downloaded.system properties
- an instance of a class implementing the ISystemProperties interface. It is used to extract from the system the properties os.name and os.arch, which the define the platform where we are installing.
The download method, which downloads list file and SWT library, has the following parameters:
listURL
- the URL where to find the list file with the links for all platforms.zipPath
- the local path where to save the SWT library zip filefinalPath
- the local path where to write the files extracted from the SWT library zip file
The list file format
The list file is an XML file that contains:- A list of sites from which the SWT library can be downloaded.
- A list of all platforms (configurations) for which the SWT library can be installed, with the name of the SWT zip file for that platform.
More in details the file has this content:
<installer>
<sites>
<site dir="[absolute link of the site directory where the files are located]" description="[site description]"/>
...
</sites>
<configurations>
<configuration os_type="[regular expression matching the java environment variable os.type for this platform]" os_arch="[regular expression matching the java environment variable os.arch for this platform]" description="[Human readable description of the platform]" link="[file name of the zip file in the site directory]"/>
...
</configurations>
</installer>
How do I test it?
The SWT web installer comes with two batch files, one for Windows (installer.bat) and one for Unix-like environment (installer.sh), which call directly the ConsoleWebDownloader and can therefore be used to test the library on different platforms.Why it is called osdepinstaller.jar ?
The SWT web installer can be used to download any library that is platform dependent, not only SWT.Therefore its name is actually Operating system dependent library installer (osdepinstaller).