编写一个maven自定义报告插件;如何生成html正文或“中间"我的报告? [英] Writing a maven custom report plugin; how do I generate the html body or "middle" of my report?

查看:81
本文介绍了编写一个maven自定义报告插件;如何生成html正文或“中间"我的报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建自定义Maven报告,以在项目中运行mvn网站目标时生成.我已按照此处的说明进行操作:

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:

具体来说,我创建了一个实现适当方法的mojo,并且在运行mvn网站时调用了其"executeReport(...)方法.我还实现了一个扩展AbstractMavenReportRenderer的类,并填写了renderBody(. ..)方法,对接收器中的方法进行了一些调用.我的Mojo在其"getRenderer()"方法中返回了该自定义渲染器的新实例.

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.

当我运行mvn网站目标时,我的报告显示在报告列表中,并且它的html文件是使用一般的maven网站魔术(所有菜单和标题以及所有内容)正确生成的.但是我不知道要在"executeReport"方法中放入什么以填充中间内容",如上面文档中所建议的那样.我需要打什么电话才能关闭该循环?

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?

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

还有我的渲染器:

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

}

推荐答案

答案是将renderBody()中的代码放入executeReport(Locale loc)方法内:

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

这篇关于编写一个maven自定义报告插件;如何生成html正文或“中间"我的报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆