From 812d23695017ae34f196d19742821f20167c3704 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 5 Jun 2020 14:03:06 -0600 Subject: Launch the desired Java version --- spec/integration/java/maven_spec.rb | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'spec/integration/java') diff --git a/spec/integration/java/maven_spec.rb b/spec/integration/java/maven_spec.rb index 85637b2..1e0e4e4 100644 --- a/spec/integration/java/maven_spec.rb +++ b/spec/integration/java/maven_spec.rb @@ -100,4 +100,46 @@ RSpec.describe "maven" do specify { expect(report.dependency_names).to match_array(['jackson-core']) } specify { expect(report.licenses_for('jackson-core')).to match_array(['Apache-2.0']) } end + + context "when specifying the version of java using environment variables" do + let(:output_file) { Pathname.new(runner.project_path.join('output.txt')) } + + before do + runner.add_file('custom.sh') do + <<~SCRIPT + #!/bin/bash -l + + java -version 2> '#{output_file}' + SCRIPT + end + end + + it 'prioritizes `LM_JAVA_VERSION` over the `ASDF_JAVA_VERSION`' do + runner.scan(env: { + 'ASDF_JAVA_VERSION' => 'adopt-openjdk-11.0.7+10', + 'LM_JAVA_VERSION' => '8', + 'SETUP_CMD' => 'bash custom.sh' + }) + + expect(output_file).to exist + expect(output_file.read).to include('openjdk version "1.8.0_242"') + end + + it 'reads the ASDF_JAVA_VERSION' do + runner.scan(env: { + 'ASDF_JAVA_VERSION' => 'adopt-openjdk-11.0.7+10', + 'SETUP_CMD' => 'bash custom.sh' + }) + + expect(output_file).to exist + expect(output_file.read).to include('openjdk version "11.0.7"') + end + + it 'defaults to java 8' do + runner.scan(env: { 'SETUP_CMD' => 'bash custom.sh' }) + + expect(output_file).to exist + expect(output_file.read).to include('openjdk version "1.8.0_242"') + end + end end -- cgit v1.2.3 From 5d7201bf7830f16174adda1cd145e6804d7056b4 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 5 Jun 2020 14:54:33 -0600 Subject: Allow configuring Python version using environment variables --- run.sh | 10 ++++++++- spec/integration/java/maven_spec.rb | 2 +- spec/integration/python/pip_spec.rb | 42 +++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) (limited to 'spec/integration/java') diff --git a/run.sh b/run.sh index c394872..023ae8a 100755 --- a/run.sh +++ b/run.sh @@ -5,6 +5,7 @@ set -e BUNDLE_JOBS="$(nproc)" export ASDF_JAVA_VERSION="${ASDF_JAVA_VERSION:-}" +export ASDF_PYTHON_VERSION="${ASDF_PYTHON_VERSION:-}" export BUNDLE_JOBS export BUNDLE_WITHOUT="development:test" export CI_API_V4_URL="${CI_API_V4_URL:-https://gitlab.com/api/v4}" @@ -17,6 +18,7 @@ export HISTSIZE=0 export LANG=C.UTF-8 export LICENSE_FINDER_CLI_OPTS=${LICENSE_FINDER_CLI_OPTS:=--no-debug} export LM_JAVA_VERSION=${LM_JAVA_VERSION:-} +export LM_PYTHON_VERSION=${LM_PYTHON_VERSION:-} export LM_REPORT_FILE=${LM_REPORT_FILE:-'gl-license-management-report.json'} export MAVEN_CLI_OPTS="${MAVEN_CLI_OPTS:--DskipTests}" export NO_UPDATE_NOTIFIER=true @@ -91,7 +93,13 @@ else switch_to java "adopt-openjdk-8" fi -switch_to python "$(major_version_from "${LM_PYTHON_VERSION:-3}")" +if [ -n "$LM_PYTHON_VERSION" ]; then + switch_to python "$(major_version_from "$LM_PYTHON_VERSION")" +elif [ -n "$ASDF_PYTHON_VERSION" ]; then + asdf shell python "$ASDF_PYTHON_VERSION" +else + switch_to python "3" +fi prepare_project [[ $CI_DEBUG_TRACE == 'true' ]] && debug_env diff --git a/spec/integration/java/maven_spec.rb b/spec/integration/java/maven_spec.rb index 1e0e4e4..9230a9f 100644 --- a/spec/integration/java/maven_spec.rb +++ b/spec/integration/java/maven_spec.rb @@ -109,7 +109,7 @@ RSpec.describe "maven" do <<~SCRIPT #!/bin/bash -l - java -version 2> '#{output_file}' + java -version &> '#{output_file}' SCRIPT end end diff --git a/spec/integration/python/pip_spec.rb b/spec/integration/python/pip_spec.rb index 0ba3d0e..e808188 100644 --- a/spec/integration/python/pip_spec.rb +++ b/spec/integration/python/pip_spec.rb @@ -157,4 +157,46 @@ setup( expect(report.licenses_for('requests')).to match_array(['Apache-2.0']) end end + + context "when specifying the version of Python using environment variables" do + let(:output_file) { Pathname.new(runner.project_path.join('output.txt')) } + + before do + runner.add_file('custom.sh') do + <<~SCRIPT + #!/bin/bash -l + + python --version &> '#{output_file}' + SCRIPT + end + end + + it 'prioritizes `LM_PYTHON_VERSION` over the `ASDF_PYTHON_VERSION`' do + runner.scan(env: { + 'ASDF_PYTHON_VERSION' => '3.8.2', + 'LM_PYTHON_VERSION' => '2.7.18', + 'SETUP_CMD' => 'bash custom.sh' + }) + + expect(output_file).to exist + expect(output_file.read).to include('2.7.18') + end + + it 'reads the ASDF_PYTHON_VERSION' do + runner.scan(env: { + 'ASDF_PYTHON_VERSION' => '3.8.2', + 'SETUP_CMD' => 'bash custom.sh' + }) + + expect(output_file).to exist + expect(output_file.read).to include('3.8.2') + end + + it 'defaults to Python 3' do + runner.scan(env: { 'SETUP_CMD' => 'bash custom.sh' }) + + expect(output_file).to exist + expect(output_file.read).to include('3.8.2') + end + end end -- cgit v1.2.3