■ ■ Extend an extension point.
■ ■ Implement the methods to extend
the functionality encapsulated by an
extension point.
Hudson provides the concept of
extension points and extensions to facilitate using plug-ins to add functionality
to the core platform. Extension
points are interfaces that
encapsulate entry points to
extend the functionality of a
service provided by the
core platform.
Among the various services
provided by Hudson, the
foremost is building a job. A
job is a buildable project that
consists of several configu-rable areas and build steps.
The following are some of the
build steps:
■ ■ SCM checkout: Based on
the SCM type, the source
code is checked out.
■ ■ Prebuild: This step is invoked to indicate that the build
is starting.
■ ■ Build wrapper: This step prepares an
environment for the build.
■ ■ Builder runs: This step causes the
actual building to occur, much like
calling Ant or Make.
■ ■ Recording: This step records the
output from the build, such as
test results.
■ ■ Notification: This step sends out notifications that are based on the results
determined so far.
Builders are responsible for building
jobs. The extension point provided by
Hudson for contributing to the Builder
runs step is aptly called Builder.
Hudson comes bundled with two of the
most-popular builders: Ant and Maven.
They are in fact extensions to the Builder
extension point. So it is possible for a
plug-in to provide its own builder extension as one of the builders of the job.
Several external plug-ins
exist for other popular builders, such as Make, Gradle,
Rake, and so on. HelloBuilder,
our example builder extension, is a contrived example
to demonstrate how extensions are built. Far more-sophisticated builder extensions are possible using the
Builder extension point. Let's
examine the source code to
understand how the extension mechanism works.
Tip: Even though in this article the sample extension is
referred to as HelloBuilder, the
Java class corresponding to it is called
HelloWorldBuilder.java.
Examining the HelloBuilder extension.
In order for Hudson to understand a
class as an extension, you must do
the following:
■ ■ Extend a class that advertises itself as
an extension point
■ ■ Implement the required abstract
methods to extend the functionality
■ ■ Tell Hudson that the particular class is
an extension
Looking at the source code for
Hello WorldBuilder.java, you can see that
the class Hello WorldBuilder extends the
public boolean perform(AbstractBuild<?, ?> ab, Launcher launcher,
BuildListener bl) throws InterruptedException, IOException;
COMMUNITY
JAVA IN ACTION
Hudson provides
the concept of
extension points
and extensions
to facilitate using
plug-ins to add
functionality to the
core platform.
See all listings as text
class Builder, which is the extension
point for the Hudson Builder interface.
public class Hello WorldBuilder
extends Builder {
The Builder class itself is a subclass
of BuildStep, which defines the abstract
method that needs to be implemented
by the extension to contribute to the
Builder interface. The abstract method
that needs to be implemented by any
builder extension is shown in Listing 1.
ABOUT US
blog