jenkins-plugin-runtime 0.1.16 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Charles Lowell"]
10
10
  s.email = ["cowboyd@thefrontside.net"]
11
- s.homepage = "http://github.com/cowboyd/jenkins-plugins.rb"
11
+ s.homepage = "http://github.com/cowboyd/jenkins-plugin-runtime"
12
12
  s.summary = %q{Runtime support libraries for Jenkins Ruby plugins}
13
13
  s.description = %q{I'll think of a better description later, but if you're reading this, then I haven't}
14
14
 
@@ -24,6 +24,6 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency "rake", "0.8.7"
25
25
  s.add_development_dependency "rspec", "~> 2.0"
26
26
  s.add_development_dependency "rspec-spies"
27
- s.add_development_dependency "jenkins-war"
27
+ s.add_development_dependency "jenkins-war", "~> 1.445"
28
28
 
29
29
  end
@@ -4,7 +4,7 @@ module Jenkins
4
4
  class FilePath
5
5
  Stat = Struct.new(:size, :mode, :mtime)
6
6
 
7
- attr_reader :natvie
7
+ attr_reader :native
8
8
 
9
9
  def initialize(native)
10
10
  @native = native
@@ -3,9 +3,9 @@ require 'jenkins/filepath'
3
3
  module Jenkins
4
4
  module Model
5
5
 
6
- ##
7
- # Represents a single build. In general, you won't need this
8
- #
6
+ # Represents a single build. This object is passed in to
7
+ # all build steps, and can be used to configure, halt, message
8
+ # the current running build.
9
9
  class Build
10
10
 
11
11
  # Raised to indicate that a build wrapper halted a build.
@@ -16,9 +16,24 @@ module Jenkins
16
16
  # the Hudson::Model::AbstractBuild represented by this build
17
17
  attr_reader :native
18
18
 
19
- def initialize(native = nil)
19
+ # Hash of environment variables that will be added to each process
20
+ # started as part of this build. E.g.
21
+ #
22
+ # build.env['GEM_HOME'] = '/path/to/my/gem/home'
23
+ #
24
+ # Note that this is not an exhaustive list of all environement variables,
25
+ # only those which have been explicitly set by code inside this Ruby
26
+ # plugin.
27
+ #
28
+ # Also, this list does not contain variables that might get set by things
29
+ # like .profile and .rc files.
30
+ attr_reader :env
31
+
32
+ def initialize(native)
20
33
  @native = native
21
34
  @variables = {}
35
+ @env = {}
36
+ @native.buildEnvironments.add(EnvironmentVariables.new(@env))
22
37
  end
23
38
 
24
39
  # Gets a build value. Each build stores a map of key,value
@@ -40,6 +55,8 @@ module Jenkins
40
55
  @variables[key.to_s] = value
41
56
  end
42
57
 
58
+ # The workspace associated with this build
59
+ # @return [Jenkins::FilePath] workspace
43
60
  def workspace
44
61
  FilePath.new(@native.getWorkspace())
45
62
  end
@@ -58,18 +75,24 @@ module Jenkins
58
75
  raise Java.hudson.AbortException.new(reason)
59
76
  end
60
77
 
61
- def build_var
62
- @native.getBuildVariables()
63
- end
78
+ class EnvironmentVariables < Java.hudson.model.Environment
79
+ def initialize(variables)
80
+ super()
81
+ @variables = variables
82
+ end
64
83
 
65
- def env
66
- @native.getEnvironment(nil)
84
+ def buildEnvVars(map)
85
+ @variables.each do |key,value|
86
+ map.put(key.to_s.upcase, value.to_s)
87
+ end
88
+ end
67
89
  end
68
90
 
69
- def build_wrapper_environment(cls)
70
- @native.getEnvironmentList().find do |e|
71
- e.instance_of?(Jenkins::Plugin::Proxies::EnvironmentWrapper) && e.build_wrapper.instance_of?(cls)
72
- end
91
+ # Until the accessor gets into mainline, we
92
+ # add directly to the protected field
93
+ # @see https://github.com/jenkinsci/jenkins/commit/8cd23888b4f07efaa5bb499ad599375ca67b9146
94
+ Java.hudson.model.AbstractBuild.class_eval do
95
+ field_accessor :buildEnvironments
73
96
  end
74
97
 
75
98
  Jenkins::Plugin::Proxies.register self, Java.hudson.model.AbstractBuild
@@ -179,7 +179,7 @@ module Jenkins
179
179
  begin
180
180
  load path
181
181
  rescue Exception => e
182
- puts "#{e.message} (#{e.class})\n" << (e.backtrace || []).join("\n")
182
+ puts "#{e.message} (#{e.class})\n " << (e.backtrace || ["(not available)"]).join("\n ")
183
183
  end
184
184
  nil
185
185
  end
@@ -1,7 +1,7 @@
1
1
  module Jenkins
2
2
  class Plugin
3
3
  module Runtime
4
- VERSION = "0.1.16"
4
+ VERSION = "0.1.17"
5
5
  end
6
6
  end
7
7
  end
@@ -2,16 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe Jenkins::Model::Build do
4
4
  include Jenkins::Model
5
+ include SpecHelper
5
6
 
6
7
  before :each do
7
- @native = mock("AbstractBuild")
8
+ @native = mockito(Java.hudson.model.AbstractBuild)
9
+ @native.buildEnvironments = java.util.ArrayList.new
8
10
  @build = Jenkins::Model::Build.new(@native)
9
11
  end
10
12
 
11
- it "can be instantiated" do
12
- Jenkins::Model::Build.new
13
- end
14
-
15
13
  it "returns workspace path" do
16
14
  fs = Jenkins::FilePath.new(nil)
17
15
  fs.should_receive(:getRemote).and_return(".")
@@ -19,16 +17,6 @@ describe Jenkins::Model::Build do
19
17
  @build.workspace.to_s.should == "."
20
18
  end
21
19
 
22
- it "returns build variables as Hash-like" do
23
- @native.should_receive(:getBuildVariables).and_return("FOO" => "BAR")
24
- @build.build_var.should == {"FOO" => "BAR"}
25
- end
26
-
27
- it "returns environment variables as Hash-like" do
28
- @native.should_receive(:getEnvironment).with(nil).and_return("FOO" => "BAR")
29
- @build.env.should == {"FOO" => "BAR"}
30
- end
31
-
32
20
  it "can halt" do
33
21
  expect {@build.halt "stopping"}.should raise_error(Jenkins::Model::Build::Halt, "stopping")
34
22
  end
@@ -57,4 +45,21 @@ describe Jenkins::Model::Build do
57
45
  end
58
46
  end
59
47
 
48
+ describe "environment variables" do
49
+ before do
50
+ @build.env['FOO'] = 'bar'
51
+ @build.env[:bar] = :baz
52
+ Java.org.mockito.Mockito.when(@native.getEvironment(nil)).thenCallRealMethod()
53
+ @vars = @native.getEnvironment(nil)
54
+ end
55
+
56
+ it "sets environment variables into the native build environment" do
57
+ @vars.get('FOO').should eql 'bar'
58
+ end
59
+
60
+ it "capitalizes and stringifies keys and stringifies values" do
61
+ @vars.get('BAR').should eql 'baz'
62
+ end
63
+ end
64
+
60
65
  end
@@ -10,6 +10,7 @@ $:.unshift Pathname(__FILE__).dirname.join('../lib')
10
10
 
11
11
  require 'jenkins/plugin/runtime'
12
12
  require 'jenkins/plugin/proxies/proxy_helper'
13
+ require File.expand_path '../mockito-all-1.8.5.jar', __FILE__
13
14
 
14
15
  module SpecHelper
15
16
  # Java does not support opening directory as a File: File.open(".")
@@ -42,4 +43,8 @@ module SpecHelper
42
43
  f << content
43
44
  end
44
45
  end
46
+
47
+ def mockito(cls)
48
+ Java.org.mockito.Mockito.mock(cls.java_class)
49
+ end
45
50
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jenkins-plugin-runtime
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.16
5
+ version: 0.1.17
6
6
  platform: ruby
7
7
  authors:
8
8
  - Charles Lowell
@@ -10,63 +10,63 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-12-14 00:00:00 Z
13
+ date: 2011-12-27 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
17
- version_requirements: &id001 !ruby/object:Gem::Requirement
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
18
19
  none: false
19
20
  requirements:
20
21
  - - ">="
21
22
  - !ruby/object:Gem::Version
22
23
  version: "0"
23
- requirement: *id001
24
- prerelease: false
25
24
  type: :runtime
25
+ version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rake
28
- version_requirements: &id002 !ruby/object:Gem::Requirement
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
29
30
  none: false
30
31
  requirements:
31
32
  - - "="
32
33
  - !ruby/object:Gem::Version
33
34
  version: 0.8.7
34
- requirement: *id002
35
- prerelease: false
36
35
  type: :development
36
+ version_requirements: *id002
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- version_requirements: &id003 !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
40
41
  none: false
41
42
  requirements:
42
43
  - - ~>
43
44
  - !ruby/object:Gem::Version
44
45
  version: "2.0"
45
- requirement: *id003
46
- prerelease: false
47
46
  type: :development
47
+ version_requirements: *id003
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rspec-spies
50
- version_requirements: &id004 !ruby/object:Gem::Requirement
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
51
52
  none: false
52
53
  requirements:
53
54
  - - ">="
54
55
  - !ruby/object:Gem::Version
55
56
  version: "0"
56
- requirement: *id004
57
- prerelease: false
58
57
  type: :development
58
+ version_requirements: *id004
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: jenkins-war
61
- version_requirements: &id005 !ruby/object:Gem::Requirement
61
+ prerelease: false
62
+ requirement: &id005 !ruby/object:Gem::Requirement
62
63
  none: false
63
64
  requirements:
64
- - - ">="
65
+ - - ~>
65
66
  - !ruby/object:Gem::Version
66
- version: "0"
67
- requirement: *id005
68
- prerelease: false
67
+ version: "1.445"
69
68
  type: :development
69
+ version_requirements: *id005
70
70
  description: I'll think of a better description later, but if you're reading this, then I haven't
71
71
  email:
72
72
  - cowboyd@thefrontside.net
@@ -128,10 +128,11 @@ files:
128
128
  - spec/jenkins/plugin_spec.rb
129
129
  - spec/jenkins/tasks/build_wrapper_spec.rb
130
130
  - spec/jenkins/tasks/builder_spec.rb
131
+ - spec/mockito-all-1.8.5.jar
131
132
  - spec/spec_helper.rb
132
133
  - src/jenkins/ruby/DoDynamic.java
133
134
  - src/jenkins/ruby/Get.java
134
- homepage: http://github.com/cowboyd/jenkins-plugins.rb
135
+ homepage: http://github.com/cowboyd/jenkins-plugin-runtime
135
136
  licenses: []
136
137
 
137
138
  post_install_message:
@@ -144,18 +145,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
145
  requirements:
145
146
  - - ">="
146
147
  - !ruby/object:Gem::Version
147
- hash: 2
148
- segments:
149
- - 0
150
148
  version: "0"
151
149
  required_rubygems_version: !ruby/object:Gem::Requirement
152
150
  none: false
153
151
  requirements:
154
152
  - - ">="
155
153
  - !ruby/object:Gem::Version
156
- hash: 2
157
- segments:
158
- - 0
159
154
  version: "0"
160
155
  requirements: []
161
156
 
@@ -164,24 +159,5 @@ rubygems_version: 1.8.9
164
159
  signing_key:
165
160
  specification_version: 3
166
161
  summary: Runtime support libraries for Jenkins Ruby plugins
167
- test_files:
168
- - spec/jenkins/filepath_spec.rb
169
- - spec/jenkins/launcher_spec.rb
170
- - spec/jenkins/model/action_spec.rb
171
- - spec/jenkins/model/build_spec.rb
172
- - spec/jenkins/model/describable_spec.rb
173
- - spec/jenkins/model/listener_spec.rb
174
- - spec/jenkins/model_spec.rb
175
- - spec/jenkins/plugin/example.pluginspec
176
- - spec/jenkins/plugin/proxies/build_wrapper_spec.rb
177
- - spec/jenkins/plugin/proxies/builder_spec.rb
178
- - spec/jenkins/plugin/proxies/proxy_helper.rb
179
- - spec/jenkins/plugin/proxies/publisher_spec.rb
180
- - spec/jenkins/plugin/proxies/root_action_spec.rb
181
- - spec/jenkins/plugin/proxies_spec.rb
182
- - spec/jenkins/plugin/proxy_spec.rb
183
- - spec/jenkins/plugin/specification_spec.rb
184
- - spec/jenkins/plugin_spec.rb
185
- - spec/jenkins/tasks/build_wrapper_spec.rb
186
- - spec/jenkins/tasks/builder_spec.rb
187
- - spec/spec_helper.rb
162
+ test_files: []
163
+