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 org.apache.rat.ReportConfiguration;
22  import org.apache.rat.analysis.DefaultAnalyserFactory;
23  import org.apache.rat.document.IDocumentAnalyser;
24  import org.apache.rat.document.impl.util.DocumentAnalyserMultiplexer;
25  import org.apache.rat.license.LicenseSetFactory.LicenseFilter;
26  import org.apache.rat.policy.DefaultPolicy;
27  import org.apache.rat.report.RatReport;
28  import org.apache.rat.report.claim.ClaimStatistic;
29  import org.apache.rat.report.claim.impl.ClaimAggregator;
30  import org.apache.rat.report.claim.impl.xml.SimpleXmlClaimReporter;
31  import org.apache.rat.report.claim.util.ClaimReporterMultiplexer;
32  import org.apache.rat.report.claim.util.LicenseAddingReport;
33  import org.apache.rat.report.xml.writer.IXmlWriter;
34  
35  import java.util.ArrayList;
36  import java.util.List;
37  
38  /**
39   * A factory to create reports from a writer and a configuration.
40   *
41   */
42  public class XmlReportFactory {
43      /**
44       * Creates a RatReport from the arguments.
45       * The {@code statistic} is used to create a ClaimAggregator.
46       * If the {@code configuration} indicates that licenses should be added a LicenseAddingReport is added.
47       * @param writer The XML writer to send output to.
48       * @param statistic the ClaimStatistics for the report. may be null.
49       * @param configuration The report configuration.
50       * @return a RatReport instance.
51       */
52      public static RatReport createStandardReport(IXmlWriter writer,
53                                                   final ClaimStatistic statistic, ReportConfiguration configuration) {
54          final List<RatReport> reporters = new ArrayList<>();
55          if (statistic != null) {
56              reporters.add(new ClaimAggregator(statistic));
57          }
58          if (configuration.isAddingLicenses()) {
59              reporters.add(new LicenseAddingReport(configuration.getLog(), configuration.getCopyrightMessage(), configuration.isAddingLicensesForced()));
60          }
61          reporters.add(new SimpleXmlClaimReporter(writer));
62  
63          final IDocumentAnalyser analyser =
64              DefaultAnalyserFactory.createDefaultAnalyser(configuration.getLog(), configuration.getLicenses(LicenseFilter.all));
65          final DefaultPolicy policy = new DefaultPolicy(configuration.getLicenseFamilies(LicenseFilter.approved));
66  
67          final IDocumentAnalyser[] analysers = {analyser, policy};
68          DocumentAnalyserMultiplexer analysisMultiplexer = new DocumentAnalyserMultiplexer(analysers);
69          return new ClaimReporterMultiplexer(analysisMultiplexer, reporters);
70      }
71  }