From e8795168aebcb95ad3a290dddc165329ba8c7892 Mon Sep 17 00:00:00 2001 From: Andrey Turbanov Date: Sat, 5 Oct 2024 23:12:53 +0300 Subject: [PATCH] AbstractCompilerMojo: Replace StringBuilder with String.join() Initialize patchModules = new LinkedHashSet with capacity. Signed-off-by: Sergey Ponomarev --- .../plugin/compiler/AbstractCompilerMojo.java | 27 ++++--------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java index 8a5126e6..83dd698b 100644 --- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java +++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java @@ -1013,15 +1013,9 @@ public void execute() { } String[] cl = compiler.createCommandLine(compilerConfiguration); - if (cl != null && cl.length > 0) { - StringBuilder sb = new StringBuilder(); - sb.append(cl[0]); - for (int i = 1; i < cl.length; i++) { - sb.append(" "); - sb.append(cl[i]); - } + if (cl != null && cl.length > 0 && getLog().isDebugEnabled()) { getLog().debug("Command line options:"); - getLog().debug(sb.toString()); + getLog().debug(String.join(" ", cl)); } } catch (CompilerException ce) { getLog().debug("Compilation error", ce); @@ -1058,13 +1052,12 @@ public void execute() { String[] values = value.split("="); - StringBuilder patchModule = new StringBuilder(values[0]); - patchModule.append('='); + String patchModule = values[0] + "="; - Set patchModules = new LinkedHashSet<>(); Set sourceRoots = new HashSet<>(getCompileSourceRoots()); String[] files = values[1].split(PS); + Set patchModules = new LinkedHashSet<>(files.length, 1); for (String file : files) { Path filePath = Paths.get(file); @@ -1090,19 +1083,9 @@ public void execute() { } } - StringBuilder sb = new StringBuilder(); - if (!patchModules.isEmpty()) { - for (String mod : patchModules) { - if (sb.length() > 0) { - sb.append(", "); - } - // use 'invalid' separator to ensure values are transformed - sb.append(mod); - } - jpmsLines.add("--patch-module"); - jpmsLines.add(patchModule + sb.toString()); + jpmsLines.add(patchModule + String.join(", ", patchModules)); } } }