View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   */
19  package org.apache.rat.report.xml;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.apache.rat.ReportConfiguration;
25  import org.apache.rat.analysis.AnalyserFactory;
26  import org.apache.rat.license.LicenseSetFactory.LicenseFilter;
27  import org.apache.rat.report.ConfigurationReport;
28  import org.apache.rat.report.RatReport;
29  import org.apache.rat.report.claim.ClaimAggregator;
30  import org.apache.rat.report.claim.ClaimReporterMultiplexer;
31  import org.apache.rat.report.claim.ClaimStatistic;
32  import org.apache.rat.report.claim.ClaimValidatorReport;
33  import org.apache.rat.report.claim.LicenseAddingReport;
34  import org.apache.rat.report.claim.SimpleXmlClaimReporter;
35  import org.apache.rat.report.xml.writer.IXmlWriter;
36  
37  /**
38   * A factory to create reports from a writer and a configuration.
39   */
40  public final class XmlReportFactory {
41  
42      private XmlReportFactory() {
43          // Do not instantiate
44      }
45  
46      /**
47       * Creates a RatReport from the arguments.
48       * The {@code statistic} is used to create a ClaimAggregator.
49       * If the {@code configuration} indicates that licenses should be added a LicenseAddingReport is added.
50       *
51       * @param writer        The XML writer to send output to.
52       * @param statistic     the ClaimStatistics for the report. may be null.
53       * @param configuration The report configuration.
54       * @return a RatReport instance.
55       */
56      public static RatReport createStandardReport(final IXmlWriter writer, final ClaimStatistic statistic, final ReportConfiguration configuration) {
57          final List<RatReport> reporters = new ArrayList<>();
58          if (statistic != null) {
59              reporters.add(new ClaimAggregator(statistic));
60          }
61          if (configuration.isAddingLicenses() && !configuration.isDryRun()) {
62              reporters.add(new LicenseAddingReport(configuration.getCopyrightMessage(), configuration.isAddingLicensesForced()));
63          }
64  
65          if (configuration.listFamilies() != LicenseFilter.NONE || configuration.listLicenses() != LicenseFilter.NONE) {
66  
67              reporters.add(new ConfigurationReport(writer, configuration));
68          }
69  
70          reporters.add(new SimpleXmlClaimReporter(writer));
71          reporters.add(new ClaimValidatorReport(writer, statistic, configuration));
72  
73          return new ClaimReporterMultiplexer(writer, configuration.isDryRun(), AnalyserFactory.createConfiguredAnalyser(configuration), reporters);
74      }
75  }