license_finder 0.9.5.1-java → 1.0.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +9 -0
  4. data/CHANGELOG.rdoc +9 -0
  5. data/MIT.LICENSE +20 -0
  6. data/db/migrate/201401302113_re_reassociate_license.rb +23 -0
  7. data/features/gradle_dependencies.feature +9 -0
  8. data/features/maven_dependencies.feature +9 -0
  9. data/features/step_definitions/gradle_steps.rb +8 -0
  10. data/features/step_definitions/maven_steps.rb +8 -0
  11. data/features/step_definitions/node_steps.rb +1 -1
  12. data/features/step_definitions/set_license_steps.rb +0 -1
  13. data/features/step_definitions/shared_steps.rb +26 -13
  14. data/lib/license_finder.rb +6 -1
  15. data/lib/license_finder/cli.rb +13 -9
  16. data/lib/license_finder/configuration.rb +113 -72
  17. data/lib/license_finder/dependency_manager.rb +12 -7
  18. data/lib/license_finder/license.rb +39 -65
  19. data/lib/license_finder/license/any_matcher.rb +13 -0
  20. data/lib/license_finder/license/definitions.rb +106 -0
  21. data/lib/license_finder/license/header_matcher.rb +10 -0
  22. data/lib/license_finder/license/matcher.rb +17 -0
  23. data/lib/license_finder/license/template.rb +16 -0
  24. data/lib/license_finder/license/text.rb +19 -0
  25. data/lib/license_finder/license_url.rb +1 -4
  26. data/lib/license_finder/package.rb +18 -2
  27. data/lib/license_finder/package_managers/bower_package.rb +3 -17
  28. data/lib/license_finder/package_managers/bundler_package.rb +2 -2
  29. data/lib/license_finder/package_managers/gradle.rb +29 -0
  30. data/lib/license_finder/package_managers/gradle_package.rb +41 -0
  31. data/lib/license_finder/package_managers/maven.rb +31 -0
  32. data/lib/license_finder/package_managers/maven_package.rb +46 -0
  33. data/lib/license_finder/package_managers/npm_package.rb +2 -16
  34. data/lib/license_finder/package_managers/pip_package.rb +7 -7
  35. data/lib/license_finder/package_saver.rb +1 -1
  36. data/lib/license_finder/possible_license_file.rb +1 -5
  37. data/lib/license_finder/possible_license_files.rb +4 -2
  38. data/lib/license_finder/reports/dependency_report.rb +5 -1
  39. data/lib/license_finder/reports/detailed_text_report.rb +0 -1
  40. data/lib/license_finder/reports/formatted_report.rb +21 -0
  41. data/lib/license_finder/reports/html_report.rb +1 -21
  42. data/lib/license_finder/reports/markdown_report.rb +1 -21
  43. data/lib/license_finder/reports/reporter.rb +8 -7
  44. data/lib/license_finder/reports/text_report.rb +0 -2
  45. data/lib/license_finder/tables.rb +1 -1
  46. data/lib/license_finder/tables/dependency.rb +12 -12
  47. data/lib/license_finder/yml_to_sql.rb +4 -4
  48. data/license_finder.gemspec +3 -2
  49. data/readme.md +10 -1
  50. data/release/publish.sh +10 -7
  51. data/spec/fixtures/build.gradle +24 -0
  52. data/spec/fixtures/pom.xml +19 -0
  53. data/spec/lib/license_finder/cli_spec.rb +13 -3
  54. data/spec/lib/license_finder/configuration_spec.rb +121 -74
  55. data/spec/lib/license_finder/dependency_manager_spec.rb +34 -16
  56. data/spec/lib/license_finder/license/{new_bsd_spec.rb → definitions_spec.rb} +93 -7
  57. data/spec/lib/license_finder/license_spec.rb +72 -26
  58. data/spec/lib/license_finder/license_url_spec.rb +10 -14
  59. data/spec/lib/license_finder/package_managers/bower_package_spec.rb +17 -5
  60. data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +2 -2
  61. data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +66 -0
  62. data/spec/lib/license_finder/package_managers/gradle_spec.rb +89 -0
  63. data/spec/lib/license_finder/package_managers/maven_package_spec.rb +72 -0
  64. data/spec/lib/license_finder/package_managers/maven_spec.rb +115 -0
  65. data/spec/lib/license_finder/package_managers/npm_package_spec.rb +17 -3
  66. data/spec/lib/license_finder/package_managers/pip_package_spec.rb +27 -5
  67. data/spec/lib/license_finder/possible_license_file_spec.rb +2 -2
  68. data/spec/lib/license_finder/{detailed_text_report_spec.rb → reports/detailed_text_report_spec.rb} +0 -0
  69. data/spec/lib/license_finder/{html_report_spec.rb → reports/html_report_spec.rb} +0 -0
  70. data/spec/lib/license_finder/{markdown_report_spec.rb → reports/markdown_report_spec.rb} +0 -0
  71. data/spec/lib/license_finder/reports/reporter_spec.rb +33 -0
  72. data/spec/lib/license_finder/{text_report_spec.rb → reports/text_report_spec.rb} +0 -0
  73. data/spec/lib/license_finder/tables/dependency_spec.rb +1 -2
  74. data/spec/lib/license_finder/tables/license_alias_spec.rb +1 -2
  75. data/spec/lib/license_finder/yml_to_sql_spec.rb +10 -11
  76. data/spec/lib/license_finder_spec.rb +5 -71
  77. metadata +64 -53
  78. data/features/rails_rake.feature +0 -9
  79. data/features/step_definitions/rails_rake_steps.rb +0 -12
  80. data/lib/license_finder/license/apache2.rb +0 -8
  81. data/lib/license_finder/license/bsd.rb +0 -4
  82. data/lib/license_finder/license/gplv2.rb +0 -4
  83. data/lib/license_finder/license/isc.rb +0 -3
  84. data/lib/license_finder/license/lgpl.rb +0 -4
  85. data/lib/license_finder/license/mit.rb +0 -23
  86. data/lib/license_finder/license/new_bsd.rb +0 -27
  87. data/lib/license_finder/license/python.rb +0 -8
  88. data/lib/license_finder/license/ruby.rb +0 -11
  89. data/lib/license_finder/license/simplified_bsd.rb +0 -8
  90. data/lib/license_finder/railtie.rb +0 -7
  91. data/lib/tasks/license_finder.rake +0 -7
  92. data/spec/lib/license_finder/license/apache_spec.rb +0 -7
  93. data/spec/lib/license_finder/license/bsd_spec.rb +0 -41
  94. data/spec/lib/license_finder/license/gplv2_spec.rb +0 -7
  95. data/spec/lib/license_finder/license/isc_spec.rb +0 -7
  96. data/spec/lib/license_finder/license/lgpl_spec.rb +0 -7
  97. data/spec/lib/license_finder/license/mit_spec.rb +0 -33
  98. data/spec/lib/license_finder/license/python_spec.rb +0 -7
  99. data/spec/lib/license_finder/license/ruby_spec.rb +0 -19
  100. data/spec/lib/license_finder/license/simplified_bsd_spec.rb +0 -7
  101. data/spec/lib/license_finder/reporter_spec.rb +0 -46
  102. data/spec/support/license_examples.rb +0 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89fb12de764cafe5769301d178e23bc7cedc0f80
4
- data.tar.gz: 3f8ec0ff77cb5de65600417a36a7de3fbcd54d68
3
+ metadata.gz: 2bfbd9c59602704b7c3a40d8ecd9e31e52891a59
4
+ data.tar.gz: 3f06d5b52cdb43ddf1d8e1f7e0181a6dc1812d37
5
5
  SHA512:
6
- metadata.gz: afa69cd67d0052b1b4106430becba1cb62f2b0dba455ebabaf3da89184fa868c5612b1593c9d241a7865c9c73cb38efb15042cecf4ca42ac24fcab17c8b37817
7
- data.tar.gz: cfef9c50d427fb2c2515469e789ee3cfe3349e9c4fa4f8c94d54225b1058854242f08e0002b170aaee707970ad8ef07ce3493876419dc8d036a979107c769b5c
6
+ metadata.gz: ea159ba85c83ae2758bf0ccf26345f596c42f814d5b37e2e67d8fca3d51dd9bd72837bdc4d402092f8f47200c788deb9876166ac921ebad802a9aa78e53f6a6e
7
+ data.tar.gz: bf0c2f24a983fc2318bacdf4c89dbbbbaff3ad3a656e7fe5fe419895e0d740743b1298903ce423d6bea16c2573d02feecc710b32ee8a1de8a32702c65fdffe60
data/.gitignore CHANGED
@@ -2,5 +2,6 @@ pkg/*
2
2
  Gemfile.lock
3
3
  .rvmrc
4
4
  .idea/*
5
+ .gradle/
5
6
  tmp/
6
7
  .pairs
@@ -12,6 +12,8 @@ matrix:
12
12
  - rvm: ruby-head
13
13
  - rvm: jruby-head
14
14
 
15
+ env: JAVA_OPTS='-client -XX:+TieredCompilation -XX:TieredStopAtLevel=1' JRUBY_OPTS='-J-Djruby.launch.inproc=true'
16
+
15
17
  notifications:
16
18
  email:
17
19
  - licensefinder@pivotallabs.com
@@ -19,3 +21,10 @@ notifications:
19
21
  urls:
20
22
  - http://pulse.pivotallabs.com/projects/657d35b7-b896-4bf3-8837-9d558e2ab651/status
21
23
  on_start: true
24
+
25
+ before_install:
26
+ - sudo apt-get update
27
+
28
+ install:
29
+ - sudo apt-get install gradle -qq -y
30
+ - bundle install
@@ -1,3 +1,12 @@
1
+ === 1.0.0 / Unreleased
2
+
3
+ * Features
4
+
5
+ * When approving a license, can specify who is approving, and why.
6
+ * Remove `rake license_finder` task from Rails projects. Just include
7
+ 'license_finder' as a development dependency, and run `license_finder` in
8
+ the shell.
9
+
1
10
  === 0.9.5.1 / 2014-01-30
2
11
 
3
12
  * Features
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008-2014 Pivotal Labs
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ Sequel.migration do
2
+ up do
3
+ LicenseFinder::DB << <<-SQL
4
+ UPDATE dependencies
5
+ SET license_id =
6
+ (SELECT min(la.id)
7
+ FROM
8
+ license_aliases la,
9
+ license_aliases la_orig
10
+ WHERE
11
+ la.name = la_orig.name AND
12
+ la_orig.id = license_id
13
+ LIMIT 1)
14
+ SQL
15
+
16
+ LicenseFinder::DB << <<-SQL
17
+ DELETE
18
+ FROM license_aliases
19
+ WHERE
20
+ id NOT IN (SELECT license_id FROM dependencies)
21
+ SQL
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ Feature: Tracking Gradle Dependencies
2
+ So that I can track Gradle dependencies
3
+ As an application developer using license finder
4
+ I want to be able to manage Gradle dependencies
5
+
6
+ Scenario: See the dependencies from the build.gradle file
7
+ Given A build.gradle file with dependencies
8
+ When I run license_finder
9
+ Then I should see a Gradle dependency with a license
@@ -0,0 +1,9 @@
1
+ Feature: Tracking Maven Dependencies
2
+ So that I can track Maven dependencies
3
+ As an application developer using license finder
4
+ I want to be able to manage Maven dependencies
5
+
6
+ Scenario: See the dependencies from the pom file
7
+ Given A pom file with dependencies
8
+ When I run license_finder
9
+ Then I should see a Maven dependency with a license
@@ -0,0 +1,8 @@
1
+ Given(/^A build.gradle file with dependencies$/) do
2
+ @user = ::DSL::User.new
3
+ @user.create_gradle_app
4
+ end
5
+
6
+ Then(/^I should see a Gradle dependency with a license$/) do
7
+ @output.should =~ /^junit, 4.11, Common Public License Version 1.0$/
8
+ end
@@ -0,0 +1,8 @@
1
+ Given(/^A pom file with dependencies$/) do
2
+ @user = ::DSL::User.new
3
+ @user.create_maven_app
4
+ end
5
+
6
+ Then(/^I should see a Maven dependency with a license$/) do
7
+ @output.should =~ /^junit, 4.11, Common Public License Version 1.0$/
8
+ end
@@ -4,5 +4,5 @@ Given(/^A package file with dependencies$/) do
4
4
  end
5
5
 
6
6
  Then(/^I should see a Node dependency with a license$/) do
7
- @output.should =~ /^jshint, 2.1.9, MIT$/
7
+ @output.should =~ /^http-server, 0.6.1, MIT$/
8
8
  end
@@ -1,7 +1,6 @@
1
1
  Given(/^I have an app with license finder that depends on an other licensed gem$/) do
2
2
  @user = ::DSL::User.new
3
3
  @user.create_nonrails_app
4
- @user.add_license_finder_to_rakefile
5
4
  @user.add_dependency_to_app 'other_gem', version: '1.0', license: 'other'
6
5
  @user.add_dependency_to_app 'control_gem', version: '1.0', license: 'other'
7
6
  end
@@ -47,17 +47,37 @@ module DSL
47
47
  `mkdir -p #{app_path}`
48
48
  `cd #{app_path} && touch package.json`
49
49
 
50
- add_npm_dependency('jshint', '2.1.9')
50
+ add_npm_dependency('http-server', '0.6.1')
51
51
 
52
52
  npm_install
53
53
  end
54
54
 
55
+ def create_maven_app
56
+ reset_projects!
57
+
58
+ path = File.expand_path("spec/fixtures/pom.xml")
59
+
60
+ `mkdir -p #{app_path}`
61
+ `cd #{app_path} && cp #{path} .`
62
+
63
+ mvn_install
64
+ end
65
+
66
+ def create_gradle_app
67
+ reset_projects!
68
+
69
+ path = File.expand_path("spec/fixtures/build.gradle")
70
+
71
+ `mkdir -p #{app_path}`
72
+ `cd #{app_path} && cp #{path} .`
73
+ `gradle dependencies`
74
+ end
75
+
55
76
  def create_nonrails_app
56
77
  reset_projects!
57
78
 
58
79
  `cd #{projects_path} && bundle gem #{app_name}`
59
80
 
60
- add_gem_dependency('rake')
61
81
  add_gem_dependency('license_finder', :path => root_path)
62
82
 
63
83
  bundle_app
@@ -73,13 +93,6 @@ module DSL
73
93
  bundle_app
74
94
  end
75
95
 
76
- def add_license_finder_to_rakefile
77
- add_to_rakefile <<-RUBY
78
- require 'bundler/setup'
79
- require 'license_finder'
80
- RUBY
81
- end
82
-
83
96
  def update_gem(name, attrs)
84
97
  file_contents = YAML.load(File.read(dependencies_file_path))
85
98
 
@@ -205,6 +218,10 @@ module DSL
205
218
  `cd #{app_path} && npm install 2>/dev/null`
206
219
  end
207
220
 
221
+ def mvn_install
222
+ `cd #{app_path} && mvn install`
223
+ end
224
+
208
225
  def modifying_dependencies_file
209
226
  FileUtils.mkdir_p(File.dirname(dependencies_file_path))
210
227
  File.open(dependencies_file_path, 'w+') { |f| yield f }
@@ -216,10 +233,6 @@ module DSL
216
233
  `echo #{line.inspect} >> #{File.join(app_path, "Gemfile")}`
217
234
  end
218
235
 
219
- def add_to_rakefile(line)
220
- `echo #{line.inspect} >> #{File.join(app_path, "Rakefile")}`
221
- end
222
-
223
236
  def add_to_requirements(line)
224
237
  `echo #{line.inspect} >> #{File.join(app_path, "requirements.txt")}`
225
238
  end
@@ -22,10 +22,15 @@ module LicenseFinder
22
22
  autoload :Bundler, 'license_finder/package_managers/bundler'
23
23
  autoload :NPM, 'license_finder/package_managers/npm'
24
24
  autoload :Pip, 'license_finder/package_managers/pip'
25
+ autoload :Maven, 'license_finder/package_managers/maven'
26
+ autoload :Gradle, 'license_finder/package_managers/gradle'
25
27
  autoload :BowerPackage, 'license_finder/package_managers/bower_package'
26
28
  autoload :BundlerPackage, 'license_finder/package_managers/bundler_package'
27
29
  autoload :PipPackage, 'license_finder/package_managers/pip_package'
28
30
  autoload :NpmPackage, 'license_finder/package_managers/npm_package'
31
+ autoload :MavenPackage, 'license_finder/package_managers/maven_package'
32
+ autoload :GradlePackage, 'license_finder/package_managers/gradle_package'
33
+
29
34
 
30
35
  autoload :BundlerGroup, 'license_finder/tables/bundler_group'
31
36
  autoload :Dependency, 'license_finder/tables/dependency'
@@ -33,6 +38,7 @@ module LicenseFinder
33
38
  autoload :YmlToSql, 'license_finder/yml_to_sql'
34
39
 
35
40
  autoload :DependencyReport, 'license_finder/reports/dependency_report'
41
+ autoload :FormattedReport, 'license_finder/reports/formatted_report'
36
42
  autoload :HtmlReport, 'license_finder/reports/html_report'
37
43
  autoload :MarkdownReport, 'license_finder/reports/markdown_report'
38
44
  autoload :Reporter, 'license_finder/reports/reporter'
@@ -44,7 +50,6 @@ module LicenseFinder
44
50
  end
45
51
  end
46
52
 
47
- require 'license_finder/railtie' if defined?(Rails)
48
53
  unless defined?(LicenseAudit)
49
54
  require 'license_finder/tables'
50
55
  LicenseFinder::YmlToSql.convert_if_required
@@ -40,7 +40,7 @@ module LicenseFinder
40
40
 
41
41
  class Dependencies < Subcommand
42
42
  method_option :approve, type: :boolean, desc: "Approve the added dependency"
43
- desc "Add LICENSE DEPENDENCY_NAME [VERSION] [--approve]", "Add a dependency that is not managed by Bundler, NPM, etc"
43
+ desc "add LICENSE DEPENDENCY_NAME [VERSION] [--approve]", "Add a dependency that is not managed by Bundler, NPM, etc"
44
44
  def add(license, name, version = nil)
45
45
  die_on_error {
46
46
  DependencyManager.create_manually_managed(license, name, version)
@@ -53,7 +53,7 @@ module LicenseFinder
53
53
  end
54
54
  end
55
55
 
56
- desc "Remove DEPENDENCY_NAME", "Remove a dependency that is not managed by Bundler, NPM, etc"
56
+ desc "remove DEPENDENCY_NAME", "Remove a dependency that is not managed by Bundler, NPM, etc"
57
57
  def remove(name)
58
58
  die_on_error {
59
59
  DependencyManager.destroy_manually_managed(name)
@@ -87,7 +87,7 @@ module LicenseFinder
87
87
  end
88
88
  end
89
89
 
90
- desc "add LICENSE", "Add one ore more licenses to the whitelist"
90
+ desc "add LICENSE...", "Add one or more licenses to the whitelist"
91
91
  def add(*licenses)
92
92
  modifying {
93
93
  licenses.each do |license|
@@ -97,7 +97,7 @@ module LicenseFinder
97
97
  say "Added #{licenses.join(", ")} to the license whitelist"
98
98
  end
99
99
 
100
- desc "remove LICENSE", "Remove one ore more licenses from the whitelist"
100
+ desc "remove LICENSE...", "Remove one or more licenses from the whitelist"
101
101
  def remove(*licenses)
102
102
  modifying {
103
103
  licenses.each do |license|
@@ -160,13 +160,17 @@ module LicenseFinder
160
160
  end
161
161
  default_task :rescan
162
162
 
163
- desc "approve DEPENDENCY_NAME", "Approve one ore more dependencies by name"
163
+ desc "approve DEPENDENCY_NAME...", "Approve one or more dependencies by name"
164
164
  def approve(*names)
165
- die_on_error {
166
- names.each { |name| DependencyManager.approve!(name) }
167
- }
165
+ if(names.count < 1)
166
+ say "Warning: Must specify dependencies to approve.", :red
167
+ else
168
+ die_on_error {
169
+ names.each { |name| DependencyManager.approve!(name) }
170
+ }
168
171
 
169
- say "The #{names.join(", ")} dependency has been approved!", :green
172
+ say "The #{names.join(", ")} dependency has been approved!", :green
173
+ end
170
174
  end
171
175
 
172
176
  desc "license LICENSE DEPENDENCY_NAME", "Update a dependency's license"
@@ -1,108 +1,149 @@
1
- require "rake"
1
+ require "delegate"
2
2
 
3
3
  module LicenseFinder
4
4
  class Configuration
5
- attr_accessor :whitelist, :ignore_groups, :dependencies_dir, :project_name
6
-
7
- def self.config_file_path
8
- File.join('.', 'config', 'license_finder.yml')
9
- end
10
-
11
5
  def self.ensure_default
12
- make_config_file unless File.exists?(config_file_path)
13
- new
14
- end
15
-
16
- def self.make_config_file
17
- FileUtils.mkdir_p(File.join('.', 'config'))
18
- FileUtils.cp(
19
- ROOT_PATH.join('..', 'files', 'license_finder.yml'),
20
- config_file_path
21
- )
6
+ Persistence.init
7
+ prepare(Persistence.get)
22
8
  end
23
9
 
24
10
  def self.move!
25
- config = config_hash('dependencies_file_dir' => './doc/')
26
- File.open(config_file_path, 'w') do |f|
27
- f.write YAML.dump(config)
28
- end
11
+ config = prepare(Persistence.get.merge('dependencies_file_dir' => './doc/'))
12
+ config.save
29
13
 
30
- FileUtils.mkdir_p("doc")
31
- FileUtils.mv(Dir["dependencies.*"], "doc")
14
+ FileUtils.mv(Dir["dependencies*"], config.artifacts.dir)
32
15
  end
33
16
 
34
- def self.config_hash(config)
35
- if File.exists?(config_file_path)
36
- yaml = File.read(config_file_path)
37
- config = YAML.load(yaml).merge config
38
- end
39
- config
17
+ # It's nice to keep destructive file system manipulation out of the
18
+ # initializer. That reduces test polution, but is slightly inconvenient
19
+ # for methods like Configuration.ensure_default and Configuration.move!,
20
+ # which need a working artifacts directory. This helper is a compromise.
21
+ def self.prepare(config)
22
+ result = new(config)
23
+ result.artifacts.init
24
+ result
40
25
  end
41
26
 
42
- def initialize(config={})
43
- config = self.class.config_hash(config)
27
+ attr_accessor :whitelist, :ignore_groups, :artifacts, :project_name
44
28
 
45
- @whitelist = config['whitelist'] || []
46
- @ignore_groups = (config["ignore_groups"] || [])
47
- @dependencies_dir = config['dependencies_file_dir'] || './doc/'
48
- @project_name = config['project_name'] || determine_project_name
49
- FileUtils.mkdir_p(@dependencies_dir)
29
+ def initialize(config)
30
+ @whitelist = Array(config['whitelist'])
31
+ @ignore_groups = Array(config["ignore_groups"])
32
+ @artifacts = Artifacts.new(Pathname(config['dependencies_file_dir'] || './doc/'))
33
+ @project_name = config['project_name'] || determine_project_name
50
34
  end
51
35
 
52
- def database_uri
53
- URI.escape(File.expand_path(File.join(dependencies_dir, "dependencies.db")))
36
+ def whitelisted?(license_name)
37
+ license = License.find_by_name(license_name)
38
+ whitelisted_licenses.include? license
54
39
  end
55
40
 
56
- def dependencies_yaml
57
- File.join(dependencies_dir, "dependencies.yml")
41
+ def save
42
+ Persistence.set(to_hash)
58
43
  end
59
44
 
60
- def dependencies_text
61
- File.join(dependencies_dir, "dependencies.csv")
62
- end
45
+ private
63
46
 
64
- def dependencies_detailed_text
65
- File.join(dependencies_dir, "dependencies_detailed.csv")
47
+ def to_hash
48
+ {
49
+ 'whitelist' => whitelist.uniq,
50
+ 'ignore_groups' => ignore_groups.uniq,
51
+ 'dependencies_file_dir' => artifacts.dir.to_s,
52
+ 'project_name' => project_name
53
+ }
66
54
  end
67
55
 
68
- def dependencies_legacy_text
69
- File.join(dependencies_dir, "dependencies.txt")
56
+ def whitelisted_licenses
57
+ whitelist.map do |license_name|
58
+ License.find_by_name(license_name) || license_name
59
+ end.compact
70
60
  end
71
61
 
72
- def dependencies_html
73
- File.join(dependencies_dir, "dependencies.html")
62
+ def determine_project_name
63
+ Pathname.pwd.basename.to_s
74
64
  end
75
65
 
76
- def dependencies_markdown
77
- File.join(dependencies_dir, "dependencies.md")
78
- end
66
+ class Artifacts < SimpleDelegator
67
+ def init
68
+ mkpath
69
+ end
79
70
 
80
- def whitelisted?(license_name)
81
- license = License.find_by_name(license_name) || license_name
82
- whitelisted_licenses.include? license
83
- end
71
+ def dir
72
+ __getobj__
73
+ end
84
74
 
85
- def save
86
- File.open(Configuration.config_file_path, 'w') do |file|
87
- file.write({
88
- 'whitelist' => @whitelist.uniq,
89
- 'ignore_groups' => @ignore_groups.uniq,
90
- 'dependencies_file_dir' => @dependencies_dir,
91
- 'project_name' => @project_name
92
- }.to_yaml)
75
+ def database_uri
76
+ URI.escape(database_file.expand_path.to_s)
93
77
  end
94
- end
95
78
 
96
- private
79
+ def database_file
80
+ join("dependencies.db")
81
+ end
97
82
 
98
- def whitelisted_licenses
99
- whitelist.map do |license_name|
100
- License.find_by_name(license_name) || license_name
101
- end.compact
83
+ def text_file
84
+ join("dependencies.csv")
85
+ end
86
+
87
+ def detailed_text_file
88
+ join("dependencies_detailed.csv")
89
+ end
90
+
91
+ def html_file
92
+ join("dependencies.html")
93
+ end
94
+
95
+ def markdown_file
96
+ join("dependencies.md")
97
+ end
98
+
99
+ def legacy_yaml_file
100
+ join("dependencies.yml")
101
+ end
102
+
103
+ def legacy_text_file
104
+ join("dependencies.txt")
105
+ end
102
106
  end
103
107
 
104
- def determine_project_name
105
- File.basename(Dir.getwd)
108
+ module Persistence
109
+ extend self
110
+
111
+ def init
112
+ init! unless inited?
113
+ end
114
+
115
+ def get
116
+ return {} unless inited?
117
+
118
+ YAML.load(file.read)
119
+ end
120
+
121
+ def set(hash)
122
+ file.open('w') { |f| f.write(YAML.dump(hash)) }
123
+ end
124
+
125
+ private
126
+
127
+ def inited?
128
+ file.exist?
129
+ end
130
+
131
+ def init!
132
+ file_dir.mkpath
133
+ FileUtils.cp(file_template, file)
134
+ end
135
+
136
+ def file_dir
137
+ Pathname.new('.').join('config')
138
+ end
139
+
140
+ def file
141
+ file_dir.join('license_finder.yml')
142
+ end
143
+
144
+ def file_template
145
+ ROOT_PATH.join('..', 'files', 'license_finder.yml')
146
+ end
106
147
  end
107
148
  end
108
149
  end