Jenkins插件开发(5)—— 向Jenkins注册自定义扩展点
2013-04-18 21:58
971 查看
WIKI文档参照:https://wiki.jenkins-ci.org/display/JENKINS/Defining+a+new+extension+point
片段如下:
“@Extension”的说明参考:http://javadoc.jenkins-ci.org/?hudson/Extension.html
片段如下:
验证扩展点是否注册成功:
以ItemListerner为例进行了测试:
创建一个helloworld插件框架,在HelloWorldBuilder.java中添加如下内部类:
在perform方法中检测扩展点是否已经被注册了:
Debug之后,extList的值为:
PS:后面的几章节将会记录我将要开发的一个Jenkins插件的整个开发过程。
片段如下:
Implementing extension points Implementing an extension point defined in a plugin is no different from implementing an extension point defined in the core. See hudson.Extension for more details. @Extension public class Lion extends Animal { ... }
“@Extension”的说明参考:http://javadoc.jenkins-ci.org/?hudson/Extension.html
片段如下:
hudson Annotation Type Extension @Retention(value=RUNTIME) @Target(value={TYPE,FIELD,METHOD}) @Documented public @interface Extension Marks a field, a method, or a class for automatic discovery, so that Hudson can locate implementations of ExtensionPoints automatically. (In contrast, in earlier Hudson, the registration was manual.) In a simplest case, put this on your class, and Hudson will create an instance of it and register it to the appropriate ExtensionList. (在Class上添加@Extension注解,是最简单的向Jenkins注册扩展点实现的方式。) If you'd like Hudson to call a factory method instead of a constructor, put this annotation on your static factory method. Hudson will invoke it and if the method returns a non-null instance, it'll be registered. The return type of the method is used to determine which ExtensionList will get the instance. Finally, you can put this annotation on a static field if the field contains a reference to an instance that you'd like to register. This is the default way of having your implementations auto-registered to Hudson, but Hudson also supports arbitrary DI containers for hosting your implementations. See ExtensionFinder for more details.
验证扩展点是否注册成功:
示例1: ExtensionList<ItemListener> extList = Jenkins.getInstance() .getExtensionList(ItemListener.class);
示例2: ExtensionList<ItemListener> extList = Jenkins.getInstance() .getExtensionList(SaveableListener.class);
以ItemListerner为例进行了测试:
创建一个helloworld插件框架,在HelloWorldBuilder.java中添加如下内部类:
@Extension public static final class MyProjectRenameListener extends ItemListener { @Override public void onRenamed(Item item, String oldName, String newName) { super.onRenamed(item, oldName, newName); } }
在perform方法中检测扩展点是否已经被注册了:
@Override public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) { // This is where you 'build' the project. // Since this is a dummy, we just say 'hello world' and call that a // build. ExtensionList<ItemListener> extList = Jenkins.getInstance().getExtensionList(ItemListener.class); // This also shows how you can consult the global configuration of the // builder if (getDescriptor().getUseFrench()) listener.getLogger().println("Bonjour, " + name + "!"); else listener.getLogger().println("Hello, " + name + "!"); return true; }
Debug之后,extList的值为:
[com.yihaodian.plugin.jenkins.jobsync.HelloWorldBuilder$MyProjectRenameListener@84c1c3, hudson.diagnosis.OldDataMonitor$2@1cd000a, hudson.model.DisplayNameListener@1bdb13f, hudson.model.Fingerprint$ProjectRenameListener@bfb588, hudson.tasks.BuildTrigger$DescriptorImpl$ItemListenerImpl@270dbf, org.jenkinsci.main.modules.sshd.ItemListenerImpl@1f79b9a]
PS:后面的几章节将会记录我将要开发的一个Jenkins插件的整个开发过程。
相关文章推荐
- 监控开发之用python扩展dstat插件自定义实时监控 推荐
- Jenkins插件开发(4)——插件开发扩展点(Extension Point)
- Jenkins插件开发(6.2)—— 如何自定义CLI命令
- 易语言版{大智慧/分析家/飞狐交易师}DLL插件接口开发模块(beta),自定义股票软件公式扩展函数
- 易语言版{大智慧/分析家/飞狐交易师}DLL插件接口开发模块(beta5),自定义股票软件公式扩展函数
- Jenkins插件开发(1)——Jenkins扩展指南(Extend Jenkins)
- Jenkins插件开发进阶篇之扩展插件功能
- Qt键盘驱动处理类的实现:Qt键盘驱动处理类的实现,通过Qt的插件机制实现嵌入式开发中的自定义键盘处理。
- jquery开发自定义的插件总结
- Android+Cordova混合开发以及Cordova自定义插件
- iOS8扩展插件开发配置 [转载]
- 功能强大的wordpress自定义登录注册插件:DX Login Register 正式发布
- jquery 自定义插件开发
- jQuery自定义插件开发基础1——jQuery实用函数的实现 .
- nginx lua 插件扩展开发 博客整理
- iOS8扩展插件开发配置
- FireFox插件和扩展开发(三)—— scriptable实例
- Jenkins插件开发(三)-- 插件编写
- FireFox插件和扩展开发(四)——常见问题的解决
- Eclipse 插件开发 -- 深入理解菜单(Menu)功能及其扩展点