TW-50332 use system's line-endings in credential helper script
authorDmitry Neverov <dmitry.neverov@gmail.com>
Tue, 13 Jun 2017 15:16:57 +0000 (17:16 +0200)
committerDmitry Neverov <dmitry.neverov@gmail.com>
Tue, 13 Jun 2017 15:18:09 +0000 (17:18 +0200)
git-agent/src/jetbrains/buildServer/buildTriggers/vcs/git/agent/AgentPluginConfig.java
git-agent/src/jetbrains/buildServer/buildTriggers/vcs/git/agent/PluginConfigImpl.java
git-agent/src/jetbrains/buildServer/buildTriggers/vcs/git/agent/UpdaterImpl.java
git-agent/src/jetbrains/buildServer/buildTriggers/vcs/git/agent/command/ScriptGen.java

index 0c766cc3c0de5a4054df8f10511ea3859a396462..57e801d2dccf6f0eb5dd8e6fa70a58e3f91fcba2 100644 (file)
@@ -64,6 +64,8 @@ public interface AgentPluginConfig extends PluginConfig {
 
   boolean isExcludeUsernameFromHttpUrl();
 
+  boolean isCleanCredHelperScript();
+
   /**
    * Defines how progress output from git commands is written into build log
    */
index 2149bf7a50e403c5e1f52a25e834134f922cf26c..0c99fd5b7c17c727455715882b2ef9e4c00223cf 100644 (file)
@@ -49,6 +49,7 @@ public class PluginConfigImpl implements AgentPluginConfig {
   public static final String FETCH_ALL_HEADS = "teamcity.git.fetchAllHeads";
   public static final String FETCH_TAGS = "teamcity.git.fetchTags";
   public static final String EXCLUDE_USERNAME_FROM_HTTP_URL = "teamcity.git.excludeUsernameFromHttpUrl";
+  public static final String CLEAN_CRED_HELPER_SCRIPT = "teamcity.git.cleanCredHelperScript";
 
   private final BuildAgentConfiguration myAgentConfig;
   private final AgentRunningBuild myBuild;
@@ -247,6 +248,12 @@ public class PluginConfigImpl implements AgentPluginConfig {
     return !"false".equals(value);
   }
 
+  @Override
+  public boolean isCleanCredHelperScript() {
+    String value = myBuild.getSharedConfigParameters().get(CLEAN_CRED_HELPER_SCRIPT);
+    return !"false".equals(value);
+  }
+
   private int parseTimeout(String valueFromBuild) {
     return parseTimeout(valueFromBuild, DEFAULT_IDLE_TIMEOUT);
   }
index 057870feeb6bb151dd48ec029393494e24812837..9e1a6e544130ab09b4eced5f0fbcd01d30040308 100644 (file)
@@ -886,12 +886,14 @@ public class UpdaterImpl implements Updater {
       for (Map.Entry<String, String> e : config.getEnv().entrySet()) {
         command.setEnv(e.getKey(), e.getValue());
       }
-      command.addPostAction(new Runnable() {
-        @Override
-        public void run() {
-          FileUtil.delete(credHelper);
-        }
-      });
+      if (myPluginConfig.isCleanCredHelperScript()) {
+        command.addPostAction(new Runnable() {
+          @Override
+          public void run() {
+            FileUtil.delete(credHelper);
+          }
+        });
+      }
     } catch (Exception e) {
       if (credentialsHelper != null)
         FileUtil.delete(credentialsHelper);
index fed8aabb0be234e949a0cbd704fecaad267df2c9..435817a5311d40202dd15006d8ddf6fc402d816c 100644 (file)
@@ -57,7 +57,10 @@ public abstract class ScriptGen {
       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());
-      out.print(script);
+      String[] lines = script.split("(\r\n|\r|\n)");
+      for (String line : lines) {
+        out.println(line);
+      }
       if (!result.setExecutable(true))
         throw new IOException("Cannot make credentialsHelper script executable");
     } catch (IOException e) {