Skip to content

Commit

Permalink
Merge branch 'master' into remove-test-fixtures-from-gem
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Klassen authored Sep 20, 2017
2 parents b783cf7 + afffeca commit 4907bf2
Show file tree
Hide file tree
Showing 23 changed files with 324 additions and 7 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ To successfully run the test suite, you will need the following installed:
- GoDep, GoWorkspace, and GoVendor (requires golang)
- CocoaPods (requires ruby)
- Bundler (requires ruby)
- Mix (requires Elixir)

The [LicenseFinder docker image](https://hub.docker.com/r/licensefinder/license_finder/) already contains these dependencies.

Expand Down
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A170311380
curl -sSL https://raw.githubusercontent.com/wayneeseguin/rvm/stable/binscripts/rvm-installer | sudo bash -s stable --ruby=2.4.1
ENV PATH=/usr/local/rvm/bin:$PATH

#install mix
RUN wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb && \
sudo dpkg -i erlang-solutions_1.0_all.deb && \
sudo apt-get update && \
sudo apt-get install -y esl-erlang && \
sudo apt-get install -y elixir

# install bundler
RUN bash -lc "gem update --system && gem install bundler"

Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ report.

* Erlang (via `rebar`)
* Objective-C (+ CocoaPods 0.39 and below. See [CocoaPods Specs Repo Sharding](http://blog.cocoapods.org/Sharding/))
* Elixir (via `mix`)

## Installation

Expand Down Expand Up @@ -152,6 +153,7 @@ languages, as long as that language has a package definition in the project dire
* `bower.json` (for `bower`)
* `Podfile` (for CocoaPods)
* `rebar.config` (for `rebar`)
* `mix.exs` (for `mix`)
* `packages/` directory (for `Nuget`)


Expand Down Expand Up @@ -336,11 +338,14 @@ If you have a gradle project, you can invoke gradle with a custom script by
passing (for example) `--gradle_command gradlew` to `license_finder` or
`license_finder report`.


Similarly you can invoke a custom rebar script with `--rebar_command rebar2`.
If you store rebar dependencies in a custom directory (by setting `deps_dir` in
`rebar.config`), set `--rebar_deps_dir`.

You can also invoke a custom Mix script `remix` with `--mix_command remix` and
set `--mix_deps_dir` to fetch Mix dependencies from a custom directory.


### Saving Configuration

It may be difficult to remember to pass command line options to every command.
Expand All @@ -355,6 +360,8 @@ decisions_file: './some_path/decisions.yml'
gradle_command: './gradlew'
rebar_command: './rebarw'
rebar_deps_dir: './rebar_deps'
mix_command: './mixw'
mix_deps_dir: './mix_deps'
```
### Gradle Projects
Expand Down
13 changes: 11 additions & 2 deletions ci/pipelines/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ resources:
private_key: ((CfOslBotPrivateKey))
branch: master

- name: lf-dockerfile
type: git
source:
uri: [email protected]:pivotal/LicenseFinder.git
private_key: ((CfOslBotPrivateKey))
branch: master
paths: ["Dockerfile"]

- name: lf-image
type: docker-image
source:
Expand All @@ -24,10 +32,11 @@ resources:
jobs:
- name: docker
plan:
- get: lf-git
- get: lf-dockerfile
trigger: true
- put: lf-image
params:
build: lf-git
build: lf-dockerfile

- name: release
plan:
Expand Down
2 changes: 1 addition & 1 deletion ci/tasks/build-windows.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
platform: windows
inputs:
- name: lf-git
- name: LicenseFinder
run:
path: powershell
args: ["-File", "lf-git/ci/scripts/test.ps1"]
16 changes: 16 additions & 0 deletions features/features/package_managers/mix_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require_relative '../../support/feature_helper'

describe "Mix Dependencies" do
# As an Elixir developer
# I want to be able to manage Mix dependencies

let(:elixir_developer) { LicenseFinder::TestingDSL::User.new }

specify "are shown in reports" do
LicenseFinder::TestingDSL::MixProject.create
puts "mix project created"
elixir_developer.run_license_finder
expect(elixir_developer).to be_seeing_line "fs, 0.9.1, ISC"
expect(elixir_developer).to be_seeing_line "uuid, 1.1.5, \"Apache 2.0\""
end
end
22 changes: 22 additions & 0 deletions features/fixtures/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

defmodule Awesome.Mixfile do
use Mix.Project

def project do
[app: :awesome,
version: "0.1.0",
elixir: "~> 1.2",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps()]
end

def application do
[applications: []]
end

defp deps do
[{:fs, "0.9.1"},
{:uuid, "1.1.5"}]
end
end
13 changes: 13 additions & 0 deletions features/support/testing_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,19 @@ def install
end
end

class MixProject < Project
def add_dep
install_fixture("mix.exs")
end

def install
shell_out("mix local.hex --force")
shell_out("mix local.rebar --force")
shell_out("mix deps.get")
shell_out("mix deps.compile")
end
end

class NugetProject < Project
def add_dep
clone('nuget')
Expand Down
2 changes: 2 additions & 0 deletions lib/license_finder/cli/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def license_finder_config
:pip_requirements_path,
:rebar_command,
:rebar_deps_dir,
:mix_command,
:mix_deps_dir,
:save
).merge(
logger: logger_config
Expand Down
2 changes: 2 additions & 0 deletions lib/license_finder/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Main < Base
class_option :pip_requirements_path, desc: "Path to python requirements file. Defaults to requirements.txt."
class_option :rebar_command, desc: "Command to use when fetching rebar packages. Only meaningful if used with a Erlang/rebar project. Defaults to 'rebar'."
class_option :rebar_deps_dir, desc: "Path to rebar dependencies directory. Only meaningful if used with a Erlang/rebar project. Defaults to 'deps'."
class_option :mix_command, desc: "Command to use when fetching packages through Mix. Only meaningful if used with a Mix project (i.e., Elixir or Erlang). Defaults to 'mix'."
class_option :mix_deps_dir, desc: "Path to Mix dependencies directory. Only meaningful if used with a Mix project (i.e., Elixir or Erlang). Defaults to 'deps'."
class_option :subprojects, type: :array, desc: "Generate a single report for multiple sub-projects. Ex: --subprojects='path/to/project1', 'path/to/project2'"
class_option :recursive, desc: "Recursively runs License Finder on all sub-projects."

Expand Down
9 changes: 9 additions & 0 deletions lib/license_finder/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,20 @@ def rebar_command
get(:rebar_command)
end

def mix_command
get(:mix_command) || "mix"
end

def rebar_deps_dir
path = get(:rebar_deps_dir) || 'deps'
project_path.join(path).expand_path
end

def mix_deps_dir
path = get(:mix_deps_dir) || 'deps'
project_path.join(path).expand_path
end

def decisions_file_path
path = get(:decisions_file) || 'doc/dependency_decisions.yml'
project_path.join(path).expand_path
Expand Down
2 changes: 2 additions & 0 deletions lib/license_finder/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def current_packages
pip_requirements_path: config.pip_requirements_path,
rebar_command: config.rebar_command,
rebar_deps_dir: config.rebar_deps_dir,
mix_command: config.mix_command,
mix_deps_dir: config.mix_deps_dir,
)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/license_finder/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,6 @@ def missing?
require 'license_finder/package_managers/gradle_package'
require 'license_finder/package_managers/cocoa_pods_package'
require 'license_finder/package_managers/rebar_package'
require 'license_finder/package_managers/mix_package'
require 'license_finder/package_managers/merged_package'
require 'license_finder/package_managers/nuget_package'
3 changes: 2 additions & 1 deletion lib/license_finder/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module LicenseFinder
#
class PackageManager
def self.package_managers
[GoDep, GoWorkspace, GoVendor, Bundler, NPM, Pip, Bower, Maven, Gradle, CocoaPods, Rebar, Nuget]
[GoDep, GoWorkspace, GoVendor, Bundler, NPM, Pip, Bower, Maven, Gradle, CocoaPods, Rebar, Nuget, Mix]
end

def self.current_packages(options)
Expand Down Expand Up @@ -91,6 +91,7 @@ def self.command_exists? command
require 'license_finder/package_managers/npm'
require 'license_finder/package_managers/pip'
require 'license_finder/package_managers/maven'
require 'license_finder/package_managers/mix'
require 'license_finder/package_managers/cocoa_pods'
require 'license_finder/package_managers/gradle'
require 'license_finder/package_managers/rebar'
Expand Down
53 changes: 53 additions & 0 deletions lib/license_finder/package_managers/mix.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module LicenseFinder
class Mix < PackageManager
def initialize(options={})
super
@command = options[:mix_command] || Mix::package_management_command
@deps_path = Pathname(options[:mix_deps_dir] || "deps")
end

def current_packages
mix_output.map do |name, version|
MixPackage.new(
name,
version,
install_path: @deps_path.join(name),
logger: logger
)
end
end

def self.package_management_command
"mix"
end

private

def mix_output
command = "#{@command} deps"
output, success = Dir.chdir(project_path) { capture(command) }
raise "Command '#{command}' failed to execute: #{output}" unless success

output
.each_line
.map(&:strip)
.select { |line| line_of_interest? line }
.each_slice(2).to_a
.map { |line1, line2| [ line1.split(" ")[1], resolve_version(line2) ] }
end

def line_of_interest?(line)
line.start_with?("* ") ||
line.start_with?("locked at") ||
line.start_with?("the dependency is not available")
end

def resolve_version(line)
line =~ /locked at ([^\s]+)/ ? $1 : line
end

def package_path
project_path.join('mix.exs')
end
end
end
7 changes: 7 additions & 0 deletions lib/license_finder/package_managers/mix_package.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module LicenseFinder
class MixPackage < Package
def package_manager
'Mix'
end
end
end
Binary file added license_finder-2.1.2.gem
Binary file not shown.
Empty file added spec/fixtures/all_pms/mix.exs
Empty file.
4 changes: 4 additions & 0 deletions spec/lib/license_finder/cli/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ module CLI
"--gradle_command=do_things",
"--rebar_command=do_other_things",
"--rebar_deps_dir=rebar_dir",
"--mix_command=surprise_me",
"--mix_deps_dir=mix_dir",
"--save"
] }
let(:logger_options) {
Expand All @@ -53,6 +55,8 @@ module CLI
gradle_command: 'do_things',
rebar_command: 'do_other_things',
rebar_deps_dir: 'rebar_dir',
mix_command: 'surprise_me',
mix_deps_dir: 'mix_dir',
save: 'license_report',
logger: {}
} }
Expand Down
57 changes: 57 additions & 0 deletions spec/lib/license_finder/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,62 @@ module LicenseFinder
expect(subject.rebar_deps_dir.to_s).to end_with "magic_path/primary"
end
end

describe "mix_deps_dir" do
it "has default" do
subject = described_class.new(
{mix_deps_dir: nil},
{"mix_deps_dir" => nil}
)
expect(subject.mix_deps_dir.to_s).to end_with "deps"
end

it "prepends project path to default path if project_path option is set" do
subject = described_class.new({project_path: "magic_path"}, {})
expect(subject.mix_deps_dir.to_s).to end_with "magic_path/deps"
end

it "prepends the saved config value if set" do
subject = described_class.new({}, {"mix_command" => "savedmix"})
expect(subject.mix_command.to_s).to eq "savedmix"
end

it "prepends project path to provided value" do
subject = described_class.new(
{mix_deps_dir: "primary",
project_path: "magic_path"},
{"mix_deps_dir" => "secondary"}
)
expect(subject.mix_deps_dir.to_s).to end_with "magic_path/primary"
end
end

describe "mix_command" do
it "has default" do
subject = described_class.new(
{mix_command: nil},
{"mix_command" => nil}
)
expect(subject.mix_command.to_s).to eq "mix"
end

it "defaults the mix_command to mix" do
subject = described_class.new({}, {})
expect(subject.mix_command.to_s).to eq "mix"
end

it "defaults to the saved config if set" do
subject = described_class.new({}, { "mix_command" => "savedmix" })
expect(subject.mix_command.to_s).to eq "savedmix"
end

it "overrides the mix command if specified" do
subject = described_class.new(
{mix_command: "newmix"},
{"mix_command" => "mix"}
)
expect(subject.mix_command.to_s).to eq "newmix"
end
end
end
end
8 changes: 6 additions & 2 deletions spec/lib/license_finder/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ module LicenseFinder
project_path: 'other_directory',
gradle_command: 'just_do_it',
rebar_command: 'do_it',
rebar_deps_dir: 'nowhere/deps'
rebar_deps_dir: 'nowhere/deps',
mix_command: 'mix_it',
mix_deps_dir: 'mixes_in_here/deps'
}
}
let(:package_options) {
Expand All @@ -34,7 +36,9 @@ module LicenseFinder
maven_options: nil,
pip_requirements_path: nil,
rebar_command: configuration.rebar_command,
rebar_deps_dir: configuration.rebar_deps_dir
rebar_deps_dir: configuration.rebar_deps_dir,
mix_command: configuration.mix_command,
mix_deps_dir: configuration.mix_deps_dir
}
}

Expand Down
Loading

0 comments on commit 4907bf2

Please sign in to comment.