From 7aa7094f7f4c179740aede0202939dce9df8f751 Mon Sep 17 00:00:00 2001 From: blackduck-serv-builder Date: Fri, 4 Oct 2024 15:20:37 -0400 Subject: [PATCH] Committing the latest update-site contents to gh-pages branch. --- detect10-3.2.0-SNAPSHOT.ps1 | 393 ++++++++++++++++++++++++++++++++++++ detect10-3.2.0-SNAPSHOT.sh | 205 +++++++++++++++++++ latest-commit-id.txt | 2 +- 3 files changed, 599 insertions(+), 1 deletion(-) create mode 100755 detect10-3.2.0-SNAPSHOT.ps1 create mode 100755 detect10-3.2.0-SNAPSHOT.sh diff --git a/detect10-3.2.0-SNAPSHOT.ps1 b/detect10-3.2.0-SNAPSHOT.ps1 new file mode 100755 index 0000000..e546ba9 --- /dev/null +++ b/detect10-3.2.0-SNAPSHOT.ps1 @@ -0,0 +1,393 @@ +# Detect Powershell Script +# Recommended Invocation: powershell "irm https://detect.blackduck.com/detect.ps1?$(Get-Random) | iex; detect" +$ProgressPreference = 'SilentlyContinue' +function Get-EnvironmentVariable($Key, $DefaultValue) { if (-not (Test-Path Env:$Key)) { return $DefaultValue; }else { return (Get-ChildItem Env:$Key).Value; } } + +# DETECT_LATEST_RELEASE_VERSION should be set in your +# environment if you wish to use a version different +# from LATEST. +$EnvDetectDesiredVersion = Get-EnvironmentVariable -Key "DETECT_LATEST_RELEASE_VERSION" -DefaultValue ""; + +# To override the default version key, specify a +# different DETECT_VERSION_KEY in your environment and +# *that* key will be used to get the download url from +# artifactory. These DETECT_VERSION_KEY values are +# properties in Artifactory that resolve to download +# urls for the detect jar file. As of 2024-10-04, the +# available DETECT_VERSION_KEY values are: +# DETECT_LATEST_10 +# Every new major version of detect will have its own +# DETECT_LATEST_X key. +$EnvDetectVersionKey = Get-EnvironmentVariable -Key "DETECT_VERSION_KEY" -DefaultValue "DETECT_LATEST_10"; + +# If you want to skip the test for java +# DETECT_SKIP_JAVA_TEST=1 +$EnvDetectSkipJavaTest = Get-EnvironmentVariable -Key "DETECT_SKIP_JAVA_TEST" -DefaultValue ""; + +# You can specify your own download url from +# artifactory which can bypass using the property keys +# (this is mainly for QA purposes only) +$EnvDetectSource = Get-EnvironmentVariable -Key "DETECT_SOURCE" -DefaultValue ""; + +# To override the default location of /tmp, specify +# your own DETECT_JAR_DOWNLOAD_DIR in your environment and +# *that* location will be used. +# *NOTE* We currently do not support spaces in the +# DETECT_JAR_DOWNLOAD_DIR. +# Otherwise, if the environment temp folder is set, +# it will be used. Otherwise, a temporary folder will +# be created in your home directory +$EnvDetectFolder = Get-EnvironmentVariable -Key "DETECT_JAR_DOWNLOAD_DIR" -DefaultValue ""; +if ([string]::IsNullOrEmpty($EnvDetectFolder)) { + # Try again using old name for backward compatibility + $EnvDetectFolder = Get-EnvironmentVariable -Key "DETECT_JAR_PATH" -DefaultValue ""; +} + +$EnvTempFolder = Get-EnvironmentVariable -Key "TMP" -DefaultValue ""; +$EnvHomeTempFolder = "$HOME/tmp" + + +# If you do not want to exit with the detect exit +# code, set DETECT_EXIT_CODE_PASSTHRU to 1 and this +# script won't exit, but simply return it (pass it thru). +$EnvDetectExitCodePassthru = Get-EnvironmentVariable -Key "DETECT_EXIT_CODE_PASSTHRU" -DefaultValue ""; + +# If you want to pass proxy information, use detect +# environment variables such as 'blackduck.proxy.host' +# If you do pass the proxy information in this way, +# you do not need to supply it to detect as arguments. +# Note: This script will not pick up proxy information +# from the passed 'detect arguments' +# Note: This script will not pick up proxy information +# passed to the bash script using 'DETECT_CURL_OPTS' + +# To control which java detect will use to run, specify +# the path in in DETECT_JAVA_PATH or JAVA_HOME in your +# environment, or ensure that java is first on the path. +# DETECT_JAVA_PATH will take precedence over JAVA_HOME. +# JAVA_HOME will take precedence over the path. +# Note: DETECT_JAVA_PATH should point directly to the +# java executable. For JAVA_HOME the java executable is +# expected to be in JAVA_HOME/bin/java +$DetectJavaPath = Get-EnvironmentVariable -Key "DETECT_JAVA_PATH" -DefaultValue ""; +$JavaHome = Get-EnvironmentVariable -Key "JAVA_HOME" -DefaultValue ""; + +# If you only want to download the appropriate jar file set +# this to 1 in your environment. This can be useful if you +# want to invoke the jar yourself but do not want to also +# get and update the jar file when a new version releases. +$DownloadOnly = Get-EnvironmentVariable -Key "DETECT_DOWNLOAD_ONLY" -DefaultValue ""; + +# TODO: Mirror the functionality of the shell script +# and allow Java opts. + +# If you want to pass any java options to the +# invocation, specify DETECT_JAVA_OPTS in your +# environment. For example, to specify a 6 gigabyte +# heap size, you would set DETECT_JAVA_OPTS=-Xmx6G. +# $DetectJavaOpts = Get-EnvironmentVariable -Key "DETECT_JAVA_OPTS" -DefaultValue ""; + +$Version = "3.2.0-SNAPSHOT" + +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 #Enable TLS2 + +function Detect { + Write-Host "Detect Powershell Script $Version" + + if ($EnvDetectSkipJavaTest -ne "1") { + 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." + } + + Write-Host "Initializing Detect folder." + $DetectFolder = Initialize-DetectFolder -DetectFolder $EnvDetectFolder -TempFolder $EnvTempFolder -HomeTempFolder $EnvHomeTempFolder + + Write-Host "Checking for proxy." + $ProxyInfo = Get-ProxyInfo + + Write-Host "Getting Detect." + $DetectJarFile = Get-DetectJar -DetectFolder $DetectFolder -DetectSource $EnvDetectSource -DetectVersionKey $EnvDetectVersionKey -DetectVersion $EnvDetectDesiredVersion -ProxyInfo $ProxyInfo + + if ($DownloadOnly -ne "1") { + Write-Host "Executing Detect." + $DetectArgs = $args; + $DetectExitCode = Invoke-Detect -DetectJar $DetectJarFile -DetectArgs $DetectArgs + + if ($EnvDetectExitCodePassthru -eq "1") { + return $DetectExitCode + } else { + exit $DetectExitCode + } + } +} + +function Get-FirstFromEnv($Names) { + foreach ($Name in $Names) { + $Value = Get-EnvironmentVariable -Key $Name -Default $null; + if (-Not [string]::IsNullOrEmpty($Value)) { + return $Value; + } + } + return $null; +} + +function Get-ProxyInfo () { + $ProxyInfoProperties = @{ + 'Uri' = $null + 'Credentials' = $null + } + + try { + + $ProxyHost = Get-FirstFromEnv @("blackduck.proxy.host", "BLACKDUCK_PROXY_HOST", "blackduck.hub.proxy.host", "BLACKDUCK_HUB_PROXY_HOST"); + + if ([string]::IsNullOrEmpty($ProxyHost)) { + Write-Host "Skipping proxy, no host found." + } + else { + Write-Host "Found proxy host." + $ProxyUrlBuilder = New-Object System.UriBuilder -ArgumentList $ProxyHost + + $ProxyPort = Get-FirstFromEnv @("blackduck.proxy.port", "BLACKDUCK_PROXY_PORT", "blackduck.hub.proxy.port", "BLACKDUCK_HUB_PROXY_PORT"); + + if ([string]::IsNullOrEmpty($ProxyPort)) { + Write-Host "No proxy port found." + } + else { + Write-Host "Found proxy port." + $ProxyUrlBuilder.Port = $ProxyPort + } + + $ProxyInfoProperties.Uri = $ProxyUrlBuilder.Uri + + #Handle credentials + $ProxyUsername = Get-FirstFromEnv @("blackduck.proxy.username", "BLACKDUCK_PROXY_USERNAME", "blackduck.hub.proxy.username", "BLACKDUCK_HUB_PROXY_USERNAME"); + $ProxyPassword = Get-FirstFromEnv @("blackduck.proxy.password", "BLACKDUCK_PROXY_PASSWORD", "blackduck.hub.proxy.password", "BLACKDUCK_HUB_PROXY_PASSWORD"); + + if ([string]::IsNullOrEmpty($ProxyPassword) -or [string]::IsNullOrEmpty($ProxyUsername)) { + Write-Host "No proxy credentials found." + } + else { + Write-Host "Found proxy credentials." + $ProxySecurePassword = ConvertTo-SecureString $ProxyPassword -AsPlainText -Force + $ProxyCredentials = New-Object System.Management.Automation.PSCredential ($ProxyUsername, $ProxySecurePassword) + + $ProxyInfoProperties.Credentials = $ProxyCredentials; + } + + Write-Host "Proxy has been configured." + } + + } + catch [Exception] { + Write-Host ("An exception occurred setting up the proxy, will continue but will not use a proxy.") + Write-Host (" Reason: {0}" -f $_.Exception.GetType().FullName); + Write-Host (" Reason: {0}" -f $_.Exception.Message); + Write-Host (" Reason: {0}" -f $_.Exception.StackTrace); + } + + $ProxyInfo = New-Object -TypeName PSObject -Prop $ProxyInfoProperties + + return $ProxyInfo; +} + +function Invoke-WebRequestWrapper($Url, $ProxyInfo, $DownloadLocation = $null) { + $parameters = @{} + try { + if ($DownloadLocation -ne $null) { + $parameters.Add("OutFile", $DownloadLocation); + } + if ($ProxyInfo -ne $null) { + if ($ProxyInfo.Uri -ne $null) { + $parameters.Add("Proxy", $ProxyInfo.Uri); + } + if ($ProxyInfo.Credentials -ne $null) { + $parameters.Add("ProxyCredential", $ProxyInfo.Credentials); + } + } + } + catch [Exception] { + Write-Host ("An exception occurred setting additional properties on web request.") + Write-Host (" Reason: {0}" -f $_.Exception.GetType().FullName); + Write-Host (" Reason: {0}" -f $_.Exception.Message); + Write-Host (" Reason: {0}" -f $_.Exception.StackTrace); + } + + return Invoke-WebRequest $Url -UseBasicParsing @parameters -UserAgent "PowerShell" # Workaround for https://www.jfrog.com/jira/si/jira.issueviews:issue-html/RTFACT-26216/RTFACT-26216.html +} + +function Get-DetectJar ($DetectFolder, $DetectSource, $DetectVersionKey, $DetectVersion, $ProxyInfo) { + $LastDownloadFile = "$DetectFolder/detect-last-downloaded-jar.txt" + + if ($DetectSource -eq "") { + if ($DetectVersion -eq "") { + $DetectVersionUrl = "https://repo.blackduck.com/api/storage/bds-integrations-release/com/blackduck/integration/detect?properties=" + $DetectVersionKey + $DetectSource = Receive-DetectSource -ProxyInfo $ProxyInfo -DetectVersionUrl $DetectVersionUrl -DetectVersionKey $DetectVersionKey + } + else { + $DetectSource = "https://repo.blackduck.com/bds-integrations-release/com/blackduck/integration/detect/" + $DetectVersion + "/detect-" + $DetectVersion + ".jar" + } + } + + if ($DetectSource) { + Write-Host "Using Detect source $DetectSource" + + $DetectFileName = Parse-Detect-File-Name -DetectSource $DetectSource + + $DetectJarFile = "$DetectFolder/$DetectFileName" + } else { + Write-Host "Unable to find Detect Source, will attempt to find a last downloaded detect." + + $LastDownloadFileExists = Test-Path $LastDownloadFile + Write-Host "Last download exists '$LastDownloadFileExists'" + + if ($LastDownloadFileExists) { + $DetectJarFile = Get-Content -Path $LastDownloadFile + Write-Host "Using last downloaded detect '$DetectJarFile'" + } else { + Write-Host "Unable to determine detect version and no downloaded detect found." + exit -1 + } + } + + + $DetectJarExists = Test-Path $DetectJarFile + Write-Host "Detect jar exists '$DetectJarExists'" + + if (!$DetectJarExists) { + Receive-DetectJar -DetectUrl $DetectSource -DetectJarFile $DetectJarFile -ProxyInfo $ProxyInfo -LastDownloadFile $LastDownloadFile + } + else { + Write-Host "You have already downloaded the latest file, so the local file will be used." + } + + return $DetectJarFile +} + +function Parse-Detect-File-Name($DetectSource) { + $SlashParts = $DetectSource.Split("/") + $LastPart = $SlashParts[$SlashParts.Length - 1] + return $LastPart +} + +function Invoke-Detect ($DetectJarFile, $DetectArgs) { + ${Env:detect.phone.home.passthrough.powershell.version} = $Version + $JavaArgs = @("-jar", $DetectJarFile) + $AllArgs = $JavaArgs + $DetectArgs + Set-ToEscaped($AllArgs) + Write-Host "Running Detect: $AllArgs" + $JavaCommand = Determine-Java($JavaHome, $DetectJavaPath) + $DetectProcess = Start-Process $JavaCommand -ArgumentList $AllArgs -NoNewWindow -PassThru + Wait-Process -InputObject $DetectProcess -ErrorAction SilentlyContinue + $DetectExitCode = $DetectProcess.ExitCode; + Write-Host "Result code of $DetectExitCode, exiting" + return $DetectExitCode +} + +function Determine-Java ($EnvJavaHome, $EnvDetectJavaPath) { + $JavaCommand = "java" + if ($DetectJavaPath -ne "") { + $JavaCommand = $DetectJavaPath + Write-Host "Java Source: DETECT_JAVA_PATH=$JavaCommand" + } elseif ($JavaHome -ne "") { + $JavaCommand = "$JavaHome/bin/java" + Write-Host "Java Source: JAVA_HOME/bin/java=$JavaCommand" + } else { + Write-Host "Java Source: PATH" + } + + return $JavaCommand +} + +function Initialize-DetectFolder ($DetectFolder, $TempFolder, $HomeTempFolder) { + if ($DetectFolder -ne "") { + Write-Host "Using supplied Detect folder: $DetectFolder" + return Initialize-Folder -Folder $DetectFolder + } + + if ($TempFolder -ne "") { + Write-Host "Using system temp folder: $TempFolder" + return Initialize-Folder -Folder $TempFolder + } + + return Initialize-Folder -Folder $HomeTempFolder +} + +function Initialize-Folder ($Folder) { + If (!(Test-Path $Folder)) { + Write-Host "Created folder: $Folder" + New-Item -ItemType Directory -Force -Path $Folder | Out-Null #Pipe to Out-Null to prevent dirtying to the function output + } + return $Folder +} + +function Receive-DetectSource ($ProxyInfo, $DetectVersionUrl, $DetectVersionKey) { + Write-Host "Finding latest Detect version." + $DetectVersionData = Invoke-WebRequestWrapper -Url $DetectVersionUrl -ProxyInfo $ProxyInfo + if (!$DetectVersionData){ + Write-Host "Failed to get detect version" + return $null + } + + $DetectVersionJson = ConvertFrom-Json -InputObject $DetectVersionData + + $Properties = $DetectVersionJson | select -ExpandProperty "properties" + $DetectVersionUrl = $Properties | select -ExpandProperty $DetectVersionKey + return $DetectVersionUrl +} + +function Receive-DetectJar ($DetectUrl, $DetectJarFile, $LastDownloadFile, $ProxyInfo) { + Write-Host "You don't have Detect. Downloading now." + Write-Host "Using url $DetectUrl" + $DetectJarTempFile = "$DetectJarFile.tmp" + $Request = Invoke-WebRequestWrapper -Url $DetectUrl -DownloadLocation $DetectJarTempFile -ProxyInfo $ProxyInfo + Rename-Item -Path $DetectJarTempFile -NewName $DetectJarFile + $DetectJarExists = Test-Path $DetectJarFile + Write-Host "Downloaded Detect jar successfully '$DetectJarExists'" + Set-Content -Value $DetectJarFile -Path $LastDownloadFile +} + +function Set-ToEscaped ($ArgArray) { + for ($i = 0; $i -lt $ArgArray.Count ; $i++) { + $Value = $ArgArray[$i] + $ArgArray[$i] = """$Value""" + } +} + +function Test-JavaNotAvailable() { + Write-Host "Checking if Java is installed by asking for version." + try { + $ProcessStartInfo = New-object System.Diagnostics.ProcessStartInfo + $ProcessStartInfo.CreateNoWindow = $true + $ProcessStartInfo.UseShellExecute = $false + $ProcessStartInfo.RedirectStandardOutput = $true + $ProcessStartInfo.RedirectStandardError = $true + $ProcessStartInfo.FileName = Determine-Java($JavaHome, $DetectJavaPath) + $ProcessStartInfo.Arguments = @("-version") + $Process = New-Object System.Diagnostics.Process + $Process.StartInfo = $ProcessStartInfo + [void]$Process.Start() + $StdOutput = $process.StandardOutput.ReadToEnd() + $StdError = $process.StandardError.ReadToEnd() + $Process.WaitForExit() + 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." + return $TRUE; + } +} diff --git a/detect10-3.2.0-SNAPSHOT.sh b/detect10-3.2.0-SNAPSHOT.sh new file mode 100755 index 0000000..284ae1c --- /dev/null +++ b/detect10-3.2.0-SNAPSHOT.sh @@ -0,0 +1,205 @@ +#!/bin/bash + +get_path_separator() { + # Performs a check to see if the system is Windows based. + if [[ `uname` == *"NT"* ]] || [[ `uname` == *"UWIN"* ]]; then + echo "\\" + else + echo "/" + fi +} + +# DETECT_LATEST_RELEASE_VERSION should be set in your +# environment if you wish to use a version different +# from LATEST. +DETECT_RELEASE_VERSION=${DETECT_LATEST_RELEASE_VERSION} + +# To override the default version key, specify a +# different DETECT_VERSION_KEY in your environment and +# *that* key will be used to get the download url from +# artifactory. These DETECT_VERSION_KEY values are +# properties in Artifactory that resolve to download +# urls for the detect jar file. As of 2024-10-04, the +# available DETECT_VERSION_KEY values are: +# DETECT_LATEST_10 +# Every new major version of detect will have its own +# DETECT_LATEST_X key. +DETECT_VERSION_KEY=${DETECT_VERSION_KEY:-DETECT_LATEST_10} + +# You can specify your own download url from +# artifactory which can bypass using the property keys +# (this is mainly for QA purposes only) +DETECT_SOURCE=${DETECT_SOURCE:-} + +# To override the default location of $HOME/detect, specify +# your own DETECT_JAR_DOWNLOAD_DIR in your environment and +# *that* location will be used. +# *NOTE* We currently do not support spaces in the +# DETECT_JAR_DOWNLOAD_DIR. +DEFAULT_DETECT_JAR_DOWNLOAD_DIR="${HOME}$(get_path_separator)detect$(get_path_separator)download" +if [[ -z "${DETECT_JAR_DOWNLOAD_DIR}" ]]; then + # If new name not set: Try old name for backward compatibility + DETECT_JAR_DOWNLOAD_DIR=${DETECT_JAR_PATH:-${DEFAULT_DETECT_JAR_DOWNLOAD_DIR}} +fi +DETECT_JAR_DOWNLOAD_DIR=${DETECT_JAR_DOWNLOAD_DIR:-${DEFAULT_DETECT_JAR_DOWNLOAD_DIR}} + +# To control which java detect will use to run, specify +# the path in in DETECT_JAVA_PATH or JAVA_HOME in your +# environment, or ensure that java is first on the path. +# DETECT_JAVA_PATH will take precedence over JAVA_HOME. +# JAVA_HOME will take precedence over the path. +# Note: DETECT_JAVA_PATH should point directly to the +# java executable. For JAVA_HOME the java executable is +# expected to be in JAVA_HOME/bin/java +DETECT_JAVA_PATH=${DETECT_JAVA_PATH:-} + +# If you want to pass any java options to the +# invocation, specify DETECT_JAVA_OPTS in your +# environment. For example, to specify a 6 gigabyte +# heap size, you would set DETECT_JAVA_OPTS=-Xmx6G. +DETECT_JAVA_OPTS=${DETECT_JAVA_OPTS:-} + +# If you want to pass any additional options to +# curl, specify DETECT_CURL_OPTS in your environment. +# For example, to specify a proxy, you would set +# DETECT_CURL_OPTS=--proxy http://myproxy:3128 +DETECT_CURL_OPTS=${DETECT_CURL_OPTS:-} + +# If you only want to download the appropriate jar file set +# this to 1 in your environment. This can be useful if you +# want to invoke the jar yourself but do not want to also +# get and update the jar file when a new version releases. +DETECT_DOWNLOAD_ONLY=${DETECT_DOWNLOAD_ONLY:-0} + +SCRIPT_ARGS="" +for NEXT_ARG in "$@" +do + SCRIPT_ARGS+="\"${NEXT_ARG}\" " +done + +LOGGABLE_SCRIPT_ARGS="" + +# This provides a way to get the script version (via, say, grep/sed). Do not change. +SCRIPT_VERSION=3.2.0-SNAPSHOT + +echo "Detect Shell Script ${SCRIPT_VERSION}" + +DETECT_BINARY_REPO_URL=https://repo.blackduck.com + +for i in $*; do + if [[ $i == --blackduck.hub.password=* ]]; then + LOGGABLE_SCRIPT_ARGS="$LOGGABLE_SCRIPT_ARGS --blackduck.hub.password=" + elif [[ $i == --blackduck.hub.proxy.password=* ]]; then + LOGGABLE_SCRIPT_ARGS="$LOGGABLE_SCRIPT_ARGS --blackduck.hub.proxy.password=" + elif [[ $i == --blackduck.hub.api.token=* ]]; then + LOGGABLE_SCRIPT_ARGS="$LOGGABLE_SCRIPT_ARGS --blackduck.hub.api.token=" + elif [[ $i == --blackduck.password=* ]]; then + LOGGABLE_SCRIPT_ARGS="$LOGGABLE_SCRIPT_ARGS --blackduck.password=" + elif [[ $i == --blackduck.proxy.password=* ]]; then + LOGGABLE_SCRIPT_ARGS="$LOGGABLE_SCRIPT_ARGS --blackduck.proxy.password=" + elif [[ $i == --blackduck.api.token=* ]]; then + LOGGABLE_SCRIPT_ARGS="$LOGGABLE_SCRIPT_ARGS --blackduck.api.token=" + elif [[ $i == --polaris.access.token=* ]]; then + LOGGABLE_SCRIPT_ARGS="$LOGGABLE_SCRIPT_ARGS --polaris.access.token=" + else + LOGGABLE_SCRIPT_ARGS="$LOGGABLE_SCRIPT_ARGS $i" + fi +done + +run() { + get_detect + if [[ ${DETECT_DOWNLOAD_ONLY} -eq 0 ]]; then + run_detect + fi +} + +get_detect() { + PATH_SEPARATOR=$(get_path_separator) + USE_LOCAL=0 + LOCAL_FILE="${DETECT_JAR_DOWNLOAD_DIR}${PATH_SEPARATOR}detect-last-downloaded-jar.txt" + if [[ -z "${DETECT_SOURCE}" ]]; then + if [[ -z "${DETECT_RELEASE_VERSION}" ]]; then + VERSION_CURL_CMD="curl ${DETECT_CURL_OPTS} --silent --header \"X-Result-Detail: info\" '${DETECT_BINARY_REPO_URL}/api/storage/bds-integrations-release/com/blackduck/integration/detect?properties=${DETECT_VERSION_KEY}'" + VERSION_EXTRACT_CMD="${VERSION_CURL_CMD} | grep \"${DETECT_VERSION_KEY}\" | sed 's/[^[]*[^\"]*\"\([^\"]*\).*/\1/'" + DETECT_SOURCE=$(eval ${VERSION_EXTRACT_CMD}) + if [[ -z "${DETECT_SOURCE}" ]]; then + echo "Unable to derive the location of ${DETECT_VERSION_KEY} from response to: ${VERSION_CURL_CMD}" + USE_LOCAL=1 + fi + else + DETECT_SOURCE="${DETECT_BINARY_REPO_URL}/bds-integrations-release/com/blackduck/integration/detect/${DETECT_RELEASE_VERSION}/detect-${DETECT_RELEASE_VERSION}.jar" + fi + fi + + if [[ USE_LOCAL -eq 0 ]]; then + echo "Will look for : ${DETECT_SOURCE}" + else + echo "Will look for : ${LOCAL_FILE}" + fi + + if [[ USE_LOCAL -eq 1 ]] && [[ -f "${LOCAL_FILE}" ]]; then + echo "Found local file ${LOCAL_FILE}" + DETECT_FILENAME=`cat ${LOCAL_FILE}` + elif [[ USE_LOCAL -eq 1 ]]; then + echo "${LOCAL_FILE} is missing and unable to communicate with a Detect source." + exit -1 + else + DETECT_FILENAME=${DETECT_FILENAME:-$(awk -F "/" '{print $NF}' <<< $DETECT_SOURCE)} + fi + DETECT_DESTINATION="${DETECT_JAR_DOWNLOAD_DIR}${PATH_SEPARATOR}${DETECT_FILENAME}" + + USE_REMOTE=1 + if [[ USE_LOCAL -ne 1 ]] && [[ ! -f "${DETECT_DESTINATION}" ]]; then + echo "You don't have the current file, so it will be downloaded." + else + echo "You have already downloaded the latest file, so the local file will be used." + USE_REMOTE=0 + fi + + if [ ${USE_REMOTE} -eq 1 ]; then + echo "getting ${DETECT_SOURCE} from remote" + TEMP_DETECT_DESTINATION="${DETECT_DESTINATION}-temp" + curlReturn=$(curl ${DETECT_CURL_OPTS} --silent -w "%{http_code}" -L -o "${TEMP_DETECT_DESTINATION}" --create-dirs "${DETECT_SOURCE}") + if [[ 200 -eq ${curlReturn} ]]; then + mv "${TEMP_DETECT_DESTINATION}" "${DETECT_DESTINATION}" + if [[ -f ${LOCAL_FILE} ]]; then + rm "${LOCAL_FILE}" + fi + echo "${DETECT_FILENAME}" >> "${LOCAL_FILE}" + echo "saved ${DETECT_SOURCE} to ${DETECT_DESTINATION}" + else + echo "The curl response was ${curlReturn}, which is not successful - please check your configuration and environment." + exit -1 + fi + fi +} + +set_detect_java_path() { + PATH_SEPARATOR=$(get_path_separator) + + if [[ -n "${DETECT_JAVA_PATH}" ]]; then + echo "Java Source: DETECT_JAVA_PATH=${DETECT_JAVA_PATH}" + elif [[ -n "${JAVA_HOME}" ]]; then + DETECT_JAVA_PATH="${JAVA_HOME}${PATH_SEPARATOR}bin${PATH_SEPARATOR}java" + echo "Java Source: JAVA_HOME${PATH_SEPARATOR}bin${PATH_SEPARATOR}java=${DETECT_JAVA_PATH}" + else + echo "Java Source: PATH" + DETECT_JAVA_PATH="java" + fi +} + +run_detect() { + set_detect_java_path + + JAVACMD="\"${DETECT_JAVA_PATH}\" ${DETECT_JAVA_OPTS} -jar \"${DETECT_DESTINATION}\"" + echo "running Detect: ${JAVACMD} ${LOGGABLE_SCRIPT_ARGS}" + + eval "${JAVACMD} ${SCRIPT_ARGS}" + RESULT=$? + echo "Result code of ${RESULT}, exiting" + exit ${RESULT} +} + +run +# pipeline test + diff --git a/latest-commit-id.txt b/latest-commit-id.txt index c08755a..7f20695 100644 --- a/latest-commit-id.txt +++ b/latest-commit-id.txt @@ -1 +1 @@ -51741071eb931a590a7b2afe1e2e8aa107229735 \ No newline at end of file +b80906bb5b2c7422ca92ba7d737ffc47dca2778e \ No newline at end of file