TW-50733 specify full path to java in credential helper
authorDmitry Neverov <dmitry.neverov@gmail.com>
Wed, 12 Jul 2017 12:30:10 +0000 (14:30 +0200)
committerDmitry Neverov <dmitry.neverov@gmail.com>
Wed, 12 Jul 2017 12:30:10 +0000 (14:30 +0200)
To make it work when java is not in the $PATH

git-agent/src/META-INF/credentials-helper.bat
git-agent/src/META-INF/credentials-helper.sh
git-agent/src/jetbrains/buildServer/buildTriggers/vcs/git/agent/command/ScriptGen.java

index 36d1f7b04f489193d71bf2cebbc959e637b5ba31..62ce0ff3933021c14c2fd9b18a912b783c38e08d 100644 (file)
@@ -2,7 +2,7 @@
 
 if ""%1"" == ""erase"" goto erase
 
-java -cp {CREDENTIALS_CLASSPATH} {CREDENTIALS_CLASS} %*
+{JAVA} -cp {CREDENTIALS_CLASSPATH} {CREDENTIALS_CLASS} %*
 goto end
 
 :erase
index aa2a01894ba16b93b6c4cfba7d19bbdbe709f32c..01ac103200fd741b297e8b6ddbbd06d58ee8b3ec 100644 (file)
@@ -5,4 +5,4 @@ if [ "$1" = "erase" ]; then
   exit;
 fi
 
-java -cp '{CREDENTIALS_CLASSPATH}' {CREDENTIALS_CLASS} $*
\ No newline at end of file
+{JAVA} -cp '{CREDENTIALS_CLASSPATH}' {CREDENTIALS_CLASS} $*
\ No newline at end of file
index 435817a5311d40202dd15006d8ddf6fc402d816c..e2ad01aafcf96f5e47370a6606e2dc908a0db3a6 100644 (file)
@@ -21,6 +21,7 @@ import jetbrains.buildServer.agent.ClasspathUtil;
 import jetbrains.buildServer.buildTriggers.vcs.git.AuthSettings;
 import jetbrains.buildServer.buildTriggers.vcs.git.agent.CredentialsHelper;
 import jetbrains.buildServer.util.FileUtil;
+import jetbrains.buildServer.util.StringUtil;
 import org.jetbrains.annotations.NotNull;
 
 import java.io.*;
@@ -54,6 +55,12 @@ public abstract class ScriptGen {
       if (templateStream == null)
         throw new IOException("Cannot read script template " + template);
       String script = StreamUtil.readText(templateStream);
+      String javaPath = "java";
+      String javaHome = System.getProperty("java.home");
+      if (StringUtil.isNotEmpty(javaHome)) {
+        javaPath = "\"" + javaHome + File.separatorChar + "bin" + File.separatorChar + "java\"";
+      }
+      script = script.replace("{JAVA}", javaPath);
       script = script.replace("{CREDENTIALS_SCRIPT}", result.getCanonicalPath());
       script = script.replace("{CREDENTIALS_CLASSPATH}", ClasspathUtil.composeClasspath(new Class[]{CredentialsHelper.class}, null, null));
       script = script.replace("{CREDENTIALS_CLASS}", CredentialsHelper.class.getName());