Class: Jenkins::Plugin
- Inherits:
-
Object
- Object
- Jenkins::Plugin
- Defined in:
- lib/jenkins/plugin.rb,
lib/jenkins/plugin/proxy.rb,
lib/jenkins/plugin/proxies.rb,
lib/jenkins/plugin/specification.rb,
lib/jenkins/plugin/proxies/action.rb,
lib/jenkins/plugin/proxies/builder.rb,
lib/jenkins/plugin/runtime/version.rb,
lib/jenkins/plugin/proxies/publisher.rb,
lib/jenkins/plugin/proxies/build_step.rb,
lib/jenkins/plugin/proxies/root_action.rb,
lib/jenkins/plugin/proxies/build_wrapper.rb
Overview
Acts as the primary gateway between Ruby and Jenkins There is one instance of this object for the entire plugin
On the Java side, it contains a reference to an instance of RubyPlugin. These two objects talk to each other to get things done.
Each running ruby plugin has exactly one instance of ‘Jenkins::Plugin`
Defined Under Namespace
Modules: Proxy, Runtime Classes: OpaqueJavaObject, Proxies, Specification
Constant Summary collapse
- ExportError =
Class.new(StandardError)
- ImportError =
Class.new(StandardError)
- SpecificationError =
Class.new(StandardError)
- SpecificationNotFound =
Class.new(SpecificationError)
Instance Attribute Summary collapse
-
#descriptors ⇒ Object
readonly
A list of all the hudson.model.Descriptor objects of which this plugin is aware *indexed by Wrapper class*.
-
#peer ⇒ Object
readonly
the instance of jenkins.ruby.RubyPlugin with which this Plugin is associated.
Class Method Summary collapse
-
.initialize(java) ⇒ Jenkins::Plugin
Initialize the singleton instance that will run for a ruby plugin.
-
.instance ⇒ Jenkins::Plugin
Get the singleton instance associated with this plugin.
Instance Method Summary collapse
-
#export(object) ⇒ Object
Reflect a native Ruby object into its External Java form.
-
#import(object) ⇒ Object
Reflect an Java object coming from Jenkins into the context of this plugin If the object is originally from the ruby plugin, and it was previously exported, then it will unwrap it.
-
#initialize(java) ⇒ Plugin
constructor
Initializes this plugin by reading the models.rb file.
-
#linkout(internal, external) ⇒ Object
Link a plugin-local Ruby object to an external Java object.
- #load_models ⇒ Object
-
#name ⇒ Object
unique identifier for this plugin in the Jenkins server.
-
#register_describable(ruby_class, java_class) ⇒ Object
Register a ruby class as a Jenkins extension point of a particular java type.
-
#register_extension(class_or_instance, *args) ⇒ Object
Registers a singleton extension point directly with Jenkins.
-
#start ⇒ Object
Called once when Jenkins first initializes this plugin currently does nothing, but plugin startup hooks would go here.
-
#stop ⇒ Object
Called one by Jenkins (via RubyPlugin) when this plugin is shut down.
Constructor Details
#initialize(java) ⇒ Plugin
Initializes this plugin by reading the models.rb file. This is a manual registration process Where ruby objects register themselves with the plugin In the future, this process will be automatic, but I haven’t decided the best way to do this yet.
38 39 40 41 42 43 |
# File 'lib/jenkins/plugin.rb', line 38 def initialize(java) @java = @peer = java @start = @stop = proc {} @descriptors = {} @proxies = Proxies.new(self) end |
Instance Attribute Details
#descriptors ⇒ Object (readonly)
A list of all the hudson.model.Descriptor objects of which this plugin is aware *indexed by Wrapper class*
This is used so that wrappers can always have a single place to go when they are asked for a descriptor. That way, wrapper instances can always return the descriptor associated with their class.
This may go away.
26 27 28 |
# File 'lib/jenkins/plugin.rb', line 26 def descriptors @descriptors end |
#peer ⇒ Object (readonly)
the instance of jenkins.ruby.RubyPlugin with which this Plugin is associated
29 30 31 |
# File 'lib/jenkins/plugin.rb', line 29 def peer @peer end |
Class Method Details
.initialize(java) ⇒ Jenkins::Plugin
Initialize the singleton instance that will run for a ruby plugin. This method is designed to be called by the Java side when setting up the ruby plugin
49 50 51 52 53 54 |
# File 'lib/jenkins/plugin.rb', line 49 def self.initialize(java) #TODO: check for double initialization?!? @instance = new(java) @instance.load_models return @instance end |
.instance ⇒ Jenkins::Plugin
64 65 66 |
# File 'lib/jenkins/plugin.rb', line 64 def self.instance @instance end |
Instance Method Details
#export(object) ⇒ Object
Reflect a native Ruby object into its External Java form.
Delegates to ‘Proxies` for the heavy lifting.
145 146 147 |
# File 'lib/jenkins/plugin.rb', line 145 def export(object) @proxies.export object end |
#import(object) ⇒ Object
Reflect an Java object coming from Jenkins into the context of this plugin If the object is originally from the ruby plugin, and it was previously exported, then it will unwrap it. Otherwise, it will just use the object as a normal Java object.
135 136 137 |
# File 'lib/jenkins/plugin.rb', line 135 def import(object) @proxies.import object end |
#linkout(internal, external) ⇒ Object
Link a plugin-local Ruby object to an external Java object.
see ‘Proxies#link`
155 156 157 |
# File 'lib/jenkins/plugin.rb', line 155 def linkout(internal, external) @proxies.linkout internal, external end |
#load_models ⇒ Object
159 160 161 162 163 164 |
# File 'lib/jenkins/plugin.rb', line 159 def load_models path = @java.getModelsPath().getPath() # TODO: can we access to Jenkins console logger? puts "Trying to load models from #{path}" load_file_in_dir(path) end |
#name ⇒ Object
unique identifier for this plugin in the Jenkins server
110 111 112 |
# File 'lib/jenkins/plugin.rb', line 110 def name @peer.getWrapper().getShortName() end |
#register_describable(ruby_class, java_class) ⇒ Object
Register a ruby class as a Jenkins extension point of a particular java type
This method is invoked automatically as part of the auto-registration process, and should not need to be invoked by plugin code.
103 104 105 106 107 |
# File 'lib/jenkins/plugin.rb', line 103 def register_describable(ruby_class, java_class) descriptor = Jenkins::Model::Descriptor.new(ruby_class, self, java_class) @descriptors[ruby_class] = descriptor @peer.addExtension(descriptor) end |
#register_extension(class_or_instance, *args) ⇒ Object
Registers a singleton extension point directly with Jenkins. Extensions registered via this method are different than those registered via ‘register_describable` in that there are only one instance of them, and so things like configuration construction, and validation do not apply.
This method accepts either an instance of the extension point or a class implementing the extension point. If a class is provided, it will attempt to construct an instance with the arguments provided. e.g.
# construct an instance
plugin.register_extension SomeRootAction, "gears.png"
# pass in a preconfigured instance
ext = MyGreatExtension.build do |c|
c.name "fantastic"
c.fizzle :foo
end
plugin.register_extension ext
90 91 92 93 |
# File 'lib/jenkins/plugin.rb', line 90 def register_extension(class_or_instance, *args) extension = class_or_instance.is_a?(Class) ? class_or_instance.new : class_or_instance @peer.addExtension(export(extension)) end |
#start ⇒ Object
Called once when Jenkins first initializes this plugin currently does nothing, but plugin startup hooks would go here.
117 118 119 |
# File 'lib/jenkins/plugin.rb', line 117 def start @start.call() end |
#stop ⇒ Object
Called one by Jenkins (via RubyPlugin) when this plugin is shut down. Currently this does nothing, but plugin shutdown hooks would go here.
124 125 126 |
# File 'lib/jenkins/plugin.rb', line 124 def stop @stop.call() end |