Writing a maven custom report plugin; how do I gen

2019-05-14 10:58发布

问题:

I am attempting to create an custom maven report to generate when I run the mvn site goal in my project. I have followed the instructions here:

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

Specifically I have created a mojo that implements the appropriate methods, and its "executeReport(...) method is called when I run mvn site. I have also implemented a class that extends AbstractMavenReportRenderer, and filled out the renderBody(...) method with some calls to the methods in the sink. My Mojo returns a new instance of that custom renderer in its "getRenderer()" method.

My report is showing up in the list of reports when I run the mvn site target, and its html file is correctly generated with the general maven site magic (all the menus and headings and everything are there). But I don't know what to put in the "executeReport" method in order to "fill out the middle" as is suggested on the documentation above. What calls do I need to make to close that loop?

My Mojo:

@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();
  }

}

回答1:

The answer was to put the code from renderBody() inside the 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();
}