make version a required dependency arg

This commit is contained in:
Jon Ruskin 2019-01-03 14:29:15 -07:00
Родитель 41a95a1a2e
Коммит 9ab4e95ae1
24 изменённых файлов: 57 добавлений и 46 удалений

Просмотреть файл

@ -28,7 +28,7 @@ module Licensed
# ensure each dependency is cached
source.dependencies.each do |dependency|
name = dependency.name
version = dependency.data["version"]
version = dependency.version
names << name
filename = cache_path.join("#{name}.txt")

Просмотреть файл

@ -19,7 +19,7 @@ module Licensed
source_dependencies = dependencies(app, source)
source_dependencies.each do |dependency|
@config.ui.info " Found #{dependency.name} (#{dependency.data["version"]})"
@config.ui.info " Found #{dependency.name} (#{dependency.version})"
end
@config.ui.confirm " * #{type} dependencies: #{source_dependencies.size}"

Просмотреть файл

@ -30,7 +30,7 @@ module Licensed
if File.exist?(filename)
license = License.read(filename)
if license["version"] != dependency.data["version"]
if license["version"] != dependency.version
warnings << "cached license data out of date"
end
warnings << "missing license text" if license.licenses.empty?

Просмотреть файл

@ -6,8 +6,9 @@ module Licensed
LEGAL_FILES_PATTERN = /(AUTHORS|NOTICE|LEGAL)(?:\..*)?\z/i
attr_reader :name
attr_reader :version
def initialize(name:, path:, search_root: nil, metadata: {})
def initialize(name:, version:, path:, search_root: nil, metadata: {})
# enforcing absolute paths makes life much easier when determining
# an absolute file path in #notices
unless Pathname.new(path).absolute?
@ -15,6 +16,7 @@ module Licensed
end
@name = name
@version = version
@metadata = metadata
super(path, search_root: search_root, detect_readme: true, detect_packages: true)
end
@ -62,11 +64,14 @@ module Licensed
# is written to YAML in the dependencys cached text file
def license_metadata
{
"name" => name, # name can be overriden by a name given in metadata
# can be overriden by values in @metadata
"name" => name,
"version" => version
}.merge(
@metadata
).merge({
"license" => license_key # license determination overrides metadata
# overrides all other values
"license" => license_key
})
end
end

Просмотреть файл

@ -16,10 +16,10 @@ module Licensed
path = bower_path.join(file).dirname.to_path
Dependency.new(
name: package["name"],
version: package["version"] || package["_release"],
path: path,
metadata: {
"type" => Bower.type,
"version" => package["version"] || package["_release"],
"summary" => package["description"],
"homepage" => package["homepage"]
}

Просмотреть файл

@ -19,10 +19,10 @@ module Licensed
specs.map do |spec|
Licensed::Dependency.new(
name: spec.name,
version: spec.version.to_s,
path: spec.gem_dir,
metadata: {
"type" => Bundler.type,
"version" => spec.version.to_s,
"summary" => spec.summary,
"homepage" => spec.homepage
}

Просмотреть файл

@ -18,13 +18,13 @@ module Licensed
path, search_root = package_docs_dirs(package)
Dependency.new(
name: package["name"],
version: package["version"],
path: path,
search_root: search_root,
metadata: {
"type" => Cabal.type,
"version" => package["version"],
"summary" => package["synopsis"],
"homepage" => safe_homepage(package["homepage"]),
"homepage" => safe_homepage(package["homepage"])
}
)
end

Просмотреть файл

@ -21,12 +21,12 @@ module Licensed
Dependency.new(
name: package[:name],
version: package[:version],
path: package_dir.to_s,
search_root: search_root.to_s,
metadata: {
"type" => Dep.type,
"homepage" => "https://#{package[:name]}",
"version" => package[:version]
"homepage" => "https://#{package[:name]}"
}
)
end

Просмотреть файл

@ -30,11 +30,11 @@ module Licensed
Licensed::Dependency.new(
name: submodule_path,
version: version,
path: @config.pwd.join(displaypath),
metadata: {
"type" => self.class.type,
"name" => name,
"version" => version,
"homepage" => homepage
}
)

Просмотреть файл

@ -16,13 +16,13 @@ module Licensed
package_dir = package["Dir"]
Dependency.new(
name: import_path,
version: package_version(package),
path: package_dir,
search_root: search_root(package_dir),
metadata: {
"type" => Go.type,
"summary" => package["Doc"],
"homepage" => homepage(import_path),
"version" => package_version(package)
"homepage" => homepage(import_path)
}
)
end

Просмотреть файл

@ -12,12 +12,12 @@ module Licensed
packages.map do |package_name, sources|
Licensed::Sources::Manifest::Dependency.new(
name: package_name,
version: package_version(sources),
path: configured_license_path(package_name) || sources_license_path(sources),
sources: sources,
metadata: {
"type" => Manifest.type,
"name" => package_name,
"version" => package_version(sources)
"name" => package_name
}
)
end
@ -189,9 +189,9 @@ module Licensed
)
/imx.freeze
def initialize(name:, path:, sources:, metadata: {})
def initialize(name:, version:, path:, sources:, metadata: {})
@sources = sources
super(name: name, path: path, metadata: metadata)
super(name: name, version: version, path: path, metadata: metadata)
end
def project_files

Просмотреть файл

@ -18,11 +18,11 @@ module Licensed
fail "couldn't locate #{name} under node_modules/" unless path
Dependency.new(
name: name,
version: package["version"],
path: path,
metadata: {
"type" => NPM.type,
"name" => package["name"],
"version" => package["version"],
"summary" => package["description"],
"homepage" => package["homepage"]
}

Просмотреть файл

@ -16,12 +16,12 @@ module Licensed
location = File.join(package["Location"], package["Name"] + "-" + package["Version"] + ".dist-info")
Dependency.new(
name: package["Name"],
version: package["Version"],
path: location,
metadata: {
"type" => Pip.type,
"summary" => package["Summary"],
"homepage" => package["Home-page"],
"version" => package["Version"]
"homepage" => package["Home-page"]
}
)
end

Просмотреть файл

@ -87,6 +87,7 @@ describe Licensed::Command::Cache do
test_dependency = Licensed::Dependency.new(
name: "dependency",
version: "1.0",
path: Dir.pwd,
metadata: {
"type" => TestSource.type
@ -112,6 +113,7 @@ describe Licensed::Command::Cache do
test_dependency = Licensed::Dependency.new(
name: "dependency",
version: "1.0",
path: Dir.pwd,
metadata: {
"type" => TestSource.type

Просмотреть файл

@ -80,7 +80,11 @@ describe Licensed::Command::Status do
end
it "warns if versions do not match" do
source.dependencies.first.data["version"] = "nope"
filename = config.cache_path.join("test/dependency.txt")
license = Licensed::License.read(filename)
license["version"] = "9001"
license.save(filename)
out, _ = capture_io { verifier.run }
assert_match(/cached license data out of date/, out)
end

Просмотреть файл

@ -3,35 +3,35 @@ require "test_helper"
require "tmpdir"
describe Licensed::Dependency do
def mkproject(metadata: {}, &block)
def mkproject(&block)
Dir.mktmpdir do |dir|
Dir.chdir dir do
yield Licensed::Dependency.new(name: "test", path: dir, metadata: metadata)
yield Licensed::Dependency.new(name: "test", version: "1.0", path: dir)
end
end
end
it "raises an error if the path argument is not an absolute path" do
assert_raises ArgumentError do
Licensed::Dependency.new(name: "test", path: ".")
Licensed::Dependency.new(name: "test", version: "1.0", path: ".")
end
end
describe "license" do
it "returns a Licensed::License object with dependency data" do
mkproject(metadata: { "version" => "1.0" }) do |dependency|
mkproject do |dependency|
File.write "LICENSE", Licensee::License.find("mit").text
File.write "AUTHORS", "author"
assert_equal "mit", dependency.data["license"]
assert_equal "test", dependency.data["name"]
assert_equal "1.0", dependency.data["version"]
assert_equal "1.0", dependency.version
assert_includes dependency.data.licenses, Licensee::License.find("mit").text
assert_includes dependency.data.notices, "author"
end
end
it "prefers a name given via metadata over the `name` kwarg" do
dep = Licensed::Dependency.new(name: "name", path: Dir.pwd, metadata: { "name" => "meta_name" })
dep = Licensed::Dependency.new(name: "name", version: "1.0", path: Dir.pwd, metadata: { "name" => "meta_name" })
assert_equal "meta_name", dep.data["name"]
end
end
@ -164,7 +164,7 @@ describe Licensed::Dependency do
Dir.mkdir "dependency"
Dir.chdir "dependency" do
dep = Licensed::Dependency.new(name: "test", path: Dir.pwd, search_root: File.expand_path(".."))
dep = Licensed::Dependency.new(name: "test", version: "1.0", path: Dir.pwd, search_root: File.expand_path(".."))
assert_includes dep.license_contents, "license"
end
end

Просмотреть файл

@ -36,7 +36,7 @@ if Licensed::Shell.tool_available?("bower")
Dir.chdir(fixtures) do
dep = source.dependencies.find { |d| d.name == "jquery" }
assert dep
assert_equal "2.1.4", dep.data["version"]
assert_equal "2.1.4", dep.version
end
end
end

Просмотреть файл

@ -112,7 +112,7 @@ if Licensed::Shell.tool_available?("bundle")
Dir.chdir(fixtures) do
dep = source.dependencies.find { |d| d.name == "semantic" }
assert dep
assert_equal "1.6.0", dep.data["version"]
assert_equal "1.6.0", dep.version
end
end
@ -126,7 +126,7 @@ if Licensed::Shell.tool_available?("bundle")
Dir.chdir(fixtures) do
dep = source.dependencies.find { |d| d.name == "pathed-gem-fixture" }
assert dep
assert_equal "0.0.1", dep.data["version"]
assert_equal "0.0.1", dep.version
end
end
@ -163,12 +163,12 @@ if Licensed::Shell.tool_available?("bundle")
# test
dep = source.dependencies.find { |d| d.name == "minitest" }
assert dep
assert_equal "5.11.3", dep.data["version"]
assert_equal "5.11.3", dep.version
# dev
dep = source.dependencies.find { |d| d.name == "tzinfo" }
assert dep
assert_equal "1.2.5", dep.data["version"]
assert_equal "1.2.5", dep.version
end
end
end

Просмотреть файл

@ -55,7 +55,7 @@ if Licensed::Shell.tool_available?("ghc")
dep = source.dependencies.detect { |d| d.name == "zlib" }
assert dep
assert_equal "cabal", dep.data["type"]
assert_equal "0.6.2", dep.data["version"]
assert_equal "0.6.2", dep.version
assert dep.data["summary"]
end
end
@ -66,7 +66,7 @@ if Licensed::Shell.tool_available?("ghc")
dep = source.dependencies.detect { |d| d.name == "Glob" }
assert dep
assert_equal "cabal", dep.data["type"]
assert_equal "0.9.2", dep.data["version"]
assert_equal "0.9.2", dep.version
assert dep.data["summary"]
end
end

Просмотреть файл

@ -45,7 +45,7 @@ if Licensed::Shell.tool_available?("git")
Dir.chdir(fixtures) do
dep = source.dependencies.find { |d| d.name == "submodule" }
assert dep
assert_equal latest_repository_commit(submodule_repo_path), dep.data["version"]
assert_equal latest_repository_commit(submodule_repo_path), dep.version
assert_equal "submodule", dep.data["name"]
end
end
@ -54,7 +54,7 @@ if Licensed::Shell.tool_available?("git")
Dir.chdir(fixtures) do
dep = source.dependencies.find { |d| d.name == "submodule/nested" }
assert dep
assert_equal latest_repository_commit(recursive_repo_path), dep.data["version"]
assert_equal latest_repository_commit(recursive_repo_path), dep.version
assert_equal "nested", dep.data["name"]
end
end

Просмотреть файл

@ -174,7 +174,7 @@ if Licensed::Shell.tool_available?("go")
ENV["GO111MODULE"] = "on"
Dir.chdir fixtures do
dep = source.dependencies.detect { |d| d.name == "github.com/gorilla/context" }
assert_equal "v1.1.1", dep.data["version"]
assert_equal "v1.1.1", dep.version
end
ensure
ENV["GO111MODULE"] = nil
@ -187,7 +187,7 @@ if Licensed::Shell.tool_available?("go")
Dir.chdir fixtures do
Licensed::Git.stub(:available?, false) do
dep = source.dependencies.detect { |d| d.name == "github.com/gorilla/context" }
assert_nil dep.data["version"]
assert_nil dep.version
end
end
end
@ -195,7 +195,7 @@ if Licensed::Shell.tool_available?("go")
it "is the latest git SHA of the package directory" do
Dir.chdir fixtures do
dep = source.dependencies.detect { |d| d.name == "github.com/gorilla/context" }
assert_match(/[a-f0-9]{40}/, dep.data["version"])
assert_match(/[a-f0-9]{40}/, dep.version)
end
end
end

Просмотреть файл

@ -34,7 +34,7 @@ describe Licensed::Sources::Manifest do
dep = source.dependencies.detect { |d| d.name == "manifest_test" }
assert dep
assert_equal "manifest", dep.data["type"]
assert dep.data["version"] # version comes from git, just make sure its there
assert dep.version # version comes from git, just make sure its there
end
it "uses a license specified in the configuration if provided" do

Просмотреть файл

@ -36,7 +36,7 @@ if Licensed::Shell.tool_available?("npm")
dep = @source.dependencies.detect { |d| d.name == "autoprefixer" }
assert dep
assert_equal "npm", dep.data["type"]
assert_equal "5.2.0", dep.data["version"]
assert_equal "5.2.0", dep.version
assert dep.data["homepage"]
assert dep.data["summary"]
end
@ -81,7 +81,7 @@ if Licensed::Shell.tool_available?("npm")
graceful_fs_dependencies = @source.dependencies.select { |dep| dep.name =~ /graceful-fs/ }
assert_equal 2, graceful_fs_dependencies.size
graceful_fs_dependencies.each do |dependency|
assert_equal "#{dependency.data["name"]}-#{dependency.data["version"]}", dependency.name
assert_equal "#{dependency.data["name"]}-#{dependency.version}", dependency.name
end
end
end

Просмотреть файл

@ -23,10 +23,10 @@ class TestSource < Licensed::Sources::Source
[
Licensed::Dependency.new(
name: @name,
version: "1.0",
path: Dir.pwd,
metadata: {
"type" => TestSource.type,
"version" => "1.0",
"dir" => Dir.pwd
}.merge(@metadata)
)