001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.terminal.report; 018 019import static org.apache.juneau.commons.utils.Shorts.*; 020 021import java.nio.file.*; 022 023 024/** 025 * Reads a single JUnit-XML report file, such as pytest's <c>--junitxml</c> output. 026 * 027 * <p> 028 * The framework key defaults to <c>junit-xml</c>; pass <c>"pytest"</c> to the constructor when the producer knows the 029 * file came from pytest. 030 */ 031public final class JUnitXmlReportReader implements ReportReader { 032 033 private final String fw; 034 035 /** Constructor; the framework key is <c>junit-xml</c>. */ 036 public JUnitXmlReportReader() { 037 this("junit-xml"); 038 } 039 040 /** 041 * Constructor. 042 * 043 * @param fw The framework key, matching <c>^[a-z0-9][a-z0-9._-]{0,31}$</c>. 044 * @throws IllegalArgumentException If the key does not match. 045 */ 046 public JUnitXmlReportReader(String fw) { 047 if (! TerminalViewChecks.isFw(fw)) 048 throw iaex("JUnitXmlReportReader fw must match ^[a-z0-9][a-z0-9._-]{0,31}$; got '%s'.", fw); 049 this.fw = fw; 050 } 051 052 @Override /* ReportReader */ 053 public String fw() { 054 return fw; 055 } 056 057 @Override /* ReportReader */ 058 public ReportResult read(Path path, ReportLimits limits) { 059 var out = new ReportBuilder(); 060 JUnitXmlParser.parse(path, limits, out); 061 return out.build(fw); 062 } 063}