Skip to content

Commit

Permalink
[MJLINK-84] Remove remaining commons-lang3 (#211)
Browse files Browse the repository at this point in the history
* [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: #167

* use trim().isEmpty() vs isBlank() (j8 compt)

* address comments

* remove lang3 dep from pom.xml
  • Loading branch information
matriv authored Dec 19, 2024
1 parent 5af2179 commit ccc252b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,6 @@
<version>3.6.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
import java.util.Optional;
import java.util.stream.Collectors;

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;
Expand Down Expand Up @@ -131,15 +129,15 @@ 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);

if (jLinkExe.isDirectory()) {
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");
}

Expand All @@ -160,9 +158,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().trim();
output = output.isEmpty() ? null : '\n' + output;

if (exitCode != 0) {

Expand All @@ -176,7 +173,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().trim().isEmpty()) {
msg.append(" - ").append(err.getOutput());
}
msg.append('\n');
Expand All @@ -197,4 +194,17 @@ private int executeCommand(Commandline cmd) throws MojoExecutionException {
throw new MojoExecutionException("Unable to execute jlink command: " + e.getMessage(), e);
}
}

private static boolean isOSWindows() {
try {
String osName = System.getProperty("os.name");
if (osName == null) {
return false;
}
return osName.startsWith("Windows");
} catch (final SecurityException ex) {
// we are not allowed to look at this property
return false;
}
}
}

0 comments on commit ccc252b

Please sign in to comment.