jenkins-plugin-runtime 0.1.6 → 0.1.7
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 +133 -0
- data/lib/jenkins/launcher.rb +103 -6
- data/lib/jenkins/model/action.rb +11 -17
- data/lib/jenkins/model/build.rb +7 -6
- data/lib/jenkins/model/describable.rb +1 -1
- data/lib/jenkins/model/descriptor.rb +25 -1
- data/lib/jenkins/model/listener.rb +48 -23
- data/lib/jenkins/model/root_action.rb +4 -4
- data/lib/jenkins/plugin.rb +27 -8
- data/lib/jenkins/plugin/proxies.rb +5 -2
- data/lib/jenkins/plugin/proxies/action.rb +31 -0
- data/lib/jenkins/plugin/proxies/build_step.rb +32 -0
- data/lib/jenkins/plugin/proxies/builder.rb +2 -9
- data/lib/jenkins/plugin/proxies/publisher.rb +25 -0
- data/lib/jenkins/plugin/proxies/root_action.rb +35 -0
- data/lib/jenkins/plugin/runtime/version.rb +1 -1
- data/lib/jenkins/tasks/build_step.rb +23 -0
- data/lib/jenkins/tasks/builder.rb +6 -25
- data/lib/jenkins/tasks/publisher.rb +18 -0
- data/spec/jenkins/filepath_spec.rb +123 -0
- data/spec/jenkins/launcher_spec.rb +210 -0
- data/spec/jenkins/model/action_spec.rb +2 -3
- data/spec/jenkins/model/build_spec.rb +22 -3
- data/spec/jenkins/model/listener_spec.rb +9 -7
- data/spec/jenkins/plugin/proxies/builder_spec.rb +11 -0
- data/spec/jenkins/plugin/proxies/publisher_spec.rb +35 -0
- data/spec/jenkins/plugin/proxies/root_action_spec.rb +31 -0
- data/spec/jenkins/plugin/proxies_spec.rb +17 -1
- data/spec/jenkins/plugin_spec.rb +65 -0
- data/spec/spec_helper.rb +34 -0
- metadata +15 -2
data/lib/jenkins/plugin.rb
CHANGED
@@ -157,17 +157,36 @@ module Jenkins
|
|
157
157
|
end
|
158
158
|
|
159
159
|
def load_models
|
160
|
-
|
160
|
+
path = @java.getModelsPath().getPath()
|
161
161
|
# TODO: can we access to Jenkins console logger?
|
162
|
-
puts "Trying to load models from #{
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
162
|
+
puts "Trying to load models from #{path}"
|
163
|
+
load_file_in_dir(path)
|
164
|
+
end
|
165
|
+
|
166
|
+
private
|
167
|
+
|
168
|
+
# Loads files in the specified directory.
|
169
|
+
# It seaches directories in depth first with loading files for each directory.
|
170
|
+
def load_file_in_dir(dirpath)
|
171
|
+
dirs = []
|
172
|
+
Dir.new(dirpath).each do |entry|
|
173
|
+
next if entry == '.' || entry == '..'
|
174
|
+
path = File.join(dirpath, entry)
|
175
|
+
if File.directory?(path)
|
176
|
+
dirs << path
|
177
|
+
elsif /\.rb\z/ =~ path
|
178
|
+
puts "Loading " + path
|
179
|
+
begin
|
180
|
+
load path
|
181
|
+
rescue Exception => e
|
182
|
+
puts "#{e.message} (#{e.class})\n" << (e.backtrace || []).join("\n")
|
183
|
+
end
|
184
|
+
nil
|
169
185
|
end
|
170
186
|
end
|
187
|
+
dirs.each do |dir|
|
188
|
+
load_file_in_dir(dir)
|
189
|
+
end
|
171
190
|
end
|
172
191
|
end
|
173
192
|
end
|
@@ -5,6 +5,7 @@ module Jenkins
|
|
5
5
|
|
6
6
|
ExportError = Class.new(StandardError)
|
7
7
|
ImportError = Class.new(StandardError)
|
8
|
+
NativeJavaObject = Struct.new(:native)
|
8
9
|
|
9
10
|
# Maps JRuby objects part of the idomatic Ruby API
|
10
11
|
# to a plain Java object representation and vice-versa.
|
@@ -60,7 +61,9 @@ module Jenkins
|
|
60
61
|
end
|
61
62
|
cls = cls.superclass
|
62
63
|
end
|
63
|
-
|
64
|
+
internal = NativeJavaObject.new(object)
|
65
|
+
link(internal, object)
|
66
|
+
return internal
|
64
67
|
end
|
65
68
|
|
66
69
|
# Reflect a native Ruby object into its External Java form.
|
@@ -126,6 +129,6 @@ module Jenkins
|
|
126
129
|
end
|
127
130
|
|
128
131
|
require 'jenkins/model/describable'
|
129
|
-
["build_wrapper", "builder"].each do |proxy|
|
132
|
+
["action", "build_wrapper", "builder", "publisher", "root_action"].each do |proxy|
|
130
133
|
require "jenkins/plugin/proxies/#{proxy}"
|
131
134
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'jenkins/model/action'
|
2
|
+
|
3
|
+
module Jenkins
|
4
|
+
class Plugin
|
5
|
+
class Proxies
|
6
|
+
class Action
|
7
|
+
include Java.hudson.model.Action
|
8
|
+
include Java.jenkins.ruby.Get
|
9
|
+
include Jenkins::Plugin::Proxy
|
10
|
+
|
11
|
+
def getIconFileName
|
12
|
+
@object.icon
|
13
|
+
end
|
14
|
+
|
15
|
+
def getUrlName
|
16
|
+
@object.url_path
|
17
|
+
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
|
+
end
|
27
|
+
|
28
|
+
register Jenkins::Model::Action, Action
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Jenkins
|
2
|
+
class Plugin
|
3
|
+
class Proxies
|
4
|
+
module BuildStep
|
5
|
+
def prebuild(build, listener)
|
6
|
+
boolean_result(listener) do
|
7
|
+
@object.prebuild(import(build), import(listener))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def perform(build, launcher, listener)
|
12
|
+
boolean_result(listener) do
|
13
|
+
@object.perform(import(build), import(launcher), import(listener))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def boolean_result(listener, &block)
|
20
|
+
begin
|
21
|
+
yield
|
22
|
+
true
|
23
|
+
rescue Exception => e
|
24
|
+
msg = "#{e.message} (#{e.class})\n" << (e.backtrace || []).join("\n")
|
25
|
+
listener.error(msg + "\n")
|
26
|
+
false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
1
|
require 'jenkins/tasks/builder'
|
2
|
+
require 'jenkins/plugin/proxies/build_step'
|
3
3
|
|
4
4
|
module Jenkins
|
5
5
|
class Plugin
|
@@ -8,13 +8,7 @@ module Jenkins
|
|
8
8
|
include Java.jenkins.ruby.Get
|
9
9
|
include Jenkins::Plugin::Proxy
|
10
10
|
|
11
|
-
|
12
|
-
@object.prebuild(import(build), import(listener)) ? true : false
|
13
|
-
end
|
14
|
-
|
15
|
-
def perform(build, launcher, listener)
|
16
|
-
@object.perform(import(build), import(launcher), import(listener)) ? true : false
|
17
|
-
end
|
11
|
+
include BuildStep
|
18
12
|
|
19
13
|
def getDescriptor
|
20
14
|
@plugin.descriptors[@object.class]
|
@@ -23,7 +17,6 @@ module Jenkins
|
|
23
17
|
def get(name)
|
24
18
|
@object.respond_to?(name) ? @object.send(name) : nil
|
25
19
|
end
|
26
|
-
|
27
20
|
end
|
28
21
|
|
29
22
|
register Jenkins::Tasks::Builder, Builder
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'jenkins/tasks/publisher'
|
2
|
+
require 'jenkins/plugin/proxies/build_step'
|
3
|
+
|
4
|
+
module Jenkins
|
5
|
+
class Plugin
|
6
|
+
class Proxies
|
7
|
+
class Publisher < Java.hudson.tasks.Publisher
|
8
|
+
include Java.jenkins.ruby.Get
|
9
|
+
include Jenkins::Plugin::Proxy
|
10
|
+
|
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
|
+
end
|
21
|
+
|
22
|
+
register Jenkins::Tasks::Publisher, Publisher
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'jenkins/model/root_action'
|
2
|
+
|
3
|
+
module Jenkins
|
4
|
+
class Plugin
|
5
|
+
class Proxies
|
6
|
+
class RootAction
|
7
|
+
include Java.hudson.model.RootAction
|
8
|
+
include Java.jenkins.ruby.Get
|
9
|
+
include Jenkins::Plugin::Proxy
|
10
|
+
|
11
|
+
def getDisplayName
|
12
|
+
@object.display_name
|
13
|
+
end
|
14
|
+
|
15
|
+
def getIconFileName
|
16
|
+
@object.icon
|
17
|
+
end
|
18
|
+
|
19
|
+
def getUrlName
|
20
|
+
@object.url_path
|
21
|
+
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
|
+
end
|
31
|
+
|
32
|
+
register Jenkins::Model::RootAction, RootAction
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Jenkins
|
2
|
+
module Tasks
|
3
|
+
module BuildStep
|
4
|
+
##
|
5
|
+
# Runs before the build begins
|
6
|
+
#
|
7
|
+
# @param [Jenkins::Model::Build] build the build which will begin
|
8
|
+
# @param [Jenkins::Launcher] launcher the launcher that can run code on the node running this build
|
9
|
+
# @param [Jenkins::Model::Listener] listener the listener for this build.
|
10
|
+
def prebuild(build, launcher, listener)
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# Runs the step over the given build and reports the progress to the listener.
|
15
|
+
#
|
16
|
+
# @param [Jenkins::Model::Build] build on which to run this step
|
17
|
+
# @param [Jenkins::Launcher] launcher the launcher that can run code on the node running this build
|
18
|
+
# @param [Jenkins::Model::Listener] listener the listener for this build.
|
19
|
+
def perform(build, launcher, listener)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,37 +1,18 @@
|
|
1
|
+
require 'jenkins/tasks/build_step'
|
1
2
|
|
2
3
|
module Jenkins
|
3
4
|
module Tasks
|
4
5
|
##
|
5
|
-
# A single step in the entire build process
|
6
|
+
# A single build step in the entire build process
|
7
|
+
#
|
8
|
+
# See BuildStep to see interface definitions.
|
6
9
|
class Builder
|
7
10
|
include Jenkins::Model
|
8
11
|
include Jenkins::Model::Describable
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
##
|
13
|
-
# Runs before the build begins
|
14
|
-
#
|
15
|
-
# @param [Jenkins::Model::Build] build the build which will begin
|
16
|
-
# @param [Jenkins::Launcher] launcher the launcher that can run code on the node running this build
|
17
|
-
# @param [Jenkins::Model::Listener] listener the listener for this build.
|
18
|
-
# @return `true` if this build can continue or `false` if there was an error
|
19
|
-
# and the build needs to be aborted
|
20
|
-
def prebuild(build, launcher, listener)
|
21
|
-
|
22
|
-
end
|
13
|
+
include BuildStep
|
23
14
|
|
24
|
-
|
25
|
-
# Runs the step over the given build and reports the progress to the listener.
|
26
|
-
#
|
27
|
-
# @param [Jenkins::Model::Build] build on which to run this step
|
28
|
-
# @param [Jenkins::Launcher] launcher the launcher that can run code on the node running this build
|
29
|
-
# @param [Jenkins::Model::Listener] listener the listener for this build.
|
30
|
-
# return `true if this build can continue or `false` if there was an error
|
31
|
-
# and the build needs to be aborted
|
32
|
-
def perform(build, launcher, listener)
|
33
|
-
|
34
|
-
end
|
15
|
+
describe_as Java.hudson.tasks.Builder
|
35
16
|
end
|
36
17
|
end
|
37
18
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'jenkins/tasks/build_step'
|
2
|
+
|
3
|
+
module Jenkins
|
4
|
+
module Tasks
|
5
|
+
##
|
6
|
+
# A single build step that run after the build is complete
|
7
|
+
#
|
8
|
+
# See BuildStep to see interface definitions.
|
9
|
+
class Publisher
|
10
|
+
include Jenkins::Model
|
11
|
+
include Jenkins::Model::Describable
|
12
|
+
|
13
|
+
include BuildStep
|
14
|
+
|
15
|
+
describe_as Java.hudson.tasks.Publisher
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Jenkins::FilePath do
|
4
|
+
include SpecHelper
|
5
|
+
|
6
|
+
def create(str)
|
7
|
+
native = Java.hudson.FilePath.new(Java.java.io.File.new(str))
|
8
|
+
Jenkins::FilePath.new(native)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "can be instantiated" do
|
12
|
+
Jenkins::FilePath.new(mock(Java.hudson.FilePath))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns child for +" do
|
16
|
+
(create(".") + "foo").to_s.should == "foo"
|
17
|
+
(create(".") + "foo" + "bar").to_s.should == "foo/bar"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns path for to_s" do
|
21
|
+
create(".").to_s.should == "."
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns realpath" do
|
25
|
+
create(".").realpath.should match /\A\//
|
26
|
+
end
|
27
|
+
|
28
|
+
it "reads file" do
|
29
|
+
create(__FILE__).read.should match /MATCH EXACTLY THIS REGEX STRING IN FILE/
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns Time as mtime" do
|
33
|
+
create(__FILE__).mtime.should be_an_instance_of Time
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns stat" do
|
37
|
+
stat = create(__FILE__).stat
|
38
|
+
rstat = File.stat(__FILE__)
|
39
|
+
stat.size.should == rstat.size
|
40
|
+
stat.mode.should == rstat.mode
|
41
|
+
stat.mtime.should == rstat.mtime
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns basename" do
|
45
|
+
create(__FILE__).basename.should be_an_instance_of Jenkins::FilePath
|
46
|
+
create(__FILE__).basename.to_s.should == __FILE__.split("/").last
|
47
|
+
end
|
48
|
+
|
49
|
+
it "checks existence" do
|
50
|
+
create(".").exist?.should == true
|
51
|
+
create("__NOSUCHFILE__").exist?.should == false
|
52
|
+
end
|
53
|
+
|
54
|
+
it "checks directory or not" do
|
55
|
+
create(".").directory?.should == true
|
56
|
+
create(__FILE__).directory?.should == false
|
57
|
+
end
|
58
|
+
|
59
|
+
it "checks file or not" do
|
60
|
+
create(".").file?.should == false
|
61
|
+
create(__FILE__).file?.should == true
|
62
|
+
end
|
63
|
+
|
64
|
+
it "returns size" do
|
65
|
+
create(__FILE__).size.should == File.size(__FILE__)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "returns entries in directory" do
|
69
|
+
create(".").entries.each do |e|
|
70
|
+
e.should be_an_instance_of Jenkins::FilePath
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it "iterates entries in directory" do
|
75
|
+
create(".").each_entry do |e|
|
76
|
+
e.should be_an_instance_of Jenkins::FilePath
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns parent directory" do
|
81
|
+
create("/").parent.to_s.should == "/"
|
82
|
+
create(".").parent.to_s.should == ".."
|
83
|
+
create(".").parent.parent.to_s.should == "../.."
|
84
|
+
create(__FILE__).parent.to_s.should == File.dirname(__FILE__)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "can touch the file" do
|
88
|
+
mktmpdir do |dir|
|
89
|
+
t = Time.now
|
90
|
+
(create(dir) + "foo").touch(t)
|
91
|
+
(create(dir) + "foo").mtime.to_i.should == t.to_i
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it "can check remote or not" do
|
96
|
+
create(".").remote?.should == false
|
97
|
+
end
|
98
|
+
|
99
|
+
it "can create directory" do
|
100
|
+
mktmpdir do |dir|
|
101
|
+
(create(dir) + "foo").mkdir
|
102
|
+
create(File.join(dir, "foo")).exist?.should == true
|
103
|
+
create(File.join(dir, "foo")).directory?.should == true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it "can delete file" do
|
108
|
+
mktmpdir do |dir|
|
109
|
+
(create(dir) + "foo").touch(Time.now)
|
110
|
+
(create(dir) + "foo").delete
|
111
|
+
create(File.join(dir, "foo")).exist?.should == false
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it "can delete directory" do
|
116
|
+
mktmpdir do |dir|
|
117
|
+
(create(dir) + "foo").mkdir
|
118
|
+
(create(dir) + "foo").rmtree
|
119
|
+
create(File.join(dir, "foo")).exist?.should == false
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|