-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RAT-190: Fixes for minor bugs that blocked problem detection #250
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,13 @@ | |
* KIND, either express or implied. See the License for the * | ||
* specific language governing permissions and limitations * | ||
* under the License. * | ||
*/ | ||
*/ | ||
package org.apache.rat.report.xml; | ||
|
||
import org.apache.commons.lang3.time.DateFormatUtils; | ||
import org.apache.rat.ReportConfiguration; | ||
import org.apache.rat.analysis.DefaultAnalyserFactory; | ||
import org.apache.rat.api.RatException; | ||
import org.apache.rat.document.IDocumentAnalyser; | ||
import org.apache.rat.document.impl.util.DocumentAnalyserMultiplexer; | ||
import org.apache.rat.license.LicenseSetFactory.LicenseFilter; | ||
|
@@ -33,45 +35,80 @@ | |
import org.apache.rat.report.claim.util.LicenseAddingReport; | ||
import org.apache.rat.report.xml.writer.IXmlWriter; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Calendar; | ||
import java.util.List; | ||
|
||
/** | ||
* A factory to create reports from a writer and a configuration. | ||
* | ||
*/ | ||
public class XmlReportFactory { | ||
public final class XmlReportFactory { | ||
private static final String RAT_REPORT = "rat-report"; | ||
private static final String TIMESTAMP = "timestamp"; | ||
|
||
private XmlReportFactory() { | ||
// Do not instantiate | ||
} | ||
|
||
/** | ||
* Creates a RatReport from the arguments. | ||
* The {@code statistic} is used to create a ClaimAggregator. | ||
* If the {@code configuration} indicates that licenses should be added a LicenseAddingReport is added. | ||
* @param writer The XML writer to send output to. | ||
* @param statistic the ClaimStatistics for the report. may be null. | ||
* | ||
* @param writer The XML writer to send output to. | ||
* @param statistic the ClaimStatistics for the report. may be null. | ||
* @param configuration The report configuration. | ||
* @return a RatReport instance. | ||
*/ | ||
public static RatReport createStandardReport(IXmlWriter writer, | ||
final ClaimStatistic statistic, ReportConfiguration configuration) { | ||
public static RatReport createStandardReport(final IXmlWriter writer, final ClaimStatistic statistic, final ReportConfiguration configuration) { | ||
final List<RatReport> reporters = new ArrayList<>(); | ||
if (statistic != null) { | ||
reporters.add(new ClaimAggregator(statistic)); | ||
} | ||
if (configuration.isAddingLicenses() && !configuration.isDryRun()) { | ||
reporters.add(new LicenseAddingReport(configuration.getLog(), configuration.getCopyrightMessage(), configuration.isAddingLicensesForced())); | ||
} | ||
|
||
if (configuration.listFamilies() != LicenseFilter.NONE || configuration.listLicenses() != LicenseFilter.NONE) { | ||
|
||
reporters.add(new ConfigurationReport(writer, configuration)); | ||
} | ||
|
||
reporters.add(new SimpleXmlClaimReporter(writer)); | ||
|
||
final IDocumentAnalyser analyser = DefaultAnalyserFactory.createDefaultAnalyser(configuration); | ||
final DefaultPolicy policy = new DefaultPolicy(configuration.getLicenseFamilies(LicenseFilter.APPROVED)); | ||
|
||
final IDocumentAnalyser[] analysers = {analyser, policy}; | ||
DocumentAnalyserMultiplexer analysisMultiplexer = new DocumentAnalyserMultiplexer(analysers); | ||
return new ClaimReporterMultiplexer(configuration.isDryRun(), analysisMultiplexer, reporters); | ||
return new ClaimReporterMultiplexer(writer, configuration.isDryRun(), analysisMultiplexer, reporters); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LHF: Pls reformat this class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LHF? what does that mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sry, Low Hanging Fruit (LHF) - I use this abbreviation in commits or reviews in case of minor details or simple things. |
||
/** | ||
* Starts the XML report by writing the standard header into the writer. | ||
* @param writer The writer to write into | ||
* @throws RatException on error | ||
*/ | ||
public static void startReport(final IXmlWriter writer) throws RatException { | ||
try { | ||
writer.openElement(RAT_REPORT).attribute(TIMESTAMP, DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT.format(Calendar.getInstance())); | ||
} catch (IOException e) { | ||
throw new RatException("Cannot open start element", e); | ||
} | ||
} | ||
|
||
/** | ||
* Ends the XML reprot by closing the element that startReport opened. | ||
* @param writer the write to write into. | ||
* @throws RatException on error | ||
* @see #startReport(IXmlWriter) | ||
*/ | ||
public static void endReport(final IXmlWriter writer) throws RatException { | ||
try { | ||
writer.closeElement(); | ||
} catch (IOException e) { | ||
throw new RatException("Cannot close start element: " + RAT_REPORT, e); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<rat-config> | ||
<families> | ||
<family id="LiOne" name="License One" /> | ||
</families> | ||
<licenses> | ||
<license family="LiOne"> | ||
<text>License One</text> | ||
</license> | ||
</licenses> | ||
</rat-config> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<rat-config> | ||
<families> | ||
<family id="LiTwo" name="License Two" /> | ||
</families> | ||
<licenses> | ||
<license family="LiTwo"> | ||
<text>License Two</text> | ||
</license> | ||
</licenses> | ||
</rat-config> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls update the site template to keep its text in sync with the stuff in the code. Should we add a javadoc in this class on where to keep it in sync with in case of changes?