Class: Corundum::GemCutter

Inherits:
Mattock::TaskLib
  • Object
show all
Defined in:
lib/corundum/gemcutter.rb

Defined Under Namespace

Modules: CommandTweaks Classes: CheckerForRubyGems189, CheckerForRubyGems200, DepsChecker

Instance Method Summary collapse

Instance Method Details

#default_configuration(toolkit, build) ⇒ Object



16
17
18
19
20
# File 'lib/corundum/gemcutter.rb', line 16

def default_configuration(toolkit, build)
  super
  toolkit.copy_settings_to(self)
  self.build = build
end

#defineObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/corundum/gemcutter.rb', line 87

def define
  in_namespace do
    task :uninstall do |t|
      when_writing("Uninstalling #{gemfile.full_name}") do
        require "rubygems/commands/uninstall_command"
        uninstall = get_command Gem::Commands::UninstallCommand
        uninstall.options[:args] = [gem_path]
        uninstall.execute
      end
    end

    task :install => [gem_path] do |t|
      when_writing("Installing #{gem_path}") do
        require "rubygems/commands/install_command"
        install = get_command Gem::Commands::InstallCommand
        install.options[:args] = [gem_path]
        install.execute
      end
    end

    task :reinstall => [:uninstall, :install]

    task :dependencies_available do
      require 'corundum/qa-report'
      report = QA::Report.new("Gem dependencies[#{File::basename(gemspec.loaded_from)}]")
      qa_rejections << report
      checker = DepsChecker.build
      gemspec.runtime_dependencies.each do |dep|
        if checker.fulfilled?(dep)
          report.add("status", dep, nil, "fulfilled")
        else
          report.add("status", dep, nil, "missing")
          report.fail "Dependency unfulfilled remotely"
        end
      end
    end

    task :pinned_dependencies do
      return unless File::exists?("Gemfile.lock")
      require 'corundum/qa-report'
      require 'bundler/lockfile_parser'
      parser = File::open("Gemfile.lock") do |lockfile|
        Bundler::LockfileParser.new(lockfile.read)
      end
      report = QA::Report.new("Bundler pinned dependencies")
      qa_rejections << report
      runtime_deps = gemspec.runtime_dependencies.map(&:name)
      parser.dependencies.each do |_, dep|
        next unless runtime_deps.include? dep.name
        _, source = dep.source
        next if source.nil?
        next if source.respond_to?(:path) and source.path.to_s == "."
        report.add("source", dep, nil, source)
        report.fail("Pinned gem dependencies:\n" +
                    "   Specs depended on by the gemspec are pinned (by :path or :git) and " +
                    "as a result, spec results are suspect\n")
      end
    end

    task :is_unpushed do
      checker = DepsChecker.build
      dep = Gem::Dependency.new(gemspec.name, ">= #{gemspec.version}")
      if checker.fulfilled?(dep)
        fail "Gem #{gemspec.full_name} is already pushed"
      end
    end

    desc 'Push a gem up to Gemcutter'
    task :push => [:dependencies_available, :is_unpushed] do
      require "rubygems/commands/push_command"
      push = get_command(Gem::Commands::PushCommand)
      push.options[:args] = [gem_path.abspath]
      push.execute
    end
    task :push => build_file.abspath
  end
  task :release => in_namespace(:push)
  task :preflight => in_namespace(:is_unpushed)
  task :run_quality_assurance => in_namespace(:dependencies_available, :pinned_dependencies)
  task :run_continuous_integration => in_namespace(:pinned_dependencies)
end

#get_command(klass, args = nil) ⇒ Object



49
50
51
52
53
54
# File 'lib/corundum/gemcutter.rb', line 49

def get_command(klass, args=nil)
  cmd = klass.new
  cmd.extend(CommandTweaks)
  cmd.setup_args(args)
  cmd
end

#resolve_configurationObject



22
23
24
25
26
# File 'lib/corundum/gemcutter.rb', line 22

def resolve_configuration
  super
  gem_path.relative_path = gemspec.file_name
  resolve_paths
end