/// <summary>
        /// Creates the process info.	
        /// </summary>
        /// <param name="p4">The p4.</param>
        /// <param name="extraArguments">The extra arguments.</param>
        /// <returns></returns>
        /// <remarks></remarks>
		public ProcessInfo CreateProcessInfo(P4 p4, string extraArguments)
		{
			ProcessInfo processInfo = new ProcessInfo(p4.Executable, BuildCommonArguments(p4) + extraArguments);
			processInfo.TimeOut = 0; // Don't time out - this should be configurable
            processInfo.WorkingDirectory = p4.WorkingDirectory;
			return processInfo;
		}
 private void CreateClientNameIfOneNotSet(P4 p4, string projectName)
 {
     if (p4.Client == null || (p4.Client != null && p4.Client.Length == 0))
     {
         p4.Client = string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}-{1}-{2}", ClientPrefix, Dns.GetHostName(), projectName);
     }
 }
예제 #3
0
 private void CreateClientNameIfOneNotSet(P4 p4, string projectName)
 {
     if (p4.Client == null || p4.Client == string.Empty)
     {
         p4.Client = string.Format("{0}-{1}-{2}", ClientPrefix, Dns.GetHostName(), projectName);
     }
 }
예제 #4
0
		private void DeleteClientSpec(P4 p4)
		{
			ProcessResult result = executor.Execute(infoCreator.CreateProcessInfo(p4, "client -d " + p4.Client));
			if (result.ExitCode != ProcessResult.SUCCESSFUL_EXIT_CODE)
			{
				throw new CruiseControlException(string.Format(System.Globalization.CultureInfo.CurrentCulture,"Failed to Initialize client (exit code was {0}).\r\nStandard output was: {1}\r\nStandard error was {2}", result.ExitCode, result.StandardOutput, result.StandardError));
			}
		}
		public void ShouldCreateProcessWithDefaultArgumentsIfNoneAreSet()
		{
			// Setup
			P4 p4 = new P4();

			ProcessInfo info = new P4ConfigProcessInfoCreator().CreateProcessInfo(p4, "my arguments");

			Assert.AreEqual("p4", info.FileName);
			Assert.AreEqual("-s my arguments", info.Arguments);
		}
예제 #6
0
 public void Purge(P4 p4, string workingDirectory)
 {
     if (p4.Client != null && p4.Client != string.Empty)
     {
         Log.Info(string.Format("Attempting to Delete Perforce Client Spec [{0}]", p4.Client));
         DeleteClientSpec(p4);
     }
     Log.Info(string.Format("Attempting to Delete Working Directory [{0}]", workingDirectory));
     new IoService().DeleteIncludingReadOnlyObjects(workingDirectory);
 }
예제 #7
0
        /// <summary>
        /// Purges the specified p4.	
        /// </summary>
        /// <param name="p4">The p4.</param>
        /// <param name="workingDirectory">The working directory.</param>
        /// <remarks></remarks>
		public void Purge(P4 p4, string workingDirectory)
		{
			if (p4.Client != null && !(p4.Client != null && p4.Client.Length == 0))
			{
				Log.Info(string.Format(System.Globalization.CultureInfo.CurrentCulture,"Attempting to Delete Perforce Client Spec [{0}]", p4.Client));
				DeleteClientSpec(p4);
			}
			Log.Info(string.Format(System.Globalization.CultureInfo.CurrentCulture,"Attempting to Delete Working Directory [{0}]", workingDirectory));
			new IoService().DeleteIncludingReadOnlyObjects(workingDirectory);
		}
		public void ShouldCreateProcessWithDefaultArgumentsIfOnlyUserIsSet()
		{
			// Setup
			P4 p4 = new P4();
			p4.User = "******";

			ProcessInfo info = new P4ConfigProcessInfoCreator().CreateProcessInfo(p4, "my arguments");

			Assert.AreEqual("p4", info.FileName);
			Assert.AreEqual("-s -u myUser my arguments", info.Arguments);
		}
 /// <summary>
 /// Initializes the specified p4.	
 /// </summary>
 /// <param name="p4">The p4.</param>
 /// <param name="project">The project.</param>
 /// <param name="workingDirectory">The working directory.</param>
 /// <remarks></remarks>
 public void Initialize(P4 p4, string project, string workingDirectory)
 {
     CheckWorkingDirectoryIsValid(workingDirectory);
     CheckViewIsValid(p4.ViewForSpecifications);
     CreateClientNameIfOneNotSet(p4, project);
     ProcessInfo processInfo = processInfoCreator.CreateProcessInfo(p4, "client -i");
     processInfo.StandardInputContent = CreateClientSpecification(p4, workingDirectory);
     ProcessResult result = executor.Execute(processInfo);
     if (result.ExitCode != ProcessResult.SUCCESSFUL_EXIT_CODE)
     {
         throw new CruiseControlException(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Failed to Initialize client (exit code was {0}).\r\nStandard output was: {1}\r\nStandard error was {2}", result.ExitCode, result.StandardOutput, result.StandardError));
     }
 }
		public void ShouldCreateProcessUsingAllConfigurationVariablesIfTheyAreSet()
		{
			// Setup
			P4 p4 = new P4();
			p4.Executable = "myExecutable";
			p4.Client = "myClient";
			p4.User = "******";
			p4.Port = "anotherserver:2666";

			ProcessInfo info = new P4ConfigProcessInfoCreator().CreateProcessInfo(p4, "my arguments");

			Assert.AreEqual("myExecutable", info.FileName);
			Assert.AreEqual("-s -c myClient -p anotherserver:2666 -u myUser my arguments", info.Arguments);
		}
예제 #11
0
        public void CreateGetChangeListsProcess()
        {
            P4 p4 = new P4();
            p4.View = "//depot/myproj/...";
            DateTime from = new DateTime(2002, 10, 20, 2, 0, 0);
            DateTime to = new DateTime(2002, 10, 31, 5, 5, 0);

            ProcessInfo process = p4.CreateChangeListProcess(from, to);

            string expectedArgs = "-s changes -s submitted //depot/myproj/...@2002/10/20:02:00:00,@2002/10/31:05:05:00";

            Assert.AreEqual("p4", process.FileName);
            Assert.AreEqual(expectedArgs, process.Arguments);
        }
		public void ShouldCheckToSeeWorkingDirectoryIsAnAbsolutePath()
		{
			P4 p4 = new P4();
			try
			{
				p4Initializer.Initialize(p4, "myProject", "thisIsNotAnAbsoluteDirectory");
				Assert.Fail("Should check for non absolute working directory");
			}
			catch (CruiseControlException e)
			{
				Assert.IsTrue(e.Message.ToLower().IndexOf("absolute path") > -1, "Should mention something about an absolute directory");
			}

			VerifyAll();
		}
 private string BuildCommonArguments(P4 p4)
 {
     StringBuilder args = new StringBuilder();
     args.Append("-s "); // for "scripting" mode
     if (p4.Client != null && p4.Client != string.Empty)
     {
         args.Append("-c " + p4.Client + " ");
     }
     if (p4.Port != null && p4.Port != string.Empty)
     {
         args.Append("-p " + p4.Port + " ");
     }
     if (p4.User != null && p4.Port != string.Empty)
     {
         args.Append("-u " + p4.User + " ");
     }
     return args.ToString();
 }
예제 #14
0
        private string BuildCommonArguments(P4 p4)
        {
            StringBuilder args = new StringBuilder();

            args.Append("-s ");             // for "scripting" mode
            if (p4.Client != null && p4.Client != string.Empty)
            {
                args.Append("-c " + p4.Client + " ");
            }
            if (p4.Port != null && p4.Port != string.Empty)
            {
                args.Append("-p " + p4.Port + " ");
            }
            if (p4.User != null && p4.Port != string.Empty)
            {
                args.Append("-u " + p4.User + " ");
            }
            return(args.ToString());
        }
 private string BuildCommonArguments(P4 p4)
 {
     StringBuilder args = new StringBuilder();
     args.Append("-s "); // for "scripting" mode
     if (!string.IsNullOrEmpty(p4.Client))
     {
         args.Append("-c " + p4.Client + " ");
     }
     if (!string.IsNullOrEmpty(p4.Port))
     {
         args.Append("-p " + p4.Port + " ");
     }
     if (!string.IsNullOrEmpty(p4.User))
     {
         args.Append("-u " + p4.User + " ");
     }
     if (!string.IsNullOrEmpty(p4.Password))
     {
         args.Append("-P " + p4.Password + " ");
     }
     return args.ToString();
 }
예제 #16
0
        private string BuildCommonArguments(P4 p4)
        {
            StringBuilder args = new StringBuilder();

            args.Append("-s ");             // for "scripting" mode
            if (!string.IsNullOrEmpty(p4.Client))
            {
                args.Append("-c " + p4.Client + " ");
            }
            if (!string.IsNullOrEmpty(p4.Port))
            {
                args.Append("-p " + p4.Port + " ");
            }
            if (!string.IsNullOrEmpty(p4.User))
            {
                args.Append("-u " + p4.User + " ");
            }
            if (!string.IsNullOrEmpty(p4.Password))
            {
                args.Append("-P " + p4.Password + " ");
            }
            return(args.ToString());
        }
        public void CreatesAClientWithConstructedClientNameIfOneNotSpecifiedAndSavesClientNameInConfig()
        {
            // Setup
            P4 p4 = new P4();
            p4.View = "//mydepot/...";
            string projectName = "myProject";

            string expectedClientName = string.Format("CCNet-{0}-{1}", Dns.GetHostName(), projectName);

            ProcessInfo processInfo = new ProcessInfo("createclient");
            ProcessInfo processInfoWithStdInContent = new ProcessInfo("createclient");
            processInfoWithStdInContent.StandardInputContent = string.Format("Client: {0}\n\nRoot:   c:\\my\\working\\dir\n\nView:\n //mydepot/... //{0}/mydepot/...\n", expectedClientName);

            processInfoCreatorMock.ExpectAndReturn("CreateProcessInfo", processInfo, p4, "client -i");
            processExecutorMock.ExpectAndReturn("Execute", new ProcessResult("", "", 0, false), processInfoWithStdInContent);

            // Execute
            p4Initializer.Initialize(p4, projectName, @"c:\my\working\dir");

            // Verify
            Assert.AreEqual(expectedClientName, p4.Client);
            VerifyAll();
        }
예제 #18
0
        public void CreateGetDescribeProcess()
        {
            string changes = "3327 3328 332";
            ProcessInfo process = new P4().CreateDescribeProcess(changes);

            string expectedArgs = "-s describe -s " + changes;
            Assert.AreEqual("p4", process.FileName);
            Assert.AreEqual(expectedArgs, process.Arguments);
        }
예제 #19
0
 private string CreateClientSpecification(P4 p4, string workingDirectory)
 {
     return(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Client: {0}\n\nRoot:   {1}\n\nView:\n{2}", p4.Client, workingDirectory, GenerateClientView(p4.ViewForSpecifications, p4.Client)));
 }
 public void ShouldCheckViewIsValid()
 {
     P4 p4 = new P4();
     p4.View = "ThisIsNotAValidView";
     try
     {
         p4Initializer.Initialize(p4, "myProject", @"c:\my\working\dir");
         Assert.Fail("Should check for a valid view");
     }
     catch (CruiseControlException e)
     {
         Assert.IsTrue(e.Message.ToLower().IndexOf("valid view") > -1, "Should mention something about a valid view");
     }
     VerifyAll();
 }
        public void ShouldThrowExceptionIfProcessFails()
        {
            // Setup
            P4 p4 = new P4();
            p4.View = "//mydepot/...";
            string projectName = "myProject";

            string expectedClientName = string.Format("CCNet-{0}-{1}", Dns.GetHostName(), projectName);

            ProcessInfo processInfo = new ProcessInfo("createclient");
            ProcessInfo processInfoWithStdInContent = new ProcessInfo("createclient");
            processInfoWithStdInContent.StandardInputContent = string.Format("Client: {0}\n\nRoot:   c:\\my\\working\\dir\n\nView:\n //mydepot/... //{0}/mydepot/...\n", expectedClientName);

            processInfoCreatorMock.ExpectAndReturn("CreateProcessInfo", processInfo, p4, "client -i");
            processExecutorMock.ExpectAndReturn("Execute", new ProcessResult("This is standard out", "This is standard error", 1, false), processInfoWithStdInContent);

            // Execute
            try
            {
                p4Initializer.Initialize(p4, projectName, @"c:\my\working\dir");
                Assert.Fail("Should throw an exception since process result has a non zero exit code");
            }
            catch (CruiseControlException e)
            {
                Assert.IsTrue(e.Message.IndexOf("This is standard out") > -1);
                Assert.IsTrue(e.Message.IndexOf("This is standard error") > -1);
            }

            // Verify
            Assert.AreEqual(expectedClientName, p4.Client);
            VerifyAll();
        }
예제 #22
0
 private string CreateClientSpecification(P4 p4, string workingDirectory)
 {
     return(string.Format("Client: {0}\n\nRoot:   {1}\n\nView:\n{2}", p4.Client, workingDirectory, GenerateClientView(p4.ViewForSpecifications, p4.Client)));
 }
 private string CreateClientSpecification(P4 p4, string workingDirectory)
 {
     return string.Format(System.Globalization.CultureInfo.CurrentCulture, "Client: {0}\n\nRoot:   {1}\n\nView:\n{2}", p4.Client, workingDirectory, GenerateClientView(p4.ViewForSpecifications, p4.Client));
 }
        public void ShouldAllowViewsWithSpaces()
        {
            P4 p4 = new P4();
            p4.View = @"""//blah/my path with spaces/...""";
            processInfoCreatorMock.SetupResult("CreateProcessInfo", new ProcessInfo(""), typeof(P4), typeof(string));
            processExecutorMock.SetupResult("Execute", new ProcessResult("", "", 0, false), typeof(ProcessInfo));

            p4Initializer.Initialize(p4, "myProject", @"c:\my\working\dir");
            VerifyAll();
        }
예제 #25
0
 private P4 CreateP4WithNoArgContructor(string p4root)
 {
     P4 perforce = new P4();
     NetReflector.Read(p4root, perforce);
     return perforce;
 }
예제 #26
0
 private string CreateClientSpecification(P4 p4, string workingDirectory)
 {
     return string.Format("Client: {0}\n\nRoot:   {1}\n\nView:\n{2}", p4.Client, workingDirectory, GenerateClientView(p4.ViewForSpecifications, p4.Client));
 }