Module: Licensed

Defined in:
lib/licensed/sources/bundler/missing_specification.rb,
lib/licensed/cli.rb,
lib/licensed/git.rb,
lib/licensed/shell.rb,
lib/licensed/report.rb,
lib/licensed/sources.rb,
lib/licensed/version.rb,
lib/licensed/commands.rb,
lib/licensed/ui/shell.rb,
lib/licensed/reporters.rb,
lib/licensed/dependency.rb,
lib/licensed/migrations.rb,
lib/licensed/sources/go.rb,
lib/licensed/sources/dep.rb,
lib/licensed/sources/mix.rb,
lib/licensed/sources/npm.rb,
lib/licensed/sources/pip.rb,
lib/licensed/sources/pnpm.rb,
lib/licensed/sources/yarn.rb,
lib/licensed/commands/list.rb,
lib/licensed/configuration.rb,
lib/licensed/migrations/v2.rb,
lib/licensed/sources/bower.rb,
lib/licensed/sources/cabal.rb,
lib/licensed/sources/cargo.rb,
lib/licensed/sources/nuget.rb,
lib/licensed/sources/swift.rb,
lib/licensed/commands/cache.rb,
lib/licensed/sources/gradle.rb,
lib/licensed/sources/pipenv.rb,
lib/licensed/sources/source.rb,
lib/licensed/commands/status.rb,
lib/licensed/sources/bundler.rb,
lib/licensed/sources/yarn/v1.rb,
lib/licensed/commands/command.rb,
lib/licensed/commands/notices.rb,
lib/licensed/sources/composer.rb,
lib/licensed/sources/manifest.rb,
lib/licensed/dependency_record.rb,
lib/licensed/sources/cocoapods.rb,
lib/licensed/reporters/reporter.rb,
lib/licensed/sources/yarn/berry.rb,
lib/licensed/commands/environment.rb,
lib/licensed/sources/git_submodule.rb,
lib/licensed/reporters/json_reporter.rb,
lib/licensed/reporters/list_reporter.rb,
lib/licensed/reporters/yaml_reporter.rb,
lib/licensed/reporters/cache_reporter.rb,
lib/licensed/reporters/status_reporter.rb,
lib/licensed/reporters/notices_reporter.rb,
lib/licensed/sources/bundler/definition.rb,
lib/licensed/sources/helpers/content_versioning.rb

Overview

This monkey patch instead creates MissingSpecification objects to identify missing specs without raising errors and halting enumeration. It was the most minimal-touch solution I could think of that should reliably work across many bundler versions

Defined Under Namespace

Modules: Bundler, Commands, Git, Migrations, Reporters, Shell, Sources, UI Classes: AppConfiguration, CLI, Configuration, Dependency, DependencyRecord, Report

Constant Summary collapse

VERSION =
begin
  root = File.expand_path("../..", __dir__)
  loaded_spec = Gem.loaded_specs["licensed"]
  loaded_from = loaded_spec&.loaded_from && File.expand_path(loaded_spec.loaded_from)

  # Published gems should report the version stored in gem metadata. Source
  # checkouts need to ignore Bundler's path gemspec so development builds can
  # infer the next release version from git tags.
  if loaded_spec&.version && loaded_from != File.join(root, "licensed.gemspec")
    loaded_spec.version.to_s
  else
    git_error = nil

    begin
      output, status = Open3.capture2e(
        "git",
        "describe",
        "--tags",
        chdir: root
      )
    rescue SystemCallError => e
      git_error = e.message
    end

    if status&.success?
      described_version = output.strip.delete_prefix("v")

      # Exact tags build that tag's version. Commits after a tag build the
      # next patch version Homebrew and the release workflow should expect.
      if (match = described_version.match(/\A(.+)-\d+-g[0-9a-f]+(?:-dirty)?\z/))
        match[1].sub(/\d+\z/) { |segment| (segment.to_i + 1).to_s.rjust(segment.length, "0") }
      else
        described_version
      end
    elsif File.exist?(lockfile = File.join(root, "Gemfile.lock"))
      # Shallow CI checkouts do not fetch tags in the broad test matrix. The
      # lockfile keeps Bundler setup fast and deterministic there.
      lockfile_version = File.read(lockfile)[/^    licensed \(([^)]+)\)$/, 1]
      raise "Unable to determine licensed version from Gemfile.lock" unless lockfile_version

      lockfile_version
    else
      error_output = output.to_s.strip
      raise "Unable to determine licensed version" if git_error.to_s.empty? && error_output.empty?

      raise "Unable to determine licensed version: #{git_error || error_output}"
    end
  end
end.freeze

Class Method Summary collapse

Class Method Details

.previous_major_versionsObject



55
56
57
58
# File 'lib/licensed/version.rb', line 55

def self.previous_major_versions
  major_version = Gem::Version.new(Licensed::VERSION).segments.first
  (1...major_version).to_a
end