hudson 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/.gitignore +1 -0
  2. data/Changelog.md +3 -0
  3. data/Gemfile.lock +11 -43
  4. data/README.md +3 -151
  5. data/Rakefile +0 -77
  6. data/bin/hudson +2 -10
  7. data/hudson.gemspec +2 -12
  8. data/lib/hudson.rb +1 -8
  9. data/lib/hudson/version.rb +1 -1
  10. metadata +8 -203
  11. data/features/default_host.feature +0 -19
  12. data/features/development.feature +0 -14
  13. data/features/launch_server.feature +0 -17
  14. data/features/listing_jobs.feature +0 -34
  15. data/features/manage_jobs.feature +0 -207
  16. data/features/manage_slave_nodes.feature +0 -80
  17. data/features/step_definitions/common_steps.rb +0 -197
  18. data/features/step_definitions/fixture_project_steps.rb +0 -8
  19. data/features/step_definitions/hudson_steps.rb +0 -104
  20. data/features/step_definitions/scm_steps.rb +0 -12
  21. data/features/support/common.rb +0 -37
  22. data/features/support/env.rb +0 -14
  23. data/features/support/hooks.rb +0 -16
  24. data/features/support/hudson_helpers.rb +0 -6
  25. data/features/support/matchers.rb +0 -10
  26. data/lib/hudson/api.rb +0 -219
  27. data/lib/hudson/cli.rb +0 -253
  28. data/lib/hudson/cli/formatting.rb +0 -53
  29. data/lib/hudson/config.rb +0 -27
  30. data/lib/hudson/core_ext/hash.rb +0 -9
  31. data/lib/hudson/core_ext/object/blank.rb +0 -77
  32. data/lib/hudson/hudson-cli.jar +0 -0
  33. data/lib/hudson/installation.rb +0 -136
  34. data/lib/hudson/job_config_builder.rb +0 -287
  35. data/lib/hudson/project_scm.rb +0 -22
  36. data/lib/hudson/remote.rb +0 -11
  37. data/spec/fixtures/ec2_global.config.xml +0 -103
  38. data/spec/fixtures/rails.multi.config.xml +0 -82
  39. data/spec/fixtures/rails.single.config.triggers.xml +0 -84
  40. data/spec/fixtures/rails.single.config.xml +0 -80
  41. data/spec/fixtures/ruby.multi-ruby-multi-labels.config.xml +0 -84
  42. data/spec/fixtures/ruby.multi.config.xml +0 -77
  43. data/spec/fixtures/ruby.single.config.xml +0 -58
  44. data/spec/fixtures/therubyracer.config.xml +0 -77
  45. data/spec/hash_key_cleaner_spec.rb +0 -25
  46. data/spec/job_config_builder_spec.rb +0 -137
  47. data/spec/spec_helper.rb +0 -15
@@ -1,53 +0,0 @@
1
- require 'term/ansicolor'
2
-
3
- module Hudson
4
- class CLI < Thor
5
- module Formatting
6
- module ClassMethods
7
- def task_help(shell, task_name)
8
- meth = normalize_task_name(task_name)
9
- task = all_tasks[meth]
10
- handle_no_task_error(meth) unless task
11
-
12
- shell.say "usage: #{banner(task)}"
13
- shell.say
14
- class_options_help(shell, nil => task.options.map { |_, o| o })
15
- # shell.say task.description
16
- # shell.say
17
- end
18
-
19
-
20
- def print_options(shell, options, grp = nil)
21
- return if options.empty?
22
- table = options.map do |option|
23
- prototype = if option.default
24
- " [#{option.default}]"
25
- elsif option.boolean?
26
- ""
27
- elsif option.required?
28
- " #{option.banner}"
29
- else
30
- " [#{option.banner}]"
31
- end
32
- aliases = option.aliases.empty? ? "" : option.aliases.join(" ") + ","
33
- [aliases, "--#{option.name}#{prototype}", "\t",option.description]
34
- end
35
- shell.print_table(table, :ident => 2)
36
- shell.say
37
- end
38
- end
39
-
40
- module InstanceMethods
41
- def c
42
- Term::ANSIColor
43
- end
44
- end
45
-
46
- def self.included(receiver)
47
- receiver.extend ClassMethods
48
- receiver.send :include, InstanceMethods
49
- end
50
- end
51
- end
52
- end
53
-
@@ -1,27 +0,0 @@
1
- module Hudson
2
- module Config
3
- extend self
4
-
5
- def [](key)
6
- config[key]
7
- end
8
-
9
- def config
10
- @config ||= if File.exist?(config_file)
11
- JSON.parse(File.read(config_file))
12
- else
13
- {}
14
- end
15
- end
16
-
17
- def store!
18
- @config ||= {}
19
- FileUtils.mkdir_p(File.dirname(config_file))
20
- File.open(config_file, "w") { |file| file << @config.to_json }
21
- end
22
-
23
- def config_file
24
- @config_file ||= "#{ENV['HOME']}/.hudson/hudsonrb-config.json"
25
- end
26
- end
27
- end
@@ -1,9 +0,0 @@
1
- class Hash
2
- def with_clean_keys
3
- self.inject({}) do |mem, (key, value)|
4
- clean_key = key.to_s.gsub(/-/,"_").to_sym
5
- mem[clean_key] = value
6
- mem
7
- end
8
- end
9
- end
@@ -1,77 +0,0 @@
1
- # Vendored from activesupport 3.0.1
2
- class Object
3
- # An object is blank if it's false, empty, or a whitespace string.
4
- # For example, "", " ", +nil+, [], and {} are blank.
5
- #
6
- # This simplifies:
7
- #
8
- # if !address.nil? && !address.empty?
9
- #
10
- # ...to:
11
- #
12
- # if !address.blank?
13
- def blank?
14
- respond_to?(:empty?) ? empty? : !self
15
- end
16
-
17
- # An object is present if it's not blank.
18
- def present?
19
- !blank?
20
- end
21
-
22
- # Returns object if it's #present? otherwise returns nil.
23
- # object.presence is equivalent to object.present? ? object : nil.
24
- #
25
- # This is handy for any representation of objects where blank is the same
26
- # as not present at all. For example, this simplifies a common check for
27
- # HTTP POST/query parameters:
28
- #
29
- # state = params[:state] if params[:state].present?
30
- # country = params[:country] if params[:country].present?
31
- # region = state || country || 'US'
32
- #
33
- # ...becomes:
34
- #
35
- # region = params[:state].presence || params[:country].presence || 'US'
36
- def presence
37
- self if present?
38
- end
39
- end
40
-
41
- class NilClass #:nodoc:
42
- def blank?
43
- true
44
- end
45
- end
46
-
47
- class FalseClass #:nodoc:
48
- def blank?
49
- true
50
- end
51
- end
52
-
53
- class TrueClass #:nodoc:
54
- def blank?
55
- false
56
- end
57
- end
58
-
59
- class Array #:nodoc:
60
- alias_method :blank?, :empty?
61
- end
62
-
63
- class Hash #:nodoc:
64
- alias_method :blank?, :empty?
65
- end
66
-
67
- class String #:nodoc:
68
- def blank?
69
- self !~ /\S/
70
- end
71
- end
72
-
73
- class Numeric #:nodoc:
74
- def blank?
75
- false
76
- end
77
- end
Binary file
@@ -1,136 +0,0 @@
1
- module Hudson
2
- class Installation
3
- attr_reader :directory
4
-
5
- def initialize(shell, opts = {})
6
- @shell = shell
7
- @options = opts
8
- @serverhome = File.expand_path(@options[:home])
9
- @warfile = File.join(File.dirname(@serverhome), "hudson.war")
10
- @versionfile = "#{@serverhome}/version.txt"
11
- @control_port = opts[:control]
12
- end
13
-
14
- def launch!
15
- unless warfile?
16
- @shell.say "no server currently installed."
17
- upgrade!
18
- end
19
- javatmp = File.join(@serverhome, "javatmp")
20
- FileUtils.mkdir_p javatmp
21
- ENV['HUDSON_HOME'] = @serverhome
22
- cmd = ["java", "-Djava.io.tmpdir=#{javatmp}", "-jar", @warfile]
23
- cmd << "--daemon" if @options[:daemon]
24
- cmd << "--logfile=#{File.expand_path(@options[:logfile])}" if @options[:logfile]
25
- cmd << "--httpPort=#{@options[:port]}"
26
- cmd << "--controlPort=#{@control_port}"
27
- @shell.say cmd.join(" ")
28
- exec(*cmd)
29
- end
30
-
31
- def kill!
32
- require 'socket'
33
- TCPSocket.open("localhost", @control_port) do |sock|
34
- sock.write("0")
35
- end
36
- exit
37
- end
38
-
39
- def upgrade!
40
- FileUtils.mkdir_p @serverhome
41
- hudson_stock ? upgrade_from_fixture_stock : upgrade_from_network_stock
42
- end
43
-
44
- def hudson_stock
45
- ENV['HUDSON_STOCK']
46
- end
47
-
48
- private
49
-
50
- def warfile?
51
- File.exists?(@warfile) && system("unzip -l #{@warfile} > /dev/null 2>/dev/null")
52
- end
53
-
54
- def upgrade_from_fixture_stock
55
- FileUtils.cp File.join(hudson_stock, "hudson.war"), @warfile
56
- FileUtils.cp_r File.join(hudson_stock, "plugins"), @serverhome
57
- end
58
-
59
- def upgrade_from_network_stock
60
- require 'ostruct'
61
- progress = Progress.new
62
- latest = progress.means "grabbing the latest metadata from hudson-ci.org" do |step|
63
- JSON.parse(HTTParty.get("http://hudson-ci.org/update-center.json").lines.to_a[1..-2].join("\n"))
64
- end
65
- progress.means "downloading hudson server" do |step|
66
- latest_version = latest["core"]["version"]
67
- if latest_version > current_server_version
68
- puts
69
- `curl -L --progress-bar #{latest["core"]["url"]} -o #{@warfile}`
70
- self.current_server_version = latest_version
71
- step.ok("#{current_server_version} -> #{latest_version}")
72
- else
73
- step.ok("Up-to-date at #{current_server_version}")
74
- end
75
- end
76
-
77
- plugins_dir = File.join(@serverhome, 'plugins')
78
- plugins = if File.exists?(plugins_dir)
79
- Dir.chdir(plugins_dir) do
80
- Dir['*.hpi'].map {|entry| File.basename(entry,".hpi")}
81
- end
82
- else
83
- %w(envfile git github greenballs rake ruby)
84
- end
85
- FileUtils.mkdir_p(plugins_dir)
86
- for plugin in plugins do
87
- metadata = OpenStruct.new(latest['plugins'][plugin])
88
- progress.means "downloading #{plugin} plugin" do |step|
89
- system("curl -L --silent #{metadata.url} > #{plugins_dir}/#{plugin}.hpi")
90
- step.ok(metadata.version)
91
- end
92
- end unless progress.aborted
93
- end
94
-
95
- def current_server_version
96
- File.exists?(@versionfile) ? File.read(@versionfile) : "0"
97
- end
98
-
99
- def current_server_version=(version)
100
- File.open(@versionfile, "w") do |f|
101
- f.write(version)
102
- end
103
- end
104
-
105
- class Progress
106
- attr_reader :aborted
107
- def initialize
108
- @shell = Thor::Shell::Color.new
109
- @aborted = false
110
- end
111
-
112
- def means(step)
113
- return if @aborted
114
- begin
115
- @shell.say(step + "... ")
116
- yield(self).tap do
117
- @shell.say("[OK]", :green)
118
- end
119
- rescue Ok => ok
120
- @shell.say("[OK#{ok.message ? " - #{ok.message}" : ''}]", :green)
121
- rescue StandardError => e
122
- @shell.say("[FAIL - #{e.message}]", :red)
123
- @aborted = true
124
- false
125
- end
126
- end
127
-
128
- def ok(msg = nil)
129
- raise Ok.new(msg)
130
- end
131
-
132
- class Ok < StandardError
133
- end
134
- end
135
- end
136
- end
@@ -1,287 +0,0 @@
1
- require "builder"
2
-
3
- module Hudson
4
- class JobConfigBuilder
5
- attr_accessor :job_type
6
- attr_accessor :steps, :rubies
7
- attr_accessor :scm, :public_scm, :scm_branches
8
- attr_accessor :scm, :public_scm, :git_branches
9
- attr_accessor :assigned_node, :node_labels # TODO just one of these
10
- attr_accessor :envfile
11
-
12
- InvalidTemplate = Class.new(StandardError)
13
-
14
- VALID_JOB_TEMPLATES = %w[none rails rails3 ruby rubygem]
15
-
16
- # +job_type+ - template of default steps to create with the job
17
- # +steps+ - array of [:method, cmd], e.g. [:build_shell_step, "bundle initial"]
18
- # - Default is based on +job_type+.
19
- # +scm+ - URL to the repository. Currently only support git URLs.
20
- # +public_scm+ - convert the +scm+ URL to a publicly accessible URL for the Hudson job config.
21
- # +scm_branches+ - array of branches to run builds. Default: ['master']
22
- # +rubies+ - list of RVM rubies to run tests (via Hudson Axes).
23
- # +assigned_node+ - restrict this job to running on slaves with these labels (space separated)
24
- def initialize(job_type = :ruby, &block)
25
- self.job_type = job_type.to_s if job_type
26
-
27
- yield self
28
-
29
- self.scm_branches ||= ["master"]
30
- raise InvalidTemplate unless VALID_JOB_TEMPLATES.include?(job_type.to_s)
31
- end
32
-
33
- def builder
34
- b = Builder::XmlMarkup.new :indent => 2
35
- b.instruct!
36
- b.tag!(matrix_project? ? "matrix-project" : "project") do
37
- b.actions
38
- b.description
39
- b.keepDependencies false
40
- b.properties
41
- build_scm b
42
- b.assignedNode assigned_node if assigned_node
43
- b.canRoam !assigned_node
44
- b.disabled false
45
- b.blockBuildWhenUpstreamBuilding false
46
- b.triggers :class => "vector"
47
- b.concurrentBuild false
48
- build_axes b if matrix_project?
49
- build_steps b
50
- b.publishers
51
- build_wrappers b
52
- b.runSequentially false if matrix_project?
53
- end
54
- end
55
-
56
- def to_xml
57
- builder.to_s
58
- end
59
-
60
- protected
61
-
62
- # <scm class="hudson.plugins.git.GitSCM"> ... </scm>
63
- def build_scm(b)
64
- if scm && scm =~ /git/
65
- scm_url = public_scm ? public_only_git_scm(scm) : scm
66
- b.scm :class => "hudson.plugins.git.GitSCM" do
67
- b.configVersion 1
68
- b.remoteRepositories do
69
- b.tag! "org.spearce.jgit.transport.RemoteConfig" do
70
- b.string "origin"
71
- b.int 5
72
- b.string "fetch"
73
- b.string "+refs/heads/*:refs/remotes/origin/*"
74
- b.string "receivepack"
75
- b.string "git-upload-pack"
76
- b.string "uploadpack"
77
- b.string "git-upload-pack"
78
- b.string "url"
79
- b.string scm_url
80
- b.string "tagopt"
81
- b.string
82
- end
83
- end
84
-
85
- if scm_branches
86
- b.branches do
87
- scm_branches.each do |branch|
88
- b.tag! "hudson.plugins.git.BranchSpec" do
89
- b.name branch
90
- end
91
- end
92
- end
93
- end
94
-
95
- b.localBranch
96
- b.mergeOptions
97
- b.recursiveSubmodules false
98
- b.doGenerateSubmoduleConfigurations false
99
- b.authorOrCommitter false
100
- b.clean false
101
- b.wipeOutWorkspace false
102
- b.buildChooser :class => "hudson.plugins.git.util.DefaultBuildChooser"
103
- b.gitTool "Default"
104
- b.submoduleCfg :class => "list"
105
- b.relativeTargetDir
106
- b.excludedRegions
107
- b.excludedUsers
108
- end
109
- end
110
- end
111
-
112
- def matrix_project?
113
- !(rubies.blank? && node_labels.blank?)
114
- end
115
-
116
- # <hudson.matrix.TextAxis>
117
- # <name>RUBY_VERSION</name>
118
- # <values>
119
- # <string>1.8.7</string>
120
- # <string>1.9.2</string>
121
- # <string>rbx-head</string>
122
- # <string>jruby</string>
123
- # </values>
124
- # </hudson.matrix.TextAxis>
125
- # <hudson.matrix.LabelAxis>
126
- # <name>label</name>
127
- # <values>
128
- # <string>1.8.7</string>
129
- # <string>ubuntu</string>
130
- # </values>
131
- # </hudson.matrix.LabelAxis>
132
- def build_axes(b)
133
- b.axes do
134
- unless rubies.blank?
135
- b.tag! "hudson.matrix.TextAxis" do
136
- b.name "RUBY_VERSION"
137
- b.values do
138
- rubies.each do |rvm_name|
139
- b.string rvm_name
140
- end
141
- end
142
- end
143
- end
144
- unless node_labels.blank?
145
- b.tag! "hudson.matrix.LabelAxis" do
146
- b.name "label"
147
- b.values do
148
- node_labels.each do |label|
149
- b.string label
150
- end
151
- end
152
- end
153
- end
154
- end
155
- end
156
-
157
- # Example:
158
- # <buildWrappers>
159
- # <hudson.plugins.envfile.EnvFileBuildWrapper>
160
- # <filePath>/path/to/env/file</filePath>
161
- # </hudson.plugins.envfile.EnvFileBuildWrapper>
162
- # </buildWrappers>
163
- def build_wrappers(b)
164
- if envfile
165
- b.buildWrappers do
166
- self.envfile = [envfile] unless envfile.is_a?(Array)
167
- b.tag! "hudson.plugins.envfile.EnvFileBuildWrapper" do
168
- envfile.each do |file|
169
- b.filePath file
170
- end
171
- end
172
- end
173
- else
174
- b.buildWrappers
175
- end
176
- end
177
-
178
- # The important sequence of steps that are run to process a job build.
179
- # Can be defaulted by the +job_type+ using +default_steps(job_type)+,
180
- # or customized via +steps+ array.
181
- def build_steps(b)
182
- b.builders do
183
- self.steps ||= default_steps(job_type)
184
- steps.each do |step|
185
- method, cmd = step
186
- send(method.to_sym, b, cmd) # e.g. build_shell_step(b, "bundle install")
187
- end
188
- end
189
- end
190
-
191
- def default_steps(job_type)
192
- steps = case job_type.to_sym
193
- when :rails, :rails3
194
- [
195
- [:build_shell_step, "bundle install"],
196
- [:build_ruby_step, <<-RUBY.gsub(/^ /, '')],
197
- unless File.exist?("config/database.yml")
198
- require 'fileutils'
199
- example = Dir["config/database*"].first
200
- puts "Using \#{example} for config/database.yml"
201
- FileUtils.cp example, "config/database.yml"
202
- end
203
- RUBY
204
- [:build_shell_step, "bundle exec rake db:create:all"],
205
- [:build_shell_step, <<-RUBY.gsub(/^ /, '')],
206
- if [ -f db/schema.rb ]; then
207
- bundle exec rake db:schema:load
208
- else
209
- bundle exec rake db:migrate
210
- fi
211
- RUBY
212
- [:build_shell_step, "bundle exec rake"]
213
- ]
214
- when :ruby, :rubygems
215
- [
216
- [:build_shell_step, "bundle install"],
217
- [:build_shell_step, "bundle exec rake"]
218
- ]
219
- else
220
- [ [:build_shell_step, 'echo "THERE ARE NO STEPS! Except this one..."'] ]
221
- end
222
- rubies.blank? ? steps : default_rvm_steps + steps
223
- end
224
-
225
- def default_rvm_steps
226
- [
227
- [:build_shell_step, "rvm $RUBY_VERSION"],
228
- [:build_shell_step, "rvm gemset create ruby-$RUBY_VERSION && rvm gemset use ruby-$RUBY_VERSION"]
229
- ]
230
- end
231
-
232
- # <hudson.tasks.Shell>
233
- # <command>echo &apos;THERE ARE NO STEPS! Except this one...&apos;</command>
234
- # </hudson.tasks.Shell>
235
- def build_shell_step(b, command)
236
- b.tag! "hudson.tasks.Shell" do
237
- b.command command.to_xs.gsub("&amp;", '&') #.gsub(%r{"}, '&quot;').gsub(%r{'}, '&apos;')
238
- end
239
- end
240
-
241
- # <hudson.plugins.ruby.Ruby>
242
- # <command>unless File.exist?(&quot;config/database.yml&quot;)
243
- # require &apos;fileutils&apos;
244
- # example = Dir[&quot;config/database*&quot;].first
245
- # puts &quot;Using #{example} for config/database.yml&quot;
246
- # FileUtils.cp example, &quot;config/database.yml&quot;
247
- # end</command>
248
- # </hudson.plugins.ruby.Ruby>
249
- def build_ruby_step(b, command)
250
- b.tag! "hudson.plugins.ruby.Ruby" do
251
- b.command do
252
- b << command.to_xs.gsub(%r{"}, '&quot;').gsub(%r{'}, '&apos;')
253
- end
254
- end
255
- end
256
-
257
- # Usage: build_ruby_step b, "db:schema:load"
258
- #
259
- # <hudson.plugins.rake.Rake>
260
- # <rakeInstallation>(Default)</rakeInstallation>
261
- # <rakeFile></rakeFile>
262
- # <rakeLibDir></rakeLibDir>
263
- # <rakeWorkingDir></rakeWorkingDir>
264
- # <tasks>db:schema:load</tasks>
265
- # <silent>false</silent>
266
- # </hudson.plugins.rake.Rake>
267
- def build_rake_step(b, tasks)
268
- b.tag! "hudson.plugins.rake.Rake" do
269
- b.rakeInstallation "(Default)"
270
- b.rakeFile
271
- b.rakeLibDir
272
- b.rakeWorkingDir
273
- b.tasks tasks
274
- b.silent false
275
- end
276
- end
277
-
278
- # Converts git@github.com:drnic/newgem.git into git://github.com/drnic/newgem.git
279
- def public_only_git_scm(scm_url)
280
- if scm_url =~ /git@([\w\-_.]+):(.+)\.git/
281
- "git://#{$1}/#{$2}.git"
282
- else
283
- scm_url
284
- end
285
- end
286
- end
287
- end