public class Util
extends java.lang.Object
Constructor and Description |
---|
Util() |
Modifier and Type | Method and Description |
---|---|
static void |
dumpVariables(Context context)
Dump all defined installer variables to stderr.
|
static void |
fatalError(java.lang.Throwable t)
This method can be invoked if you encounter a non-recoverable and non-expected error in
your custom code.
|
static java.lang.String |
getAnnotatedStackTrace(java.lang.Throwable t)
If a stack trace comes from scripts, it can be difficult to trace them to their origin by looking at the
stack trace alone.
|
static java.io.File |
getLogFile()
Get the location of the log file.
|
static java.awt.Window |
getParentWindow()
Get the window of the installer.
|
static java.lang.String |
getStandardApplicationsDirectory()
Returns the standard directory for installing applications.
|
static java.lang.String |
getUserHome()
Returns the home directory.
|
static boolean |
hasFullAdminRights()
Checks whether the current process has full administration rights.
|
static boolean |
is64BitWindows()
Returns whether the Windows is a 64-bit Windows, regardless of whether the installer is running with a 32-bit JVM or
a 64-bit JVM.
|
static boolean |
isAdminGroup()
Checks whether the current user is from the administration group.
|
static boolean |
isAdminUser()
Deprecated.
use
isAdminGroup() and hasFullAdminRights() instead. |
static boolean |
isAix()
Returns whether the platform is AIX.
|
static boolean |
isAtLeastWindows7()
Returns whether the platform is at least Windows 7.
|
static boolean |
isAtLeastWindowsVista()
Returns whether the platform is at least Windows Vista.
|
static boolean |
isAtLeastWindowsXP()
Deprecated.
|
static boolean |
isDirectoryWritable(java.io.File directory)
Checks if a directory is writable with the currently available privileges.
|
static boolean |
isHpux()
Returns whether the platform is HP UX.
|
static boolean |
isLinux()
Returns whether the platform is Linux.
|
static boolean |
isMacOS()
Returns whether the platform is macOS.
|
static boolean |
isMacosInstaller()
Returns whether the installer is a macOS installer
|
static boolean |
isSolaris()
Returns whether the platform is Solaris.
|
static boolean |
isUnixInstaller()
Returns whether the installer is a Unix installer
|
static boolean |
isWindows()
Returns whether the platform is Windows.
|
static boolean |
isWindows10()
Returns whether the platform is Windows 10.
|
static boolean |
isWindows2000()
Returns whether the platform is Windows 2000.
|
static boolean |
isWindows2003()
Returns whether the platform is Windows 2003.
|
static boolean |
isWindows2008()
Returns whether the platform is Windows 2008.
|
static boolean |
isWindows2012()
Returns whether the platform is Windows 2012.
|
static boolean |
isWindows2016()
Returns whether the platform is Windows 2016.
|
static boolean |
isWindows7()
Returns whether the platform is Windows 7.
|
static boolean |
isWindows8()
Returns whether the platform is Windows 8.
|
static boolean |
isWindows9X()
Deprecated.
always returns
false because launchers do not work with Windows 9X anymore |
static boolean |
isWindowsInstaller()
Returns whether the installer is a Windows installer
|
static boolean |
isWindowsNT()
Deprecated.
|
static boolean |
isWindowsVista()
Returns whether the platform is Windows Vista.
|
static boolean |
isWindowsXP()
Returns whether the platform is Windows XP.
|
static void |
loadNativeFromResources(java.lang.String fileName)
Call
System.load(java.lang.String) with the supplied file name resolved against the resource directory. |
static void |
log(java.lang.Throwable t)
Writes an stack trace to the installation log.
|
static void |
logError(java.lang.Object source,
java.lang.String message)
Writes an error message to the installation log.
|
static void |
logInfo(java.lang.Object source,
java.lang.String message)
Writes an info message to the installation log.
|
static void |
moveLogFile(java.io.File newLogFile)
Move the log file to a new location.
|
static void |
printAnnotatedStackTrace(java.lang.Throwable t)
Prints the return value of
getAnnotatedStackTrace(Throwable) to System.err . |
static void |
showErrorMessage(java.lang.String message)
Show a message dialog.
|
static void |
showMessage(java.lang.String message)
Show a message dialog.
|
static void |
showMessage(java.lang.String message,
int messageType)
Show a message dialog.
|
static int |
showOptionDialog(java.lang.String message,
java.lang.String[] options,
int messageType)
Show an options dialog.
|
static void |
showPath(java.lang.String path)
Show the specified directory or file.
|
static void |
showUrl(java.net.URL url)
Show a URL in the default browser.
|
static void |
showWarningMessage(java.lang.String message)
Show a message dialog.
|
public static java.lang.String getUserHome()
public static boolean isSolaris()
public static boolean isLinux()
public static boolean isWindows()
@Deprecated public static boolean isWindows9X()
false
because launchers do not work with Windows 9X anymore@Deprecated public static boolean isWindowsNT()
public static boolean isAtLeastWindowsVista()
public static boolean isAtLeastWindows7()
@Deprecated public static boolean isAtLeastWindowsXP()
public static boolean isWindowsVista()
public static boolean isWindows7()
public static boolean isWindows8()
public static boolean isWindows10()
public static boolean isWindowsXP()
public static boolean isWindows2000()
public static boolean isWindows2003()
public static boolean isWindows2008()
public static boolean isWindows2012()
public static boolean isWindows2016()
public static boolean is64BitWindows()
System.getProperty("os.arch")
, since this will
return a value that corresponds to the JRE and not to the OS (i.e. always "x86" for a 32-bit JRE, even if it is running
on a 64-bit Windows).
This method inspects the environment variables PROCESSOR_ARCHITECTURE
and PROCESSOR_ARCHITEW6432
.
If PROCESSOR_ARCHITECTURE
contains AMD64
or IA64
, the currently used JRE is a 64-bit JRE which is then
by definition running on a 64-bit Windows. If PROCESSOR_ARCHITECTURE
contains x86
, the PROCESSOR_ARCHITEW6432
is undefined for a 32-bit Windows and contains AMD64
or IA64
for a 64-bit Windows.
false
.public static boolean isMacOS()
public static boolean isHpux()
public static boolean isAix()
public static boolean isWindowsInstaller()
public static boolean isUnixInstaller()
public static boolean isMacosInstaller()
public static java.lang.String getStandardApplicationsDirectory()
public static void showUrl(java.net.URL url)
For quiet installers, this method does nothing.
url
- the URL to be shown in the browser.public static void showMessage(java.lang.String message, int messageType)
message
- the messagemessageType
- the message type (see JOptionPane)JOptionPane
public static void showMessage(java.lang.String message)
Paragraphs can be created by double line feeds (\n\n), single line feeds will be ignored. On Windows and macOS, the string is split into a title that is shown in a larger font and a message that is shown in a regular font. If the message does not contain a line feed, the entire message is shown as a title. If the message contains a line feed, the title is split from the beginning up to the first dot or the first line feed, the remainder is shown as the regular message. If you do not want to display anything in the title font, start the message with a single line break.
Text is wrapped automatically on word boundaries. On Windows, text that cannot be wrapped is split with an
ellipsis in the middle of the line to limit the maximum width of the message dialog. In some circumstances this
may not be desirable, for example for displaying stack trace elements. You can prepend the message with a
zero character \0
to prevent word wrapping and ellipsis insertion. On macOS, text is wrapped on word
boundaries and within words if the width of a single word is too large. This behavior of the native alert
cannot be changed.
message
- the messageJOptionPane
public static void showErrorMessage(java.lang.String message)
See showMessage(String, int)
for a discussion on the message format.
message
- the messageJOptionPane
public static void showWarningMessage(java.lang.String message)
See showMessage(String, int)
for a discussion on the message format.
message
- the messageJOptionPane
public static int showOptionDialog(java.lang.String message, java.lang.String[] options, int messageType) throws UserCanceledException
See showMessage(String, int)
for a discussion on the message format.
message
- the messageoptions
- the options. To explicitly set keys for answers in console mode, prefix the desired letter
with '&'. For example new String[] {"&Enter", "E&xit"}
. If no explicit keys are set
the first letters of the options are taken. Repeating letters are replaced with numeric indices.messageType
- the message type (see JOptionPane)UserCanceledException
- if the user cancels the selection in console modeJOptionPane
public static void fatalError(java.lang.Throwable t)
t
- the exception that occurredpublic static java.awt.Window getParentWindow()
null
if the installer is silentpublic static void logInfo(java.lang.Object source, java.lang.String message)
source
- the object that requests the log. Usually the bean that executes this code. Can be null
, in this
case the currently executed action or - if no action is being executed - the currently displayed screen are used. A
case where you should explicitly set this parameter is in code that is executed from form components.message
- the message to be logged.public static void logError(java.lang.Object source, java.lang.String message)
source
- the object that requests the log. Usually the bean that executes this code. Can be null
, in this
case the currently executed action or - if no action is being executed - the currently displayed screen are used. A
case where you should explicitly set this parameter is in code that is executed from form components.message
- the message to be logged.public static void log(java.lang.Throwable t)
t
- the throwable instancepublic static void dumpVariables(Context context)
context
- the context@Deprecated public static boolean isAdminUser()
isAdminGroup()
and hasFullAdminRights()
instead.true
if the installer is running with administration privileges.
true
if the user is member of the "admin" group.true
if the current user is called "root".true
or false
.public static boolean isAdminGroup()
true
if the user is member of the "admin" group.true
if the current user is called "root".true
or false
.public static boolean hasFullAdminRights()
true
if the installer is running with elevated privileges.true
if the current user is called "root".true
or false
.public static java.lang.String getAnnotatedStackTrace(java.lang.Throwable t)
t
- the exceptionpublic static void printAnnotatedStackTrace(java.lang.Throwable t)
getAnnotatedStackTrace(Throwable)
to System.err
.
This can be used for debugging purposes.t
- the exceptionpublic static void showPath(java.lang.String path)
path
- the directory that should be displayedpublic static boolean isDirectoryWritable(java.io.File directory)
directory
- the directory. If the directory is a file, false
is returned. It is acceptable if the
directory does not exist.true
or false
.public static java.io.File getLogFile()
.install4j/installation.log
before the installer terminates if an "Install files" action has been executed. For an installer application,
this log file will be deleted when the installer application is terminated unless the VM parameter
-Dinstall4j.keepLog=true
is set.public static void moveLogFile(java.io.File newLogFile)
getLogFile()
public static void loadNativeFromResources(java.lang.String fileName)
System.load(java.lang.String)
with the supplied file name resolved against the resource directory.
This is useful to load supporting native libraries for SQL drivers, such as
sqljdbc_auth.dll
for the Oracle JDBC driver. If you add that DLL on the "Installer->Custom code &
resources step", you can load it with the code
Util.loadNativeFromResources("sqljdbc_auth.dll");
in a "Run script" action.fileName
- the file name of the native library