1. 配置maven环境:

 安装Maven,在config文件夹中的settings配置如下:

  1. <settings> 
  2. <profiles> 
  3.   <profile> 
  4.     <id>hudson</id> 
  5.     <activation> 
  6.       <activeByDefault /> 
  7.     </activation> 
  8.  
  9.     <pluginRepositories> 
  10.       <pluginRepository> 
  11.         <id>m.g.o-public</id> 
  12.         <url>http://maven.glassfish.org/content/groups/public/</url> 
  13.       </pluginRepository> 
  14.     </pluginRepositories> 
  15.     <repositories> 
  16.       <repository> 
  17.         <id>m.g.o-public</id> 
  18.         <url>http://maven.glassfish.org/content/groups/public/</url> 
  19.       </repository> 
  20.     </repositories> 
  21.   </profile> 
  22. </profiles> 
  23.  
  24. <activeProfiles> 
  25.   <activeProfile>hudson</activeProfile> 
  26. </activeProfiles> 
  27.  
  28. <pluginGroups> 
  29.   <pluginGroup>org.jvnet.hudson.tools</pluginGroup> 
  30. </pluginGroups> 
  31.  
  32. </settings> 


这会将Maven指向拥有maven插件的仓库。

 

2.创建一个新的插件:

mvn -cpu hpi:create

会要求输入groupId和ProjectId

创建完成以后,会在/%uesername%/下找到这个新创建的插件

3.配置好Eclipse下的开发环境:

使用如下命令将为目前/%username%/下的所有插件项目配置eclipe工程文件:

mvn -DdownloadSources=true eclipse:eclipse

然后导入到eclipse项目中

4.文件目录

pom.xml

Maven uses it for building your plugin

src/main/java

Java source files of the plugin

src/main/resources

Jelly/Groovy views of the plugin. See this document for more about it.

src/main/webapp

Static resources of the plugin, such as p_w_picpaths and HTML files.

 

5.代码结构:

入口是继承自Plugin的类PluginImpl,Hudson会自动检测所有插件中的PluginImpl类然后创建一个实例并调用其中的方法。

6.扩展点

Hudson给出了一系列的扩展点,用于插件开发者按照需求来查找这个目录,找出需要调用的方法和类。

7.调试插件

使用eclipse调试插件,首先,在jetty中启动带有你编写的插件的hudson,同时启用调试窗口8000

> set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n                    
> mvn hpi:run 注意:在启用调试之前,保证你的8080端口没有被占用。
之后,打开http://localhost:8080你就能看到在jetty中运行的hudson,同时在manage plugin里你可以发现你自己
的插件已经安装过了。然后你需要在eclipse中设置通过8000端口来进行远程调试。