From 4b306796702d34ad270648000433c2db4e6d569d Mon Sep 17 00:00:00 2001 From: Claude Warren Date: Mon, 27 Apr 2026 11:50:41 +0100 Subject: [PATCH 1/2] Replace NoCloseOutputStream with apahe commons CloseShieldOutputStream --- .../org/apache/rat/ReportConfiguration.java | 67 ++----------------- .../apache/rat/ReportConfigurationTest.java | 4 +- .../java/org/apache/rat/anttasks/Report.java | 3 +- 3 files changed, 8 insertions(+), 66 deletions(-) diff --git a/apache-rat-core/src/main/java/org/apache/rat/ReportConfiguration.java b/apache-rat-core/src/main/java/org/apache/rat/ReportConfiguration.java index aacd360b1..799dfaf53 100644 --- a/apache-rat-core/src/main/java/org/apache/rat/ReportConfiguration.java +++ b/apache-rat-core/src/main/java/org/apache/rat/ReportConfiguration.java @@ -39,6 +39,7 @@ import java.util.function.Consumer; import org.apache.commons.io.function.IOSupplier; +import org.apache.commons.io.output.CloseShieldOutputStream; import org.apache.rat.analysis.IHeaderMatcher; import org.apache.rat.commandline.StyleSheets; import org.apache.rat.config.AddLicenseHeaders; @@ -504,10 +505,10 @@ public void setStyleSheet(final URL styleSheet) { * Sets the supplier for the output stream. The supplier may be called multiple * times to provide the stream. Suppliers should prepare streams that are * appended to and that can be closed. If an {@code OutputStream} should not be - * closed consider wrapping it in a {@code NoCloseOutputStream} + * closed consider wrapping it in a {@code CloseShieldOutputStream} * @param out The OutputStream supplier that provides the output stream to write * the report to. A null value will use System.out. - * @see NoCloseOutputStream + * @see CloseShieldOutputStream */ public void setOut(final IOSupplier out) { this.out = out; @@ -542,7 +543,7 @@ public void setOut(final File file) { * @return The supplier of the output stream to write the report to. */ public IOSupplier getOutput() { - return out == null ? () -> new NoCloseOutputStream(System.out) : out; + return out == null ? () -> CloseShieldOutputStream.wrap(System.out) : out; } /** @@ -841,64 +842,4 @@ public void validate(final Consumer logger) { throw new ConfigurationException(msg); } } - - /** - * A wrapper around an output stream that does not close the output stream. - */ - public static class NoCloseOutputStream extends OutputStream { - /** the output stream this stream wraps */ - private final OutputStream delegate; - - /** - * Constructor. - * @param delegate the output stream to wrap. - */ - public NoCloseOutputStream(final OutputStream delegate) { - this.delegate = delegate; - } - - @Override - public void write(final int arg0) throws IOException { - delegate.write(arg0); - } - - /** - * Does not actually close the delegate. But does perform a flush. - * @throws IOException on Error. - */ - @Override - public void close() throws IOException { - this.delegate.flush(); - } - - @Override - public boolean equals(final Object obj) { - return delegate.equals(obj); - } - - @Override - public void flush() throws IOException { - delegate.flush(); - } - - @Override - public int hashCode() { - return delegate.hashCode(); - } - - @Override - public String toString() { - return delegate.toString(); - } - - @Override - public void write(final byte[] arg0, final int arg1, final int arg2) throws IOException { - delegate.write(arg0, arg1, arg2); - } - - @Override - public void write(final byte[] b) throws IOException { - delegate.write(b); - } - } } diff --git a/apache-rat-core/src/test/java/org/apache/rat/ReportConfigurationTest.java b/apache-rat-core/src/test/java/org/apache/rat/ReportConfigurationTest.java index 8ff47a287..69af88b2b 100644 --- a/apache-rat-core/src/test/java/org/apache/rat/ReportConfigurationTest.java +++ b/apache-rat-core/src/test/java/org/apache/rat/ReportConfigurationTest.java @@ -41,7 +41,7 @@ import java.util.function.Function; import org.apache.commons.io.filefilter.DirectoryFileFilter; -import org.apache.rat.ReportConfiguration.NoCloseOutputStream; +import org.apache.commons.io.output.CloseShieldOutputStream; import org.apache.rat.analysis.IHeaderMatcher; import org.apache.rat.config.AddLicenseHeaders; import org.apache.rat.config.exclusion.StandardCollection; @@ -452,7 +452,7 @@ public void licensesTest() { @Test public void outputTest() throws IOException { - assertThat(underTest.getOutput().get()).isExactlyInstanceOf(NoCloseOutputStream.class); + assertThat(underTest.getOutput().get()).isExactlyInstanceOf(CloseShieldOutputStream.class); assertThat(underTest.getWriter()).isNotNull(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); diff --git a/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java b/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java index 1dd3414ab..a069084f2 100644 --- a/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java +++ b/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java @@ -29,6 +29,7 @@ import org.apache.commons.cli.Option; import org.apache.commons.io.filefilter.IOFileFilter; +import org.apache.commons.io.output.CloseShieldOutputStream; import org.apache.rat.ConfigurationException; import org.apache.rat.DeprecationReporter; import org.apache.rat.ImplementationException; @@ -443,7 +444,7 @@ public ReportConfiguration getConfiguration() { public void execute() { try { Reporter r = new Reporter(validate(getConfiguration())); - r.output(StyleSheets.PLAIN.getStyleSheet(), () -> new ReportConfiguration.NoCloseOutputStream(System.out)); + r.output(StyleSheets.PLAIN.getStyleSheet(), () -> CloseShieldOutputStream.wrap(System.out)); r.output(); } catch (BuildException e) { throw e; From 48747efe32c58fb7e6e5bd80fd7ec0f40f70066b Mon Sep 17 00:00:00 2001 From: "P. Ottlinger" Date: Tue, 28 Apr 2026 18:42:43 +0200 Subject: [PATCH 2/2] RAT-551: Add changelog --- src/changes/changes.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c8bf1f55e..b115353d7 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -68,6 +68,9 @@ in order to be properly linked in site reports. --> + + Replace NoCloseOutputStream with Apache Commons CloseShieldOutputStream. + Enable reproducible build and keep a changing timestamp for webpage generation.