@@ -31,7 +31,7 @@ $EnvDetectFolder = Get-EnvironmentVariable -Key "DETECT_JAR_PATH" -DefaultValue
3131$EnvTempFolder = Get-EnvironmentVariable - Key " TMP" - DefaultValue " " ;
3232$EnvHomeTempFolder = " $HOME \tmp"
3333
34- # If you want to pass proxy information, use detect environment variables such as 'blackduck.hub. proxy.host'
34+ # If you want to pass proxy information, use detect environment variables such as 'blackduck.proxy.host'
3535# If you do pass the proxy information in this way, you do not need to supply it to detect as arguments.
3636# Note: This script will not pick up proxy information from the passed 'detect arguments'
3737# Note: This script will not pick up proxy information passed to the bash script using 'DETECT_CURL_OPTS'
@@ -44,7 +44,7 @@ $EnvHomeTempFolder = "$HOME\tmp"
4444# heap size, you would set DETECT_JAVA_OPTS=-Xmx6G.
4545# $DetectJavaOpts = Get-EnvironmentVariable -Key "DETECT_JAVA_OPTS" -DefaultValue "";
4646
47- $Version = " 0.6.4 "
47+ $Version = " 0.7.0 "
4848
4949$DetectReleaseBaseUrl = " https://test-repo.blackducksoftware.com/artifactory/bds-integrations-release/com/blackducksoftware/integration/hub-detect"
5050$DetectSnapshotBaseUrl = " https://test-repo.blackducksoftware.com/artifactory/bds-integrations-snapshot/com/blackducksoftware/integration/hub-detect"
@@ -57,7 +57,14 @@ function Detect {
5757 Write-Host " Detect Powershell Script $Version "
5858
5959 if ($EnvDetectSkipJavaTest -ne " 1" ){
60- Test-JavaExists
60+ if (Test-JavaNotAvailable ){ # If java is not available, we abort early.
61+ $JavaExitCode = 127 # Command not found http://tldp.org/LDP/abs/html/exitcodes.html
62+ if ($EnvDetectExitCodePassthru -eq " 1" ){
63+ return $JavaExitCode
64+ }else {
65+ exit $JavaExitCode
66+ }
67+ }
6168 }else {
6269 Write-Host " Skipping java test."
6370 }
@@ -86,6 +93,16 @@ function Detect {
8693 }
8794}
8895
96+ function Get-FirstFromEnv ($Names ) {
97+ foreach ($Name in $Names ){
98+ $Value = Get-EnvironmentVariable - Key $Name - Default $null ;
99+ if (-Not [string ]::IsNullOrEmpty($Value )){
100+ return $Value ;
101+ }
102+ }
103+ return $null ;
104+ }
105+
89106function Get-ProxyInfo () {
90107 $ProxyInfoProperties = @ {
91108 ' Uri' = $null
@@ -94,24 +111,15 @@ function Get-ProxyInfo () {
94111
95112 try {
96113
97- $ProxyHost = ${Env: blackduck.hub.proxy.host} ;
98-
99- if ([string ]::IsNullOrEmpty($ProxyHost )){
100- $ProxyHost = ${BLACKDUCK_HUB_PROXY_HOST} ;
101- }
114+ $ProxyHost = Get-FirstFromEnv @ (" blackduck.proxy.host" , " BLACKDUCK_PROXY_HOST" , " blackduck.hub.proxy.host" , " BLACKDUCK_HUB_PROXY_HOST" );
102115
103116 if ([string ]::IsNullOrEmpty($ProxyHost )){
104117 Write-Host " Skipping proxy, no host found."
105118 }else {
106119 Write-Host " Found proxy host."
107- $ProxyUrlBuilder = New-Object System.UriBuilder
108- $ProxyUrlBuilder.Host = $ProxyHost
120+ $ProxyUrlBuilder = New-Object System.UriBuilder - ArgumentList $ProxyHost
109121
110- $ProxyPort = ${Env: blackduck.hub.proxy.port} ;
111-
112- if ([string ]::IsNullOrEmpty($ProxyPort )){
113- $ProxyPort = ${Env: BLACKDUCK_HUB_PROXY_PORT} ;
114- }
122+ $ProxyPort = Get-FirstFromEnv @ (" blackduck.proxy.port" , " BLACKDUCK_PROXY_PORT" , " blackduck.hub.proxy.port" , " BLACKDUCK_HUB_PROXY_PORT" );
115123
116124 if ([string ]::IsNullOrEmpty($ProxyPort )){
117125 Write-Host " No proxy port found."
@@ -123,16 +131,8 @@ function Get-ProxyInfo () {
123131 $ProxyInfoProperties.Uri = $ProxyUrlBuilder.Uri
124132
125133 # Handle credentials
126- $ProxyUsername = ${Env: blackduck.hub.proxy.username} ;
127- $ProxyPassword = ${Env: blackduck.hub.proxy.password} ;
128-
129- if ([string ]::IsNullOrEmpty($ProxyUsername )){
130- $ProxyUsername = ${BLACKDUCK_HUB_PROXY_USERNAME} ;
131- }
132-
133- if ([string ]::IsNullOrEmpty($ProxyPassword )){
134- $ProxyPassword = ${BLACKDUCK_HUB_PROXY_PASSWORD} ;
135- }
134+ $ProxyUsername = Get-FirstFromEnv @ (" blackduck.proxy.username" , " BLACKDUCK_PROXY_USERNAME" , " blackduck.hub.proxy.username" , " BLACKDUCK_HUB_PROXY_USERNAME" );
135+ $ProxyPassword = Get-FirstFromEnv @ (" blackduck.proxy.password" , " BLACKDUCK_PROXY_PASSWORD" , " blackduck.hub.proxy.password" , " BLACKDUCK_HUB_PROXY_PASSWORD" );
136136
137137 if ([string ]::IsNullOrEmpty($ProxyPassword ) -or [string ]::IsNullOrEmpty($ProxyUsername )){
138138 Write-Host " No proxy credentials found."
@@ -303,7 +303,7 @@ function Set-ToEscaped ($ArgArray){
303303 }
304304}
305305
306- function Test-JavaExists () {
306+ function Test-JavaNotAvailable () {
307307 Write-Host " Checking if Java is installed by asking for version."
308308 try {
309309 $ProcessStartInfo = New-object System.Diagnostics.ProcessStartInfo
@@ -322,8 +322,9 @@ function Test-JavaExists() {
322322 Write-Host " Java Standard Output: $StdOutput "
323323 Write-Host " Java Error Output: $StdError "
324324 Write-Host " Successfully able to start java and get version."
325+ return $FALSE ;
325326 }catch {
326327 Write-Host " An error occurred checking the Java version. Please ensure Java is installed."
327- exit 127 # Command not found http://tldp.org/LDP/abs/html/exitcodes.html
328+ return $TRUE ;
328329 }
329- }
330+ }
0 commit comments