org.jvnet.hudson.maven.plugins.hudson
Class AbstractHudsonMojo

java.lang.Object
  extended by org.apache.maven.plugin.AbstractMojo
      extended by org.jvnet.hudson.maven.plugins.hudson.AbstractHudsonMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
Direct Known Subclasses:
AbstractActionPerJobMojo, AddJobMojo, AdjustViolationsMojo, BuildAllMojo

public abstract class AbstractHudsonMojo
extends org.apache.maven.plugin.AbstractMojo

Base class for working with Hudson.

Author:
edelsonj

Nested Class Summary
protected static interface AbstractHudsonMojo.JobClosure
          Callback interface for the forEachJob method.
protected static class AbstractHudsonMojo.PluginType
          Enum that defines the update types we can add plugins configurations for.
 
Field Summary
protected  org.apache.commons.httpclient.HttpClient httpClient
          HttpClient instance for methods to use.
protected  java.net.URL hudsonURL
          Hudson URL.
protected  org.apache.maven.project.MavenProject project
          The Maven Project Object.
protected  org.apache.maven.settings.Settings settings
          Maven settings.
 
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
 
Constructor Summary
AbstractHudsonMojo()
           
 
Method Summary
protected  void configurePlugin(org.jdom.Document jobDoc, AbstractHudsonMojo.PluginType pluginType, org.jdom.Element element)
          Configure a Hudson plugin by adding or replacing its configuration in the configuration document.
protected  void createHudsonURL()
          Create the base URL for Hudson.
protected  java.net.URL createJobBuildURL(java.lang.String jobName)
          Create the URL for building a job from Hudson.
protected  java.net.URL createJobConfigURL(java.lang.String jobName)
          Create the URL for getting a job config in Hudson.
protected  java.net.URL createJobListURL()
          Create the URL for getting a job list from Hudson.
protected  void createOrChange(org.jdom.Element element, java.lang.String name, int value)
          If a child element exists, change it's value.
protected  void createOrChange(org.jdom.Element element, java.lang.String name, java.lang.String value)
          If a child element exists, change it's value.
protected  void doPost(java.net.URL url, int expectedStatus)
          Make an HTTP Post to the URL, erroring out if the returned status doesn't make an expectation.
protected  void doPost(java.net.URL url, org.apache.commons.httpclient.methods.RequestEntity requestEntity, int expectedStatus)
          Make an HTTP Post to the URL, erroring out if the returned status doesn't make an expectation.
protected  org.apache.maven.settings.Server findServer()
          Search the Maven Settings object for a Server object that matches the URL provided.
protected  void forEachJob(AbstractHudsonMojo.JobClosure closure)
          Perform some task for each job in the CI server.
protected  org.jdom.Document getDocumentFromHudson(java.net.URL url)
           
protected  java.util.List<java.lang.String> getJobList()
          Fetch the job list from Hudson.
protected  org.jdom.Document loadJobConfig(java.lang.String name)
           
protected  void rebuildJob(java.lang.String job)
          Request a rebuild of the job.
protected  void saveJobConfig(java.lang.String name, org.jdom.Document jobDoc)
          Save the job's configuration.
protected  void setupClient()
          Configure the HttpClient instance with any necessary authentication parameters.
 
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.maven.plugin.Mojo
execute
 

Field Detail

httpClient

protected final org.apache.commons.httpclient.HttpClient httpClient
HttpClient instance for methods to use.


hudsonURL

protected java.net.URL hudsonURL
Hudson URL.


project

protected org.apache.maven.project.MavenProject project
The Maven Project Object.


settings

protected org.apache.maven.settings.Settings settings
Maven settings.

Constructor Detail

AbstractHudsonMojo

public AbstractHudsonMojo()
Method Detail

configurePlugin

protected void configurePlugin(org.jdom.Document jobDoc,
                               AbstractHudsonMojo.PluginType pluginType,
                               org.jdom.Element element)
Configure a Hudson plugin by adding or replacing its configuration in the configuration document.

Parameters:
jobDoc - the job Document
pluginType - the type of Plugin (publisher, trigger, etc.)
element - the new plugin element

createHudsonURL

protected void createHudsonURL()
                        throws org.apache.maven.plugin.MojoExecutionException
Create the base URL for Hudson. Will first look at the ciManagement section of the pom and then override that with the hudson.url property (if available).

Throws:
org.apache.maven.plugin.MojoExecutionException - if there's no hudson url
java.net.MalformedURLException - if the hudson url is badly formed

createJobBuildURL

protected java.net.URL createJobBuildURL(java.lang.String jobName)
                                  throws org.apache.maven.plugin.MojoExecutionException
Create the URL for building a job from Hudson.

Parameters:
jobName - The name of the job
Returns:
the URL to post to to run a build on Hudson
Throws:
org.apache.maven.plugin.MojoExecutionException

createJobConfigURL

protected java.net.URL createJobConfigURL(java.lang.String jobName)
                                   throws org.apache.maven.plugin.MojoExecutionException
Create the URL for getting a job config in Hudson.

Parameters:
jobName - The name of the job
Returns:
the URL of the job config in Hudson
Throws:
org.apache.maven.plugin.MojoExecutionException - if something goes wrong

createJobListURL

protected java.net.URL createJobListURL()
                                 throws org.apache.maven.plugin.MojoExecutionException
Create the URL for getting a job list from Hudson.

Returns:
the URL to get a job list from on Hudson
Throws:
org.apache.maven.plugin.MojoExecutionException - if something goes wrong

createOrChange

protected void createOrChange(org.jdom.Element element,
                              java.lang.String name,
                              int value)
If a child element exists, change it's value. Otherwise, create a new element with the specified name and text.

Parameters:
element - the parent Element
name - the child element name
value - the child element's new text value

createOrChange

protected void createOrChange(org.jdom.Element element,
                              java.lang.String name,
                              java.lang.String value)
If a child element exists, change it's value. Otherwise, create a new element with the specified name and text.

Parameters:
element - the parent Element
name - the child element name
value - the child element's new text value

doPost

protected void doPost(java.net.URL url,
                      int expectedStatus)
               throws java.io.IOException,
                      org.apache.maven.plugin.MojoExecutionException
Make an HTTP Post to the URL, erroring out if the returned status doesn't make an expectation.

Parameters:
url - the URL to POST to.
expectedStatus - expected HTTP status code
Throws:
java.io.IOException - if something goes wrong
org.apache.maven.plugin.MojoExecutionException - if the status doesn't match

doPost

protected void doPost(java.net.URL url,
                      org.apache.commons.httpclient.methods.RequestEntity requestEntity,
                      int expectedStatus)
               throws java.io.IOException,
                      org.apache.maven.plugin.MojoExecutionException
Make an HTTP Post to the URL, erroring out if the returned status doesn't make an expectation.

Parameters:
url - the URL to POST to.
requestEntity - an entity to include with the POST.
expectedStatus - expected HTTP status code.
Throws:
java.io.IOException - if something goes wrong
org.apache.maven.plugin.MojoExecutionException - if the status doesn't match

findServer

protected org.apache.maven.settings.Server findServer()
Search the Maven Settings object for a Server object that matches the URL provided. If the port isn't provided or is the default, then the Server ID is expected to be just the hostname. If the port is provided and is not the default, the Server ID is hostname:port.

Returns:
the corresponding Server object or null

forEachJob

protected void forEachJob(AbstractHudsonMojo.JobClosure closure)
                   throws org.apache.maven.plugin.MojoExecutionException
Perform some task for each job in the CI server.

Parameters:
closure - the action to take per job
Throws:
org.apache.maven.plugin.MojoExecutionException - if something goes wrong

getDocumentFromHudson

protected org.jdom.Document getDocumentFromHudson(java.net.URL url)
                                           throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

getJobList

protected java.util.List<java.lang.String> getJobList()
                                               throws org.apache.maven.plugin.MojoExecutionException,
                                                      java.io.IOException
Fetch the job list from Hudson.

Throws:
org.apache.maven.plugin.MojoExecutionException
java.io.IOException

loadJobConfig

protected org.jdom.Document loadJobConfig(java.lang.String name)
                                   throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

rebuildJob

protected void rebuildJob(java.lang.String job)
                   throws org.apache.maven.plugin.MojoExecutionException
Request a rebuild of the job.

Parameters:
job - the job name
Throws:
org.apache.maven.plugin.MojoExecutionException

saveJobConfig

protected void saveJobConfig(java.lang.String name,
                             org.jdom.Document jobDoc)
                      throws org.apache.maven.plugin.MojoExecutionException
Save the job's configuration.

Parameters:
name - the job name
jobDoc - the job config document
Throws:
org.apache.maven.plugin.MojoExecutionException

setupClient

protected void setupClient()
Configure the HttpClient instance with any necessary authentication parameters.

Parameters:
client -
hudsonURL -


Copyright © 1981-2010 MTV Networks. All Rights Reserved.