Class: LicenseFinder::Package
- Inherits:
-
Object
- Object
- LicenseFinder::Package
- Defined in:
- lib/license_finder/package.rb
Overview
Super-class that adapts data from different package management systems (gems, npm, pip, etc.) to a common interface.
Guidance on adding a new system
-
subclass Package, and initialize based on the data you receive from the package manager
-
if the package specs will report license names, pass :spec_licenses in the constructor options
-
if the package’s files can be searched for licenses pass :install_path in the constructor options
-
otherwise, override #licenses_from_spec or #license_files
Direct Known Subclasses
BowerPackage, BundlerPackage, CargoPackage, CarthagePackage, CocoaPodsPackage, ConanPackage, GoPackage, GradlePackage, ManualPackage, MavenPackage, MergedPackage, MixPackage, NpmPackage, NugetPackage, PipPackage, RebarPackage, SbtPackage, YarnPackage
Instance Attribute Summary collapse
-
#authors ⇒ Object
readonly
DESCRIPTION.
-
#children ⇒ Object
readonly
DESCRIPTION.
-
#description ⇒ Object
readonly
DESCRIPTION.
-
#groups ⇒ Object
readonly
DESCRIPTION.
-
#homepage ⇒ Object
readonly
DESCRIPTION.
-
#install_path ⇒ Object
readonly
checked in tests, otherwise private.
-
#license_names_from_spec ⇒ Object
readonly
LICENSING.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#manual_approval ⇒ Object
readonly
Returns the value of attribute manual_approval.
-
#name ⇒ Object
readonly
DESCRIPTION.
-
#parents ⇒ Object
readonly
DESCRIPTION.
-
#summary ⇒ Object
readonly
DESCRIPTION.
-
#version ⇒ Object
readonly
DESCRIPTION.
Class Method Summary collapse
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
EQUALITY.
- #activations ⇒ Object
- #approved? ⇒ Boolean
-
#approved_manually!(approval) ⇒ Object
APPROVAL.
- #approved_manually? ⇒ Boolean
- #blacklisted! ⇒ Object
- #blacklisted? ⇒ Boolean
- #decide_on_license(license) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name, version = nil, options = {}) ⇒ Package
constructor
A new instance of Package.
- #license_files ⇒ Object
- #licenses ⇒ Object
- #licenses_from_spec ⇒ Object
- #licensing ⇒ Object
- #log_activation(activation) ⇒ Object
- #missing? ⇒ Boolean
- #notice_files ⇒ Object
- #package_manager ⇒ Object
- #whitelisted! ⇒ Object
- #whitelisted? ⇒ Boolean
Constructor Details
#initialize(name, version = nil, options = {}) ⇒ Package
Returns a new instance of Package.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/license_finder/package.rb', line 36 def initialize(name, version = nil, = {}) @logger = [:logger] || Core.default_logger ## DESCRIPTION @name = name @version = version @authors = [:authors] || '' @summary = [:summary] || '' @description = [:description] || '' @homepage = [:homepage] || '' @children = [:children] || [] @parents = Set.new # will be figured out later by package manager @groups = [:groups] || [] ## APPROVAL @whitelisted = false @blacklisted = false @manual_approval = nil ## LICENSING @license_names_from_spec = [:spec_licenses] || [] @install_path = [:install_path] @missing = [:missing] || false @decided_licenses = Set.new end |
Instance Attribute Details
#authors ⇒ Object (readonly)
DESCRIPTION
64 65 66 |
# File 'lib/license_finder/package.rb', line 64 def @authors end |
#children ⇒ Object (readonly)
DESCRIPTION
64 65 66 |
# File 'lib/license_finder/package.rb', line 64 def children @children end |
#description ⇒ Object (readonly)
DESCRIPTION
64 65 66 |
# File 'lib/license_finder/package.rb', line 64 def description @description end |
#groups ⇒ Object (readonly)
DESCRIPTION
64 65 66 |
# File 'lib/license_finder/package.rb', line 64 def groups @groups end |
#homepage ⇒ Object (readonly)
DESCRIPTION
64 65 66 |
# File 'lib/license_finder/package.rb', line 64 def homepage @homepage end |
#install_path ⇒ Object (readonly)
checked in tests, otherwise private
123 124 125 |
# File 'lib/license_finder/package.rb', line 123 def install_path @install_path end |
#license_names_from_spec ⇒ Object (readonly)
LICENSING
122 123 124 |
# File 'lib/license_finder/package.rb', line 122 def license_names_from_spec @license_names_from_spec end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
21 22 23 |
# File 'lib/license_finder/package.rb', line 21 def logger @logger end |
#manual_approval ⇒ Object (readonly)
Returns the value of attribute manual_approval.
101 102 103 |
# File 'lib/license_finder/package.rb', line 101 def manual_approval @manual_approval end |
#name ⇒ Object (readonly)
DESCRIPTION
64 65 66 |
# File 'lib/license_finder/package.rb', line 64 def name @name end |
#parents ⇒ Object (readonly)
DESCRIPTION
64 65 66 |
# File 'lib/license_finder/package.rb', line 64 def parents @parents end |
#summary ⇒ Object (readonly)
DESCRIPTION
64 65 66 |
# File 'lib/license_finder/package.rb', line 64 def summary @summary end |
#version ⇒ Object (readonly)
DESCRIPTION
64 65 66 |
# File 'lib/license_finder/package.rb', line 64 def version @version end |
Class Method Details
.license_names_from_standard_spec(spec) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/license_finder/package.rb', line 23 def self.license_names_from_standard_spec(spec) licenses = spec['licenses'] || [spec['license']].compact licenses = [licenses] unless licenses.is_a?(Array) licenses = licenses.flatten licenses.map do |license| if license.is_a? Hash license['type'] else license end end end |
Instance Method Details
#<=>(other) ⇒ Object
EQUALITY
105 106 107 108 109 110 |
# File 'lib/license_finder/package.rb', line 105 def <=>(other) eq_name = name <=> other.name return eq_name unless eq_name.zero? version <=> other.version end |
#activations ⇒ Object
129 130 131 132 133 |
# File 'lib/license_finder/package.rb', line 129 def activations licensing.activations.tap do |activations| activations.each { |activation| log_activation activation } end end |
#approved? ⇒ Boolean
78 79 80 81 82 83 |
# File 'lib/license_finder/package.rb', line 78 def approved? # Question: is `!blacklisted?` redundant? # DecisionApplier does not call `whitelisted!` or `approved_manually!` # if a Package has been blacklisted. (approved_manually? || whitelisted?) && !blacklisted? end |
#approved_manually!(approval) ⇒ Object
APPROVAL
70 71 72 |
# File 'lib/license_finder/package.rb', line 70 def approved_manually!(approval) @manual_approval = approval end |
#approved_manually? ⇒ Boolean
74 75 76 |
# File 'lib/license_finder/package.rb', line 74 def approved_manually? !@manual_approval.nil? end |
#blacklisted! ⇒ Object
93 94 95 |
# File 'lib/license_finder/package.rb', line 93 def blacklisted! @blacklisted = true end |
#blacklisted? ⇒ Boolean
97 98 99 |
# File 'lib/license_finder/package.rb', line 97 def blacklisted? @blacklisted end |
#decide_on_license(license) ⇒ Object
139 140 141 |
# File 'lib/license_finder/package.rb', line 139 def decide_on_license(license) @decided_licenses << license end |
#eql?(other) ⇒ Boolean
112 113 114 |
# File 'lib/license_finder/package.rb', line 112 def eql?(other) name == other.name && version == other.version end |
#hash ⇒ Object
116 117 118 |
# File 'lib/license_finder/package.rb', line 116 def hash [name, version].hash end |
#license_files ⇒ Object
149 150 151 |
# File 'lib/license_finder/package.rb', line 149 def license_files LicenseFiles.find(install_path, logger: logger) end |
#licenses ⇒ Object
125 126 127 |
# File 'lib/license_finder/package.rb', line 125 def licenses @licenses ||= activations.map(&:license).to_set end |
#licenses_from_spec ⇒ Object
143 144 145 146 147 |
# File 'lib/license_finder/package.rb', line 143 def licenses_from_spec license_names_from_spec .map { |name| License.find_by_name(name) } .to_set end |
#licensing ⇒ Object
135 136 137 |
# File 'lib/license_finder/package.rb', line 135 def licensing Licensing.new(self, @decided_licenses, licenses_from_spec, license_files) end |
#log_activation(activation) ⇒ Object
165 166 167 168 169 170 171 172 173 174 |
# File 'lib/license_finder/package.rb', line 165 def log_activation(activation) preamble = format('package %s:', activation.package.name) if activation.sources.empty? logger.debug activation.package.class, format('%s no licenses found', preamble) else activation.sources.each do |source| logger.debug activation.package.class, format("%s found license '%s' %s", preamble, activation.license.name, source) end end end |
#missing? ⇒ Boolean
161 162 163 |
# File 'lib/license_finder/package.rb', line 161 def missing? @missing end |
#notice_files ⇒ Object
153 154 155 |
# File 'lib/license_finder/package.rb', line 153 def notice_files NoticeFiles.find(install_path, logger: logger) end |
#package_manager ⇒ Object
157 158 159 |
# File 'lib/license_finder/package.rb', line 157 def package_manager 'unknown' end |
#whitelisted! ⇒ Object
85 86 87 |
# File 'lib/license_finder/package.rb', line 85 def whitelisted! @whitelisted = true end |
#whitelisted? ⇒ Boolean
89 90 91 |
# File 'lib/license_finder/package.rb', line 89 def whitelisted? @whitelisted end |