-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
❇️ provide Flutter project scanning support
> through pub package manager > needs to have the proper ENV variable set
- Loading branch information
1 parent
cfbc7d3
commit e739f21
Showing
14 changed files
with
512 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../support/feature_helper' | ||
|
||
describe 'Pubspec Dependencies' do | ||
# As a developer on Flutter platform | ||
# I want to be able to manage Pub Package Manager dependencies | ||
|
||
let(:flutter_developer) { LicenseFinder::TestingDSL::User.new } | ||
|
||
specify 'are shown in reports' do | ||
LicenseFinder::TestingDSL::FlutterProject.create | ||
flutter_developer.run_license_finder | ||
expect(flutter_developer).to be_seeing_line 'device_info, 2.0.3, "New BSD"' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: test_app | ||
description: Test app for Flutter license_finder evolution | ||
|
||
publish_to: 'none' # Remove this line if you wish to publish to pub.dev | ||
|
||
version: 1.0.0+1 | ||
|
||
environment: | ||
sdk: ">=2.12.0 <3.0.0" | ||
|
||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
device_info: ^2.0.3 | ||
|
||
dev_dependencies: | ||
flutter_test: | ||
sdk: flutter | ||
|
||
flutter: | ||
generate: true | ||
# The following line ensures that the Material Icons font is | ||
# included with your application, so that you can use the icons in | ||
# the material Icons class. | ||
uses-material-design: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'json' | ||
|
||
module LicenseFinder | ||
class Pub < PackageManager | ||
class PubError < RuntimeError; end | ||
|
||
def current_packages | ||
unless File.exist?('pubspec.lock') | ||
raise PubError, "No checked-out Pub packages found. | ||
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)" | ||
end | ||
_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'] | ||
homepage = nil | ||
|
||
project_repo = dependency["source"] == "git" ? Pathname("#{ENV["PUB_CACHE"]}/git/#{dependency["name"]}-*/") : Pathname("#{ENV["PUB_CACHE"]}/hosted/pub.dartlang.org/#{subpath}") | ||
|
||
PubPackage.new( | ||
package_name, | ||
package_version, | ||
license_text(project_repo), | ||
logger: logger, | ||
install_path: project_repo, | ||
homepage: homepage, | ||
) | ||
end | ||
end | ||
|
||
def possible_package_paths | ||
[project_path.join("pubspec.lock")] | ||
end | ||
|
||
def package_management_command | ||
'flutter' | ||
end | ||
|
||
def prepare_command | ||
'flutter pub get' | ||
end | ||
|
||
def prepare | ||
prep_cmd = '#{prepare_command} #{production_flag}' | ||
_stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(prep_cmd) } | ||
|
||
return if status.success? | ||
|
||
log_errors stderr | ||
raise "Prepare command '#{prep_cmd}' failed" unless @prepare_no_fail | ||
end | ||
|
||
private | ||
|
||
|
||
def license_text(subpath) | ||
license_path = license_pattern(subpath).find { |f| File.exist?(f) } | ||
license_path.nil? ? nil : IO.read(license_path) | ||
end | ||
|
||
def license_pattern(subpath) | ||
Dir.glob(subpath.join('LICENSE*'), File::FNM_CASEFOLD) | ||
end | ||
|
||
def production_flag | ||
return '' if @ignored_groups.nil? | ||
|
||
@ignored_groups.include?('devDependencies') ? '' : 'no-' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module LicenseFinder | ||
class PubPackage < Package | ||
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 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
# Generated by pub | ||
# See https://dart.dev/tools/pub/glossary#lockfile | ||
packages: | ||
async: | ||
dependency: transitive | ||
description: | ||
name: async | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "2.8.1" | ||
boolean_selector: | ||
dependency: transitive | ||
description: | ||
name: boolean_selector | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "2.1.0" | ||
characters: | ||
dependency: transitive | ||
description: | ||
name: characters | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "1.1.0" | ||
charcode: | ||
dependency: transitive | ||
description: | ||
name: charcode | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "1.3.1" | ||
clock: | ||
dependency: transitive | ||
description: | ||
name: clock | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "1.1.0" | ||
collection: | ||
dependency: transitive | ||
description: | ||
name: collection | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "1.15.0" | ||
device_info: | ||
dependency: "direct main" | ||
description: | ||
name: device_info | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "2.0.3" | ||
device_info_platform_interface: | ||
dependency: transitive | ||
description: | ||
name: device_info_platform_interface | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "2.0.1" | ||
fake_async: | ||
dependency: transitive | ||
description: | ||
name: fake_async | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "1.2.0" | ||
flutter: | ||
dependency: "direct main" | ||
description: flutter | ||
source: sdk | ||
version: "0.0.0" | ||
flutter_test: | ||
dependency: "direct dev" | ||
description: flutter | ||
source: sdk | ||
version: "0.0.0" | ||
matcher: | ||
dependency: transitive | ||
description: | ||
name: matcher | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "0.12.10" | ||
meta: | ||
dependency: transitive | ||
description: | ||
name: meta | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "1.7.0" | ||
path: | ||
dependency: transitive | ||
description: | ||
name: path | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "1.8.0" | ||
plugin_platform_interface: | ||
dependency: transitive | ||
description: | ||
name: plugin_platform_interface | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "2.1.2" | ||
sky_engine: | ||
dependency: transitive | ||
description: flutter | ||
source: sdk | ||
version: "0.0.99" | ||
source_span: | ||
dependency: transitive | ||
description: | ||
name: source_span | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "1.8.1" | ||
stack_trace: | ||
dependency: transitive | ||
description: | ||
name: stack_trace | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "1.10.0" | ||
stream_channel: | ||
dependency: transitive | ||
description: | ||
name: stream_channel | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "2.1.0" | ||
string_scanner: | ||
dependency: transitive | ||
description: | ||
name: string_scanner | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "1.1.0" | ||
term_glyph: | ||
dependency: transitive | ||
description: | ||
name: term_glyph | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "1.2.0" | ||
test_api: | ||
dependency: transitive | ||
description: | ||
name: test_api | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "0.4.2" | ||
typed_data: | ||
dependency: transitive | ||
description: | ||
name: typed_data | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "1.3.0" | ||
vector_math: | ||
dependency: transitive | ||
description: | ||
name: vector_math | ||
url: "https://pub.dartlang.org" | ||
source: hosted | ||
version: "2.1.0" | ||
sdks: | ||
dart: ">=2.12.0 <3.0.0" | ||
flutter: ">=1.12.13+hotfix.5" |
Oops, something went wrong.