Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Add item_listener generator to jpi
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed Apr 19, 2013
1 parent 0ade77c commit 5ba29a8
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ruby-tools/jpi/lib/jenkins/plugin/cli/generate.rb
Expand Up @@ -49,6 +49,12 @@ def run_listener(name)
template('templates/run_listener.tt', "models/#{name.downcase}_listener.rb")
end

desc "item_listener", "item_listener NAME", :desc => "receive notification of job change events"
def item_listener(name)
@name = name
template('templates/item_listener.tt', "models/#{name.downcase}_listener.rb")
end

desc "computer_listener", "computer_listener NAME", :desc => "receive notification of computers events"
def computer_listener(name)
@name = name
Expand Down
68 changes: 68 additions & 0 deletions ruby-tools/jpi/lib/jenkins/plugin/cli/templates/item_listener.tt
@@ -0,0 +1,68 @@
# Receives notifications about CRUD operations of Items.
#
# This class will receive callbacks
# when items are created, copied, updated, deleted, etc...
#
# To receive a callback, override the method with the same name as
# the event. E.g.
#
# class MyRunListener
# include Jenkins::Listeners::ItemListener
#
# def updated(item)
# puts "#{item.inspect} updated!"
# end
# end
#
class <%= name.capitalize %>Listener
include Jenkins::Listeners::ItemListener

# Called after a new job is created and added to@link jenkins.model.Jenkinsend,
# before the initial configuration page is provided.
#
# This is useful for changing the default initial configuration of newly created jobs.
# For example, you can enable/add builders, etc.
def created(item)
end

# Called after a new job is created by copying from an existing job.
#
# For backward compatibility, the default implementation of this method calls@link #onCreated(Item)end.
# If you choose to handle this method, think about whether you want to call super.onCopied or not.
#
# @param [Jenkins::Model::Item] The source item that the new one was copied from. Never null.
# @param [Jenkins::Model::Item] The newly created item. Never null.
def copied(src_item, item)
end

# Called after all the jobs are loaded from disk into@link jenkins.model.Jenkinsend
# object.
def loaded()
end

# Called right before a job is going to be deleted.
#
# At this point the data files of the job is already gone.
# @param [Jenkins::Model::Item] The item being deleted.
def deleted(item)
end

# Called after a job is renamed.
#
# @param [Jenkins::Model::Item] The item being renamed
# @param The old name of the job.
# @param The new name of the job. Same as@link Item#getName()end.
def renamed(item, oldName, newName)
end

# Called after a job has its configuration updated.
#
# @param [Jenkins::Model::Item] The item being updated
def updated(item)
end

# Called at the begenning of the orderly shutdown sequence to
# allow plugins to clean up stuff
def before_shutdown()
end
end

0 comments on commit 5ba29a8

Please sign in to comment.