Skip to content

Commit 6c62ede

Browse files
ahornaceVladimir Kotal
authored andcommitted
Leverage util methods from apache commons and java 11
1 parent 33a219c commit 6c62ede

30 files changed

+117
-517
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/Ctags.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, 2020, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.analysis;
@@ -44,12 +44,12 @@
4444
import java.util.logging.Level;
4545
import java.util.logging.Logger;
4646

47+
import org.apache.commons.lang3.SystemUtils;
4748
import org.opengrok.indexer.configuration.RuntimeEnvironment;
4849
import org.opengrok.indexer.index.IndexerParallelizer;
4950
import org.opengrok.indexer.logger.LoggerFactory;
5051
import org.opengrok.indexer.util.Executor;
5152
import org.opengrok.indexer.util.IOUtils;
52-
import org.opengrok.indexer.util.PlatformUtils;
5353
import org.opengrok.indexer.util.SourceSplitter;
5454

5555
/**
@@ -210,7 +210,7 @@ private void initialize() {
210210
}
211211

212212
private void run() throws IOException {
213-
String commandStr = Executor.escapeForShell(command, false, PlatformUtils.isWindows());
213+
String commandStr = Executor.escapeForShell(command, false, SystemUtils.IS_OS_WINDOWS);
214214
LOGGER.log(Level.FINE, "Executing ctags command [{0}]", commandStr);
215215

216216
ProcessBuilder processBuilder = new ProcessBuilder(command);

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/hcl/HCLLexer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void hereOp(String capture) throws IOException {
9494
}
9595

9696
// Trim any whitespace, which is allowed by HCL after the HERE op.
97-
remaining = remaining.replaceFirst("^\\s+", "");
97+
remaining = remaining.stripLeading();
9898

9999
Matcher m = HERE_TERMINATOR_MATCH.matcher(remaining);
100100
if (!m.find()) {
@@ -128,7 +128,7 @@ public boolean maybeHereStart() throws IOException {
128128
* @return true if the Here state ended
129129
*/
130130
public boolean maybeHereEnd(String capture) throws IOException {
131-
String trimmed = capture.replaceFirst("^\\s+", "");
131+
String trimmed = capture.stripLeading();
132132
HereDocSettings settings = dataHead.hereSettings.peek();
133133
assert settings != null;
134134

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/perl/PerlLexer.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public void qop(boolean doWrite, String capture, int namelength,
212212
}
213213

214214
String postop = postboundary.substring(qopname.length());
215-
String ltpostop = postop.replaceFirst("^\\s+", "");
215+
String ltpostop = postop.stripLeading();
216216
char opc = ltpostop.charAt(0);
217217
setEndQuoteChar(opc);
218218
setState(ltpostop, nointerp);
@@ -291,7 +291,7 @@ public void hqopPunc(String capture) throws IOException {
291291
// `preceding' is everything before the '/'; 'lede' is the initial part
292292
// before any whitespace; and `intervening' is any whitespace.
293293
String preceding = capture.substring(0, capture.length() - 1);
294-
String lede = preceding.replaceFirst("\\s+$", "");
294+
String lede = preceding.stripTrailing();
295295
String intervening = preceding.substring(lede.length());
296296

297297
// OK to pass a fake "m/" with doWrite=false
@@ -312,7 +312,7 @@ public void hqopSymbol(String capture) throws IOException {
312312
// `preceding' is everything before the '/'; 'lede' is the initial part
313313
// before any whitespace; and `intervening' is any whitespace.
314314
String preceding = capture.substring(0, capture.length() - 1);
315-
String lede = preceding.replaceFirst("\\s+$", "");
315+
String lede = preceding.stripTrailing();
316316
String intervening = preceding.substring(lede.length());
317317

318318
// OK to pass a fake "m/" with doWrite=false
@@ -374,7 +374,7 @@ public void hop(String capture) throws IOException {
374374
indented = true;
375375
remaining = remaining.substring(1);
376376
}
377-
remaining = remaining.replaceFirst("^\\s+", "");
377+
remaining = remaining.stripLeading();
378378
char c = remaining.charAt(0);
379379
switch (c) {
380380
case '\'':
@@ -442,7 +442,7 @@ public boolean maybeStartHere() throws IOException {
442442
* @return true if the quote state ended
443443
*/
444444
public boolean maybeEndHere(String capture) throws IOException {
445-
String trimmed = capture.replaceFirst("^\\s+", "");
445+
String trimmed = capture.stripLeading();
446446
HereDocSettings settings = hereSettings.peek();
447447

448448
boolean didZspan = false;
@@ -489,7 +489,7 @@ public void sigilID(String capture) throws IOException {
489489
}
490490

491491
String postsigil = capture.substring(1);
492-
String id = postsigil.replaceFirst("^\\s+", "");
492+
String id = postsigil.stripLeading();
493493
String s0 = postsigil.substring(0, postsigil.length() - id.length());
494494

495495
int ohnooo;
@@ -544,13 +544,13 @@ public void bracedSigilID(String capture) throws IOException {
544544
String sigil = capture.substring(0, 1);
545545
String rpunc = capture.substring(capture.length() - 1);
546546
String interior0 = capture.substring(1, capture.length() - 1);
547-
String ltinterior0 = interior0.replaceFirst("^\\s+", "");
547+
String ltinterior0 = interior0.stripLeading();
548548
String s0 = interior0.substring(0, interior0.length() -
549549
ltinterior0.length());
550550

551551
String lpunc = ltinterior0.substring(0, 1);
552552
String interior1 = ltinterior0.substring(1);
553-
String ltinterior1 = interior1.replaceFirst("^\\s+", "");
553+
String ltinterior1 = interior1.stripLeading();
554554
String s1 = interior1.substring(0, interior1.length() -
555555
ltinterior1.length());
556556

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/ruby/RubyLexer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public void hqopPunc(String capture) throws IOException {
215215
// `preceding' is everything before the '/'; 'lede' is the initial part
216216
// before any whitespace; and `intervening' is any whitespace.
217217
String preceding = capture.substring(0, capture.length() - 1);
218-
String lede = preceding.replaceFirst("\\s+$", "");
218+
String lede = preceding.stripTrailing();
219219
String intervening = preceding.substring(lede.length());
220220

221221
// OK to pass a fake "m/" with doWrite=false
@@ -240,7 +240,7 @@ public void hqopSymbol(String capture) throws IOException {
240240
// `preceding' is everything before the '/'; 'lede' is the initial part
241241
// before any whitespace; and `intervening' is any whitespace.
242242
String preceding = capture.substring(0, capture.length() - 1);
243-
String lede = preceding.replaceFirst("\\s+$", "");
243+
String lede = preceding.stripTrailing();
244244
String intervening = preceding.substring(lede.length());
245245

246246
// OK to pass a fake "m/" with doWrite=false
@@ -365,7 +365,7 @@ public boolean maybeStartHere() throws IOException {
365365
* @return true if the quote state ended
366366
*/
367367
public boolean maybeEndHere(String capture) throws IOException {
368-
String trimmed = capture.replaceFirst("^\\s+", "");
368+
String trimmed = capture.stripLeading();
369369
HereDocSettings settings = dHead.hereSettings.peek();
370370
assert settings != null;
371371

opengrok-indexer/src/main/java/org/opengrok/indexer/history/RazorHistoryParser.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import java.util.regex.Matcher;
3636
import java.util.regex.Pattern;
3737
import org.opengrok.indexer.logger.LoggerFactory;
38-
import org.opengrok.indexer.util.StringUtils;
3938

4039
/**
4140
* A History Parser for Razor.
@@ -100,7 +99,7 @@ protected History parseContents(BufferedReader contents) throws IOException {
10099

101100
parseDebug("Processing '" + line + "'");
102101

103-
if (StringUtils.isOnlyWhitespace(line)) {
102+
if (line.isBlank()) {
104103

105104
if (entry != null && entry.getDate() != null) {
106105
entries.add(entry);

opengrok-indexer/src/main/java/org/opengrok/indexer/index/Indexer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import java.util.logging.Logger;
5959
import java.util.stream.Collectors;
6060

61+
import org.apache.commons.lang3.SystemUtils;
6162
import org.opengrok.indexer.Info;
6263
import org.opengrok.indexer.Metrics;
6364
import org.opengrok.indexer.analysis.AnalyzerGuru;
@@ -81,7 +82,6 @@
8182
import org.opengrok.indexer.util.Executor;
8283
import org.opengrok.indexer.util.HostUtil;
8384
import org.opengrok.indexer.util.OptionParser;
84-
import org.opengrok.indexer.util.PlatformUtils;
8585
import org.opengrok.indexer.util.Statistics;
8686

8787
/**
@@ -1237,7 +1237,7 @@ private static void exitWithHelp() {
12371237

12381238
private static String getCtagsCommand() {
12391239
Ctags ctags = CtagsUtil.newInstance(env);
1240-
return Executor.escapeForShell(ctags.getArgv(), true, PlatformUtils.isWindows());
1240+
return Executor.escapeForShell(ctags.getArgv(), true, SystemUtils.IS_OS_WINDOWS);
12411241
}
12421242

12431243
private enum HelpMode {

opengrok-indexer/src/main/java/org/opengrok/indexer/index/NumLinesLOCAccessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
package org.opengrok.indexer.index;
2424

25+
import org.apache.commons.lang3.math.NumberUtils;
2526
import org.apache.lucene.document.Document;
2627
import org.apache.lucene.document.Field;
2728
import org.apache.lucene.document.StoredField;
@@ -41,7 +42,6 @@
4142
import org.opengrok.indexer.analysis.NullableNumLinesLOC;
4243
import org.opengrok.indexer.analysis.NumLinesLOC;
4344
import org.opengrok.indexer.search.QueryBuilder;
44-
import org.opengrok.indexer.util.NumberUtil;
4545

4646
import java.io.File;
4747
import java.io.IOException;
@@ -169,8 +169,8 @@ private void updateDocumentData(IndexWriter writer, IndexSearcher searcher,
169169
if (docID != null) {
170170
Document doc = searcher.doc(docID);
171171
if (isAggregatingDeltas) {
172-
extantLines = NumberUtil.tryParseLongPrimitive(doc.get(QueryBuilder.NUML));
173-
extantLOC = NumberUtil.tryParseLongPrimitive(doc.get(QueryBuilder.LOC));
172+
extantLines = NumberUtils.toLong(doc.get(QueryBuilder.NUML));
173+
extantLOC = NumberUtils.toLong(doc.get(QueryBuilder.LOC));
174174
}
175175
writer.deleteDocuments(new Term(QueryBuilder.D, aggregate.getPath()));
176176
}

opengrok-indexer/src/main/java/org/opengrok/indexer/util/BooleanUtil.java

Lines changed: 0 additions & 71 deletions
This file was deleted.

opengrok-indexer/src/main/java/org/opengrok/indexer/util/ClassUtil.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.logging.Logger;
3636

3737
import com.fasterxml.jackson.databind.ObjectMapper;
38+
import org.apache.commons.lang3.BooleanUtils;
3839
import org.opengrok.indexer.logger.LoggerFactory;
3940

4041
/**
@@ -87,23 +88,13 @@ private static Object stringToObject(String fieldName, Class<?> c, String value)
8788
* datatypes</a>.
8889
*/
8990
if (paramClass.equals("boolean") || paramClass.equals(Boolean.class.getName())) {
90-
if (!BooleanUtil.isBoolean(value)) {
91+
Boolean parsedValue = BooleanUtils.toBooleanObject(value);
92+
if (parsedValue == null) {
9193
throw new IOException(String.format("Unsupported type conversion from String to a boolean for name \"%s\" -"
9294
+ " got \"%s\" - allowed values are [false, off, 0, true, on, 1].",
9395
paramClass, value));
9496
}
95-
boolean boolValue = Boolean.parseBoolean(value);
96-
if (!boolValue) {
97-
/*
98-
* The Boolean.valueOf() returns true only for "true" case
99-
* insensitive so now we have either the false values or
100-
* "on" or "1". These are convenient shortcuts for "on", "1"
101-
* to be interpreted as booleans.
102-
*/
103-
boolValue = value.equalsIgnoreCase("on");
104-
boolValue = boolValue || value.equals("1");
105-
}
106-
v = boolValue;
97+
v = parsedValue;
10798
} else if (paramClass.equals("short") || paramClass.equals(Short.class.getName())) {
10899
v = Short.valueOf(value);
109100
} else if (paramClass.equals("int") || paramClass.equals(Integer.class.getName())) {

opengrok-indexer/src/main/java/org/opengrok/indexer/util/CtagsUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package org.opengrok.indexer.util;
2525

26+
import org.apache.commons.lang3.SystemUtils;
2627
import org.opengrok.indexer.analysis.AnalyzerGuru;
2728
import org.opengrok.indexer.analysis.Ctags;
2829
import org.opengrok.indexer.configuration.RuntimeEnvironment;
@@ -99,7 +100,7 @@ public static void deleteTempFiles() {
99100
Set<String> dirs = new HashSet<>(Arrays.asList(System.getProperty("java.io.tmpdir"),
100101
System.getenv("TMPDIR"), System.getenv("TMP")));
101102

102-
if (PlatformUtils.isUnix()) {
103+
if (SystemUtils.IS_OS_UNIX) {
103104
// hard-coded TMPDIR in Universal Ctags on Unix.
104105
dirs.add("/tmp");
105106
}

0 commit comments

Comments
 (0)