<commit_before>require "monitor"
require "pathname"
require "set"
require "tempfile"
require "fileutils"
require "uri"

require "rubygems/package"
require "rubygems/uninstaller"
require "rubygems/name_tuple"

require_relative "shared_helpers"
require_relative "version"
require_relative "util/safe_env"

module Vagrant
  # This class manages Vagrant's interaction with Bundler. Vagrant uses
  # Bundler as a way to properly resolve all dependencies of Vagrant and
  # all Vagrant-installed plugins.
  class Bundler

    # Location of HashiCorp gem repository
    HASHICORP_GEMSTORE = "https://gems.hashicorp.com/".freeze

    # Default gem repositories
    DEFAULT_GEM_SOURCES = [
      HASHICORP_GEMSTORE,
      "https://rubygems.org/".freeze
    ].freeze

    def self.instance
      @bundler ||= self.new
    end

    # @return [Pathname] Global plugin path
    attr_reader :plugin_gem_path
    # @return [Pathname] Vagrant environment specific plugin path
    attr_reader :env_plugin_gem_path

    def initialize
      @plugin_gem_path = Vagrant.user_data_path.join("gems", RUBY_VERSION).freeze
      @logger = Log4r::Logger.new("vagrant::bundler")

      # TODO: Remove fix when https://github.com/rubygems/rubygems/pull/2735
      # gets merged and released
      #
      # Because of a rubygems bug, we need to set the gemrc file path
      # through this method rather than relying on the environment varible
      # GEMRC. On windows, that path gets split on `:`: and `;`, which means
      # the drive letter gets treated as its own path. If that path exists locally,
      # (like having a random folder called `c` where the library was invoked),
      # it fails thinking the folder `c` is a gemrc file.
      gemrc_val = ENV["GEMRC"]
      ENV["GEMRC"] = ""
      Gem.configuration = Gem::ConfigFile.new(["--config-file", gemrc_val])
      ENV["GEMRC"] = gemrc_val
    end

    # Enable Vagrant environment specific plugins at given data path
    #
    # @param [Pathname] Path to Vagrant::Environment data directory
    # @return [Pathname] Path to environment specific gem directory
    def environment_path=(env_data_path)
      @env_plugin_gem_path = env_data_path.join("plugins", "gems", RUBY_VERSION).freeze
    end

    # Initializes Bundler and the various gem paths so that we can begin
    # loading gems.
    def init!(plugins, repair=false)
      if !@initial_specifications
        @initial_specifications = Gem::Specification.find_all{true}
      else
        Gem::Specification.all = @initial_specifications
        Gem::Specification.reset
      end

      # Add HashiCorp RubyGems source
      if !Gem.sources.include?(HASHICORP_GEMSTORE)
        current_sources = Gem.sources.sources.dup
        Gem.sources.clear
        Gem.sources << HASHICORP_GEMSTORE
        current_sources.each do |src|
          Gem.sources << src
        end
      end

      # Generate dependencies for all registered plugins
      plugin_deps = plugins.map do |name, info|
        Gem::Dependency.new(name, info['installed_gem_version'].to_s.empty? ? '> 0' : info['installed_gem_version'])
      end

      @logger.debug("Current generated plugin dependency list: #{plugin_deps}")

      # Load dependencies into a request set for resolution
      request_set = Gem::RequestSet.new(*plugin_deps)
      # Never allow dependencies to be remotely satisfied during init
      request_set.remote = false<commit_msg>Clean up gem sources modifications<commit_after>require "monitor"
require "pathname"
require "set"
require "tempfile"
require "fileutils"
require "uri"

require "rubygems/package"
require "rubygems/uninstaller"
require "rubygems/name_tuple"

require_relative "shared_helpers"
require_relative "version"
require_relative "util/safe_env"

module Vagrant
  # This class manages Vagrant's interaction with Bundler. Vagrant uses
  # Bundler as a way to properly resolve all dependencies of Vagrant and
  # all Vagrant-installed plugins.
  class Bundler

    # Location of HashiCorp gem repository
    HASHICORP_GEMSTORE = "https://gems.hashicorp.com/".freeze

    # Default gem repositories
    DEFAULT_GEM_SOURCES = [
      HASHICORP_GEMSTORE,
      "https://rubygems.org/".freeze
    ].freeze

    def self.instance
      @bundler ||= self.new
    end

    # @return [Pathname] Global plugin path
    attr_reader :plugin_gem_path
    # @return [Pathname] Vagrant environment specific plugin path
    attr_reader :env_plugin_gem_path

    def initialize
      @plugin_gem_path = Vagrant.user_data_path.join("gems", RUBY_VERSION).freeze
      @logger = Log4r::Logger.new("vagrant::bundler")

      # TODO: Remove fix when https://github.com/rubygems/rubygems/pull/2735
      # gets merged and released
      #
      # Because of a rubygems bug, we need to set the gemrc file path
      # through this method rather than relying on the environment varible
      # GEMRC. On windows, that path gets split on `:`: and `;`, which means
      # the drive letter gets treated as its own path. If that path exists locally,
      # (like having a random folder called `c` where the library was invoked),
      # it fails thinking the folder `c` is a gemrc file.
      gemrc_val = ENV["GEMRC"]
      ENV["GEMRC"] = ""
      Gem.configuration = Gem::ConfigFile.new(["--config-file", gemrc_val])
      ENV["GEMRC"] = gemrc_val
    end

    # Enable Vagrant environment specific plugins at given data path
    #
    # @param [Pathname] Path to Vagrant::Environment data directory
    # @return [Pathname] Path to environment specific gem directory
    def environment_path=(env_data_path)
      @env_plugin_gem_path = env_data_path.join("plugins", "gems", RUBY_VERSION).freeze
    end

    # Initializes Bundler and the various gem paths so that we can begin
    # loading gems.
    def init!(plugins, repair=false)
      if !@initial_specifications
        @initial_specifications = Gem::Specification.find_all{true}
      else
        Gem::Specification.all = @initial_specifications
        Gem::Specification.reset
      end

      # Add HashiCorp RubyGems source
      if !Gem.sources.include?(HASHICORP_GEMSTORE)
        sources = [HASHICORP_GEMSTORE] + Gem.sources.sources
        Gem.sources.replace(sources)
      end

      # Generate dependencies for all registered plugins
      plugin_deps = plugins.map do |name, info|
        Gem::Dependency.new(name, info['installed_gem_version'].to_s.empty? ? '> 0' : info['installed_gem_version'])
      end

      @logger.debug("Current generated plugin dependency list: #{plugin_deps}")

      # Load dependencies into a request set for resolution
      request_set = Gem::RequestSet.new(*plugin_deps)
      # Never allow dependencies to be remotely satisfied during init
      request_set.remote = false
{'fraction_non_alphanumeric': 0.08624260355029585, 'fraction_numerical': 0.0017751479289940828, 'mean_word_length': 3.3146139119336313, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3477325', 'n_tokens_mistral': 2048, 'n_tokens_neox': 1991, 'n_words': 596}