Skip to content

Latest commit

 

History

History
437 lines (335 loc) · 23.7 KB

functions.asciidoc

File metadata and controls

437 lines (335 loc) · 23.7 KB
Table of Contents

Documentations of functions

1. Functions for testing flags

The functions for testing flags return 0 (true) if flag is set and 1 (false) otherwise. The name of the flag is part of the function name.

1.1. doIsBatch

Determines if batch mode is active. This mode shall be used for non-interactive usage (e.g. in automated invocations) where no user is available for interactive feedback. It can be enabled with -b or --batch.

1.2. doIsDebug

Determines if debug mode is active. This mode activates more verbose output for debugging. It can be enabled with -d or --debug.

1.3. doIsForce

Determines if force mode is active. This mode enforces specific aspects such as downloading cached resources again or to answer questions to continue automatically with yes. It can be enabled with option -f or --force.

1.4. doIsQuiet

Determines if quiet mode is active. This mode reduces the output to a minimum so information messages are suppressed. It can be enabled with option -q or --quiet.

2. Functions for input and output

Output functions like doEcho support backslash-escaped characters, for example "\n" for new line.

2.1. doAskToContinue

Display a question and ask the user if he wants to continue. In force or batch mode, it will continue automatically.

Param

Name

Description

$1

question

The question to display. Defaults to Do you want to continue?.

$2

return

If the user does not want to continue, this function will exit immediately by default. However, if return is passed the function will return 255 and the called can handle the program flow.

2.2. doConfirmWarning

Passes all arguments to doWarning to print as warning. Then it calls doAskToContinue.

2.3. doDebug

Prints the given arguments as debug message with according coloring (in gray). Debug messages will be printed in debug mode.

2.4. doEcho

Prints the given arguments as regular info message. The message will be suppressed in quiet mode.

2.5. doEchoAttention

Like doWarning but prefixes the message with an ATTENTION header.

2.6. doEchoInteraction

Prints the given arguments as interaction message with according coloring (in light blue). An interaction message is an information or question the end-user should react to with interactive feedback.

2.7. doEchoOption

Prints the given arguments as option message with according coloring (in light blue). An option message is an option the user can choose from.

2.8. doEchoStep

Prints the given arguments as step message with according coloring (in purple). A step message informs about a step as part of a command or process that has been completed.

2.9. doError

Prints the given arguments as error message with according coloring (in bright red). An error message informs the user that something went wrong. The coloring should help to highlight such problems.

2.10. doFail

Prints an ATTENTION banner. Then it prints the first argument followed by a generic text as error message. Then this function immediately exists the program with an error code. The error code can be provided as second argument but 0 will be replaced with 1 and if omitted 255 is used.

2.11. doInfo

Prints the given arguments as info message with according coloring (in blue). An information message is a more important message but not indicating any problem (like warning or error).

2.12. doLicenseAgreement

Ensures that the end-user confirms the license agreement of devonfw-ide on the first usage on his machine. If the user has already confirmed, this function will have no effect. Otherwise it will print the logo followed by the license information. This contains a link that will also be opened automatically in the web-browser. Then doAskToContinue is used to let the user confirm the license agreement. If the user does not confirm or runs in batch mode this function will fail with an error message. Otherwise, the user confirmation will be saved to $DEVON_HOME_DIR/.devon/.license.agreement.

Prints out the devon logo with clipping if the width of the terminal is too small to prevent line-wrapping.

2.14. doQuestion

Passes arguments to doEchoInteraction.

2.15. doResult

Handles the result of a command. Will print the operation ($1) as success message if exitCode ($2) is 0. Otherwise it will pass it to doFail.

Param

Name

Description

$1

operation

The operation that failed or succeeded.

$2

exitCode

0 for sucess, otherwise the error code.

2.16. doSuccess

Prints the given arguments as success message with according coloring (in green).

2.17. doWarning

Prints the given arguments as warning message with according coloring (in orange).

3. Environment Checks

The functions for testing environments return 0 (true) if the operating-system matches and 1 (false) otherwise.

3.1. doIsMacOs

Checks if the operating system is detected as MacOs.

3.2. doIsWindows

Checks if the operating system is detected as Windows.

4. Functions to verify requirements

4.1. doRequireNotBatch

Uses doIsBatch to check whether the batch variable is set and, if set, issues an error message.

4.2. doRequireWsl

Checks whether Windows Subsystem for Linux (WSL) is installed and whether it is activated and issues a corresponding message via doFail if one of the two requirements is not met.

5. Functions for generic command execution

5.1. doDevonCommand

Calls doDevonCommandAndReturn and passes all the parameters. On success it calls doUpdatePath to ensure the PATH is updated after an installation. On failure it will ask to continue if not in batch mode or exit immediately with the error code.

5.2. doDevonCommandAllWorkspaces

Iterates over all workspaces (sub-folders of workspaces folder) and executes the given commandlet in each of them.

5.3. doDevonCommandAndReturn

Runs the commandlet at $DEVON_IDE_HOME/scripts/command/$1 with the further given arguments. It will automatically pass mode options like batch to the commandlet before other given arguments. Further it prints an error message if the commandlet was not successful. It will return with the exit code of the commandlet that has been invoked.

Param

Name

Description

$1

commandlet

The devonfw-ide commandlet to call. E.g. help or ide.

$2-$n

args

Any additional argument is passed to the specified commandlet.

5.4. doRunCommand

Executes the given command ($1). If a a third parameter ($3) is provided, it has to point to an existing directory where to command will be executed and the function will return back to the original directory afterwards. It will use doResult using the message ($2) to handle the result of the command execution (success or failure).

Param

Name

Description

$1

command

The command to execute including all its parameters.

$2

message

Optional description of the command. Will fall back to "run command" followed by a simplification of the command ($1).

$3

dir

Optional working directory where to execute the command.

5.5. doRunFirstExecutable

Runs the first executable from the given arguments. It supports executables but can also run EXE and MSI files on windows. It will only return if the execution was successful. Otherwise it will always exit. For example doRunFirstExecutable "${dir}/".msi "${dir}/".exe will run the first found MSI or EXE file from the directory ${dir}.

6. Functions for IO operations (download, install, backup, extract, load, save)

6.1. doBackup

Takes a file or directory as the first parameter and the date after which the backup directory is named that is to be created in the updates/backups subdirectory for the backup as the second parameter. If the second parameter is not specified, the current date is used. If a single file is specified in the first parameter and such a file already exists in the backup directory, then a time stamp is added to the backup directory as an additional subdirectory. Then the backup directory is created and the files to be backed up are moved there.

6.2. doBrewInstall

Installs a tool using homebrew. If homebrew is installed (brew command found), the desired tool will be installed using brew install. Otherwise, the function will fail with an error message guiding the user to install homebrew.

6.3. doDownload

Downloads an artifact from the internet. If the URL is not provided as first argument, it will use the urls config to automatically determine the URL from the other arguments.

Param

Name

Description

$1

URL

The explicit URL to download from or - to compute from urls.

$2

dir

The optional target directory where to save the downloaded file.

$3

name

The name of the software to download.

$4

version

The version of the software to download. May be omitted to download the latest version.

$5

edition

The optional edition of the software to install (e.g. "enterprise" or "community").

$6

os

The optional OS indicator ('-' if OS independent). If omitted the OS will be determined automatically.

$7

arch

The optional architecture (e.g. x86_64).

$8

ext

The optional extension (e.g. 'tar.gz' or 'zip').

$9

filename

The optional filename to save the downloaded file to.

6.4. doDownloadInternal

Takes the URL as the first parameter, a temporary name for the file to be downloaded as the second, and the target directory in which the file is to be stored as the third parameter. Optionally, the name of the downloaded file can be given as a fourth parameter. If this does not happen, the name is determined from the URL. If the file exists and the force option was not specified, the function ends with a corresponding message and the return value 255. Otherwise the file is downloaded and, if successful, moved to the target directory.

6.5. doEnvironmentProject

Loads all devon.properties via doLoadProperties. If the first argument is not empty (set to export) it will export all the properties. Also it sets the environment variables DEVON_HOME_DIR, WORKSPACE, and WORKSPACE_PATH. Finally, it updates the PATH variable via doUpdatePath and exports it.

6.6. doExtract

Takes the file to be extracted and possibly a path to where it should be extracted. Then the right tool is selected based on the file extension and the file is unzipped.

6.7. doGitPullOrClone

Takes the target path and the URL or URL#branch as parameters. If the directory is a Git repository, it is tested whether remote repositories are configured and, if so, a git pull is performed. If not, a corresponding message is output and the function is ended with a return value of 1. If the directory is not a Git repository and no URL was specified, the function is aborted with a doFail message. However, if a URL was specified, the specified directory is created, changed to the directory and the repository of the specified URL is cloned into the specified directory. If the branch was also specified in the URL, a checkout is carried out on this branch.

6.8. doInstall

Ensures a specific version of a software is installed. If no fixed version is given, it resolves the final version (if version is empty use latest, in case of version prefix use latest matching version). In case the software is already installed in the resolved version, return 1.

Param

Name

Description

$1

software

The name of the software to install.

$2

version

The version of the software to install. May be omitted to install the latest version.

$3

silent

The optional silent flag ('silent' to suppress output if already up-to-date or empty for version output).

$4

edition

The optional edition of the software to install (e.g. "enterprise" or "community").

$5

path

The absolute target path where to install the software.

$6

os

The optional OS indicator ('-' if OS independent). If omitted the OS will be determined automatically.

$7

noUnpack

The optional argument to ignore extracting downloaded files (use 'noUnpack' or leave empty to extract)

$8

repo

The optional software repository.

$9

url

The optional download URL.

$10

target filename

The optional target filename.

6.9. doInstallWithPackageManager

Called with a list of installation options for various (non windows) operating systems. For each provided installer option it will check if that installer (e.g. apt-get, yum, apk, brew) is present. If present, it will call that option with sudo and return. In case none of the provided installer options could be executed, it will fail with an according error message.

6.10. doLoadProperties

Loads a .properties file given as first argument into variables of the bash context. The second argument allows to specify an optional prefix for the variables to load. So e.g. if the properties file contains foo=bar and seconds argument is some_ it will result in the variable assignment some_foo=bar. In case the third argument is not empty, then all variables will be exported. *ATTENTION: This function is defined in the file environment-project.

6.11. doMoveGlobSafe

Moves the file specified as the second parameter after checking whether it exists to the target specified in parameter one and outputs the performed action via doEcho.

6.12. doOpen

Opens the URL passed to it in the browser window or calls the specified program under Windows or MacOS.

6.13. doReplaceExtracted

Prepares to move an unpacked archive (specified in the first parameter). The current date is defined as the name for the backup directory of the currently installed software. Then it is checked whether the target directory (specified in the second parameter) corresponds to DEVON_IDE_HOME. If it does not correspond to DEVON_IDE_HOME, the function doReplaceExtractedSkipSingleFolder is called and the parameters archive directory, target directory, backup directory and the specification that all files in the archive directory are to be processed are passed. If the target directory is DEVON_IDE_HOME, which corresponds to the complete devonfw IDE installation, then all files and directories, except the workspaces directory, are passed in a loop to the doReplaceExtractedFile function as the first parameter, the second parameter specifies the target directory with the corresponding subdirectory names and the third Parameter is the backup directory. Attention: for one installation package the function doReplaceExtractedSkipSingleFolder is called, while in the other case the function doReplaceExtractedFile is called in a loop.

6.14. doReplaceExtractedFile

Called with the three parameters path of the file or directory to be moved, the target directory and a backup directory. The function creates missing directories, makes a backup from the target directory to the backup directory. Then the files specified in the first parameter are moved to the target directory. Finally, the migration script is run to migrate the ide to the latest version.

6.15. doReplaceExtractedSkipSingleFolder

The parameters source directory, target directory, backup directory and possibly a list of files and directories via shell file name expansion (globbing) are passed to the doReplaceExtractedSkipSingleFolder function. The first three parameters are taken directly into variables and removed from the list of passed parameters with the shift so that the last specification can be viewed as a whole. If the last parameter is a single directory and, on MacOS, not a directory with a name like *.app, it is taken as the source directory. Then the function doReplaceExtractedFile is called with the saved parameters, with source directory, target directory and backup directory.

6.16. doUnzip

Checks if an unzip program is installed, and if not, installs the program. The file specified in the first parameter is then unpacked into the directory specified in the second parameter.

6.17. doUpdateUrls

Uses doGitPullOrClone to clone or pull urls ensuring that everything is up-to-date.

6.18. doCheckNetworkStatus

Checks if system is connected to the internet, if online, it returns the value 0, and if offline, it returns the value 1.

7. Functions on system PATH, files, or folders

7.1. doExtendPath

Takes a directory as a parameter. The function then checks whether the "bin" subdirectory exists in the transferred directory. If the directory exists, the PATH variable is extended by this "bin" directory. Otherwise the PATH variable is expanded with the passed directory.

7.2. doGetExtension

Takes a file name as a parameter, including the path, and returns the file extension as the result.

7.3. doGetFirstExistingPath

Takes a list of directories as a parameter and then checks in the specified order until one of the specified directories exists. This directory is then output and the function ends with the return value 0. If none of the passed directories exist, the function ends with the return value 1.

7.4. doGetFirstExistingPathOrFail

Takes a list of directories as a parameter and then checks in the specified sequence until one of the specified directories exists. This directory is then output and the function ends with the return value 0. If none of the directories passed exist, the doFail function is called with a corresponding message.

7.5. doIsEmptyDirectory

Checks whether the directory passed as a parameter is empty. If the directory is empty, the return value is 0, otherwise 1.

7.6. doIsIgnoredFolder

Checks whether the directory that is passed to it as a parameter corresponds to the directory target, eclipse-target, node_modules, .git, or .svn and returns the return code 0 otherwise 255.

7.7. doIsInstallerExtension

Checks whether the file extension of the file specified in the parameter is an executable file, i.e. .exe .msi .pkg or .bat. If so, the function returns 0, otherwise 255.

7.8. doUpdatePath

Updates the PATH variable according to the latest tools installed in the software folder. ATTENTION: This function is defined in the file environment-project.

8. Version handling

8.1. doCheckSoftwareSecurityVersion

Determines whether the actual version is contained in the security file for the corresponding tool and print out a message if so.

8.2. doCheckVersionRange

Determines whether a version is in a version range.

8.3. doGetAnyLatestSoftwareVersion

Determines the latest available version of software and returns it. If a prefix is given, it will be taken into account.

8.4. doGetLatestSoftwareVersion

Determines the latest stable available version of software and returns it. If a prefix is given, it will be taken into account.

8.5. doGetNextVersion

A version number is passed to the function doGetNextVersion as an argument and the next version number is generated from this by incrementing the last digit by one and outputs it.

8.6. doGetSoftwareEdition

Determines the currently in the environment configured edition of a software and returns it.

8.7. doGetSoftwareVersion

Determines the currently installed version of a software and prints it out for the end-user.

Param

Name

Description

$1

software

The software tool to check (e.g. maven or java).

$2

version_cmd

The command to determine the version via the software. Maybe - if the software is a regular installation but does not support this.

$3

commandlet

The commandlet corresponding to the software. Typically the same as $1 but may differ (e.g. mvn instead of maven). Only used for log messages to assist end-user.

8.8. doIsDevVersion

Checks whether one of the two values "dev-SNAPSHOT" or "0-SNAPSHOT" was passed to it as a parameter. If this is the case, it ends with the return value 0 otherwise 1.

8.9. doListSoftwareVersions

Takes the name of the tool as a parameter and displays the available versions.

8.10. doReportVersionSecurityWarning

Prints out a message on version security alerts.

8.11. doSetSoftwareVersion

Used to set a specific version of a software tool, and requires 2 parameters: the name of the software tool and the desired version. The version is saved as «tool»_VERSION variable in settings/devon.properties.

8.12. doVersionCompare

Two version numbers are passed to the doVersionCompare function as parameters. If the versions are equal, the function returns 0, if the first version is higher than the second, returns 1, and if the second version is higher than the first, the function returns 2.

9. Functions on workspaces

9.1. doConfigureWorkspace

Runs the configurator using doRunConfigurator to configure a workspace.

9.2. doCreateIdeScript

Creates a launch script for the IDE given as first argument (e.g. eclipse) and the configured workspace ($WORKSPACE).

9.3. doRunConfigurator

Runs the given Java class from the configurator (jar files in lib) with the given arguments.

10. Functions for Maven

10.1. doMavenArchetype

Calls maven to generate archetype (project template) for the given parameters. Uses $ARCHETYPE_GROUP_ID and $ARCHETYPE_ARTIFACT_ID that default to devon4j template.

10.2. doMavenGetLatestVersion

The doMavenGetLatestVersion function looks in the artifact repository specified in the (url) parameter for the latest version of the software stored there.

10.3. doUpgradeMavenArtifact

The function doUpgradeMavenArtifact first looks in the target directory to see if it is a git repository and then carries out a doGitPullOrClone if necessary and then terminates the function. If the target directory is not a git repository and LATEST was specified as the fourth parameter for the target version, then the latest target version of the Maven artifact (parameter 3) is determined under the url (parameter 2). Now the current version (parameter 6) is compared with the desired target version, and if it is the same or if the current version is greater than the target version, the function aborts with a corresponding message. If the target version is larger than the current version, the software is installed in the target version in the target directory (parameter 1).

11. Misc

11.1. doArrayContainsItemWithPrefix

An array is defined from a number of elements, with the last element being defined as a prefix. The function doArrayContainsItemWithPrefix now checks the array if it contains elements that start with this prefix. If this is the case, the function ends with the return value 0, otherwise with 1.

11.2. doIsPackageJsonContainingScript

Checks whether the module passed with the first parameter is contained in the package package.json. If so, then it ends with the return value 0 otherwise with a message and the return value 255.

11.3. doIsPrefix

Checks if the first arg is a prefix of the second arg. E.g. doIsPrefix "foo/bar" "foo/bar/some" will be true but doIsPrefix "/foo/bar" "foo/bar/some" will be false.

11.4. doParseOption

Checks whether the parameter passed to it

11.5. doVerifyChecksums

Creates a sha256 checksum for a file and compares it to the given checksum

  • is one of the options -b, -f, -d or -q and accordingly sets the associated variable batch, force, debug or quiet and terminates the function with the return value 0.

  • is the option version. In this case, it does the handling to list, get, or set the version and exits the program.

If — is passed, a variable is set that prevents further calls of this function and ends with the return value 0. If none of these options are passed, the return value is 255.