diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 2d237726c..381a0e08d 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -7,8 +7,13 @@ This file documents all notable changes to https://github.com/devonfw/ide[devonf New release with various improvements and bugfixes: * https://github.com/devonfw/ide/issues/826[#826]: List available versions for a tool +* https://github.com/devonfw/ide/issues/878[#878]: Use default tool version from `available-versions` +* https://github.com/devonfw/ide/issues/893[#893]: Ability to configure version prefix +* https://github.com/devonfw/ide/issues/908[#908]: AWS CLI integration for MacOS and bugfix for win/linux +* https://github.com/devonfw/ide/issues/940[#940]: Make doInstall even more generic * https://github.com/devonfw/ide/issues/935[#935]: doDevonCommand should use doFail instead of doAskToContinue * https://github.com/devonfw/ide/issues/905[#905]: Better error handling when installing Eclipse plugins +* https://github.com/devonfw/ide/issues/960[#960]: openshift version check fails * https://github.com/devonfw/ide/issues/929[#929]: Ensure function documentation is in sync The full list of changes for this release can be found in https://github.com/devonfw/ide/milestone/34?closed=1[milestone 2022.08.004]. diff --git a/documentation/DoD.asciidoc b/documentation/DoD.asciidoc index 531567339..9f3d2d6db 100644 --- a/documentation/DoD.asciidoc +++ b/documentation/DoD.asciidoc @@ -22,7 +22,7 @@ However, chances to get your change merged quickly are higher if you address all * [ ] You followed all coding conventions (indent with 2 spaces, no tabs, functions start with `do` prefix, variables are enclosed with curly braces, variables in functions are declared with `local`, etc.) * [ ] You have already added the issue implemented by your PR in https://github.com/devonfw/ide/blob/master/CHANGELOG.asciidoc[CHANGELOG.asciidoc] to the next open release (see milestones or https://github.com/devonfw/ide/blob/master/.mvn/maven.config[maven.config]). If there is no issue for your PR consider creating it or directly link the PR itself. Please note that the CHANGELOG shall only reflect public changes relevant for end-users. So e.g. if we implement a story and then add another PR as bugfix or improvement to the same story, we do not need to document this in the CHANGELOG to avoid spam and confusion. * [ ] In case your PR adds a new tool `«tool»` as commandlet there are the following additional checks: -** [ ] The tool is already available as folder `«tool»` in https://github.com/devonfw/ide-mirrors[ide-mirrors] +** [ ] The tool is already available as folder `«tool»` in https://github.com/devonfw/ide-mirrors[ide-mirrors] including `available-versions`. ** [ ] A new commandlet named `«tool»` has been added to https://github.com/devonfw/ide/tree/master/scripts/src/main/resources/scripts/command[command] that allows to install and launch the given software. ** [ ] The tool can be installed automatically (during setup via settings) or via the commandlet call. ** [ ] During the installation process (`devon «tool» setup`) reasonable progress and status information are displayed. @@ -36,6 +36,8 @@ However, chances to get your change merged quickly are higher if you address all ** [ ] The new tool is added to the table of tools in https://github.com/devonfw/ide/blob/master/documentation/LICENSE.asciidoc#license[LICENSE.asciidoc] with its according licesne. If that license is not yet included, the full license text needs to be added. ** [ ] The new commandlet is a https://github.com/devonfw/ide/blob/master/documentation/cli.asciidoc#command-wrapper[command-wrapper] for `«tool»`. ** [ ] The new commandlet installs potential dependencies automatically (e.g. `doDevonCommand «required-other-tool» setup silent`). +** [ ] The new commandlet defines the variable `TOOL_VERSION_COMMAND` before sourcing the `functions`. If no version check is supported by the tool itself set the value to `-`. In case your commandlet is not about a tool that can be setup, simply set the value as empty to make this explicit. +** [ ] If the new commandlet is about a tool that can be setup, then test that also `devon «tool» version list`, `devon «tool» version get`, and `devon «tool» version set` are all working. ** [ ] The variable `«TOOL»_VERSION` is honored by your commandlet so if present that version will be downloaded and installed. ** [ ] The new commandlet is tested on all plattforms it is availible for. Assuming you are using Windows, testing for Linux can be done with the Windows Subsystem for Linux and for MacOS we have a virtual cloud instance. * [ ] In case your PR adds, changes, or removes a function (in `functions` or `environment-project`) you need to update `functions.asciidoc` accordingly. There is an automated test that will fail otherwise. diff --git a/documentation/functions.asciidoc b/documentation/functions.asciidoc index f135b380e..24bfce726 100644 --- a/documentation/functions.asciidoc +++ b/documentation/functions.asciidoc @@ -192,11 +192,10 @@ If the URL is not provided as first argument, it will use the `mirrors` config t |`$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` |code |The optional technical code used for specific software to compute download URL. -|`$7` |os |The optional OS indicator ('-' if OS independent). If omitted the OS will be determined automatically. -|`$8` |arch |The optional architecture (e.g. x86_64). -|`$9` |ext |The optional extension (e.g. 'tar.gz' or 'zip'). -|`$10` |filename|The optional filename to save the downloaded file to. +|`$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. |======================= === doDownloadInternal @@ -206,10 +205,34 @@ 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. +=== doEnvironmentProject +Loads all `devon.properties` via xref: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 xref:doUpdatePath[] and exports it. + === 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. +=== doResolveDownloadUrl +Function for additional custom logic when resolving the download URL. +The xref:doDownload[] function resolves standard variables like `version`, `os`, `arch`, and `ext` automatically in URLs from `mirrors` repository config. +However, for special cases this is insufficient as some tools do not follow best-pratices for consistent and systematic download URLs. +Therefore xref:doDownload[] will call this function to further resolve the computed download URL. +By default this function does nothing but echoing the given URL (`$1`). +However, a commandlet may override this function after souring `functions` in order to define custom logic for URL resolving. +When required, we typically resolve a `code` variable that can be derived from the arguments given to this function. + +|======================= +|*Param*|*Name* |*Description* +|`$1` |URL |The download URL with standard variables resolved. +|`$2` |version |The resolved version to download. +|`$3` |os |The resolved/mapped operating system. +|`$4` |arch |The resolved/mapped architecture (e.g. x86_64). +|`$5` |edition |The optional edition of the software to install (e.g. "enterprise" or "community"). +|======================= + === 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. @@ -219,37 +242,21 @@ However, if a URL was specified, the specified directory is created, changed to If the branch was also specified in the URL, a checkout is carried out on this branch. === doInstall -The url of the software to be installed, the target directory in which the software is to be stored and the name of the software are given as parameters to the doInstall function. -The function then downloads the software via doDownload into the download directory of the registered user, unpacks the software into the updates/extracted directory and then finally moves the software into the DEVON_IDE_HOME/software/"name of the software" directory. - -Additional parameters can also be passed to the function: - -* The version parameter ensures that a specific version of the software is installed. - -* If a "-" is passed to the function as the url, the settings from the Git repository ide-mirrors are used to download the correct software, e.g. -depending on the operating system. - -* You can specify your own repository using the repository parameter or the DEVON_SOFTWARE_REPOSITORY variable. -This ensures that the package to be installed is loaded from there. - -* If software is required that needs to be installed instead of just being unpacked and moved to the IDE_DEVON_HOME/software directory, you can set the directory for the installation software to DEVON_IDE_HOME/updates/install as the target directory. -Following the doInstall call in the commandlet, the installation of the software can then be initiated. - -* If parameters five through nine (edition, code, os, arch, and ext) are specified, they are passed directly to the doDownload function. +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` |URL |The explicit URL to download from or `-` to compute in xref:doDownload[]. -|`$2` |path |The absolute target path where to install the software. -|`$3` |name |The name of the software to install. -|`$4` |version |The version of the software to install. May be omitted to install the latest version. -|`$5` |edition |The optional edition of the software to install (e.g. "enterprise" or "community"). -|`$6` |code |The optional technical code used for specific software to compute download URL. -|`$7` |os |The optional OS indicator ('-' if OS independent). If omitted the OS will be determined automatically. -|`$8` |arch |The optional architecture (e.g. x86_64). -|`$9` |ext |The optional extension (e.g. 'tar.gz' or 'zip'). -|`$10` |repo |The optional software repository. -|`$11` |noUnpack|The optional argument to ignore extracting downloaded files (if not empty extracting will be skipped) +|`$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. |======================= === doInstallWithPackageManager @@ -408,6 +415,10 @@ If this is the case, the function ends with the return value 0, otherwise with 1 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. +=== 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. + === doParseOption Checks whether the parameter passed to it diff --git a/documentation/software.asciidoc b/documentation/software.asciidoc index 0db71188f..fec629009 100644 --- a/documentation/software.asciidoc +++ b/documentation/software.asciidoc @@ -26,22 +26,24 @@ This subfolder needs to contain the tool in that version for every operating sys By default, each installation of `devonfw-ide` has its own physical installations of the required tools in the desired versions stored in its local `software` folder. While this is great for isolation of `devonfw-ide` installations and to prevent side-effects, it can cause a huge waste of disc resources in case you are having many installations of `devonfw-ide`. If you are a power-user of `devonfw-ide` with more then ten or even up to hundreds of installations on your machine, you might love to share installations of a software tool in a particular version between multiple `devonfw-ide` installations. +In order to do so, you only need to link:configuration.asciidoc[configure] the variable `DEVON_SOFTWARE_PATH` in your `~/devon.properties` pointing to an existing absolute directory on your disc (e.g. `/projects/software` or `C:\projects\software`). -CAUTION: If you use this power-feature you are taking responsibility for side-effects and should not expect support. Also if you are using Windows please read https://www.joshkel.com/2018/01/18/symlinks-in-windows/[Symlinks in Windows] and make your mind if you really want to do so. You might also use this link:advanced-tooling-windows.asciidoc#create-symbolic-links[hint] and maintain it manually without enabling the following feature. +CAUTION: DEVON_SOFTWARE_PATH must be an absolte path that is an existing directory. On windows it has to be on the same drive as your IDE installations. If you use this power-feature you are taking responsibility for side-effects and should not expect support. You might also use this link:advanced-tooling-windows.asciidoc#create-symbolic-links[hint] and maintain it manually without enabling the following feature. -In order to do so, you only need to link:configuration.asciidoc[configure] the variable `DEVON_SOFTWARE_PATH` in your `~/devon.properties` pointing to an existing directory on your disc (e.g. `/projects/software` or `C:\projects\software`). Then `devonfw-ide` will install required software into `${DEVON_SOFTWARE_PATH}/${software_name}/${software_version}` as needed and create a symbolic link to it in `${DEVON_IDE_HOME}/software/${software_name}`. -As a benefit, another `devonfw-ide` installation will using the same software with the same version can re-use the existing installation and only needs to create the symbolic link. No more waste of having many identical JDK installations on your disc. +As a benefit, another `devonfw-ide` installation will using the same software with the same version can re-use the existing installation and only needs to create the symbolic link. +No more waste of having many identical JDK installations on your disc. As a drawback, you need to be aware that specific tools may be "manipulated" after installation. -The most common case is that a tool allows to install plugins or extensions such as all IDEs do. Such "manipulations" will cause side-effects between the different `devonfw-ide` installations sharing the same version of that tool. +The most common case is that a tool allows to install plugins or extensions such as all IDEs do. +Such "manipulations" will cause side-effects between the different `devonfw-ide` installations sharing the same version of that tool. While this can also be a benefit it may also cause trouble. If you have a sensitive project that should not be affected by such side-effects, you may again override the `DEVON_SOFTWARE_PATH` variable to the empty value in your `${DEVON_IDE_HOME}/conf/devon.properties` of that sensitive installation: ``` DEVON_SOFTWARE_PATH= ``` -This will disable this feature particularly for that specific sensitive `devonfw-ide` installation but let you use it for all other ones. +This will disable this feature particularly for that specific sensitive `devonfw-ide` installation but let you use it for other ones. == Custom diff --git a/scripts/src/main/resources/scripts/command/aws b/scripts/src/main/resources/scripts/command/aws old mode 100644 new mode 100755 index db0d3e2d3..c75d48fe1 --- a/scripts/src/main/resources/scripts/command/aws +++ b/scripts/src/main/resources/scripts/command/aws @@ -10,19 +10,9 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND="aws --version" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions -# Call aws with specified arguments. -function doRun() { - doSetup silent - findAws - doRunCommand "'${AWS}' ${*}" -} - - # OS independent check if aws is installed. function findAws() { AWS="aws" @@ -38,23 +28,32 @@ function findAws() { aws_win="${aws_win}/Amazon/AWSCLIV2/aws" if [ -f "${aws_win}" ] then - AWS="${aws_win}" AWS_INSTALLED="yes" fi + AWS="${aws_win}" fi + TOOL_VERSION_COMMAND="'${AWS}' --version" +} + +findAws +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli + +# Call aws with specified arguments. +function doRun() { + doSetup silent + findAws + doRunCommand "'${AWS}' ${*}" } # $1: path_to_package -# $2: software version -function doPackageInstall() -{ +function doPackageInstall() { local path_to_package="${1}" - local version="${2}" if doIsWindows then doEcho "Installing AWS for Windows..." windows_path_to_package=$(cygpath -w "${path_to_package}") - powershell.exe -Command "Start-Process msiexec.exe -verb runas -Wait -ArgumentList '/I ${windows_path_to_package}\aws-${version}-windows.msi /quiet'" + powershell.exe -Command "Start-Process msiexec.exe -verb runas -Wait -ArgumentList '/I ${windows_path_to_package}\aws-*-windows.msi /quiet'" elif doIsMacOs then doEcho "Installing AWS for MacOS..." @@ -71,33 +70,30 @@ function doPackageInstall() } function doSetup() { - local ERR="" - findAws - if [[ ${AWS_INSTALLED} != "yes" ]] || [[ "${1}" != "silent" ]] + if [ "${AWS_INSTALLED}" == "yes" ] then - # Get leatest release - if [ -z "${AWS_VERSION}" ] + if [ -z "${1}" ] then - doEcho "Getting latest release..." - AWS_VERSION=$(curl "https://github.com/aws/aws-cli/tags" | awk -F'tags/' '/archive/ { print $2}' | sort -r | head -1 | awk -F'.zip' '{print $1}') + doEcho "Aws already installed in version ${AWS_VERSION:-latest}" + doRunCommand "${TOOL_VERSION_COMMAND}" "verify installation of aws" fi - - doInstall "-" "${DEVON_IDE_HOME}/updates/install/aws" "aws" "${AWS_VERSION}" - ERR="${?}" - if [ "${ERR}" = "0" ] + else + # workaround as we are downloading the installer and not installing the software itself + TOOL_VERSION_COMMAND="-" + doInstall "aws" "${AWS_VERSION}" "${1}" "" "${DEVON_IDE_HOME}/updates/install/aws" + if [ "${?}" = 0 ] then - doPackageInstall "${DEVON_IDE_HOME}/updates/install/aws" "${AWS_VERSION}" + doPackageInstall "${DEVON_IDE_HOME}/updates/install/aws" + findAws + if [ "${1}" != "silent" ] && ! doIsQuiet + then + doRunCommand "${TOOL_VERSION_COMMAND}" "verify installation of aws" + fi fi doRunCommand "rm -rf ${DEVON_IDE_HOME}/updates/install/aws" - - if [ "${1}" != "silent" ] && ! doIsQuiet - then - doEcho "logon again to test aws with \"aws --version\"" - fi fi } - # CLI case ${1} in "help" | "-h") @@ -105,11 +101,11 @@ case ${1} in echo echo "Arguments:" echo " setup install aws on your machine." - echo " «args» call aws with the specified arguments. Call aws --help for details or use aws directly as preferred." + echo " «args» call aws with the specified arguments. Call aws --help for details or use aws directly as preferred." echo ;; "setup" | "s" | "") - doSetup + doSetup "${2}" ;; *) doRun "${@}" diff --git a/scripts/src/main/resources/scripts/command/az b/scripts/src/main/resources/scripts/command/az old mode 100644 new mode 100755 index 302ad67d2..f001553c4 --- a/scripts/src/main/resources/scripts/command/az +++ b/scripts/src/main/resources/scripts/command/az @@ -9,10 +9,11 @@ then fi exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND="az -v" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TOOL_VERSION_COMMAND="az -v" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli function doSetup() { if [ "${1}" != "silent" ] || [[ ! $(command -v az) =~ ${DEVON_IDE_HOME}/software/ ]] diff --git a/scripts/src/main/resources/scripts/command/build b/scripts/src/main/resources/scripts/command/build index fd11baaa6..45b428849 100755 --- a/scripts/src/main/resources/scripts/command/build +++ b/scripts/src/main/resources/scripts/command/build @@ -10,10 +10,11 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND= # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TOOL_VERSION_COMMAND= +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli function doBuild() { doDevonCommand "${@}" diff --git a/scripts/src/main/resources/scripts/command/cobigen b/scripts/src/main/resources/scripts/command/cobigen index b0c06b8af..aadc3a55c 100755 --- a/scripts/src/main/resources/scripts/command/cobigen +++ b/scripts/src/main/resources/scripts/command/cobigen @@ -10,10 +10,11 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND="cg -v" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TOOL_VERSION_COMMAND="cg --version" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli function doSetup() { # We need Java to run and Maven for installing plug-ins diff --git a/scripts/src/main/resources/scripts/command/docker b/scripts/src/main/resources/scripts/command/docker index 80277a4b3..8a6da6c55 100755 --- a/scripts/src/main/resources/scripts/command/docker +++ b/scripts/src/main/resources/scripts/command/docker @@ -10,10 +10,29 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND="docker version" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TOOL_VERSION_COMMAND="docker version" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli + +# $1: URL +# $2: resolved version +# $3: resolved os +# $4: resolved arch +# $5: optional software edition +function doResolveDownloadUrl() { + local url="${1}" + local version="${2}" + local code + if doIsWindows + then + code="Docker%20Desktop%20Installer" + else + code="Docker" + fi + echo "${url//\$\{code\}/${code}}" +} # $1: optional setup function doSetup() { @@ -39,26 +58,16 @@ function doSetup() { fi else doRequireNotBatch - local version="${RANCHER_VERSION}" - if [ -z "${version}" ] - then - version="1.4.1" - latestversion=$(curl -Ls -o /dev/null -w '%{url_effective}' https://github.com/rancher-sandbox/rancher-desktop/releases/latest | sed 's/.*\([0-9]\.[0-9]\.[0-9]\).*/\1/') - doVersionCompare "${latestversion}" "${version}" - VersCompRes=${?} - if [ "${VersCompRes}" = 1 ] - then - version=${latestversion} - fi - fi local rancher_install_dir="${DEVON_IDE_HOME}/updates/install/rancherdesktop" - doInstall "-" "${rancher_install_dir}" "rancher" "${version}" + TOOL_VERSION_COMMAND="-" + doInstall "rancher" "${RANCHER_VERSION}" "${1}" "" "${rancher_install_dir}" + TOOL_VERSION_COMMAND="docker version" if doIsWindows then doSetVpnKitStartupInstaller doEcho "Installing Rancher Desktop for Windows..." # ensures installation of vpnkit if user directly restarts computer for enabling wsl - doRunCommand "${rancher_install_dir}/rancher-${version}-windows.exe" + doRunCommand "${rancher_install_dir}/rancher-*-windows.exe" #check if vpnkit is already installed doEnsureVpnKitInstallation elif doIsMacOs @@ -82,18 +91,7 @@ function doSetup() { fi else doRequireNotBatch - local version="${DOCKER_VERSION:-stable}" - local code - if doIsWindows - then - code="Docker%20Desktop%20Installer" - elif doIsMacOs - then - code="Docker" - else - doFail "Sorry, docker-installation support is not yet implemented for your OS. Please use Rancher Desktop instead, or install manually or help devonfw-ide to support it for your OS by contributing a pull-request." - fi - doDownload "-" "" "docker" "${version}" "" "${code}" + doDownload "-" "" "docker" "${DOCKER_VERSION:-stable}" if doIsWindows then doEchoStep "Installing Docker Desktop for Windows..." @@ -134,7 +132,7 @@ function doEnsureVpnKitInstallation { #check if vpnkit is already installed if ! doIsVpnKitInstalled then - doInstallVpnKit + doInstallVpnKit #if still not installed, reboot needed for WSL feature, so we set a startup script to install after reboot if ! doIsVpnKitInstalled then @@ -237,7 +235,7 @@ case ${1} in echo " «args» call docker with the specified arguments. Call docker help for details or use docker directly as preferred." ;; "setup" | "s" | "") - doSetup setup "${2}" + doSetup "${2}" ;; *) doRun "${@}" diff --git a/scripts/src/main/resources/scripts/command/dotnet b/scripts/src/main/resources/scripts/command/dotnet index ee99b8a6e..6688ce2bf 100644 --- a/scripts/src/main/resources/scripts/command/dotnet +++ b/scripts/src/main/resources/scripts/command/dotnet @@ -9,10 +9,12 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND="dotnet --version" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TOOL_VERSION_COMMAND="dotnet --version" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli + cd "${DEVON_IDE_HOME}" || exit 255 function doExists() { @@ -25,19 +27,12 @@ function doExists() { } function doSetup() { - if [ "${1}" != "silent" ] || [ ! -d "${DOTNET_HOME}" ] + doInstall "dotnet" "${DOTNET_VERSION}" "${1}" + if doExists ~/.templateengine/packages/Devon4Net.WebAPI.Template* then - doInstall "-" "${DOTNET_HOME}" "dotnet" "${DOTNET_VERSION:-6.0.300}" - if doExists ~/.templateengine/packages/Devon4Net.WebAPI.Template* - then - doDebug "Devon4net template already installed." - else - doRun new -i devon4net.WebApi.Template - fi - fi - if [ "${1}" != "silent" ] && ! doIsQuiet - then - doRunCommand "'${DOTNET}' --version" "verify installation of dotnet" + doDebug "Devon4net template already installed." + else + doRun new -i devon4net.WebApi.Template fi } @@ -65,7 +60,7 @@ case ${1} in exit ;; "setup" | "s") - doSetup setup + doSetup "${2}" ;; "create" | "c") doRun new Devon4NetAPI diff --git a/scripts/src/main/resources/scripts/command/eclipse b/scripts/src/main/resources/scripts/command/eclipse index 509e8a836..270ceeb2c 100755 --- a/scripts/src/main/resources/scripts/command/eclipse +++ b/scripts/src/main/resources/scripts/command/eclipse @@ -14,21 +14,28 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi +# shellcheck source=scripts/functions +source "$(dirname "${0}")"/../functions ECLIPSE_HOME="${DEVON_IDE_HOME}/software/eclipse" +ECLIPSE="${ECLIPSE_HOME}/eclipse" +if doIsWindows +then + ECLIPSE="${ECLIPSE_HOME}/eclipsec" +fi ECLIPSE_JAVA_HOME="${JAVA_HOME}" if [ -n "${EXTRA_JAVA_VERSION}" ] then ECLIPSE_JAVA_HOME="${DEVON_IDE_HOME}/software/extra/java" fi -ECLIPSE_PRODUCT="${ECLIPSE_HOME}/Eclipse.app/Contents/Eclipse/.eclipseproduct" -if [ ! -e "${ECLIPSE_PRODUCT}" ] +ECLIPSE_PRODUCT="${ECLIPSE_HOME}/.eclipseproduct" +if doIsMacOs then - ECLIPSE_PRODUCT="${ECLIPSE_HOME}/.eclipseproduct" + ECLIPSE_PRODUCT="${DEVON_IDE_HOME}/software/macos/eclipse/Eclipse.app/Contents/Eclipse/.eclipseproduct" fi TOOL_VERSION_COMMAND="cat '${ECLIPSE_PRODUCT}'" -# shellcheck source=scripts/functions -source "$(dirname "${0}")"/../functions +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli + L_PWD=$(pwd) cd "${DEVON_IDE_HOME}" || exit 255 @@ -57,14 +64,13 @@ function doInstallEclipsePlugin() { local debug_info_file debug_info_file=$(mktemp) # get only !MESSAGE lines from the debug info - "${ECLIPSE_HOME}/eclipsec" -consoleLog -nosplash -vm "${ECLIPSE_JAVA_HOME}/bin/java" -application org.eclipse.equinox.p2.director -repository "${2}" -installIU "${1}" -vmargs "${ECLIPSE_VMARGS}" > "${debug_info_file}" 2>&1 + "${ECLIPSE}" -consoleLog -nosplash -vm "${ECLIPSE_JAVA_HOME}/bin/java" -application org.eclipse.equinox.p2.director -repository "${2}" -installIU "${1}" -vmargs "${ECLIPSE_VMARGS}" | grep '^!MESSAGE' | sed 's/^!MESSAGE //' > "${debug_info_file}" 2>&1 local exit_code=$? - # Overwrite file with lines containing !MESSAGE - sed -i -n '/!MESSAGE/ p' "${debug_info_file}" - - if [[ $(grep "Overall install request is satisfiable" "${debug_info_file}") != "" ]] && [ "${exit_code}" == 0 ]; then + if [[ $(grep "Overall install request is satisfiable" "${debug_info_file}") != "" ]] && [ "${exit_code}" == 0 ] + then return 0 - elif [[ $(grep "Unable to load repositories" "${debug_info_file}") != "" ]] || [[ $(grep "No repository found at" "${debug_info_file}") != "" ]]; then + elif [[ $(grep "Unable to load repositories" "${debug_info_file}") != "" ]] || [[ $(grep "No repository found at" "${debug_info_file}") != "" ]] + then doError "The given repository ${2} is not a correct update site." return 1 else @@ -118,48 +124,42 @@ function doCheckPluginsInstalled() { } function doSetup() { + local silent="${1}" doDevonCommand java setup silent - if [ "${1}" != "silent" ] || [ ! -d "${ECLIPSE_HOME}" ] + # check version + local javaVersion="${EXTRA_JAVA_VERSION}" + if [ -z "${javaVersion}" ] then - local version="${ECLIPSE_VERSION:-2022-03}" - local javaVersion="${EXTRA_JAVA_VERSION}" - if [ -z "${javaVersion}" ] - then - javaVersion="${JAVA_VERSION}" - fi - if [ -n "${javaVersion}" ] + javaVersion="${JAVA_VERSION}" + fi + if [ -n "${javaVersion}" ] + then + doVersionCompare "${javaVersion}" "11u0" + if [ "${?}" == 2 ] then - doVersionCompare "${javaVersion}" "11u0" - if [ "${?}" == 2 ] + # Java version is lower than 11 + local requireJava11="no" + if [ -z "${ECLIPSE_VERSION}" ] then - # Java version is lower than 11 - doVersionCompare "${version}" "2020-09" + requireJava11="yes" + else + doVersionCompare "${ECLIPSE_VERSION}" "2020-09" if [ "${?}" != 2 ] then # Eclipse version is >= 2020-09 - doConfirmWarning "You are using eclipse version ${version} that requires Java 11 or newer.\nHowever, [EXTRA_]JAVA_VERSION is ${javaVersion} - in this setup eclipse can not work.\nPlease update JAVA_VERSION, set EXTRA_JAVA_VERSION or downgrade ECLIPSE_VERSION in your settings/devon.properties!" + requireJava11="yes" fi fi - fi - doInstall "-" "${ECLIPSE_HOME}" "eclipse" "${version}" "${ECLIPSE_EDITION_TYPE:-java}" - if doIsMacOs - then - if [ ! -x "${ECLIPSE_HOME}/eclipse" ] + if [ "${requireJava11}" = "yes" ] then - echo "Doing workarounds for MacOS quirks..." - echo -e "#!/usr/bin/env bash\nECLIPSE_HOME=\"\$(dirname \"\${0}\")\"\n\"\${ECLIPSE_HOME}/Eclipse.app/Contents/MacOS/eclipse\" \$@" > "${ECLIPSE_HOME}/eclipse" - chmod a+x "${ECLIPSE_HOME}/eclipse" + doConfirmWarning "You are using eclipse version ${ECLIPSE_VERSION:-latest} that requires Java 11 or newer.\nHowever, [EXTRA_]JAVA_VERSION is ${javaVersion} - in this setup eclipse can not work.\nPlease update JAVA_VERSION, set EXTRA_JAVA_VERSION or downgrade ECLIPSE_VERSION in your settings/devon.properties!" fi fi - doAddPlugins fi - if [ ! -x "${ECLIPSE_HOME}/eclipse" ] + doInstall "eclipse" "${ECLIPSE_VERSION}" "${silent}" "${ECLIPSE_EDITION_TYPE:-java}" + if [ "${?}" = 0 ] then - doFail "Eclipse binary is not available in ${ECLIPSE_HOME}" - fi - if [ "${1}" != "silent" ] && ! doIsQuiet - then - doRunCommand "${TOOL_VERSION_COMMAND}" + doAddPlugins fi } @@ -295,10 +295,10 @@ function doStartEclipse() { if doIsWindows then # shellcheck disable=SC2086 - start "eclipse" /B "${ECLIPSE_HOME}/eclipsec" -clean -data "${WORKSPACE_PATH}" -keyring ~/.eclipse/.keyring -vm "${ECLIPSE_JAVA_HOME}/bin/javaw" -showlocation "${WORKSPACE}" -vmargs ${ECLIPSE_VMARGS} + start "eclipse" /B "${ECLIPSE}" -clean -data "${WORKSPACE_PATH}" -keyring ~/.eclipse/.keyring -vm "${ECLIPSE_JAVA_HOME}/bin/javaw" -showlocation "${WORKSPACE}" -vmargs ${ECLIPSE_VMARGS} else # shellcheck disable=SC2086 - "${ECLIPSE_HOME}/eclipse" -clean -data "${WORKSPACE_PATH}" -keyring ~/.eclipse/.keyring -vm "${ECLIPSE_JAVA_HOME}/bin/java" -showlocation "${DEVON_IDE_HOME/*\//}/${WORKSPACE}" -vmargs ${ECLIPSE_VMARGS} & + "${ECLIPSE}" -clean -data "${WORKSPACE_PATH}" -keyring ~/.eclipse/.keyring -vm "${ECLIPSE_JAVA_HOME}/bin/java" -showlocation "${DEVON_IDE_HOME/*\//}/${WORKSPACE}" -vmargs ${ECLIPSE_VMARGS} & fi } @@ -327,7 +327,7 @@ function doImportEclipse() { importWorkingSets="${2}" echo "Starting eclipse import for ${importPath} into workspace ${WORKSPACE} at ${WORKSPACE_PATH}" # shellcheck disable=SC2086 - "${ECLIPSE_HOME}/eclipse" -nosplash -vm "${ECLIPSE_JAVA_HOME}/bin/java" -application org.eclipse.ant.core.antRunner -buildfile "${DEVON_IDE_HOME}/scripts/lib_script/import.xml" -data "${WORKSPACE_PATH}" -keyring ~/.eclipse/.keyring -vm "${ECLIPSE_JAVA_HOME}/bin/java" -vmargs -DdevonImportPath="${importPath}" -DdevonImportWorkingSet="${importWorkingSets}" ${ECLIPSE_VMARGS} + "${ECLIPSE}" -nosplash -vm "${ECLIPSE_JAVA_HOME}/bin/java" -application org.eclipse.ant.core.antRunner -buildfile "${DEVON_IDE_HOME}/scripts/lib_script/import.xml" -data "${WORKSPACE_PATH}" -keyring ~/.eclipse/.keyring -vm "${ECLIPSE_JAVA_HOME}/bin/java" -vmargs -DdevonImportPath="${importPath}" -DdevonImportWorkingSet="${importWorkingSets}" ${ECLIPSE_VMARGS} } # $1: id @@ -347,8 +347,8 @@ function doMirrorUpdateSite() { fi local timestamp timestamp=$(date +'%Y-%m-%d') - "${ECLIPSE_HOME}/eclipse" -nosplash -vm "${ECLIPSE_JAVA_HOME}/bin/java" -application org.eclipse.equinox.p2.metadata.repository.mirrorApplication -source "${url}" -destination "${DEVON_DOWNLOAD_DIR}/update-sites/${1}-${timestamp}" -vmargs "${ECLIPSE_VMARGS}" - "${ECLIPSE_HOME}/eclipse" -nosplash -vm "${ECLIPSE_JAVA_HOME}/bin/java" -application org.eclipse.equinox.p2.artifact.repository.mirrorApplication -source "${url}" -destination "${DEVON_DOWNLOAD_DIR}/update-sites/${1}-${timestamp}" -vmargs "${ECLIPSE_VMARGS}" + "${ECLIPSE}" -nosplash -vm "${ECLIPSE_JAVA_HOME}/bin/java" -application org.eclipse.equinox.p2.metadata.repository.mirrorApplication -source "${url}" -destination "${DEVON_DOWNLOAD_DIR}/update-sites/${1}-${timestamp}" -vmargs "${ECLIPSE_VMARGS}" + "${ECLIPSE}" -nosplash -vm "${ECLIPSE_JAVA_HOME}/bin/java" -application org.eclipse.equinox.p2.artifact.repository.mirrorApplication -source "${url}" -destination "${DEVON_DOWNLOAD_DIR}/update-sites/${1}-${timestamp}" -vmargs "${ECLIPSE_VMARGS}" local result="${?}" if [ "${result}" != 0 ] then diff --git a/scripts/src/main/resources/scripts/command/gcviewer b/scripts/src/main/resources/scripts/command/gcviewer old mode 100644 new mode 100755 index 747af4ff6..76bbd6621 --- a/scripts/src/main/resources/scripts/command/gcviewer +++ b/scripts/src/main/resources/scripts/command/gcviewer @@ -10,23 +10,18 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -GCVIEWER_HOME="${DEVON_IDE_HOME}/software/gcviewer" -TOOL_VERSION_COMMAND="-" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +GCVIEWER_HOME="${DEVON_IDE_HOME}/software/gcviewer" +TOOL_VERSION_COMMAND="-" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # gcviewer installation function doSetup() { doDevonCommand java setup silent - if [ "${1}" != "silent" ] || [ ! -d "${GCVIEWER_HOME}" ] + doInstall "gcviewer" "${GCVIEWER_VERSION}" "${1}" "" "${GCVIEWER_HOME}" "" "noUnpack" + if [ "${?}" = 0 ] then - if [ -z "${GCVIEWER_VERSION}" ] - then - doEcho "Getting the latest release of GCViewer..." - GCVIEWER_VERSION=$(curl "https://github.com/chewiebug/GCViewer/tags" | awk -F "/tag/" '/GCViewer/ {print $2}' | sort -r | head -1 | awk -F "\">" '{print $1}') - fi - do_not_extract="Not Empty" - doInstall "-" "${GCVIEWER_HOME}" "gcviewer" "${GCVIEWER_VERSION}" "" "" "" "" "" "" "${do_not_extract}" doCreateGCViewerScript fi } @@ -38,10 +33,8 @@ function doStart() { } doCreateGCViewerScript() { - cd "${GCVIEWER_HOME}" || exit - touch gcviewer - echo -e "#!/usr/bin/env bash\ncd \${0%/*}\njava -jar gcviewer*.jar&" >> gcviewer - chmod +x gcviewer + echo -e "#!/usr/bin/env bash\ncd \${0%/*}\njava -jar gcviewer*.jar&" > "${GCVIEWER_HOME}/gcviewer" + chmod a+x "${GCVIEWER_HOME}/gcviewer" } # CLI @@ -54,12 +47,7 @@ case ${1} in echo " start launch GCViewer App." ;; "setup" | "s") - if [ "${2}" == "silent" ] - then - doSetup silent - else - doSetup - fi + doSetup "${2}" ;; "start" | "") doStart diff --git a/scripts/src/main/resources/scripts/command/gh b/scripts/src/main/resources/scripts/command/gh old mode 100644 new mode 100755 index ec66a9e75..dab3c9a73 --- a/scripts/src/main/resources/scripts/command/gh +++ b/scripts/src/main/resources/scripts/command/gh @@ -10,32 +10,17 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND="gh --version" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TOOL_VERSION_COMMAND="gh --version" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli GH_HOME="${DEVON_IDE_HOME}/software/gh" -function doSetup(){ - # Install GitHub CLI in the software folder - - if [ ! -d "${GH_HOME}" ] || [ "${1}" != "silent" ] - then - # Get leatest release - if [ -z "${GH_VERSION}" ] - then - doEcho "Getting latest release..." - local GH_VERSION - GH_VERSION=$( curl -LsH "Accept: application/vnd.github.v3+json" https://api.github.com/repos/cli/cli/releases/latest | awk -F':' '/tag_name/ {print $2}' | awk -F'"' '{print $2}' | tr -d 'v' ) - doInstall "-" "${GH_HOME}" "gh" "${GH_VERSION}" - fi - fi - - if [ "${1}" != "silent" ] && ! doIsQuiet - then - doRunCommand "${TOOL_VERSION_COMMAND}" - fi +function doSetup() { + doInstall "gh" "${GH_VERSION}" "${1}" + return 0 } function doRun(){ @@ -52,7 +37,6 @@ case ${1} in echo " «args» call GitHub CLI with the specified arguments." ;; "setup" | "s") - doEcho "Installing GitHub CLI..." doSetup "${2}" ;; *) diff --git a/scripts/src/main/resources/scripts/command/graalvm b/scripts/src/main/resources/scripts/command/graalvm index 31e513d96..d2a0cea7d 100755 --- a/scripts/src/main/resources/scripts/command/graalvm +++ b/scripts/src/main/resources/scripts/command/graalvm @@ -10,51 +10,25 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -GRAALVM_HOME="${DEVON_IDE_HOME}/software/extra/graalvm" -TOOL_VERSION_COMMAND="'${GRAALVM_HOME}/bin/java' -version" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +GRAALVM_HOME="${DEVON_IDE_HOME}/software/extra/graalvm" +TOOL_VERSION_COMMAND="'${GRAALVM_HOME}/bin/java' -version" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # $1: optional setup function doSetup() { - - doDevonCommand java setup silent - if [ "${1}" != "silent" ] || [ ! -d "${GRAALVM_HOME}" ] + #doDevonCommand java setup silent + doInstall "graalvm" "${GRAALVM_VERSION}" "${1}" "" "${GRAALVM_HOME}" + if [ "${?}" = 0 ] then - local version="${GRAALVM_VERSION:-22.0.0.2}" - local javaVersion="${EXTRA_JAVA_VERSION}" - if [ -z "${javaVersion}" ] - then - javaVersion="${JAVA_VERSION}" - fi - if [ -n "${javaVersion}" ] - then - doVersionCompare "${javaVersion}" "11u0" - if [ "${?}" == 2 ] - then - # Java version is lower than 11 - doConfirmWarning "GraalVM requires Java 11 or newer.\nHowever, [EXTRA_]JAVA_VERSION is ${javaVersion} - in this setup GraalVM can not work.\nPlease update JAVA_VERSION or set EXTRA_JAVA_VERSION in your settings/devon.properties!" - fi - fi - doInstall "-" "${GRAALVM_HOME}" "graalvm" "${version}" - graalvm_export="export GRAALVM_HOME=${GRAALVM_HOME}" if ! grep -q "${graalvm_export}" "${DEVON_IDE_HOME}/conf/devon.properties" then echo -e "\n${graalvm_export}" >> "${DEVON_IDE_HOME}/conf/devon.properties" fi fi - - if [ "${1}" != "silent" ] && ! doIsQuiet - then - local java_binary="${GRAALVM_HOME}/bin/java" - if [ ! -f "${java_binary}" ] - then - java_binary="${GRAALVM_HOME}/bin/java.exe" - fi - doRunCommand "'${java_binary}' -version" "verify installation of GraalVM" - fi } # Call GraalVM with specified arguments diff --git a/scripts/src/main/resources/scripts/command/gradle b/scripts/src/main/resources/scripts/command/gradle index 827ea55bc..e5a1ccc96 100755 --- a/scripts/src/main/resources/scripts/command/gradle +++ b/scripts/src/main/resources/scripts/command/gradle @@ -10,23 +10,19 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND="gradle -v" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +GRADLE_HOME="${DEVON_IDE_HOME}/software/gradle" +GRADLE="${GRADLE_HOME}/bin/gradle" +TOOL_VERSION_COMMAND="${GRADLE} -v" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # $1: optional setup function doSetup() { doDevonCommand java setup silent - if [ "${1}" != "silent" ] || [ ! -d "${GRADLE_HOME}" ] - then - local version="${GRADLE_VERSION:-5.5.1}" - doInstall "-" "${GRADLE_HOME}" "gradle" "${version}" "" "" "-" - fi - if [ "${1}" != "silent" ] && ! doIsQuiet - then - doRunCommand "'${GRADLE}' -v" "verify installation of gradle" - fi + doInstall "gradle" "${GRADLE_VERSION}" "${1}" "" "${GRADLE_HOME}" "-" + return 0 } function doGetProjectVersion() { @@ -89,8 +85,6 @@ then echo " «args» call gradle with the specified arguments" exit fi -GRADLE_HOME="${DEVON_IDE_HOME}/software/gradle" -GRADLE="${GRADLE_HOME}/bin/gradle" if [ -z "${1}" ] then # shellcheck disable=SC2086 diff --git a/scripts/src/main/resources/scripts/command/helm b/scripts/src/main/resources/scripts/command/helm old mode 100644 new mode 100755 index 17fba5190..73ca099d0 --- a/scripts/src/main/resources/scripts/command/helm +++ b/scripts/src/main/resources/scripts/command/helm @@ -10,10 +10,12 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND="helm version" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +HELM_HOME="${DEVON_IDE_HOME}/software/helm" +TOOL_VERSION_COMMAND="helm version" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # Call helm with specified arguments. function doRun() { @@ -22,27 +24,11 @@ function doRun() { } function doSetup() { - if [ ! -d "${HELM_HOME}" ] || [ "${1}" != "silent" ] - then - # Get leatest release - if [ -z "${HELM_VERSION}" ] - then - doEcho "Getting latest release..." - HELM_VERSION=$(curl -LsH "Accept: application/vnd.github.v3+json" https://api.github.com/repos/helm/helm/releases/latest | awk -F':' '/tag_name/ {print $2}' | awk -F'"' '{print $2}') - fi - - doInstall "-" "${HELM_HOME}" "helm" "${HELM_VERSION}" - fi - - if [ "${1}" != "silent" ] && ! doIsQuiet - then - doRunCommand "helm version" - fi + doInstall "helm" "${HELM_VERSION}" "${1}" + return 0 } -HELM_HOME="${DEVON_IDE_HOME}/software/helm" - # CLI case ${1} in "help" | "-h") @@ -53,8 +39,7 @@ case ${1} in echo " «args» call helm with the specified arguments. Call helm --help for details or use helm directly as preferred." ;; "setup" | "s" | "") - doEcho "Installating helm..." - doSetup + doSetup "${2}" ;; *) doRun "${@}" diff --git a/scripts/src/main/resources/scripts/command/help b/scripts/src/main/resources/scripts/command/help index 714fa728e..dc86c5252 100755 --- a/scripts/src/main/resources/scripts/command/help +++ b/scripts/src/main/resources/scripts/command/help @@ -10,10 +10,11 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND= # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TOOL_VERSION_COMMAND= +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli echo doLogo echo diff --git a/scripts/src/main/resources/scripts/command/ide b/scripts/src/main/resources/scripts/command/ide index 055667094..47eeb2dc2 100755 --- a/scripts/src/main/resources/scripts/command/ide +++ b/scripts/src/main/resources/scripts/command/ide @@ -24,10 +24,11 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND= # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TOOL_VERSION_COMMAND= +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli DEVON_IDE_REPO_URL="https://repo.maven.apache.org/maven2/com/devonfw/tools/ide" function doUpdateMetaFile() { @@ -372,7 +373,7 @@ function doUpdateSoftware() { repo="${default_repo}" fi fi - doInstall "-" "${DEVON_IDE_HOME}/software/${software}" "${software}" "${software_version}" "" "" "${os}" "" ".tgz" "${repo}" + doInstall "${software}" "${software_version}" "silent" "" "${DEVON_IDE_HOME}/software/${software}" "${os}" "" "${repo}" fi fi done @@ -450,27 +451,27 @@ function doUninstall() { } function doCreate() { - local create_path="${1}" - if [ -z "${create_path}" ] - then - create_path="${PWD}" - fi + local create_path="${1}" + if [ -z "${create_path}" ] + then + create_path="${PWD}" + fi - if [ ! -d "${create_path}" ] - then - mkdir -p "${create_path}" - fi - if ! doIsEmptyDirectory "${create_path}" - then - doAskToContinue "Directory is not empty, continue?" - fi + if [ ! -d "${create_path}" ] + then + mkdir -p "${create_path}" + fi + if ! doIsEmptyDirectory "${create_path}" + then + doAskToContinue "Directory is not empty, continue?" + fi - doUpgradeMavenArtifact "${create_path}/" "${DEVON_IDE_REPO_URL}" "devonfw-ide-scripts" "${target_version}" ".tar.gz" + doUpgradeMavenArtifact "${create_path}/" "${DEVON_IDE_REPO_URL}" "devonfw-ide-scripts" "${target_version}" ".tar.gz" - cd "${create_path}" || exit 255 - [ -f "./.devon.software.version" ] && rm "./.devon.software.version" - shift - ./setup "${@}" + cd "${create_path}" || exit 255 + [ -f "./.devon.software.version" ] && rm "./.devon.software.version" + shift + ./setup "${@}" } target_version="LATEST" diff --git a/scripts/src/main/resources/scripts/command/intellij b/scripts/src/main/resources/scripts/command/intellij index 985bf2bd2..7d691e4b0 100755 --- a/scripts/src/main/resources/scripts/command/intellij +++ b/scripts/src/main/resources/scripts/command/intellij @@ -14,49 +14,32 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi +# shellcheck source=scripts/functions +source "$(dirname "${0}")"/../functions IDEA_HOME="${DEVON_IDE_HOME}/software/intellij" -if [ "${OSTYPE:0:6}" = "darwin" ] +if doIsMacOs then - TOOL_VERSION_COMMAND="cat '${IDEA_HOME}/IntelliJ.app/Contents/Resources/product-info.json'" + # TODO path needs to be fixed... + TOOL_VERSION_COMMAND="cd '${DEVON_IDE_HOME}/software/macos/intellij'/*.app && head -n 6 'Contents/Resources/product-info.json'" else - TOOL_VERSION_COMMAND="cat '${IDEA_HOME}/product-info.json'" + TOOL_VERSION_COMMAND="head -n 6 '${IDEA_HOME}/product-info.json'" fi -# shellcheck source=scripts/functions -source "$(dirname "${0}")"/../functions +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli cd "${DEVON_IDE_HOME}" || exit 255 function doSetup() { doDevonCommand java setup silent - if [ "${1}" != "silent" ] || [ ! -d "${IDEA_HOME}" ] + doInstall "intellij" "${INTELLIJ_VERSION}" "${1}" "${INTELLIJ_EDITION_TYPE:-C}" + if [ "${?}" = 0 ] then - local version="${INTELLIJ_VERSION:-2021.3}" - local edition="${INTELLIJ_EDITION_TYPE:-C}" - doInstall "-" "${IDEA_HOME}" "intellij" "${version}" "${edition}" - if [ "${?}" = 0 ] && doIsMacOs - then - echo "Doing workarounds for MacOS quirks..." - if [ "${edition}" = "U" ] - then - mv "${DEVON_IDE_HOME}/software/intellij/IntelliJ IDEA.app" "${DEVON_IDE_HOME}/software/intellij/IntelliJ.app" - else - mv "${DEVON_IDE_HOME}/software/intellij/IntelliJ IDEA CE.app" "${DEVON_IDE_HOME}/software/intellij/IntelliJ.app" - fi - mkdir -p "${IDEA_HOME}/bin" - echo -e "#!/usr/bin/env bash\n'${DEVON_IDE_HOME}/software/intellij/IntelliJ.app/Contents/MacOS/idea' \$@" > "${IDEA_HOME}/bin/idea" - chmod a+x "${IDEA_HOME}/bin/idea" - fi if [ -f "${IDEA_HOME}/bin/idea.sh" ] then - ln -s "${IDEA_HOME}/bin/idea.sh" "${IDEA_HOME}/bin/idea" + ln -s "${IDEA_HOME}/bin/idea.sh" "${IDEA_HOME}/bin/idea" fi export PATH="${IDEA_HOME}/bin:${PATH}" doAddPlugins fi - if [ "${1}" != "silent" ] && ! doIsQuiet - then - doRunCommand "${TOOL_VERSION_COMMAND}" - fi } function doAddPlugins() { @@ -102,7 +85,7 @@ function doAddPlugin() { filename=$(curl -sI "${download_url}" | grep -o -E 'location:.*$' | sed -e 's/location://') filename="${filename##*/}" filename="${filename%%\?*}" - doDownload "${download_url}" "${download_dir}" "intellij-plugin-${intellij_build}-${pluginId}" "" "" "" "" "" "" "${filename}" + doDownload "${download_url}" "${download_dir}" "intellij-plugin-${intellij_build}-${pluginId}" "" "" "" "" "" "${filename}" if [ "${filename##*.}" = "zip" ] then local extract_name=${filename%.*} diff --git a/scripts/src/main/resources/scripts/command/ionic b/scripts/src/main/resources/scripts/command/ionic index 8b936c61a..97da4c28d 100755 --- a/scripts/src/main/resources/scripts/command/ionic +++ b/scripts/src/main/resources/scripts/command/ionic @@ -10,10 +10,11 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND="ionic -v" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TOOL_VERSION_COMMAND="ionic -v" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # $1: optional setup function doSetup() { diff --git a/scripts/src/main/resources/scripts/command/jasypt b/scripts/src/main/resources/scripts/command/jasypt index 156df0f0b..664999076 100755 --- a/scripts/src/main/resources/scripts/command/jasypt +++ b/scripts/src/main/resources/scripts/command/jasypt @@ -10,10 +10,11 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND= # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TOOL_VERSION_COMMAND= +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # $1: optional setup function doSetup() { diff --git a/scripts/src/main/resources/scripts/command/java b/scripts/src/main/resources/scripts/command/java index cae8319ee..bdd6fa6ac 100755 --- a/scripts/src/main/resources/scripts/command/java +++ b/scripts/src/main/resources/scripts/command/java @@ -17,52 +17,41 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND="java -version" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TOOL_VERSION_COMMAND="java -version" +# $1: URL +# $2: resolved version +# $3: resolved os +function doResolveDownloadUrl() { + local url="${1}" + local version="${2}" + local os="${3}" + local code + if [ "${version:0:1}" = "8" ] + then + code="jdk${version/b/-b}" + else + code="jdk-${version/_/%2B}" + fi + echo "${url//\$\{code\}/${code}}" +} +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli -# $1: optional setup +# $1: optional silent mode function doSetup() { export JAVA_HOME="${DEVON_IDE_HOME}/software/java" - local version="${JAVA_VERSION:-11.0.13_8}" - doSetupJava "${1}" "${version}" "${DEVON_IDE_HOME}/software" + doInstall "java" "${JAVA_VERSION}" "${1}" if [ -n "${EXTRA_JAVA_VERSION}" ] then - if [ "${EXTRA_JAVA_VERSION}" = "${version}" ] + if [ -n "${JAVA_VERSION}" ] && [ "${EXTRA_JAVA_VERSION}" = "${JAVA_VERSION}" ] then doConfirmWarning "You have configured EXTRA_JAVA_VERSION=${EXTRA_JAVA_VERSION} what is the same as JAVA_VERSION.\nThis does not make any sense. Please revisit your configuration." fi - doSetupJava "${1}" "${EXTRA_JAVA_VERSION}" "${DEVON_IDE_HOME}/software/extra" - fi -} - -# $1: mode (e.g. 'silent') -# $2: version -# $3: software path -# $4: label (e.g. 'extra Java') -function doSetupJava() { - local mode="${1}" - local version="${2}" - local path="${3}" - local java_path="${path}/java" - if [ "${mode}" != "silent" ] || [ ! -d "${java_path}" ] - then - local code - if [ "${version:0:1}" = "8" ] - then - code="jdk${version/b/-b}" - else - code="jdk-${version/_/%2B}" - fi - doInstall "-" "${java_path}" "java" "${version}" "" "${code}" - # delete not used jdk for old installations - rm -rf "${DEVON_IDE_HOME}/software/jdk" - fi - if [ "${mode}" != "silent" ] && ! doIsQuiet - then - doRunCommand "'${java_path}/bin/java' -version" "verify installation of Java" + doInstall "java" "${EXTRA_JAVA_VERSION}" "${1}" "" "${DEVON_IDE_HOME}/software/extra/java" fi + return 0 } #$@ args (see help) diff --git a/scripts/src/main/resources/scripts/command/jenkins b/scripts/src/main/resources/scripts/command/jenkins index 53997342c..1dd17dc16 100755 --- a/scripts/src/main/resources/scripts/command/jenkins +++ b/scripts/src/main/resources/scripts/command/jenkins @@ -10,11 +10,12 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -JENKINS_HOME="${DEVON_IDE_HOME}/software/jenkins" -TOOL_VERSION_COMMAND="java -jar '${JENKINS_HOME}/jenkins.war' --version" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +JENKINS_HOME="${DEVON_IDE_HOME}/software/jenkins" +TOOL_VERSION_COMMAND="java -jar '${JENKINS_HOME}/jenkins.war' --version" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # $1: optional setup function doSetup() { @@ -27,7 +28,7 @@ function doSetup() { fi else local version=${JENKINS_VERSION:-latest} - doDownload "-" "" "jenkins" "${version}" "-" "" "" "" "" "jenkins.war" + doDownload "-" "" "jenkins" "${version}" "-" "" "" "" "jenkins.war" mkdir -p "${JENKINS_HOME}" doRunCommand "mv '${DEVON_DOWNLOAD_DIR}/jenkins.war' '${JENKINS_HOME}/jenkins.war'" # http://localhost:9999/jnlpJars/jenkins-cli.jar diff --git a/scripts/src/main/resources/scripts/command/kubectl b/scripts/src/main/resources/scripts/command/kubectl index ed60122d2..144519d85 100755 --- a/scripts/src/main/resources/scripts/command/kubectl +++ b/scripts/src/main/resources/scripts/command/kubectl @@ -10,10 +10,11 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND= # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TOOL_VERSION_COMMAND= +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # $1: optional setup function doSetup() { @@ -26,12 +27,7 @@ function doSetup() { fi return fi - if doIsWindows || doIsMacOs - then - doDevonCommand docker setup silent - else - doFail "Sorry, kubernetes-installation support is not yet implemented for your OS. Please install manually or help devonfw-ide to support it for your OS by contributing a pull-request." - fi + doDevonCommand docker setup silent } diff --git a/scripts/src/main/resources/scripts/command/lazydocker b/scripts/src/main/resources/scripts/command/lazydocker index 860a5b146..042ae3ab2 100644 --- a/scripts/src/main/resources/scripts/command/lazydocker +++ b/scripts/src/main/resources/scripts/command/lazydocker @@ -10,10 +10,11 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND="lazydocker --version" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TOOL_VERSION_COMMAND="lazydocker --version" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # Call lazydocker with specified arguments. function doRun() { @@ -30,22 +31,9 @@ function doSetup() { if [ ! -d "${LAZYDOCKER_HOME}" ] || [ "${1}" != "silent" ] then doDevonCommand docker setup silent - local version="${LAZYDOCKER_VERSION}" - # Get latest release - if [ -z "${version}" ] - then - version="0.18.1" - doEcho "Getting latest release..." - local latestversion - latestversion=$(curl -Ls -o /dev/null -w '%{url_effective}' https://github.com/jesseduffield/lazydocker/releases/latest | sed 's/^.*\///' | sed 's/^v//') - doVersionCompare "${latestversion}" "${version}" - if [ "${?}" = 1 ] - then - version=${latestversion} - fi - fi doCheckDockerVersions - doInstall "-" "${LAZYDOCKER_HOME}" "lazydocker" "${version}" + doInstall "lazydocker" "${LAZYDOCKER_VERSION}" "${1}" + return 0 fi } @@ -95,8 +83,7 @@ case ${1} in echo " call lazydocker by executing the command 'devon lazydocker'. Call lazydocker --help for details or use lazydocker directly as preferred." ;; "setup" | "s" ) - doEcho "Installing lazydocker..." - doSetup + doSetup "${2}" ;; "version" | "v" ) lazydversion=$(cat "${LAZYDOCKER_HOME}"/.devon.software.version) diff --git a/scripts/src/main/resources/scripts/command/mvn b/scripts/src/main/resources/scripts/command/mvn index 65528fb43..eb53cc170 100755 --- a/scripts/src/main/resources/scripts/command/mvn +++ b/scripts/src/main/resources/scripts/command/mvn @@ -10,22 +10,18 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND="mvn -v" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions - -function doGetMavenVersion() { - echo "${MAVEN_VERSION:-3.8.4}" -} +MAVEN_HOME="${DEVON_IDE_HOME}/software/maven" +MVN="${MAVEN_HOME}/bin/mvn" +TOOL_VERSION_COMMAND="${MVN} -v" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # $1: optional setup function doSetup() { doDevonCommand java setup silent - if [ "${1}" != "silent" ] || [ ! -d "${MAVEN_HOME}" ] - then - doInstall "-" "${MAVEN_HOME}" "maven" "$(doGetMavenVersion)" "" "" "-" - fi + doInstall "maven" "${MAVEN_VERSION}" "${1}" "" "${MAVEN_HOME}" "-" if [ "${1}" != "silent" ] then if [ -d "${SETTINGS_PATH}" ] @@ -72,10 +68,6 @@ function doSetup() { doEchoInteraction "Please run the following command to fix:" doEchoInteraction "devon setup" fi - if [ "${1}" != "silent" ] && ! doIsQuiet - then - doRunCommand "'${MVN}' -v" "verify installation of maven" - fi fi } @@ -316,7 +308,7 @@ function doRunBuild() { fi if [ -n "${MAVEN_ARGS}" ] then - doVersionCompare "$(doGetMavenVersion)" "4.0" + doVersionCompare "$(cat "${MAVEN_HOME}/.devon.software.version")" "4.0" if [ "${?}" == 2 ] then # Maven version is lower than 4.0 (3.x) @@ -344,8 +336,6 @@ function doRunBuild() { } # CLI -MAVEN_HOME="${DEVON_IDE_HOME}/software/maven" -MVN="${MAVEN_HOME}/bin/mvn" if [ "${1}" = "-h" ] || [ "${1}" = "help" ] then echo "Setup or run maven build tool." diff --git a/scripts/src/main/resources/scripts/command/ng b/scripts/src/main/resources/scripts/command/ng index 1699ff621..6ba72fd69 100755 --- a/scripts/src/main/resources/scripts/command/ng +++ b/scripts/src/main/resources/scripts/command/ng @@ -10,10 +10,11 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND="ng version" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TOOL_VERSION_COMMAND="ng version" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # $1: optional setup function doSetup() { @@ -45,11 +46,6 @@ then echo "«args» call ng with the specified arguments" exit fi -NG_CMD="${DEVON_IDE_HOME}/software/node/ng" -if [ ! -x "${NG_CMD}" ] -then - NG_CMD="${DEVON_IDE_HOME}/software/node/bin/ng" -fi if [ -z "${1}" ] || [ "${1}" = "setup" ] then @@ -61,5 +57,5 @@ then ng new "${@}" else doSetup silent - "${NG_CMD}" "${@}" + ng "${@}" fi diff --git a/scripts/src/main/resources/scripts/command/node b/scripts/src/main/resources/scripts/command/node index 5558b48b8..ca299fc74 100755 --- a/scripts/src/main/resources/scripts/command/node +++ b/scripts/src/main/resources/scripts/command/node @@ -10,23 +10,17 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -NODE_HOME="${DEVON_IDE_HOME}/software/node" -TOOL_VERSION_COMMAND="node -v" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +NODE_HOME="${DEVON_IDE_HOME}/software/node" +TOOL_VERSION_COMMAND="node -v" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # $1: optional setup function doSetup() { - if [ "${1}" != "silent" ] || [ ! -d "${NODE_HOME}" ] - then - local version="${NODE_VERSION:-v14.17.6}" - doInstall "-" "${NODE_HOME}" "nodejs" "${version}" - fi - if [ "${1}" != "silent" ] && ! doIsQuiet - then - doRunCommand "${TOOL_VERSION_COMMAND}" - fi + doInstall "nodejs" "${NODE_VERSION}" "${1}" "" "${NODE_HOME}" + return 0 } function doSetupDevon4node() { diff --git a/scripts/src/main/resources/scripts/command/npm b/scripts/src/main/resources/scripts/command/npm index 5cfccb209..f83448023 100755 --- a/scripts/src/main/resources/scripts/command/npm +++ b/scripts/src/main/resources/scripts/command/npm @@ -10,32 +10,20 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND="npm -v" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +NODE_HOME="${DEVON_IDE_HOME}/software/node" +TOOL_VERSION_COMMAND="npm -v" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # $1: optional setup function doSetup() { - local software_version=${NPM_VERSION} - local installed_version - if [ -x "${NPM_CMD}" ] + doDevonCommand node setup silent + local software_dir="${NODE_HOME}/node_modules/npm" + doInstall "npm" "${NPM_VERSION}" "${1}" "" "${software_dir}" + if [ "${?}" = 0 ] then - installed_version=$(${NPM_CMD} -version) - else - doDevonCommand node setup silent - installed_version=$(${NPM_CMD} -version) - fi - - if [ -z "${software_version}" ] || [ "${installed_version}" == "${software_version}" ] - then - if [ "${1}" != "silent" ] - then - doEcho "Version ${installed_version} of npm is already installed at ${NPM_CMD}" - fi - else - local software_dir="${NODE_HOME}/node_modules/npm" - doInstall "-" "${software_dir}" "npm" "${software_version}" if [ -f "${NODE_HOME}/npm" ] then rm "${NODE_HOME}/npm" @@ -56,7 +44,7 @@ function doSetup() { cp "${software_dir}/bin/npm.cmd" "${NODE_HOME}" cp "${software_dir}/bin/npx" "${NODE_HOME}" cp "${software_dir}/bin/npx.cmd" "${NODE_HOME}" - fi + fi } function doGetProjectVersion() { @@ -95,9 +83,9 @@ function doRunBuild() { doEcho "Running: npm ${*}" if doIsQuiet then - "${NPM_CMD}" --quiet "${@}" + npm --quiet "${@}" else - "${NPM_CMD}" "${@}" + npm "${@}" fi } @@ -125,17 +113,6 @@ then exit fi -if [ -z "${NODE_HOME}" ] -then - NODE_HOME="${DEVON_IDE_HOME}/software/node" -fi - -NPM_CMD="${DEVON_IDE_HOME}/software/node/npm" -if [ ! -x "${NPM_CMD}" ] -then - NPM_CMD="${DEVON_IDE_HOME}/software/node/bin/npm" -fi - if [ -z "${1}" ] || [ "${1}" = "build" ] then if [ -n "${NPM_BUILD_OPTS}" ] diff --git a/scripts/src/main/resources/scripts/command/oc b/scripts/src/main/resources/scripts/command/oc old mode 100644 new mode 100755 index 8c782bc62..f60ac1d04 --- a/scripts/src/main/resources/scripts/command/oc +++ b/scripts/src/main/resources/scripts/command/oc @@ -10,36 +10,23 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -OPENSHIFT_HOME="${DEVON_IDE_HOME}/software/oc" -TOOL_VERSION_COMMAND="oc version" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions - +OC_HOME="${DEVON_IDE_HOME}/software/oc" +TOOL_VERSION_COMMAND="-" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # Call oc with specified arguments. function doRun() { doSetup silent - doRunCommand "${OPENSHIFT_HOME}/oc ${*}" + doRunCommand "${OC_HOME}/oc ${*}" } # openshift installation function doSetup() { - if [ ! -d "${OPENSHIFT_HOME}" ] || [ "${1}" != "silent" ] - then - # Getting latest release - if [ -z "${OC_VERSION}" ] - then - doEcho "Getting latest release..." - OC_VERSION=$(curl "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/" | awk -F "openshift-client-windows-" '/openshift-client-windows-/ {print $2}' | head -1 | awk -F'.zip' '{print $1}') - fi - doInstall "-" "${OPENSHIFT_HOME}" "oc" "${OC_VERSION}" - fi - - if [ "${1}" != "silent" ] && ! doIsQuiet - then - doRunCommand "${TOOL_VERSION_COMMAND}" - fi + doInstall "oc" "${OC_VERSION}" "${1}" + return 0 } # CLI diff --git a/scripts/src/main/resources/scripts/command/pip b/scripts/src/main/resources/scripts/command/pip old mode 100644 new mode 100755 index 77cb5e1d3..d2a1b6ee7 --- a/scripts/src/main/resources/scripts/command/pip +++ b/scripts/src/main/resources/scripts/command/pip @@ -10,10 +10,11 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND="pip --version" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TOOL_VERSION_COMMAND="pip --version" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli function doSetup() { # If no python is installed in directory, install it @@ -39,8 +40,8 @@ function doSetup() { # Install pip via python doDownload "-" "${PIP_HOME}" "pip" "latest" "" "pip" cd "${PIP_HOME}" || exit 255 - doDevonCommand python pip-latest-windows.py --no-warn-script-location "--target=${PIP_HOME}" - rm -rf "${PIP_HOME}/pip-latest-windows.py" + doDevonCommand python pip-latest-pip.py --no-warn-script-location "--target=${PIP_HOME}" + rm -rf "${PIP_HOME}/pip-latest-pip.py" doExtendPath "${PIP_HOME}" else doEcho "Your operating system is unsupported!" diff --git a/scripts/src/main/resources/scripts/command/project b/scripts/src/main/resources/scripts/command/project index a611e043b..5b28cea6b 100755 --- a/scripts/src/main/resources/scripts/command/project +++ b/scripts/src/main/resources/scripts/command/project @@ -10,10 +10,11 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND= # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TOOL_VERSION_COMMAND= +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # $1: project to setup (omit for all all projects) function doSetup() { diff --git a/scripts/src/main/resources/scripts/command/python b/scripts/src/main/resources/scripts/command/python old mode 100644 new mode 100755 index f334f6df1..e4e121dd5 --- a/scripts/src/main/resources/scripts/command/python +++ b/scripts/src/main/resources/scripts/command/python @@ -10,24 +10,22 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND="python --version" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +PYTHON_HOME="${DEVON_IDE_HOME}/software/python" +TOOL_VERSION_COMMAND="python --version" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli function doSetup() { - if [ ! -d "${PYTHON_HOME}" ] || [ "${1}" != "silent" ] + TOOL_VERSION_COMMAND="-" + doInstall "python" "${PYTHON_VERSION}" "${1}" + TOOL_VERSION_COMMAND="python --version" + if [ "${?}" = 0 ] then - # Get leatest release - if [ -z "${PYTHON_VERSION}" ] - then - PYTHON_VERSION="3.10.5" - fi - if doIsMacOs then doBrewInstall openssl - doInstall "-" "${PYTHON_HOME}" "python" "${PYTHON_VERSION}" sh "${PYTHON_HOME}"/configure MACOSX_DEPLOYMENT_TARGET=12 --enable-optimizations --with-ensurepip=install --with-openssl=/opt/homebrew/opt/openssl@3 --prefix="${PYTHON_HOME}" make -j 8 make altinstall @@ -36,7 +34,6 @@ function doSetup() { elif doIsWindows then - doInstall "-" "${PYTHON_HOME}" "python" "${PYTHON_VERSION}" if [ -a "$(find "${PYTHON_HOME}" -name '*._pth')" ] then PTH_FILE="$(find "${PYTHON_HOME}" -name '*._pth')" @@ -49,9 +46,6 @@ function doSetup() { doInstallWithPackageManager "apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev" \ "yum -y groupinstall \"Development Tools\"" \ "zypp install automake fdupes gcc gcc-c++ gcc-fortran gdbm-devel gettext-tools gmp-devel intltool libbz2-devel libexpat-devel libffi-devel libnsl-devel lzma-devel make ncurses-devel netcfg openssl-devel pkgconfig readline-devel sqlite-devel xz zlib-devel" - - - doInstall "-" "${PYTHON_HOME}" "python" "${PYTHON_VERSION}" "${PYTHON_HOME}"/configure --enable-optimizations --with-ensurepip=install --prefix="${PYTHON_HOME}" make -j 8 make altinstall @@ -59,12 +53,6 @@ function doSetup() { make distclean fi fi - - # check version - if [ "${1}" != "silent" ] && ! doIsQuiet - then - doRunCommand "${TOOL_VERSION_COMMAND}" - fi } function doRunPython() { @@ -77,8 +65,6 @@ function doRunPython() { fi } -PYTHON_HOME="${DEVON_IDE_HOME}/software/python" - case ${1} in "help" | "-h") echo "Install Python." diff --git a/scripts/src/main/resources/scripts/command/quarkus b/scripts/src/main/resources/scripts/command/quarkus old mode 100644 new mode 100755 index 169306959..51e9fb144 --- a/scripts/src/main/resources/scripts/command/quarkus +++ b/scripts/src/main/resources/scripts/command/quarkus @@ -10,11 +10,12 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -QUARKUS_HOME="${DEVON_IDE_HOME}/software/quarkus" -TOOL_VERSION_COMMAND="quarkus -v" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +QUARKUS_HOME="${DEVON_IDE_HOME}/software/quarkus" +TOOL_VERSION_COMMAND="quarkus -v" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # Call quarkus with specified arguments. function doRun() { @@ -24,16 +25,8 @@ function doRun() { # quarkus CLI installation function doSetup() { - if [ ! -d "${QUARKUS_HOME}" ] || [ "${1}" != "silent" ] - then - # Getting latest release - if [ -z "${QUARKUS_VERSION}" ] - then - doEcho "Getting latest release..." - QUARKUS_VERSION=$(curl "https://api.github.com/repos/quarkusio/quarkus/releases" | awk -F "\"" '/tag_name/ {print $4}' | grep -v "CR" | head -1) - fi - doInstall "-" "${QUARKUS_HOME}" "quarkus" "${QUARKUS_VERSION}" - fi + doInstall "quarkus" "${QUARKUS_VERSION}" "${1}" + return 0 } # CLI diff --git a/scripts/src/main/resources/scripts/command/release b/scripts/src/main/resources/scripts/command/release index 990b380a4..40258af4c 100755 --- a/scripts/src/main/resources/scripts/command/release +++ b/scripts/src/main/resources/scripts/command/release @@ -10,10 +10,11 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND= # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TOOL_VERSION_COMMAND= +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli function doGitHasUncomittedChanges() { ! git diff-index --quiet HEAD || [ -n "$(git status -s)" ] diff --git a/scripts/src/main/resources/scripts/command/sonar b/scripts/src/main/resources/scripts/command/sonar index fee9b249d..0bfac2aab 100755 --- a/scripts/src/main/resources/scripts/command/sonar +++ b/scripts/src/main/resources/scripts/command/sonar @@ -10,24 +10,18 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -SONARQUBE_HOME="${DEVON_IDE_HOME}/software/sonarqube" -TOOL_VERSION_COMMAND="ls '${SONARQUBE_HOME}/lib/sonar-application'-*.jar | sed 's/.*sonar-application-//' | sed 's/\.jar//'" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +SONARQUBE_HOME="${DEVON_IDE_HOME}/software/sonarqube" +TOOL_VERSION_COMMAND="ls '${SONARQUBE_HOME}/lib/sonar-application'-*.jar | sed 's/.*sonar-application-//' | sed 's/\.jar//'" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # $1: optional setup function doSetup() { doDevonCommand java setup silent - if [ "${1}" != "silent" ] || [ ! -d "${SONARQUBE_HOME}" ] - then - local version="${SONARQUBE_VERSION:-9.4.0.54424}" - doInstall "-" "${SONARQUBE_HOME}" "sonarqube" "${version}" "" "" "-" - fi - if [ "${1}" != "silent" ] && ! doIsQuiet - then - echo doRunCommand "'${SONAR}' -v" "verify installation of sonarqube" - fi + doInstall "sonarqube" "${SONARQUBE_VERSION}" "${1}" "" "${SONARQUBE_HOME}" "-" + return 0 } function doStart() { diff --git a/scripts/src/main/resources/scripts/command/terraform b/scripts/src/main/resources/scripts/command/terraform old mode 100644 new mode 100755 index 1d46d37e4..3e98038d3 --- a/scripts/src/main/resources/scripts/command/terraform +++ b/scripts/src/main/resources/scripts/command/terraform @@ -10,10 +10,12 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND="terraform version" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TERRAFORM_HOME="${DEVON_IDE_HOME}/software/terraform" +TOOL_VERSION_COMMAND="terraform version" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # Call Terraform with specified arguments. function doRun() { @@ -22,32 +24,16 @@ function doRun() { } function doSetup() { - if [ ! -d "${TERRAFORM_HOME}" ] || [ "${1}" != "silent" ] + doInstall "terraform" "${TERRAFORM_VERSION}" + if [ "${?}" = 0 ] then - # Get leatest release - if [ -z "${TERRAFORM_VERSION}" ] - then - doEcho "Getting latest release..." - TERRAFORM_VERSION=$(curl -s https://api.github.com/repos/hashicorp/terraform/releases/latest | awk -F ":" '/tag_name/ {print $2}'| awk -F "\"" '{print $2}' | sed 's/v//') - fi - - doInstall "-" "${TERRAFORM_HOME}" "terraform" "${TERRAFORM_VERSION}" - if ! grep terraform ~/.bashrc >/dev/null then terraform -install-autocomplete fi fi - - if [ "${1}" != "silent" ] && ! doIsQuiet - then - doRunCommand "${TOOL_VERSION_COMMAND}" - fi - } -TERRAFORM_HOME="${DEVON_IDE_HOME}/software/terraform" - # CLI case ${1} in "help" | "-h") diff --git a/scripts/src/main/resources/scripts/command/vscode b/scripts/src/main/resources/scripts/command/vscode index 92b60cf50..0e36725bf 100755 --- a/scripts/src/main/resources/scripts/command/vscode +++ b/scripts/src/main/resources/scripts/command/vscode @@ -14,27 +14,19 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -VSCODE_HOME="${DEVON_IDE_HOME}/software/vscode" -TOOL_VERSION_COMMAND="code -v" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +VSCODE_HOME="${DEVON_IDE_HOME}/software/vscode" +TOOL_VERSION_COMMAND="code -v" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli + cd "${DEVON_IDE_HOME}" || exit 255 function doSetup() { - if [ "${1}" != "silent" ] || [ ! -d "${VSCODE_HOME}" ] + doInstall "vscode" "${VSCODE_VERSION}" "${1}" + if [ "${?}" = 0 ] then - local version="${VSCODE_VERSION:-1.71.0}" - doInstall "-" "${VSCODE_HOME}" "vscode" "${version}" - if [ "${?}" = 0 ] - then - if doIsMacOs - then - mkdir "${VSCODE_HOME}/bin" - echo -e "#!/usr/bin/env bash\n\"${VSCODE_HOME}/Visual Studio Code.app/Contents/MacOS/Electron\" \$@" > "${VSCODE_HOME}/bin/code" - chmod a+x "${VSCODE_HOME}/bin/code" - fi - fi cleanupPlugins doAddPlugins fi @@ -55,7 +47,7 @@ function cleanupPlugins() { function doAddPlugins() { local file - local pluginsToInstall + local pluginsToInstall=() for file in "${SETTINGS_PATH}"/vscode/plugins/*.properties do if [ -f "${file}" ] @@ -68,20 +60,30 @@ function doAddPlugins() { doWarning "Invalid vscode plugin config: ${file}" elif [ "${plugin_active}" = "true" ] then - pluginsToInstall="${pluginsToInstall} --install-extension ${plugin_id}" + pluginsToInstall+=("${plugin_id}") fi fi done - doAddPlugin "${pluginsToInstall}" + if [ "${#pluginsToInstall}" -gt 0 ] + then + doAddPlugin "${pluginsToInstall[@]}" + fi } function doAddPlugin() { - if [ -n "${1}" ] + local plugins="${*}" + local args=() + while [ -n "${1}" ] + do + args+=("--install-extension" "${1}") + shift + done + if [ "${#args}" = 0 ] then - doEchoAttention "Execute plugin installation with following parameters (${1}) into VS code...\nPlease wait until VSCode has successfully installed all plugins.\nYou may then use or close VSCode as you like." - doRunVsCode --force "${1}" - else doEcho "No plugins to be installed / uninstalled" + else + doEchoAttention "Starting installation of the following plugins into VS code:\n${plugins}\nPlease wait until VSCode has successfully installed all plugins." + doRunVsCode --force "${args[@]}" fi } @@ -158,8 +160,9 @@ while [ -n "${1}" ] do if [ "${1}" = "run" ] || [ "${1}" = "start" ] then + shift doSetup silent - doStartVsCode + doStartVsCode "${@}" elif [ "${1}" = "ws-up" ] || [ "${1}" = "ws-update" ] then doConfigureVsCode -u diff --git a/scripts/src/main/resources/scripts/command/yarn b/scripts/src/main/resources/scripts/command/yarn index 94d7d5c8d..6da4afa94 100755 --- a/scripts/src/main/resources/scripts/command/yarn +++ b/scripts/src/main/resources/scripts/command/yarn @@ -10,10 +10,11 @@ then exit fi -if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi -TOOL_VERSION_COMMAND="yarn -v" # shellcheck source=scripts/functions source "$(dirname "${0}")"/../functions +TOOL_VERSION_COMMAND="yarn -v" +# shellcheck source=scripts/commandlet-cli +source "$(dirname "${0}")"/../commandlet-cli # $1: optional setup function doSetup() { diff --git a/scripts/src/main/resources/scripts/commandlet-cli b/scripts/src/main/resources/scripts/commandlet-cli new file mode 100644 index 000000000..aebddd4da --- /dev/null +++ b/scripts/src/main/resources/scripts/commandlet-cli @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# Will be sourced, hash bang only for filetype detection and editor syntax support + +doEnvironmentProject export +DEVON_DOWNLOAD_DIR="${DEVON_HOME_DIR}/Downloads/devonfw-ide" +# defaults, may be overridden before calling doMavenArchetype +ARCHETYPE_GROUP_ID="com.devonfw.java.templates" +ARCHETYPE_ARTIFACT_ID="devon4j-template-server" + +batch="" +force="" +quiet="" +debug="" +while [ -n "${1}" ] +do + doParseOption "${@}" + status_code="${?}" + if [ "${status_code}" = 0 ] + then + shift + elif [ "${status_code}" = 1 ] + then + shift + break + else + break + fi +done diff --git a/scripts/src/main/resources/scripts/devon b/scripts/src/main/resources/scripts/devon index 9080af1c1..9a9de823d 100755 --- a/scripts/src/main/resources/scripts/devon +++ b/scripts/src/main/resources/scripts/devon @@ -40,6 +40,7 @@ do source scripts/environment-project unset -f doLoadProperties unset -f doUpdatePath + unset -f doEnvironmentProject fi if [ -z "${1}" ] then diff --git a/scripts/src/main/resources/scripts/environment-project b/scripts/src/main/resources/scripts/environment-project index 890f1fad3..30e16cf19 100755 --- a/scripts/src/main/resources/scripts/environment-project +++ b/scripts/src/main/resources/scripts/environment-project @@ -3,158 +3,6 @@ if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi # Script to setup devonfw-ide environment. Will actually be sourced, # hash bang only for filetype detection and editor syntax support -# $1: path of properties file to load -# $2: optional prefix to add to variables -# $3: optional arg to export all variables if not empty -function doLoadProperties() { - if ! [ -f "${1}" ] - then - return - fi - if test "$(tail -c 1 "${1}" | wc -l)" -eq 0 - then - echo "Appending missing newline to ${1}" - echo >> "${1}" - fi - local key - local value - local export_key - while IFS='=' read -r key value - do - if [ -n "${key}" ] && [ "${key:0:1}" != "#" ] - then - key="${key//$'\r'}" - value="${value//$'\r'}" - export_key="" - if [ "${value:0:1}" = "~" ] - then - value=${HOME}${value:1} - fi - if [ "${key:0:7}" = "export " ] - then - export_key="true" - key="${key:7}" - elif [ -n "${3}" ] - then - export_key="true" - fi - key="${2}${key/./_}" - if [ -z "${value}" ] - then - if [ -n "${key}" ] - then - unset "${key}" - fi - else - if [ "${OSTYPE}" = "cygwin" ] || [ "${OSTYPE}" = "msys" ] - then - if [[ "${value}" =~ ^[A-Za-z]:[\\/] ]] - then - value="$(cygpath "${value}")" - fi - fi - if [ "${value:0:1}" != "(" ] && [ "${value:0:1}" != '"' ] - then - value=\"${value}\" - fi - eval "${key}=${value}" - if [ "${export_key}" = "true" ] && [ -z "${2}" ] - then - # shellcheck disable=SC2086,SC2163 - export ${key?} - fi - fi - fi - done < "${1}" -} - -function doUpdatePath() { - if [ -z "${DEVON_OLD_PATH}" ] - then - export DEVON_OLD_PATH="${PATH}" - else - if [[ "${DEVON_OLD_PATH}" == *"C:\\WINDOWS"* ]] - then - # https://github.com/devonfw/ide/issues/49 - DEVON_OLD_PATH= - IFS=':' - set -f - for dir in ${PATH} - do - if [[ "${dir}" != "${DEVON_IDE_HOME}"* ]] - then - if [ -z "${DEVON_OLD_PATH}" ] - then - DEVON_OLD_PATH="${dir}" - else - DEVON_OLD_PATH="${DEVON_OLD_PATH}:${dir}" - fi - fi - done - set +f - unset IFS - export DEVON_OLD_PATH - fi - PATH="${DEVON_OLD_PATH}" - fi - # Setup path - SOFTWARE_PATH=${DEVON_IDE_HOME}/software - for SOFTWARE_FOLDER in "${SOFTWARE_PATH}"/* - do - if [ "${SOFTWARE_FOLDER}" != "${SOFTWARE_PATH}/extra" ] - then - if [ -d "${SOFTWARE_FOLDER}/bin" ] - then - PATH="${SOFTWARE_FOLDER}/bin:${PATH}" - else - PATH="${SOFTWARE_FOLDER}:${PATH}" - fi - # Load custom configuration of software - if [ -e "${SOFTWARE_FOLDER}/ide-config" ] - then - # shellcheck disable=SC1090,SC1091 - source "${SOFTWARE_FOLDER}/ide-config" - fi - fi - done - - # node.js support - if [ -d "${DEVON_IDE_HOME}/software/nodejs" ] - then - PATH="${PATH}:$(npm bin -g 2> /dev/null)" - fi -} - -# determine proper home directory -DEVON_HOME_DIR=~ -if [ "${OSTYPE}" = "cygwin" ] -then - DEVON_HOME_DIR="$(cygpath "${USERPROFILE}")" -fi -# load and setup configuration -doLoadProperties "${DEVON_IDE_HOME}/scripts/devon.properties" "" "${@}" -doLoadProperties "${DEVON_HOME_DIR}/devon.properties" "" "${@}" -doLoadProperties "${DEVON_IDE_HOME}/devon.properties" "" "${@}" -doLoadProperties "${SETTINGS_PATH}/devon.properties" "" "${@}" -if [ -z "${WORKSPACE}" ] -then - WORKSPACE=main -fi -export WORKSPACE -export WORKSPACE_PATH=${DEVON_IDE_HOME}/workspaces/${WORKSPACE} -if [ ! -d "${WORKSPACE_PATH}" ] -then - if [ "${WORKSPACE}" = "main" ] - then - echo "Creating main workspace directory" - mkdir -p "${WORKSPACE_PATH}" - else - echo "Workspace ${WORKSPACE} does not exist" - fi -fi -doLoadProperties "${WORKSPACE_PATH}/devon.properties" "" "${@}" -doUpdatePath -# load user settings late so variables like M2_REPO can be overridden -doLoadProperties "${DEVON_IDE_HOME}/conf/devon.properties" "" "${@}" - -export PATH +# shellcheck source=scripts/functions-core +source "${DEVON_IDE_HOME}/scripts/functions-core" +doEnvironmentProject "${@}" diff --git a/scripts/src/main/resources/scripts/functions b/scripts/src/main/resources/scripts/functions index 4db384ac9..96b0ae597 100755 --- a/scripts/src/main/resources/scripts/functions +++ b/scripts/src/main/resources/scripts/functions @@ -11,9 +11,8 @@ then echo "DEVON_IDE_HOME variable set to ${DEVON_IDE_HOME}" fi -# shellcheck source=scripts/environment-project -source "${DEVON_IDE_HOME}/scripts/environment-project" export -DEVON_DOWNLOAD_DIR="${DEVON_HOME_DIR}/Downloads/devonfw-ide" +# shellcheck source=scripts/functions-core +source "${DEVON_IDE_HOME}/scripts/functions-core" # $1: message (may contain newlines with \n) # $2: optional exit code @@ -62,29 +61,31 @@ function doResult() { # $2: message # $3: optional working directory function doRunCommand() { - local cwd=${PWD} - if [ -n "${3}" ] + local command="${1}" + local message="${2}" + local dir="${3}" + if [ -n "${dir}" ] then - if [ -d "${3}" ] + if [ -d "${dir}" ] then - cd "${3}" || exit 1 + pushd "${dir}" > /dev/null || exit 255 else doFail "Working directory ${3} does not exist." fi fi - local message - if [ -z "${2}" ] + if [ -z "${message}" ] then - message="run command ${1/ */}" + doDebug "Trying to run command ${command}" + message="run command ${command/ */}" else - message="${2} (${1})" + doDebug "Trying to ${message} (${command})" + message="${message} (${command/ */})" fi - doDebug "Trying to ${message}" - eval "${1}" + eval "${command}" result=${?} - if [ -n "${3}" ] + if [ -n "${dir}" ] then - cd "${cwd}" || exit 1 + popd > /dev/null || exit 255 fi doResult "${message}" ${result} } @@ -385,23 +386,22 @@ function doUpdateMirrors() { # $3: the software to download (e.g. 'java', 'mvn', 'node') # $4: the version of the software to download # $5: the optional edition (e.g. "enterprise" or "community") -# $6: the optional code (magic value to avoid tool specific quirks in general functions) -# $7: operating system name -# $8: the optional architecture (e.g. x64 or x86_64) -# $9: the optional extension (e.g. 'tar.gz' or 'zip') -# $10: the optional filename to download to +# $6: operating system name +# $7: the optional architecture (e.g. x64 or x86_64) +# $8: the optional extension (e.g. 'tar.gz' or 'zip') +# $9: the optional filename to download to function doDownload() { + doDebug "doDownload ${*}" doLicenseAgreement local url="${1}" local target_dir="${2}" local software="${3}" local version="${4}" local edition="${5}" - local code="${6}" - local os="${7}" - local arch="${8}" - local ext="${9}" - local filename="${10}" + local os="${6}" + local arch="${7}" + local ext="${8}" + local filename="${9}" if [ -z "${target_dir}" ] then target_dir="${DEVON_DOWNLOAD_DIR}" @@ -545,7 +545,7 @@ function doDownload() { mirror_url="${mirror_url//\$\{ext\}/${ext}}" mirror_url="${mirror_url//\$\{edition\}/${edition}}" mirror_url="${mirror_url//\$\{major\}/${major}}" - mirror_url="${mirror_url//\$\{code\}/${code}}" + mirror_url="$(doResolveDownloadUrl "${mirror_url}" "${version}" "${os_new}" "${arch_new}" "${edition}")" if [ -z "${filename}" ] then @@ -673,6 +673,7 @@ function doGetFirstExistingPath() { function doExtract() { local target_dir=${DEVON_IDE_HOME}/updates/extracted local filename=${1/*\//} + local extracted="yes" rm -rf "${target_dir}" if [ -n "${2}" ] then @@ -701,10 +702,16 @@ function doExtract() { elif doIsInstallerExtension "${filename}" then doRunCommand "mv \"${1}\" \"${target_dir}\"" + extracted="no" else doFail "Unknown archive format: ${ext}. Can not extract ${1}" fi - doSuccess "Successfully extracted/moved archive ${filename} to updates/extracted" + if [ "${extracted}" = "no" ] + then + doSuccess "Successfully moved archive ${filename} to ${target_dir}" + else + doSuccess "Successfully extracted archive ${filename} to ${target_dir}" + fi } # $1: the file to unzip @@ -804,8 +811,9 @@ function doReplaceExtractedSkipSingleFolder() { local target_dir="${2}" local backup_dir="${3}" shift 3 - if [ "${#*}" = 1 ] && [ -d "${1}" ] && [[ ! "${1}" =~ .*\.app ]] + if [ "${#*}" = 1 ] && [ "${1%.app}" = "${1}" ] && [ -d "${1}" ] then + doDebug "Changing source directory from ${source_dir} to ${1} due to single folder." source_dir="${1}" fi doReplaceExtractedFile "${source_dir}" "${target_dir}" "${backup_dir}" @@ -851,10 +859,6 @@ function doIsDevVersion() { [ "${1}" = "dev-SNAPSHOT" ] || [ "${1}" = "0-SNAPSHOT" ] } -# defaults, may be overridden before calling doMavenArchetype -ARCHETYPE_GROUP_ID="com.devonfw.java.templates" -ARCHETYPE_ARTIFACT_ID="devon4j-template-server" - # ${1}-${n-1}: array # ${n}: prefix to check if array contains element starting with function doArrayContainsItemWithPrefix() { @@ -1035,7 +1039,7 @@ function doUpgradeMavenArtifact() { doAskToContinue "Latest version seems unstable: ${target_version}\nAre you sure you want to install this version?" fi url="${url}/${target_version}/${artifact_id}-${target_version}${suffix}" - doInstall "${url}" "${1}" "${artifact_id}" "${target_version}" "${suffix}" "-" "" "" "" "${repository}" + doInstall "${artifact_id}" "${target_version}" "" "" "${1}" "-" "" "${repository}" "${url}" } # $1: target @@ -1060,7 +1064,7 @@ function doGitPullOrClone() { fi if [ -d "${dir}/.git" ] then - pushd "${dir}" > /dev/null || exit 255 + pushd "${dir}" > /dev/null || exit 255 local remotes remotes="$(git remote)" local message="Can not update git repository: ${dir}\n" @@ -1109,33 +1113,45 @@ function doGitPullOrClone() { fi } -# $1: download URL -# $2: absolute target path where to install -# $3: name of software -# $4: version of software -# $5: the optional edition (e.g. "enterprise" or "community") -# $6: optional code (for tool specific quirks) -# $7: optional OS indicator ('-' if OS independent) -# $8: optional architecture (e.g. x86_64) -# $9: optional extension (e.g. 'tar.gz' or 'zip') -# $10: optional software repo -# $11: optional to ignore extracting downloaded files (must not be empty to ignore extracting!) +# $1: URL +# $2: resolved version +# $3: resolved os +# $4: resolved arch +# $5: optional software edition +function doResolveDownloadUrl() { + echo "${1}" +} + +# $1: name of software +# $2: version of software +# $3: optional silent flag ('silent' to suppress output if already up-to-date or empty for version output) +# $4: optional edition (e.g. "enterprise" or "community") +# $5: optional absolute target path where to install +# $6: optional OS indicator ('-' if OS independent) +# $7: optional to ignore extracting downloaded files (use 'noUnpack' or leave empty to extract) +# $8: optional software repository +# $9: optional download URL function doInstall() { - local url="${1}" - local target_path="${2}" - local software="${3}" - local version="${4}" - local edition="${5}" - local code="${6}" - local os="${7}" - local arch="${8}" - local ext="${9}" - local repository="${10}" - local ignore_extract="${11}" + doDebug "doInstall ${*}" + local software="${1}" + local version="${2}" + local silent="${3}" + local edition="${4}" + local target_path="${5}" + local os="${6}" + local noUnpack="${7}" + local repository="${8}" + local url="${9}" + if [ -z "${target_path}" ] + then + target_path="${DEVON_IDE_HOME}/software/${software}" + fi + local ext + local arch local download_dir="${DEVON_DOWNLOAD_DIR}" - if [ -z "${target_path}" ] || [ -z "${url}" ] || [ -z "${software}" ] + if [ -z "${software}" ] then - doFail "Missing arguments for doInstall: ${*}" + doFail "Missing software argument for doInstall: ${*}" fi local result=0 if [ "${url/.git/}" != "${url}" ] @@ -1143,6 +1159,38 @@ function doInstall() { doGitPullOrClone "${target_path}" "${url}" return fi + if [ -z "${version}" ] + then + doUpdateMirrors + local available_versions="${DEVON_IDE_HOME}/mirrors/${software}/available-versions" + if [ -e "${available_versions}" ] + then + version="$(head -n 1 "${available_versions}")" + doDebug "Resolved latest version of ${software} to ${version} from ${available_versions}" + else + doFail "Version is unspecified for ${software} but could not be found in ${available_versions}." + fi + elif [ "${version:${#version}-1}" = "*" ] + then + doDebug "Resolving version prefix ${version}" + local version_prefix="${version:0:${#version}-1}" + doUpdateMirrors + local available_versions="${DEVON_IDE_HOME}/mirrors/${software}/available-versions" + if [ -e "${available_versions}" ] + then + local resolved_version + resolved_version="$(grep "^${version_prefix}[^0-9]" "${available_versions}" | head -n 1)" + if [ -n "${resolved_version}" ] + then + doDebug "Resolved version prefix ${version} to ${resolved_version}" + version="${resolved_version}" + else + doFail "Could not resolve version prefix ${version} : no matching version found in ${available_versions}" + fi + else + doFail "Could not resolve version prefix ${version} : missing file ${available_versions}" + fi + fi local version_file="${target_path}/.devon.software.version" local current_version= if [ -e "${version_file}" ] @@ -1150,17 +1198,21 @@ function doInstall() { current_version="$(cat "${version_file}")" if [ "${current_version}" == "${version}" ] then - doEcho "Version ${version} of ${software} is already installed." + if [ -z "${silent}" ] + then + doEcho "Version ${version} of ${software} is already installed." + if [ -n "${TOOL_VERSION_COMMAND}" ] && [ "${TOOL_VERSION_COMMAND}" != "-" ] && ! doIsQuiet + then + doRunCommand "${TOOL_VERSION_COMMAND}" "verify installation of ${software}" + fi + fi return 1 else doEcho "Updating ${software} from version ${current_version} to version ${version}..." fi fi - local dir=${target_path/*\//} - if [ "${target_path}" = "${DEVON_IDE_HOME}/software/${dir}" ] - then - mkdir -p "${DEVON_IDE_HOME}/software" - fi + local dir="${target_path/*\//}" + doRunCommand "mkdir -p '${target_path%/*}'" local repo="default" if [ -z "${repository}" ] then @@ -1201,20 +1253,21 @@ function doInstall() { rm "${target_path}" fi local install_path="${target_path}" - if [ -n "${DEVON_SOFTWARE_PATH}" ] && [ "${target_path}" != "${DEVON_IDE_HOME}" ] + if [ "${target_path}" = "${DEVON_IDE_HOME}/software/${dir}" ] || [ "${target_path}" = "${DEVON_IDE_HOME}/software/extra/${dir}" ] && [ -n "${DEVON_SOFTWARE_PATH}" ] then install_path="${DEVON_SOFTWARE_PATH}/${repo}/${software}/${version}" version_file="${install_path}/.devon.software.version" fi if [ ! -d "${install_path}" ] || [ "${install_path}" == "${target_path}" ] then - if [ -n "${ignore_extract}" ] + doDownload "${url}" "${download_dir}" "${software}" "${version}" "${edition}" "${os}" "${arch}" "${ext}" + doDebug "Received download file ${DOWNLOAD_FILENAME}" + if [ -n "${noUnpack}" ] then - doDownload "${url}" "${target_path}" "${software}" "${version}" "${edition}" "${code}" "${os}" "${arch}" "${ext}" - doDebug "Received download file ${DOWNLOAD_FILENAME}" + doDebug "Download shall not be extracted, hence copying ${DOWNLOAD_FILENAME} to ${install_path}" + doRunCommand "mkdir -p '${install_path}'" + doRunCommand "cp '${download_dir}/${DOWNLOAD_FILENAME}' '${install_path}'" else - doDownload "${url}" "${download_dir}" "${software}" "${version}" "${edition}" "${code}" "${os}" "${arch}" "${ext}" - doDebug "Received download file ${DOWNLOAD_FILENAME}" doExtract "${download_dir}/${DOWNLOAD_FILENAME}" "${dir}" doReplaceExtracted "${DEVON_IDE_HOME}/updates/extracted/${dir}" "${install_path}" fi @@ -1236,17 +1289,13 @@ function doInstall() { doFail "Installation corrupt at ${install_path}\nDetected version: ${current_version}\nExpected version: ${version}" fi fi - if [ "${target_path}" = "${DEVON_IDE_HOME}/software/${dir}" ] - then - doExtendPath "${target_path}" - fi if [ "${install_path}" != "${target_path}" ] then doBackup "${target_path}" doEcho "Linking ${install_path} to ${target_path}" if doIsWindows then - cmd //c mklink "${install_path}" "${target_path}" + doRunCommand "cmd //c 'mklink /d /j $(cygpath -w "${target_path}") $(cygpath -w "${install_path}")'" if [ "${?}" != 0 ] then doFail "Creating symbolic links is not supported on your windows operating system.\nPlease read the documentation how to properly configure your OS or disable this feature by removing the DEVON_SOFTWARE_PATH variable." @@ -1257,21 +1306,77 @@ function doInstall() { fi # macos workaround - if [ ! -d "${target_path}/bin" ] && doIsMacOs && [ -d "${target_path}/Contents/Home/bin" ] + if [ ! -d "${target_path}/bin" ] && doIsMacOs then - doEcho "Creating symlink as workaround for ${software} on MacOS" - local target_software_macos=${target_path%\/*}/macos - if [ ! -d "${target_software_macos}" ] + local contents="Contents" + if ! [ -d "${target_path}/${contents}" ] + then + pushd "${target_path}" > /dev/null || exit 255 + # doGetFirstExistingPath does not have options + # shellcheck disable=SC2035 + contents="$(doGetFirstExistingPath *.app/Contents)" + popd > /dev/null || exit 255 + fi + if [ -n "${contents}" ] && [ -d "${target_path}/${contents}" ] then - mkdir -p "${target_software_macos}" + doDebug "Found MacOS app in ${target_path}/${contents}" + local app_folder="-" + if [ -d "${target_path}/${contents}/Resources/app/bin" ] + then + app_folder="Resources/app" + else + local folder + while IFS= read -r -d '' folder + do + folder="${folder/*\//}" + doDebug "Checking app sub-folder ${folder}" + if [ "${folder}" != "Contents" ] && [ "${folder}" != "Resources" ] && [ "${folder}" != "bin" ] && [ "${folder:0:1}" != "_" ] + then + if [ -d "${target_path}/${contents}/${folder}/bin" ] + then + app_folder="${folder}" + doDebug "App folder with bin detected as ${app_folder}" + break + else + doDebug "Looking for executable in ${folder}" + local file + while IFS= read -r -d '' file + do + if [ -x "${file}" ] && [ "${file:(-4)}" != ".txt" ] + then + app_folder="${folder/*\//}" + doDebug "App folder with executable detected as ${app_folder}" + break + fi + done < <(find "${target_path}/${contents}/${folder}/" -maxdepth 1 -type f -print0) + fi + fi + done < <(find "${target_path}/${contents}" -maxdepth 1 -type d -print0) + fi + if [ "${app_folder}" != "-" ] && [ -d "${target_path}/${contents}/${app_folder}" ] + then + doEcho "Creating symlink as workaround for ${software} on MacOS" + local target_software_macos=${target_path%\/*}/macos + if [ ! -d "${target_software_macos}" ] + then + mkdir -p "${target_software_macos}" + fi + local target_software_software=${target_software_macos}/${dir} + doRunCommand "rm -rf '${target_software_software}'" + doRunCommand "mv '${target_path}' '${target_software_software}'" + doRunCommand "ln -sf 'macos/${dir}/${contents}/${app_folder}' '${target_path}'" + doRunCommand "cp '${target_software_software}/.devon.software.version' '${target_path}'" + fi fi - local target_software_software=${target_software_macos}/${dir} - doRunCommand "rm -rf '${target_software_software}'" - doRunCommand "mv '${target_path}' '${target_software_software}'" - doRunCommand "ln -sf 'macos/${dir}/Contents/Home' '${target_path}'" - doRunCommand "cp '${target_software_software}/.devon.software.version' '${target_path}'" fi - + if [ "${target_path}" = "${DEVON_IDE_HOME}/software/${dir}" ] + then + doExtendPath "${target_path}" + fi + if [ -n "${TOOL_VERSION_COMMAND}" ] && [ "${TOOL_VERSION_COMMAND}" != "-" ] && ! doIsQuiet + then + doRunCommand "${TOOL_VERSION_COMMAND}" "verify installation of ${software}" + fi return ${result} } @@ -1336,7 +1441,7 @@ function doRunConfigurator() { classpath="${classpath}:${file}" fi done - doRunCommand "java -cp '${classpath}' ${*}" + doRunCommand "java -cp '${classpath}' ${*}" "Configure workspace" } # $1: name of ide @@ -1406,8 +1511,8 @@ function doVersionCompare() { n2="${r2//[^0-9]/}" local x1="${r1:0:(${#r1}-${#n1})}" local x2="${r2:0:(${#r2}-${#n2})}" - x1="${x1//[-_+]/}" - x2="${x2//[-_+]/}" + x1="${x1//[-_+*]/}" + x2="${x2//[-_+*]/}" if [ "${x1}" = "${x2}" ] then if [ -z "${n1}" ] @@ -1504,6 +1609,16 @@ function doIsWindows() { return 255 } +# $1: prefic to check +# $2: string potentially containing the prefix +function doIsPrefix() { + case "${2}" in + "${1}"*) + return 0;; + esac + return 255 +} + # $1: dirctory function doIsEmptyDirectory() { local dir="${1}" @@ -1562,6 +1677,9 @@ function doGetToolFolderName() { elif [ "${tool}" = "sonar" ] then tool="sonarqube" + elif [ "${tool}" = "cobigen" ] + then + tool="cobigen-cli" fi echo "${tool}" } @@ -1650,14 +1768,9 @@ function doListSoftwareVersions() { # $@: CLI args # returns 0 if a standard option was detected and handled, 255 otherwise (regular argument to be handeled by CLI parser) function doParseOption() { - if [ -n "${end_options}" ] - then - return 255 - fi if [ "${1}" = "--" ] then - end_options="true" - return + return 1 elif [ "${1}" = "-b" ] || [ "${1}" = "--batch" ] then batch="${1}" @@ -1696,13 +1809,3 @@ function doParseOption() { fi return 255 } - -end_options="" -batch="" -force="" -quiet="" -debug="" -while [ -n "${1}" ] && doParseOption "${@}" -do - shift -done diff --git a/scripts/src/main/resources/scripts/functions-core b/scripts/src/main/resources/scripts/functions-core new file mode 100644 index 000000000..aeaa567a1 --- /dev/null +++ b/scripts/src/main/resources/scripts/functions-core @@ -0,0 +1,161 @@ +#!/usr/bin/env bash +if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi +# Script with fundamental functions already needed by devon command. +# Will be sourced, hash bang only for filetype detection and editor syntax support + +# $1: path of properties file to load +# $2: optional prefix to add to variables +# $3: optional arg to export all variables if not empty +function doLoadProperties() { + if ! [ -f "${1}" ] + then + return + fi + if test "$(tail -c 1 "${1}" | wc -l)" -eq 0 + then + echo "Appending missing newline to ${1}" + echo >> "${1}" + fi + local key + local value + local export_key + while IFS='=' read -r key value + do + if [ -n "${key}" ] && [ "${key:0:1}" != "#" ] + then + key="${key//$'\r'}" + value="${value//$'\r'}" + export_key="" + if [ "${value:0:1}" = "~" ] + then + value=${HOME}${value:1} + fi + if [ "${key:0:7}" = "export " ] + then + export_key="true" + key="${key:7}" + elif [ -n "${3}" ] + then + export_key="true" + fi + key="${2}${key/./_}" + if [ -z "${value}" ] + then + if [ -n "${key}" ] + then + unset "${key}" + fi + else + if [ "${OSTYPE}" = "cygwin" ] || [ "${OSTYPE}" = "msys" ] + then + if [[ "${value}" =~ ^[A-Za-z]:[\\/] ]] + then + value="$(cygpath "${value}")" + fi + fi + if [ "${value:0:1}" != "(" ] && [ "${value:0:1}" != '"' ] + then + value=\"${value}\" + fi + eval "${key}=${value}" + if [ "${export_key}" = "true" ] && [ -z "${2}" ] + then + # shellcheck disable=SC2086,SC2163 + export ${key?} + fi + fi + fi + done < "${1}" +} + +function doUpdatePath() { + if [ -z "${DEVON_OLD_PATH}" ] + then + export DEVON_OLD_PATH="${PATH}" + else + if [[ "${DEVON_OLD_PATH}" == *"C:\\WINDOWS"* ]] + then + # https://github.com/devonfw/ide/issues/49 + DEVON_OLD_PATH= + IFS=':' + set -f + for dir in ${PATH} + do + if [[ "${dir}" != "${DEVON_IDE_HOME}"* ]] + then + if [ -z "${DEVON_OLD_PATH}" ] + then + DEVON_OLD_PATH="${dir}" + else + DEVON_OLD_PATH="${DEVON_OLD_PATH}:${dir}" + fi + fi + done + set +f + unset IFS + export DEVON_OLD_PATH + fi + PATH="${DEVON_OLD_PATH}" + fi + # Setup path + SOFTWARE_PATH=${DEVON_IDE_HOME}/software + for SOFTWARE_FOLDER in "${SOFTWARE_PATH}"/* + do + if [ "${SOFTWARE_FOLDER}" != "${SOFTWARE_PATH}/extra" ] + then + if [ -d "${SOFTWARE_FOLDER}/bin" ] + then + PATH="${SOFTWARE_FOLDER}/bin:${PATH}" + else + PATH="${SOFTWARE_FOLDER}:${PATH}" + fi + # Load custom configuration of software + if [ -e "${SOFTWARE_FOLDER}/ide-config" ] + then + # shellcheck disable=SC1090,SC1091 + source "${SOFTWARE_FOLDER}/ide-config" + fi + fi + done + + # node.js support + if [ -d "${DEVON_IDE_HOME}/software/nodejs" ] + then + PATH="${PATH}:$(npm bin -g 2> /dev/null)" + fi +} + +function doEnvironmentProject() { + # determine proper home directory + DEVON_HOME_DIR=~ + if [ "${OSTYPE}" = "cygwin" ] + then + DEVON_HOME_DIR="$(cygpath "${USERPROFILE}")" + fi + # load and setup configuration + doLoadProperties "${DEVON_IDE_HOME}/scripts/devon.properties" "" "${@}" + doLoadProperties "${DEVON_HOME_DIR}/devon.properties" "" "${@}" + doLoadProperties "${DEVON_IDE_HOME}/devon.properties" "" "${@}" + doLoadProperties "${SETTINGS_PATH}/devon.properties" "" "${@}" + if [ -z "${WORKSPACE}" ] + then + WORKSPACE=main + fi + export WORKSPACE + export WORKSPACE_PATH=${DEVON_IDE_HOME}/workspaces/${WORKSPACE} + if [ ! -d "${WORKSPACE_PATH}" ] + then + if [ "${WORKSPACE}" = "main" ] + then + echo "Creating main workspace directory" + mkdir -p "${WORKSPACE_PATH}" + else + echo "Workspace ${WORKSPACE} does not exist" + fi + fi + doLoadProperties "${WORKSPACE_PATH}/devon.properties" "" "${@}" + doUpdatePath + # load user settings late so variables like M2_REPO can be overridden + doLoadProperties "${DEVON_IDE_HOME}/conf/devon.properties" "" "${@}" + export PATH +} \ No newline at end of file diff --git a/scripts/src/test/bash/test-functions-doc b/scripts/src/test/bash/test-functions-doc index 9376a9976..8e9c5e7a7 100755 --- a/scripts/src/test/bash/test-functions-doc +++ b/scripts/src/test/bash/test-functions-doc @@ -1,7 +1,7 @@ #!/bin/bash SCRIPTS_PATH="../../../../scripts/src/main/resources/scripts" -( set -o pipefail; grep "function " "${SCRIPTS_PATH}/functions" "${SCRIPTS_PATH}/environment-project" | sed 's/.*function //' | sed 's/() {//' | sort -u > functions.list ) || exit 1 +( set -o pipefail; grep "function " "${SCRIPTS_PATH}/functions" "${SCRIPTS_PATH}/functions-core" | sed 's/.*function //' | sed 's/() {//' | sort -u > functions.list ) || exit 1 ( set -o pipefail; grep "=== " "../../../../documentation/functions.asciidoc" | sed 's/=== //' | sort -u > functions.adoc.list ) || exit 1 diff functions.list functions.adoc.list diff --git a/scripts/src/test/bash/test-version-compare b/scripts/src/test/bash/test-version-compare index bf87436ef..2ef44762b 100755 --- a/scripts/src/test/bash/test-version-compare +++ b/scripts/src/test/bash/test-version-compare @@ -58,5 +58,6 @@ doTestVersionCompare 3.0.0.rc2 '<' 3.0.0 doTestVersionCompare 3.0.0-beta17 '>' 3.0.0-beta11-SNAPSHOT doTestVersionCompare 3.0.0.11 '>' 3.0.0-beta11-SNAPSHOT doTestVersionCompare 2020.04.001 '>' 3.3.1 +doTestVersionCompare "11*" '>' "11u0" exit "${exitcode}" \ No newline at end of file