#if NET_2_0
using System;
+using System.Collections;
using System.Text;
+using System.Text.RegularExpressions;
using Microsoft.Build.Framework;
namespace Microsoft.Build.Utilities
public class CommandLineBuilder
{
StringBuilder commandLine;
+ static Hashtable chars;
+ static CommandLineBuilder ()
+ {
+ chars = new Hashtable ();
+
+ chars.Add (' ', null);
+ chars.Add ('\t', null);
+ chars.Add ('\n', null);
+ chars.Add ('\u000b', null);
+ chars.Add ('\u000c', null);
+ chars.Add ('\'', null);
+ chars.Add ('\"', null);
+ }
+
public CommandLineBuilder ()
{
commandLine = new StringBuilder ();
{
if (fileName == null)
return;
+
AppendSpaceIfNotEmpty ();
commandLine.Append (fileName);
}
{
if (fileItem == null)
return;
+
AppendSpaceIfNotEmpty ();
commandLine.Append (fileItem.ToString());
}
public void AppendFileNamesIfNotNull (string[] fileNames,
string delimiter)
{
+ if (delimiter == null)
+ throw new ArgumentNullException (null, "Parameter \"delimiter\" cannot be null.");
+
if (fileNames == null)
return;
+
bool appendDelimiter = false;
AppendSpaceIfNotEmpty ();
for (int i = 0; i < fileNames.Length; i++) {
public void AppendFileNamesIfNotNull (ITaskItem[] fileItems,
string delimiter)
{
+ if (delimiter == null)
+ throw new ArgumentNullException (null, "Parameter \"delimiter\" cannot be null.");
+
if (fileItems == null)
return;
+
bool appendDelimiter = false;
AppendSpaceIfNotEmpty ();
for (int i = 0; i < fileItems.Length; i++) {
}
}
- protected void AppendFileNamesWithQuoting (string fileName)
+ protected void AppendFileNameWithQuoting (string fileName)
{
if (IsQuotingRequired (fileName))
commandLine.AppendFormat ("\"{0}\"",fileName);
public void AppendSwitch (string switchName)
{
if (switchName == null)
- return;
+ throw new ArgumentNullException (null, "Parameter \"switchName\" cannot be null.");
+
AppendSpaceIfNotEmpty ();
commandLine.Append (switchName);
}
public void AppendSwitchIfNotNull (string switchName,
string parameter)
{
- if (switchName == null || parameter == null)
+ if (switchName == null)
+ throw new ArgumentNullException (null, "Parameter \"switchName\" cannot be null.");
+
+ if (parameter == null)
return;
+
AppendSpaceIfNotEmpty ();
commandLine.AppendFormat ("{0}{1}",switchName,
parameter);
public void AppendSwitchIfNotNull (string switchName,
ITaskItem parameter)
{
- if (switchName == null || parameter == null)
+ if (switchName == null)
+ throw new ArgumentNullException (null, "Parameter \"switchName\" cannot be null.");
+
+ if (parameter == null)
return;
+
AppendSpaceIfNotEmpty ();
commandLine.AppendFormat ("{0}{1}",switchName,
parameter.ToString ());
string[] parameters,
string delimiter)
{
- if (switchName == null || parameters == null)
+ if (switchName == null)
+ throw new ArgumentNullException (null, "Parameter \"switchName\" cannot be null.");
+
+ if (delimiter == null)
+ throw new ArgumentNullException (null, "Parameter \"delimiter\" cannot be null.");
+
+ if (parameters == null)
return;
+
AppendSpaceIfNotEmpty ();
commandLine.AppendFormat ("{0}",switchName);
bool appendDelimiter = false;
ITaskItem[] parameters,
string delimiter)
{
- if (switchName == null || parameters == null)
+ if (switchName == null)
+ throw new ArgumentNullException (null, "Parameter \"switchName\" cannot be null.");
+
+ if (delimiter == null)
+ throw new ArgumentNullException (null, "Parameter \"delimiter\" cannot be null.");
+
+ if (parameters == null)
return;
+
AppendSpaceIfNotEmpty ();
commandLine.AppendFormat ("{0}",switchName);
bool appendDelimiter = false;
public void AppendSwitchUnquotedIfNotNull (string switchName,
string parameter)
{
- if (switchName == null || parameter == null)
+ if (switchName == null)
+ throw new ArgumentNullException (null, "Parameter \"switchName\" cannot be null.");
+
+ if (parameter == null)
return;
+
AppendSpaceIfNotEmpty ();
commandLine.AppendFormat ("{0}{1}", switchName, parameter);
}
public void AppendSwitchUnquotedIfNotNull (string switchName,
ITaskItem parameter)
{
- if (switchName == null || parameter == null)
+ if (switchName == null)
+ throw new ArgumentNullException (null, "Parameter \"switchName\" cannot be null.");
+
+ if (parameter == null)
return;
+
AppendSpaceIfNotEmpty ();
- commandLine.AppendFormat ("{0}{1}", switchName, parameter.GetMetadata ("Include"));
+ commandLine.AppendFormat ("{0}{1}", switchName, parameter.ItemSpec);
}
public void AppendSwitchUnquotedIfNotNull (string switchName,
string[] parameters,
string delimiter)
{
- if (switchName == null || delimiter == null || parameters == null)
+ if (switchName == null)
+ throw new ArgumentNullException (null, "Parameter \"switchName\" cannot be null.");
+
+ if (delimiter == null)
+ throw new ArgumentNullException (null, "Parameter \"delimiter\" cannot be null.");
+
+ if (parameters == null)
return;
+
AppendSpaceIfNotEmpty ();
commandLine.AppendFormat ("{0}",switchName);
bool appendDelimiter = false;
ITaskItem[] parameters,
string delimiter)
{
- if (switchName == null || delimiter == null || parameters == null)
+ if (switchName == null)
+ throw new ArgumentNullException (null, "Parameter \"switchName\" cannot be null.");
+
+ if (delimiter == null)
+ throw new ArgumentNullException (null, "Parameter \"delimiter\" cannot be null.");
+
+ if (parameters == null)
return;
+
AppendSpaceIfNotEmpty ();
commandLine.AppendFormat ("{0}",switchName);
bool appendDelimiter = false;
parameter.Trim ();
// FIXME: change this to regex
foreach (char c in parameter) {
- if (c == ' ' || c == '\t' || c == '\u000b' || c == '\u000c')
+ if (chars.Contains (c))
return true;
}
return false;
}
+ [MonoTODO]
+ protected virtual void VerifyThrowNoEmbeddedDoubleQuotes (string switchName,
+ string parameter)
+ {
+ }
+
public override string ToString ()
{
return commandLine.ToString ();
}
}
-#endif
\ No newline at end of file
+#endif