[niftyplugins commit] r64 - in trunk: Build NiftyPerforce Shared

0 views
Skip to first unread message

codesite...@google.com

unread,
Feb 27, 2009, 2:23:37 AM2/27/09
to niftyplug...@googlegroups.com
Author: jim.tilander
Date: Thu Feb 26 23:22:57 2009
New Revision: 64

Added:
trunk/Shared/Process.cs
Modified:
trunk/Build/Experimental_NiftyPerforce.msi
trunk/Build/Experimental_NiftyPerforce2008.msi
trunk/Build/Experimental_NiftySolution.msi
trunk/Build/Experimental_NiftySolution2008.msi
trunk/NiftyPerforce/P4Operations.cs
trunk/Shared/AuroraCore.csproj

Log:
- Added support for reading out the correct client/port/user information
from the command line just before the timelapse view.

Modified: trunk/Build/Experimental_NiftyPerforce.msi
==============================================================================
Binary files. No diff available.

Modified: trunk/Build/Experimental_NiftyPerforce2008.msi
==============================================================================
Binary files. No diff available.

Modified: trunk/Build/Experimental_NiftySolution.msi
==============================================================================
Binary files. No diff available.

Modified: trunk/Build/Experimental_NiftySolution2008.msi
==============================================================================
Binary files. No diff available.

Modified: trunk/NiftyPerforce/P4Operations.cs
==============================================================================
--- trunk/NiftyPerforce/P4Operations.cs (original)
+++ trunk/NiftyPerforce/P4Operations.cs Thu Feb 26 23:22:57 2009
@@ -1,208 +1,239 @@
-// Copyright (C) 2006-2008 Jim Tilander. See COPYING for and README for
more details.
-using System;
-using EnvDTE;
-using System.Threading;
+// Copyright (C) 2006-2008 Jim Tilander. See COPYING for and README for
more details.
+using System;
+using EnvDTE;
+using System.Threading;
using System.Collections.Generic;
-using System.IO;
-
-namespace Aurora
-{
- namespace NiftyPerforce
- {
- // Simplification wrapper around running perforce commands.
- class P4Operations
- {
- public static bool IntegrateFile(OutputWindowPane output, string
filename, string oldName)
- {
- return ScheduleRunCommand(output, "p4.exe",
GetUserInfoString() + "integrate \"" + oldName + "\" \"" + filename + "\"",
System.IO.Path.GetDirectoryName(filename));
- }
-
- public static bool DeleteFile(OutputWindowPane output, string filename)
- {
- return ScheduleRunCommand(output, "p4.exe", GetUserInfoString()
+ "delete \"" + filename + "\"", System.IO.Path.GetDirectoryName(filename));
- }
-
- public static bool AddFile(OutputWindowPane output, string filename)
- {
- return ScheduleRunCommand(output, "p4.exe", GetUserInfoString() + "add
\"" + filename + "\"", System.IO.Path.GetDirectoryName(filename));
- }
-
- public static bool EditFile(OutputWindowPane output, string filename)
- {
- return ScheduleRunCommand(output, "p4.exe", GetUserInfoString()
+ "edit \"" + filename + "\"", System.IO.Path.GetDirectoryName(filename));
- }
-
- public static bool EditFileImmediate(OutputWindowPane output, string
filename)
- {
- return RunCommand(output, "p4.exe", GetUserInfoString() + "edit \"" +
filename + "\"", System.IO.Path.GetDirectoryName(filename),
m_commandCount++);
- }
-
- public static bool RevertFile(OutputWindowPane output, string
filename)
- {
- return ScheduleRunCommand(output, "p4.exe", GetUserInfoString()
+ "revert \"" + filename + "\"", System.IO.Path.GetDirectoryName(filename));
- }
-
- public static bool DiffFile(OutputWindowPane output, string
filename)
- {
- return ScheduleRunCommand(output, "p4win.exe", GetUserInfoString()
+ "-D \"" + filename + "\"", System.IO.Path.GetDirectoryName(filename));
- }
-
- public static bool RevisionHistoryFile(OutputWindowPane
output, string filename)
- {
- return ScheduleRunCommand(output, "p4win.exe", GetUserInfoString() + "
\"" + filename + "\"", System.IO.Path.GetDirectoryName(filename));
- }
-
- private static string GetUserInfoString()
- {
- // NOTE: This to allow the user to have a P4CONFIG variable and
connect to multiple perforce servers seamlessly.
- if( Singleton<Config>.Instance.useSystemEnv )
- return "";
-
- string arguments = "";
- arguments += " -p " + Singleton<Config>.Instance.port;
- arguments += " -u " + Singleton<Config>.Instance.username;
- arguments += " -c " + Singleton<Config>.Instance.client;
- arguments += " ";
- return arguments;
- }
-
- public static bool TimeLapseView(OutputWindowPane output, string
filename)
- {
- // NOTE: The timelapse view uses the undocumented feature for bringing
up the timelapse view. The username, client and port needs to be given in a
certain order to work (straight from perforce).
- string arguments = " -win 0 ";
- arguments += " -p " + Singleton<Config>.Instance.port;
- arguments += " -u " + Singleton<Config>.Instance.username;
- arguments += " -c " + Singleton<Config>.Instance.client;
- arguments += " -cmd \"annotate -i " + filename + "\"";
- return ScheduleRunCommand(output, "p4v.exe", arguments,
System.IO.Path.GetDirectoryName(filename));
- }
-
- private static bool ScheduleRunCommand(OutputWindowPane
output, string executableName, string command, string workingDirectory)
- {
- Command cmd = new Command();
- cmd.output = output;
- cmd.exe = executableName;
- cmd.arguments = command;
- cmd.workingDir = workingDirectory;
- cmd.sequence = m_commandCount++;
- try
- {
- m_queueLock.WaitOne();
- m_commandQueue.Enqueue(cmd);
- }
- finally
- {
- m_queueLock.ReleaseMutex();
- }
-
- m_startEvent.Release();
- output.OutputString(string.Format( "{0}: Scheduled {1} {2}\n",
cmd.sequence, cmd.exe, cmd.arguments ) );
- return true;
- }
-
- public static bool RunCommand(OutputWindowPane output, string
executableName, string command, string workingDirectory, int sequence)
- {
- System.Diagnostics.Process process = new System.Diagnostics.Process();
- process.StartInfo.UseShellExecute = false;
- process.StartInfo.FileName = executableName;
- process.StartInfo.RedirectStandardOutput = true;
- process.StartInfo.RedirectStandardError = true;
- process.StartInfo.CreateNoWindow = true;
- process.StartInfo.WorkingDirectory = workingDirectory;
- process.StartInfo.Arguments = command;
- if (!process.Start())
- {
- if (null != output)
- {
- output.OutputString(string.Format( "{0}: Failed to start {1}. Is
Perforce installed and in the path?\n", sequence, executableName ));
- }
- return false;
- }
- process.WaitForExit();
-
- string stdOut = process.StandardOutput.ReadToEnd();
- string stdErr = process.StandardError.ReadToEnd();
-
- if (null != output)
- {
- output.OutputString(sequence.ToString() + ": " + executableName + " "
+ command + "\n");
- output.OutputString(stdOut);
- output.OutputString(stdErr);
- }
-
- System.Diagnostics.Debug.WriteLine(command + "\n");
- System.Diagnostics.Debug.WriteLine(stdOut);
- System.Diagnostics.Debug.WriteLine(stdErr);
-
- if (0 != process.ExitCode)
- {
- if (null != output)
- {
- output.OutputString(sequence.ToString() + ":
Process exit code was " + process.ExitCode + ".\n");
- }
- return false;
- }
- return true;
- }
-
- private class Command
- {
- public string exe = "";
- public string arguments = "";
- public string workingDir = "";
- public OutputWindowPane output = null;
- public int sequence = 0;
-
-
- public void Run()
- {
- P4Operations.RunCommand(output, exe, arguments, workingDir, sequence);
- }
- };
-
- static private Mutex m_queueLock = new Mutex();
- static private Semaphore m_startEvent = new Semaphore(0, 9999);
- static private Queue<Command> m_commandQueue = new Queue<Command>();
- static private System.Threading.Thread m_helperThread;
- static private int m_commandCount = 0;
-
- public static void InitThreadHelper()
- {
- m_helperThread = new System.Threading.Thread(new
ThreadStart(ThreadMain));
- m_helperThread.Start();
- }
-
- public static void KillThreadHelper()
- {
- m_helperThread.Abort();
- }
-
- static public void ThreadMain()
- {
- while( true )
- {
- m_startEvent.WaitOne();
- Command cmd = null;
-
- try
- {
- m_queueLock.WaitOne();
- cmd = m_commandQueue.Dequeue();
- }
- finally
- {
- m_queueLock.ReleaseMutex();
- }
-
- try
- {
- System.Threading.Thread thread = new System.Threading.Thread( new
ThreadStart( cmd.Run ) );
- thread.Start();
- }
- catch
- {
- }
- }
+using System.IO;
+using System.Text.RegularExpressions;
+
+namespace Aurora
+{
+ namespace NiftyPerforce
+ {
+ // Simplification wrapper around running perforce commands.
+ class P4Operations
+ {
+ public static bool IntegrateFile(OutputWindowPane output, string
filename, string oldName)
+ {
+ return ScheduleRunCommand(output, "p4.exe",
GetUserInfoString() + "integrate \"" + oldName + "\" \"" + filename + "\"",
System.IO.Path.GetDirectoryName(filename));
+ }
+
+ public static bool DeleteFile(OutputWindowPane output, string filename)
+ {
+ return ScheduleRunCommand(output, "p4.exe", GetUserInfoString()
+ "delete \"" + filename + "\"", System.IO.Path.GetDirectoryName(filename));
+ }
+
+ public static bool AddFile(OutputWindowPane output, string filename)
+ {
+ return ScheduleRunCommand(output, "p4.exe", GetUserInfoString() + "add
\"" + filename + "\"", System.IO.Path.GetDirectoryName(filename));
+ }
+
+ public static bool EditFile(OutputWindowPane output, string filename)
+ {
+ return ScheduleRunCommand(output, "p4.exe", GetUserInfoString()
+ "edit \"" + filename + "\"", System.IO.Path.GetDirectoryName(filename));
+ }
+
+ public static bool EditFileImmediate(OutputWindowPane output, string
filename)
+ {
+ return RunCommand(output, "p4.exe", GetUserInfoString() + "edit \"" +
filename + "\"", System.IO.Path.GetDirectoryName(filename),
m_commandCount++);
+ }
+
+ public static bool RevertFile(OutputWindowPane output, string
filename)
+ {
+ return ScheduleRunCommand(output, "p4.exe", GetUserInfoString()
+ "revert \"" + filename + "\"", System.IO.Path.GetDirectoryName(filename));
+ }
+
+ public static bool DiffFile(OutputWindowPane output, string
filename)
+ {
+ return ScheduleRunCommand(output, "p4win.exe", GetUserInfoString()
+ "-D \"" + filename + "\"", System.IO.Path.GetDirectoryName(filename));
+ }
+
+ public static bool RevisionHistoryFile(OutputWindowPane
output, string filename)
+ {
+ return ScheduleRunCommand(output, "p4win.exe", GetUserInfoString() + "
\"" + filename + "\"", System.IO.Path.GetDirectoryName(filename));
+ }
+
+ private static string GetUserInfoString()
+ {
+ return GetUserInfoStringFull(false, "");
+ }
+
+ private static string GetUserInfoStringFull(bool lookup, string dir)
+ {
+ // NOTE: This to allow the user to have a P4CONFIG variable and
connect to multiple perforce servers seamlessly.
+ if( Singleton<Config>.Instance.useSystemEnv )
+ {
+ if(lookup)
+ {
+ try
+ {
+ string output = Process.Execute("p4", "-s -L \"{0}\" info", dir);
+ Regex userpattern = new Regex(@"User name: (?<user>.*)$",
RegexOptions.Compiled | RegexOptions.Multiline);
+ Regex portpattern = new Regex(@"Server address: (?<port>.*)$",
RegexOptions.Compiled | RegexOptions.Multiline);
+ Regex clientpattern = new Regex(@"Client name: (?<client>.*)$",
RegexOptions.Compiled | RegexOptions.Multiline);
+
+ Match usermatch = userpattern.Match(output);
+ Match portmatch = portpattern.Match(output);
+ Match clientmatch = clientpattern.Match(output);
+
+ string port = portmatch.Groups["port"].Value.Trim();
+ string username = usermatch.Groups["user"].Value.Trim();
+ string client = clientmatch.Groups["client"].Value.Trim();
+
+ return string.Format( " -p {0} -u {1} -c {2} ", port, username,
client);
+ }
+ catch(Process.Error e)
+ {
+ Log.Error( "Failed to execute info string discovery: {0}", e.info);
+ }
+ }
+
+ return "";
+ }
+
+ string arguments = "";
+ arguments += " -p " + Singleton<Config>.Instance.port;
+ arguments += " -u " + Singleton<Config>.Instance.username;
+ arguments += " -c " + Singleton<Config>.Instance.client;
+ arguments += " ";
+ return arguments;
+ }
+
+ public static bool TimeLapseView(OutputWindowPane output, string
filename)
+ {
+ // NOTE: The timelapse view uses the undocumented feature for bringing
up the timelapse view. The username, client and port needs to be given in a
certain order to work (straight from perforce).
+ string arguments = " -win 0 ";
+ arguments += GetUserInfoStringFull(true,
Path.GetDirectoryName(filename));
+ arguments += " -cmd \"annotate -i " + filename + "\"";
+ return ScheduleRunCommand(output, "p4v.exe", arguments,
System.IO.Path.GetDirectoryName(filename));
+ }
+
+ private static bool ScheduleRunCommand(OutputWindowPane
output, string executableName, string command, string workingDirectory)
+ {
+ Command cmd = new Command();
+ cmd.output = output;
+ cmd.exe = executableName;
+ cmd.arguments = command;
+ cmd.workingDir = workingDirectory;
+ cmd.sequence = m_commandCount++;
+ try
+ {
+ m_queueLock.WaitOne();
+ m_commandQueue.Enqueue(cmd);
+ }
+ finally
+ {
+ m_queueLock.ReleaseMutex();
+ }
+
+ m_startEvent.Release();
+ output.OutputString(string.Format( "{0}: Scheduled {1} {2}\n",
cmd.sequence, cmd.exe, cmd.arguments ) );
+ return true;
+ }
+
+ public static bool RunCommand(OutputWindowPane output, string
executableName, string command, string workingDirectory, int sequence)
+ {
+ System.Diagnostics.Process process = new System.Diagnostics.Process();
+ process.StartInfo.UseShellExecute = false;
+ process.StartInfo.FileName = executableName;
+ process.StartInfo.RedirectStandardOutput = true;
+ process.StartInfo.RedirectStandardError = true;
+ process.StartInfo.CreateNoWindow = true;
+ process.StartInfo.WorkingDirectory = workingDirectory;
+ process.StartInfo.Arguments = command;
+ if (!process.Start())
+ {
+ if (null != output)
+ {
+ output.OutputString(string.Format( "{0}: Failed to start {1}. Is
Perforce installed and in the path?\n", sequence, executableName ));
+ }
+ return false;
+ }
+ process.WaitForExit();
+
+ string stdOut = process.StandardOutput.ReadToEnd();
+ string stdErr = process.StandardError.ReadToEnd();
+
+ if (null != output)
+ {
+ output.OutputString(sequence.ToString() + ": " + executableName + " "
+ command + "\n");
+ output.OutputString(stdOut);
+ output.OutputString(stdErr);
+ }
+
+ System.Diagnostics.Debug.WriteLine(command + "\n");
+ System.Diagnostics.Debug.WriteLine(stdOut);
+ System.Diagnostics.Debug.WriteLine(stdErr);
+
+ if (0 != process.ExitCode)
+ {
+ if (null != output)
+ {
+ output.OutputString(sequence.ToString() + ":
Process exit code was " + process.ExitCode + ".\n");
+ }
+ return false;
+ }
+ return true;
+ }
+
+ private class Command
+ {
+ public string exe = "";
+ public string arguments = "";
+ public string workingDir = "";
+ public OutputWindowPane output = null;
+ public int sequence = 0;
+
+
+ public void Run()
+ {
+ P4Operations.RunCommand(output, exe, arguments, workingDir, sequence);
+ }
+ };
+
+ static private Mutex m_queueLock = new Mutex();
+ static private Semaphore m_startEvent = new Semaphore(0, 9999);
+ static private Queue<Command> m_commandQueue = new Queue<Command>();
+ static private System.Threading.Thread m_helperThread;
+ static private int m_commandCount = 0;
+
+ public static void InitThreadHelper()
+ {
+ m_helperThread = new System.Threading.Thread(new
ThreadStart(ThreadMain));
+ m_helperThread.Start();
+ }
+
+ public static void KillThreadHelper()
+ {
+ m_helperThread.Abort();
+ }
+
+ static public void ThreadMain()
+ {
+ while( true )
+ {
+ m_startEvent.WaitOne();
+ Command cmd = null;
+
+ try
+ {
+ m_queueLock.WaitOne();
+ cmd = m_commandQueue.Dequeue();
+ }
+ finally
+ {
+ m_queueLock.ReleaseMutex();
+ }
+
+ try
+ {
+ System.Threading.Thread thread = new System.Threading.Thread( new
ThreadStart( cmd.Run ) );
+ thread.Start();
+ }
+ catch
+ {
+ }
+ }
}

static public string ResolveFileNameWithCase(string fullpath)
@@ -222,8 +253,8 @@

// Should never happen...
return fullpath;
- }
- }
- }
-
-}
+ }
+ }
+ }
+
+}

Modified: trunk/Shared/AuroraCore.csproj
==============================================================================
--- trunk/Shared/AuroraCore.csproj (original)
+++ trunk/Shared/AuroraCore.csproj Thu Feb 26 23:22:57 2009
@@ -43,6 +43,7 @@
<Compile Include="DebugLogHandler.cs" />
<Compile Include="Log.cs" />
<Compile Include="Plugin.cs" />
+ <Compile Include="Process.cs" />
<Compile Include="Singleton.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="VisualStudioLogHandler.cs" />

Added: trunk/Shared/Process.cs
==============================================================================
--- (empty file)
+++ trunk/Shared/Process.cs Thu Feb 26 23:22:57 2009
@@ -0,0 +1,41 @@
+// Copyright (C) 2006-2008 Jim Tilander. See COPYING for and README for
more details.
+using System;
+
+namespace Aurora
+{
+ public static class Process
+ {
+ public class Error : System.Exception
+ {
+ public string info;
+ public Error(string info_, params object[] vaargs_) { info =
string.Format(info_, vaargs_); }
+ };
+
+ public static string Execute(string executable, string arguments, params
object[] vaargs)
+ {
+ System.Diagnostics.Process process = new System.Diagnostics.Process();
+ process.StartInfo.UseShellExecute = false;
+ process.StartInfo.FileName = executable;
+ process.StartInfo.RedirectStandardOutput = true;
+ process.StartInfo.RedirectStandardError = true;
+ process.StartInfo.CreateNoWindow = true;
+ process.StartInfo.Arguments = string.Format(arguments, vaargs);
+
+ if(!process.Start())
+ {
+ throw new Error("{0}: Failed to start {1}.", executable,
process.StartInfo.Arguments);
+ }
+ process.WaitForExit();
+
+ string stdOut = process.StandardOutput.ReadToEnd();
+ string stdErr = process.StandardError.ReadToEnd();
+
+ if(0 != process.ExitCode)
+ {
+ throw new Error("Failed to execute {0} {1}, exit code was {2}",
executable, process.StartInfo.Arguments, process.ExitCode);
+ }
+ return stdOut + "\n" + stdErr;
+ }
+ }
+}
+

Reply all
Reply to author
Forward
0 new messages