Home | History | Annotate | Download | only in html
      1 /*******************************************************************************
      2  * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors
      3  * All rights reserved. This program and the accompanying materials
      4  * are made available under the terms of the Eclipse Public License v1.0
      5  * which accompanies this distribution, and is available at
      6  * http://www.eclipse.org/legal/epl-v10.html
      7  *
      8  * Contributors:
      9  *    Marc R. Hoffmann - initial API and implementation
     10  *
     11  *******************************************************************************/
     12 package org.jacoco.report.internal.html;
     13 
     14 import java.io.IOException;
     15 
     16 import org.jacoco.core.analysis.IBundleCoverage;
     17 import org.jacoco.core.analysis.ICoverageNode;
     18 import org.jacoco.report.ISourceFileLocator;
     19 import org.jacoco.report.internal.AbstractGroupVisitor;
     20 import org.jacoco.report.internal.ReportOutputFolder;
     21 import org.jacoco.report.internal.html.page.BundlePage;
     22 import org.jacoco.report.internal.html.page.GroupPage;
     23 import org.jacoco.report.internal.html.page.NodePage;
     24 import org.jacoco.report.internal.html.page.ReportPage;
     25 
     26 /**
     27  * Group visitor for HTML reports.
     28  */
     29 public class HTMLGroupVisitor extends AbstractGroupVisitor {
     30 
     31 	private final ReportOutputFolder folder;
     32 
     33 	private final IHTMLReportContext context;
     34 
     35 	private final GroupPage page;
     36 
     37 	/**
     38 	 * Create a new group handler.
     39 	 *
     40 	 * @param parent
     41 	 *            optional hierarchical parent
     42 	 * @param folder
     43 	 *            base folder for this group
     44 	 * @param context
     45 	 *            settings context
     46 	 * @param name
     47 	 *            group name
     48 	 */
     49 	public HTMLGroupVisitor(final ReportPage parent,
     50 			final ReportOutputFolder folder, final IHTMLReportContext context,
     51 			final String name) {
     52 		super(name);
     53 		this.folder = folder;
     54 		this.context = context;
     55 		page = new GroupPage(total, parent, folder, context);
     56 	}
     57 
     58 	/**
     59 	 * Returns the page rendered for this group.
     60 	 *
     61 	 * @return page for this group
     62 	 */
     63 	public NodePage<ICoverageNode> getPage() {
     64 		return page;
     65 	}
     66 
     67 	@Override
     68 	protected void handleBundle(final IBundleCoverage bundle,
     69 			final ISourceFileLocator locator) throws IOException {
     70 		final BundlePage bundlepage = new BundlePage(bundle, page, locator,
     71 				folder.subFolder(bundle.getName()), context);
     72 		bundlepage.render();
     73 		page.addItem(bundlepage);
     74 	}
     75 
     76 	@Override
     77 	protected AbstractGroupVisitor handleGroup(final String name)
     78 			throws IOException {
     79 		final HTMLGroupVisitor handler = new HTMLGroupVisitor(page,
     80 				folder.subFolder(name), context, name);
     81 		page.addItem(handler.getPage());
     82 		return handler;
     83 	}
     84 
     85 	@Override
     86 	protected void handleEnd() throws IOException {
     87 		page.render();
     88 	}
     89 
     90 }
     91