Package tk.rpjosh.installer
Class InstallConfig
- java.lang.Object
-
- tk.rpjosh.installer.InstallConfig
-
public class InstallConfig extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
InstallConfig.OSType
-
Field Summary
Fields Modifier and Type Field Description protected boolean
addVersion
protected char[]
authPassword
protected char[]
authUsername
protected boolean
createIconForDeletion
protected boolean
createPathVariable
protected boolean
createUnitFile
protected java.lang.String
desktopCategories
protected java.lang.String
desktopKeywords
protected java.lang.String
downloadURL
protected java.lang.String
iconForDeletionPath
protected java.lang.String
installAliasName
protected java.lang.String
installWantedBy
protected boolean
isInstallationStarted
protected java.util.List<java.lang.String>
serviceEnvironment
protected java.util.List<java.lang.String>
serviceExecStart
protected java.util.List<java.lang.String>
serviceExecStartPost
protected java.util.List<java.lang.String>
serviceExecStartPre
protected java.lang.String
serviceExecStop
protected java.lang.String
serviceGroup
protected java.lang.String
serviceRestart
protected java.lang.Integer
serviceRestartSec
protected java.lang.Integer
serviceTimeout
protected java.lang.String
serviceType
protected java.lang.String
serviceUser
protected java.lang.String
serviceWorkingDir
protected java.lang.Boolean
startAtBoot
protected java.lang.String
unitAfter
protected java.lang.String
unitDescription
protected java.lang.Integer
unitStartLimitBurst
protected java.lang.Integer
unitStartLimitInterval
protected java.lang.String
urlEnding
-
Constructor Summary
Constructors Constructor Description InstallConfig(java.lang.String company, java.lang.String version, java.lang.String applicationNameShort, java.lang.String applicationNameLong)
Creates a configuration object for the installation with all the necessary informations
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
createConfigDirs(java.util.ArrayList<java.lang.String> directorys)
Creates the given directory in the configuration directoryvoid
createPathEntry()
[Windows] creates a entry in the path variable for the program TODO: create Launcher wie unter Linuxvoid
createProgramDirs(java.util.ArrayList<java.lang.String> directorys)
Creates the given directory in the application directoryvoid
createServiceUnitFile(boolean startAtBoot, java.lang.String unitDescription, java.lang.String unitAfter, java.lang.Integer unitStartLimitBurst, java.lang.Integer unitStartLimitInterval, java.lang.String installWantedBy, java.lang.String installAliasName, java.lang.String serviceWorkingDir, java.lang.String serviceUser, java.lang.String serviceGroup, java.util.List<java.lang.String> serviceEnvironment, java.util.List<java.lang.String> serviceExecStartPre, java.util.List<java.lang.String> serviceExecStartPost, java.lang.Integer serviceTimeout, java.lang.String serviceType, java.util.List<java.lang.String> serviceExecStart, java.lang.String serviceExecStop, java.lang.String serviceRestart, java.lang.Integer serviceRestartSec)
[Linux] Creates a unit file for systemd.java.lang.String
getApplicationDir()
Returns the main directory of the application.protected java.lang.String
getApplicationNameLong()
protected java.lang.String
getApplicationNameShort()
protected java.lang.String
getCompany()
java.lang.String
getConfigDir()
Returns the configuration directory of the application: /home/user/.config/ or C:\Users\User\AppData\ If the path isn't existing, it will be createdprotected boolean
getCreateDesktopEntry()
protected tk.rpjosh.installer.Data
getData()
protected boolean
getDebug()
protected java.lang.String
getDesktopDir()
Returns the path of the desktopprotected java.lang.String
getDesktopLinuxPNG()
protected java.lang.String
getDesktopWindowsICO()
protected int
getEstimatedSize()
[Windows] Returns the setted estimates size of the programprotected java.util.Map<java.lang.String,java.lang.String>
getFontsToInstall()
protected boolean
getIsPortable()
protected boolean
getIsUser()
protected java.lang.String
getLocationOfJarFile()
Returns the path to the actual jar fileprotected int
getMaxHeapSize()
protected boolean
getOffline()
static InstallConfig.OSType
getOsType()
protected java.lang.String
getPortableDir()
Returns the main directory of the portable installationprotected boolean
getQuiet()
protected boolean
getResource(java.lang.String pathInJar, java.lang.String pathToWrite)
Extracts a file from the jar file and copy it to the given pathprotected boolean
getResource(java.lang.String pathInJar, java.lang.String pathToWrite, boolean logError)
Extracts a file from the jar file and copy it to the given pathprotected boolean
getRunInBackgroundByDefault()
protected java.lang.String
getVersion()
protected void
initApplicationDir()
void
installDesktopEntry(java.lang.String windowsICO, java.lang.String linuxPNG, java.lang.String keywords)
Creates a desktop entry during the installationvoid
setDebug(boolean debug)
When the debug mode is enabled, all error messages will be printed out exactlyvoid
setDesktopCategories(java.lang.String categories)
[Linux] Sets the categories in which the applications should be present in the menus (desktop entry)void
setDesktopKeywords(java.lang.String keywords)
[Linux] Sets the keywords for the application (desktop entry)void
setDownloadOfflinePath(java.lang.String path)
Installs the executable from the local file systems instead of downloading the filevoid
setDownloadURLForProgramm(java.lang.String url, char[] basicAuthUser, char[] basicAuthPassword)
Sets the URL of the file to be installed.void
setDownloadURLForProgramm(java.lang.String url, char[] basicAuthUser, char[] basicAuthPassword, java.lang.String end)
Sets the URL of the file to be installed.void
setEstimatedSize(double estimatedSize)
[Windows] The estimated size of the whole application which should been displayed to the uservoid
setFontsToInstall(java.util.Map<java.lang.String,java.lang.String> fonts)
The given fonts will be installed (the fonts has to be in the format .ttf)void
setIconForWindowsUninstaller(java.lang.String windowsICO)
[Windows] Icon for the removal of the application.protected void
setLocationOfJarFile(java.lang.String location)
Sets the path to the jar runtime path -> overwrite for the portable installationvoid
setMaxHeapSize(int sizeInMb)
Sets the maximum heap size the JVM may consume (-Xmx)void
setPortable(java.lang.String dir)
Installs the program portablevoid
setQuiet(boolean quiet)
If the installation should be executed in the background -> no command prompt will appear and prompts will be ignoredvoid
setRunInBackgroundByDefault(boolean runInBackground)
When the application is launched from the command line, the program will be launched in the foreground normally.void
setUserInstallation()
[Windows] Installs the program only for the actual user -> administrator rights aren't necessary
-
-
-
Field Detail
-
downloadURL
protected java.lang.String downloadURL
-
addVersion
protected boolean addVersion
-
urlEnding
protected java.lang.String urlEnding
-
authUsername
protected char[] authUsername
-
authPassword
protected char[] authPassword
-
desktopCategories
protected java.lang.String desktopCategories
-
desktopKeywords
protected java.lang.String desktopKeywords
-
createPathVariable
protected boolean createPathVariable
-
createIconForDeletion
protected boolean createIconForDeletion
-
iconForDeletionPath
protected java.lang.String iconForDeletionPath
-
isInstallationStarted
protected boolean isInstallationStarted
-
createUnitFile
protected boolean createUnitFile
-
startAtBoot
protected java.lang.Boolean startAtBoot
-
unitDescription
protected java.lang.String unitDescription
-
unitAfter
protected java.lang.String unitAfter
-
unitStartLimitBurst
protected java.lang.Integer unitStartLimitBurst
-
unitStartLimitInterval
protected java.lang.Integer unitStartLimitInterval
-
installWantedBy
protected java.lang.String installWantedBy
-
installAliasName
protected java.lang.String installAliasName
-
serviceWorkingDir
protected java.lang.String serviceWorkingDir
-
serviceUser
protected java.lang.String serviceUser
-
serviceGroup
protected java.lang.String serviceGroup
-
serviceEnvironment
protected java.util.List<java.lang.String> serviceEnvironment
-
serviceExecStartPre
protected java.util.List<java.lang.String> serviceExecStartPre
-
serviceExecStartPost
protected java.util.List<java.lang.String> serviceExecStartPost
-
serviceTimeout
protected java.lang.Integer serviceTimeout
-
serviceType
protected java.lang.String serviceType
-
serviceExecStart
protected java.util.List<java.lang.String> serviceExecStart
-
serviceExecStop
protected java.lang.String serviceExecStop
-
serviceRestart
protected java.lang.String serviceRestart
-
serviceRestartSec
protected java.lang.Integer serviceRestartSec
-
-
Constructor Detail
-
InstallConfig
public InstallConfig(java.lang.String company, java.lang.String version, java.lang.String applicationNameShort, java.lang.String applicationNameLong)
Creates a configuration object for the installation with all the necessary informations- Parameters:
company
- the name of your company under which the application should be installedversion
- the versionapplicationNameShort
- the short name of your applicationapplicationNameLong
- the long name of your application
-
-
Method Detail
-
getOsType
public static InstallConfig.OSType getOsType()
-
setDebug
public void setDebug(boolean debug)
When the debug mode is enabled, all error messages will be printed out exactly- Parameters:
debug
- if the debug mode should been enabled
-
getDebug
protected boolean getDebug()
-
setQuiet
public void setQuiet(boolean quiet)
If the installation should be executed in the background -> no command prompt will appear and prompts will be ignored- Parameters:
quiet
- Whether to run the installation in the background
-
getQuiet
protected boolean getQuiet()
-
getVersion
protected java.lang.String getVersion()
-
getCompany
protected java.lang.String getCompany()
-
getApplicationNameShort
protected java.lang.String getApplicationNameShort()
-
getApplicationNameLong
protected java.lang.String getApplicationNameLong()
-
getData
protected tk.rpjosh.installer.Data getData()
-
getIsUser
protected boolean getIsUser()
-
getIsPortable
protected boolean getIsPortable()
-
setFontsToInstall
public void setFontsToInstall(java.util.Map<java.lang.String,java.lang.String> fonts)
The given fonts will be installed (the fonts has to be in the format .ttf)- Parameters:
fonts
- a map with all the fonts: the name without .ttf | location of the fonts within the jar file (with .ttf)
-
getFontsToInstall
protected java.util.Map<java.lang.String,java.lang.String> getFontsToInstall()
-
setDownloadURLForProgramm
public void setDownloadURLForProgramm(java.lang.String url, char[] basicAuthUser, char[] basicAuthPassword)
Sets the URL of the file to be installed. The executable will be downloaded from the specified URL- Parameters:
url
- the URLbasicAuthUser
- [ the user for the basic auth ]basicAuthPassword
- [ the passwort for the basic auth ]
-
setDownloadURLForProgramm
public void setDownloadURLForProgramm(java.lang.String url, char[] basicAuthUser, char[] basicAuthPassword, java.lang.String end)
Sets the URL of the file to be installed. The executable will be downloaded from the specified URL In addition the operation system and the architecture will be added automatically to the URL (_windows_x64, _linux_arm32)- Parameters:
url
- die URL (without file extension)basicAuthUser
- [ the user for the basic auth ]basicAuthPassword
- [ the passwort for the basic auth ]end
- die file ending of the file (.jar)
-
setDownloadOfflinePath
public void setDownloadOfflinePath(java.lang.String path)
Installs the executable from the local file systems instead of downloading the file- Parameters:
path
- the path of the jar file in the file system
-
getOffline
protected boolean getOffline()
-
installDesktopEntry
public void installDesktopEntry(java.lang.String windowsICO, java.lang.String linuxPNG, java.lang.String keywords)
Creates a desktop entry during the installation. - Windows: a entry will be created in the public desktop or in the user desktop directory (for a user installation). also an entry in the start menu will be created. - Linux: the desktop file will be registered into the start menu. The given picrute will be saved under the program directory under pics/desktop.png / pics/desktop.ico- Parameters:
windowsICO
- [Windows] the path to the .ico file inside the jar file (resource/pic.ico). The optimum resolution is 256x256linuxPNG
- [Linux] the path of the .png file inside the jar file ...keywords
- [Linux] key-words for the desktop entry e.g: Spiele;Berichtshefte;Dokumente;Textverarbeitung;
-
getDesktopWindowsICO
protected java.lang.String getDesktopWindowsICO()
-
getDesktopLinuxPNG
protected java.lang.String getDesktopLinuxPNG()
-
getCreateDesktopEntry
protected boolean getCreateDesktopEntry()
-
setDesktopCategories
public void setDesktopCategories(java.lang.String categories)
[Linux] Sets the categories in which the applications should be present in the menus (desktop entry)- Parameters:
categories
- the categories separated by a ';' (e.g. Office;AudioVideo;Network;System)
-
setDesktopKeywords
public void setDesktopKeywords(java.lang.String keywords)
[Linux] Sets the keywords for the application (desktop entry)- Parameters:
keywords
- the keywords separated by a ';'
-
setRunInBackgroundByDefault
public void setRunInBackgroundByDefault(boolean runInBackground)
When the application is launched from the command line, the program will be launched in the foreground normally. With the parameter --b can the program be launched in the foreground- Parameters:
runInBackground
- whether the program should be launched in background by default -> for launching it in the foreground the parameter --f is required
-
getRunInBackgroundByDefault
protected boolean getRunInBackgroundByDefault()
-
createServiceUnitFile
public void createServiceUnitFile(boolean startAtBoot, java.lang.String unitDescription, java.lang.String unitAfter, java.lang.Integer unitStartLimitBurst, java.lang.Integer unitStartLimitInterval, java.lang.String installWantedBy, java.lang.String installAliasName, java.lang.String serviceWorkingDir, java.lang.String serviceUser, java.lang.String serviceGroup, java.util.List<java.lang.String> serviceEnvironment, java.util.List<java.lang.String> serviceExecStartPre, java.util.List<java.lang.String> serviceExecStartPost, java.lang.Integer serviceTimeout, java.lang.String serviceType, java.util.List<java.lang.String> serviceExecStart, java.lang.String serviceExecStop, java.lang.String serviceRestart, java.lang.Integer serviceRestartSec)
[Linux] Creates a unit file for systemd. All the given parameters are optional (except startAtBoot). For the ..Exec.. parameters and the working directory you can use #~LaunchScript~#, #~AppPath~#, #~ConfigPath~# with a leading slash -> /home/myPath/- Parameters:
startAtBoot
- whether the service should start at boot timeunitDescription
- the description of the serviceunitAfter
- after which target the service should been startedunitStartLimitBurst
- the maximum number of start retriesunitStartLimitInterval
- the interval in seconds in which the maximum number of start retries should been summarizedinstallWantedBy
- to which time of the boot process the service should been started -> multi-user.target (normal) or graphical.target (when GUI is needed)installAliasName
- an alias for the service nameserviceWorkingDir
- the working directory of the serviceserviceUser
- the user for the serviceserviceGroup
- the group for the serviceserviceEnvironment
- the environment variables to setserviceExecStartPre
- the commands to execute before the service starts. Useto replace the location of the launch script serviceExecStartPost
- the commands to execute after the service has started. Useto replace the location of the launch script serviceTimeout
- the number of seconds which should been allowed to start / stop the serviceserviceType
- the type of the service -> oneshot, simple, exec and forkingserviceExecStart
- the start command. Please take in mind that only with the type "oneshot" multiple commands can be specified. Useto replace the location of the launch script serviceExecStop
- the stop command. Use #LaunchScript# to replace the location of the launch scriptserviceRestart
- whether the service should been restarted when the execution failed -> on-failure or alwaysserviceRestartSec
- the number of seconds to wait between a restart
-
setEstimatedSize
public void setEstimatedSize(double estimatedSize)
[Windows] The estimated size of the whole application which should been displayed to the user- Parameters:
estimatedSize
- the estimated size in megabyte
-
getEstimatedSize
protected int getEstimatedSize()
[Windows] Returns the setted estimates size of the program- Returns:
- the estimated size in bytes
-
setIconForWindowsUninstaller
public void setIconForWindowsUninstaller(java.lang.String windowsICO)
[Windows] Icon for the removal of the application. A file (pics/uninstall.ico) will be created.- Parameters:
windowsICO
- the path of the .ico file inside of the jar file (e.g. resource/uninstall.ico)
-
setPortable
public void setPortable(java.lang.String dir)
Installs the program portable- Parameters:
dir
- the main directory for the portable installation (e.g. C:/Users/de03710/MyProgram/)
-
setUserInstallation
public void setUserInstallation()
[Windows] Installs the program only for the actual user -> administrator rights aren't necessary
-
createPathEntry
public void createPathEntry()
[Windows] creates a entry in the path variable for the program TODO: create Launcher wie unter Linux
-
getDesktopDir
protected java.lang.String getDesktopDir()
Returns the path of the desktop- Returns:
- desktop path: /home/user/Desktop/ or C:/User/myUserName/Desktop/. when no path could been determined, null will be returned
-
getConfigDir
public java.lang.String getConfigDir()
Returns the configuration directory of the application: /home/user/.config/ or C:\Users\User\AppData\ If the path isn't existing, it will be created- Returns:
- the path of the directory: /home/user/.config/Company/ShortName/
-
createConfigDirs
public void createConfigDirs(java.util.ArrayList<java.lang.String> directorys)
Creates the given directory in the configuration directory- Parameters:
directorys
- a list with all the directorys to create. This are relative paths -> logs/ or config/
-
getApplicationDir
public java.lang.String getApplicationDir()
Returns the main directory of the application. If the directory doesn't exist, it will be created- Returns:
- the path of the application dir: C:/Program Files/Company/MyProgram/
-
createProgramDirs
public void createProgramDirs(java.util.ArrayList<java.lang.String> directorys)
Creates the given directory in the application directory- Parameters:
directorys
- a list with all the directorys to create. This are relative paths -> logs/ or config/
-
initApplicationDir
protected void initApplicationDir()
-
getPortableDir
protected java.lang.String getPortableDir()
Returns the main directory of the portable installation- Returns:
- the path: C:/Users/de03710/BeMa/
-
getResource
protected boolean getResource(java.lang.String pathInJar, java.lang.String pathToWrite, boolean logError)
Extracts a file from the jar file and copy it to the given path- Parameters:
pathInJar
- the path in the jar file to extract: resource/48x48.pngpathToWrite
- the destination pathlogError
- if an error message should be displayed- Returns:
- if the resource was sucessfully extracted
-
getResource
protected boolean getResource(java.lang.String pathInJar, java.lang.String pathToWrite)
Extracts a file from the jar file and copy it to the given path- Parameters:
pathInJar
- the path in the jar file to extract: resource/48x48.pngpathToWrite
- the destination path- Returns:
- if the resource was sucessfully extracted
-
getLocationOfJarFile
protected java.lang.String getLocationOfJarFile()
Returns the path to the actual jar file- Returns:
- the absolute path to the jar file: C:/Users/myUserName/BeMa.jar. When no jar file was found (when launched in Eclipse) the path to the "extracted" jar file will be returned
-
setLocationOfJarFile
protected void setLocationOfJarFile(java.lang.String location)
Sets the path to the jar runtime path -> overwrite for the portable installation- Parameters:
location
- the absolute path to the jar file: C:/Users/de03710/BeMa.jar
-
setMaxHeapSize
public void setMaxHeapSize(int sizeInMb)
Sets the maximum heap size the JVM may consume (-Xmx)- Parameters:
sizeInMb
- the maximum size in megabye
-
getMaxHeapSize
protected int getMaxHeapSize()
-
-