Map gems file to specs

 @param [Array] gems Gems list
 @return [Array]
329177
def map_gems_to_specs(gems)
      gems.map.with_index do |gemfile, index|
        # rubocop:disable Metrics/LineLength
        Utils.logger.info("[#{index + 1}/#{gems.size}]: Processing #{gemfile.split('/')[-1]}")
        # rubocop:enable Metrics/LineLength

        if File.size(gemfile).zero?
          Utils.logger.warn("Skipping zero-length gem: #{gemfile}")
          next
        end

        begin
          spec = if ::Gem::Package.respond_to? :open
                   ::Gem::Package
                     .open(File.open(gemfile, 'rb'), 'r', &:metadata)
                 else
                   ::Gem::Package.new(gemfile).spec
                 end

          spec.loaded_from = gemfile

          # HACK: fuck this shit - borks all tests that use pl1
          if File.basename(gemfile, '.gem') != spec.original_name
            exp = spec.full_name
            exp << " (#{spec.original_name})" if
              spec.original_name != spec.full_name
            msg = "Skipping misnamed gem: #{gemfile} should be named #{exp}"
            Utils.logger.warn(msg)
            next
          end

          version = spec.version.version
          unless version =~ /^\d+\.\d+\.\d+.*/
            msg = "Skipping gem #{spec.full_name} - invalid version #{version}"
            Utils.logger.warn(msg)
            next
          end

          if ::Gem::VERSION >= '2.5.0'
            spec.abbreviate
            spec.sanitize
          else
            abbreviate spec
            sanitize spec
          end

          spec
        rescue SignalException
          msg = 'Received signal, exiting'
          Utils.logger.error(msg)
          raise
        rescue StandardError => e
          msg = ["Unable to process #{gemfile}",
                 "#{e.message} (#{e.class})",
                 "\t#{e.backtrace.join "\n\t"}"].join("\n")
          Utils.logger.debug(msg)
        end
      end.compact
    end
1224231
def parse_files(options)
      @stats = Stats.new options.verbosity

      files = options.files
      files = ["."] if files.empty?

      file_list = normalized_file_list(options, files, true, options.exclude)

      return [] if file_list.empty?

      file_info = []

      file_list.each do |filename|
        @stats.add_file filename

        content = if RUBY_VERSION >= '1.9' then
                    File.open(filename, "r:ascii-8bit") { |f| f.read }
                  else
                    File.read filename
                  end

        if defined? Encoding then
          if /coding:\s*(\S+)/ =~ content[/\A(?:.*\n){0,2}/]
            if enc = ::Encoding.find($1)
              content.force_encoding(enc)
            end
          end
        end

        top_level = ::RDoc::TopLevel.new filename

        parser = ::RDoc::Parser.for top_level, filename, content, options,
                                    @stats

        file_info << parser.scan
      end

      file_info
    end
501551
def lookup_gemspec
      dot_gemspec = (project.root + '.gemspec').to_s
      if File.exist?(dot_gemspec)
        dot_gemspec.to_s
      else
        project.metadata.name + '.gemspec'
      end
    end
1055081
def with_gemfile(path, *args, &block)
      # Make sure that if block calls  #gemfile we still return the gemfile for this
      # process, regardless of what's in ENV temporarily
      @gemfile_changed = true
      @process_gemfile = ENV['BUNDLE_GEMFILE']
      Bundler.with_clean_env do
        ENV['BUNDLE_GEMFILE'] = path
        block.call(*args)
      end
    ensure
      @gemfile_changed = false
      ENV['BUNDLE_GEMFILE'] = @process_gemfile
    end
963863
def create_gemspec(file=nil)
      file = gemspec if !file
      #require 'gemdo/gemspec'
      yaml = project.to_gemspec.to_yaml
      File.open(file, 'w') do |f|
        f << yaml
      end
      status File.basename(file) + " updated."
      return file
    end
816417
def define
      super
      task :package => [:gem]
      desc "Build the gem file #{gem_file}"
      task :gem => ["#{package_dir}/#{gem_file}"]
      file "#{package_dir}/#{gem_file}" => [package_dir] + @gem_spec.files do
        when_writing("Creating GEM") {
          Gem::Builder.new(gem_spec).build
          verbose(true) {
            mv gem_file, "#{package_dir}/#{gem_file}"
          }
        }
      end
    end
490749
def _parse_file_spec(self, spec):
        '''
        
        '''
        # separate wildcard specs into more specs
        if '*' in spec['file']:
            expanded_paths = _expand_paths(spec['file'])
            if not expanded_paths:
                return []
            expanded_specs = []
            for p in expanded_paths:
                _spec = copy.copy(spec)
                _spec['file'] = p
                expanded_specs.append(_spec)
            return expanded_specs

        else:
            return [spec]
1247966
def find_loaded_gem(name, property = nil)
      gem_spec = Gem.loaded_specs.values.find { |repo| repo.name == name }
      gem_spec.present? && property.present? ? gem_spec.send(property) : gem_spec
    end
701599
def load_from(gemspec_path, pattern)
      Gem.refresh
      spec = Gem::Specification.load(gemspec_path)
      dependencies = spec.runtime_dependencies.concat(spec.development_dependencies)
      dependencies.each do |gem|
        gem_name = gem.name[pattern]
        next if gem_name.to_s.empty?
        register(gem_name, Plugin.new(gem_name, gem))
      end
      self
    end
380418
private void getRubygemsSetupScript(RubyStringBuilder builder) {
        File[] gemPaths = gemsConfig.getGemPath();
        if (gemHome == null && gemPaths == null) {
            return;
        }

        builder.appendLine("# Set up GEM_HOME and GEM_PATH for running outside of maven");
        builder.appendLine();

        if (gemHome != null) {
            builder.appendLine("ENV['GEM_HOME']='" + gemHome + "'");
        }

        if (gemPaths != null) {
            builder.append("ENV['GEM_PATH']='");
            String sep = "";
            for(File path: gemPaths) {
                builder.append(sep + path);
                sep = System.getProperty("path.separator");
            }
            builder.appendLine("'");
        }

        builder.appendLine();
    }
807504
def jimfile_to_json
      h = {
        "bundle_dir" => bundle_dir
      }.merge(options)
      h['bundles'] = {}
      self.bundles.each do |bundle_name, requirements|
        h['bundles'][bundle_name] = []
        requirements.each do |name, version|
          h['bundles'][bundle_name] << if version.nil? || version.strip == ''
            name
          else
            [name, version]
          end
        end
      end
      Yajl::Encoder.encode(h, :pretty => true)
    end
986690
def format_diff
      gemfile.changes.map do |gem, details|
        ERB.new(template, nil, '<>').result(binding)
      end
    end
374663
def versions_for(gem)
      available = @versions_file.versions_for(gem.name)
      return [available.last] if gem.only_latest?

      versions = available.select do |v|
        gem.requirement.satisfied_by?(v[0])
      end

      versions = [available.last] if versions.empty?

      versions
    end
317781
def manifest_task
      # Load all the gem's files using "git ls-files"
      repository_files = `#{git} ls-files`.split("\n")
      test_files       = Dir[test_pattern] + Dir[spec_pattern]

      update_gemspec(:files, repository_files)
      update_gemspec(:test_files, repository_files & test_files)
    end
732453
def gem(*args)
      options = extract_options!(args)
      name, version = args

      # Set the message to be shown in logs. Uses the git repo if one is given,
      # otherwise use name (version).
      parts, message = [ name.inspect ], name
      if version ||= options.delete(:version)
        parts   << version.inspect
        message << " (#{version})"
      end
      message = options[:git] if options[:git]

      say_status :gemfile, message

      options.each do |option, value|
        parts << "#{option}: #{value.inspect}"
      end

      in_root do
        str = "gem #{parts.join(", ")}"
        str = "\n" + str
        append_file "Gemfile", str, :verbose => false
      end
    end
654144
def append_to_existing_spec(class_or_module, dry_run, rails_mode, spec_path)
      existing_spec = File.read(spec_path)
      lacking_methods = class_or_module.method_list.
        select { |m| m.visibility == :public }.
        reject { |m| existing_spec.match(m.name) }

      if lacking_methods.empty?
        puts "#{spec_path} skipped."
      else
        # These names are used in ERB template, don't delete.
        # rubocop:disable Lint/UselessAssignment
        methods_to_generate = lacking_methods
        c = class_or_module
        # rubocop:enable Lint/UselessAssignment

        erb = RSpecKickstarter::ERBFactory.new(@delta_template).get_instance_for_appending(rails_mode, spec_path)
        additional_spec = erb.result(binding)

        last_end_not_found = true
        code = existing_spec.split("\n").reverse.reject { |line|
          before_modified = last_end_not_found
          last_end_not_found = line.gsub(/#.+$/, '').strip != 'end' if before_modified
          before_modified
        }.reverse.join("\n") + "\n" + additional_spec + "\nend\n"

        if dry_run
          puts "----- #{spec_path} -----"
          puts code
        else
          File.open(spec_path, 'w') { |f| f.write(code) }
        end
        puts "#{spec_path} modified."
      end
    end
616725
def update_gemspec(attribute, new_value, literal = false)

      unless literal
        new_value = case new_value
          when Array        then "%w(#{new_value.join(' ')})"
          when Hash, String then new_value.inspect
          when Date         then new_value.strftime('%Y-%m-%d').inspect
          else              raise "Cannot write value #{new_value.inspect} to gemspec file!"
        end
      end

      spec   = File.read(gemspec_file)
      regexp = Regexp.new('^(\s+\w+\.' + Regexp.quote(attribute.to_s) + '\s*=\s*)[^\s].*$')
      if spec.sub!(regexp) { $1 + new_value }
        File.open(gemspec_file, 'w') { |f| f << spec }
        modified_files << gemspec_file

        # Reload the gemspec so the changes are incorporated
        load_gemspec!
        
        # Also mark the Gemfile.lock file as changed because of the new version.
        modified_files << 'Gemfile.lock' if File.exist?(File.join(root_dir, 'Gemfile.lock'))
      end
    end