Permalink
Browse files

Merge pull request #160 from RubenWillems/master

Issue with CCNet and CCNetFailureUsers argument (Bug #191)
  • Loading branch information...
2 parents 5c6ca66 + ef08896 commit 41c883c494e682da0ef52295f8cad7d09fb36074 @RubenWillems RubenWillems committed Sep 23, 2012
@@ -132,6 +132,41 @@ public void TestAutoDoubleQuoteString()
}
[Test]
+ public void TestStripThenEncodeParameterArgument()
+ {
+ string[][] tests = new string[][] {
+ new string[] { "foo", "foo"}
+ ,
+ new string[] { "\"foo\"", "foo"}
+ ,
+ new string[] { "\"foo", "foo"}
+ ,
+ new string[] { "f o o", "\"f o o\""}
+ ,
+ new string[] { @"\foo\", @"\foo\"}
+ ,
+ new string[] { @"\\fo\o\\\", @"\\fo\o\\\"}
+ ,
+ new string[] { " ", "\" \""}
+ ,
+ new string[] { "fo\"o", "fo\\\"o"}
+ ,
+ new string[] { "fo\\\"o", "fo\\\\\\\"o"}
+ ,
+ new string[] { "foo \"something\" bar", "\"foo \\\"something\\\" bar\""}
+ ,
+ new string[] { "fo o\\", "\"fo o\\\\\""}
+ ,
+ new string[] { "foo\\ ", "\"foo\\ \""}
+ };
+
+ foreach (string[] test in tests)
+ {
+ Assert.AreEqual(StringUtil.StripThenEncodeParameterArgument(test[0]), test[1]);
+ }
+ }
+
+ [Test]
public void TestRemoveTrailingPathDelimiter()
{
const string actual = "foo";
@@ -204,6 +204,137 @@ public void RunNantAndExecTaskWithArgumentsOnSingleAndMultiLines()
}
+ [Test]
+ public void RunNantWhenFailureUsersHaveQuoutesInTheirNames()
+ {
+ const string ProjectName1 = "NantTest02";
+
+ string IntegrationFolder = System.IO.Path.Combine("scenarioTests", ProjectName1);
+ string CCNetConfigFile = System.IO.Path.Combine("IntegrationScenarios", "NantFailureUsersWithQuote.xml");
+ string ProjectStateFile = new System.IO.FileInfo(ProjectName1 + ".state").FullName;
+
+ IntegrationCompleted = new System.Collections.Generic.Dictionary<string, bool>();
+
+ string workingDirectory = "Nant02";
+
+ var ios = new CCNet.Core.Util.IoService();
+ ios.DeleteIncludingReadOnlyObjects(workingDirectory);
+ System.IO.Directory.CreateDirectory(workingDirectory);
+
+ System.IO.File.Delete(ProjectStateFile);
+
+ string NantBuildFile = @"IntegrationScenarios\Nant.Build";
+ var NantExeLocation = "";
+
+#if DEBUG
+ NantExeLocation = @"..\..\..\..\Tools\Nant\nant.exe";
+#else
+ NantExeLocation = @"..\..\Tools\Nant\nant.exe";
+#endif
+ var configFileData = System.IO.File.ReadAllText(CCNetConfigFile);
+ configFileData = configFileData.Replace("WillBeReplacedViaTheTest", NantExeLocation);
+ System.IO.File.WriteAllText(CCNetConfigFile, configFileData);
+
+ System.IO.File.Copy(NantBuildFile, System.IO.Path.Combine(workingDirectory, new System.IO.FileInfo(NantBuildFile).Name));
+
+
+
+ IntegrationCompleted.Add(ProjectName1, false);
+
+ Log("Clear existing state file, to simulate first run : " + ProjectStateFile);
+ System.IO.File.Delete(ProjectStateFile);
+
+ Log("Clear integration folder to simulate first run");
+ if (System.IO.Directory.Exists(IntegrationFolder)) System.IO.Directory.Delete(IntegrationFolder, true);
+
+ string FailureFileLocation = System.IO.Path.Combine(workingDirectory, "FailBuild.txt");
+
+ Log("Creating failure file so the build will fail the nant task");
+ var ff = new System.IO.FileStream(FailureFileLocation, System.IO.FileMode.CreateNew);
+ ff.Close();
+ ff.Dispose();
+
+
+ CCNet.Remote.Messages.ProjectStatusResponse psr;
+ CCNet.Remote.Messages.ProjectRequest pr1 = new CCNet.Remote.Messages.ProjectRequest(null, ProjectName1);
+
+
+ Log("Making CruiseServerFactory");
+ CCNet.Core.CruiseServerFactory csf = new CCNet.Core.CruiseServerFactory();
+
+ Log("Making cruiseServer with config from :" + CCNetConfigFile);
+ using (var cruiseServer = csf.Create(true, CCNetConfigFile))
+ {
+
+ // subscribe to integration complete to be able to wait for completion of a build
+ cruiseServer.IntegrationCompleted += new EventHandler<ThoughtWorks.CruiseControl.Remote.Events.IntegrationCompletedEventArgs>(CruiseServerIntegrationCompleted);
+
+ Log("Starting cruiseServer");
+ cruiseServer.Start();
+
+ System.Threading.Thread.Sleep(250); // give time to start
+
+ Log("Forcing build to fail the build");
+ CheckResponse(cruiseServer.ForceBuild(pr1));
+
+ System.Threading.Thread.Sleep(250); // give time to start the build
+
+ Log("Waiting for integration to complete");
+ while (!IntegrationCompleted[ProjectName1])
+ {
+ for (int i = 1; i <= 4; i++) System.Threading.Thread.Sleep(250);
+ Log(" waiting ...");
+ }
+
+
+ Log("Forcing build so it will pass now");
+
+ IntegrationCompleted[ProjectName1] = false;
+ System.IO.File.Delete(FailureFileLocation);
+ CheckResponse(cruiseServer.ForceBuild(pr1));
+
+
+ System.Threading.Thread.Sleep(250); // give time to start the build
+
+ Log("Waiting for integration to complete");
+ while (!IntegrationCompleted[ProjectName1])
+ {
+ for (int i = 1; i <= 4; i++) System.Threading.Thread.Sleep(250);
+ Log(" waiting ...");
+ }
+
+
+
+ // un-subscribe to integration complete
+ cruiseServer.IntegrationCompleted -= new EventHandler<ThoughtWorks.CruiseControl.Remote.Events.IntegrationCompletedEventArgs>(CruiseServerIntegrationCompleted);
+
+ Log("getting project status");
+ psr = cruiseServer.GetProjectStatus(pr1);
+ CheckResponse(psr);
+
+ Log("Stopping cruiseServer");
+ cruiseServer.Stop();
+
+ Log("waiting for cruiseServer to stop");
+ cruiseServer.WaitForExit(pr1);
+ Log("cruiseServer stopped");
+
+ }
+
+ Log("Checking the data");
+ CCNet.Remote.ProjectStatus ps = null;
+
+ // checking data of project 1
+ foreach (var p in psr.Projects)
+ {
+ if (p.Name == ProjectName1) ps = p;
+ }
+
+ Assert.AreEqual(ProjectName1, ps.Name);
+ Assert.AreEqual(CCNet.Remote.IntegrationStatus.Success, ps.BuildStatus, "wrong build state for project " + ProjectName1);
+
+ }
+
@@ -1388,6 +1388,9 @@
<Content Include="resources\IntegrationScenarios\NantAndExecTestMultiLineBuildArgs.xml">
<SubType>Designer</SubType>
</Content>
+ <Content Include="resources\IntegrationScenarios\NantFailureUsersWithQuote.xml">
+ <SubType>Designer</SubType>
+ </Content>
<Content Include="resources\IntegrationScenarios\PackagePublisherTest01.xml" />
<Content Include="resources\IntegrationScenarios\PackagePublisherTest02.xml" />
<Content Include="resources\IntegrationScenarios\PackagePublisherTest03.xml" />
@@ -4,12 +4,15 @@
<property name="solution" value="Source/Finance.sln" />
<property name="CreateInstallZips" value="False" />
<property name="isCi" value="True" />
+ <property name="FileToCheckToFail" value="FailBuild.txt" />
+
<property name="CCNetBuildCondition" unless="${property::exists('CCNetBuildCondition')}" value="ForceBuild" />
<property name="CCNetLabel" unless="${property::exists('CCNetLabel')}" value="0.0.0.0" />
<property name="CCNetRequestSource" unless="${property::exists('CCNetRequestSource')}" value="Finance_ArtifactDirectory" />
<property name="CCNetWorkingDirectory" unless="${property::exists('CCNetWorkingDirectory')}" value="" />
+ <property name="CCNetFailureUsers" unless="${property::exists('CCNetFailureUsers')}" value="" />
<target name="showHelp" >
@@ -21,8 +24,13 @@
<echo message="CCNetLabel : ${CCNetLabel} " />
<echo message="CCNetRequestSource : ${CCNetRequestSource} " />
<echo message="CCNetWorkingDirectory : ${CCNetWorkingDirectory} " />
- <echo message="CreateInstallZips : ${CreateInstallZips} " />
+ <echo message="CCNetFailureUsers : ${CCNetFailureUsers} " />
+ <echo message="CreateInstallZips : ${CreateInstallZips} " />
<echo message="isCi : ${isCi} " />
</target>
-
+
+ <target name="FailBuildIfFileExists" >
+ <fail message="Failure file found" if="${file::exists(FileToCheckToFail)}" />
+ </target>
+
</project>
@@ -4,7 +4,7 @@
<project name="NantTest01"
workingDirectory="Nant01">
<triggers />
-
+
<tasks>
<nant description="running Nant with buildargs on multiple lines">
<executable>WillBeReplacedViaTheTest</executable>
@@ -0,0 +1,33 @@
+<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
+
+ <!-- ensure that multi line buildargs work -->
+ <project name="NantTest02"
+ workingDirectory="Nant02">
+ <triggers />
+
+ <sourcecontrol type="nullSourceControl" alwaysModified="true">
+ </sourcecontrol>
+
+ <tasks>
+
+ <nant description="running Nant">
+ <executable>WillBeReplacedViaTheTest</executable>
+ <buildFile>Nant.build</buildFile>
+ <targetList>
+ <target>showProperties</target>
+ <target>FailBuildIfFileExists</target>
+ </targetList>
+ <buildTimeoutSeconds>600</buildTimeoutSeconds>
+ </nant>
+
+ </tasks>
+
+
+
+ <publishers>
+ <xmllogger />
+ </publishers>
+ </project>
+
+
+</cruisecontrol>
@@ -93,7 +93,7 @@ public Modification[] GetModifications(IIntegrationResult from, IIntegrationResu
mod.FileName = "AlwaysModified";
mod.FolderName = "NullSourceControl";
mod.ModifiedTime = DateTime.Now;
- mod.UserName = "JohnWayne";
+ mod.UserName = "John \"The Duke\" Wayne";
mod.Comment = "Making a change";
mod.Type = "modified";
@@ -240,7 +240,7 @@ private static void AppendIntegrationResultProperties(ProcessArgumentBuilder buf
{
object value = result.IntegrationProperties[key];
if (value != null)
- buffer.AppendArgument(string.Format(System.Globalization.CultureInfo.CurrentCulture,"{0}={1}", key, StringUtil.AutoDoubleQuoteString(StringUtil.RemoveTrailingPathDelimeter(StringUtil.IntegrationPropertyToString(value)))));
+ buffer.AppendArgument(string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}={1}", key, StringUtil.StripThenEncodeParameterArgument(StringUtil.RemoveTrailingPathDelimeter(StringUtil.IntegrationPropertyToString(value)))));
}
}
@@ -239,7 +239,7 @@ private ProcessInfo NewProcessInfoFrom(IIntegrationResult result)
object obj1 = result.IntegrationProperties[varName];
if ((obj1 != null) && !info.EnvironmentVariables.ContainsKey(varName))
{
- info.EnvironmentVariables.Add(varName, StringUtil.AutoDoubleQuoteString(StringUtil.RemoveTrailingPathDelimeter(StringUtil.IntegrationPropertyToString(obj1))));
+ info.EnvironmentVariables.Add(varName, StringUtil.StripThenEncodeParameterArgument(StringUtil.RemoveTrailingPathDelimeter(StringUtil.IntegrationPropertyToString(obj1))));
}
}
return info;
@@ -302,7 +302,7 @@ private static string GetPropertyArgs(IIntegrationResult result)
foreach (string key in properties.Keys)
{
if (count > 0) builder.Append(";");
- builder.Append(string.Format(System.Globalization.CultureInfo.CurrentCulture,"{0}={1}", key, StringUtil.AutoDoubleQuoteString(StringUtil.IntegrationPropertyToString(result.IntegrationProperties[key]))));
+ builder.Append(string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}={1}", key, StringUtil.StripThenEncodeParameterArgument(StringUtil.IntegrationPropertyToString(result.IntegrationProperties[key]))));
count++;
}
Oops, something went wrong.

0 comments on commit 41c883c

Please sign in to comment.