You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@creadur.apache.org by jo...@apache.org on 2022/03/31 21:12:36 UTC
[creadur-rat] branch master updated: PR: RAT-273 Workaround for an incompatibility in the java.io.LineNumberReaderm which has been replaced with the org.apache.rat.header.LineNumberReader.
This is an automated email from the ASF dual-hosted git repository.
jochen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/creadur-rat.git
The following commit(s) were added to refs/heads/master by this push:
new ec1d46e PR: RAT-273 Workaround for an incompatibility in the java.io.LineNumberReaderm which has been replaced with the org.apache.rat.header.LineNumberReader.
ec1d46e is described below
commit ec1d46ee782b95ca322f178a97caf34fca6db885
Author: Jochen Wiedmann <jo...@gmail.com>
AuthorDate: Thu Mar 31 22:10:40 2022 +0100
PR: RAT-273
Workaround for an incompatibility in the java.io.LineNumberReaderm which has been replaced
with the org.apache.rat.header.LineNumberReader.
---
.../rat/header/FilteringSequenceFactory.java | 4 +
.../java/org/apache/rat/header/HeaderMatcher.java | 1 -
...gSequenceFactory.java => LineNumberReader.java} | 123 +++++++++++----------
src/changes/changes.xml | 4 +
4 files changed, 72 insertions(+), 60 deletions(-)
diff --git a/apache-rat-core/src/main/java/org/apache/rat/header/FilteringSequenceFactory.java b/apache-rat-core/src/main/java/org/apache/rat/header/FilteringSequenceFactory.java
index f01dc0f..ac5d31a 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/header/FilteringSequenceFactory.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/header/FilteringSequenceFactory.java
@@ -39,6 +39,10 @@ class FilteringSequenceFactory {
}
public CharSequence filter(Reader reader) throws IOException {
+ return filter(new LineNumberReader(reader));
+ }
+
+ public CharSequence filter(LineNumberReader reader) throws IOException {
buffer.clear();
boolean eof = false;
while(!eof) {
diff --git a/apache-rat-core/src/main/java/org/apache/rat/header/HeaderMatcher.java b/apache-rat-core/src/main/java/org/apache/rat/header/HeaderMatcher.java
index eb3353e..ac720bf 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/header/HeaderMatcher.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/header/HeaderMatcher.java
@@ -19,7 +19,6 @@
package org.apache.rat.header;
import java.io.IOException;
-import java.io.LineNumberReader;
import java.io.Reader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
diff --git a/apache-rat-core/src/main/java/org/apache/rat/header/FilteringSequenceFactory.java b/apache-rat-core/src/main/java/org/apache/rat/header/LineNumberReader.java
similarity index 51%
copy from apache-rat-core/src/main/java/org/apache/rat/header/FilteringSequenceFactory.java
copy to apache-rat-core/src/main/java/org/apache/rat/header/LineNumberReader.java
index f01dc0f..d5f150b 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/header/FilteringSequenceFactory.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/header/LineNumberReader.java
@@ -1,59 +1,64 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one *
- * or more contributor license agreements. See the NOTICE file *
- * distributed with this work for additional information *
- * regarding copyright ownership. The ASF licenses this file *
- * to you under the Apache License, Version 2.0 (the *
- * "License"); you may not use this file except in compliance *
- * with the License. You may obtain a copy of the License at *
- * *
- * http://www.apache.org/licenses/LICENSE-2.0 *
- * *
- * Unless required by applicable law or agreed to in writing, *
- * software distributed under the License is distributed on an *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
- * KIND, either express or implied. See the License for the *
- * specific language governing permissions and limitations *
- * under the License. *
- */
-package org.apache.rat.header;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.nio.CharBuffer;
-
-class FilteringSequenceFactory {
-
- private static final int BUFFER_CAPACITY = 5000;
-
- private final CharBuffer buffer;
- private final CharFilter filter;
-
- public FilteringSequenceFactory(final CharFilter filter) {
- this(BUFFER_CAPACITY, filter);
- }
-
- public FilteringSequenceFactory(final int capacity, final CharFilter filter) {
- this.buffer = CharBuffer.allocate(capacity);
- this.filter = filter;
- }
-
- public CharSequence filter(Reader reader) throws IOException {
- buffer.clear();
- boolean eof = false;
- while(!eof) {
- final int next = reader.read();
- if (next == -1 || !buffer.hasRemaining()) {
- eof = true;
- } else {
- final char character = (char) next;
- if (!filter.isFilteredOut(character))
- {
- buffer.put(character);
- }
- }
- }
- buffer.limit(buffer.position()).rewind();
- return buffer;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ */
+package org.apache.rat.header;
+
+import java.io.IOException;
+import java.io.Reader;
+
+/** Replacement for {@link java.io.LineNumberReader}. This class
+ * provides a workaround for an incompatibility in the
+ * {@link java.io.LineNumberReader}: If the last line in a file
+ * isn't terminated with LF, or CR, or CRLF, then that line
+ * is counted in Java 16, and beyond, but wasn't counted before.
+ * This implementation is compatible with the latter variant,
+ * thus providing upwards compatibility for RAT.
+ */
+public class LineNumberReader {
+ private final Reader parent;
+ private boolean previousCharWasCR = false;
+ private int lineNumber = 0;
+
+ public LineNumberReader(Reader pReader) {
+ parent = pReader;
+ }
+
+ public int read() throws IOException {
+ final int c = parent.read();
+ switch(c) {
+ case 13:
+ previousCharWasCR = true;
+ ++lineNumber;
+ break;
+ case 10:
+ if (!previousCharWasCR) {
+ ++lineNumber;
+ }
+ previousCharWasCR = false;
+ break;
+ default:
+ previousCharWasCR = false;
+ break;
+ }
+ return c;
+ }
+
+ public int getLineNumber() {
+ return lineNumber;
+ }
+}
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f876d93..50f2014 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -55,6 +55,10 @@ The <action> type attribute can be add,update,fix,remove.
<body>
<release version="0.14-SNAPSHOT" date="2020-xx-xx" description="Current SNAPSHOT - to be done">
+ <action issue="RAT-273" type="fix" dev="jochen">
+ Workaround for an incompatibility in the java.io.LineNumberReader, which is
+ being replaced by the org.apache.rat.header.LineNumberReader.
+ </action>
<action issue="RAT-297" type="add" dev="pottlinger" due-to="Michael Osipov">
Update maven-reporting-api from 3.0 to 3.1.0 and remove usage of deprecated Sink API.
</action>