Class AbstractFileReporter

  • All Implemented Interfaces:
    AutoCloseable, org.revapi.configuration.Configurable, org.revapi.Reporter

    public abstract class AbstractFileReporter
    extends Object
    implements org.revapi.Reporter
    This class can be used as a base class for reporters that want to write the reports into the files. It provides some basic features like difference filtering based on severity, the ability to specify the file to write to (including "out" and "err" as special file names for standard output and standard error) and whether to overwrite or append to an existing file.
    • Field Detail

      • minLevel

        protected org.revapi.DifferenceSeverity minLevel
      • minCriticality

        protected org.revapi.Criticality minCriticality
      • file

        protected File file
      • shouldClose

        protected boolean shouldClose
      • keepEmptyFile

        protected boolean keepEmptyFile
      • analysis

        protected org.revapi.AnalysisContext analysis
    • Constructor Detail

      • AbstractFileReporter

        public AbstractFileReporter()
    • Method Detail

      • setOutput

        protected void setOutput​(PrintWriter wrt)
        For testing.
        Parameters:
        wrt - the output writer
      • flushReports

        protected abstract void flushReports()
                                      throws IOException
        Subclasses should write the reports to the output in this method. This method MUST NOT close the output though.
        Throws:
        IOException
      • initialize

        public void initialize​(@Nonnull
                               org.revapi.AnalysisContext analysis)
        Specified by:
        initialize in interface org.revapi.configuration.Configurable
      • createOutputWriter

        protected PrintWriter createOutputWriter​(OutputStream stream,
                                                 org.revapi.AnalysisContext ctx)
        Creates a print writer to be used as an output from the supplied output stream. This method is called during the default initialize(AnalysisContext) and the default implementation creates a print writer writing in UTF-8.
        Parameters:
        stream - the stream to convert to a print writer
        ctx - the analysis context which is being used in initialize(AnalysisContext)
        Returns:
        a print writer to be used as output
      • report

        public void report​(@Nonnull
                           org.revapi.Report report)
        This is the default implementation of the report method that does the initial filtering based on the configured minimum severity and then delegates to doReport(Report) if the reporting should really be performed.
        Specified by:
        report in interface org.revapi.Reporter
        Parameters:
        report - the report with the differences
      • isReportable

        protected boolean isReportable​(org.revapi.Report report)
      • doReport

        protected abstract void doReport​(org.revapi.Report report)
        The report contains differences of at least the configured severity. This method is called from report(Report) by default.
      • getReportsByElementOrderComparator

        protected Comparator<org.revapi.Report> getReportsByElementOrderComparator()
        Returns:
        a comparator that can be used to sort the reports in the order of the compared elements.
        See Also:
        ReportComparator