HTMLGroupVisitor.java

  1. /*******************************************************************************
  2.  * Copyright (c) 2009, 2025 Mountainminds GmbH & Co. KG and Contributors
  3.  * This program and the accompanying materials are made available under
  4.  * the terms of the Eclipse Public License 2.0 which is available at
  5.  * http://www.eclipse.org/legal/epl-2.0
  6.  *
  7.  * SPDX-License-Identifier: EPL-2.0
  8.  *
  9.  * Contributors:
  10.  *    Marc R. Hoffmann - initial API and implementation
  11.  *
  12.  *******************************************************************************/
  13. package org.jacoco.report.internal.html;

  14. import java.io.IOException;

  15. import org.jacoco.core.analysis.IBundleCoverage;
  16. import org.jacoco.core.analysis.ICoverageNode;
  17. import org.jacoco.report.ISourceFileLocator;
  18. import org.jacoco.report.internal.AbstractGroupVisitor;
  19. import org.jacoco.report.internal.ReportOutputFolder;
  20. import org.jacoco.report.internal.html.page.BundlePage;
  21. import org.jacoco.report.internal.html.page.GroupPage;
  22. import org.jacoco.report.internal.html.page.NodePage;
  23. import org.jacoco.report.internal.html.page.ReportPage;

  24. /**
  25.  * Group visitor for HTML reports.
  26.  */
  27. public class HTMLGroupVisitor extends AbstractGroupVisitor {

  28.     private final ReportOutputFolder folder;

  29.     private final IHTMLReportContext context;

  30.     private final GroupPage page;

  31.     /**
  32.      * Create a new group handler.
  33.      *
  34.      * @param parent
  35.      *            optional hierarchical parent
  36.      * @param folder
  37.      *            base folder for this group
  38.      * @param context
  39.      *            settings context
  40.      * @param name
  41.      *            group name
  42.      */
  43.     public HTMLGroupVisitor(final ReportPage parent,
  44.             final ReportOutputFolder folder, final IHTMLReportContext context,
  45.             final String name) {
  46.         super(name);
  47.         this.folder = folder;
  48.         this.context = context;
  49.         page = new GroupPage(total, parent, folder, context);
  50.     }

  51.     /**
  52.      * Returns the page rendered for this group.
  53.      *
  54.      * @return page for this group
  55.      */
  56.     public NodePage<ICoverageNode> getPage() {
  57.         return page;
  58.     }

  59.     @Override
  60.     protected void handleBundle(final IBundleCoverage bundle,
  61.             final ISourceFileLocator locator) throws IOException {
  62.         final BundlePage bundlepage = new BundlePage(bundle, page, locator,
  63.                 folder.subFolder(bundle.getName()), context);
  64.         bundlepage.render();
  65.         page.addItem(bundlepage);
  66.     }

  67.     @Override
  68.     protected AbstractGroupVisitor handleGroup(final String name)
  69.             throws IOException {
  70.         final HTMLGroupVisitor handler = new HTMLGroupVisitor(page,
  71.                 folder.subFolder(name), context, name);
  72.         page.addItem(handler.getPage());
  73.         return handler;
  74.     }

  75.     @Override
  76.     protected void handleEnd() throws IOException {
  77.         page.render();
  78.     }

  79. }