Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -504,10 +505,10 @@
* 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<OutputStream> out) {
this.out = out;
Expand Down Expand Up @@ -542,7 +543,7 @@
* @return The supplier of the output stream to write the report to.
*/
public IOSupplier<OutputStream> getOutput() {
return out == null ? () -> new NoCloseOutputStream(System.out) : out;
return out == null ? () -> CloseShieldOutputStream.wrap(System.out) : out;

Check warning on line 546 in apache-rat-core/src/main/java/org/apache/rat/ReportConfiguration.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this use of System.out by a logger.

See more on https://sonarcloud.io/project/issues?id=apache_creadur-rat&issues=AZ3OnVeUC9pcvfWDKkYP&open=AZ3OnVeUC9pcvfWDKkYP&pullRequest=653
}

/**
Expand Down Expand Up @@ -841,64 +842,4 @@
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -443,7 +444,7 @@
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));

Check warning on line 447 in apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this use of System.out by a logger.

See more on https://sonarcloud.io/project/issues?id=apache_creadur-rat&issues=AZ3OnVgsC9pcvfWDKkYQ&open=AZ3OnVgsC9pcvfWDKkYQ&pullRequest=653
r.output();
} catch (BuildException e) {
throw e;
Expand Down
3 changes: 3 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ in order to be properly linked in site reports.
</release>
-->
<release version="1.0.0-SNAPSHOT" date="xxxx-yy-zz" description="Current SNAPSHOT - release to be done">
<action issue="RAT-551" type="add" dev="claudenw">
Replace NoCloseOutputStream with Apache Commons CloseShieldOutputStream.
</action>
<action issue="RAT-536" type="fix" dev="pottlinger" due-to="Hervé Boutemy">
Enable reproducible build and keep a changing timestamp for webpage generation.
</action>
Expand Down