jenkins-plugin-runtime 0.1.21 → 0.1.22

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.
@@ -0,0 +1,55 @@
1
+ module Jenkins::Listeners
2
+ # Receive notification of build events.
3
+ #
4
+ # Include this module in your class in order to receive callbacks
5
+ # when builds are started, completed, deleted, etc...
6
+ #
7
+ # To receive a callback, override the method with the same name as
8
+ # the event. E.g.
9
+ #
10
+ # class MyRunListener
11
+ # include Jenkins::Listeners::RunListener
12
+ #
13
+ # def started(build, listener)
14
+ # puts "build.inspect started!"
15
+ # end
16
+ # end
17
+ #
18
+ module RunListener
19
+ extend Jenkins::Plugin::Behavior
20
+
21
+ implemented do |cls|
22
+ Jenkins.plugin.register_extension RunListenerProxy.new(Jenkins.plugin, cls.new)
23
+ end
24
+
25
+ # Called when a build is started (i.e. it was in the queue, and will now start running
26
+ # on an executor)
27
+ #
28
+ # @param [Jenkins::Model::Build] the started build
29
+ # @param [Jenkins::Model::TaskListener] the task listener for this build
30
+ def started(build, listener)
31
+ end
32
+
33
+ # Called after a build is completed.
34
+ #
35
+ # @param [Jenkins::Model::Build] the completed build
36
+ # @param [Jenkins::Model::TaskListener] the task listener for this build
37
+ def completed(build, listener)
38
+ end
39
+
40
+ # Called after a build is finalized.
41
+ #
42
+ # At this point, all the records related to a build is written down to the disk. As such,
43
+ # task Listener is no longer available. This happens later than {#completed}.
44
+ #
45
+ # @param [Jenkins::Model::Build] the finalized build
46
+ def finalized(build)
47
+ end
48
+
49
+ # Called right before a build is going to be deleted.
50
+ #
51
+ # @param [Jenkins::Model::Build] The build.
52
+ def deleted(build)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,25 @@
1
+ module Jenkins::Listeners
2
+ class RunListenerProxy < Java.hudson.model.listeners.RunListener
3
+ include Jenkins::Plugin::Proxy
4
+
5
+ def initialize(plugin, object)
6
+ super(plugin, object, Java.hudson.model.AbstractBuild.java_class)
7
+ end
8
+
9
+ def onStarted(run, listener)
10
+ @object.started(run, listener)
11
+ end
12
+
13
+ def onCompleted(run, listener)
14
+ @object.completed(run, listener)
15
+ end
16
+
17
+ def onFinalized(run)
18
+ @object.finalized(run)
19
+ end
20
+
21
+ def onDeleted(run)
22
+ @object.deleted(run)
23
+ end
24
+ end
25
+ end
@@ -17,3 +17,5 @@ require 'jenkins/slaves/cloud'
17
17
  require 'jenkins/tasks/builder'
18
18
  require 'jenkins/tasks/build_wrapper'
19
19
  require 'jenkins/launcher'
20
+ require 'jenkins/listeners/run_listener'
21
+ require 'jenkins/listeners/run_listener_proxy'
@@ -1,7 +1,7 @@
1
1
  module Jenkins
2
2
  class Plugin
3
3
  module Runtime
4
- VERSION = "0.1.21"
4
+ VERSION = "0.1.22"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'rspec-spies'
3
+
4
+ describe Jenkins::Listeners::RunListenerProxy do
5
+ before do
6
+ @listener = mock(Jenkins::Listeners::RunListener)
7
+ @proxy = Jenkins::Listeners::RunListenerProxy.new(mock(Jenkins::Plugin, :name => 'test-plugin'), @listener)
8
+ @build = mock(Jenkins::Model::Build)
9
+ @console = mock(Jenkins::Model::Listener)
10
+ end
11
+
12
+ describe "when started" do
13
+ before do
14
+ @listener.stub(:started)
15
+ @proxy.onStarted(@build, @console)
16
+ end
17
+ it 'invokes the started callback' do
18
+ @listener.should have_received(:started).with(@build, @console)
19
+ end
20
+ end
21
+
22
+ describe 'when completed' do
23
+ before do
24
+ @listener.stub(:completed)
25
+ @proxy.onCompleted(@build, @console)
26
+ end
27
+ it 'invokes the completed callback' do
28
+ @listener.should have_received(:completed).with(@build, @console)
29
+ end
30
+ end
31
+
32
+ describe 'when finalized' do
33
+ before do
34
+ @listener.stub(:finalized)
35
+ @proxy.onFinalized(@build)
36
+ end
37
+ it 'invokes the finalized callback' do
38
+ @listener.should have_received(:finalized).with(@build)
39
+ end
40
+ end
41
+
42
+ describe 'when deleted' do
43
+ before do
44
+ @listener.stub(:deleted)
45
+ @proxy.onDeleted(@build)
46
+ end
47
+ it 'invokes the deleted callback' do
48
+ @listener.should have_received(:deleted).with(@build)
49
+ end
50
+ end
51
+ 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.21
5
+ version: 0.1.22
6
6
  platform: ruby
7
7
  authors:
8
8
  - Charles Lowell
@@ -99,6 +99,8 @@ files:
99
99
  - lib/jenkins/cli/command_proxy.rb
100
100
  - lib/jenkins/filepath.rb
101
101
  - lib/jenkins/launcher.rb
102
+ - lib/jenkins/listeners/run_listener.rb
103
+ - lib/jenkins/listeners/run_listener_proxy.rb
102
104
  - lib/jenkins/model.rb
103
105
  - lib/jenkins/model/action.rb
104
106
  - lib/jenkins/model/build.rb
@@ -131,6 +133,7 @@ files:
131
133
  - spec/jenkins/cli/command_spec.rb
132
134
  - spec/jenkins/filepath_spec.rb
133
135
  - spec/jenkins/launcher_spec.rb
136
+ - spec/jenkins/listeners/run_listener_proxy_spec.rb
134
137
  - spec/jenkins/model/action_spec.rb
135
138
  - spec/jenkins/model/build_spec.rb
136
139
  - spec/jenkins/model/describable_spec.rb
@@ -184,6 +187,7 @@ test_files:
184
187
  - spec/jenkins/cli/command_spec.rb
185
188
  - spec/jenkins/filepath_spec.rb
186
189
  - spec/jenkins/launcher_spec.rb
190
+ - spec/jenkins/listeners/run_listener_proxy_spec.rb
187
191
  - spec/jenkins/model/action_spec.rb
188
192
  - spec/jenkins/model/build_spec.rb
189
193
  - spec/jenkins/model/describable_spec.rb