From 401cdb55f513336b650023005c24a6a26939c51a Mon Sep 17 00:00:00 2001 From: Marios Trivyzas Date: Tue, 30 Jul 2024 11:18:12 +0300 Subject: [PATCH] [MJLINK-84] Remove remaining commons-lang3 Dependency to commons-lang3 has been removed earlier on, but still there were usages of `StringUtils` & `SystemUtils` which lead to the plugin requiring the dependency to be added explicitly when used. Follows: https://github.com/apache/maven-jlink-plugin/pull/167 --- .../jlink/AbstractJLinkToolchainExecutor.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkToolchainExecutor.java b/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkToolchainExecutor.java index 15fd7db8..059842b8 100644 --- a/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkToolchainExecutor.java +++ b/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkToolchainExecutor.java @@ -42,8 +42,6 @@ import java.util.NoSuchElementException; import java.util.Optional; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.SystemUtils; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.shared.utils.cli.CommandLineException; @@ -127,7 +125,7 @@ private String getJLinkExecutable() { } // TODO: Check if there exist a more elegant way? - String jLinkCommand = "jlink" + (SystemUtils.IS_OS_WINDOWS ? ".exe" : ""); + String jLinkCommand = "jlink" + (isOSWindows() ? ".exe" : ""); File jLinkExe = new File(jLinkExecutable); @@ -135,7 +133,7 @@ private String getJLinkExecutable() { jLinkExe = new File(jLinkExe, jLinkCommand); } - if (SystemUtils.IS_OS_WINDOWS && jLinkExe.getName().indexOf('.') < 0) { + if (isOSWindows() && jLinkExe.getName().indexOf('.') < 0) { jLinkExe = new File(jLinkExe.getPath() + ".exe"); } @@ -156,9 +154,8 @@ private int executeCommand(Commandline cmd) throws MojoExecutionException { try { int exitCode = CommandLineUtils.executeCommandLine(cmd, out, err); - String output = StringUtils.isEmpty(out.getOutput()) - ? null - : '\n' + out.getOutput().trim(); + String output = + out.getOutput().isBlank() ? null : '\n' + out.getOutput().trim(); if (exitCode != 0) { @@ -172,7 +169,7 @@ private int executeCommand(Commandline cmd) throws MojoExecutionException { StringBuilder msg = new StringBuilder("\nExit code: "); msg.append(exitCode); - if (StringUtils.isNotEmpty(err.getOutput())) { + if (!err.getOutput().isBlank()) { msg.append(" - ").append(err.getOutput()); } msg.append('\n'); @@ -193,4 +190,18 @@ private int executeCommand(Commandline cmd) throws MojoExecutionException { throw new MojoExecutionException("Unable to execute jlink command: " + e.getMessage(), e); } } + + private static boolean isOSWindows() { + String osName; + try { + osName = System.getProperty("os.name"); + } catch (final SecurityException ex) { + // we are not allowed to look at this property + return false; + } + if (osName == null) { + return false; + } + return osName.startsWith("Windows"); + } }