Class Util
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddumpVariables(Context context) Dump all defined installer variables to stderr.static voidAlias for @{link Context#handleCriticalException(Throwable)}.static StringIf a stack trace comes from scripts, it can be difficult to trace them to their origin by looking at the stack trace alone.static FileGet the location of the log file.static WindowDeprecated.static StringReturns the standard directory for installing applications.static StringReturns the home directory.static booleanChecks whether the current process has full administration rights.static booleanReturns 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 booleanChecks whether the current user is from the administration group.static booleanDeprecated.useisAdminGroup()andhasFullAdminRights()instead.static booleanisAix()Returns whether the platform is AIX.static booleanReturns whether the application was installed from an archive or an installer media type.static booleanReturns whether the platform is at least Windows 10.static booleanReturns whether the platform is at least Windows 7.static booleanReturns whether the platform is at least Windows Vista.static booleanDeprecated.static booleanisDirectoryWritable(File directory) Checks if a directory is writable with the currently available privileges.static booleanisHpux()Returns whether the platform is HP UX.static booleanisLinux()Returns whether the platform is Linux.static booleanisMacOS()Returns whether the platform is macOS.static booleanReturns whether the installer is a macOS installerstatic booleanReturns whether the platform is Solaris.static booleanReturns whether the installer is a Unix installerstatic booleanReturns whether the platform is Windows.static booleanReturns whether the platform is Windows 10.static booleanReturns whether the platform is Windows 2000.static booleanReturns whether the platform is Windows 2003.static booleanReturns whether the platform is Windows 2008.static booleanReturns whether the platform is Windows 2012.static booleanReturns whether the platform is Windows 2016.static booleanReturns whether the platform is Windows 7.static booleanReturns whether the platform is Windows 8.static booleanDeprecated.always returnsfalsebecause launchers do not work with Windows 9X anymorestatic booleanReturns whether the installer is a Windows installerstatic booleanDeprecated.static booleanReturns whether the platform is Windows Vista.static booleanReturns whether the platform is Windows XP.static voidloadNativeFromResources(String fileName) CallSystem.load(java.lang.String)with the supplied file name resolved against the resource directory.static voidWrites a stack trace to the installation log.static voidWrites an error message to the installation log.static voidWrites an info message to the installation log.static voidmoveLogFile(File newLogFile) Move the log file to a new location.static voidPrints the return value ofgetAnnotatedStackTrace(Throwable)toSystem.err.static voidshowErrorMessage(String message) Show a message dialog.static voidshowMessage(String message) Show a message dialog.static voidshowMessage(String message, int messageType) Show a message dialog.static intshowOptionDialog(String message, String[] options, int messageType) Show an option dialog.static voidShow the specified directory or file.static voidShow a URL in the default browser.static voidshowWarningMessage(String message) Show a message dialog.
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
getUserHome
Returns the home directory.- Returns:
- the home directory
-
isSolaris
public static boolean isSolaris()Returns whether the platform is Solaris.- Returns:
- the result
-
isLinux
public static boolean isLinux()Returns whether the platform is Linux.- Returns:
- the result
-
isWindows
public static boolean isWindows()Returns whether the platform is Windows.- Returns:
- the result
-
isWindows9X
Deprecated.always returnsfalsebecause launchers do not work with Windows 9X anymoreReturns whether the platform is Windows 9X (95, 98, ME).- Returns:
- the result
-
isWindowsNT
Deprecated.Returns whether the platform is Windows NT.- Returns:
- the result
-
isAtLeastWindowsVista
public static boolean isAtLeastWindowsVista()Returns whether the platform is at least Windows Vista.- Returns:
- the result
-
isAtLeastWindows7
public static boolean isAtLeastWindows7()Returns whether the platform is at least Windows 7.- Returns:
- the result
-
isAtLeastWindowsXP
Deprecated.Returns whether the platform is at least Windows XP.- Returns:
- the result
-
isWindowsVista
public static boolean isWindowsVista()Returns whether the platform is Windows Vista.- Returns:
- the result
-
isWindows7
public static boolean isWindows7()Returns whether the platform is Windows 7.- Returns:
- the result
-
isWindows8
public static boolean isWindows8()Returns whether the platform is Windows 8. This includes Windows 8.1.- Returns:
- the result
-
isWindows10
public static boolean isWindows10()Returns whether the platform is Windows 10.- Returns:
- the result
-
isAtLeastWindows10
public static boolean isAtLeastWindows10()Returns whether the platform is at least Windows 10.- Returns:
- the result
-
isWindowsXP
public static boolean isWindowsXP()Returns whether the platform is Windows XP.- Returns:
- the result
-
isWindows2000
public static boolean isWindows2000()Returns whether the platform is Windows 2000.- Returns:
- the result
-
isWindows2003
public static boolean isWindows2003()Returns whether the platform is Windows 2003.- Returns:
- the result
-
isWindows2008
public static boolean isWindows2008()Returns whether the platform is Windows 2008.- Returns:
- the result
-
isWindows2012
public static boolean isWindows2012()Returns whether the platform is Windows 2012.- Returns:
- the result
-
isWindows2016
public static boolean isWindows2016()Returns whether the platform is Windows 2016.- Returns:
- the result
-
is64BitWindows
public 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. This condition cannot be found out by inspectingSystem.getProperty("os.arch"), since this will return a value that corresponds to the JRE and not to the OS, for example, always "x86" for a 32-bit JRE, even if it is running on a 64-bit Windows.This method inspects the environment variables
PROCESSOR_ARCHITECTUREandPROCESSOR_ARCHITEW6432. IfPROCESSOR_ARCHITECTUREcontainsAMD64,IA64orARM64, the currently used JRE is a 64-bit JRE which is then by definition running on a 64-bit Windows. IfPROCESSOR_ARCHITECTUREcontainsx86, thePROCESSOR_ARCHITEW6432is undefined for a 32-bit Windows and containsAMD64,IA64orARM64for a 64-bit Windows.- Returns:
- the result. If the current OS is not Windows, the result is always
false.
-
isMacOS
public static boolean isMacOS()Returns whether the platform is macOS.- Returns:
- the result
-
isHpux
public static boolean isHpux()Returns whether the platform is HP UX.- Returns:
- the result
-
isAix
public static boolean isAix()Returns whether the platform is AIX.- Returns:
- the result
-
isWindowsInstaller
public static boolean isWindowsInstaller()Returns whether the installer is a Windows installer- Returns:
- the result
-
isUnixInstaller
public static boolean isUnixInstaller()Returns whether the installer is a Unix installer- Returns:
- the result
-
isMacosInstaller
public static boolean isMacosInstaller()Returns whether the installer is a macOS installer- Returns:
- the result
-
getStandardApplicationsDirectory
Returns the standard directory for installing applications.- Returns:
- the directory
-
isArchive
public static boolean isArchive()Returns whether the application was installed from an archive or an installer media type.- Returns:
trueif this is an archive
-
showUrl
Show a URL in the default browser. If no default browser can be determined for the operating system, the user is asked to locate the executable of the internet browser. This executable is cached so that subsequent invocations of this method do not bring up this question again.For quiet installers, this method does nothing.
- Parameters:
url- the URL to be shown in the browser.
-
showMessage
Show a message dialog. This message dialog is a JOptionPane, the parameters are equivalent to those of the standard Java class. This method works in both GUI and console mode.- Parameters:
message- the messagemessageType- the message type (see JOptionPane)- See Also:
-
showMessage
Show a message dialog. This message dialog is a JOptionPane with a message type of INFORMATION_MESSAGE. This method works in both GUI and console mode.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
\0to 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.- Parameters:
message- the message- See Also:
-
showErrorMessage
Show a message dialog. This message dialog is a JOptionPane with a message type of ERROR_MESSAGE. This method works in both GUI and console mode.See
showMessage(String, int)for a discussion on the message format.- Parameters:
message- the message- See Also:
-
showWarningMessage
Show a message dialog. This message dialog is a JOptionPane with a message type of WARNING_MESSAGE. This method works in both GUI and console mode.See
showMessage(String, int)for a discussion on the message format.- Parameters:
message- the message- See Also:
-
showOptionDialog
public static int showOptionDialog(@Nls String message, @Nls String[] options, int messageType) throws UserCanceledException Show an option dialog. This option dialog is a JOptionPane, the parameters are equivalent to those of the standard Java class. This method works in both GUI and console mode.See
showMessage(String, int)for a discussion on the message format.- Parameters:
message- the messageoptions- the options. To explicitly set keys for answers in console mode, prefix the desired letter with '&'. For examplenew 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)- Returns:
- the index of the selected option or -1 if the installer is running in unattended mode
- Throws:
UserCanceledException- if the user cancels the selection in console mode- See Also:
-
fatalError
Alias for @{link Context#handleCriticalException(Throwable)}. -
getParentWindow
Deprecated.useUiUtil.getParentWindow()insteadGet the window of the installer application. -
logInfo
Writes an info message to the installation log.- Parameters:
source- the object that requests the log. Usually the bean that executes this code. Can benull, in this case the currently executed action or - if no action is being executed - the currently displayed screen is 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.
-
logError
Writes an error message to the installation log.- Parameters:
source- the object that requests the log. Usually the bean that executes this code. Can benull, in this case the currently executed action or - if no action is being executed - the currently displayed screen is 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.
-
log
Writes a stack trace to the installation log.- Parameters:
t- the throwable instance
-
dumpVariables
Dump all defined installer variables to stderr. To be able to see the output, you have to create a debug installer by selecting the corresponding option in the Build step in the install4j GUI.- Parameters:
context- the context
-
isAdminUser
Deprecated.useisAdminGroup()andhasFullAdminRights()instead.Checks whether the current user has administration privileges.- On Windows this method returns
trueif the installer is running with administration privileges. - On macOS this method returns
trueif the user is member of the "admin" group. - On Unix this method returns
trueif the current user is called "root".
- Returns:
trueorfalse.
- On Windows this method returns
-
isAdminGroup
public static boolean isAdminGroup()Checks whether the current user is from the administration group.- On Windows this is the case, if the user is a member of the "Administrators" group.
- On macOS this method returns
trueif the user is member of the "admin" group. - On Unix this method returns
trueif the current user is called "root".
- Returns:
trueorfalse.
-
hasFullAdminRights
public static boolean hasFullAdminRights()Checks whether the current process has full administration rights.- On Windows this method returns
trueif the installer is running with elevated privileges. - On macOS and Unix this method returns
trueif the current user is called "root".
- Returns:
trueorfalse.
- On Windows this method returns
-
getAnnotatedStackTrace
If a stack trace comes from scripts, it can be difficult to trace them to their origin by looking at the stack trace alone. With this method, you can annotate the stack trace with the actual names of properties, actions, screens or form components that contain the offending script code.- Parameters:
t- the exception- Returns:
- the annotated stack trace
-
printAnnotatedStackTrace
Prints the return value ofgetAnnotatedStackTrace(Throwable)toSystem.err. This can be used for debugging purposes.- Parameters:
t- the exception
-
showPath
Show the specified directory or file. On Windows this will open an explorer window, and on Linux/Unix it will open a terminal. On macOS it will open a finder window for regular files or directories.- Parameters:
path- the directory that should be displayed
-
isDirectoryWritable
Checks if a directory is writable with the currently available privileges.- Parameters:
directory- the directory. If the directory is a file,falseis returned. It is acceptable if the directory does not exist.- Returns:
trueorfalse.
-
getLogFile
Get the location of the log file. This is a temporary file, for the installer it will be moved to.install4j/installation.logbefore 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=trueis set.- Returns:
- the log file
-
moveLogFile
Move the log file to a new location. With this method, an alternative permanent location of the log file can be specified. The log file will be moved immediately, and it will not be deleted when the installer application exits.- See Also:
-
loadNativeFromResources
CallSystem.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 assqljdbc_auth.dllfor the Oracle JDBC driver. If you add that DLL on the "Installer->Custom code & resources step", you can load it with the code
in a "Run script" action.Util.loadNativeFromResources("sqljdbc_auth.dll");- Parameters:
fileName- the file name of the native library
-
UiUtil.getParentWindow()instead