diff --git a/aQute.libg/src/aQute/lib/collections/LineCollection.java b/aQute.libg/src/aQute/lib/collections/LineCollection.java index 435d725b6e..f6bea6a950 100644 --- a/aQute.libg/src/aQute/lib/collections/LineCollection.java +++ b/aQute.libg/src/aQute/lib/collections/LineCollection.java @@ -27,7 +27,7 @@ public LineCollection(File in) throws IOException { } public LineCollection(Reader reader) throws IOException { - this(new BufferedReader(reader)); + this((reader instanceof BufferedReader) ? (BufferedReader) reader : new BufferedReader(reader)); } public LineCollection(BufferedReader reader) throws IOException { diff --git a/aQute.libg/src/aQute/lib/io/IO.java b/aQute.libg/src/aQute/lib/io/IO.java index 76e7f37ff9..433d1e47b8 100644 --- a/aQute.libg/src/aQute/lib/io/IO.java +++ b/aQute.libg/src/aQute/lib/io/IO.java @@ -1315,7 +1315,7 @@ public static BufferedReader reader(Path path, Charset encoding) throws IOExcept } public static BufferedReader reader(ByteBuffer bb, Charset encoding) { - return reader(new ByteBufferInputStream(bb), encoding); + return reader(stream(bb), encoding); } public static BufferedReader reader(CharBuffer cb) { diff --git a/aQute.libg/src/aQute/lib/io/LineSeparatorBufferedReader.java b/aQute.libg/src/aQute/lib/io/LineSeparatorBufferedReader.java new file mode 100644 index 0000000000..97d283e5cb --- /dev/null +++ b/aQute.libg/src/aQute/lib/io/LineSeparatorBufferedReader.java @@ -0,0 +1,157 @@ +package aQute.lib.io; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Reader; +import java.nio.CharBuffer; + +/** + * BufferedReader which returns the line separator string for the + * previously read line. + */ +public class LineSeparatorBufferedReader extends BufferedReader { + public LineSeparatorBufferedReader(Reader in) { + super(in); + } + + public LineSeparatorBufferedReader(Reader in, int size) { + super(in, size); + } + + private int markedPushBack = -1; + private int pushBack = -1; + private int markedEol; + private int eol; + + @Override + public void mark(int readAheadLimit) throws IOException { + super.mark(readAheadLimit); + markedPushBack = pushBack; + markedEol = eol; + } + + @Override + public void reset() throws IOException { + super.reset(); + pushBack = markedPushBack; + eol = markedEol; + } + + @Override + public int read() throws IOException { + lineSeparator(); // consume any line separator characters + return read0(); + } + + private int read0() throws IOException { + int c = pushBack; + if (c != -1) { + pushBack = -1; + return c; + } + return super.read(); + } + + @Override + public int read(char[] cbuf, int off, int len) throws IOException { + lineSeparator(); // consume any line separator characters + int c = pushBack; + if (c != -1) { + if ((off >= 0) && (off < cbuf.length) && (len > 0)) { + pushBack = -1; + cbuf[off] = (char) c; + return 1; + } + } + return super.read(cbuf, off, len); + } + + @Override + public int read(CharBuffer target) throws IOException { + lineSeparator(); // consume any line separator characters + int c = pushBack; + if (c != -1) { + if (target.remaining() > 0) { + pushBack = -1; + target.put((char) c); + return 1; + } + } + return super.read(target); + } + + @Override + public int read(char[] cbuf) throws IOException { + return read(cbuf, 0, cbuf.length); + } + + @Override + public String readLine() throws IOException { + int c = read0(); + if (c == -1) { + eol = 0; + return null; + } + StringBuilder sb = new StringBuilder(80); + for (; c != -1; c = read0()) { + if (c == '\n') { + if (eol == '\r') { + eol = 0; + continue; + } + eol = c; + return sb.toString(); + } + if (c == '\r') { + eol = c; + return sb.toString(); + } + sb.append((char)c); + } + eol = 0; + return sb.toString(); + } + + @Override + public long skip(long n) throws IOException { + lineSeparator(); // consume any line separator characters + if ((pushBack != -1) && (n > 0L)) { + pushBack = -1; + return super.skip(n - 1) + 1; + } + return super.skip(n); + } + + @Override + public boolean ready() throws IOException { + return (pushBack != -1) || super.ready(); + } + + /** + * Return the line separator string from the previously read line + * using {@link #readLine()} or the empty string if end of file. + * This method can be called once per read line. Subsequent calls + * per read line will return the empty string. + * + * @return The line separator string from the previously read line. + * @throws IOException If an exception occurs reading. + */ + public String lineSeparator() throws IOException { + int e = eol; + if (e == '\n') { + eol = 0; + return "\n"; + } + if (e == '\r') { + eol = 0; + int c = read0(); + if (c != '\n') { + pushBack = c; + return "\r"; + } + return "\r\n"; + } + return ""; + } + +} diff --git a/aQute.libg/src/aQute/lib/strings/Strings.java b/aQute.libg/src/aQute/lib/strings/Strings.java index 2121733391..8553352b09 100644 --- a/aQute.libg/src/aQute/lib/strings/Strings.java +++ b/aQute.libg/src/aQute/lib/strings/Strings.java @@ -634,4 +634,17 @@ public static String removeQuotes(String s) { } return s; } + + public static boolean startsWithIgnoreCase(String target, String prefix) { + return startsWithIgnoreCase(target, prefix, 0); + } + + public static boolean startsWithIgnoreCase(String target, String prefix, int toffset) { + return target.regionMatches(true, toffset, prefix, 0, prefix.length()); + } + + public static boolean endsWithIgnoreCase(String target, String suffix) { + int suffixLen = suffix.length(); + return target.regionMatches(true, target.length() - suffixLen, suffix, 0, suffixLen); + } } diff --git a/aQute.libg/src/aQute/lib/strings/package-info.java b/aQute.libg/src/aQute/lib/strings/package-info.java index bb6fd6c40b..981b43afbe 100644 --- a/aQute.libg/src/aQute/lib/strings/package-info.java +++ b/aQute.libg/src/aQute/lib/strings/package-info.java @@ -1,4 +1,4 @@ -@Version("1.11.0") +@Version("1.12.0") package aQute.lib.strings; import org.osgi.annotation.versioning.Version; diff --git a/aQute.libg/test/aQute/lib/io/LineSeparatorBufferedReaderTest.java b/aQute.libg/test/aQute/lib/io/LineSeparatorBufferedReaderTest.java new file mode 100644 index 0000000000..fab2443447 --- /dev/null +++ b/aQute.libg/test/aQute/lib/io/LineSeparatorBufferedReaderTest.java @@ -0,0 +1,322 @@ +package aQute.lib.io; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.StringReader; +import java.nio.CharBuffer; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +class LineSeparatorBufferedReaderTest { + @Test + void empty() throws Exception { + String testString = ""; + StringReader stringReader = new StringReader(testString); + LineSeparatorBufferedReader reader = new LineSeparatorBufferedReader(stringReader); + assertThat(reader.readLine()).isNull(); + } + + @Test + void no_eol() throws Exception { + String testString = "foo=bar"; + StringReader stringReader = new StringReader(testString); + LineSeparatorBufferedReader reader = new LineSeparatorBufferedReader(stringReader); + assertThat(reader.readLine()).isEqualTo("foo=bar"); + assertThat(reader.lineSeparator()).isEqualTo(""); + assertThat(reader.lineSeparator()).isEqualTo(""); + assertThat(reader.readLine()).isNull(); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + + @Test + void lf() throws Exception { + String testString = "foo=bar\n"; + StringReader stringReader = new StringReader(testString); + LineSeparatorBufferedReader reader = new LineSeparatorBufferedReader(stringReader); + assertThat(reader.readLine()).isEqualTo("foo=bar"); + assertThat(reader.lineSeparator()).isEqualTo("\n"); + assertThat(reader.lineSeparator()).isEqualTo(""); + assertThat(reader.readLine()).isNull(); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + + @Test + void cr() throws Exception { + String testString = "foo=bar\r"; + StringReader stringReader = new StringReader(testString); + LineSeparatorBufferedReader reader = new LineSeparatorBufferedReader(stringReader); + assertThat(reader.readLine()).isEqualTo("foo=bar"); + assertThat(reader.lineSeparator()).isEqualTo("\r"); + assertThat(reader.lineSeparator()).isEqualTo(""); + assertThat(reader.readLine()).isNull(); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + + @Test + void crlf() throws Exception { + String testString = "foo=bar\r\n"; + StringReader stringReader = new StringReader(testString); + LineSeparatorBufferedReader reader = new LineSeparatorBufferedReader(stringReader); + assertThat(reader.readLine()).isEqualTo("foo=bar"); + assertThat(reader.lineSeparator()).isEqualTo("\r\n"); + assertThat(reader.lineSeparator()).isEqualTo(""); + assertThat(reader.readLine()).isNull(); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + + @ValueSource(booleans = {true, false}) + @ParameterizedTest + void mixed_eol(boolean lineSeparator) throws Exception { + String testString = "\nfoo1=bar\r\nfoo2=bar\nfoo3=bar\rfoo4=bar"; + StringReader stringReader = new StringReader(testString); + LineSeparatorBufferedReader reader = new LineSeparatorBufferedReader(stringReader); + assertThat(reader.readLine()).isEqualTo(""); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\n"); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + assertThat(reader.readLine()).isEqualTo("foo1=bar"); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\r\n"); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + assertThat(reader.readLine()).isEqualTo("foo2=bar"); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\n"); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + assertThat(reader.readLine()).isEqualTo("foo3=bar"); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\r"); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + assertThat(reader.readLine()).isEqualTo("foo4=bar"); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo(""); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + assertThat(reader.readLine()).isNull(); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo(""); + } + } + + @ValueSource(booleans = {true, false}) + @ParameterizedTest + void skip(boolean lineSeparator) throws Exception { + String testString = "\nfoo1=bar\r\nfoo2=bar\nfoo3=bar\rfoo4=bar"; + StringReader stringReader = new StringReader(testString); + LineSeparatorBufferedReader reader = new LineSeparatorBufferedReader(stringReader); + assertThat(reader.readLine()).isEqualTo(""); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\n"); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + assertThat(reader.readLine()).isEqualTo("foo1=bar"); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\r\n"); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + String skipString = "foo2=bar\n"; + assertThat(reader.skip(skipString.length())).isEqualTo(skipString.length()); + assertThat(reader.readLine()).isEqualTo("foo3=bar"); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\r"); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + assertThat(reader.readLine()).isEqualTo("foo4=bar"); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo(""); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + assertThat(reader.readLine()).isNull(); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo(""); + } + } + + @ValueSource(booleans = {true, false}) + @ParameterizedTest + void mark(boolean lineSeparator) throws Exception { + String testString = "\nfoo1=bar\r\nfoo2=bar\nfoo3=bar\rfoo4=bar"; + StringReader stringReader = new StringReader(testString); + LineSeparatorBufferedReader reader = new LineSeparatorBufferedReader(stringReader); + assertThat(reader.readLine()).isEqualTo(""); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\n"); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + assertThat(reader.readLine()).isEqualTo("foo1=bar"); + reader.mark(200); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\r\n"); + } + reader.reset(); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\r\n"); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + reader.mark(200); + assertThat(reader.readLine()).isEqualTo("foo2=bar"); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\n"); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + reader.reset(); + assertThat(reader.readLine()).isEqualTo("foo2=bar"); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\n"); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + assertThat(reader.readLine()).isEqualTo("foo3=bar"); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\r"); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + reader.mark(200); + assertThat(reader.readLine()).isEqualTo("foo4=bar"); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo(""); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + reader.reset(); + assertThat(reader.readLine()).isEqualTo("foo4=bar"); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo(""); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + assertThat(reader.readLine()).isNull(); + assertThat(reader.lineSeparator()).isEqualTo(""); + } + + @ValueSource(booleans = {true, false}) + @ParameterizedTest + void newlines(boolean lineSeparator) throws Exception { + String testString = "\n\r\n\n\rfoo=bar"; + StringReader stringReader = new StringReader(testString); + LineSeparatorBufferedReader reader = new LineSeparatorBufferedReader(stringReader); + assertThat(reader.readLine()).isEqualTo(""); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\n"); + } + assertThat(reader.readLine()).isEqualTo(""); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\r\n"); + } + assertThat(reader.readLine()).isEqualTo(""); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\n"); + } + assertThat(reader.readLine()).isEqualTo(""); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\r"); + } + assertThat(reader.readLine()).isEqualTo("foo=bar"); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo(""); + } + assertThat(reader.readLine()).isNull(); + } + + @Test + void read_single() throws Exception { + String testString = "\nfoo1=bar\r\n"; + StringReader stringReader = new StringReader(testString); + LineSeparatorBufferedReader reader = new LineSeparatorBufferedReader(stringReader); + for (char c : testString.toCharArray()) { + assertThat(reader.read()).isEqualTo(c); + } + assertThat(reader.read()).isEqualTo(-1); + } + + @ValueSource(booleans = {true, false}) + @ParameterizedTest + void read_single_pushback(boolean lineSeparator) throws Exception { + String testString = "\nfoo1=bar\rfoo2=bar"; + StringReader stringReader = new StringReader(testString); + LineSeparatorBufferedReader reader = new LineSeparatorBufferedReader(stringReader); + assertThat(reader.read()).isEqualTo('\n'); + assertThat(reader.readLine()).isEqualTo("foo1=bar"); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\r"); + } + String remainder = "foo2=bar"; + for (char c : remainder.toCharArray()) { + assertThat(reader.read()).isEqualTo(c); + } + assertThat(reader.read()).isEqualTo(-1); + } + + @Test + void read_array() throws Exception { + String testString = "\nfoo1=bar\r\n"; + StringReader stringReader = new StringReader(testString); + LineSeparatorBufferedReader reader = new LineSeparatorBufferedReader(stringReader); + char[] cbuf = new char[200]; + assertThat(reader.read(cbuf)).isEqualTo(testString.length()); + assertThat(cbuf).startsWith(testString.toCharArray()); + assertThat(reader.read(cbuf)).isEqualTo(-1); + } + + @ValueSource(booleans = {true, false}) + @ParameterizedTest + void read_array_pushback(boolean lineSeparator) throws Exception { + String testString = "\nfoo1=bar\rfoo2=bar"; + StringReader stringReader = new StringReader(testString); + LineSeparatorBufferedReader reader = new LineSeparatorBufferedReader(stringReader); + assertThat(reader.read()).isEqualTo('\n'); + assertThat(reader.readLine()).isEqualTo("foo1=bar"); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\r"); + } + char[] cbuf = new char[200]; + String remainder = "foo2=bar"; + for (int remaining; (remaining = remainder.length()) > 0;) { + int length = reader.read(cbuf); + assertThat(length).isBetween(1, remaining); + assertThat(cbuf).startsWith(remainder.substring(0, length) + .toCharArray()); + remainder = remainder.substring(length); + } + assertThat(reader.read(cbuf)).isEqualTo(-1); + } + + @Test + void read_charbuffer() throws Exception { + String testString = "\nfoo1=bar\r\n"; + StringReader stringReader = new StringReader(testString); + LineSeparatorBufferedReader reader = new LineSeparatorBufferedReader(stringReader); + CharBuffer cbuf = CharBuffer.allocate(200); + assertThat(reader.read(cbuf)).isEqualTo(testString.length()); + cbuf.flip(); + assertThat(cbuf.toString()).isEqualTo(testString); + cbuf.clear(); + assertThat(reader.read(cbuf)).isEqualTo(-1); + } + + @ValueSource(booleans = {true, false}) + @ParameterizedTest + void read_charbuffer_pushback(boolean lineSeparator) throws Exception { + String testString = "\nfoo1=bar\rfoo2=bar"; + StringReader stringReader = new StringReader(testString); + LineSeparatorBufferedReader reader = new LineSeparatorBufferedReader(stringReader); + assertThat(reader.read()).isEqualTo('\n'); + assertThat(reader.readLine()).isEqualTo("foo1=bar"); + if (lineSeparator) { + assertThat(reader.lineSeparator()).isEqualTo("\r"); + } + CharBuffer cbuf = CharBuffer.allocate(200); + String remainder = "foo2=bar"; + for (int remaining; (remaining = remainder.length()) > 0;) { + int length = reader.read(cbuf); + cbuf.flip(); + assertThat(length).isBetween(1, remaining); + assertThat(cbuf.toString()).isEqualTo(remainder.substring(0, length)); + remainder = remainder.substring(length); + cbuf.clear(); + } + assertThat(reader.read(cbuf)).isEqualTo(-1); + } +} diff --git a/aQute.libg/test/aQute/lib/strings/StringsTest.java b/aQute.libg/test/aQute/lib/strings/StringsTest.java index c56fe4281f..3acf2dc823 100644 --- a/aQute.libg/test/aQute/lib/strings/StringsTest.java +++ b/aQute.libg/test/aQute/lib/strings/StringsTest.java @@ -5,9 +5,13 @@ import java.util.Arrays; import java.util.Collections; +import java.util.Locale; import java.util.regex.Pattern; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; public class StringsTest { @@ -195,4 +199,71 @@ public void testError() { assertThat(Strings.unescape("foo$$", '$')).isNotPresent(); } + @ParameterizedTest(name = "Validate startsWithIgnoreCase {arguments}") + @CsvSource(value = { + "'foobar',''", // + "'foobar','foo'", // + "'foobar','Foo'", // + "'foobar','FOO'", // + "'FooBar','foo'", // + "'FOOBAR','Foo'", // + "'fOObar','FOO'", // + "'foobar','foof'", // + "'foobar','foobar'", // + "'foobar','FooBar'", // + "'foobar','foobarf'" // + }) + @DisplayName("Validate startsWithIgnoreCase") + void starts_with_ignore_case(String target, String prefix) { + boolean expected = target.toLowerCase(Locale.ROOT) + .startsWith(prefix.toLowerCase(Locale.ROOT)); + assertThat(Strings.startsWithIgnoreCase(target, prefix)) + .isEqualTo(expected); + } + + @ParameterizedTest(name = "Validate startsWithIgnoreCase index {arguments}") + @CsvSource(value = { + "'foobar','',2", // + "'foobar','',8", // + "'foobar','oba',2", // + "'foobar','oBa',2", // + "'foobar','OBA',2", // + "'FooBar','oba',2", // + "'FOObar','oBa',2", // + "'FooBar','OBA',2", // + "'foobar','obaf',2", // + "'foobar','bar',3", // + "'FOOBAR','bar',3", // + "'foobar','bar',4", // + "'foobar','bar',8" // + }) + @DisplayName("Validate startsWithIgnoreCase index") + void starts_with_ignore_case_offset(String target, String prefix, int offset) { + boolean expected = target.toLowerCase(Locale.ROOT) + .startsWith(prefix.toLowerCase(Locale.ROOT), offset); + assertThat(Strings.startsWithIgnoreCase(target, prefix, offset)) + .isEqualTo(expected); + } + + @ParameterizedTest(name = "Validate endsWithIgnoreCase {arguments}") + @CsvSource(value = { + "'foobar',''", // + "'foobar','bar'", // + "'foobar','Bar'", // + "'foobar','BAR'", // + "'FooBar','bar'", // + "'FOOBAR','Bar'", // + "'foobAR','BAR'", // + "'foobar','fbar'", // + "'foobar','foobar'", // + "'foobar','FooBar'", // + "'foobar','ffoobar'" // + }) + @DisplayName("Validate endsWithIgnoreCase") + void ends_with_ignore_case(String target, String suffix) { + boolean expected = target.toLowerCase(Locale.ROOT) + .endsWith(suffix.toLowerCase(Locale.ROOT)); + assertThat(Strings.endsWithIgnoreCase(target, suffix)).isEqualTo(expected); + } + } diff --git a/biz.aQute.bnd.exporters/src/aQute/bnd/exporter/subsystem/ContainerType.java b/biz.aQute.bnd.exporters/src/aQute/bnd/exporter/subsystem/ContainerType.java index 5f54160083..6339498006 100644 --- a/biz.aQute.bnd.exporters/src/aQute/bnd/exporter/subsystem/ContainerType.java +++ b/biz.aQute.bnd.exporters/src/aQute/bnd/exporter/subsystem/ContainerType.java @@ -2,10 +2,11 @@ import java.io.File; import java.util.Arrays; -import java.util.Locale; import org.osgi.framework.Constants; -import org.osgi.service.subsystem.SubsystemConstants;; +import org.osgi.service.subsystem.SubsystemConstants; + +import aQute.lib.strings.Strings;; public enum ContainerType { @@ -111,11 +112,9 @@ public static ContainerType byFile(File file) { if (file == null || !file.isFile()) { return null; } - String filename = file.getName() - .toLowerCase(Locale.ROOT); + String filename = file.getName(); return Arrays.stream(ContainerType.values()) - .filter(c -> filename.endsWith(".".concat(c.getExtension() - .toLowerCase(Locale.ROOT)))) + .filter(c -> Strings.endsWithIgnoreCase(filename, ".".concat(c.getExtension()))) .findFirst() .orElse(null); } diff --git a/biz.aQute.bnd/src/aQute/bnd/main/MbrCommand.java b/biz.aQute.bnd/src/aQute/bnd/main/MbrCommand.java index ffdce7b0f2..9355884b6c 100644 --- a/biz.aQute.bnd/src/aQute/bnd/main/MbrCommand.java +++ b/biz.aQute.bnd/src/aQute/bnd/main/MbrCommand.java @@ -21,7 +21,6 @@ import aQute.bnd.repository.maven.provider.MavenBndRepository; import aQute.bnd.version.MavenVersion; import aQute.bnd.version.Version; -import aQute.lib.collections.LineCollection; import aQute.lib.collections.MultiMap; import aQute.lib.getopt.Arguments; import aQute.lib.getopt.Description; @@ -191,10 +190,12 @@ private boolean update(MavenBndRepository repo, Map trans Iterator lc; if (repo.getIndexFile() .isFile()) { - lc = new LineCollection(repo.getIndexFile()); + lc = IO.reader(repo.getIndexFile()) + .lines() + .iterator(); bnd.trace("reading %s", repo.getIndexFile()); } else { - lc = new ArrayList().iterator(); + lc = Collections.emptyIterator(); } for (Iterator i = lc; i.hasNext();) { diff --git a/biz.aQute.bnd/src/aQute/bnd/main/bnd.java b/biz.aQute.bnd/src/aQute/bnd/main/bnd.java index ffda71f4b6..17530921d8 100644 --- a/biz.aQute.bnd/src/aQute/bnd/main/bnd.java +++ b/biz.aQute.bnd/src/aQute/bnd/main/bnd.java @@ -3735,9 +3735,8 @@ public void _copy(CopyOptions options) throws Exception { .getMainAttributes() .entrySet()) { String header = e.getKey() - .toString() - .toLowerCase(Locale.ROOT); - if (header.startsWith("bundle-")) + .toString(); + if (Strings.startsWithIgnoreCase(header, "Bundle-")) continue; if (!isIn(Constants.BUNDLE_SPECIFIC_HEADERS, header)) diff --git a/biz.aQute.bndlib/src/aQute/bnd/build/Project.java b/biz.aQute.bndlib/src/aQute/bnd/build/Project.java index 5aad432e4e..920b456bfe 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/build/Project.java +++ b/biz.aQute.bndlib/src/aQute/bnd/build/Project.java @@ -29,7 +29,6 @@ import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; @@ -983,9 +982,7 @@ public boolean getRunBuilds() { boolean result; String runBuildsStr = getProperty(Constants.RUNBUILDS); if (runBuildsStr == null) - result = !getPropertiesFile().getName() - .toLowerCase(Locale.ROOT) - .endsWith(Constants.DEFAULT_BNDRUN_EXTENSION); + result = !Strings.endsWithIgnoreCase(getPropertiesFile().getName(), Constants.DEFAULT_BNDRUN_EXTENSION); else result = Boolean.parseBoolean(runBuildsStr); return result; diff --git a/biz.aQute.bndlib/src/aQute/bnd/build/model/BndEditModel.java b/biz.aQute.bndlib/src/aQute/bnd/build/model/BndEditModel.java index e35e346f9a..c46afa3bf5 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/build/model/BndEditModel.java +++ b/biz.aQute.bndlib/src/aQute/bnd/build/model/BndEditModel.java @@ -17,7 +17,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; @@ -1008,10 +1007,8 @@ public void setEE(EE ee) { } public void setRunFramework(String clause) { - assert (Constants.RUNFRAMEWORK_SERVICES.equals(clause.toLowerCase(Locale.ROOT) - .trim()) || Constants.RUNFRAMEWORK_NONE.equals( - clause.toLowerCase(Locale.ROOT) - .trim())); + assert (Constants.RUNFRAMEWORK_SERVICES.equalsIgnoreCase(clause.trim()) + || Constants.RUNFRAMEWORK_NONE.equalsIgnoreCase(clause.trim())); String oldValue = getRunFramework(); doSetObject(Constants.RUNFRAMEWORK, oldValue, clause, newlineEscapeFormatter); } diff --git a/biz.aQute.bndlib/src/aQute/bnd/maven/MavenCommand.java b/biz.aQute.bndlib/src/aQute/bnd/maven/MavenCommand.java index 37cd69bef8..08d117f27a 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/maven/MavenCommand.java +++ b/biz.aQute.bndlib/src/aQute/bnd/maven/MavenCommand.java @@ -40,7 +40,6 @@ import aQute.bnd.osgi.Processor; import aQute.bnd.osgi.Resource; import aQute.bnd.util.home.Home; -import aQute.lib.collections.LineCollection; import aQute.lib.io.IO; import aQute.lib.settings.Settings; import aQute.lib.utf8properties.UTF8Properties; @@ -145,11 +144,9 @@ private void settings() throws FileNotFoundException, Exception { error("There is no settings file at '%s'", settings.getAbsolutePath()); return; } - try (LineCollection lc = new LineCollection(IO.reader(settings))) { - while (lc.hasNext()) { - System.err.println(lc.next()); - } - } + IO.reader(settings) + .lines() + .forEachOrdered(System.err::println); } /** diff --git a/biz.aQute.bndlib/src/aQute/bnd/osgi/Domain.java b/biz.aQute.bndlib/src/aQute/bnd/osgi/Domain.java index dfeafe7f37..371c313b6f 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/osgi/Domain.java +++ b/biz.aQute.bndlib/src/aQute/bnd/osgi/Domain.java @@ -23,7 +23,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.Iterator; -import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; @@ -44,6 +43,7 @@ import aQute.lib.converter.Converter; import aQute.lib.io.ByteBufferInputStream; import aQute.lib.io.IO; +import aQute.lib.strings.Strings; import aQute.lib.utf8properties.UTF8Properties; import aQute.service.reporter.Reporter; @@ -518,9 +518,7 @@ public static Domain domain(File file) throws IOException { return domain; } } catch (ZipException e) { - if (file.getName() - .toLowerCase(Locale.ROOT) - .endsWith(".jar")) + if (Strings.endsWithIgnoreCase(file.getName(), ".jar")) throw new ZipException("invalid jar format: " + file); } diff --git a/biz.aQute.bndlib/src/aQute/bnd/osgi/OSInformation.java b/biz.aQute.bndlib/src/aQute/bnd/osgi/OSInformation.java index e1f78c6d06..be85917554 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/osgi/OSInformation.java +++ b/biz.aQute.bndlib/src/aQute/bnd/osgi/OSInformation.java @@ -355,8 +355,7 @@ public static OSNameVersion getOperatingSystemAliases(String sysPropOsName, Stri nc.osversion = convertUnixKernelVersion(sysPropOsVersion); nc.osnames = "MacOSX,Mac OS X"; return nc; - } else if (sysPropOsName.toLowerCase(Locale.ROOT) - .startsWith("linux")) { + } else if (Strings.startsWithIgnoreCase(sysPropOsName, "linux")) { nc.osversion = convertUnixKernelVersion(sysPropOsVersion); nc.osnames = "Linux"; } else if (sysPropOsName.startsWith("Solaris")) { diff --git a/biz.aQute.bndlib/src/aQute/bnd/osgi/Processor.java b/biz.aQute.bndlib/src/aQute/bnd/osgi/Processor.java index f670ee9645..44a3c47ba7 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/osgi/Processor.java +++ b/biz.aQute.bndlib/src/aQute/bnd/osgi/Processor.java @@ -871,9 +871,7 @@ public void doIncludeFile(File file, boolean overwrite, Properties target, Strin } updateModified(file.lastModified(), file.toString()); Properties sub; - if (file.getName() - .toLowerCase(Locale.ROOT) - .endsWith(".mf")) { + if (Strings.endsWithIgnoreCase(file.getName(), ".mf")) { try (InputStream in = IO.stream(file)) { sub = getManifestAsProperties(in); } diff --git a/bndtools.core/src/bndtools/editor/contents/GeneralInfoPart.java b/bndtools.core/src/bndtools/editor/contents/GeneralInfoPart.java index be30a29843..106f5b0642 100644 --- a/bndtools.core/src/bndtools/editor/contents/GeneralInfoPart.java +++ b/bndtools.core/src/bndtools/editor/contents/GeneralInfoPart.java @@ -54,6 +54,7 @@ import aQute.bnd.build.model.BndEditModel; import aQute.bnd.exceptions.Exceptions; +import aQute.lib.strings.Strings; import bndtools.Plugin; import bndtools.UIConstants; import bndtools.editor.utils.ToolTips; @@ -327,9 +328,7 @@ protected List doGenerateProposals(String contents, int positi @Override protected boolean match(String contents, int position, IContentProposal proposal) { String prefix = contents.substring(0, position); - return ((JavaTypeContentProposal) proposal).getTypeName() - .toLowerCase(Locale.ROOT) - .startsWith(prefix.toLowerCase(Locale.ROOT)); + return Strings.startsWithIgnoreCase(((JavaTypeContentProposal) proposal).getTypeName(), prefix); } } } diff --git a/bndtools.core/src/bndtools/refactor/PkgRenameParticipant.java b/bndtools.core/src/bndtools/refactor/PkgRenameParticipant.java index d02a39a5ba..2625cd49d2 100644 --- a/bndtools.core/src/bndtools/refactor/PkgRenameParticipant.java +++ b/bndtools.core/src/bndtools/refactor/PkgRenameParticipant.java @@ -6,7 +6,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -48,6 +47,7 @@ import aQute.bnd.properties.IRegion; import aQute.bnd.properties.LineType; import aQute.bnd.properties.PropertiesLineReader; +import aQute.lib.strings.Strings; public class PkgRenameParticipant extends RenameParticipant implements ISharableParticipant { private static final ILogger logger = Logger @@ -103,9 +103,7 @@ public Change createChange(IProgressMonitor pm) throws CoreException, OperationC return true; } - if (!((proxy.getType() == IResource.FILE) && proxy.getName() - .toLowerCase(Locale.ROOT) - .endsWith(".bnd"))) { + if (!((proxy.getType() == IResource.FILE) && Strings.endsWithIgnoreCase(proxy.getName(), ".bnd"))) { return false; } diff --git a/bndtools.core/src/bndtools/utils/ClassFolderFilter.java b/bndtools.core/src/bndtools/utils/ClassFolderFilter.java index 864a16c0e9..cbf01d6bd8 100644 --- a/bndtools.core/src/bndtools/utils/ClassFolderFilter.java +++ b/bndtools.core/src/bndtools/utils/ClassFolderFilter.java @@ -1,7 +1,5 @@ package bndtools.utils; -import java.util.Locale; - import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; @@ -10,6 +8,8 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerFilter; +import aQute.lib.strings.Strings; + public class ClassFolderFilter extends ViewerFilter { @Override @@ -21,9 +21,7 @@ public boolean select(Viewer viewer, Object parentElement, Object element) { try { IResource[] members = ((IContainer) element).members(); for (IResource member : members) { - if (member instanceof IFile && member.getName() - .toLowerCase(Locale.ENGLISH) - .endsWith(".class")) { + if (member instanceof IFile && Strings.endsWithIgnoreCase(member.getName(), ".class")) { return true; } else if (member instanceof IContainer) { boolean memberResult = select(viewer, element, member); diff --git a/bndtools.core/src/bndtools/views/resolution/ResolutionView.java b/bndtools.core/src/bndtools/views/resolution/ResolutionView.java index 6adc7b9360..a272cde8c4 100644 --- a/bndtools.core/src/bndtools/views/resolution/ResolutionView.java +++ b/bndtools.core/src/bndtools/views/resolution/ResolutionView.java @@ -6,7 +6,6 @@ import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Set; @@ -71,6 +70,7 @@ import aQute.bnd.osgi.Clazz; import aQute.bnd.unmodifiable.Sets; import aQute.lib.io.IO; +import aQute.lib.strings.Strings; import bndtools.Plugin; import bndtools.model.repo.RepositoryResourceElement; import bndtools.model.resolution.CapReqMapContentProvider; @@ -151,13 +151,9 @@ private boolean setLoaders(Set newLoaders) { private CapReqLoader getLoaderForFile(File file) { CapReqLoader loader; - if (file.getName() - .toLowerCase(Locale.ROOT) - .endsWith(".bnd")) { + if (Strings.endsWithIgnoreCase(file.getName(), ".bnd")) { loader = new BndFileCapReqLoader(file); - } else if (file.getName() - .toLowerCase(Locale.ROOT) - .endsWith(".jar")) { + } else if (Strings.endsWithIgnoreCase(file.getName(), ".jar")) { loader = new JarFileCapReqLoader(file); } else { loader = null;