hudson.maven
Class MavenReporter

java.lang.Object
  extended by hudson.maven.MavenReporter
All Implemented Interfaces:
ExtensionPoint, MavenProjectActionBuilder, Describable<MavenReporter>, Serializable
Direct Known Subclasses:
AbstractMavenJavadocArchiver, BuildInfoRecorder, MavenArtifactArchiver, MavenFingerprinter, MavenMailer, MavenSiteArchiver, ReportCollector, TestFailureDetector

public abstract class MavenReporter
extends Object
implements Describable<MavenReporter>, ExtensionPoint, Serializable, MavenProjectActionBuilder

Listens to the build execution of MavenBuild, and normally records some information and exposes thoses in MavenBuild later.

MavenReporter is first instanciated on the master. Then during the build, it is serialized and sent over into the maven process by serialization. Reporters will then receive event callbacks as mojo execution progresses. Those event callbacks are the ones that take MavenBuildProxy.

Once the maven build completes normally or abnormally, the reporters will be sent back to the master by serialization again, then have its end(MavenBuild, Launcher, BuildListener) method invoked. This is a good opportunity to perform the post-build action.

This is the MavenBuild equivalent of BuildStep. Instances of MavenReporters are persisted with MavenModule/MavenModuleSet, possibly with configuration specific to that job.

Callback Firing Sequence

The callback methods are invoked in the following order:

 SEQUENCE := preBuild MODULE* postBuild end
 MODULE   := enterModule MOJO+ leaveModule
 MOJO     := preExecute postExecute
 

When an error happens, the call sequence could be terminated at any point and no further callback methods may be invoked.

Action

MavenReporter can contribute Action to MavenBuild so that the report can be displayed in the web UI.

Such action can also implement AggregatableAction if it further wishes to contribute a separate action to MavenModuleSetBuild. This mechanism is usually used to provide aggregated report for all the module builds.

Author:
Kohsuke Kawaguchi
See Also:
MavenReporters, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
 
Constructor Summary
MavenReporter()
           
 
Method Summary
 boolean end(MavenBuild build, Launcher launcher, BuildListener listener)
          Called after the maven execution finished and the result is determined.
 boolean enterModule(MavenBuildProxy build, org.apache.maven.project.MavenProject pom, BuildListener listener)
          Called when the build enters a next MavenProject.
 Action getAggregatedProjectAction(MavenModuleSet project)
          Works like getProjectAction(MavenModule) but works at MavenModuleSet level.
 MavenReporterDescriptor getDescriptor()
          Gets the descriptor for this instance.
 Action getProjectAction(MavenModule module)
          Deprecated. as of 1.341 Use getProjectActions(MavenModule) instead.
 Collection<? extends Action> getProjectActions(MavenModule module)
          Equivalent of BuildStep.getProjectActions(AbstractProject) for MavenReporter.
 boolean leaveModule(MavenBuildProxy build, org.apache.maven.project.MavenProject pom, BuildListener listener)
          Called when the build leaves the current MavenProject.
 boolean postBuild(MavenBuildProxy build, org.apache.maven.project.MavenProject pom, BuildListener listener)
          Called after a build of one maven2 module is completed.
 boolean postExecute(MavenBuildProxy build, org.apache.maven.project.MavenProject pom, MojoInfo mojo, BuildListener listener, Throwable error)
          Called after execution of a single mojo.
 boolean preBuild(MavenBuildProxy build, org.apache.maven.project.MavenProject pom, BuildListener listener)
          Called before the actual maven2 execution begins.
 boolean preExecute(MavenBuildProxy build, org.apache.maven.project.MavenProject pom, MojoInfo mojo, BuildListener listener)
          Called before execution of a single mojo.
 boolean reportGenerated(MavenBuildProxy build, org.apache.maven.project.MavenProject pom, MavenReportInfo report, BuildListener listener)
          Called after a MavenReport is successfully generated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MavenReporter

public MavenReporter()
Method Detail

preBuild

public boolean preBuild(MavenBuildProxy build,
                        org.apache.maven.project.MavenProject pom,
                        BuildListener listener)
                 throws InterruptedException,
                        IOException
Called before the actual maven2 execution begins.

Parameters:
pom - Represents the POM to be executed.
Returns:
true if the build can continue, false if there was an error and the build needs to be aborted.
Throws:
InterruptedException - If the build is interrupted by the user (in an attempt to abort the build.) Normally the MavenReporter implementations may simply forward the exception it got from its lower-level functions.
IOException - If the implementation wants to abort the processing when an IOException happens, it can simply propagate the exception to the caller. This will cause the build to fail, with the default error message. Implementations are encouraged to catch IOException on its own to provide a better error message, if it can do so, so that users have better understanding on why it failed.

enterModule

public boolean enterModule(MavenBuildProxy build,
                           org.apache.maven.project.MavenProject pom,
                           BuildListener listener)
                    throws InterruptedException,
                           IOException
Called when the build enters a next MavenProject.

When the current build is a multi-module reactor build, every time the build moves on to the next module, this method will be invoked.

Note that as of Maven 2.0.4, Maven does not perform any smart optimization on the order of goal executions. Therefore, the same module might be entered more than once during the build.

Returns:
See preBuild(hudson.maven.MavenBuildProxy, org.apache.maven.project.MavenProject, hudson.model.BuildListener)
Throws:
InterruptedException - See preBuild(hudson.maven.MavenBuildProxy, org.apache.maven.project.MavenProject, hudson.model.BuildListener)
IOException - See preBuild(hudson.maven.MavenBuildProxy, org.apache.maven.project.MavenProject, hudson.model.BuildListener)

leaveModule

public boolean leaveModule(MavenBuildProxy build,
                           org.apache.maven.project.MavenProject pom,
                           BuildListener listener)
                    throws InterruptedException,
                           IOException
Called when the build leaves the current MavenProject.

Throws:
InterruptedException
IOException
See Also:
enterModule(hudson.maven.MavenBuildProxy, org.apache.maven.project.MavenProject, hudson.model.BuildListener)

preExecute

public boolean preExecute(MavenBuildProxy build,
                          org.apache.maven.project.MavenProject pom,
                          MojoInfo mojo,
                          BuildListener listener)
                   throws InterruptedException,
                          IOException
Called before execution of a single mojo.

When this method is invoked, MojoInfo.mojo is fully injected with its configuration values.

Returns:
See preBuild(hudson.maven.MavenBuildProxy, org.apache.maven.project.MavenProject, hudson.model.BuildListener)
Throws:
InterruptedException - See preBuild(hudson.maven.MavenBuildProxy, org.apache.maven.project.MavenProject, hudson.model.BuildListener)
IOException - See preBuild(hudson.maven.MavenBuildProxy, org.apache.maven.project.MavenProject, hudson.model.BuildListener)

postExecute

public boolean postExecute(MavenBuildProxy build,
                           org.apache.maven.project.MavenProject pom,
                           MojoInfo mojo,
                           BuildListener listener,
                           Throwable error)
                    throws InterruptedException,
                           IOException
Called after execution of a single mojo.

See preExecute(hudson.maven.MavenBuildProxy, org.apache.maven.project.MavenProject, hudson.maven.MojoInfo, hudson.model.BuildListener) for the contract.

Parameters:
error - If mojo execution failed with MojoFailureException or MojoExecutionException, this method is still invoked with those error objects. If mojo executed successfully, this parameter is null.
Throws:
InterruptedException
IOException

postBuild

public boolean postBuild(MavenBuildProxy build,
                         org.apache.maven.project.MavenProject pom,
                         BuildListener listener)
                  throws InterruptedException,
                         IOException
Called after a build of one maven2 module is completed.

Note that at this point the build result is still not determined.

Returns:
See preBuild(hudson.maven.MavenBuildProxy, org.apache.maven.project.MavenProject, hudson.model.BuildListener)
Throws:
InterruptedException - See preBuild(hudson.maven.MavenBuildProxy, org.apache.maven.project.MavenProject, hudson.model.BuildListener)
IOException - See preBuild(hudson.maven.MavenBuildProxy, org.apache.maven.project.MavenProject, hudson.model.BuildListener)

end

public boolean end(MavenBuild build,
                   Launcher launcher,
                   BuildListener listener)
            throws InterruptedException,
                   IOException
Called after the maven execution finished and the result is determined.

This method fires after postBuild(MavenBuildProxy, MavenProject, BuildListener). Works like BuildStepCompatibilityLayer.perform(Build, Launcher, BuildListener).

Throws:
InterruptedException
IOException

reportGenerated

public boolean reportGenerated(MavenBuildProxy build,
                               org.apache.maven.project.MavenProject pom,
                               MavenReportInfo report,
                               BuildListener listener)
                        throws InterruptedException,
                               IOException
Called after a MavenReport is successfully generated.

MavenReport is an execution unit inside the Maven site plugin mojos, such as site:generate. These are what's configured through <reporting> tag inside POM, although there's normally more MavenReports than what's specified explicitly, due to defaulting and inheritance and all the other Maven processing.

This provides an opportunity for plugins to auto-perform some action when a certain reporting is generated.

This method is invoked during the execution of site mojos, between its preExecute(MavenBuildProxy, MavenProject, MojoInfo, BuildListener) and postExecute(MavenBuildProxy, MavenProject, MojoInfo, BuildListener, Throwable)

Returns:
See preBuild(hudson.maven.MavenBuildProxy, org.apache.maven.project.MavenProject, hudson.model.BuildListener)
Throws:
InterruptedException - See preBuild(hudson.maven.MavenBuildProxy, org.apache.maven.project.MavenProject, hudson.model.BuildListener)
IOException - See preBuild(hudson.maven.MavenBuildProxy, org.apache.maven.project.MavenProject, hudson.model.BuildListener)
Since:
1.237

getProjectAction

public Action getProjectAction(MavenModule module)
Deprecated. as of 1.341 Use getProjectActions(MavenModule) instead.

Equivalent of BuildStep.getProjectAction(AbstractProject) for MavenReporter.

Registers a transient action to MavenModule when it's rendered. This is useful if you'd like to display an action at the module level.

Since this contributes a transient action, the returned Action will not be serialized.

For this method to be invoked, your MavenReporter has to invoke MavenBuildProxy.registerAsProjectAction(MavenReporter) during the build.

Returns:
null not to contribute an action, which is the default.

getProjectActions

public Collection<? extends Action> getProjectActions(MavenModule module)
Equivalent of BuildStep.getProjectActions(AbstractProject) for MavenReporter.

Registers a transient action to MavenModule when it's rendered. This is useful if you'd like to display an action at the module level.

Since this contributes a transient action, the returned Action will not be serialized.

For this method to be invoked, your MavenReporter has to invoke MavenBuildProxy.registerAsProjectAction(MavenReporter) during the build.

Specified by:
getProjectActions in interface MavenProjectActionBuilder
Returns:
can be empty but never null.
Since:
1.341

getAggregatedProjectAction

public Action getAggregatedProjectAction(MavenModuleSet project)
Works like getProjectAction(MavenModule) but works at MavenModuleSet level.

For this method to be invoked, your MavenReporter has to invoke MavenBuildProxy.registerAsAggregatedProjectAction(MavenReporter) during the build.

Returns:
null not to contribute an action, which is the default.

getDescriptor

public MavenReporterDescriptor getDescriptor()
Description copied from interface: Describable
Gets the descriptor for this instance.

Descriptor is a singleton for every concrete Describable implementation, so if a.getClass()==b.getClass() then a.getDescriptor()==b.getDescriptor() must hold.

Specified by:
getDescriptor in interface Describable<MavenReporter>


Copyright © 2004-2013. All Rights Reserved.