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, ComposerPackage, ConanPackage, CondaPackage, ErlangmkPackage, GoPackage, GradlePackage, ManualPackage, MavenPackage, MergedPackage, MixPackage, NpmPackage, NugetPackage, PNPMPackage, PipPackage, PubPackage, RebarPackage, SbtPackage, SpmPackage, YarnPackage
Instance Attribute Summary collapse
-
#authors ⇒ Object
readonly
Returns the value of attribute authors.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#homepage ⇒ Object
DESCRIPTION.
-
#install_path ⇒ Object
readonly
Returns the value of attribute install_path.
-
#license_names_from_spec ⇒ Object
readonly
Returns the value of attribute license_names_from_spec.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#manual_approval ⇒ Object
readonly
Returns the value of attribute manual_approval.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#package_url ⇒ Object
DESCRIPTION.
-
#parents ⇒ Object
readonly
Returns the value of attribute parents.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
EQUALITY.
- #activations ⇒ Object
- #approved? ⇒ Boolean
-
#approved_manually!(approval) ⇒ Object
APPROVAL.
- #approved_manually? ⇒ 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
LICENSING # stubbed in tests, otherwise private # checked in tests, otherwise private.
- #licenses_from_spec ⇒ Object
- #licensing ⇒ Object
- #log_activation(activation) ⇒ Object
- #missing? ⇒ Boolean
- #notice_files ⇒ Object
- #package_manager ⇒ Object
- #permitted! ⇒ Object
- #permitted? ⇒ Boolean
- #restricted! ⇒ Object
- #restricted? ⇒ 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 61 |
# 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] || '' @package_url = [:package_url].to_s @children = [:children] || [] @parents = Set.new # will be figured out later by package manager @groups = [:groups] || [] ## APPROVAL @permitted = false @restricted = 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)
Returns the value of attribute authors.
21 22 23 |
# File 'lib/license_finder/package.rb', line 21 def @authors end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
21 22 23 |
# File 'lib/license_finder/package.rb', line 21 def children @children end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
21 22 23 |
# File 'lib/license_finder/package.rb', line 21 def description @description end |
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
21 22 23 |
# File 'lib/license_finder/package.rb', line 21 def groups @groups end |
#homepage ⇒ Object
DESCRIPTION
65 66 67 |
# File 'lib/license_finder/package.rb', line 65 def homepage @homepage end |
#install_path ⇒ Object (readonly)
Returns the value of attribute install_path.
21 22 23 |
# File 'lib/license_finder/package.rb', line 21 def install_path @install_path end |
#license_names_from_spec ⇒ Object (readonly)
Returns the value of attribute license_names_from_spec.
21 22 23 |
# File 'lib/license_finder/package.rb', line 21 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.
21 22 23 |
# File 'lib/license_finder/package.rb', line 21 def manual_approval @manual_approval end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/license_finder/package.rb', line 21 def name @name end |
#package_url ⇒ Object
DESCRIPTION
65 66 67 |
# File 'lib/license_finder/package.rb', line 65 def package_url @package_url end |
#parents ⇒ Object (readonly)
Returns the value of attribute parents.
21 22 23 |
# File 'lib/license_finder/package.rb', line 21 def parents @parents end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
21 22 23 |
# File 'lib/license_finder/package.rb', line 21 def summary @summary end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
21 22 23 |
# File 'lib/license_finder/package.rb', line 21 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
102 103 104 105 106 107 |
# File 'lib/license_finder/package.rb', line 102 def <=>(other) eq_name = name <=> other.name return eq_name unless eq_name.zero? version <=> other.version end |
#activations ⇒ Object
123 124 125 126 127 |
# File 'lib/license_finder/package.rb', line 123 def activations licensing.activations.tap do |activations| activations.each { |activation| log_activation activation } end end |
#approved? ⇒ Boolean
77 78 79 80 81 82 |
# File 'lib/license_finder/package.rb', line 77 def approved? # Question: is `!restricted?` redundant? # DecisionApplier does not call `permitted!` or `approved_manually!` # if a Package has been restricted. (approved_manually? || permitted?) && !restricted? end |
#approved_manually!(approval) ⇒ Object
APPROVAL
69 70 71 |
# File 'lib/license_finder/package.rb', line 69 def approved_manually!(approval) @manual_approval = approval end |
#approved_manually? ⇒ Boolean
73 74 75 |
# File 'lib/license_finder/package.rb', line 73 def approved_manually? !@manual_approval.nil? end |
#decide_on_license(license) ⇒ Object
133 134 135 |
# File 'lib/license_finder/package.rb', line 133 def decide_on_license(license) @decided_licenses << license end |
#eql?(other) ⇒ Boolean
109 110 111 |
# File 'lib/license_finder/package.rb', line 109 def eql?(other) name == other.name && version == other.version end |
#hash ⇒ Object
113 114 115 |
# File 'lib/license_finder/package.rb', line 113 def hash [name, version].hash end |
#license_files ⇒ Object
143 144 145 |
# File 'lib/license_finder/package.rb', line 143 def license_files LicenseFiles.find(install_path, logger: logger) end |
#licenses ⇒ Object
LICENSING # stubbed in tests, otherwise private # checked in tests, otherwise private
119 120 121 |
# File 'lib/license_finder/package.rb', line 119 def licenses @licenses ||= activations.map(&:license).sort_by(&:name).to_set end |
#licenses_from_spec ⇒ Object
137 138 139 140 141 |
# File 'lib/license_finder/package.rb', line 137 def licenses_from_spec license_names_from_spec .map { |name| License.find_by_name(name) } .to_set end |
#licensing ⇒ Object
129 130 131 |
# File 'lib/license_finder/package.rb', line 129 def licensing Licensing.new(self, @decided_licenses, licenses_from_spec, license_files) end |
#log_activation(activation) ⇒ Object
159 160 161 162 163 164 165 166 167 168 |
# File 'lib/license_finder/package.rb', line 159 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
155 156 157 |
# File 'lib/license_finder/package.rb', line 155 def missing? @missing end |
#notice_files ⇒ Object
147 148 149 |
# File 'lib/license_finder/package.rb', line 147 def notice_files NoticeFiles.find(install_path, logger: logger) end |
#package_manager ⇒ Object
151 152 153 |
# File 'lib/license_finder/package.rb', line 151 def package_manager 'unknown' end |
#permitted! ⇒ Object
84 85 86 |
# File 'lib/license_finder/package.rb', line 84 def permitted! @permitted = true end |
#permitted? ⇒ Boolean
88 89 90 |
# File 'lib/license_finder/package.rb', line 88 def permitted? @permitted end |
#restricted! ⇒ Object
92 93 94 |
# File 'lib/license_finder/package.rb', line 92 def restricted! @restricted = true end |
#restricted? ⇒ Boolean
96 97 98 |
# File 'lib/license_finder/package.rb', line 96 def restricted? @restricted end |