Skip to content

Commit

Permalink
[ADDED] Support to find gradle.kts files [#161629958]
Browse files Browse the repository at this point in the history
Signed-off-by: Shane Lattanzio <slattanzio@pivotal.io>
  • Loading branch information
xtreme-lisheng-tai authored and xtreme-shane-lattanzio committed Nov 8, 2018
1 parent bf2829b commit f7cb587
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 14 deletions.
36 changes: 23 additions & 13 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,42 @@ Bundler::GemHelper.install_tasks
require './lib/license_finder/platform'
require 'rspec/core/rake_task'

desc 'Run all specs in spec/'
task :spec do
RSpec::Core::RakeTask.new(:spec) do |t|
namespace :spec do
desc 'Run test tagged \'focus\''
RSpec::Core::RakeTask.new(:focus) do |t|
t.fail_on_error = true
t.pattern = './spec/**/*_spec.rb'
t.rspec_opts = %w[--color]
t.rspec_opts = %w[--color --tag focus]
end
end

desc 'Only run cocoapods specs'
RSpec::Core::RakeTask.new('spec:cocoapods') do |t|
desc 'Run all specs in spec/'
RSpec::Core::RakeTask.new(:spec) do |t|
t.fail_on_error = true
t.pattern = './spec/lib/license_finder/package_managers/cocoa_pods_*spec.rb'
t.pattern = './spec/**/*_spec.rb'
t.rspec_opts = %w[--color]
end

desc 'Run all specs in features/'
task :features do
RSpec::Core::RakeTask.new(:features) do |t|
namespace :features do
desc 'Run test tagged \'focus\''
RSpec::Core::RakeTask.new(:focus) do |t|
t.fail_on_error = true
t.pattern = './features/**/*_spec.rb'
opts = %w[--color --format d]
opts = %w[--color --format d --tag focus]
opts += LicenseFinder::Platform.darwin? ? [] : %w[--tag ~ios]
t.rspec_opts = opts
end
end

desc 'Run all specs in features/'
RSpec::Core::RakeTask.new(:features) do |t|
t.fail_on_error = true
t.pattern = './features/**/*_spec.rb'
opts = %w[--color --format d]
opts += LicenseFinder::Platform.darwin? ? [] : %w[--tag ~ios]
t.rspec_opts = opts
end

desc 'Check for non-Ruby development dependencies.'
task :check_dependencies do
require './lib/license_finder'
Expand Down Expand Up @@ -77,7 +86,8 @@ task :update_release_pipeline do
system(cmd)
end

task default: %i[spec features]
task spec: :check_dependencies
task features: :check_dependencies

task default: %i[spec features]
task 'spec:focus': :check_dependencies
task 'features:focus': :check_dependencies
6 changes: 6 additions & 0 deletions features/features/package_managers/gradle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@
java_developer.run_license_finder('alternate-build-file-gradle')
expect(java_developer).to be_seeing_line 'junit, 4.11, "Common Public License Version 1.0"'
end

specify 'are shown in reports for a project with an kotlin build.gradle.kts file' do
LicenseFinder::TestingDSL::KtsBuildFileGradleProject.create
java_developer.run_license_finder('kts-build-file-gradle')
expect(java_developer).to be_seeing_line 'kotlin-stdlib, 1.2.61, "Apache 2.0"'
end
end
27 changes: 27 additions & 0 deletions features/fixtures/kts-build-file-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
gradle.startParameter.excludedTaskNames += "licenseMain"
gradle.startParameter.excludedTaskNames += "licenseTest"

plugins {
application
kotlin("jvm") version "1.2.61"
id ("com.github.hierynomus.license") version "0.14.0"
}

application {
mainClassName = "hello.HelloWorldKt"
}

dependencies {
compile(kotlin("stdlib"))
testCompile ("junit:junit:4.11")
compile("org.springframework:spring-jdbc:5.0.7.RELEASE")
compile("org.postgresql:postgresql:42.2.2")
}

repositories {
jcenter()
}

tasks.withType<Wrapper> {
gradleVersion = "4.10.2"
}
6 changes: 6 additions & 0 deletions features/support/testing_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ def add_dep
end
end

class KtsBuildFileGradleProject < Project
def add_dep
clone('kts-build-file-gradle')
end
end

class GoProject < Project
def add_dep
clone('gopath')
Expand Down
7 changes: 7 additions & 0 deletions lib/license_finder/package_managers/gradle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ def detected_package_path
alternate_build_file = build_file_from_settings(project_path)
return alternate_build_file if alternate_build_file

build_gradle_file
end

def build_gradle_file
kotlin_gradle_path = project_path.join('build.gradle.kts')
return kotlin_gradle_path if File.exist? kotlin_gradle_path

project_path.join('build.gradle')
end

Expand Down
13 changes: 12 additions & 1 deletion spec/lib/license_finder/package_managers/gradle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,23 @@ module LicenseFinder
end
end

context "when there's no build.gradle" do
context "when there's no build.gradle or build.gradle.kts" do
it 'returns false' do
expect(subject.active?).to be false
end
end

context "when there's build.gradle.kts" do
it 'return true' do
FakeFS do
FileUtils.mkdir_p '/fake/path'
FileUtils.touch '/fake/path/build.gradle.kts'

expect(subject.active?).to be true
end
end
end

context "when there's a settings.gradle" do
it 'uses the build.gradle referenced inside' do
SETTINGS_DOT_GRADLE = <<-GRADLE
Expand Down

0 comments on commit f7cb587

Please sign in to comment.