Detect powershell script won't simply exit if the java test fails. If passthrough is set it will pass 127 to the external script.
@@ -44,7 +44,7 @@ $EnvHomeTempFolder = "$HOME\tmp"
# heap size, you would set DETECT_JAVA_OPTS=-Xmx6G.
#$DetectJavaOpts = Get-EnvironmentVariable -Key "DETECT_JAVA_OPTS" -DefaultValue "";
-$Version = "0.6.3"
+$Version = "0.6.4"
$DetectReleaseBaseUrl = "https://test-repo.blackducksoftware.com/artifactory/bds-integrations-release/com/blackducksoftware/integration/hub-detect"
$DetectSnapshotBaseUrl = "https://test-repo.blackducksoftware.com/artifactory/bds-integrations-snapshot/com/blackducksoftware/integration/hub-detect"
@@ -57,7 +57,14 @@ function Detect {
Write-Host "Detect Powershell Script $Version"
if ($EnvDetectSkipJavaTest -ne "1"){
- Test-JavaExists
+ if (Test-JavaNotAvailable){ #If java is not available, we abort early.
+ $JavaExitCode = 127 #Command not found http://tldp.org/LDP/abs/html/exitcodes.html
+ if ($EnvDetectExitCodePassthru -eq "1"){
+ return $JavaExitCode
+ }else{
+ exit $JavaExitCode
+ }
+ }
}else{
Write-Host "Skipping java test."
}
@@ -303,7 +310,7 @@ function Set-ToEscaped ($ArgArray){
}
}
-function Test-JavaExists() {
+function Test-JavaNotAvailable() {
Write-Host "Checking if Java is installed by asking for version."
try {
$ProcessStartInfo = New-object System.Diagnostics.ProcessStartInfo
@@ -322,8 +329,9 @@ function Test-JavaExists() {
Write-Host "Java Standard Output: $StdOutput"
Write-Host "Java Error Output: $StdError"
Write-Host "Successfully able to start java and get version."
+ return $FALSE;
}catch {
Write-Host "An error occurred checking the Java version. Please ensure Java is installed."
- exit 127 #Command not found http://tldp.org/LDP/abs/html/exitcodes.html
+ return $TRUE;
}
}
