Writing a custom maven reporting plugin; how can i generate the html body or "middle" of my report?

I am trying to create a custom maven report to generate when I run the mvn site target in my project. I followed the instructions below:

http://docs.codehaus.org/display/MAVENUSER/Write+your+own+report+plugin

Specifically, I created a mojo that implements the appropriate methods and its executeReport (...) method is called when the mvn site starts up. I also implemented a class that extends AbstractMavenReportRenderer and populates renderBody (...) with some method calls in the receiver. My Mojo is returning a new instance of this custom renderer in its getRenderer () method.

My report shows up in the list of reports when I run the mvn target and its html file is correctly generated by the general maven site magic (all menus and headers and everything there). But I don't know what to add to the "executeReport" method to "fill in the middle" as suggested in the documentation above. What calls do I need to make to close this loop?

My Moho:

@Mojo( name = "message-documentation-report-generator")
public class MessageDocumentationReportMojo extends AbstractMavenReport
{

  /**
   * Directory where reports will go.
   *
   * @parameter expression="${project.reporting.outputDirectory}"
   * @required
   * @readonly
   */
  private String outputDirectory;

  /**
   * @parameter default-value="${project}"
   * @required
   * @readonly
   */
  private MavenProject project;

  @Override
  public String getDescription(Locale arg0)
  {
    return "Message Documentation Information";
  }

  @Override
  public String getName(Locale arg0)
  {
    return "Messages";
  }

  @Override
  public String getOutputName()
  {
    return "messages";
  }

  @Override
  protected void executeReport(Locale arg0) throws MavenReportException
  {
  }

  @Override
  protected String getOutputDirectory()
  {
    return outputDirectory;
  }

  @Override
  protected MavenProject getProject()
  {
    return project;
  }

  @Override
  protected Renderer getSiteRenderer()
  {
    return (Renderer) new MessageReportSiteRenderer(getSink());
  }
}

      

And my renderer:

public class MessageReportSiteRenderer extends AbstractMavenReportRenderer
{

  public MessageReportSiteRenderer(Sink sink)
  {
    super(sink);
  }

  @Override
  public String getTitle()
  {
    return "Message Documentation Renderer?";
  }

  @Override
  protected void renderBody()
  {
    sink.head();
    sink.title();
    sink.text("FIDL graph report");
    sink.title_();
    sink.head_();

    sink.body();
    sink.section1();

    sink.sectionTitle1();
    sink.text("FIDL automata index");
    sink.sectionTitle1_();
    sink.lineBreak();
    sink.lineBreak();

    sink.text("List of behavioral elements with link to graphical representation of FIDL automata.");

    sink.lineBreak();
    sink.section1_();
    sink.body_();
    sink.flush();
    sink.close();
  }

}

      

+3


source to share


1 answer


The answer was to put the code from renderBody () method inside executeReport (Locale loc) method:



@Override
protected void executeReport(Locale arg0) throws MavenReportException
{

sink.head();
sink.title();
sink.text("FIDL graph report");
sink.title_();
sink.head_();

sink.body();
sink.section1();

sink.sectionTitle1();
sink.text("FIDL automata index");
sink.sectionTitle1_();
sink.lineBreak();
sink.lineBreak();

sink.text("List of behavioral elements with link to graphical representation of FIDL automata.");

sink.lineBreak();
sink.section1_();
sink.body_();
sink.flush();
sink.close();
}

      

+5


source







All Articles