<commit_before>require_relative 'logging'
require_relative 'util'

module TeracyDev
  class Plugin
    # install or uninstall plugins bases on the plugins config
    def self.sync(plugins)
      logger = TeracyDev::Logging.logger_for(self)
      plugins ||= []
      plugin_manager = Vagrant::Plugin::Manager.instance
      installed_plugins = plugin_manager.installed_plugins

      # reload_required when any plugin is installed/uninstalled
      reload_required = false

      plugins.each do |plugin|

        if !installed_plugins.has_key?(plugin['name']) and plugin['state'] == 'installed'
          logger.info("installing plugin: #{plugin}")
          plugin_manager.install_plugin(plugin['name'], Util.symbolize(plugin))
          reload_required = true
        end

        if installed_plugins.has_key?(plugin['name']) and plugin['state'] == 'uninstalled'
          logger.info("uninstalling plugin: #{plugin['name']}")
          plugin_manager.uninstall_plugin(plugin['name'])
          reload_required = true
        end
      end

      if reload_required
        logger.info("reloading...")
        exec "vagrant #{ARGV.join(" ")}"
      end
    end

    def self.installed?(plugin_name)
      return Vagrant.has_plugin?(plugin_name)
    end<commit_msg>@ #486 | fix plugin installation when no plugin is installed<commit_after>require_relative 'logging'
require_relative 'util'

module TeracyDev
  class Plugin
    # install or uninstall plugins bases on the plugins config
    def self.sync(plugins)
      logger = TeracyDev::Logging.logger_for(self)
      plugins ||= []
      plugin_manager = Vagrant::Plugin::Manager.instance
      installed_plugins = plugin_manager.installed_plugins

      # reload_required when any plugin is installed/uninstalled
      reload_required = false

      plugins.each do |plugin|

        if !installed_plugins.has_key?(plugin['name']) and plugin['state'] == 'installed'
          logger.info("installing plugin: #{plugin}")

          if plugin['sources'].nil? or plugin['sources'].empty?
            plugin['sources'] = [
              "https://rubygems.org/",
              "https://gems.hashicorp.com/"
            ]
          end

          plugin_manager.install_plugin(plugin['name'], Util.symbolize(plugin))
          reload_required = true
        end

        if installed_plugins.has_key?(plugin['name']) and plugin['state'] == 'uninstalled'
          logger.info("uninstalling plugin: #{plugin['name']}")
          plugin_manager.uninstall_plugin(plugin['name'])
          reload_required = true
        end
      end

      if reload_required
        logger.info("reloading...")
        exec "vagrant #{ARGV.join(" ")}"
      end
    end

    def self.installed?(plugin_name)
      return Vagrant.has_plugin?(plugin_name)
    end
{'fraction_non_alphanumeric': 0.11166785969935576, 'fraction_numerical': 0.0010737294201861132, 'mean_word_length': 2.8340192043895747, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '6166968', 'n_tokens_mistral': 787, 'n_tokens_neox': 758, 'n_words': 168}