jenkins-plugin-runtime 0.1.17 → 0.1.18
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.
- data/lib/jenkins/filepath.rb +4 -0
- data/lib/jenkins/model/build.rb +1 -1
- data/lib/jenkins/model/describable.rb +18 -8
- data/lib/jenkins/model/descriptor.rb +16 -2
- data/lib/jenkins/plugin/proxies/action.rb +2 -8
- data/lib/jenkins/plugin/proxies/build_wrapper.rb +1 -9
- data/lib/jenkins/plugin/proxies/builder.rb +1 -9
- data/lib/jenkins/plugin/proxies/describable.rb +17 -0
- data/lib/jenkins/plugin/proxies/publisher.rb +1 -9
- data/lib/jenkins/plugin/proxies/root_action.rb +1 -8
- data/lib/jenkins/plugin/proxies.rb +6 -1
- data/lib/jenkins/plugin/proxy.rb +3 -2
- data/lib/jenkins/plugin/runtime/version.rb +1 -1
- data/lib/jenkins/plugin/runtime.rb +1 -0
- data/lib/jenkins/plugin.rb +16 -4
- data/lib/jenkins/rack.rb +1 -1
- data/spec/jenkins/model/build_spec.rb +1 -0
- data/spec/jenkins/model/describable_spec.rb +13 -2
- data/spec/jenkins/plugin/proxies_spec.rb +14 -0
- data/spec/jenkins/plugin_spec.rb +0 -3
- metadata +25 -4
data/lib/jenkins/filepath.rb
CHANGED
data/lib/jenkins/model/build.rb
CHANGED
@@ -21,7 +21,7 @@ module Jenkins
|
|
21
21
|
#
|
22
22
|
# build.env['GEM_HOME'] = '/path/to/my/gem/home'
|
23
23
|
#
|
24
|
-
# Note that this is not an exhaustive list of all
|
24
|
+
# Note that this is not an exhaustive list of all environment variables,
|
25
25
|
# only those which have been explicitly set by code inside this Ruby
|
26
26
|
# plugin.
|
27
27
|
#
|
@@ -19,6 +19,7 @@ module Jenkins
|
|
19
19
|
# class Builder
|
20
20
|
# include Jenkins::Model::Describable
|
21
21
|
# describe_as Java.hudson.tasks.Builder
|
22
|
+
# descriptor_is Jenkins::Tasks::BuildStepDescriptor
|
22
23
|
# end
|
23
24
|
#
|
24
25
|
# behind the scenes, this creates a `Descriptor` instance registered against the java type
|
@@ -31,15 +32,22 @@ module Jenkins
|
|
31
32
|
DescribableError = Class.new(StandardError)
|
32
33
|
|
33
34
|
module DescribeAs
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
# Java class that represents the extension point, which gets eventually set to Descriptor.clazz
|
36
|
+
# :with will use this java class as the type of descriptor.
|
37
|
+
def describe_as cls, options = {}
|
38
|
+
@describe_as_type = verify_java_class(cls).java_class
|
39
|
+
@descriptor_is = verify_java_class(options[:with]).java_class if options[:with]
|
40
|
+
end
|
41
|
+
attr_reader :describe_as_type
|
42
|
+
attr_reader :descriptor_is
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def verify_java_class cls
|
47
|
+
if !defined?(cls.java_class) || !cls.is_a?(Class)
|
38
48
|
fail DescribableError, "#{cls.class.inspect} is not an instance of java.lang.Class"
|
39
49
|
end
|
40
|
-
|
41
|
-
def describe_as_type
|
42
|
-
@describe_as_type
|
50
|
+
cls
|
43
51
|
end
|
44
52
|
end
|
45
53
|
|
@@ -49,11 +57,13 @@ module Jenkins
|
|
49
57
|
super(cls)
|
50
58
|
cls.extend Inherited
|
51
59
|
describe_as_type = @describe_as_type
|
60
|
+
descriptor_is = @descriptor_is
|
52
61
|
cls.class_eval do
|
53
62
|
@describe_as_type = describe_as_type
|
63
|
+
@descriptor_is = descriptor_is
|
54
64
|
end
|
55
65
|
if Jenkins::Plugin.instance
|
56
|
-
Jenkins::Plugin.instance.register_describable(cls, describe_as_type)
|
66
|
+
Jenkins::Plugin.instance.register_describable(cls, describe_as_type, descriptor_is)
|
57
67
|
end
|
58
68
|
end
|
59
69
|
end
|
@@ -3,8 +3,13 @@ require 'json'
|
|
3
3
|
|
4
4
|
module Jenkins
|
5
5
|
module Model
|
6
|
-
|
7
|
-
|
6
|
+
#
|
7
|
+
# Jenkins typically defines one Descriptor subtype per extension point, and
|
8
|
+
# in Ruby we want to subtype those to add Ruby-specific behaviours.
|
9
|
+
#
|
10
|
+
# This class captures commonality of such "Ruby-specific behaviours" across different Descriptors
|
11
|
+
# so it can be mixed into the Descriptor subtypes
|
12
|
+
module RubyDescriptor
|
8
13
|
def initialize(impl, plugin, java_type)
|
9
14
|
super(java_type)
|
10
15
|
@impl, @plugin, @java_type = impl, plugin, java_type
|
@@ -22,6 +27,11 @@ module Jenkins
|
|
22
27
|
@java_type
|
23
28
|
end
|
24
29
|
|
30
|
+
# let Jenkins use our Ruby class for resource lookup and all
|
31
|
+
def getKlass()
|
32
|
+
@plugin.peer.klassFor(@impl)
|
33
|
+
end
|
34
|
+
|
25
35
|
# we take a fully-qualified class name, like Abc::Def::GhiJkl to underscore-separated tokens, like abc/def/ghi_jkl
|
26
36
|
# and then look for config.* (where *=.erb, .haml, ...)
|
27
37
|
def getConfigPage
|
@@ -52,6 +62,7 @@ module Jenkins
|
|
52
62
|
def construct(attrs)
|
53
63
|
@impl.new(attrs)
|
54
64
|
rescue ArgumentError
|
65
|
+
# TODO: this automatic rescue can mask a user-problem in the constructor
|
55
66
|
@impl.new
|
56
67
|
end
|
57
68
|
|
@@ -67,5 +78,8 @@ module Jenkins
|
|
67
78
|
end
|
68
79
|
end
|
69
80
|
|
81
|
+
class Descriptor < Java.hudson.model.Descriptor
|
82
|
+
include RubyDescriptor
|
83
|
+
end
|
70
84
|
end
|
71
85
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'jenkins/model/action'
|
2
|
+
require 'jenkins/plugin/proxies/describable'
|
2
3
|
|
3
4
|
module Jenkins
|
4
5
|
class Plugin
|
@@ -7,6 +8,7 @@ module Jenkins
|
|
7
8
|
include Java.hudson.model.Action
|
8
9
|
include Java.jenkins.ruby.Get
|
9
10
|
include Jenkins::Plugin::Proxy
|
11
|
+
include Jenkins::Plugin::Proxies::Describable
|
10
12
|
|
11
13
|
def getIconFileName
|
12
14
|
@object.icon
|
@@ -15,14 +17,6 @@ module Jenkins
|
|
15
17
|
def getUrlName
|
16
18
|
@object.url_path
|
17
19
|
end
|
18
|
-
|
19
|
-
def getDescriptor
|
20
|
-
@plugin.descriptors[@object.class]
|
21
|
-
end
|
22
|
-
|
23
|
-
def get(name)
|
24
|
-
@object.respond_to?(name) ? @object.send(name) : nil
|
25
|
-
end
|
26
20
|
end
|
27
21
|
|
28
22
|
register Jenkins::Model::Action, Action
|
@@ -11,6 +11,7 @@ module Jenkins
|
|
11
11
|
# Ruby API Jenkins::Tasks::BuildWrapper
|
12
12
|
|
13
13
|
class BuildWrapper < Java.hudson.tasks.BuildWrapper
|
14
|
+
include Jenkins::Plugin::Proxies::Describable
|
14
15
|
include Java.jenkins.ruby.Get
|
15
16
|
include Jenkins::Plugin::Proxy
|
16
17
|
|
@@ -20,15 +21,6 @@ module Jenkins
|
|
20
21
|
rescue Jenkins::Model::Build::Halt
|
21
22
|
nil
|
22
23
|
end
|
23
|
-
|
24
|
-
def getDescriptor
|
25
|
-
@plugin.descriptors[@object.class]
|
26
|
-
end
|
27
|
-
|
28
|
-
def get(name)
|
29
|
-
@object.respond_to?(name) ? @object.send(name) : nil
|
30
|
-
end
|
31
|
-
|
32
24
|
end
|
33
25
|
|
34
26
|
|
@@ -5,18 +5,10 @@ module Jenkins
|
|
5
5
|
class Plugin
|
6
6
|
class Proxies
|
7
7
|
class Builder < Java.hudson.tasks.Builder
|
8
|
+
include Jenkins::Plugin::Proxies::Describable
|
8
9
|
include Java.jenkins.ruby.Get
|
9
10
|
include Jenkins::Plugin::Proxy
|
10
|
-
|
11
11
|
include BuildStep
|
12
|
-
|
13
|
-
def getDescriptor
|
14
|
-
@plugin.descriptors[@object.class]
|
15
|
-
end
|
16
|
-
|
17
|
-
def get(name)
|
18
|
-
@object.respond_to?(name) ? @object.send(name) : nil
|
19
|
-
end
|
20
12
|
end
|
21
13
|
|
22
14
|
register Jenkins::Tasks::Builder, Builder
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Jenkins
|
2
|
+
class Plugin
|
3
|
+
class Proxies
|
4
|
+
# mix-in on top of the subtypes of the Describable Java class
|
5
|
+
# to add standard behaviour as a proxy to Ruby object
|
6
|
+
module Describable
|
7
|
+
def getDescriptor
|
8
|
+
@plugin.descriptors[@object.class]
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(name)
|
12
|
+
@object.respond_to?(name) ? @object.send(name) : nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -5,18 +5,10 @@ module Jenkins
|
|
5
5
|
class Plugin
|
6
6
|
class Proxies
|
7
7
|
class Publisher < Java.hudson.tasks.Publisher
|
8
|
+
include Jenkins::Plugin::Proxies::Describable
|
8
9
|
include Java.jenkins.ruby.Get
|
9
10
|
include Jenkins::Plugin::Proxy
|
10
|
-
|
11
11
|
include BuildStep
|
12
|
-
|
13
|
-
def getDescriptor
|
14
|
-
@plugin.descriptors[@object.class]
|
15
|
-
end
|
16
|
-
|
17
|
-
def get(name)
|
18
|
-
@object.respond_to?(name) ? @object.send(name) : nil
|
19
|
-
end
|
20
12
|
end
|
21
13
|
|
22
14
|
register Jenkins::Tasks::Publisher, Publisher
|
@@ -7,6 +7,7 @@ module Jenkins
|
|
7
7
|
include Java.hudson.model.RootAction
|
8
8
|
include Java.jenkins.ruby.Get
|
9
9
|
include Jenkins::Plugin::Proxy
|
10
|
+
include Jenkins::Plugin::Proxies::Describable
|
10
11
|
|
11
12
|
def getDisplayName
|
12
13
|
@object.display_name
|
@@ -19,14 +20,6 @@ module Jenkins
|
|
19
20
|
def getUrlName
|
20
21
|
@object.url_path
|
21
22
|
end
|
22
|
-
|
23
|
-
def getDescriptor
|
24
|
-
@plugin.descriptors[@object.class]
|
25
|
-
end
|
26
|
-
|
27
|
-
def get(name)
|
28
|
-
@object.respond_to?(name) ? @object.send(name) : nil
|
29
|
-
end
|
30
23
|
end
|
31
24
|
|
32
25
|
register Jenkins::Model::RootAction, RootAction
|
@@ -69,6 +69,8 @@ module Jenkins
|
|
69
69
|
# Reflect a native Ruby object into its External Java form.
|
70
70
|
#
|
71
71
|
# Try to find a suitable form for this object and if one is found then decorate it.
|
72
|
+
# If the object already is a java.lang.Object, then just let it pass through.
|
73
|
+
#
|
72
74
|
# @param [Object] object the ruby object that is being exported to Java
|
73
75
|
# @return [java.lang.Object] the Java wrapper that provides an interface to `object`
|
74
76
|
# @throw [ExportError] if no suitable Java representation can be found
|
@@ -78,6 +80,9 @@ module Jenkins
|
|
78
80
|
end
|
79
81
|
|
80
82
|
cls = object.class
|
83
|
+
if cls.respond_to? :java_class
|
84
|
+
return object
|
85
|
+
end
|
81
86
|
while cls do
|
82
87
|
if external_class = @@intcls2extcls[cls]
|
83
88
|
external = external_class.new(@plugin, object)
|
@@ -149,7 +154,7 @@ module Jenkins
|
|
149
154
|
# that links can be built automatically.
|
150
155
|
#
|
151
156
|
# @param [Class] internal_class the Ruby class
|
152
|
-
# @param [java.lang.Class] external_class the Java class on the
|
157
|
+
# @param [java.lang.Class] external_class the Java class on the other side of this link.
|
153
158
|
def self.register(internal_class, external_class)
|
154
159
|
@@intcls2extcls[internal_class] = external_class
|
155
160
|
@@extcls2intcls[external_class] = internal_class
|
data/lib/jenkins/plugin/proxy.rb
CHANGED
@@ -22,8 +22,9 @@ module Jenkins
|
|
22
22
|
#
|
23
23
|
# @param [Jenkins::Plugin] plugin the plugin from whence this proxy object came
|
24
24
|
# @param [Object] object the implementation to which this proxy will delegate.
|
25
|
-
|
26
|
-
|
25
|
+
# @param super_args pass through arguments to the super type
|
26
|
+
def initialize(plugin, object, *super_args)
|
27
|
+
super(*super_args) if defined? super
|
27
28
|
@plugin, @object = plugin, object
|
28
29
|
@pluginid = @plugin.name
|
29
30
|
end
|
@@ -2,6 +2,7 @@ require 'jenkins/plugin'
|
|
2
2
|
require 'jenkins/plugin/specification'
|
3
3
|
require 'jenkins/plugin/runtime/version'
|
4
4
|
require 'jenkins/plugin/proxy'
|
5
|
+
require 'jenkins/plugin/proxies/describable'
|
5
6
|
require 'jenkins/plugin/proxies'
|
6
7
|
require 'jenkins/model'
|
7
8
|
require 'jenkins/model/action'
|
data/lib/jenkins/plugin.rb
CHANGED
@@ -99,11 +99,14 @@ module Jenkins
|
|
99
99
|
# process, and should not need to be invoked by plugin code.
|
100
100
|
#
|
101
101
|
# @param [Class] ruby_class the class implementing the extension point
|
102
|
-
# @param [java.lang.Class]
|
103
|
-
|
104
|
-
|
102
|
+
# @param [java.lang.Class] describable_class that Jenkins will see this extention point as
|
103
|
+
# @param [Class] descriptor_class that we use to instantiate Descriptor.
|
104
|
+
# nil to use the plain-vanilla Descriptor class for those extension points that don't define its own Descriptor type
|
105
|
+
def register_describable(ruby_class, describable_class, descriptor_class = nil)
|
106
|
+
descriptor_class ||= Jenkins::Model::Descriptor
|
107
|
+
descriptor = descriptor_class.new(ruby_class, self, describable_class)
|
105
108
|
@descriptors[ruby_class] = descriptor
|
106
|
-
|
109
|
+
register_extension(descriptor)
|
107
110
|
end
|
108
111
|
|
109
112
|
# unique identifier for this plugin in the Jenkins server
|
@@ -189,4 +192,13 @@ module Jenkins
|
|
189
192
|
end
|
190
193
|
end
|
191
194
|
end
|
195
|
+
|
196
|
+
# Make the singleton instance available from the top-level
|
197
|
+
# namespace
|
198
|
+
#
|
199
|
+
# Jenkins.plugin
|
200
|
+
# @see [Jenkins::Plugin.instance]
|
201
|
+
def self.plugin
|
202
|
+
self::Plugin.instance
|
203
|
+
end
|
192
204
|
end
|
data/lib/jenkins/rack.rb
CHANGED
@@ -47,6 +47,7 @@ describe Jenkins::Model::Build do
|
|
47
47
|
|
48
48
|
describe "environment variables" do
|
49
49
|
before do
|
50
|
+
pending "we need to get some full stack testing for this to fully work"
|
50
51
|
@build.env['FOO'] = 'bar'
|
51
52
|
@build.env[:bar] = :baz
|
52
53
|
Java.org.mockito.Mockito.when(@native.getEvironment(nil)).thenCallRealMethod()
|
@@ -34,7 +34,7 @@ describe Jenkins::Model::Describable do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it "is registered as an extension of the java type" do
|
37
|
-
@plugin.should have_received(:register_describable).with(@subclass, java.lang.Object.java_class)
|
37
|
+
@plugin.should have_received(:register_describable).with(@subclass, java.lang.Object.java_class, nil)
|
38
38
|
end
|
39
39
|
|
40
40
|
describe ". a sub-subclass" do
|
@@ -43,9 +43,20 @@ describe Jenkins::Model::Describable do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it "is also registered as an extension of the original java type" do
|
46
|
-
@plugin.should have_received(:register_describable).with(@subsubclass, java.lang.Object.java_class)
|
46
|
+
@plugin.should have_received(:register_describable).with(@subsubclass, java.lang.Object.java_class, nil)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
describe "with a custom descriptor type" do
|
52
|
+
it "registers that custom descriptor" do
|
53
|
+
@class.describe_as java.lang.Object, :with => java.lang.String
|
54
|
+
@subclass = Class.new(@class)
|
55
|
+
@plugin.should have_received(:register_describable).with(@subclass, java.lang.Object.java_class, java.lang.String.java_class)
|
56
|
+
end
|
57
|
+
it "must be a real java class" do
|
58
|
+
lambda {@class.describe_as java.lang.Object, :with => Object}.should raise_error(Jenkins::Model::Describable::DescribableError)
|
59
|
+
end
|
60
|
+
end
|
50
61
|
end
|
51
62
|
end
|
@@ -149,6 +149,20 @@ describe Jenkins::Plugin::Proxies do
|
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
|
+
describe "exporting an alreay external java object" do
|
153
|
+
before do
|
154
|
+
@java_object = java.lang.Object.new
|
155
|
+
@export = @proxies.export(@java_object)
|
156
|
+
end
|
157
|
+
|
158
|
+
it "just passes the java object through" do
|
159
|
+
@export.should be @java_object
|
160
|
+
end
|
161
|
+
it "is idempotent" do
|
162
|
+
@proxies.export(@export).should be @export
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
152
166
|
private
|
153
167
|
|
154
168
|
def proxy_class
|
data/spec/jenkins/plugin_spec.rb
CHANGED
@@ -2,9 +2,6 @@ require 'spec_helper'
|
|
2
2
|
require 'tmpdir'
|
3
3
|
|
4
4
|
describe Jenkins::Plugin do
|
5
|
-
it "is unbelievable that I don't have a spec for this class" do
|
6
|
-
Jenkins::Plugin.instance_method(:initialize).should_not be_nil
|
7
|
-
end
|
8
5
|
|
9
6
|
describe "when plugin loads models" do
|
10
7
|
include SpecHelper
|
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.
|
5
|
+
version: 0.1.18
|
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:
|
13
|
+
date: 2012-01-10 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- lib/jenkins/plugin/proxies/build_step.rb
|
98
98
|
- lib/jenkins/plugin/proxies/build_wrapper.rb
|
99
99
|
- lib/jenkins/plugin/proxies/builder.rb
|
100
|
+
- lib/jenkins/plugin/proxies/describable.rb
|
100
101
|
- lib/jenkins/plugin/proxies/publisher.rb
|
101
102
|
- lib/jenkins/plugin/proxies/root_action.rb
|
102
103
|
- lib/jenkins/plugin/proxy.rb
|
@@ -159,5 +160,25 @@ rubygems_version: 1.8.9
|
|
159
160
|
signing_key:
|
160
161
|
specification_version: 3
|
161
162
|
summary: Runtime support libraries for Jenkins Ruby plugins
|
162
|
-
test_files:
|
163
|
-
|
163
|
+
test_files:
|
164
|
+
- spec/jenkins/filepath_spec.rb
|
165
|
+
- spec/jenkins/launcher_spec.rb
|
166
|
+
- spec/jenkins/model/action_spec.rb
|
167
|
+
- spec/jenkins/model/build_spec.rb
|
168
|
+
- spec/jenkins/model/describable_spec.rb
|
169
|
+
- spec/jenkins/model/listener_spec.rb
|
170
|
+
- spec/jenkins/model_spec.rb
|
171
|
+
- spec/jenkins/plugin/example.pluginspec
|
172
|
+
- spec/jenkins/plugin/proxies/build_wrapper_spec.rb
|
173
|
+
- spec/jenkins/plugin/proxies/builder_spec.rb
|
174
|
+
- spec/jenkins/plugin/proxies/proxy_helper.rb
|
175
|
+
- spec/jenkins/plugin/proxies/publisher_spec.rb
|
176
|
+
- spec/jenkins/plugin/proxies/root_action_spec.rb
|
177
|
+
- spec/jenkins/plugin/proxies_spec.rb
|
178
|
+
- spec/jenkins/plugin/proxy_spec.rb
|
179
|
+
- spec/jenkins/plugin/specification_spec.rb
|
180
|
+
- spec/jenkins/plugin_spec.rb
|
181
|
+
- spec/jenkins/tasks/build_wrapper_spec.rb
|
182
|
+
- spec/jenkins/tasks/builder_spec.rb
|
183
|
+
- spec/mockito-all-1.8.5.jar
|
184
|
+
- spec/spec_helper.rb
|