Skip to content

Commit

Permalink
[Added] Trash Package Manager
Browse files Browse the repository at this point in the history
- Fix tests with updated license output

[#163747415]
  • Loading branch information
Vikram Yadav committed May 15, 2019
1 parent 1382b59 commit 3a3d854
Show file tree
Hide file tree
Showing 15 changed files with 201 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ RUN mkdir /gopath && \
go get github.com/FiloSottile/gvt && \
go get github.com/Masterminds/glide && \
go get github.com/kardianos/govendor && \
go get github.com/golang/dep/cmd/dep
go get github.com/golang/dep/cmd/dep && \
go get -u github.com/rancher/trash

# Fix the locale
RUN apt-get install -y locales
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ report.
* Objective-C, Swift (via Carthage or CocoaPods \[0.39 and below. See [CocoaPods Specs Repo Sharding](http://blog.cocoapods.org/Sharding/)\])
* Objective-C (+ CocoaPods 0.39 and below. See [CocoaPods Specs Repo Sharding](http://blog.cocoapods.org/Sharding/))
* Elixir (via `mix`)
* Golang (via `gvt`, `glide`,`dep`, and `govendor`)
* Golang (via `gvt`, `glide`,`dep`, `trash` and `govendor`)
* JavaScript (via `yarn`)
* C++/C (via `conan`)
* Scala (via `sbt`)
Expand Down Expand Up @@ -181,6 +181,7 @@ languages, as long as that language has a package definition in the project dire
* `vendor/vendor.json` file (for `govendor`)
* `Gopkg.lock` file (for `dep`)
* `go.sum` file (for `go mod`)
* `vendor.conf` file (for `trash`)
* `yarn.lock` file (for `yarn`)
* `conanfile.txt` file (for `conan`)
* `build.sbt` file (for `sbt`)
Expand Down
52 changes: 52 additions & 0 deletions features/features/package_managers/trash_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

require_relative '../../support/feature_helper'

describe 'Trash Dependencies', :focus do
let(:go_developer) { LicenseFinder::TestingDSL::User.new }

context 'when the project does not contain trash.lock' do
context 'when the project is not run with prepare' do
specify 'fails to fetch the dependencies' do
LicenseFinder::TestingDSL::TrashProject.create
_output, status = go_developer.run_license_finder('gopath_trash')

expect(status).to eq 1
expect(go_developer).to_not be_seeing_something_like %r{github.com/Masterminds/vcs}
expect(go_developer).to_not be_seeing_something_like %r{gopkg.in/yaml.v2}
end
end

context 'when the project is run with prepare' do
specify 'shows dependencies in reports' do
LicenseFinder::TestingDSL::TrashProject.create
go_developer.run_license_finder('gopath_trash', '-p')

expect(go_developer).to be_seeing_line 'github.com/Masterminds/vcs, v1.12.0, MIT'
expect(go_developer).to be_seeing_line 'gopkg.in/yaml.v2, eb3733d160e74a9c7e442f435eb3bea458e1d19f, "Apache 2.0, MIT"'
end
end
end

context 'when the project contains trash.lock' do
context 'when the project is not run with prepare' do
specify 'shows dependencies in reports without license information' do
LicenseFinder::TestingDSL::TrashProject.create
go_developer.run_license_finder('gopath_trash')

expect(go_developer).to_not be_seeing_line 'github.com/Masterminds/vcs, v1.12.0, unknown'
expect(go_developer).to_not be_seeing_line 'gopkg.in/yaml.v2, eb3733d160e74a9c7e442f435eb3bea458e1d19f, unknown'
end
end

context 'when the project is run with prepare' do
specify 'shows dependencies in reports' do
LicenseFinder::TestingDSL::PreparedTrashProject.create
go_developer.run_license_finder('gopath_trash_prepared', '-p')

expect(go_developer).to be_seeing_line 'github.com/Masterminds/vcs, v1.12.0, MIT'
expect(go_developer).to be_seeing_line 'gopkg.in/yaml.v2, eb3733d160e74a9c7e442f435eb3bea458e1d19f, "Apache 2.0, MIT"'
end
end
end
end
6 changes: 6 additions & 0 deletions features/fixtures/gopath_trash/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main

import (
"gopkg.in/yaml.v2"
"github.com/Masterminds/vcs"
)
5 changes: 5 additions & 0 deletions features/fixtures/gopath_trash/vendor.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#package
gopath_trash

github.com/Masterminds/vcs v1.12.0
gopkg.in/yaml.v2 eb3733d160e74a9c7e442f435eb3bea458e1d19f
6 changes: 6 additions & 0 deletions features/fixtures/gopath_trash_prepared/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main

import (
"gopkg.in/yaml.v2"
"github.com/Masterminds/vcs"
)
5 changes: 5 additions & 0 deletions features/fixtures/gopath_trash_prepared/trash.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import:
- package: github.com/Masterminds/vcs
version: v1.12.0
- package: gopkg.in/yaml.v2
version: eb3733d160e74a9c7e442f435eb3bea458e1d19f
5 changes: 5 additions & 0 deletions features/fixtures/gopath_trash_prepared/vendor.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#package
gopath_trash_prepared

github.com/Masterminds/vcs v1.12.0
gopkg.in/yaml.v2 eb3733d160e74a9c7e442f435eb3bea458e1d19f
20 changes: 20 additions & 0 deletions features/support/testing_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,26 @@ def shell_out(command)
end
end

class TrashProject < Project
def add_dep
clone('gopath_trash')
end

def shell_out(command)
ProjectDir.new(Paths.project.join('gopath_trash')).shell_out(command)
end
end

class PreparedTrashProject < Project
def add_dep
clone('gopath_trash_prepared')
end

def shell_out(command)
ProjectDir.new(Paths.project.join('gopath_trash_prepared')).shell_out(command)
end
end

class GvtProject < Project
def add_dep
clone('gopath_gvt')
Expand Down
1 change: 1 addition & 0 deletions lib/license_finder/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def log_to_file(contents)
require 'license_finder/package_managers/glide'
require 'license_finder/package_managers/govendor'
require 'license_finder/package_managers/go_modules'
require 'license_finder/package_managers/trash'
require 'license_finder/package_managers/bundler'
require 'license_finder/package_managers/npm'
require 'license_finder/package_managers/yarn'
Expand Down
38 changes: 38 additions & 0 deletions lib/license_finder/package_managers/trash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

module LicenseFinder
class Trash < PackageManager
class << self
def package_management_command
'trash'
end

def prepare_command
'trash'
end

def takes_priority_over
Go15VendorExperiment
end
end

def possible_package_paths
[project_path.join('vendor.conf')]
end

def current_packages
dependencies_path = project_path.join('trash.lock')

YAML.load_file(dependencies_path).fetch('import').map do |package_hash|
import_path = package_hash.fetch('package')
license_path = project_path.join('vendor', import_path)

GoPackage.from_dependency({
'ImportPath' => import_path,
'InstallPath' => license_path,
'Rev' => package_hash.fetch('version')
}, nil, true)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/license_finder/scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module LicenseFinder
class Scanner
PACKAGE_MANAGERS = [GoModules, GoDep, GoWorkspace, Go15VendorExperiment, Glide, Gvt, Govendor, Dep, Bundler, NPM, Pip,
PACKAGE_MANAGERS = [GoModules, GoDep, GoWorkspace, Go15VendorExperiment, Glide, Gvt, Govendor, Trash, Dep, Bundler, NPM, Pip,
Yarn, Bower, Maven, Gradle, CocoaPods, Rebar, Nuget, Carthage, Mix, Conan, Sbt, Cargo, Dotnet].freeze

def initialize(config = { project_path: Pathname.new('') })
Expand Down
Empty file.
6 changes: 6 additions & 0 deletions spec/fixtures/config/trash.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package: github.com/rancher/trash
import:
- package: some-package-name
version: 123abc
- package: another-package-name
version: 456xyz
52 changes: 52 additions & 0 deletions spec/lib/license_finder/package_managers/trash_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

require 'spec_helper'
require 'fakefs/spec_helpers'

module LicenseFinder
describe Trash do
it_behaves_like 'a PackageManager'

subject { Trash.new(project_path: Pathname('/app'), logger: double(:logger, active: nil, log: true)) }

describe '.prepare_command' do
it 'returns the correct prepare method' do
expect(described_class.prepare_command).to eq('trash')
end
end

describe '.package_management_command' do
it 'returns the correct package management command' do
expect(described_class.package_management_command).to eq('trash')
end
end

describe '.takes_priority_over' do
it 'returns the package manager it takes priority over' do
expect(described_class.takes_priority_over).to eq(Go15VendorExperiment)
end
end

describe '#current_packages' do
let(:content) do
FakeFS.without do
fixture_from('trash.lock')
end
end

it 'returns the packages described by trash.lock' do
FakeFS.with_fresh do
FileUtils.mkdir_p '/app'
File.write(Pathname('/app/trash.lock').to_s, content)
expect(subject.current_packages.length).to eq 2

expect(subject.current_packages.first.name).to eq 'some-package-name'
expect(subject.current_packages.first.version).to eq '123abc'

expect(subject.current_packages.last.name).to eq 'another-package-name'
expect(subject.current_packages.last.version).to eq '456xyz'
end
end
end
end
end

0 comments on commit 3a3d854

Please sign in to comment.