1. 配置maven环境:
安装Maven,在config文件夹中的settings配置如下:
- <settings>
- <profiles>
- <profile>
- <id>hudson</id>
- <activation>
- <activeByDefault />
- </activation>
- <pluginRepositories>
- <pluginRepository>
- <id>m.g.o-public</id>
- <url>http://maven.glassfish.org/content/groups/public/</url>
- </pluginRepository>
- </pluginRepositories>
- <repositories>
- <repository>
- <id>m.g.o-public</id>
- <url>http://maven.glassfish.org/content/groups/public/</url>
- </repository>
- </repositories>
- </profile>
- </profiles>
- <activeProfiles>
- <activeProfile>hudson</activeProfile>
- </activeProfiles>
- <pluginGroups>
- <pluginGroup>org.jvnet.hudson.tools</pluginGroup>
- </pluginGroups>
- </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端口来进行远程调试。