diff options
Diffstat (limited to 'spec/integration/java')
| -rw-r--r-- | spec/integration/java/gradle_spec.rb | 77 | ||||
| -rw-r--r-- | spec/integration/java/maven_spec.rb | 81 |
2 files changed, 158 insertions, 0 deletions
diff --git a/spec/integration/java/gradle_spec.rb b/spec/integration/java/gradle_spec.rb new file mode 100644 index 0000000..1b566bb --- /dev/null +++ b/spec/integration/java/gradle_spec.rb @@ -0,0 +1,77 @@ +require 'spec_helper' + +RSpec.describe "gradle" do + include_examples "each report version", "java", "gradle" + + context "when running a default gradle build" do + it 'scans a gradle project' do + content = <<~GRADLE +/* + * This file was generated by the Gradle 'init' task. + * + * This is a general purpose Gradle build. + * Learn how to create Gradle builds at https://guides.gradle.org/creating-new-gradle-builds + */ +plugins { + id "com.github.hierynomus.license" version "0.15.0" +} + GRADLE + runner.add_file('build.gradle', content) + + report = runner.scan + expect(report).to match_schema(version: '2.0') + expect(report[:licenses]).to be_empty + expect(report[:dependencies]).to be_empty + end + end + + context 'when scanning a gradle project that does not include the `com.github.hierynomus.license` plugin' do + let(:project_url) { 'https://gitlab.com/one-touch-pipeline/otp.git' } + let(:result) { runner.scan } + + before do + runner.clone(project_url) + end + + it 'is able to detect licenses' do + expect(result).to match_schema(version: '2.0') + expect(result[:licenses]).not_to be_empty + + [ + { name: 'ant', licenses: ['Apache-2.0'] }, + { name: 'activation', licenses: ['CDDL-1.0'] }, + { name: 'xml-apis', licenses: ['Apache-2.0', 'SAX-PD', 'W3C-20150513'] }, + { name: 'sitemesh', licenses: ['Apache-1.1'] }, + { name: 'hibernate-jpa-2.1-api', licenses: ['BSD-3-Clause', 'EPL-1.0'] } + ].each do |dependency| + expect(result.licenses_for(dependency[:name])).to match_array(dependency[:licenses]) + end + end + end + + [ + '6.2', + '5.6', + '4.9', + '3.5', + '2.9', + '1.9' + ].each do |gradle_version| + %w[8 11].each do |java_version| + context "when scanning a gradle (v#{gradle_version}) project that uses a kotlin build script" do + let(:build_file_content) { fixture_file_content("java/build.gradle.kts") } + + it 'scans a gradle project' do + runner.add_file('build.gradle.kts', build_file_content) + runner.add_file('settings.gradle.kts', 'rootProject.name = "example"') + runner.add_file('.tool-versions', "gradle #{gradle_version}") + + report = runner.scan(env: { 'LM_JAVA_VERSION' => java_version }) + expect(report).to match_schema(version: '2.0') + expect(report[:licenses]).to be_empty + expect(report[:dependencies]).to be_empty + end + end + end + end +end diff --git a/spec/integration/java/maven_spec.rb b/spec/integration/java/maven_spec.rb new file mode 100644 index 0000000..92444e8 --- /dev/null +++ b/spec/integration/java/maven_spec.rb @@ -0,0 +1,81 @@ +require 'spec_helper' + +RSpec.describe "maven" do + include_examples "each report version", "java", "maven" + include_examples "each report version", "java", "maven-multimodules" + + describe "When the maven dependencies come from a custom public maven repository" do + it 'is able to detect some of the licenses' do + runner.add_file('pom.xml', fixture_file_content('java/pom-public-gitlab-repository.xml')) + + report = runner.scan(env: { + 'CI_PROJECT_ID' => '17523603' + }) + + expect(report).to match_schema(version: '2.0') + expect(report[:dependencies]).to match_array([{ name: 'mvn-spike', url: '', description: '', paths: ['.'], licenses: ['MIT'] }]) + end + + it 'downloads packages from by using a custom `settings.xml`' do + runner.add_file('pom.xml', fixture_file_content('java/pom-public-gitlab-repository.xml')) + runner.add_file('my_settings.xml', fixture_file_content('java/custom-maven-settings.xml')) + + report = runner.scan(env: { + 'CI_PROJECT_ID' => 'invalid', + 'MAVEN_CLI_OPTS' => "--settings my_settings.xml" + }) + + expect(report).to match_schema(version: '2.0') + expect(report[:dependencies]).to match_array([{ name: 'mvn-spike', url: '', description: '', paths: ['.'], licenses: ['MIT'] }]) + end + end + + describe "When using the `SETUP_CMD`" do + it 'executes the custom script' do + runner.add_file('custom.sh') do + <<~SCRIPT + #!/bin/bash -l + + echo 'hello' + SCRIPT + end + + report = runner.scan(env: { + 'SETUP_CMD' => 'bash custom.sh' + }) + + expect(report).to match_schema(version: '2.0') + end + end + + describe "When scanning a project with multiple modules" do + before do + runner.mount(dir: fixture_file('java/maven-multimodule')) + end + + it 'detects dependences from each module' do + report = runner.scan + + expect(report).to match_schema(version: '2.0') + expect(report[:dependencies]).not_to be_empty + + [ + { name: "asm", licenses: ["BSD-4-Clause"] }, + { name: "asm-commons", licenses: ["BSD-4-Clause"] }, + { name: "jackson-annotations", licenses: ["Apache-2.0"] }, + { name: "jackson-core", licenses: ["Apache-2.0"] }, + { name: "jackson-databind", licenses: ["Apache-2.0"] }, + { name: "jackson-dataformat-xml", licenses: ["Apache-2.0"] }, + { name: "jackson-module-jaxb-annotations", licenses: ["Apache-2.0"] }, + { name: "log4j-api", licenses: ["Apache-2.0"] }, + { name: "log4j-core", licenses: ["Apache-2.0"] }, + { name: "netty-all", licenses: ["Apache-2.0"] }, + { name: "stax2-api", licenses: ["BSD-4-Clause"] } + ].each do |dependency| + expect(report.licenses_for(dependency[:name])).to match_array(dependency[:licenses]) + end + + expect(report.dependency_names).not_to include('junit') + end + end +end |
