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

JavaExecCmdUtil: use Paths.get to join file paths #454

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -20,6 +20,7 @@
package org.evosuite.runtime.util;

import java.io.File;
import java.nio.file.Paths;
import java.util.Optional;

/**
Expand All @@ -45,19 +46,14 @@ private JavaExecCmdUtil() {
* @apiNote under maven java.home property is ${JAVA_HOME}/jre/bin/java
*/
public static String getJavaBinExecutablePath(final boolean isFullOriginalJavaExecRequired) {
final String separator = System.getProperty("file.separator");
final String JAVA_CMD =
System.getProperty("java.home") + separator + "bin" + separator + "java";
final String JAVA_CMD = Paths.get(System.getProperty("java.home"), "bin", "java").toString();
Comment on lines -48 to +49
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jose: I have amended the commit to remove the unused separator variable.


return getJavaHomeEnv()
.map(javaHomeEnvVar ->
new File(
javaHomeEnvVar + File.separatorChar + "bin" + File.separatorChar + "java" +
getOsName()
.filter(osName -> osName.toLowerCase().contains("windows"))
.map(osName -> ".exe")
.orElse("")
)
Paths.get(javaHomeEnvVar, "bin", "java", getOsName()
.filter(osName -> osName.toLowerCase().contains("windows"))
.map(osName -> ".exe")
.orElse("")).toFile()
)
.filter(File::exists)
.map(File::getPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.evosuite.runtime.util;

import java.nio.file.Paths;
import org.apache.commons.lang3.StringUtils;
import org.hamcrest.core.IsEqual;
import org.junit.Before;
Expand Down Expand Up @@ -100,7 +101,7 @@ public void unixNewBehavior() {
// set correct java_home and get real path to java
environmentVariables.set("JAVA_HOME", JAVA_HOME_SYSTEM);
assertThat(JavaExecCmdUtil.getJavaBinExecutablePath(),
IsEqual.equalTo(JAVA_HOME_SYSTEM + SEPARATOR + "bin" + SEPARATOR + "java"));
IsEqual.equalTo(Paths.get(JAVA_HOME_SYSTEM, "bin", "java").toString()));
}
);
}
Expand Down