dart_oss_licenses 0.5.1

dart_oss_licenses #

CLI tool that generate OSS license list of dart used in your project.

Getting Started #

install Dart SDK.

For example, if you are using homebrew with mac.

$ brew tap dart-lang/dart
$ brew install dart

inatall dart-oss-licenses.

$ pub global activate dart_oss_licenses

run in your project root (exists pubspec.lock). But you have task to do before that.

$ cd <your project root>
$ dart-oss-licenses

For ios #

In ios, it is realized with settings.bundle. So make it.

On Menu of Xcode
File -> New -> File... -> Select Settings.bundle -> Next -> Create as <Project>/ios/Runner/Settings.bundle

Then Rewrite Root.plist as follows.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>PreferenceSpecifiers</key>
	<array>
		<dict>
			<key>Type</key>
			<string>PSChildPaneSpecifier</string>
			<key>Title</key>
			<string>Licenses</string>
			<key>File</key>
			<string>com.ko2ic.dart-oss-licenses</string>
		</dict>
	</array>
	<key>StringsTable</key>
	<string>Root</string>
</dict>
</plist>

en.lproj/Root.strings

"Licenses" = "Licenses";

By doing this, the above command will succeed.

Application Code #

In order to transition from the application, write the following.

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    private var _result: FlutterResult?

    override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
    ) -> Bool {
        let controller: FlutterViewController = window?.rootViewController as! FlutterViewController
        let channel = FlutterMethodChannel(name: "sample/platform",
                                                 binaryMessenger: controller)
        channel.setMethodCallHandler({
            (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
            switch call.method {
            case "toOssLicense":
                if let url = URL(string: UIApplicationOpenSettingsURLString) {
                    if #available(iOS 10.0, *) {
                        UIApplication.shared.open(url, options: [:], completionHandler: nil)
                    } else {
                        UIApplication.shared.openURL(url)
                    }
                }
            default:
                result(FlutterMethodNotImplemented)
                break
            }
        })
        GeneratedPluginRegistrant.register(with: self)
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
}

For OSS used in native #

dart_oss_licenses supports dart's OSS only.
So native needs to use another tool for ios.

The recommendation is LicensePlist.
It also supports CocoaPods, Carthage and Manual(Git SubModule, direct sources and so on).

Merge results of dart_oss_licenses and LicensePlist.

For Android #

Currently, only AboutLibraries is supported.

Run command then generated in /android/app/src/main/res/values/license_strings.xml.

If it already exists, generated in /android/app/src/main/res/values/license_strings.xml.temp.

Since license_strings.xml is not perfect in some cases, you need to complete it yourself.

If the tool fails to acquire information, it is written TODO, so you can search for it and fix it.

Application Code #

android/app/build.gradle

dependencies {
    implementation "com.mikepenz:aboutlibraries:6.1.1"

Replace

class MainActivity() : FlutterActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        GeneratedPluginRegistrant.registerWith(this)

        MethodChannel(
            flutterView,
            "sample/platform"
        ).setMethodCallHandler { call: MethodCall, result: MethodChannel.Result ->
            when (call.method) {
                "toOssLicense" -> {
                    LibsBuilder()
                        .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR)
                        .withActivityTitle("Licenses")
                        .withLicenseShown(true)
                        .withLibraries(
                            <package name>
                        )
                        //start the activity
                        .start(this)
                }
            }
        }
    }
}

Dart #

Finally you can complete the following method with ui.

  static const platform = const MethodChannel('sample/platform');

  Future<void> toOssLicense() {
    return platform.invokeMethod('toOssLicense', {});
  }

Contributing #

Anything, such as corresponding to other formats, is happy. Please feel free Pull Request.

How to create other format #

Please refer to formats package and implement the FormatHoldable interface.

then add a instance in formats/format_kind.dart.

 List<FormatHoldable> instanceAllFormats() {
   return [
     AboutLibrariesFormat(),
     SettingsBundlePlistFormat(),
+    SomethingFormat(),
   ];
 }

0.5.1 #

  • Fix documents.

0.5.0 #

  • Public Release

example/README.md

Example #

Please read README.md.

Use this package as an executable

1. Install it

You can install the package from the command line:


$ pub global activate dart_oss_licenses

2. Use it

The package has the following executables:


$ dart-oss-licenses
Popularity:
Describes how popular the package is relative to other packages. [more]
12
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

We analyzed this package on Jul 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in libraries.

Health suggestions

Fix bin/http/http_exception.dart. (-1 points)

Analysis of bin/http/http_exception.dart reported 2 hints:

line 6 col 17: Don't type annotate initializing formals.

line 6 col 35: Don't type annotate initializing formals.

Fix bin/formats/commons/format_holdable.dart. (-0.50 points)

Analysis of bin/formats/commons/format_holdable.dart reported 1 hint:

line 28 col 7: Use rethrow to rethrow a caught exception.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (html).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
html ^0.13.3+3 0.13.4+2 0.14.0+2
http ^0.12.0 0.12.0+2
meta ^1.1.6 1.1.7
tuple ^1.0.2 1.0.2
yaml ^2.1.15 2.1.16
Transitive dependencies
async 2.2.0
charcode 1.1.2
collection 1.14.11
csslib 0.15.0 0.16.1
http_parser 3.1.3
matcher 0.12.5
path 1.6.2
pedantic 1.8.0+1
quiver 2.0.3
source_span 1.5.5
stack_trace 1.9.3
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
utf 0.9.0+5
Dev dependencies
test ^1.0.0

Admin