hudson-api 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem "json"
6
+ gem "builder"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "shoulda", ">= 0"
12
+ gem "bundler", "~> 1.0.0"
13
+ gem "jeweler", "~> 1.6.4"
14
+ gem "rcov", ">= 0"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ builder (3.0.0)
5
+ git (1.2.5)
6
+ jeweler (1.6.4)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ json (1.5.3)
11
+ rake (0.9.2)
12
+ rcov (0.9.10)
13
+ shoulda (2.11.3)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ builder
20
+ bundler (~> 1.0.0)
21
+ jeweler (~> 1.6.4)
22
+ json
23
+ rcov
24
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Eloy Gomez
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = hudson-api
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to hudson-api
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Eloy Gomez. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "hudson-api"
18
+ gem.homepage = "http://github.com/harlock/hudson-api"
19
+ gem.license = "MIT"
20
+ gem.summary = "Hudson api"
21
+ gem.description = "Allow manage Hudson CI from ruby"
22
+ gem.email = "eloy@indeos.es"
23
+ gem.authors = ["Eloy Gomez"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "hudson-api #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{hudson-api}
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Eloy Gomez}]
12
+ s.date = %q{2011-08-25}
13
+ s.description = %q{Allow manage Hudson CI from ruby}
14
+ s.email = %q{eloy@indeos.es}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "hudson-api.gemspec",
28
+ "lib/api/job.rb",
29
+ "lib/api/job_config.rb",
30
+ "lib/api/job_instance.rb",
31
+ "lib/hudson-api.rb",
32
+ "test/helper.rb",
33
+ "test/test_hudson-api.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/harlock/hudson-api}
36
+ s.licenses = [%q{MIT}]
37
+ s.require_paths = [%q{lib}]
38
+ s.rubygems_version = %q{1.8.8}
39
+ s.summary = %q{Hudson api}
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<json>, [">= 0"])
46
+ s.add_runtime_dependency(%q<builder>, [">= 0"])
47
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
50
+ s.add_development_dependency(%q<rcov>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<json>, [">= 0"])
53
+ s.add_dependency(%q<builder>, [">= 0"])
54
+ s.add_dependency(%q<shoulda>, [">= 0"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
57
+ s.add_dependency(%q<rcov>, [">= 0"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<json>, [">= 0"])
61
+ s.add_dependency(%q<builder>, [">= 0"])
62
+ s.add_dependency(%q<shoulda>, [">= 0"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
65
+ s.add_dependency(%q<rcov>, [">= 0"])
66
+ end
67
+ end
68
+
data/lib/api/job.rb ADDED
@@ -0,0 +1,63 @@
1
+ module Hudson
2
+ class Job < HudsonBase
3
+
4
+ attr_reader :msg, :hudson_url
5
+
6
+ def initialize(jobname)
7
+ @jobname = jobname
8
+ @api_suffix = "/api/json"
9
+ @module_url = "/job/"
10
+ load
11
+ end
12
+
13
+ # Return status of job
14
+ def heathStatusDescription
15
+ desc = String.new
16
+ @msg.fetch("healthReport").each do |report|
17
+ desc += report.fetch("description")
18
+ end
19
+ return desc
20
+ end
21
+
22
+ # Return the las complete build
23
+ # as a JobInstance
24
+ def lastCompletedBuild
25
+ id = @msg.fetch("lastCompletedBuild").fetch("number")
26
+ JobInstance.new(@jobname, id)
27
+ end
28
+
29
+ # Return builds from this job
30
+ def builds
31
+ @msg.fetch("builds")
32
+ end
33
+
34
+ # Create a new hudson job
35
+ def self.create(jobname, config)
36
+ url = "#{Hudson[:url]}/createItem?name=#{jobname}"
37
+ send_xml_post_request(url, config)
38
+ end
39
+
40
+ # Update a hudson job
41
+ def self.update(jobname, config)
42
+ url = "#{Hudson[:url]}/job/#{jobname}/config.xml"
43
+ send_xml_post_request(url, config)
44
+ end
45
+
46
+ # Perform a build
47
+ def self.run(jobname)
48
+ url = "#{Hudson[:url]}/job/#{jobname}/build"
49
+ send_post_request(url)
50
+ end
51
+
52
+
53
+ private
54
+ def load
55
+ url = "#{Hudson[:url]}/#{@module_url}/#{@jobname}/#{Hudson[:api_suffix]}"
56
+ puts url
57
+ resp = Net::HTTP.get_response(URI.parse(url))
58
+ data = resp.body
59
+ result = JSON.parse(data)
60
+ @msg = result
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,123 @@
1
+ module Hudson
2
+ class JobConfig
3
+ require 'builder'
4
+
5
+ attr_accessor :config, :description, :provider, :repositories, :targets, :archived_resources, :disabled
6
+
7
+ def initialize
8
+ @disabled = false
9
+ @targets = []
10
+ @provider = "svn"
11
+ end
12
+
13
+ def create
14
+ b = Builder::XmlMarkup.new(:indent => 1)
15
+ @config= b.project do |p|
16
+ p.description @description
17
+ p.disabled @disabled
18
+
19
+ # Repositories
20
+ unless @repositories.nil?
21
+ if @provider == "svn"
22
+ create_svn(p)
23
+ end
24
+
25
+ end
26
+
27
+ # Builders
28
+ if @targets.length > 0
29
+ create_builders(p)
30
+ else
31
+ p.builders
32
+ end
33
+
34
+ # Create publisers
35
+ create_publisher(p)
36
+
37
+ # defaults
38
+ p.properties do |prop|
39
+ prop.tag!("watched-dependencies-property")
40
+ end
41
+ p.actions
42
+ p.keepDependencies false
43
+ p.advancedAffinityChooser false
44
+ p.canRoam true
45
+ p.blockBuildWhenDownstreamBuilding false
46
+ p.blockBuildWhenUpstreamBuilding false
47
+ p.triggers("class"=>"vector")
48
+ p.concurrentBuild false
49
+ p.cleanWorkspaceRequired true
50
+ p.buildWrappers
51
+ end
52
+ @config
53
+ end
54
+
55
+ def create_svn(p)
56
+ p.scm("class"=>"hudson.scm.SubversionSCM") do |svn|
57
+ svn.excludedRegions
58
+ svn.includedRegions
59
+ svn.excludedUsers
60
+ svn.excludedRevprop
61
+ svn.excludedCommitMessages
62
+ svn.workspaceUpdater("class"=>"hudson.scm.subversion.UpdateUpdater")
63
+
64
+ svn.locations do |l|
65
+ @repositories.each do |repo|
66
+ l.tag!("hudson.scm.SubversionSCM_-ModuleLocation") do |ml|
67
+ ml.remote repo["uri"]
68
+ ml.local repo["path"]
69
+ ml.depthOption "infinity"
70
+ ml.ignoreExternalsOption false
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ def create_builders(project)
78
+
79
+ shell = "#Prepare project\n"
80
+ buckminster = "import '${WORKSPACE}/feature.p2.site/site.cquery'\n"
81
+ buckminster += "build\n"
82
+ buckminster += "perform -D target.os=* -D target.ws=* -D target.arch=* feature.p2.site#site.p2\n"
83
+
84
+
85
+ @targets.each do |t|
86
+ shell += "/opt/hudson-osx/tools/prepare ${WORKSPACE} #{t["feature"]}\n"
87
+ end
88
+
89
+ project.builders do |builder|
90
+ # Shell tashs
91
+ builder.tag!("hudson.tasks.Shell") do |t|
92
+ t.command shell
93
+ end
94
+ # Buckminster task
95
+ builder.tag!("hudson.plugins.buckminster.EclipseBuckminsterBuilder") do |b|
96
+ b.installationName "Buckminster"
97
+ b.commands buckminster
98
+ b.targetPlatformName "Opensixen Core"
99
+ b.logLevel "info"
100
+ b.params
101
+ b.userTemp
102
+ b.userOutput
103
+ b.userCommand
104
+ b.userWorkspace
105
+ b.globalPropertiesFile
106
+ b.equinoxLauncherArgs
107
+ end
108
+ end
109
+ end
110
+
111
+ def create_publisher(project)
112
+ project.publishers do |publisher|
113
+ publisher.tag!("hudson.tasks.ArtifactArchiver") do |a|
114
+ a.artifacts @archived_resources
115
+ a.compressionType "GZIP"
116
+ a.latestOnly false
117
+ a.autoValidateFileMask false
118
+ end
119
+ end
120
+ end
121
+
122
+ end
123
+ end
@@ -0,0 +1,57 @@
1
+ module Hudson
2
+
3
+ class JobInstance
4
+ attr_reader :msg, :jobname, :id
5
+
6
+ def initialize(jobname, id)
7
+ @jobname = jobname
8
+ @id = id
9
+ @module_url = "/job/"
10
+ load
11
+ end
12
+
13
+ # return artifacts created in this instance
14
+ def artifacts
15
+ f("artifacts")
16
+ end
17
+
18
+ def changeset
19
+ f("changeSet")
20
+ end
21
+
22
+ def building?
23
+ f("building")
24
+ end
25
+
26
+ def duration
27
+ f("duration")
28
+ end
29
+
30
+ def number
31
+ f("number")
32
+ end
33
+
34
+ def result
35
+ f("result")
36
+ end
37
+
38
+ def timestamp
39
+ f("timestamp")
40
+ end
41
+ private
42
+
43
+ def f(p)
44
+ @msg.fetch(p)
45
+ end
46
+
47
+ def load
48
+ url = "#{Hudson[:url]}/#{@module_url}/#{@jobname}/#{@id}/#{Hudson[:api_suffix]}"
49
+ puts url
50
+ resp = Net::HTTP.get_response(URI.parse(url))
51
+ data = resp.body
52
+ result = JSON.parse(data)
53
+ @msg = result
54
+ end
55
+ end
56
+
57
+ end
data/lib/hudson-api.rb ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+ require 'net/http'
4
+ module Hudson
5
+
6
+ # set default settings
7
+ @@settings = {:url => 'http://localhost:8080/hudson', :user => nil, :password => nil, :api_suffix=>"/api/json" }
8
+
9
+ def self.[](param)
10
+ return @@settings[param]
11
+ end
12
+
13
+ def self.[]=(param,value)
14
+ param = param.to_sym if param.kind_of?(String)
15
+ if param == :host or param == :url
16
+ value = "http://#{value}" if value !~ /https?:\/\//
17
+ @@settings[:url] = value
18
+ else
19
+ @@settings[param]=value
20
+ end
21
+ end
22
+
23
+
24
+ # Base class for all Hudson objects
25
+ class HudsonBase
26
+ def self.send_post_request(url, data={})
27
+ uri = URI.parse(url)
28
+ http = Net::HTTP.new(uri.host, uri.port)
29
+ request = Net::HTTP::Post.new(uri.request_uri)
30
+ request.basic_auth(Hudson[:user], Hudson[:password]) if Hudson[:user] and Hudson[:password]
31
+ request.add_field "Content-Type", "application/xml"
32
+ request.set_form_data(data)
33
+ response = http.request(request)
34
+ response.is_a?(Net::HTTPSuccess) or response.is_a?(Net::HTTPRedirection)
35
+ end
36
+
37
+ def self.send_xml_post_request(url, xml)
38
+ uri = URI.parse(url)
39
+ http = Net::HTTP.new(uri.host, uri.port)
40
+ request = Net::HTTP::Post.new(uri.request_uri)
41
+ request.basic_auth(Hudson[:user], Hudson[:password]) if Hudson[:user] and Hudson[:password]
42
+ request.add_field "Content-Type", "application/xml"
43
+ request.body = xml
44
+ response = http.request(request)
45
+ response.is_a?(Net::HTTPSuccess) or response.is_a?(Net::HTTPRedirection)
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ Dir[File.dirname(__FILE__) + '/api/*.rb'].each {|file| require file }
52
+
53
+
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'hudson-api'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestHudsonApi < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hudson-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eloy Gomez
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-25 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: &77143100 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *77143100
25
+ - !ruby/object:Gem::Dependency
26
+ name: builder
27
+ requirement: &77142510 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *77142510
36
+ - !ruby/object:Gem::Dependency
37
+ name: shoulda
38
+ requirement: &77141730 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *77141730
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &77141220 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *77141220
58
+ - !ruby/object:Gem::Dependency
59
+ name: jeweler
60
+ requirement: &77140750 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.6.4
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *77140750
69
+ - !ruby/object:Gem::Dependency
70
+ name: rcov
71
+ requirement: &77140110 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *77140110
80
+ description: Allow manage Hudson CI from ruby
81
+ email: eloy@indeos.es
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files:
85
+ - LICENSE.txt
86
+ - README.rdoc
87
+ files:
88
+ - .document
89
+ - Gemfile
90
+ - Gemfile.lock
91
+ - LICENSE.txt
92
+ - README.rdoc
93
+ - Rakefile
94
+ - VERSION
95
+ - hudson-api.gemspec
96
+ - lib/api/job.rb
97
+ - lib/api/job_config.rb
98
+ - lib/api/job_instance.rb
99
+ - lib/hudson-api.rb
100
+ - test/helper.rb
101
+ - test/test_hudson-api.rb
102
+ homepage: http://github.com/harlock/hudson-api
103
+ licenses:
104
+ - MIT
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ segments:
116
+ - 0
117
+ hash: 192570253
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 1.8.8
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: Hudson api
130
+ test_files: []