diff --git a/README.md b/README.md index a8dca6e..bde7cea 100644 --- a/README.md +++ b/README.md @@ -32,25 +32,24 @@ Run `mix licenses` to get the list of packages and their licenses: ```shell $ mix licenses -+---------------------+---------+--------------------------------------------------------+ -| Package | Version | License | -+---------------------+---------+--------------------------------------------------------+ -| certifi | | BSD | -| earmark | 1.3.2 | Apache 2.0 | -| ex_doc | 0.20.2 | Apache 2.0 | -| excoveralls | | Unsure (found: MIT, Unrecognized license file content) | -| hackney | | Apache 2.0 | -| idna | | Unsure (found: BSD, MIT) | -| jason | | Apache 2.0 | -| makeup | 0.8.0 | Unsure (found: BSD, Unrecognized license file content) | -| makeup_elixir | 0.13.0 | BSD | -| metrics | | BSD | -| mimerl | | MIT | -| nimble_parsec | 0.5.0 | Apache 2.0 | -| ssl_verify_fun | | MIT | -| table_rex | 2.0.0 | MIT | -| unicode_util_compat | | Unsure (found: Apache 2.0, BSD) | -+---------------------+---------+--------------------------------------------------------+ +Notice: This is not a legal advice. Use the information below at your own risk. +| Package | License | Version | Link | +|---------------------|---------------------------|---------|---------------------------------------------| +| certifi | BSD | | https://hex.pm/packages/certifi | +| earmark | Apache 2.0 | 1.3.2 | https://hex.pm/packages/earmark | +| ex_doc | Apache 2.0 | 0.20.2 | https://hex.pm/packages/ex_doc | +| excoveralls | MIT | | https://hex.pm/packages/excoveralls | +| hackney | Apache 2.0 | | https://hex.pm/packages/hackney | +| idna | BSD; MIT | | https://hex.pm/packages/idna | +| jason | Apache 2.0 | | https://hex.pm/packages/jason | +| makeup | BSD; Unrecognized license | 0.8.0 | https://hex.pm/packages/makeup | +| makeup_elixir | BSD | 0.13.0 | https://hex.pm/packages/makeup_elixir | +| metrics | BSD | | https://hex.pm/packages/metrics | +| mimerl | MIT | | https://hex.pm/packages/mimerl | +| nimble_parsec | Apache 2.0 | 0.5.0 | https://hex.pm/packages/nimble_parsec | +| ssl_verify_fun | MIT | | https://hex.pm/packages/ssl_verify_fun | +| unicode_util_compat | Apache 2.0; BSD | | https://hex.pm/packages/unicode_util_compat | +|---------------------|---------------------------|---------|---------------------------------------------| ``` Run `mix licenses --csv` to output in csv format: @@ -74,7 +73,8 @@ unicode_util_compat,,"Unsure (found: Apache 2.0, BSD)" ``` ### Flags -* `--top-level-only` - Only fetch license information from top level dependencies (e.g. packages that are directly listed in your application's `mix.exs`). Excludes transitive dependencies. + +- `--top-level-only` - Only fetch license information from top level dependencies (e.g. packages that are directly listed in your application's `mix.exs`). Excludes transitive dependencies. ## Usage as a library diff --git a/lib/licensir/file_analyzer.ex b/lib/licensir/file_analyzer.ex index 606857f..d11c801 100644 --- a/lib/licensir/file_analyzer.ex +++ b/lib/licensir/file_analyzer.ex @@ -1,10 +1,16 @@ defmodule Licensir.FileAnalyzer do # The file names to check for licenses - @license_files ["LICENSE", "LICENSE.md", "LICENSE.txt"] + @license_files ["LICENSE", "LICENSE.md", "LICENSE.txt", "LICENCE"] # The files that contain the actual text for each license @files [ - apache2: ["Apache2_text.txt", "Apache2_text.variant-2.txt", "Apache2_url.txt"], + agpl_v3: ["AGPLv3.txt"], + apache2: [ + "Apache2_text.txt", + "Apache2_text.variant-2.txt", + "Apache2_text.variant-3.txt", + "Apache2_url.txt" + ], bsd: ["BSD-3.txt", "BSD-3.variant-2.txt"], cc0: ["CC0-1.0.txt"], gpl_v2: ["GPLv2.txt"], @@ -12,17 +18,19 @@ defmodule Licensir.FileAnalyzer do isc: ["ISC.txt", "ISC.variant-2.txt"], lgpl: ["LGPL.txt"], mit: ["MIT.txt", "MIT.variant-2.txt", "MIT.variant-3.txt"], - mpl2: ["MPL2.txt"], + mpl2: ["MPL2.txt", "MPL2b.txt"], licensir_mock_license: ["LicensirMockLicense.txt"] ] def analyze(dir_path) do + Enum.find_value(@license_files, fn file_name -> dir_path |> Path.join(file_name) |> File.read() |> case do - {:ok, content} -> analyze_content(content) + {:ok, content} -> + analyze_content(content) {:error, _} -> nil end end) @@ -30,23 +38,36 @@ defmodule Licensir.FileAnalyzer do # Returns the first license that matches defp analyze_content(content) do + content = clean(content) + Enum.find_value(@files, fn {license, license_files} -> found = Enum.find(license_files, fn license_file -> - license = + license_text = :licensir |> :code.priv_dir() |> Path.join("licenses") |> Path.join(license_file) |> File.read!() + |> clean() # Returns true only if the content is a superset of the license text - clean(content) =~ clean(license) + content =~ license_text end) if found, do: license, else: nil - end) || :unrecognized_license_file + end) || unrecognised(content) + end + + defp unrecognised(_content) do + :unrecognized_license_file end - defp clean(content), do: String.replace(content, ~r/\v/, "") + def clean(content), + do: + content + |> String.replace("\n", " ") + |> String.replace(~r/\s\s+/, " ") + |> String.trim() + |> String.downcase() end diff --git a/lib/licensir/guesser.ex b/lib/licensir/guesser.ex index d6ad374..17c7751 100644 --- a/lib/licensir/guesser.ex +++ b/lib/licensir/guesser.ex @@ -17,12 +17,13 @@ defmodule Licensir.Guesser do Map.put(license, :license, conclusion) end + defp guess(file, ""), do: guess(file, nil) defp guess(nil, nil), do: "Undefined" defp guess(nil, file), do: file - defp guess(hex, nil) when length(hex) > 0, do: Enum.join(hex, ", ") + defp guess(hex, nil) when length(hex) > 0, do: Enum.join(hex, "; ") defp guess(hex, file) when length(hex) == 1 and hd(hex) == file, do: file defp guess(hex, file) do - "Unsure (found: " <> Enum.join(hex, ", ") <> ", " <> file <> ")" + Enum.join(hex, "; ") <> "; " <> file end end diff --git a/lib/licensir/license.ex b/lib/licensir/license.ex index b2dba3d..8769981 100644 --- a/lib/licensir/license.ex +++ b/lib/licensir/license.ex @@ -18,6 +18,7 @@ defmodule Licensir.License do name: "", version: nil, dep: nil, + link: nil, license: nil, certainty: 0.0, mix: nil, @@ -30,6 +31,7 @@ defmodule Licensir.License do version: String.t() | nil, dep: Mix.Dep.t(), license: String.t() | nil, + link: String.t() | nil, certainty: float(), mix: list(String.t()) | nil, hex_metadata: list(String.t()) | nil, diff --git a/lib/licensir/scanner.ex b/lib/licensir/scanner.ex index 4ceaef4..7351fdd 100644 --- a/lib/licensir/scanner.ex +++ b/lib/licensir/scanner.ex @@ -5,17 +5,18 @@ defmodule Licensir.Scanner do alias Licensir.{License, FileAnalyzer, Guesser} @human_names %{ - apache2: "Apache 2", + agpl_v3: "AGPL v3", + apache2: "Apache 2.0", bsd: "BSD", - cc0: "CC0-1.0", - gpl_v2: "GPLv2", - gpl_v3: "GPLv3", + cc0: "CC0 1.0", + gpl_v2: "GPL v2", + gpl_v3: "GPL v3", isc: "ISC", lgpl: "LGPL", mit: "MIT", - mpl2: "MPL2", + mpl2: "MPL 2.0", licensir_mock_license: "Licensir Mock License", - unrecognized_license_file: "Unrecognized license file content" + unrecognized_license_file: "Unrecognized license" } @doc """ @@ -51,10 +52,12 @@ defmodule Licensir.Scanner do defp to_struct(deps) when is_list(deps), do: Enum.map(deps, &to_struct/1) defp to_struct(%Mix.Dep{} = dep) do + %License{ app: dep.app, name: Atom.to_string(dep.app), version: get_version(dep), + link: get_link(dep.opts), dep: dep } end @@ -68,13 +71,22 @@ defmodule Licensir.Scanner do end defp get_version(%Mix.Dep{status: {:ok, version}}), do: version + defp get_version(%Mix.Dep{requirement: version}), do: version defp get_version(_), do: nil + defp get_link(%{opts: opts}) when is_list(opts), do: get_link(Enum.into(opts, %{})) + defp get_link(opts) when is_list(opts), do: get_link(Enum.into(opts, %{})) + defp get_link(%{git: url}), do: url + defp get_link(%{hex: hex}), do: "https://hex.pm/packages/#{hex}" + defp get_link(%{lock: {:git, url, _, _}}), do: url + defp get_link(_), do: nil + # # Search in hex_metadata.config # - defp search_hex_metadata(licenses) when is_list(licenses), do: Enum.map(licenses, &search_hex_metadata/1) + defp search_hex_metadata(licenses) when is_list(licenses), + do: Enum.map(licenses, &search_hex_metadata/1) defp search_hex_metadata(%License{} = license) do Map.put(license, :hex_metadata, search_hex_metadata(license.dep)) @@ -107,6 +119,7 @@ defmodule Licensir.Scanner do end defp search_file(%Mix.Dep{} = dep) do + license_atom = Mix.Dep.in_dependency(dep, fn _ -> case File.cwd() do diff --git a/lib/mix/tasks/licenses.ex b/lib/mix/tasks/licenses.ex index 2ff4ae4..41b2580 100644 --- a/lib/mix/tasks/licenses.ex +++ b/lib/mix/tasks/licenses.ex @@ -9,45 +9,93 @@ defmodule Mix.Tasks.Licenses do """ use Mix.Task + @output_file "DEPENDENCIES.md" @shortdoc "Lists each dependency's licenses" @recursive true @switches [ top_level_only: :boolean, - csv: :boolean + csv: :boolean, + only_license: :boolean ] def run(argv) do {opts, _argv} = OptionParser.parse!(argv, switches: @switches) Licensir.Scanner.scan(opts) - |> Enum.sort_by(fn license -> license.name end) - |> Enum.map(&to_row/1) + |> Enum.sort_by(fn lib -> lib.name end) + |> Enum.map(&to_row(&1, opts)) |> render(opts) end - defp to_row(map) do - [map.name, map.version, map.license] + defp to_row(map, opts) do + if Keyword.get(opts, :only_license), + do: [map.name, map.license], + else: [map.name, map.license, map.version, map.link] end defp render(rows, opts) do + if Keyword.get(opts, :only_license), + do: render(rows, opts, ["Package", "License"]), + else: render(rows, opts, ["Package", "License", "Version", "Link"]) + end + + defp render(rows, opts, headers) do cond do - Keyword.get(opts, :csv) -> render_csv(rows) - true -> render_ascii_table(rows) + Keyword.get(opts, :csv) -> + render_csv(rows, headers) + + true -> + render_ascii_table(rows, headers) end end - defp render_ascii_table(rows) do - _ = Mix.Shell.IO.info([:yellow, "Notice: This is not a legal advice. Use the information below at your own risk."]) + defp render_ascii_table(rows, headers) do + _ = + Mix.Shell.IO.info([ + :yellow, + "Notice: This is not a legal advice. Use the generated licensing information at your own risk." + ]) rows - |> TableRex.quick_render!(["Package", "Version", "License"]) - |> IO.puts() + |> TableRex.quick_render!(headers) + |> file_touch() + |> output() end - defp render_csv(rows) do + defp render_csv(rows, headers) do rows - |> List.insert_at(0, ["Package", "Version", "License"]) + |> List.insert_at(0, headers) |> Licensir.CSV.encode() - |> Enum.each(&IO.write/1) + |> file_touch() + |> Enum.each(&output/1) + end + + defp file_touch(text) do + if @output_file do + with {:ok, file} <- File.open(@output_file, [:write]) do + # IO.puts("\n\nSaving the output to " <> @output_file) + IO.binwrite(file, "\n") + text + else + _e -> + _ = + Mix.Shell.IO.info([ + :yellow, + "WARNING: Could not write to " <> @output_file + ]) + + nil + end + end + end + + defp output(text) do + filewriter = fn filename, data -> + File.open(filename, [:append]) + |> elem(1) + |> IO.binwrite(data) + end + + if @output_file, do: filewriter.(@output_file, text) end end diff --git a/lib/table_rex/renderer/text.ex b/lib/table_rex/renderer/text.ex index f8427b6..8b361f2 100755 --- a/lib/table_rex/renderer/text.ex +++ b/lib/table_rex/renderer/text.ex @@ -26,7 +26,7 @@ defmodule TableRex.Renderer.Text do vertical_style: :all, horizontal_symbol: "-", vertical_symbol: "|", - intersection_symbol: "+", + intersection_symbol: "|", top_frame_symbol: "-", title_separator_symbol: "-", header_separator_symbol: "-", @@ -77,7 +77,6 @@ defmodule TableRex.Renderer.Text do rendered = {table, meta, opts, []} - |> render_top_frame |> render_title |> render_title_separator |> render_header diff --git a/mix.lock b/mix.lock index d0bdaae..35891eb 100644 --- a/mix.lock +++ b/mix.lock @@ -1,19 +1,19 @@ %{ - "certifi": {:hex, :certifi, "2.0.0", "a0c0e475107135f76b8c1d5bc7efb33cd3815cb3cf3dea7aefdd174dabead064", [:rebar3], [], "hexpm"}, - "earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm"}, - "ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"}, - "excoveralls": {:hex, :excoveralls, "0.9.0", "dd597ccf119aa0be0c1c6681215df588596397833b8dd010fe3d1a48090f3119", [:mix], [{:hackney, ">= 0.12.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"}, + "certifi": {:hex, :certifi, "2.0.0", "a0c0e475107135f76b8c1d5bc7efb33cd3815cb3cf3dea7aefdd174dabead064", [:rebar3], [], "hexpm", "fdc6066ceeccb3aa14049ab6edf0b9af3b64ae1b0db2a92d5c52146f373bbb1c"}, + "earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm", "e3be2bc3ae67781db529b80aa7e7c49904a988596e2dbff897425b48b3581161"}, + "ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "8e24fc8ff9a50b9f557ff020d6c91a03cded7e59ac3e0eec8a27e771430c7d27"}, + "excoveralls": {:hex, :excoveralls, "0.9.0", "dd597ccf119aa0be0c1c6681215df588596397833b8dd010fe3d1a48090f3119", [:mix], [{:hackney, ">= 0.12.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8d53498b4950f5a04fccd4d203c964b78e77d6459efc1dc418347628f9672788"}, "exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"}, - "hackney": {:hex, :hackney, "1.11.0", "4951ee019df102492dabba66a09e305f61919a8a183a7860236c0fde586134b6", [:rebar3], [{:certifi, "2.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, - "idna": {:hex, :idna, "5.1.0", "d72b4effeb324ad5da3cab1767cb16b17939004e789d8c0ad5b70f3cea20c89a", [:rebar3], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"}, - "jason": {:hex, :jason, "1.0.0", "0f7cfa9bdb23fed721ec05419bcee2b2c21a77e926bce0deda029b5adc716fe2", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"}, + "hackney": {:hex, :hackney, "1.11.0", "4951ee019df102492dabba66a09e305f61919a8a183a7860236c0fde586134b6", [:rebar3], [{:certifi, "2.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "bb3cc62ecc10145f8f0965c05083a5278eae7ef1853d340cc9a7a3e27609b9bd"}, + "idna": {:hex, :idna, "5.1.0", "d72b4effeb324ad5da3cab1767cb16b17939004e789d8c0ad5b70f3cea20c89a", [:rebar3], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fc1a2f7340c422650504b1662f28fdf381f34cbd30664e8491744e52c9511d40"}, + "jason": {:hex, :jason, "1.0.0", "0f7cfa9bdb23fed721ec05419bcee2b2c21a77e926bce0deda029b5adc716fe2", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b96c400e04b7b765c0854c05a4966323e90c0d11fee0483b1567cda079abb205"}, "jsx": {:hex, :jsx, "2.8.3", "a05252d381885240744d955fbe3cf810504eb2567164824e19303ea59eef62cf", [:mix, :rebar3], [], "hexpm"}, - "makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"}, - "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"}, - "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"}, - "nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"}, - "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"}, + "makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5fbc8e549aa9afeea2847c0769e3970537ed302f93a23ac612602e805d9d1e7f"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "adf0218695e22caeda2820eaba703fa46c91820d53813a2223413da3ef4ba515"}, + "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, + "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm", "7a4c8e1115a2732a67d7624e28cf6c9f30c66711a9e92928e745c255887ba465"}, + "nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm", "5c040b8469c1ff1b10093d3186e2e10dbe483cd73d79ec017993fb3985b8a9b3"}, + "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm", "4f8805eb5c8a939cf2359367cb651a3180b27dfb48444846be2613d79355d65e"}, "table_rex": {:hex, :table_rex, "2.0.0", "712783cbc2decb4d644d2ab8ad9315294f960c41b2cf0539308164922e352084", [:mix], [], "hexpm"}, - "unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm"}, + "unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm", "da1d9bef8a092cc7e1e51f1298037a5ddfb0f657fe862dfe7ba4c5807b551c29"}, } diff --git a/priv/licenses/AGPLv3.txt b/priv/licenses/AGPLv3.txt new file mode 100755 index 0000000..d8e940a --- /dev/null +++ b/priv/licenses/AGPLv3.txt @@ -0,0 +1 @@ +Version 3, 19 November 2007 \ No newline at end of file diff --git a/priv/licenses/Apache2_text.txt b/priv/licenses/Apache2_text.txt index 597d130..9620d5b 100644 --- a/priv/licenses/Apache2_text.txt +++ b/priv/licenses/Apache2_text.txt @@ -1 +1 @@ -Licensed under the Apache License, Version 2.0 +Apache License, Version 2.0 diff --git a/priv/licenses/Apache2_text.variant-3.txt b/priv/licenses/Apache2_text.variant-3.txt new file mode 100644 index 0000000..5410b6a --- /dev/null +++ b/priv/licenses/Apache2_text.variant-3.txt @@ -0,0 +1 @@ +Apache License 2.0 \ No newline at end of file diff --git a/priv/licenses/MPL2.txt b/priv/licenses/MPL2.txt index d668e96..e0abaa6 100755 --- a/priv/licenses/MPL2.txt +++ b/priv/licenses/MPL2.txt @@ -1 +1 @@ -Mozilla Public License, version 2.0 +Mozilla Public License, version 2.0 \ No newline at end of file diff --git a/priv/licenses/MPL2b.txt b/priv/licenses/MPL2b.txt new file mode 100755 index 0000000..7cad725 --- /dev/null +++ b/priv/licenses/MPL2b.txt @@ -0,0 +1 @@ +Mozilla Public License Version 2 \ No newline at end of file diff --git a/test/licensir/guesser_test.exs b/test/licensir/guesser_test.exs index 4bdd49c..2100033 100644 --- a/test/licensir/guesser_test.exs +++ b/test/licensir/guesser_test.exs @@ -36,7 +36,7 @@ defmodule Licensir.GuesserTest do file: "License Two" } - assert Guesser.guess(license).license == "Unsure (found: License One, License Two)" + assert Guesser.guess(license).license == "License One; License Two" end test "returns unsure if there are multiple licenses in hex_metadata and also one definted in file" do @@ -46,7 +46,7 @@ defmodule Licensir.GuesserTest do } assert Guesser.guess(license).license == - "Unsure (found: License One, License Two, License Three)" + "License One; License Two; License Three" end test "returns Undefined if no license data is found" do diff --git a/test/mix/tasks/licenses_test.exs b/test/mix/tasks/licenses_test.exs index e8b7fae..649ea5f 100644 --- a/test/mix/tasks/licenses_test.exs +++ b/test/mix/tasks/licenses_test.exs @@ -5,28 +5,46 @@ defmodule Licensir.Mix.Tasks.LicensesTest do test "prints a list of dependencies and their licenses" do output = capture_io(fn -> - Mix.Tasks.Licenses.run([]) + Mix.Tasks.Licenses.run(["--only_license=true"]) end) expected = IO.ANSI.format_fragment([ - [:yellow, "Notice: This is not a legal advice. Use the information below at your own risk."], :reset, "\n", - "+-----------------------------------+---------+----------------------------------------------------+", "\n", - "| Package | Version | License |", "\n", - "+-----------------------------------+---------+----------------------------------------------------+", "\n", - "| dep_license_undefined | | Undefined |", "\n", - "| dep_of_dep | | Undefined |", "\n", - "| dep_one_license | | Licensir Mock License |", "\n", - "| dep_one_unrecognized_license_file | | Unrecognized license file content |", "\n", - "| dep_two_conflicting_licenses | | Unsure (found: License One, Licensir Mock License) |", "\n", - "| dep_two_licenses | | License Two, License Three |", "\n", - "| dep_two_variants_same_license | | Apache 2.0 |", "\n", - "| dep_with_dep | | Undefined |", "\n", - "+-----------------------------------+---------+----------------------------------------------------+", "\n", "\n" + [ + :yellow, + "Notice: This is not a legal advice. Use the information below at your own risk." + ], + :reset, + "\n", + # "|---------------------------------|----------------------------------------------------|", + "\n", + "| Package | License |", + "\n", + "|-----------------------------------|----------------------------------------------------|", + "\n", + "| dep_license_undefined | Undefined |", + "\n", + "| dep_of_dep | Undefined |", + "\n", + "| dep_one_license | Licensir Mock License |", + "\n", + "| dep_one_unrecognized_license_file | Unrecognized license |", + "\n", + "| dep_two_conflicting_licenses | License One; Licensir Mock License |", + "\n", + "| dep_two_licenses | License Two, License Three |", + "\n", + "| dep_two_variants_same_license | Apache 2.0 |", + "\n", + "| dep_with_dep | Undefined |", + "\n", + "|-----------------------------------|----------------------------------------------------|", + "\n", + "\n\n" ]) |> to_string() - assert output == expected + assert Licensir.FileAnalyzer.clean(output) == Licensir.FileAnalyzer.clean(expected) end test "prints csv format when given --csv flag" do @@ -35,18 +53,17 @@ defmodule Licensir.Mix.Tasks.LicensesTest do Mix.Tasks.Licenses.run(["--csv"]) end) - expected = - """ - Package,Version,License\r - dep_license_undefined,,Undefined\r - dep_of_dep,,Undefined\r - dep_one_license,,Licensir Mock License\r - dep_one_unrecognized_license_file,,Unrecognized license file content\r - dep_two_conflicting_licenses,,"Unsure (found: License One, Licensir Mock License)"\r - dep_two_licenses,,"License Two, License Three"\r - dep_two_variants_same_license,,Apache 2.0\r - dep_with_dep,,Undefined\r - """ + expected = """ + Package,Version,License\r + dep_license_undefined,,Undefined\r + dep_of_dep,,Undefined\r + dep_one_license,,Licensir Mock License\r + dep_one_unrecognized_license_file,,Unrecognized license\r + dep_two_conflicting_licenses,,"License One; Licensir Mock License"\r + dep_two_licenses,,"License Two, License Three"\r + dep_two_variants_same_license,,Apache 2.0\r + dep_with_dep,,Undefined\r + """ assert output == expected end