Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MJLINK-84] Remove remaining commons-lang3 #211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -127,15 +125,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 @@ -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) {

Expand All @@ -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');
Expand All @@ -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");
}
}