public void VerifyCreateQueryProcessInfoWithAttributes() { string fromtime = "01/02/2003 00:00:00"; string totime = "23/02/2006 23:14:05"; IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "source", null); IntegrationSummary lastSummary = new IntegrationSummary(IntegrationStatus.Success, "label", "lastlabel", DateTime.Now); IntegrationResult from = new IntegrationResult("test", @"c:\workspace", @"c:\artifacts", request, lastSummary); from.StartTime = DateTime.ParseExact(fromtime, PlasticSCM.DATEFORMAT, System.Globalization.CultureInfo.InvariantCulture); IntegrationResult to = new IntegrationResult("test", @"c:\workspace", @"c:\artifacts", request, lastSummary); to.StartTime = DateTime.ParseExact(totime, PlasticSCM.DATEFORMAT, System.Globalization.CultureInfo.InvariantCulture); PlasticSCM plasticscm = new PlasticSCM(); NetReflector.Read(PLASTICSCM_XML, plasticscm); string query = string.Format( @"c:\plastic\client\cm.exe find revision where branch = 'br:/main' and revno != 'CO' " + "and date between '{0}' and '{1}' on repository 'mainrep' ", fromtime, totime); string dateformat = string.Format(System.Globalization.CultureInfo.CurrentCulture, "--dateformat=\"{0}\" ", PlasticSCM.DATEFORMAT); string format = string.Format(System.Globalization.CultureInfo.CurrentCulture, "--format=\"{0}\"", PlasticSCM.FORMAT); ProcessInfo info = plasticscm.CreateQueryProcessInfo(from, to); Assert.AreEqual(query + dateformat + format, info.FileName + " " + info.Arguments); }
public string Generate(IIntegrationResult integrationResult) { try { int rebuild = 0; int revision = SvnProcessHelper.GetSvnRevision(SvnOptions); IntegrationSummary lastIntegration = integrationResult.LastIntegration; if ((integrationResult != null) && (!lastIntegration.IsInitial())) { string lastLabel = lastIntegration.Label; string[] labelParsed = StringHelper.ParseLabel(lastLabel); int lastRevision = Int32.Parse(labelParsed[2]); if (lastRevision == revision) { rebuild = Int32.Parse(labelParsed[3]) + 1; } } string resultLabel = Major.ToString() + "." + Minor.ToString() + "." + revision.ToString() + "." + rebuild.ToString(); return(resultLabel); } catch (Exception ex) { throw new Exception("Failed during svn revision labelling " + ex.ToString()); } }
public void RunForDirectoryWildCard() { IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "Somewhere", null); IntegrationSummary summary = new IntegrationSummary(IntegrationStatus.Success, "A Label", "Another Label", new DateTime(2009, 1, 1)); IntegrationResult result = new IntegrationResult("Test project", "Working directory", "Artifact directory", request, summary); Modification modification1 = GenerateModification("first file", "Add"); Modification modification2 = GenerateModification("second file", "Modify"); result.Modifications = new Modification[] { modification1, modification2 }; result.Status = IntegrationStatus.Success; result.ArtifactDirectory = Path.GetTempPath(); string packageLocation = Path.Combine(Path.GetTempPath(), "Test Package-1"); string packageName = packageLocation + ".zip"; if (File.Exists(packageName)) { File.Delete(packageName); } PackagePublisher publisher = new PackagePublisher(); publisher.PackageName = packageLocation; publisher.PackageList = new IPackageItem[] { new PackageFile(Path.Combine(Path.GetTempPath(), "**\\datafile.txt")) }; publisher.Run(result); Assert.IsTrue(File.Exists(packageName), "Package not generated"); Assert.IsTrue( File.Exists(Path.Combine(Path.GetTempPath(), Path.Combine("A Label", "Test project-packages.xml"))), "Project package list not generated"); }
public void GenerateFullManifest() { ManifestGenerator generator = new ManifestGenerator(); IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "Somewhere", null); IntegrationSummary summary = new IntegrationSummary(IntegrationStatus.Success, "A Label", "Another Label", new DateTime(2009, 1, 1)); IntegrationResult result = new IntegrationResult("Test project", "Working directory", "Artifact directory", request, summary); Modification modification1 = GenerateModification("first file", "Add"); Modification modification2 = GenerateModification("second file", "Modify"); result.Modifications = new Modification[] { modification1, modification2 }; List <string> files = new List <string>(); files.Add("first file"); XmlDocument manifest = generator.Generate(result, files.ToArray()); Assert.IsNotNull(manifest); string actualManifest = manifest.OuterXml; string expectedManifest = "<manifest>" + "<header project=\"Test project\" label=\"A Label\" build=\"ForceBuild\" status=\"Unknown\">" + "<modification user=\"johnDoe\" changeNumber=\"1\" time=\"2009-01-01T00:00:00\">" + "<comment>A comment</comment>" + "<file name=\"first file\" type=\"Add\" />" + "<file name=\"second file\" type=\"Modify\" />" + "</modification>" + "</header>" + "<file name=\"first file\" />" + "</manifest>"; Assert.AreEqual(expectedManifest, actualManifest); }
public void ImportRelativeBasedManifest() { string sourceFile = Path.Combine(Path.GetTempPath(), "ImportManifest.xml"); string expectedManifest = "<manifest>" + "From a file" + "</manifest>"; if (File.Exists(sourceFile)) { File.Delete(sourceFile); } File.WriteAllText(sourceFile, expectedManifest); ManifestImporter generator = new ManifestImporter(); generator.FileName = "ImportManifest.xml"; IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "Somewhere", null); IntegrationSummary summary = new IntegrationSummary(IntegrationStatus.Success, "A Label", "Another Label", new DateTime(2009, 1, 1)); IntegrationResult result = new IntegrationResult("Test project", "Working directory", "Artifact directory", request, summary); List <string> files = new List <string>(); result.WorkingDirectory = Path.GetTempPath(); XmlDocument manifest = generator.Generate(result, files.ToArray()); Assert.IsNotNull(manifest); string actualManifest = manifest.OuterXml; Assert.AreEqual(expectedManifest, actualManifest); }
public void CanGetPreviousState() { string workingDir = Path.GetFullPath(Path.Combine(".", "workingdir")); string artifactDir = Path.GetFullPath(Path.Combine(".", "artifacts")); IntegrationSummary expectedSummary = new IntegrationSummary(IntegrationStatus.Exception, "foo", "foo", DateTime.MinValue); result = new IntegrationResult("project", workingDir, artifactDir, IntegrationRequest.NullRequest, expectedSummary); Assert.AreEqual(new IntegrationSummary(IntegrationStatus.Exception, "foo", "foo", DateTime.MinValue), result.LastIntegration); }
private Version ParseVersion(DateTime date, IntegrationSummary lastIntegrationSummary) { try { return(new Version(lastIntegrationSummary.LastSuccessfulIntegrationLabel)); } catch (SystemException) { return(new Version(date.Year, date.Month, date.Day, 0)); } }
public void VerifyNewGetSourceProcessInfoWithAttribtues() { IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "source", null); IntegrationSummary lastSummary = new IntegrationSummary(IntegrationStatus.Success, "label", "lastlabel", DateTime.Now); IntegrationResult result = new IntegrationResult("test", @"c:\workspace", @"c:\artifacts", request, lastSummary); PlasticSCM plasticscm = new PlasticSCM(); NetReflector.Read(PLASTICSCM_XML, plasticscm); string expected = @"c:\plastic\client\cm.exe update c:\workspace --forced"; ProcessInfo info = plasticscm.NewGetSourceProcessInfo(result); Assert.AreEqual(expected, info.FileName + " " + info.Arguments); }
private IntegrationResult GetResult() { IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "Somewhere", null); IntegrationSummary summary = new IntegrationSummary(IntegrationStatus.Success, "A Label", "Another Label", new DateTime(2009, 1, 1)); IntegrationResult result = new IntegrationResult("Test project", "Working directory", "Artifact directory", request, summary); Modification modification1 = GenerateModification("first file", "Add"); Modification modification2 = GenerateModification("second file", "Modify"); result.Modifications = new Modification[] { modification1, modification2 }; result.Status = IntegrationStatus.Success; result.ArtifactDirectory = Path.GetTempPath(); return(result); }
public void VerifyGoToBranchProcessInfoBasic() { IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "source", null); IntegrationSummary lastSummary = new IntegrationSummary(IntegrationStatus.Success, "label", "lastlabel", DateTime.Now); IntegrationResult result = new IntegrationResult("test", @"c:\workspace", @"c:\artifacts", request, lastSummary); PlasticSCM plasticscm = new PlasticSCM(); NetReflector.Read(PLASTICSCM_XML, plasticscm); string expected = @"c:\plastic\client\cm.exe stb br:/main -repository=mainrep --noupdate"; ProcessInfo info = plasticscm.GoToBranchProcessInfo(result); Assert.AreEqual(expected, info.FileName + " " + info.Arguments); }
private IntegrationResult GenerateResult(int numberOfModifications) { IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "Somewhere", null); IntegrationSummary summary = new IntegrationSummary(IntegrationStatus.Success, "A Label", "Another Label", new DateTime(2009, 1, 1)); IntegrationResult result = new IntegrationResult("Test project", "Working directory", "Artifact directory", request, summary); List <Modification> modifications = new List <Modification>(); for (int loop = 0; loop < numberOfModifications; loop++) { modifications.Add(GenerateModification(string.Format(System.Globalization.CultureInfo.CurrentCulture, "modification #{0}", loop + 1), "Add")); } result.Modifications = modifications.ToArray(); result.ArtifactDirectory = Path.GetTempPath(); return(result); }
public void VerifyLabelProcessInfoBasic() { IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "source", null); IntegrationSummary lastSummary = new IntegrationSummary(IntegrationStatus.Success, "label", "lastlabel", DateTime.Now); IntegrationResult result = new IntegrationResult("test", @"c:\workspace", @"c:\artifacts", request, lastSummary); result.Label = "1"; PlasticSCM plasticscm = new PlasticSCM(); NetReflector.Read(PLASTICSCM_BASIC_XML, plasticscm); string expected = @"cm label -R lb:ccver-1 ."; ProcessInfo info = plasticscm.LabelProcessInfo(result); Assert.AreEqual(expected, info.FileName + " " + info.Arguments); }
/// <summary> /// Generates the specified integration result. /// </summary> /// <param name="integrationResult">The integration result.</param> /// <returns></returns> /// <remarks></remarks> public override string Generate(IIntegrationResult integrationResult) { IntegrationSummary lastIntegration = integrationResult.LastIntegration; if (lastIntegration.Label == null || lastIntegration.IsInitial()) { return(NewLabel(InitialLabel)); } else if (lastIntegration.Status == IntegrationStatus.Success || IncrementOnFailed) { return(NewLabel(IncrementLabel(lastIntegration.Label))); } else { return(lastIntegration.Label); } }
/// <summary> /// Generates the specified integration result. /// </summary> /// <param name="integrationResult">The integration result.</param> /// <returns></returns> /// <remarks></remarks> public override string Generate(IIntegrationResult integrationResult) { IntegrationSummary lastIntegration = integrationResult.LastIntegration; if (integrationResult == null || lastIntegration.IsInitial()) { return(LabelPrefix + InitialBuildLabel.ToString(LabelFormat, CultureInfo.CurrentCulture) + LabelPostfix); } else if (ShouldIncrementLabel(lastIntegration)) { return(LabelPrefix + IncrementLabel(lastIntegration.Label) + LabelPostfix); } else { return(integrationResult.LastIntegration.Label); } }
public void EvaluateReturnsTrueIfBeyondTime() { var condition = new LastBuildTimeTaskCondition { Time = new Timeout(1000) }; var status = new IntegrationSummary(IntegrationStatus.Success, "1", "1", DateTime.Now.AddHours(-1)); var result = this.mocks.Create <IIntegrationResult>(MockBehavior.Strict).Object; Mock.Get(result).Setup(_result => _result.IsInitial()).Returns(false).Verifiable(); Mock.Get(result).SetupGet(_result => _result.LastIntegration).Returns(status).Verifiable(); var actual = condition.Eval(result); this.mocks.VerifyAll(); Assert.IsTrue(actual); }
public void EvaluateReturnsTrueIfBeyondTime() { var condition = new LastBuildTimeTaskCondition { Time = new Timeout(1000) }; var status = new IntegrationSummary(IntegrationStatus.Success, "1", "1", DateTime.Now.AddHours(-1)); var result = this.mocks.StrictMock <IIntegrationResult>(); Expect.Call(result.IsInitial()).Return(false); Expect.Call(result.LastIntegration).Return(status); this.mocks.ReplayAll(); var actual = condition.Eval(result); this.mocks.VerifyAll(); Assert.IsTrue(actual); }
public void EvaluateReturnsFalseIfWithinTime() { var condition = new LastBuildTimeTaskCondition { Time = new Timeout(1000), Description = "Not equal test" }; var status = new IntegrationSummary(IntegrationStatus.Success, "1", "1", DateTime.Now); var result = this.mocks.StrictMock <IIntegrationResult>(); Expect.Call(result.IsInitial()).Return(false); Expect.Call(result.LastIntegration).Return(status); this.mocks.ReplayAll(); var actual = condition.Eval(result); this.mocks.VerifyAll(); Assert.IsFalse(actual); }
public void IncludeManifestInPackage() { IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "Somewhere", null); IntegrationSummary summary = new IntegrationSummary(IntegrationStatus.Success, "A Label", "Another Label", new DateTime(2009, 1, 1)); IntegrationResult result = new IntegrationResult("Test project", "Working directory", "Artifact directory", request, summary); Modification modification1 = GenerateModification("first file", "Add"); Modification modification2 = GenerateModification("second file", "Modify"); result.Modifications = new Modification[] { modification1, modification2 }; result.Status = IntegrationStatus.Success; result.ArtifactDirectory = Path.GetTempPath(); XmlDocument manifest = new XmlDocument(); manifest.AppendChild(manifest.CreateElement("manifest")); DynamicMock generatorMock = new DynamicMock(typeof(IManifestGenerator)); List <string> files = new List <string>(); files.Add(dataFilePath); generatorMock.ExpectAndReturn("Generate", manifest, result, files.ToArray()); string packageLocation = Path.Combine(Path.GetTempPath(), "Test Package-1"); string packageName = packageLocation + ".zip"; if (File.Exists(packageName)) { File.Delete(packageName); } PackagePublisher publisher = new PackagePublisher(); publisher.PackageName = packageLocation; publisher.ManifestGenerator = generatorMock.MockInstance as IManifestGenerator; publisher.PackageList = new IPackageItem[] { new PackageFile(dataFilePath) }; publisher.Run(result); Assert.IsTrue(File.Exists(packageName), "Package not generated"); Assert.IsTrue( File.Exists(Path.Combine(Path.GetTempPath(), Path.Combine("A Label", "Test project-packages.xml"))), "Project package list not generated"); generatorMock.Verify(); }
public void IncludeManifestInPackage() { IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "Somewhere", null); IntegrationSummary summary = new IntegrationSummary(IntegrationStatus.Success, "A Label", "Another Label", new DateTime(2009, 1, 1)); IntegrationResult result = new IntegrationResult("Test project", "Working directory", "Artifact directory", request, summary); Modification modification1 = GenerateModification("first file", "Add"); Modification modification2 = GenerateModification("second file", "Modify"); result.Modifications = new Modification[] { modification1, modification2 }; result.Status = IntegrationStatus.Success; result.ArtifactDirectory = Path.GetTempPath(); XmlDocument manifest = new XmlDocument(); manifest.AppendChild(manifest.CreateElement("manifest")); var generatorMock = new Mock <IManifestGenerator>(); generatorMock.Setup(generator => generator.Generate(result, It.Is <string[]>(files => files.Length == 1 && files[0] == dataFilePath))).Returns(manifest).Verifiable(); string packageLocation = Path.Combine(Path.GetTempPath(), "Test Package-1"); string packageName = packageLocation + ".zip"; if (File.Exists(packageName)) { File.Delete(packageName); } PackagePublisher publisher = new PackagePublisher(); publisher.PackageName = packageLocation; publisher.ManifestGenerator = generatorMock.Object as IManifestGenerator; publisher.PackageList = new IPackageItem[] { new PackageFile(dataFilePath) }; publisher.Run(result); Assert.IsTrue(File.Exists(packageName), "Package not generated"); Assert.IsTrue( File.Exists(Path.Combine(Path.GetTempPath(), Path.Combine("A Label", "Test project-packages.xml"))), "Project package list not generated"); generatorMock.Verify(); }
/// <summary> /// Generates the specified integration result. /// </summary> /// <param name="integrationResult">The integration result.</param> /// <returns></returns> /// <remarks></remarks> public override string Generate(IIntegrationResult integrationResult) { if (!string.IsNullOrEmpty(LabelPrefixFile)) { ThoughtWorks.CruiseControl.Core.Util.Log.Debug("Reading prefix from file : " + LabelPrefixFile); LabelPrefix = GetPrefixFromFile(); } IntegrationSummary lastIntegration = integrationResult.LastIntegration; if (integrationResult == null || lastIntegration.IsInitial()) { return(LabelPrefix + InitialBuildLabel.ToString(LabelFormat, CultureInfo.CurrentCulture) + LabelPostfix); } else if (ShouldIncrementLabel(lastIntegration)) { return(LabelPrefix + IncrementLabel(lastIntegration.Label) + LabelPostfix); } else { return(integrationResult.LastIntegration.Label); } }
public IIntegrationResult LoadState(string project) { var path = this.GeneratePath(project); using (var reader = new StreamReader( this.fileSystem.OpenInputStream(path))) { var status = (IntegrationStatus) Enum.Parse(typeof(IntegrationStatus), reader.ReadLine()); var lastSummary = new IntegrationSummary( status, reader.ReadLine(), reader.ReadLine(), DateTime.Parse(reader.ReadLine())); var result = new IntegrationResult( project, reader.ReadLine(), reader.ReadLine(), null, lastSummary); return(result); } }
/// <summary> /// Generate a label string from the last change number. /// If there is no valid change number (e.g. for a forced build without modifications), /// then the last integration label is used. /// </summary> /// <param name="resultFromThisBuild">IntegrationResult object for the current build</param> /// <returns>the new label</returns> public override string Generate(IIntegrationResult resultFromThisBuild) { int changeNumber = 0; if (int.TryParse(resultFromThisBuild.LastChangeNumber, out changeNumber)) { Log.Debug( string.Format(System.Globalization.CultureInfo.CurrentCulture, "LastChangeNumber retrieved - {0}", changeNumber)); } else { Log.Debug("LastChangeNumber defaulted to 0"); } IntegrationSummary lastIntegration = resultFromThisBuild.LastIntegration; string firstSuffix = AllowDuplicateSubsequentLabels ? string.Empty : "." + INITIAL_SUFFIX_NUMBER.ToString(CultureInfo.CurrentCulture); if (changeNumber != 0) { return(LabelPrefix + changeNumber + firstSuffix); } else if (lastIntegration.IsInitial() || lastIntegration.Label == null) { return(LabelPrefix + "unknown" + firstSuffix); } else if (!AllowDuplicateSubsequentLabels) { return(IncrementLabel(lastIntegration.Label)); } else { return(lastIntegration.Label); } }
public static IntegrationResult Create(IntegrationSummary integrationSummary) { return(new IntegrationResult(DefaultProjectName, Path.GetTempPath(), Path.GetTempPath(), ModificationExistRequest(), integrationSummary)); }
private Version ParseVersion(DateTime date, IntegrationSummary lastIntegrationSummary) { try { return new Version(lastIntegrationSummary.LastSuccessfulIntegrationLabel); } catch (SystemException) { return new Version(date.Year, date.Month, date.Day, 0); } }
private bool ShouldIncrementLabel(IntegrationSummary integrationSummary) { return(integrationSummary == null || integrationSummary.Status == IntegrationStatus.Success || IncrementOnFailure); }
private bool ShouldIncrementLabel(IntegrationSummary previousResult) { return(previousResult.Status == IntegrationStatus.Success || IncrementOnFailed); }
private bool ShouldIncrementLabel(IntegrationSummary previousResult) { return previousResult.Status == IntegrationStatus.Success || IncrementOnFailed; }