diff --git a/src/com/sap/piper/VersionUtils.groovy b/src/com/sap/piper/VersionUtils.groovy index bbde584db..f9b7a7541 100644 --- a/src/com/sap/piper/VersionUtils.groovy +++ b/src/com/sap/piper/VersionUtils.groovy @@ -5,7 +5,7 @@ import hudson.AbortException class VersionUtils implements Serializable { - def static verifyVersion(script, name, executable, version, versionOption) { + def static verifyVersion(script, name, executable, String version, versionOption) { script.echo "Verifying $name version $version or compatible version." @@ -22,4 +22,26 @@ class VersionUtils implements Serializable { } script.echo "Verification success. $name version ${installedVersion.toString()} is installed." } + + def static verifyVersion(script, name, executable, Map versions, versionOption) { + + def toolVersion + try { + toolVersion = script.sh returnStdout: true, script: """#!/bin/bash + $executable $versionOption""" + } catch(AbortException e) { + throw new AbortException("The verification of $name failed. Please check '$executable'. $e.message.") + } + for (def entry : versions) { + if (toolVersion.contains(entry.getKey())) { + def installedVersion = new Version(toolVersion) + def expectedVersion = entry.getValue() + script.echo "Verifying $name version $expectedVersion or compatible version." + if (!installedVersion.isCompatibleVersion(new Version(expectedVersion))) { + throw new AbortException("The installed version of $name is ${installedVersion.toString()}. Please install version $expectedVersion or a compatible version.") + } + script.echo "Verification success. $name version ${installedVersion.toString()} is installed." + } + } + } } diff --git a/src/com/sap/piper/tools/ToolDescriptor.groovy b/src/com/sap/piper/tools/ToolDescriptor.groovy index 9931b49c3..0f4681889 100644 --- a/src/com/sap/piper/tools/ToolDescriptor.groovy +++ b/src/com/sap/piper/tools/ToolDescriptor.groovy @@ -15,16 +15,29 @@ class ToolDescriptor implements Serializable { final stepConfigurationKey final executablePath final executableName - final version + final singleVersion + final multipleVersions final versionOption - ToolDescriptor(name, environmentKey, stepConfigurationKey, executablePath, executableName, version, versionOption) { + ToolDescriptor(name, environmentKey, stepConfigurationKey, executablePath, executableName, String singleVersion, versionOption) { this.name = name this.environmentKey = environmentKey this.stepConfigurationKey = stepConfigurationKey this.executablePath = executablePath this.executableName = executableName - this.version = version + this.singleVersion = singleVersion + this.multipleVersions = [:] + this.versionOption = versionOption + } + + ToolDescriptor(name, environmentKey, stepConfigurationKey, executablePath, executableName, Map multipleVersions, versionOption) { + this.name = name + this.environmentKey = environmentKey + this.stepConfigurationKey = stepConfigurationKey + this.executablePath = executablePath + this.executableName = executableName + this.singleVersion = '' + this.multipleVersions = multipleVersions this.versionOption = versionOption } @@ -95,7 +108,8 @@ class ToolDescriptor implements Serializable { def verifyVersion(script, configuration) { def executable = getToolExecutable(script, configuration, false) - VersionUtils.verifyVersion(script, name, executable, version, versionOption) + if (singleVersion) VersionUtils.verifyVersion(script, name, executable, singleVersion, versionOption) + if (multipleVersions) VersionUtils.verifyVersion(script, name, executable, multipleVersions, versionOption) } def getMessage() {