jenkins-plugin-runtime 0.1.26 → 0.1.27

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,6 +44,7 @@ module Jenkins::CLI
44
44
  # @see {https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI Running Jenkins CLI}
45
45
  module Command
46
46
  extend Jenkins::Plugin::Behavior
47
+ include Jenkins::Extension
47
48
 
48
49
  implemented do |cls|
49
50
  cls.instance_eval do
@@ -0,0 +1,29 @@
1
+ module Jenkins
2
+ #
3
+ # Defines the equivalent of `hudson.Extension`
4
+ #
5
+ module Extension
6
+ extend Plugin::Behavior
7
+
8
+ module ClassMethods
9
+ #
10
+ # Set the relative order of your extension among others.
11
+ # Ordinals are in the descending order, so the bigger the value, the closer you get to the head of the list.
12
+ #
13
+ # class MyRootAction extends RootAction
14
+ # ordinal 3
15
+
16
+ # ...
17
+ # end
18
+ def order(n=nil)
19
+ if n.nil?
20
+ @order || 0
21
+ else
22
+ @order = n
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+
29
+ end
@@ -17,6 +17,7 @@ module Jenkins::Listeners
17
17
  #
18
18
  module RunListener
19
19
  extend Jenkins::Plugin::Behavior
20
+ include Jenkins::Extension
20
21
 
21
22
  implemented do |cls|
22
23
  Jenkins.plugin.register_extension RunListenerProxy.new(Jenkins.plugin, cls.new)
data/lib/jenkins/model.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  module Jenkins
3
3
  module Model
4
4
  extend Plugin::Behavior
5
+ include Jenkins::Extension
5
6
 
6
7
  module InstanceDisplayName
7
8
  # Get the display name of this Model. This value will be used as a default
@@ -30,6 +30,7 @@ module Jenkins
30
30
  # glue layer and not the public runtime API.
31
31
  module Describable
32
32
  extend Plugin::Behavior
33
+ include Jenkins::Extension
33
34
  DescribableError = Class.new(StandardError)
34
35
 
35
36
  implemented do |cls|
@@ -1,6 +1,7 @@
1
1
  module Jenkins::Model
2
2
  module EnvironmentProxy
3
3
  extend Jenkins::Plugin::Behavior
4
+ include Jenkins::Extension
4
5
 
5
6
  module InstanceMethods
6
7
  def setUp(build, launcher, listener)
@@ -101,7 +101,19 @@ module Jenkins
101
101
 
102
102
  def register_extension(class_or_instance, *args)
103
103
  extension = class_or_instance.is_a?(Class) ? class_or_instance.new(*args) : class_or_instance
104
- @peer.addExtension(export(extension))
104
+
105
+ # look everywhere for possible ordinal value.
106
+ # extension can be a Java object, or a Proxy to a Ruby object
107
+ ordinal = 0
108
+ if extension.class.respond_to? :order
109
+ ordinal = extension.class.order
110
+ else
111
+ t = import(extension)
112
+ if t.class.respond_to? :order
113
+ ordinal = t.class.order
114
+ end
115
+ end
116
+ @peer.addExtension(export(extension), ordinal)
105
117
  end
106
118
 
107
119
  # Register a ruby class as a Jenkins extension point of
@@ -36,9 +36,28 @@ module Jenkins
36
36
  # end
37
37
  # end
38
38
  # end
39
+ #
39
40
  # And of course, there is the case of proxies where we need to make sure that
40
41
  # certain behaviors are always included into the proxy, and that if java classes
41
42
  # need to be implemented, they are.
43
+ #
44
+ # If the module (=X) that extend Behavior defines a module named ClassMethods in it,
45
+ # then every subtype of X automatically extends this ClassMethods.n
46
+ #
47
+ # module Foo
48
+ # extend Behavior
49
+ # module ClassMethod
50
+ # def look_ma
51
+ # puts "I'm here'"
52
+ # end
53
+ # end
54
+ # end
55
+ # class Bar
56
+ # include Foo
57
+ # end
58
+ #
59
+ # Bar.look_ma
60
+ #
42
61
  module Behavior
43
62
  def included(mod)
44
63
  if mod.is_a? Class
@@ -28,6 +28,7 @@ module Jenkins
28
28
  super(*super_args) if defined? super
29
29
  @plugin, @object = plugin, object
30
30
  @pluginid = @plugin.name
31
+ @plugin.linkout object, self
31
32
  end
32
33
 
33
34
  # tell Stapler to go look for views from the wrapped object
@@ -1,5 +1,6 @@
1
1
  require 'jenkins/plugin'
2
2
  require 'jenkins/plugin/behavior'
3
+ require 'jenkins/extension'
3
4
  require 'jenkins/plugin/wrapper'
4
5
  require 'jenkins/plugin/specification'
5
6
  require 'jenkins/plugin/runtime/version'
@@ -1,7 +1,7 @@
1
1
  module Jenkins
2
2
  class Plugin
3
3
  module Runtime
4
- VERSION = "0.1.26"
4
+ VERSION = "0.1.27"
5
5
  end
6
6
  end
7
7
  end
@@ -17,6 +17,7 @@ module Jenkins::Slaves
17
17
  #
18
18
  module ComputerListener
19
19
  extend Jenkins::Plugin::Behavior
20
+ include Jenkins::Extension
20
21
 
21
22
  implemented do |cls|
22
23
  Jenkins.plugin.register_extension ComputerListenerProxy.new(Jenkins.plugin, cls.new)
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jenkins::Extension do
4
+ include SpecHelper
5
+
6
+ it "adds the ordinal method to class" do
7
+ class Foo
8
+ class Foo
9
+ include Jenkins::Extension
10
+ order 3
11
+ end
12
+
13
+ class Bar < Foo
14
+ order 5
15
+ end
16
+
17
+ Foo.order.should == 3
18
+ Bar.order.should == 5
19
+ end
20
+ end
21
+ end
@@ -4,8 +4,10 @@ describe Jenkins::Plugin::Proxies do
4
4
  Proxies = Jenkins::Plugin::Proxies
5
5
  before do
6
6
  Proxies.clear
7
- @plugin = mock(Jenkins::Plugin)
7
+ @plugin = mock(Jenkins::Plugin, :name => 'mock-plugin')
8
+ @plugin.stub(:linkout) {|*args| @proxies.linkout(*args)}
8
9
  @proxies = Jenkins::Plugin::Proxies.new(@plugin)
10
+ Jenkins.stub(:plugin) {@plugin}
9
11
  end
10
12
 
11
13
  describe "exporting a native ruby object" do
@@ -163,15 +165,33 @@ describe Jenkins::Plugin::Proxies do
163
165
  end
164
166
  end
165
167
 
168
+ describe 'importing a java proxy object which was manually created' do
169
+ before do
170
+ @impl = Object.new
171
+ @proxy = proxy_class.new(@plugin, @impl)
172
+ end
173
+
174
+ it 'returns the proxied ruby object' do
175
+ @proxies.import(@proxy).should be @impl
176
+ end
177
+
178
+ it 'exports the proxy in lieu of the ruby implementation' do
179
+ @proxies.export(@impl).should be @proxy
180
+ end
181
+ end
182
+
166
183
  private
167
184
 
168
185
  def proxy_class
169
- cls = Class.new
186
+ cls = Class.new(java.lang.Object)
170
187
  cls.class_eval do
188
+ include Jenkins::Plugin::Proxy
171
189
  attr_reader :plugin, :object
190
+
172
191
  def initialize(plugin = nil, object = nil)
173
- @plugin, @object = plugin, object
192
+ super(plugin || Jenkins.plugin, object)
174
193
  end
194
+
175
195
  end
176
196
  return cls
177
197
  end
@@ -1,8 +1,52 @@
1
1
  require 'spec_helper'
2
+ require 'rspec-spies'
2
3
  require 'tmpdir'
3
4
 
4
5
  describe Jenkins::Plugin do
5
6
 
7
+ describe 'registering an extension.' do
8
+ before do
9
+ @peer = mock(:name => 'org.jenkinsci.ruby.RubyPlugin')
10
+ @peer.stub(:addExtension)
11
+ @plugin = Jenkins::Plugin.new @peer
12
+ @plugin.stub(:export) {|obj| obj}
13
+ end
14
+ describe 'When the extension class defines its order' do
15
+ before do
16
+ ext_class = Class.new
17
+ def ext_class.order; 10;end
18
+ @ext = ext_class.new
19
+ @plugin.register_extension @ext
20
+ end
21
+ it 'uses it' do
22
+ @peer.should have_received(:addExtension).with(@ext,10)
23
+ end
24
+ end
25
+ describe 'When the extension is a proxy' do
26
+ before do
27
+ impl_class = Class.new
28
+ def impl_class.order; 5; end
29
+ @impl = impl_class.new
30
+ @ext = Object.new
31
+ @plugin.stub(:import) {@impl}
32
+ @plugin.register_extension @ext
33
+ end
34
+ it 'uses the proxied objects class order' do
35
+ @peer.should have_received(:addExtension).with(@ext, 5)
36
+ end
37
+ end
38
+
39
+ describe 'when no order is defined' do
40
+ before do
41
+ @ext = Object.new
42
+ @plugin.register_extension @ext
43
+ end
44
+ it 'uses 0' do
45
+ @peer.should have_received(:addExtension).with(@ext, 0)
46
+ end
47
+ end
48
+ end
49
+
6
50
  describe Jenkins::Plugin::Lifecycle do
7
51
  before do |variable|
8
52
  @plugin = Jenkins::Plugin.new mock(:name => 'org.jenkinsci.ruby.RubyPlugin')
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.26
5
+ version: 0.1.27
6
6
  platform: ruby
7
7
  authors:
8
8
  - Charles Lowell
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-02-03 00:00:00 Z
13
+ date: 2012-03-22 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -88,8 +88,6 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
 
90
90
  files:
91
- - .gitignore
92
- - .travis.yml
93
91
  - Gemfile
94
92
  - README.md
95
93
  - Rakefile
@@ -97,6 +95,7 @@ files:
97
95
  - lib/core_ext/exception.rb
98
96
  - lib/jenkins/cli/command.rb
99
97
  - lib/jenkins/cli/command_proxy.rb
98
+ - lib/jenkins/extension.rb
100
99
  - lib/jenkins/filepath.rb
101
100
  - lib/jenkins/launcher.rb
102
101
  - lib/jenkins/listeners/run_listener.rb
@@ -137,6 +136,7 @@ files:
137
136
  - lib/jenkins/tasks/publisher.rb
138
137
  - spec/jenkins/cli/command_proxy_spec.rb
139
138
  - spec/jenkins/cli/command_spec.rb
139
+ - spec/jenkins/extension_spec.rb
140
140
  - spec/jenkins/filepath_spec.rb
141
141
  - spec/jenkins/launcher_spec.rb
142
142
  - spec/jenkins/listeners/run_listener_proxy_spec.rb
@@ -184,13 +184,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
184
  requirements: []
185
185
 
186
186
  rubyforge_project: jenkins-plugin-runtime
187
- rubygems_version: 1.8.9
187
+ rubygems_version: 1.8.15
188
188
  signing_key:
189
189
  specification_version: 3
190
190
  summary: Runtime support libraries for Jenkins Ruby plugins
191
191
  test_files:
192
192
  - spec/jenkins/cli/command_proxy_spec.rb
193
193
  - spec/jenkins/cli/command_spec.rb
194
+ - spec/jenkins/extension_spec.rb
194
195
  - spec/jenkins/filepath_spec.rb
195
196
  - spec/jenkins/launcher_spec.rb
196
197
  - spec/jenkins/listeners/run_listener_proxy_spec.rb
data/.gitignore DELETED
@@ -1,7 +0,0 @@
1
- .rvmrc
2
- *.gem
3
- .bundle
4
- .idea
5
- Gemfile.lock
6
- pkg/*
7
- target/
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- rvm:
2
- - jruby
3
- notifications:
4
- recipients:
5
- - cowboyd@thefrontside.net
6
- - kk@kohsuke.org
7
- - nakahiro@gmail.com