Skip to content

Commit

Permalink
[Deprecated] - Remove Dep package manager for jammy release
Browse files Browse the repository at this point in the history
  • Loading branch information
xtreme-shane-lattanzio committed Jul 17, 2023
1 parent da637b8 commit 42bed10
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 136 deletions.
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ RUN mkdir /gopath && \
#install rvm and glide
RUN apt-add-repository -y ppa:rael-gc/rvm && \
apt -q update && apt install -y rvm && \
/usr/share/rvm/bin/rvm install --default $RUBY_VERSION &&\
/usr/share/rvm/bin/rvm install --default $RUBY_VERSION && \
apt install -y golang-glide && \
rm -rf /var/lib/apt/lists/*

Expand Down Expand Up @@ -199,12 +199,11 @@ RUN \
RUN apt -q update && apt -q install -y \
binutils \
git \
unzip \
gnupg2 \
libc6-dev \
libcurl4-openssl-dev \
libedit2 \
libgcc-9-dev \
libcurl4-openssl-dev \
libpython3-dev \
libsqlite3-0 \
libstdc++-9-dev \
Expand Down
8 changes: 7 additions & 1 deletion ci/scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ pushd "$PROJECT_ROOT"
DISABLE_BINARY="--disable-binary"
fi

rvm install --default $RUBY_VERSION_UNDER_TEST $DISABLE_BINARY
# This is needed for 2.7 but also works for 2.6. For 2.6, you can also downgrade the openssl version to 1.1.1l-1ubuntu1.4 in the dockerfile with allowing downgrades for apt install -y libssl-dev=1.1.1l-1ubuntu1.4
if [[ $RUBY_VERSION_UNDER_TEST == "2.6.10" || $RUBY_VERSION_UNDER_TEST == "2.7.8" ]]; then
OPEN_SSL_FLAG="--with-openssl-dir=/usr/share/rvm/usr/"
rvm pkg install openssl
fi

rvm install --default $RUBY_VERSION_UNDER_TEST $DISABLE_BINARY $OPEN_SSL_FLAG
ruby --version

export GOPATH=$HOME/go
Expand Down
3 changes: 2 additions & 1 deletion features/features/cli/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
expect(developer).to be_receiving_exit_code(1)
end

specify 'displays an error if symlink to potential license file is dangling' do
# Dep has been deprecated since 2020
xspecify 'displays an error if symlink to potential license file is dangling' do
project = LicenseFinder::TestingDSL::BrokenSymLinkDepProject.create
ENV['GOPATH'] = "#{project.project_dir}/gopath_dep"
developer.run_license_finder('gopath_dep/src/foo-dep')
Expand Down
56 changes: 28 additions & 28 deletions features/support/testing_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -425,34 +425,34 @@ def shell_out(command)
end
end

class DepProject < Project
def add_dep
clone('gopath_dep')
end

def install
orig_gopath = ENV['GOPATH']
ENV['GOPATH'] = "#{project_dir}/gopath_dep"
shell_out('dep ensure')
ENV['GOPATH'] = orig_gopath
end

def shell_out(command)
ProjectDir.new(Paths.project.join('gopath_dep', 'src', 'foo-dep')).shell_out(command)
end
end

class BrokenSymLinkDepProject < Project
def add_dep
clone('gopath_dep')
end

def install; end

def shell_out(command)
ProjectDir.new(Paths.project.join('gopath_dep', 'src', 'foo-dep')).shell_out(command)
end
end
# class DepProject < Project
# def add_dep
# clone('gopath_dep')
# end
#
# def install
# orig_gopath = ENV['GOPATH']
# ENV['GOPATH'] = "#{project_dir}/gopath_dep"
# shell_out('dep ensure')
# ENV['GOPATH'] = orig_gopath
# end
#
# def shell_out(command)
# ProjectDir.new(Paths.project.join('gopath_dep', 'src', 'foo-dep')).shell_out(command)
# end
# end
#
# class BrokenSymLinkDepProject < Project
# def add_dep
# clone('gopath_dep')
# end
#
# def install; end
#
# def shell_out(command)
# ProjectDir.new(Paths.project.join('gopath_dep', 'src', 'foo-dep')).shell_out(command)
# end
# end

class GovendorProject < Project
def add_dep
Expand Down
84 changes: 43 additions & 41 deletions lib/license_finder/package_managers/dep.rb
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
# frozen_string_literal: true

require 'tomlrb'

module LicenseFinder
class Dep < PackageManager
def possible_package_paths
[project_path.join('Gopkg.lock')]
end

def current_packages
toml = Tomlrb.load_file(detected_package_path)
projects = toml['projects']

return [] if projects.nil?

projects.map do |project|
GoPackage.from_dependency({
'ImportPath' => project['name'],
'InstallPath' => project_path.join('vendor', project['name']),
'Rev' => project['revision'],
'Homepage' => repo_name(project['name'])
}, nil, true)
end
end

def repo_name(name)
name.split('/')[0..2].join('/')
end

def self.takes_priority_over
Go15VendorExperiment
end

def prepare_command
'dep ensure -vendor-only'
end

def package_management_command
'dep'
end
end
end
# Dep has been deprecated since 2020
#
# require 'tomlrb'
#
# module LicenseFinder
# class Dep < PackageManager
# def possible_package_paths
# [project_path.join('Gopkg.lock')]
# end
#
# def current_packages
# toml = Tomlrb.load_file(detected_package_path)
# projects = toml['projects']
#
# return [] if projects.nil?
#
# projects.map do |project|
# GoPackage.from_dependency({
# 'ImportPath' => project['name'],
# 'InstallPath' => project_path.join('vendor', project['name']),
# 'Rev' => project['revision'],
# 'Homepage' => repo_name(project['name'])
# }, nil, true)
# end
# end
#
# def repo_name(name)
# name.split('/')[0..2].join('/')
# end
#
# def self.takes_priority_over
# Go15VendorExperiment
# end
#
# def prepare_command
# 'dep ensure -vendor-only'
# end
#
# def package_management_command
# 'dep'
# end
# end
# end
5 changes: 3 additions & 2 deletions lib/license_finder/package_managers/go_workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ def possible_package_paths
def active?
return false if @strict_matching

# Dep has been deprecated since 2020
godep = LicenseFinder::GoDep.new(project_path: Pathname(project_path))
dep = LicenseFinder::Dep.new(project_path: Pathname(project_path))
# go workspace is only active if GoDep wasn't. There are some projects
# that will use the .envrc and have a Godep folder as well.
!!(!godep.active? && !dep.active? && envrc_path && ENVRC_REGEXP.match(IO.read(envrc_path)))
# !!(!godep.active? && !dep.active? && envrc_path && ENVRC_REGEXP.match(IO.read(envrc_path)))
!!(!godep.active? && envrc_path && ENVRC_REGEXP.match(IO.read(envrc_path)))
end

private
Expand Down
114 changes: 58 additions & 56 deletions spec/lib/license_finder/package_managers/dep_spec.rb
Original file line number Diff line number Diff line change
@@ -1,58 +1,60 @@
# frozen_string_literal: true

require 'spec_helper'
require 'fakefs/spec_helpers'

module LicenseFinder
describe Dep do
it_behaves_like 'a PackageManager'
describe '#current_packages' do
subject { Dep.new(project_path: Pathname('/app'), logger: double(:logger, active: nil)) }
let(:content) do
FakeFS.without do
fixture_from('gopkg.lock')
end
end

it 'returns the packages described by Gopkg.lock' do
FakeFS do
FileUtils.mkdir_p '/app'
File.write('/app/Gopkg.lock', content)
expect(subject.current_packages.length).to eq 3

expect(subject.current_packages.first.name).to eq 'github.com/Bowery/prompt'
expect(subject.current_packages.first.version).to eq '0f1139e9a1c74b57ccce6bdb3cd2f7cd04dd3449'

expect(subject.current_packages[1].name).to eq 'github.com/dchest/safefile'
expect(subject.current_packages[1].version).to eq '855e8d98f1852d48dde521e0522408d1fe7e836a'

expect(subject.current_packages.last.name).to eq 'golang.org/x/sys'
expect(subject.current_packages.last.version).to eq 'ebfc5b4631820b793c9010c87fd8fef0f39eb082'
end
end

context 'the package does not have any projects in its toml' do
before do
allow(Tomlrb).to receive(:load_file).and_return({})
end

it 'should return an empty array' do
expect(subject.current_packages).to eq([])
end
end
end

describe '.prepare_command' do
subject { Dep.new(project_path: Pathname('/app'), logger: double(:logger, active: nil)) }
it 'returns the correct prepare method' do
expect(subject.prepare_command).to eq('dep ensure -vendor-only')
end
end

describe '.package_management_command' do
it 'returns the correct package management command' do
expect(subject.package_management_command).to eq('dep')
end
end
end
end
# Dep has been deprecated since 2020

# require 'spec_helper'
# require 'fakefs/spec_helpers'
#
# module LicenseFinder
# describe Dep do
# it_behaves_like 'a PackageManager'
# describe '#current_packages' do
# subject { Dep.new(project_path: Pathname('/app'), logger: double(:logger, active: nil)) }
# let(:content) do
# FakeFS.without do
# fixture_from('gopkg.lock')
# end
# end
#
# it 'returns the packages described by Gopkg.lock' do
# FakeFS do
# FileUtils.mkdir_p '/app'
# File.write('/app/Gopkg.lock', content)
# expect(subject.current_packages.length).to eq 3
#
# expect(subject.current_packages.first.name).to eq 'github.com/Bowery/prompt'
# expect(subject.current_packages.first.version).to eq '0f1139e9a1c74b57ccce6bdb3cd2f7cd04dd3449'
#
# expect(subject.current_packages[1].name).to eq 'github.com/dchest/safefile'
# expect(subject.current_packages[1].version).to eq '855e8d98f1852d48dde521e0522408d1fe7e836a'
#
# expect(subject.current_packages.last.name).to eq 'golang.org/x/sys'
# expect(subject.current_packages.last.version).to eq 'ebfc5b4631820b793c9010c87fd8fef0f39eb082'
# end
# end
#
# context 'the package does not have any projects in its toml' do
# before do
# allow(Tomlrb).to receive(:load_file).and_return({})
# end
#
# it 'should return an empty array' do
# expect(subject.current_packages).to eq([])
# end
# end
# end
#
# describe '.prepare_command' do
# subject { Dep.new(project_path: Pathname('/app'), logger: double(:logger, active: nil)) }
# it 'returns the correct prepare method' do
# expect(subject.prepare_command).to eq('dep ensure -vendor-only')
# end
# end
#
# describe '.package_management_command' do
# it 'returns the correct package management command' do
# expect(subject.package_management_command).to eq('dep')
# end
# end
# end
# end
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ module LicenseFinder
end
end

context 'when dep is present' do
# Dep has been deprecated since 2020
xcontext 'when dep is present' do
let(:godep) { instance_double(LicenseFinder::GoDep, active?: false) }
let(:dep) { instance_double(LicenseFinder::Dep, active?: true) }

Expand Down
6 changes: 3 additions & 3 deletions spec/lib/license_finder/package_managers/pip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module LicenseFinder

context 'using default python version (python2)' do
it 'should call pip install with the requirements file' do
expect(SharedHelpers::Cmd).to receive(:run).with('pip2 install -r requirements.txt')
expect(SharedHelpers::Cmd).to receive(:run).with('pip3 install -r requirements.txt')
.and_return([dependency_json, '', cmd_success])
pip.prepare
end
Expand All @@ -57,7 +57,7 @@ module LicenseFinder
let(:pip) { Pip.new(project_path: Pathname(root), pip_requirements_path: @user_provided_requirements) }

it 'should use the provided requirements file' do
expect(SharedHelpers::Cmd).to receive(:run).with("pip2 install -r #{@user_provided_requirements}")
expect(SharedHelpers::Cmd).to receive(:run).with("pip3 install -r #{@user_provided_requirements}")
.and_return([dependency_json, '', cmd_success])
pip.prepare
end
Expand Down Expand Up @@ -141,7 +141,7 @@ def stub_pypi(name, version, response)

it 'fails to find a required distribution' do
stderr = 'some-error'
command = "python #{LicenseFinder::BIN_PATH.join('license_finder_pip.py')} some-file.txt"
command = "python3 #{LicenseFinder::BIN_PATH.join('license_finder_pip.py')} some-file.txt"
expected_error_message = "LicenseFinder command '#{command}' failed:\n\t#{stderr}"

allow(LicenseFinder::SharedHelpers::Cmd).to receive(:run).with(command).and_return(['', stderr, status])
Expand Down

0 comments on commit 42bed10

Please sign in to comment.