mono0926 / LicensePlist

A license list generator of all your dependencies for iOS applications
https://www.slideshare.net/mono0926/licenseplist-a-license-list-generator-of-all-your-dependencies-for-ios-applications
MIT License
2.43k stars 146 forks source link
automation cli commandline ios license license-management licenses productivity settings swift-package-manager xcode

LicensePlist Logo LicensePlist

platforms GitHub license Language: Swift 5.3 Swift Package Manager compatible

Lint Test

LicensePlist is a command-line tool that automatically generates a Plist of all your dependencies, including files added manually(specified by YAML config file) or using Carthage or CocoaPods. All these licenses then show up in the Settings app.

Flow

Demo

App Setting Root License List License Detail

Installation

Warning
SPM(Swift Package Manager) are not supported.

CocoaPods (Recommended)

pod 'LicensePlist'
# Installation path: `${PODS_ROOT}/LicensePlist/license-plist`

Homebrew (Also Recommended)

brew install licenseplist

Mint (Also Recommended)

mint run mono0926/LicensePlist

Xcode project - SPM

In Project Settings, on the tab "Package Dependencies", click "+" and add https://github.com/mono0926/LicensePlist.

Click "Add Package" without selecting any package products.

Download the executable binary from Releases

Download from Releases, then copy to /usr/local/bin/license-plist etc.

Or you can also download the latest binary and install it with a one-liner.

curl -fsSL https://raw.githubusercontent.com/mono0926/LicensePlist/master/install.sh | sh

From Source

Clone the master branch of the repository, then run make install.

git clone https://github.com/mono0926/LicensePlist.git
make install

Usage

  1. When you are in the directory that contains your Cartfile or Pods, simply execute license-plist.
  2. com.mono0926.LicensePlist.Output directory will be generated.
  3. Move the files in the output directory into your app's Settings.bundle.
Settings.bundle
├── Root.plist
├── com.mono0926.LicensePlist
│   ├── APIKit.plist
│   ├── Alamofire.plist
│   └── EditDistance.plist
├── com.mono0926.LicensePlist.plist
├── en.lproj
│   └── Root.strings
└── ja.lproj
    └── Root.strings

Options

You can see options by license-plist --help.

--cartfile-path

--mintfile-path

--pods-path

--package-path

--package-paths

--package-sources-path

--xcodeproj-path

--xcworkspace-path

--output-path

--github-token

--config-path

--prefix

--html-path

--markdown-path

--csv-path

--license-file-names

--force

--add-version-numbers

License list with versions

--add-sources

--suppress-opening-directory

--single-page

--fail-if-missing-license

--silence-mode / --verbose

--no-color / --color

--sandbox-mode / --no-sandbox-mode

Integrate into build - run script

Add a Run Script Phase to Build Phases:

if [ $CONFIGURATION = "Debug" ]; then
/usr/local/bin/license-plist --output-path $PRODUCT_NAME/Settings.bundle --github-token YOUR_GITHUB_TOKEN
fi

Run Script Phase

Alternatively, if you've installed LicensePlist via CocoaPods the script should look like this:

if [ $CONFIGURATION = "Debug" ]; then
${PODS_ROOT}/LicensePlist/license-plist --output-path $PRODUCT_NAME/Settings.bundle --github-token YOUR_GITHUB_TOKEN
fi

Integrate into build - build tool plugin

LicensePlist build tool plugins requires Swift package installation.

Choose package plugins

Select your target, on the tab "Build Phases", in the section "Run Build Tool Plug-ins", click "+" and add LicensePlistBuildTool.

Run build tool plug-ins

In the case of using the build tool plugin, define all the settings in license_plist.yml at the root of your project.

license_plist.yml example:

options:
  xcworkspacePath: "*.xcworkspace"
  prefix: Acknowledgements
  singlePage: true

Important: to process Swift Package licenses, the config must include one of the following parameters:

Note: outputPath and packageSourcesPath config parameters are ignored by the build tool plugin.

See the configuration section for more information.

If you need to put license files to Settings.bundle or any other specific place add the following script to build phases:

echo "Will copy acknowledgements"
ACKNOWLEDGEMENTS_DIR=${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}/com.mono0926.LicensePlist.Output
DESTINATION_PATH=${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}/Settings.bundle/
cp -r "${ACKNOWLEDGEMENTS_DIR}"/* "${DESTINATION_PATH}"
rm -rf "${ACKNOWLEDGEMENTS_DIR}"

Or in project contextual menu click "AddAcknowledgementsCopyScriptCommand" and select application target to create the build phase automatically.

AddAcknowledgementsCopyScriptCommand

Build the app. At the first run, Xcode asks a permission to run the plugin. Click "Trust & Enable All"

Trust & Enable All

For unattended use (e.g. on CI), you can disable the package validation dialog by

Note: This implicitly trusts all Xcode package plugins and bypasses Xcode's package validation dialogs, which has security implications.

Contextual menu command

LicensePlist command requires Swift package installation.

In the project contextual menu click "GenerateAcknowledgementsCommand".

Generate Acknowledgements menu command in Xcode

The command dialog allows to specify command line arguments. Since Xcode doesn't save the arguments for future use, it's recommended to use a configuration file.

Click "Run" to run LicensePlist.

Generate Acknowledgements command dialog in Xcode

Click "Allow Command to Change files". This action provides LicensePlist write access to your project directory.

"Don't ask again" option prevents showing this dialog in the future.

Allow command to change files dialog in Xcode

Note: --package-sources-path option and packageSourcesPath config parameter are ignored by the command plugin.

Configuration

General options

The main parameters from the Options can be defined in the configuration file.

All the parameters are optional.

The tool uses the command line value if both the command line and the config specify values for the same attribute.

Example

options:
  outputPath: "./com.mono0926.LicensePlist.Output"
  cartfilePath: Cartfile
  mintfilePath: Mintfile
  podsPath: Pods
  packagePaths:
    - Package.swift
  packageSourcesPath: "./SourcePackages"
  xcodeprojPath: "*.xcodeproj"
  xcworkspacePath: "*.xcworkspace"
  prefix: com.mono0926.LicensePlist
  gitHubToken: YOUR_GITHUB_TOKEN
  htmlPath: acknowledgements.html
  markdownPath: acknowledgements.md
  licenseFileNames:
    - LICENSE
    - LICENSE.*
  force: false
  addVersionNumbers: false
  suppressOpeningDirectory: false
  singlePage: false
  failIfMissingLicense: false
  addSources: false
  sandboxMode: false

Manual GitHub source

A GitHub source can be explicitly defined to include the license in the scenario where it can't be inferred from your dependency files.

Examples

github:
  - owner: mono0926
    name: LicensePlist
    version: 1.2.0

Manual License Body

If you need to include a license that isn't available on GitHub, you can place the license text in the config file to be included in the output. The license text can also be read from a local file, to keep the config file clean.

Examples

License body directly in the config file:

manual:
  - source: https://webrtc.googlesource.com/src
    name: WebRTC
    version: M61
    body: |-
      Copyright (c) 2011, The WebRTC project authors. All rights reserved.
      ...
      ...
      ...

License body in local file:

manual:
  - name: "Dummy License File"
    file: "dummy_license.txt"

Excludes

Excludes can be defined to exclude matching libraries from the final output. An exclude is a dictionary containing any combination of name, source, owner, or licenseType.

When using the dictionary format:

Examples

Exclude a package by name:

exclude:
  - name: LicensePlist

Exclude packages using a specific license:

exclude:
  - licenseType: "Apache 2.0"

Exclude packages using any matching licenses:

exclude:
  - licenseType: /BSD/

Exclude packages from a specific github owner:

exclude:
  - owner: mycompany

Exclude packages from a specific github owner containing matching licenses:

exclude:
  - owner: mycompany
    licenseType: /^(?!.*MIT).*$/ # this regex excludes packages that do NOT use the MIT license

Exclude a package from a specific github owner and repo:

exclude:
  - owner: mycompany
    name: private-repo

Rename

If a library name is unsuitable for the output bundle, you can explicitly rename it. This can be used when a library name is too vague, or if more human-readable names are needed.

Examples

rename:
  LicensePlist: License Plist # Rename LicensePlist to "License Plist"
  WebRTC: Web RTC # Rename WebRTC to "Web RTC" (which is faulty, but used for test)

Q&A

How to generate Xcode project?

Execute swift package generate-xcodeproj or make xcode.


Related Articles


Stargazers over time

Stargazers over time


寄付(Donation)

Donations are welcome if you like LicensePlist🤗

Send Money by ウォレットアプリ Kyash

Kyash