Skip to content

Commit

Permalink
[JENKINS-65155] The "java is not in the path" warning is show even th…
Browse files Browse the repository at this point in the history
…ough java is in the path (#218)

* [JENKINS-65155] The "java is not in the path" warning is show even though java is in the path

* Update src/main/java/hudson/plugins/sshslaves/SSHLauncher.java

* Update src/main/java/hudson/plugins/sshslaves/SSHLauncher.java
  • Loading branch information
kuisathaverat authored Apr 9, 2021
1 parent 79ba029 commit c51daff
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ protected String resolveJava() throws InterruptedException, IOException {
try {
return checkJavaVersion(listener, javaCommand);
} catch (IOException e) {
if(!"java".equalsIgnoreCase(javaCommand)){
LOGGER.log(WARNING, "Java is not in the PATH nor configured with the javaPath setting,"
+ " Jenkins will try to guess where is Java,"
+ "this guess will be remove in the future.");
}
LOGGER.log(FINE, "Failed to check the Java version",e);
// try the next one
}
Expand Down
28 changes: 25 additions & 3 deletions src/main/java/hudson/plugins/sshslaves/SSHLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.trilead.ssh2.ChannelCondition;
import com.trilead.ssh2.Connection;
import com.trilead.ssh2.SCPClient;
import com.trilead.ssh2.SFTPv3Client;
import com.trilead.ssh2.SFTPv3FileAttributes;
import com.trilead.ssh2.ServerHostKeyVerifier;
import com.trilead.ssh2.Session;
Expand Down Expand Up @@ -101,11 +100,11 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;

import static hudson.Util.fixEmpty;
import static java.util.logging.Level.WARNING;

/**
* A computer launcher that tries to start a linux agent by opening an SSH connection and trying to find java.
Expand Down Expand Up @@ -448,6 +447,7 @@ public Boolean call() throws InterruptedException {
if (StringUtils.isNotBlank(javaPath)) {
java = expandExpression(computer, javaPath);
} else {
checkJavaIsInPath(listener);
//FIXME deprecated on 2020-12-10, it will removed after 2021-09-01
JavaVersionChecker javaVersionChecker = new JavaVersionChecker(computer, listener, getJvmOptions(),
connection);
Expand Down Expand Up @@ -519,7 +519,29 @@ public Boolean call() throws InterruptedException {
}
}

/**
/**
* try to run the Java command in the PATH ad report its version.
* @param listener lister to print the output of the java command.
*/
private void checkJavaIsInPath(TaskListener listener) {
String msg = "Java is not in the PATH nor configured with the javaPath setting,"
+ " Jenkins will try to guess where is Java, "
+ "this guess will be removed in the future. :"
+ getDescriptor().getDisplayName();
int ret = 0;
try {
listener.getLogger().println("Checking Java version in the PATH");
ret = connection.exec("java -version", listener.getLogger());
} catch (Exception e){
ret = -1;
}
if(ret != 0){
LOGGER.log(WARNING, msg);
listener.getLogger().println(msg);
}
}

/**
* Called to terminate the SSH connection. Used liberally when we back out from an error.
*/
private void cleanupConnection(TaskListener listener) {
Expand Down

0 comments on commit c51daff

Please sign in to comment.