summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/license/finder/ext/maven.rb6
-rwxr-xr-xrun.sh12
-rw-r--r--spec/integration/java/maven_spec.rb42
-rw-r--r--spec/support/integration_test_helper.rb4
4 files changed, 59 insertions, 5 deletions
diff --git a/lib/license/finder/ext/maven.rb b/lib/license/finder/ext/maven.rb
index d6a08dc..1a3dea8 100644
--- a/lib/license/finder/ext/maven.rb
+++ b/lib/license/finder/ext/maven.rb
@@ -12,7 +12,9 @@ module LicenseFinder
def current_packages
Dir.chdir(project_path) do
- LicenseFinder::SharedHelpers::Cmd.run(detect_licenses_command)
+ _stdout, _stderr, status = shell.execute(detect_licenses_command)
+ return [] unless status.success?
+
resource_files.flat_map { |file| map_from(file.read) }.uniq
end
end
@@ -27,7 +29,7 @@ module LicenseFinder
"-Dlicense.excludedScopes=#{@ignored_groups.to_a.join(',')}",
"-Dorg.slf4j.simpleLogger.log.org.codehaus.mojo.license=debug",
ENV.fetch('MAVEN_CLI_OPTS', '-DskipTests')
- ].join(' ')
+ ]
end
def resource_files
diff --git a/run.sh b/run.sh
index 776ae98..c394872 100755
--- a/run.sh
+++ b/run.sh
@@ -4,6 +4,7 @@ set -e
[[ -z ${SETUP_CMD:-} ]] && set -uo pipefail
BUNDLE_JOBS="$(nproc)"
+export ASDF_JAVA_VERSION="${ASDF_JAVA_VERSION:-}"
export BUNDLE_JOBS
export BUNDLE_WITHOUT="development:test"
export CI_API_V4_URL="${CI_API_V4_URL:-https://gitlab.com/api/v4}"
@@ -15,6 +16,7 @@ export HISTFILESIZE=0
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_REPORT_FILE=${LM_REPORT_FILE:-'gl-license-management-report.json'}
export MAVEN_CLI_OPTS="${MAVEN_CLI_OPTS:--DskipTests}"
export NO_UPDATE_NOTIFIER=true
@@ -80,8 +82,16 @@ function prepare_project() {
fi
}
+if [ -n "$LM_JAVA_VERSION" ]; then
+ switch_to java "adopt-openjdk-${LM_JAVA_VERSION}"
+elif [ -n "$ASDF_JAVA_VERSION" ]; then
+ asdf shell java "$ASDF_JAVA_VERSION"
+ update_java_home
+else
+ switch_to java "adopt-openjdk-8"
+fi
+
switch_to python "$(major_version_from "${LM_PYTHON_VERSION:-3}")"
-switch_to java "adopt-openjdk-${LM_JAVA_VERSION:-8}"
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 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
diff --git a/spec/support/integration_test_helper.rb b/spec/support/integration_test_helper.rb
index aa3f0c0..e84ddd0 100644
--- a/spec/support/integration_test_helper.rb
+++ b/spec/support/integration_test_helper.rb
@@ -42,7 +42,7 @@ module IntegrationTestHelper
def initialize(project_path = File.join(Dir.pwd, 'tmp', SecureRandom.uuid))
FileUtils.mkdir_p(project_path)
- @project_path = project_path
+ @project_path = Pathname(project_path)
end
def add_file(name, content = nil)
@@ -67,7 +67,7 @@ module IntegrationTestHelper
end
def scan(env: {})
- return {} unless execute(env, './bin/docker-test', project_path)
+ return {} unless execute(env, './bin/docker-test', project_path.to_s)
report_path = "#{project_path}/gl-license-management-report.json"
return {} unless File.exist?(report_path)