Skip to content

Commit

Permalink
💄 fix coding-style
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennecadicidean committed Jan 26, 2022
1 parent 43280d2 commit 042cc61
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 32 deletions.
3 changes: 1 addition & 2 deletions features/support/testing_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,11 @@ def add_dep
end

def install
ENV['PUB_CACHE'] = "~/flutter/.pub-cache/"
ENV['PUB_CACHE'] = '~/flutter/.pub-cache/'
shell_out('flutter pub get')
end
end


class ConanProject < Project
def add_dep
install_fixture('conanfile.txt')
Expand Down
1 change: 0 additions & 1 deletion lib/license_finder/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,3 @@ def log_activation(activation)
require 'license_finder/packages/composer_package'
require 'license_finder/packages/conda_package'
require 'license_finder/packages/pubspec_package'

32 changes: 14 additions & 18 deletions lib/license_finder/package_managers/pub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,34 @@ def current_packages
Please install your dependencies first."
end

unless !(ENV["PUB_CACHE"].nil? || ENV["PUB_CACHE"].empty?)
raise PubError, "While PUB_CACHE environment variable is empty, retrieving package licenses is impossible. Please set the PUB_CACHE env variable (default: ~/.pub)"
if ENV['PUB_CACHE'].nil? || ENV['PUB_CACHE'].empty?
raise PubError, 'While PUB_CACHE environment variable is empty, retrieving package licenses is impossible. Please set the PUB_CACHE env variable (default: ~/.pub)'
end
_stdout, stderr, status = Cmd.run("flutter pub deps --json")
yaml_deps = JSON.parse(_stdout)
yaml_deps["packages"].map do |dependency|

stdout, _stderr, _status = Cmd.run('flutter pub deps --json')
yaml_deps = JSON.parse(stdout)
yaml_deps['packages'].map do |dependency|
package_name = dependency['name']
subpath = "#{dependency['name']}-#{dependency['version']}"
package_version = dependency['version']
project_repo = dependency["source"] == "git" ? Pathname("#{ENV["PUB_CACHE"]}/git/#{dependency["name"]}-*/") : Pathname("#{ENV["PUB_CACHE"]}/hosted/pub.dartlang.org/#{subpath}")

project_repo = dependency['source'] == 'git' ? Pathname("#{ENV['PUB_CACHE']}/git/#{dependency['name']}-*/") : Pathname("#{ENV['PUB_CACHE']}/hosted/pub.dartlang.org/#{subpath}")

homepage = read_repository_home(project_repo)
if homepage.nil? || homepage.empty?
homepage = "https://pub.dev/packages/#{package_name}"
end
homepage = "https://pub.dev/packages/#{package_name}" if homepage.nil? || homepage.empty?
PubPackage.new(
package_name,
package_version,
license_text(project_repo),
logger: logger,
install_path: project_repo,
homepage: homepage,
homepage: homepage
)
end
end

def possible_package_paths
[project_path.join("pubspec.lock")]
[project_path.join('pubspec.lock')]
end

def package_management_command
Expand All @@ -64,7 +63,6 @@ def prepare

private


def license_text(subpath)
license_path = license_pattern(subpath).find { |f| File.exist?(f) }
license_path.nil? ? nil : IO.read(license_path)
Expand All @@ -81,10 +79,8 @@ def production_flag
end

def read_repository_home(project_repo)
package_yaml = project_repo.join("pubspec.yaml")
if File.exist?(package_yaml)
YAML.load(IO.read(package_yaml))["repository"]
end
end
package_yaml = project_repo.join('pubspec.yaml')
YAML.load(IO.read(package_yaml))['repository'] if File.exist?(package_yaml)
end
end
end
4 changes: 2 additions & 2 deletions lib/license_finder/packages/pubspec_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ def initialize(name, version, license_text, options = {})
super(name, version, options)
@license = License.find_by_text(license_text.to_s)
end

def licenses_from_spec
[@license].compact
end

def package_manager
'Pub'
end
Expand Down
20 changes: 11 additions & 9 deletions spec/lib/license_finder/package_managers/pub_package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module LicenseFinder
let(:root) { '/fake-pub-project' }
let(:project_path) { fixture_path('all_pms') }
let(:pub) { Pub.new(project_path: project_path) }
let(:new_bsd_common_text) { "Redistribution and use in source and binary forms, with or without
let(:new_bsd_common_text) do
"Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
Expand All @@ -28,7 +29,8 @@ module LicenseFinder
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." }
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
end

it_behaves_like 'a PackageManager'

Expand Down Expand Up @@ -56,12 +58,12 @@ def stub_license_md(hash = {})
end
end

let(:dependency_json) do
let(:dependency_json) do
FakeFS.without do
fixture_from('pub_deps.json')
end
end

before do
allow(IO).to receive(:read).and_call_original
allow(File).to receive(:exist?).and_return(false)
Expand All @@ -73,19 +75,19 @@ def stub_license_md(hash = {})
allow(File).to receive(:exist?).and_return(true)
allow(SharedHelpers::Cmd).to receive(:run).with('flutter pub deps --json')
.and_return([dependency_json, '', cmd_success])
allow(ENV).to receive(:[]).with('PUB_CACHE').and_return(project_path.join('.pub'))
allow(ENV).to receive(:[]).with('PUB_CACHE').and_return(project_path.join('.pub'))
end

it 'lists all the current packages' do
expect(pub.current_packages.map { |p| [p.name, p.version] }).to eq [
["flutter", "0.0.0"],
["device_info", "2.0.3"]
['flutter', '0.0.0'],
['device_info', '2.0.3']
]
end

it 'passes the license text to the package' do
stub_license_md("device_info-2.0.3" => new_bsd_common_text)
expect(pub.current_packages.last.licenses.map(&:name)).to eq ["New BSD"]
stub_license_md('device_info-2.0.3' => new_bsd_common_text)
expect(pub.current_packages.last.licenses.map(&:name)).to eq ['New BSD']
end

it 'handles no licenses' do
Expand Down

0 comments on commit 042cc61

Please sign in to comment.