license_conflicts 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,212 @@
1
+ # frozen_string_literal: true
2
+
3
+ # All license names in this file use the canonical form returned by
4
+ # LicenseFinder (dependency.licenses.first.name). Input is normalised via
5
+ # LicenseNormalizer before any lookup, so SPDX IDs and common aliases are
6
+ # handled transparently.
7
+
8
+ module LicenseConflicts
9
+ APACHE2_CONFLICTS = [
10
+ "MIT",
11
+ "New BSD",
12
+ "Simplified BSD",
13
+ "Zlib",
14
+ "MPL 1.1",
15
+ "CDDL 1.0",
16
+ "AGPL 1.0"
17
+ ].freeze
18
+
19
+ NEW_BSD_CONFLICTS = [
20
+ "MIT",
21
+ "Simplified BSD",
22
+ "Zlib",
23
+ "MPL 1.1",
24
+ "CDDL 1.0",
25
+ "AGPL 1.0"
26
+ ].freeze
27
+
28
+ GPL2_CONFLICTS = [
29
+ "MIT",
30
+ "Simplified BSD",
31
+ "New BSD",
32
+ "Apache 2.0",
33
+ "Zlib",
34
+ "AFL 3.0",
35
+ "MPL 1.1",
36
+ "MPL 2.0",
37
+ "CDDL 1.0",
38
+ "LGPL 2.1",
39
+ "LGPL 3.0",
40
+ "OSL 3.0",
41
+ "AGPL 1.0"
42
+ ].freeze
43
+
44
+ GPL3_CONFLICTS = [
45
+ "MIT",
46
+ "Simplified BSD",
47
+ "New BSD",
48
+ "Apache 2.0",
49
+ "Zlib",
50
+ "AFL 3.0",
51
+ "MPL 1.1",
52
+ "MPL 2.0",
53
+ "CDDL 1.0",
54
+ "LGPL 2.1",
55
+ "LGPL 3.0",
56
+ "OSL 3.0",
57
+ "GPLv2",
58
+ "AGPL 1.0"
59
+ ].freeze
60
+
61
+ MPL2_CONFLICTS = [
62
+ "MIT",
63
+ "Simplified BSD",
64
+ "New BSD",
65
+ "Apache 2.0",
66
+ "Zlib",
67
+ "AFL 3.0",
68
+ "MPL 1.1",
69
+ "CDDL 1.0",
70
+ "LGPL 3.0",
71
+ "OSL 3.0",
72
+ "AGPL 1.0"
73
+ ].freeze
74
+
75
+ SIMPLIFIED_BSD_CONFLICTS = [
76
+ "MIT",
77
+ "Zlib",
78
+ "MPL 1.1",
79
+ "CDDL 1.0",
80
+ "AGPL 1.0"
81
+ ].freeze
82
+
83
+ CONFLICTS_MAP = {
84
+ "MIT" => [
85
+ "Zlib",
86
+ "MPL 1.1",
87
+ "CDDL 1.0",
88
+ "AGPL 1.0"
89
+ ],
90
+ "Simplified BSD" => SIMPLIFIED_BSD_CONFLICTS,
91
+ "New BSD" => NEW_BSD_CONFLICTS,
92
+ "Apache 2.0" => APACHE2_CONFLICTS,
93
+ "Zlib" => [
94
+ "MIT",
95
+ "New BSD",
96
+ "Simplified BSD",
97
+ "MPL 1.1",
98
+ "CDDL 1.0",
99
+ "AGPL 1.0"
100
+ ],
101
+ "AFL 3.0" => [
102
+ "MIT",
103
+ "Simplified BSD",
104
+ "New BSD",
105
+ "Apache 2.0",
106
+ "MPL 1.1",
107
+ "MPL 2.0",
108
+ "CDDL 1.0",
109
+ "LGPL 2.1",
110
+ "LGPL 3.0",
111
+ "GPLv2",
112
+ "GPLv3",
113
+ "AGPL 3",
114
+ "Zlib",
115
+ "AGPL 1.0"
116
+ ],
117
+ "MPL 1.1" => [
118
+ "MIT",
119
+ "Simplified BSD",
120
+ "New BSD",
121
+ "Apache 2.0",
122
+ "Zlib",
123
+ "AFL 3.0",
124
+ "LGPL 3.0",
125
+ "OSL 3.0",
126
+ "AGPL 1.0"
127
+ ],
128
+ "MPL 2.0" => MPL2_CONFLICTS,
129
+ "CDDL 1.0" => [
130
+ "MIT",
131
+ "Simplified BSD",
132
+ "New BSD",
133
+ "Apache 2.0",
134
+ "Zlib",
135
+ "AFL 3.0",
136
+ "MPL 1.1",
137
+ "MPL 2.0",
138
+ "LGPL 2.1",
139
+ "LGPL 3.0",
140
+ "OSL 3.0",
141
+ "GPLv2",
142
+ "GPLv3",
143
+ "AGPL 3",
144
+ "AGPL 1.0"
145
+ ],
146
+ "LGPL 2.1" => [
147
+ "MIT",
148
+ "Simplified BSD",
149
+ "New BSD",
150
+ "Apache 2.0",
151
+ "Zlib",
152
+ "AFL 3.0",
153
+ "MPL 1.1",
154
+ "MPL 2.0",
155
+ "CDDL 1.0",
156
+ "OSL 3.0",
157
+ "AGPL 1.0"
158
+ ],
159
+ "OSL 3.0" => [
160
+ "MIT",
161
+ "Simplified BSD",
162
+ "New BSD",
163
+ "Apache 2.0",
164
+ "Zlib",
165
+ "AFL 3.0",
166
+ "MPL 1.1",
167
+ "MPL 2.0",
168
+ "CDDL 1.0",
169
+ "LGPL 2.1",
170
+ "LGPL 3.0",
171
+ "GPLv2",
172
+ "GPLv3",
173
+ "AGPL 3",
174
+ "AGPL 1.0"
175
+ ],
176
+ "GPLv2" => GPL2_CONFLICTS,
177
+ "GPLv3" => GPL3_CONFLICTS,
178
+ "AGPL 3" => [
179
+ "MIT",
180
+ "Simplified BSD",
181
+ "New BSD",
182
+ "Apache 2.0",
183
+ "Zlib",
184
+ "AFL 3.0",
185
+ "MPL 1.1",
186
+ "MPL 2.0",
187
+ "CDDL 1.0",
188
+ "LGPL 2.1",
189
+ "LGPL 3.0",
190
+ "OSL 3.0",
191
+ "GPLv2",
192
+ "GPLv3",
193
+ "AGPL 1.0"
194
+ ],
195
+ "AGPL 1.0" => [
196
+ "MIT",
197
+ "Simplified BSD",
198
+ "New BSD",
199
+ "Apache 2.0",
200
+ "Zlib",
201
+ "AFL 3.0",
202
+ "MPL 1.1",
203
+ "MPL 2.0",
204
+ "CDDL 1.0",
205
+ "LGPL 2.1",
206
+ "LGPL 3.0",
207
+ "OSL 3.0",
208
+ "GPLv2",
209
+ "GPLv3"
210
+ ]
211
+ }.freeze
212
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'license_finder'
4
+ require 'license_conflicts/conflicts_map'
5
+ require 'license_conflicts/license_normalizer'
6
+ require 'license_conflicts/project_metadata'
7
+
8
+ module LicenseConflicts
9
+ class Finder
10
+ attr_reader :main_license
11
+
12
+ def initialize
13
+ @config ||= LicenseFinder::Configuration.with_optional_saved_config(license_finder_config)
14
+ end
15
+
16
+ def find_conflicts
17
+ @main_license = LicenseNormalizer.normalize(project_license)
18
+
19
+ raise "Could not detect the project license. Ensure your project metadata file declares a license." if main_license.nil?
20
+ raise "License '#{main_license}' is not covered by the conflict matrix." unless CONFLICTS_MAP.key?(main_license)
21
+
22
+ check_conflicts
23
+ end
24
+
25
+ def dependencies_count
26
+ unapproved.count { |d| d.name != project_name }
27
+ end
28
+
29
+ def project_license
30
+ examined_package = unapproved.find { |d| d.name == project_name }
31
+ examined_package&.licenses&.first&.name || project_metadata.license
32
+ end
33
+
34
+ private
35
+
36
+ def project_name
37
+ project_metadata.name
38
+ end
39
+
40
+ def project_metadata
41
+ @project_metadata ||= ProjectMetadata.new
42
+ end
43
+
44
+ def license_finder_config
45
+ {
46
+ prepare: true,
47
+ logger: LicenseFinder::Logger::MODE_QUIET
48
+ }
49
+ end
50
+
51
+ def finder
52
+ @finder ||= LicenseFinder::LicenseAggregator.new(config, nil)
53
+ end
54
+
55
+ def unapproved
56
+ @unapproved ||= finder.unapproved
57
+ end
58
+
59
+ def check_conflicts
60
+ unapproved.filter { |dependency| has_conflict?(dependency.licenses.first&.name) }
61
+ end
62
+
63
+ def has_conflict?(dependency_license)
64
+ CONFLICTS_MAP[main_license].include?(LicenseNormalizer.normalize(dependency_license))
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,240 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LicenseConflicts
4
+ module LicenseNormalizer
5
+ # Maps known license aliases and SPDX identifiers to the canonical names
6
+ # used by LicenseFinder (i.e. what `dependency.licenses.first.name` returns).
7
+ # Sources:
8
+ # - LicenseFinder definitions: lib/license_finder/license/definitions.rb
9
+ # - SPDX license list: https://spdx.org/licenses/
10
+ ALIASES = {
11
+ # -----------------------------------------------------------------------
12
+ # MIT
13
+ # -----------------------------------------------------------------------
14
+ "MIT" => "MIT",
15
+ "Expat" => "MIT",
16
+ "MIT license" => "MIT",
17
+ "MIT License" => "MIT",
18
+ "MIT License (MIT)" => "MIT",
19
+
20
+ # -----------------------------------------------------------------------
21
+ # Apache 2.0
22
+ # -----------------------------------------------------------------------
23
+ "Apache 2.0" => "Apache 2.0",
24
+ "Apache-2.0" => "Apache 2.0",
25
+ "apache-2.0" => "Apache 2.0",
26
+ "Apache 2" => "Apache 2.0",
27
+ "Apache Software License" => "Apache 2.0",
28
+ "Apache License 2.0" => "Apache 2.0",
29
+ "Apache License Version 2.0" => "Apache 2.0",
30
+ "Apache Public License 2.0" => "Apache 2.0",
31
+ "Apache Software License, Version 2.0" => "Apache 2.0",
32
+ "Apache Software License - Version 2.0" => "Apache 2.0",
33
+ "Apache License, Version 2.0" => "Apache 2.0",
34
+ "ASL 2.0" => "Apache 2.0",
35
+ "ASF 2.0" => "Apache 2.0",
36
+
37
+ # -----------------------------------------------------------------------
38
+ # Apache 1.1
39
+ # -----------------------------------------------------------------------
40
+ "Apache 1.1" => "Apache 1.1",
41
+ "Apache-1.1" => "Apache 1.1",
42
+ "APACHE 1.1" => "Apache 1.1",
43
+ "Apache License 1.1" => "Apache 1.1",
44
+ "Apache License Version 1.1" => "Apache 1.1",
45
+ "Apache Public License 1.1" => "Apache 1.1",
46
+ "Apache Software License, Version 1.1" => "Apache 1.1",
47
+ "Apache Software License - Version 1.1" => "Apache 1.1",
48
+ "Apache License, Version 1.1" => "Apache 1.1",
49
+ "ASL 1.1" => "Apache 1.1",
50
+ "ASF 1.1" => "Apache 1.1",
51
+
52
+ # -----------------------------------------------------------------------
53
+ # New BSD (BSD 3-Clause)
54
+ # -----------------------------------------------------------------------
55
+ "New BSD" => "New BSD",
56
+ "NewBSD" => "New BSD",
57
+ "BSD-3-Clause" => "New BSD",
58
+ "BSD3" => "New BSD",
59
+ "BSD 3" => "New BSD",
60
+ "BSD-3" => "New BSD",
61
+ "Modified BSD" => "New BSD",
62
+ "3-clause BSD" => "New BSD",
63
+ "3-Clause BSD License" => "New BSD",
64
+ "BSD 3-Clause" => "New BSD",
65
+ "BSD 3-Clause License" => "New BSD",
66
+ "BSD 3-clause New License" => "New BSD",
67
+ "New BSD License" => "New BSD",
68
+ "BSD New license" => "New BSD",
69
+ "BSD License 3" => "New BSD",
70
+ "BSD Licence 3" => "New BSD",
71
+
72
+ # -----------------------------------------------------------------------
73
+ # Simplified BSD (BSD 2-Clause)
74
+ # -----------------------------------------------------------------------
75
+ "Simplified BSD" => "Simplified BSD",
76
+ "BSD-2-Clause" => "Simplified BSD",
77
+ "BSD-2" => "Simplified BSD",
78
+ "FreeBSD" => "Simplified BSD",
79
+ "2-clause BSD" => "Simplified BSD",
80
+ "BSD 2-Clause" => "Simplified BSD",
81
+ "BSD 2-Clause License" => "Simplified BSD",
82
+
83
+ # -----------------------------------------------------------------------
84
+ # GPLv2
85
+ # -----------------------------------------------------------------------
86
+ "GPLv2" => "GPLv2",
87
+ "GPL-2.0" => "GPLv2",
88
+ "GPL-2.0-only" => "GPLv2",
89
+ "GPL-2.0+" => "GPLv2",
90
+ "GPL V2" => "GPLv2",
91
+ "gpl-v2" => "GPLv2",
92
+ "GPL 2.0" => "GPLv2",
93
+ "GNU GENERAL PUBLIC LICENSE Version 2" => "GPLv2",
94
+
95
+ # -----------------------------------------------------------------------
96
+ # GPLv3
97
+ # -----------------------------------------------------------------------
98
+ "GPLv3" => "GPLv3",
99
+ "GPL-3.0" => "GPLv3",
100
+ "GPL-3.0-only" => "GPLv3",
101
+ "GPL-3.0+" => "GPLv3",
102
+ "GPL V3" => "GPLv3",
103
+ "gpl-v3" => "GPLv3",
104
+ "GPL 3.0" => "GPLv3",
105
+ "GNU GENERAL PUBLIC LICENSE Version 3" => "GPLv3",
106
+
107
+ # -----------------------------------------------------------------------
108
+ # LGPL 3.0
109
+ # -----------------------------------------------------------------------
110
+ "LGPL" => "LGPL 3.0",
111
+ "LGPL 3.0" => "LGPL 3.0",
112
+ "LGPL-3" => "LGPL 3.0",
113
+ "LGPLv3" => "LGPL 3.0",
114
+ "LGPL-3.0" => "LGPL 3.0",
115
+ "LGPL-3.0-only" => "LGPL 3.0",
116
+
117
+ # -----------------------------------------------------------------------
118
+ # LGPL 2.1
119
+ # -----------------------------------------------------------------------
120
+ "LGPL 2.1" => "LGPL 2.1",
121
+ "LGPL-2.1" => "LGPL 2.1",
122
+ "LGPL-2.1-only" => "LGPL 2.1",
123
+ "LGPL v2.1" => "LGPL 2.1",
124
+ "GNU Lesser General Public License 2.1" => "LGPL 2.1",
125
+ "GNU Lesser General Public License version 2.1" => "LGPL 2.1",
126
+
127
+ # -----------------------------------------------------------------------
128
+ # MPL 1.1
129
+ # -----------------------------------------------------------------------
130
+ "MPL 1.1" => "MPL 1.1",
131
+ "MPL-1.1" => "MPL 1.1",
132
+ "MPL-1.1+" => "MPL 1.1",
133
+ "Mozilla 1.1" => "MPL 1.1",
134
+ "Mozilla Public License 1.1" => "MPL 1.1",
135
+ "Mozilla Public License, Version 1.1" => "MPL 1.1",
136
+ "Mozilla Public License version 1.1" => "MPL 1.1",
137
+
138
+ # -----------------------------------------------------------------------
139
+ # MPL 2.0
140
+ # -----------------------------------------------------------------------
141
+ "MPL 2.0" => "MPL 2.0",
142
+ "MPL-2.0" => "MPL 2.0",
143
+ "Mozilla 2.0" => "MPL 2.0",
144
+ "Mozilla Public License 2.0" => "MPL 2.0",
145
+ "Mozilla Public License, Version 2.0" => "MPL 2.0",
146
+ "Mozilla Public License version 2.0" => "MPL 2.0",
147
+
148
+ # -----------------------------------------------------------------------
149
+ # AGPL 3
150
+ # -----------------------------------------------------------------------
151
+ "AGPL 3" => "AGPL 3",
152
+ "AGPL3" => "AGPL 3",
153
+ "AGPL-3.0" => "AGPL 3",
154
+ "AGPL-3.0-only" => "AGPL 3",
155
+ "AGPL 3.0" => "AGPL 3",
156
+ "GNU Affero General Public License v3.0" => "AGPL 3",
157
+ "GNU Affero General Public License, Version 3" => "AGPL 3",
158
+
159
+ # -----------------------------------------------------------------------
160
+ # AGPL 1.0 (older version, not in LicenseFinder definitions but seen in the wild)
161
+ # -----------------------------------------------------------------------
162
+ "AGPL 1.0" => "AGPL 1.0",
163
+ "AGPL-1.0" => "AGPL 1.0",
164
+ "AGPL-1.0+" => "AGPL 1.0",
165
+ "AGPL1" => "AGPL 1.0",
166
+
167
+ # -----------------------------------------------------------------------
168
+ # CDDL 1.0
169
+ # -----------------------------------------------------------------------
170
+ "CDDL 1.0" => "CDDL 1.0",
171
+ "CDDL-1.0" => "CDDL 1.0",
172
+ "Common Development and Distribution License 1.0" => "CDDL 1.0",
173
+ "Common Development and Distribution License (CDDL) v1.0" => "CDDL 1.0",
174
+ "COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0" => "CDDL 1.0",
175
+
176
+ # -----------------------------------------------------------------------
177
+ # AFL 3.0
178
+ # -----------------------------------------------------------------------
179
+ "AFL 3.0" => "AFL 3.0",
180
+ "AFL-3.0" => "AFL 3.0",
181
+ "Academic Free License 3.0" => "AFL 3.0",
182
+ "Academic Free License, Version 3.0" => "AFL 3.0",
183
+
184
+ # -----------------------------------------------------------------------
185
+ # OSL 3.0
186
+ # -----------------------------------------------------------------------
187
+ "OSL 3.0" => "OSL 3.0",
188
+ "OSL-3.0" => "OSL 3.0",
189
+ "Open Software License 3.0" => "OSL 3.0",
190
+ "Open Software License, Version 3.0" => "OSL 3.0",
191
+
192
+ # -----------------------------------------------------------------------
193
+ # ISC
194
+ # -----------------------------------------------------------------------
195
+ "ISC" => "ISC",
196
+ "ISC License" => "ISC",
197
+
198
+ # -----------------------------------------------------------------------
199
+ # Zlib
200
+ # -----------------------------------------------------------------------
201
+ "Zlib" => "Zlib",
202
+ "zlib" => "Zlib",
203
+ "zlib/libpng license" => "Zlib",
204
+ "zlib License" => "Zlib",
205
+
206
+ # -----------------------------------------------------------------------
207
+ # Unlicense
208
+ # -----------------------------------------------------------------------
209
+ "Unlicense" => "Unlicense",
210
+ "The Unlicense" => "Unlicense",
211
+
212
+ # -----------------------------------------------------------------------
213
+ # EPL 1.0
214
+ # -----------------------------------------------------------------------
215
+ "EPL 1.0" => "EPL 1.0",
216
+ "EPL-1.0" => "EPL 1.0",
217
+ "Eclipse 1.0" => "EPL 1.0",
218
+ "Eclipse Public License 1.0" => "EPL 1.0",
219
+ "Eclipse Public License - v 1.0" => "EPL 1.0",
220
+
221
+ # -----------------------------------------------------------------------
222
+ # EPL 2.0
223
+ # -----------------------------------------------------------------------
224
+ "EPL 2.0" => "EPL 2.0",
225
+ "EPL-2.0" => "EPL 2.0",
226
+ "Eclipse 2.0" => "EPL 2.0",
227
+ "Eclipse Public License 2.0" => "EPL 2.0",
228
+ "Eclipse Public License - v 2.0" => "EPL 2.0"
229
+ }.freeze
230
+
231
+ # Returns the canonical license name for the given string.
232
+ # If the name is not recognised, it is returned as-is so the caller can
233
+ # decide what to do (e.g. raise "not mapped").
234
+ def self.normalize(name)
235
+ return nil if name.nil?
236
+
237
+ ALIASES.fetch(name, name)
238
+ end
239
+ end
240
+ end
@@ -0,0 +1,128 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "pathname"
5
+
6
+ module LicenseConflicts
7
+ class ProjectMetadata
8
+ def name
9
+ @name ||= read_name
10
+ end
11
+
12
+ def license
13
+ @license ||= read_license
14
+ end
15
+
16
+ private
17
+
18
+ def read_name
19
+ package_json_data&.dig("name") ||
20
+ bower_json_data&.dig("name") ||
21
+ gemspec_data&.dig(:name) ||
22
+ setup_cfg_data&.dig(:name) ||
23
+ pyproject_toml_data&.dig(:name) ||
24
+ go_mod_data&.dig(:name) ||
25
+ godeps_data&.dig(:name) ||
26
+ pom_xml_data&.dig(:name) ||
27
+ Pathname.pwd.basename.to_s
28
+ end
29
+
30
+ def read_license
31
+ package_json_data&.dig("license") ||
32
+ bower_json_data&.dig("license") ||
33
+ gemspec_data&.dig(:license) ||
34
+ setup_cfg_data&.dig(:license) ||
35
+ pyproject_toml_data&.dig(:license) ||
36
+ pom_xml_data&.dig(:license)
37
+ end
38
+
39
+ def package_json_data
40
+ return unless File.exist?("./package.json")
41
+
42
+ @package_json_data ||= JSON.parse(File.read("./package.json"))
43
+ rescue JSON::ParserError
44
+ nil
45
+ end
46
+
47
+ def bower_json_data
48
+ return unless File.exist?("./bower.json")
49
+
50
+ @bower_json_data ||= JSON.parse(File.read("./bower.json"))
51
+ rescue JSON::ParserError
52
+ nil
53
+ end
54
+
55
+ def gemspec_data
56
+ gemspec_file = Dir.glob("./*.gemspec").first
57
+ return unless gemspec_file
58
+
59
+ @gemspec_data ||= begin
60
+ content = File.read(gemspec_file)
61
+ name = content[/\.name\s*=\s*["']([^"']+)["']/, 1]
62
+ license = content[/\.license\s*=\s*["']([^"']+)["']/, 1]
63
+ { name: name, license: license }
64
+ end
65
+ end
66
+
67
+ def setup_cfg_data
68
+ return unless File.exist?("./setup.cfg")
69
+
70
+ @setup_cfg_data ||= begin
71
+ content = File.read("./setup.cfg")
72
+ name = content[/^name\s*=\s*(.+)/, 1]&.strip
73
+ license = content[/^license\s*=\s*(.+)/, 1]&.strip
74
+ { name: name, license: license }
75
+ end
76
+ end
77
+
78
+ def pyproject_toml_data
79
+ return unless File.exist?("./pyproject.toml")
80
+
81
+ @pyproject_toml_data ||= begin
82
+ require "tomlrb"
83
+ data = Tomlrb.load_file("./pyproject.toml")
84
+ project = data["project"] || data.dig("tool", "poetry") || {}
85
+ license = project["license"]
86
+ license = license["text"] if license.is_a?(Hash)
87
+ { name: project["name"], license: license }
88
+ rescue LoadError
89
+ nil
90
+ end
91
+ end
92
+
93
+ def go_mod_data
94
+ return unless File.exist?("./go.mod")
95
+
96
+ @go_mod_data ||= begin
97
+ name = File.read("./go.mod")[/^module\s+(\S+)/, 1]
98
+ { name: name }
99
+ end
100
+ end
101
+
102
+ def godeps_data
103
+ return unless File.exist?("./Godeps/Godeps.json")
104
+
105
+ @godeps_data ||= begin
106
+ data = JSON.parse(File.read("./Godeps/Godeps.json"))
107
+ { name: data["ImportPath"] }
108
+ rescue JSON::ParserError
109
+ nil
110
+ end
111
+ end
112
+
113
+ def pom_xml_data
114
+ return unless File.exist?("./pom.xml")
115
+
116
+ @pom_xml_data ||= begin
117
+ require "rexml/document"
118
+ doc = REXML::Document.new(File.read("./pom.xml"))
119
+ name = REXML::XPath.first(doc, "//project/name")&.text ||
120
+ REXML::XPath.first(doc, "//project/artifactId")&.text
121
+ license = REXML::XPath.first(doc, "//project/licenses/license/name")&.text
122
+ { name: name, license: license }
123
+ rescue REXML::ParseException
124
+ nil
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'license_finder'
4
+
5
+ module LicenseConflicts
6
+ class Report
7
+ attr_reader :format, :dependencies
8
+
9
+ FORMATS = {
10
+ 'text' => LicenseFinder::TextReport,
11
+ 'html' => LicenseFinder::HtmlReport,
12
+ 'markdown' => LicenseFinder::MarkdownReport,
13
+ 'csv' => LicenseFinder::CsvReport,
14
+ 'xml' => LicenseFinder::XmlReport,
15
+ 'json' => LicenseFinder::JsonReport,
16
+ 'junit' => LicenseFinder::JunitReport
17
+ }.freeze
18
+
19
+ def initialize(dependencies, format)
20
+ @dependencies = dependencies
21
+ @format = format
22
+ end
23
+
24
+ def report
25
+ report_class = FORMATS[format] || FORMATS['text']
26
+ puts report_class.of(dependencies, {})
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LicenseConflicts
4
+ VERSION = "0.3.0"
5
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'license_conflicts/finder'
4
+ require_relative 'license_conflicts/version'
5
+ require_relative 'license_conflicts/report'
6
+ require_relative 'license_conflicts/project_metadata'
7
+ require_relative 'license_conflicts/license_normalizer'
8
+
9
+ module LicenseConflicts
10
+ end