diff --git a/library/packages/src/lib/y2packager/license.rb b/library/packages/src/lib/y2packager/license.rb index 07692568f..f5e8b4e2e 100644 --- a/library/packages/src/lib/y2packager/license.rb +++ b/library/packages/src/lib/y2packager/license.rb @@ -19,7 +19,7 @@ module Y2Packager # This class stores the license ID and the traslated content of the license # for different languages. class License - DEFAULT_LANG = "en_US" + DEFAULT_LANG = "en_US".freeze # @return [String] License unique identifier attr_reader :id diff --git a/library/packages/src/lib/y2packager/license_reader.rb b/library/packages/src/lib/y2packager/license_reader.rb index 8b8b0aacd..a70227692 100644 --- a/library/packages/src/lib/y2packager/license_reader.rb +++ b/library/packages/src/lib/y2packager/license_reader.rb @@ -43,7 +43,7 @@ def license content = fetcher.license_content(License::DEFAULT_LANG) return unless content - store.add_license_for(product_name, License.new(:content => content)) + store.add_license_for(product_name, License.new(content: content)) end # Return the license text diff --git a/library/packages/src/lib/y2packager/license_store.rb b/library/packages/src/lib/y2packager/license_store.rb index 553e2247e..602916a5e 100644 --- a/library/packages/src/lib/y2packager/license_store.rb +++ b/library/packages/src/lib/y2packager/license_store.rb @@ -10,29 +10,49 @@ # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # ------------------------------------------------------------------------------ -require 'singleton' +require "singleton" module Y2Packager + # This class is responsible for storing the relation between products and + # licenses. A license could be the same for multiple products and it is + # determined by the license id. class LicenseStore include Singleton attr_reader :product_licenses + # Constructor def initialize @product_licenses = {} end + # Return the license for the given product name + # + # @return [License,nil] def license_for(product_name) @product_licenses[product_name] end + # Stores the given license for the given product name if there is not + # already a license with the same id. In case that there is already a + # license with the same id that license is used and returned instead. + # + # @param product_name [String] + # @param license [License] + # @return [License] The given license or the already stored one with the + # same id. def add_license_for(product_name, license) stored_license = license(license.id) @product_licenses[product_name] = stored_license || license end + private + # Looks for a license with the given id + # + # @param id [String] of the license to be found + # @return [License, nil] a license with the given id or nil if not found def license(id) @product_licenses.values.find { |l| l.id == id } end diff --git a/library/packages/src/lib/y2packager/license_translation.rb b/library/packages/src/lib/y2packager/license_translation.rb index 72ffc3f12..264325f4a 100644 --- a/library/packages/src/lib/y2packager/license_translation.rb +++ b/library/packages/src/lib/y2packager/license_translation.rb @@ -13,11 +13,16 @@ require "yast" module Y2Packager + # This class is responsible for storing the different license translations. class LicenseTranslation # @return [String] Content Language attr_reader :lang attr_reader :content + # Constructor + # + # @param language [String] + # @param content [String] of the license for the given language def initialize(language:, content:) @lang = language @content = content diff --git a/library/packages/src/lib/y2packager/licenses_fetchers/rpm.rb b/library/packages/src/lib/y2packager/licenses_fetchers/rpm.rb index 1ac13a171..89c818730 100644 --- a/library/packages/src/lib/y2packager/licenses_fetchers/rpm.rb +++ b/library/packages/src/lib/y2packager/licenses_fetchers/rpm.rb @@ -14,6 +14,10 @@ module Y2Packager module LicensesFetchers + # This class is responsible for obtaining the license and license content + # of a given product from libzypp. + # + # FIXME: Finish implementation class Rpm < Base # Return the license text to be confirmed # diff --git a/library/packages/src/lib/y2packager/licenses_fetchers/url.rb b/library/packages/src/lib/y2packager/licenses_fetchers/url.rb index 8fb237733..b0c3d58a1 100644 --- a/library/packages/src/lib/y2packager/licenses_fetchers/url.rb +++ b/library/packages/src/lib/y2packager/licenses_fetchers/url.rb @@ -14,10 +14,11 @@ module Y2Packager module LicensesFetchers + # This class reads the licenses from the eula_url product property + # # FIXME: Finish implementation class Url < Base - - def license_content(lang) + def license_content(_lang) "Fetching product license" end diff --git a/library/packages/src/lib/y2packager/product.rb b/library/packages/src/lib/y2packager/product.rb index b95726aaa..da45809e5 100644 --- a/library/packages/src/lib/y2packager/product.rb +++ b/library/packages/src/lib/y2packager/product.rb @@ -220,10 +220,8 @@ def license_content(lang) # # @param lang [String] Language # @return [Boolean] true if the product has a license - def license?(lang) - content = license(lang) - return false unless content - content != "" + def license? + license ? true : false end # Determine whether the license should be accepted or not diff --git a/library/packages/test/y2packager/product_test.rb b/library/packages/test/y2packager/product_test.rb index 2f5f346c5..c5e6ba143 100755 --- a/library/packages/test/y2packager/product_test.rb +++ b/library/packages/test/y2packager/product_test.rb @@ -184,24 +184,25 @@ end end - describe "#license" do - let(:license) { "license content" } + describe "#license_content" do + let(:license_content) { "license content" } let(:lang) { "en_US" } before do allow(Yast::Pkg).to receive(:PrdGetLicenseToConfirm).with(product.name, lang) - .and_return(license) + .and_return(license_content) + allow(product.license_reader).to receive(:license_content).and_return(license_content) end - it "return the license" do - expect(product.license(lang)).to eq(license) + it "return the license content" do + expect(product.license_content(lang)).to eq(license_content) end context "when the no license to confirm was found" do let(:license) { "" } it "return the empty string" do - expect(product.license(lang)).to eq("") + expect(product.license_content(lang)).to eq("") end end @@ -209,47 +210,32 @@ let(:license) { nil } it "return nil" do - expect(product.license(lang)).to be_nil + expect(product.license_content(lang)).to be_nil end end end describe "#license?" do let(:lang) { "en_US" } - let(:license) { "" } + let(:license) { instance_double("Y2Packager::License") } before do allow(product).to receive(:license).and_return(license) end context "when product has a license" do - let(:license) { "license content" } - - it "returns the license content" do - expect(product.license?(lang)).to eq(true) + it "returns true" do + expect(product.license?).to eq(true) end end context "when product does not have a license" do - let(:license) { "" } - - it "returns false" do - expect(product.license?(lang)).to eq(false) - end - end - - context "when product is not found" do let(:license) { nil } - it "returns nil" do - expect(product.license?(lang)).to eq(false) + it "returns false" do + expect(product.license?).to eq(false) end end - - it "asks for the license in the given language" do - expect(product).to receive(:license).with(lang) - product.license?(lang) - end end describe "#license_locales" do