AppendSwitchUnquotedIfNotNull() public method

Appends the literal parameter without trying to quote. This method appends a space to the command line (if it's not currently empty) before the switch.
public AppendSwitchUnquotedIfNotNull ( string switchName, string parameter ) : void
switchName string The switch to append to the command line, may not be null
parameter string Switch parameter to append, not quoted. If null, this method has no effect.
return void
Exemplo n.º 1
0
 /// <summary>
 /// Utility function to help to generate Switch per item
 /// </summary>
 /// <param name="commandLine"></param>
 /// <param name="strSwitch"></param>
 /// <param name="args"></param>
 private static void GenerateSwitchPerItem(Utilities.CommandLineBuilder commandLine, string strSwitch, string args)
 {
     if (!string.IsNullOrEmpty(args))
     {
         foreach (string dl in args.Split(new char[] { ';' }))
         {
             if (!string.IsNullOrEmpty(dl))
             {
                 commandLine.AppendSwitchUnquotedIfNotNull(strSwitch, dl);
             }
         }
     }
 }
Exemplo n.º 2
0
        static public void AddSkipDirectiveToBaseOptions(Utilities.CommandLineBuilder commandLineBuilder, Framework.ITaskItem[] skipRuleItems, string valueQuoteChar)
        {
            if (commandLineBuilder != null &&
                skipRuleItems != null)   // Dev10 bug 496639 foreach will throw the exception if the replaceRuleItem is null
            {
                System.Collections.Generic.List <string> arguments = new System.Collections.Generic.List <string>(6);

                foreach (Framework.ITaskItem item in skipRuleItems)
                {
                    arguments.Clear();
                    MsDeploy.Utility.BuildArgumentsBaseOnEnumTypeName(item, arguments, typeof(MsDeploy.SkipRuleMetadata), valueQuoteChar);
                    commandLineBuilder.AppendSwitchUnquotedIfNotNull("-skip:", arguments.Count == 0? null : string.Join(",", arguments.ToArray()));
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Utility to build DeclareParameterOptions
        /// </summary>
        /// <param name="commandLineBuilder"></param>
        /// <param name="items"></param>
        static public void AddDeclareParametersOptions(Utilities.CommandLineBuilder commandLineBuilder, Framework.ITaskItem[] originalItems, string valueQuote, bool foptimisticParameterDefaultValue)
        {
            System.Collections.Generic.IList <Framework.ITaskItem> items = MsDeploy.Utility.SortParametersTaskItems(originalItems, foptimisticParameterDefaultValue, MsDeploy.DeclareParameterMetadata.DefaultValue.ToString());
            if (commandLineBuilder != null && items != null)
            {
                System.Collections.Generic.List <string> arguments = new System.Collections.Generic.List <string>(6);
                System.Collections.Generic.Dictionary <string, string> lookupDictionary = new System.Collections.Generic.Dictionary <string, string>(items.Count);

                foreach (Framework.ITaskItem item in items)
                {
                    AddDeclareParameterToCommandArgument(arguments, item, valueQuote, lookupDictionary);
                    commandLineBuilder.AppendSwitchUnquotedIfNotNull("-declareParam:", arguments.Count == 0 ? null : string.Join(",", arguments.ToArray()));
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Utility function to set SimpleeSyncParameter Name/Value
        /// </summary>
        /// <param name="commandLineBuilder"></param>
        /// <param name="items"></param>
        static public void AddSimpleSetParametersToObject(Utilities.CommandLineBuilder commandLineBuilder, Framework.ITaskItem[] originalItems, string valueQuoteChar, bool foptimisticParameterDefaultValue)
        {
            System.Collections.Generic.IList <Framework.ITaskItem> items = MsDeploy.Utility.SortParametersTaskItems(originalItems, foptimisticParameterDefaultValue, MsDeploy.SimpleSyncParameterMetadata.Value.ToString());
            if (commandLineBuilder != null && items != null)
            {
                System.Collections.Generic.List <string> arguments = new System.Collections.Generic.List <string>(6);
                foreach (Framework.ITaskItem item in items)
                {
                    arguments.Clear();

                    // special for name
                    string name = item.ItemSpec;
                    if (!string.IsNullOrEmpty(name))
                    {
                        string valueData = MsDeploy.Utility.PutValueInQuote(name, valueQuoteChar);
                        arguments.Add(string.Concat("name=", valueData));
                    }
                    // the rest, build on the enum name

                    MsDeploy.Utility.BuildArgumentsBaseOnEnumTypeName(item, arguments, typeof(MsDeploy.SimpleSyncParameterMetadata), valueQuoteChar);
                    commandLineBuilder.AppendSwitchUnquotedIfNotNull("-setParam:", arguments.Count == 0 ? null : string.Join(",", arguments.ToArray()));
                }
            }
        }
Exemplo n.º 5
0
		protected void AppendIntegerSwitch(CommandLineBuilder commandLine, string @switch, int value)
		{
			commandLine.AppendSwitchUnquotedIfNotNull(@switch, value.ToString(NumberFormatInfo.InvariantInfo));
		}
Exemplo n.º 6
0
		public void TestAppendUnquotedSwitchIfNotNull10 ()
		{
			clb = new CommandLineBuilder ();
			
			clb.AppendSwitchUnquotedIfNotNull ("/switch:", (ITaskItem[]) null, ";");
			
			Assert.AreEqual (String.Empty, clb.ToString (), "A1");
			
			clb.AppendSwitchUnquotedIfNotNull ("/switch:", items, ";");
			
			Assert.AreEqual ("/switch:a;b", clb.ToString (), "A2");
		}
Exemplo n.º 7
0
		public void TestAppendSwitchUnquotedIfNotNull8 ()
		{
			clb = new CommandLineBuilder ();
			
			clb.AppendSwitchUnquotedIfNotNull (null, items, "delimiter");
		}
Exemplo n.º 8
0
		public void TestAppendSwitchUnquotedIfNotNull4 ()
		{
			string name = "/switch:";
			
			clb = new CommandLineBuilder ();
			
			clb.AppendSwitchUnquotedIfNotNull (name, (ITaskItem) null);
			
			Assert.AreEqual (String.Empty, clb.ToString (), "A1");
			
			clb.AppendSwitchUnquotedIfNotNull (name, items [0]);
			
			Assert.AreEqual (name + items [0].ItemSpec, clb.ToString (), "A2");
		}
Exemplo n.º 9
0
        /// <summary>
        /// Generates the switches that have filenames attached to the end
        /// </summary>
        /// <remarks>For file switches (e.g., PrecompiledHeaderFile), the toolSwitchName (if it exists) is emitted
        /// along with the FileName which may or may not have quotes</remarks>
        /// e.g., PrecompiledHeaderFile = "File" will emit /FpFile
        /// <param name="clb"></param>
        /// <param name="toolSwitch"></param>
        private static void EmitFileSwitch(CommandLineBuilder clb, ToolSwitch toolSwitch)
        {
            if (!String.IsNullOrEmpty(toolSwitch.Value))
            {
                String str = toolSwitch.Value;
                str.Trim();

                if (!str.StartsWith("\""))
                {
                    str = "\"" + str;
                    if (str.EndsWith("\\") && !str.EndsWith("\\\\"))
                        str += "\\\"";
                    else
                        str += "\"";
                }

                //we want quotes always, AppendSwitchIfNotNull will add them on as needed bases 
                clb.AppendSwitchUnquotedIfNotNull(toolSwitch.SwitchValue + toolSwitch.Separator, str);
            }
        }
Exemplo n.º 10
0
        static public void AddDestinationProviderSettingToObject(Utilities.CommandLineBuilder commandLineBuilder, string dest, Framework.ITaskItem[] items, string valueQuoteChar,
                                                                 Framework.ITaskItem[] additionalProviderItems, MSDeploy msdeploy)
        {
            //commandLineBuilder.AppendSwitchUnquotedIfNotNull("-source:", m_source);
            //commandLineBuilder.AppendSwitchUnquotedIfNotNull("-dest:", m_dest);
            System.Collections.Generic.List <string> arguments = new System.Collections.Generic.List <string>(6);

            if (items != null && items.GetLength(0) == 1)
            {
                Framework.ITaskItem taskItem = items[0];
                string provider  = taskItem.ItemSpec;
                string path      = taskItem.GetMetadata("Path");
                string valueData = MsDeploy.Utility.PutValueInQuote(path, valueQuoteChar);
                string setData   = (string.IsNullOrEmpty(path)) ? provider : string.Concat(provider, "=", valueData);
                arguments.Add(setData);

                //Commonly supported provider settings:
                //    computerName=<name>     Name of remote computer or proxy-URL
                //    wmsvc=<name>            Name of remote computer or proxy-URL for the Web
                //                            Management Service (wmsvc)
                //    userName=<name>         User name to authenticate
                //    password=<password>     Password of user name
                //    encryptPassword=<pwd>   Password to use for encryption related operations
                //    includeAcls=<bool>      If true, include ACLs in the operation for the
                //                            specified path

                foreach (string name in taskItem.MetadataNames)
                {
                    if (!MsDeploy.Utility.IsInternalMsdeployWellKnownItemMetadata(name))
                    {
                        string value = taskItem.GetMetadata(name);
                        if (!string.IsNullOrEmpty(value))
                        {
                            valueData = MsDeploy.Utility.PutValueInQuote(value, valueQuoteChar);
                            setData   = string.Concat(name, "=", valueData);
                            arguments.Add(setData);
                        }
                    }
                    else
                    {
                        MsDeploy.Utility.IISExpressMetadata expressMetadata;
                        if (System.Enum.TryParse <MsDeploy.Utility.IISExpressMetadata>(name, out expressMetadata))
                        {
                            string value = taskItem.GetMetadata(name);
                            if (!string.IsNullOrEmpty(value))
                            {
                                switch (expressMetadata)
                                {
                                case Utility.IISExpressMetadata.WebServerAppHostConfigDirectory:
                                    msdeploy.WebServerAppHostConfigDirectory = value;
                                    break;

                                case Utility.IISExpressMetadata.WebServerDirectory:
                                    msdeploy.WebServerDirectory = value;
                                    break;

                                case Utility.IISExpressMetadata.WebServerManifest:
                                    msdeploy.WebServerManifest = value;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            // If additional parameters are specified, we add these too. the itemSpec will be something like iisApp, contentPath, etc and
            // each item should have a name\value pair defined as metadata. Each provider will be written as itemSpec.Name=Value
            if (additionalProviderItems != null)
            {
                foreach (Framework.ITaskItem item in additionalProviderItems)
                {
                    if (!string.IsNullOrEmpty(item.ItemSpec))
                    {
                        string settingName  = item.GetMetadata("Name");
                        string settingValue = item.GetMetadata("Value");
                        if (!string.IsNullOrEmpty(settingName) && !string.IsNullOrEmpty(settingValue))
                        {
                            string providerString = string.Concat(item.ItemSpec, ".", settingName, "=", settingValue);
                            arguments.Add(providerString);
                        }
                    }
                }
            }

            commandLineBuilder.AppendSwitchUnquotedIfNotNull(dest, arguments.Count == 0 ? null : string.Join(",", arguments.ToArray()));
            return;
        }
Exemplo n.º 11
0
 public void AppendSwitchUnquotedIfNotNull()
 {
     CommandLineBuilder c = new CommandLineBuilder();
     c.AppendSwitchUnquotedIfNotNull("/D", @"A"" \""B");
     Assert.Equal(@"/DA"" \""B", c.ToString());
 }
Exemplo n.º 12
0
        public void AppendSwitchWithParameterArrayNoQuotingTaskItem()
        {
            CommandLineBuilder c = new CommandLineBuilder();
            c.AppendSwitch("/something");
            c.AppendSwitchUnquotedIfNotNull("/switch:", new TaskItem[] { new TaskItem("Mer cury.cs"), null, new TaskItem("Ve nus.cs"), new TaskItem("Ear th.cs") }, ",");

            // Managed compilers use this function to append sources files.
            Assert.Equal("/something /switch:Mer cury.cs,,Ve nus.cs,Ear th.cs", c.ToString());
        }
Exemplo n.º 13
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    private void AppendIntValue (CommandLineBuilder builder, BaseProperty property, string value)
    {
      value = value.Trim ();

      string switchName = m_parsedBuildRule.SwitchPrefix + property.Switch;

      switchName += property.Separator;

      builder.AppendSwitchUnquotedIfNotNull (switchName, value);
    }
Exemplo n.º 14
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    private void AppendStringListValue (CommandLineBuilder builder, BaseProperty property, string subtype, string [] value, string delimiter)
    {
      string switchName = m_parsedBuildRule.SwitchPrefix + property.Switch;

      switchName += property.Separator;

      if (subtype == "file" || subtype == "folder")
      {
        builder.AppendSwitchUnquotedIfNotNull (switchName, value, delimiter);
      }
      else if (!string.IsNullOrEmpty (property.Switch))
      {
        builder.AppendSwitchUnquotedIfNotNull (switchName, value, delimiter);
      }
      else if (value.Length > 0)
      {
        foreach (string entry in value)
        {
          builder.AppendTextUnquoted (entry + delimiter);
        }
      }
    }
Exemplo n.º 15
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    private void AppendStringValue (CommandLineBuilder builder, BaseProperty property, string subtype, string value)
    {
      string switchName = property.SwitchPrefix;

      if (string.IsNullOrEmpty (property.SwitchPrefix))
      {
        switchName = m_parsedBuildRule.SwitchPrefix;
      }

      switchName += property.Switch + property.Separator;

      if (subtype == "file" || subtype == "folder")
      {
        if (!string.IsNullOrWhiteSpace (switchName))
        {
          builder.AppendSwitchIfNotNull (switchName, value);
        }
        else
        {
          builder.AppendTextUnquoted (" " + PathUtils.QuoteIfNeeded (value));
        }
      }
      else if (!string.IsNullOrEmpty (property.Switch))
      {
        builder.AppendSwitchUnquotedIfNotNull (switchName, value);
      }
      else if (!string.IsNullOrEmpty (value))
      {
        builder.AppendTextUnquoted (" " + value);
      }
    }
Exemplo n.º 16
0
        /// <summary>
        /// Generates the switches for switches that either have literal strings appended, or have 
        /// different switches based on what the property is set to.
        /// </summary>
        /// <remarks>The string switch emits a switch that depends on what the parameter is set to, with and
        /// arguments
        /// e.g., Optimization = "Full" will emit /Ox, whereas Optimization = "Disabled" will emit /Od</remarks>
        /// <param name="clb"></param>
        /// <param name="toolSwitch"></param>
        private void EmitStringSwitch(CommandLineBuilder clb, ToolSwitch toolSwitch)
        {
            String strSwitch = String.Empty;
            strSwitch += toolSwitch.SwitchValue + toolSwitch.Separator;
            
            StringBuilder val = new StringBuilder(GetEffectiveArgumentsValues(toolSwitch));
            String str = toolSwitch.Value;

            if (!toolSwitch.MultiValues)
            {

                str.Trim();

                if (!str.StartsWith("\""))
                {
                    str = "\"" + str;
                    if (str.EndsWith("\\") && !str.EndsWith("\\\\"))
                        str += "\\\"";
                    else
                        str += "\"";
                }
                val.Insert(0, str);
            }

            if ((strSwitch.Length == 0) && (val.ToString().Length == 0))
                return;

            clb.AppendSwitchUnquotedIfNotNull(strSwitch, val.ToString());
            
        }
Exemplo n.º 17
0
        /// <summary>
        /// Generates command line arguments for msdeploy.exe
        /// </summary>
        protected override string GenerateCommandLineCommands()
        {
            Utilities.CommandLineBuilder commandLine = new Utilities.CommandLineBuilder();
            AddDestinationProviderSettingToObject(commandLine, "-source:", this.Source, m_strValueQuote, null, this);
            AddDestinationProviderSettingToObject(commandLine, "-dest:", this.Destination, m_strValueQuote, AdditionalDestinationProviderOptions, this);

            commandLine.AppendSwitchUnquotedIfNotNull("-verb:", m_verb);
            commandLine.AppendSwitchUnquotedIfNotNull("-failureLevel:", m_failureLevel);
            commandLine.AppendSwitchUnquotedIfNotNull("-xpath:", m_xpath);
            commandLine.AppendSwitchUnquotedIfNotNull("-replace:", m_replace);
            commandLine.AppendSwitchUnquotedIfNotNull("-skip:", m_skip);

            GenerateSwitchPerItem(commandLine, "-enableRule:", m_enableRule);
            GenerateSwitchPerItem(commandLine, "-disableRule:", m_disableRule);
            GenerateSwitchPerItem(commandLine, "-enableLink:", m_enableLink);
            GenerateSwitchPerItem(commandLine, "-disableLink:", m_disableLink);
            GenerateSwitchPerItem(commandLine, "-disableSkipDirective:", m_disableSkipDirective);
            GenerateSwitchPerItem(commandLine, "-enableSkipDirective:", m_enableSkipDirective);

            // this allow multiple replace rule to happen, we should consider do the same thing for skip:
            AddReplaceRulesToOptions(commandLine, m_replaceRuleItemsITaskItem, m_strValueQuote);
            AddSkipDirectiveToBaseOptions(commandLine, m_skipRuleItemsITaskItem, m_strValueQuote);
            AddImportDeclareParametersFilesOptions(commandLine, m_importDeclareParametersItems);
            AddDeclareParametersOptions(commandLine, m_declareParameterItems, m_strValueQuote, OptimisticParameterDefaultValue);

            AddImportSetParametersFilesOptions(commandLine, m_importSetParametersItems);
            AddSimpleSetParametersToObject(commandLine, m_simpleSetParamterItems, m_strValueQuote, OptimisticParameterDefaultValue);
            AddSetParametersToObject(commandLine, m_setParamterItems, m_strValueQuote, OptimisticParameterDefaultValue);

            if (m_xml)
            {
                commandLine.AppendSwitch("-xml");
            }
            if (m_whatif)
            {
                commandLine.AppendSwitch("-whatif");
            }
            if (m_verbose)
            {
                commandLine.AppendSwitch("-verbose");
            }
            if (m_allowUntrusted)
            {
                commandLine.AppendSwitch("-allowUntrusted");
            }
            if (m_useChecksum)
            {
                commandLine.AppendSwitch("-useChecksum");
            }

            if (m_enableTransaction)
            {
                commandLine.AppendSwitch("-enableTransaction");
            }
            if (m_retryAttempts > 0)
            {
                commandLine.AppendSwitchUnquotedIfNotNull("-retryAttempts=", m_retryAttempts.ToString(CultureInfo.InvariantCulture));
            }
            if (m_retryInterval > 0)
            {
                commandLine.AppendSwitchUnquotedIfNotNull("-retryInterval=", m_retryInterval.ToString(CultureInfo.InvariantCulture));
            }

            if (!string.IsNullOrEmpty(UserAgent))
            {
                commandLine.AppendSwitchUnquotedIfNotNull("-userAgent=", string.Concat("\"", UserAgent, "\""));
            }

            //IISExpress support
            //public const string AppHostConfigDirectory = "-appHostConfigDir";
            // *    public const string WebServerDirectory = "-webServerDir";
            //      public const string WebServerManifest = "-webServerManifest";
            commandLine.AppendSwitchIfNotNull("-appHostConfigDir:", WebServerAppHostConfigDirectory);
            commandLine.AppendSwitchIfNotNull("-webServerDir:", WebServerDirectory);
            // bug in msdeploy.exe currently only take the file name
            commandLine.AppendSwitchIfNotNull("-webServerManifest:", System.IO.Path.GetFileName(WebServerManifest));

            m_lastCommandLine = commandLine.ToString();

            // show arguments in the output
            Log.LogMessage(Framework.MessageImportance.Low, string.Concat("\"", GenerateFullPathToTool(), "\" ", m_lastCommandLine));
            return(m_lastCommandLine);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Utility function to setParameters in type, scope, match, value of SyncParameter
        /// </summary>
        /// <param name="commandLineBuilder"></param>
        /// <param name="items"></param>
        static public void AddSetParametersToObject(Utilities.CommandLineBuilder commandLineBuilder, Framework.ITaskItem[] originalItems, string valueQuote, bool foptimisticParameterDefaultValue)
        {
            System.Collections.Generic.IList <Framework.ITaskItem> items = MsDeploy.Utility.SortParametersTaskItems(originalItems, foptimisticParameterDefaultValue, MsDeploy.ExistingSyncParameterMetadata.Value.ToString());
            if (commandLineBuilder != null && items != null)
            {
                System.Collections.Generic.List <string> arguments = new System.Collections.Generic.List <string>(6);
                System.Collections.Generic.Dictionary <string, string> lookupDictionary    = new System.Collections.Generic.Dictionary <string, string>(items.Count);
                System.Collections.Generic.Dictionary <string, string> nameValueDictionary = new System.Collections.Generic.Dictionary <string, string>(items.Count, System.StringComparer.OrdinalIgnoreCase);

                foreach (Framework.ITaskItem item in items)
                {
                    arguments.Clear();

                    System.Collections.Generic.List <string> idenities = new System.Collections.Generic.List <string>(6);

                    string name = item.ItemSpec;
                    if (!string.IsNullOrEmpty(name))
                    {
                        string element = item.GetMetadata(MsDeploy.ExistingParameterValiationMetadata.Element.ToString());
                        if (string.IsNullOrEmpty(element))
                        {
                            element = "parameterEntry";
                        }

                        if (string.Compare(element, "parameterEntry", System.StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            idenities.Add(name);
                            foreach (string dPIdentity in System.Enum.GetNames(typeof(MsDeploy.ExistingDeclareParameterMetadata)))
                            {
                                idenities.Add(item.GetMetadata(dPIdentity));
                            }

                            string identity = string.Join(",", idenities.ToArray());
                            if (!lookupDictionary.ContainsKey(identity))
                            {
                                string data          = null;
                                bool   fExistingName = nameValueDictionary.ContainsKey(name);

                                if (nameValueDictionary.ContainsKey(name))
                                {
                                    data = nameValueDictionary[name];
                                }
                                else
                                {
                                    data = item.GetMetadata(MsDeploy.ExistingSyncParameterMetadata.Value.ToString());
                                    nameValueDictionary.Add(name, data);
                                }

                                // the rest, build on the Enum Name
                                MsDeploy.Utility.BuildArgumentsBaseOnEnumTypeName(item, arguments, typeof(MsDeploy.ExistingDeclareParameterMetadata), valueQuote);
                                if (arguments.Count > 0 && !string.IsNullOrEmpty(data))
                                {
                                    arguments.Add(string.Concat(MsDeploy.ExistingSyncParameterMetadata.Value.ToString().ToLower(System.Globalization.CultureInfo.InvariantCulture),
                                                                "=", MsDeploy.Utility.PutValueInQuote(data, valueQuote)));
                                }
                                lookupDictionary.Add(identity, name);
                            }
                        }
                        else if (string.Compare(element, "parameterValidation", System.StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            System.Diagnostics.Debug.Assert(false, "msdeploy.exe doesn't support parameterValidation entry in the command line for declareParameter yet.");
                        }
                    }
                    commandLineBuilder.AppendSwitchUnquotedIfNotNull("-setParam:", arguments.Count == 0 ? null : string.Join(",", arguments.ToArray()));
                }
            }
        }
Exemplo n.º 19
0
		public void TestAppendSwitchUnquotedIfNotNull2 ()
		{
			string name = "/switch:";
			string parameter = "parameter";
			
			clb = new CommandLineBuilder ();
			
			clb.AppendSwitchUnquotedIfNotNull (name, (string) null);
			
			Assert.AreEqual (String.Empty, clb.ToString (), "A1");
			
			clb.AppendSwitchUnquotedIfNotNull (name, parameter);
			
			Assert.AreEqual (name + parameter, clb.ToString (), "A2");
		}
Exemplo n.º 20
0
 public void AppendSwitchUnQuotedTaskItem()
 {
     CommandLineBuilder c = new CommandLineBuilder(true);
     c.AppendSwitchUnquotedIfNotNull("/D", new TaskItem(@"foo-bar"));
     Assert.Equal(@"/Dfoo-bar", c.ToString());
 }
Exemplo n.º 21
0
        /// <summary>
        /// Generates the switches for switches that either have literal strings appended, or have
        /// different switches based on what the property is set to.
        /// </summary>
        /// <remarks>The string switch emits a switch that depends on what the parameter is set to, with and
        /// arguments
        /// e.g., Optimization = "Full" will emit /Ox, whereas Optimization = "Disabled" will emit /Od</remarks>
        private void EmitStringSwitch(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch)
        {
            if (PerformSwitchValueSubstition(clb, commandLineToolSwitch, commandLineToolSwitch.Value))
            {
                return;
            }

            String strSwitch = String.Empty;
            strSwitch += commandLineToolSwitch.SwitchValue + commandLineToolSwitch.Separator;

            String str = commandLineToolSwitch.Value;
            if (!commandLineToolSwitch.AllowMultipleValues)
            {
                str = str.Trim();
                if (str.Contains(' '))
                {
                    if (!str.StartsWith("\"", StringComparison.OrdinalIgnoreCase))
                    {
                        str = "\"" + str;
                        if (str.EndsWith(@"\", StringComparison.OrdinalIgnoreCase) && !str.EndsWith(@"\\", StringComparison.OrdinalIgnoreCase))
                        {
                            str += "\\\"";
                        }
                        else
                        {
                            str += "\"";
                        }
                    }
                }
            }
            else
            {
                strSwitch = String.Empty;
                str = commandLineToolSwitch.SwitchValue;
                string arguments = GatherArguments(commandLineToolSwitch.Name, commandLineToolSwitch.Arguments, commandLineToolSwitch.Separator);
                if (!String.IsNullOrEmpty(arguments))
                {
                    str = str + commandLineToolSwitch.Separator + arguments;
                }
            }

            clb.AppendSwitchUnquotedIfNotNull(strSwitch, str);
        }
Exemplo n.º 22
0
		public void TestAppendSwitchUnquotedIfNotNull1 ()
		{
			clb = new CommandLineBuilder ();
			
			clb.AppendSwitchUnquotedIfNotNull (null, "parameter");
		}
Exemplo n.º 23
0
 public void AppendLiteralSwitchWithSpacesInParameter()
 {
     CommandLineBuilder c = new CommandLineBuilder();
     c.AppendSwitchUnquotedIfNotNull("/animal:", "dog and pony");
     Assert.Equal("/animal:dog and pony", c.ToString());
 }
Exemplo n.º 24
0
		public void TestAppendSwitchUnquotedIfNotNull3 ()
		{
			clb = new CommandLineBuilder ();
			
			clb.AppendSwitchUnquotedIfNotNull (null, items [0]);
		}
Exemplo n.º 25
0
        // helper for string-based properties
        private void AppendStringValue(CommandLineBuilder builder, BaseProperty property, string subtype, string value)
        {
            value = value.Trim();

            // could cache this SubType test off in property wrapper or somewhere if performance were an issue
            string switchName = m_parsedBuildRule.SwitchPrefix + property.Switch;
            switchName += property.Separator;
            if (subtype == "file" || subtype == "folder")
            {
                // for switches that contains files or folders we need quoting
                builder.AppendSwitchIfNotNull(switchName, value);
            }
            else if (!string.IsNullOrEmpty(property.Switch))
            {
                builder.AppendSwitchUnquotedIfNotNull(switchName, value);
            }
            else if (!string.IsNullOrEmpty(value))
            {
                // for non-switches such as AdditionalOptions we just append the value
                builder.AppendTextUnquoted(" " + value);
            }
        }
Exemplo n.º 26
0
		public void TestAppendSwitchUnquotedIfNotNull7 ()
		{
			clb = new CommandLineBuilder ();
			
			clb.AppendSwitchUnquotedIfNotNull ("/switch:", (string[]) null, ";");
			
			Assert.AreEqual (String.Empty, clb.ToString (), "A1");
			
			clb.AppendSwitchUnquotedIfNotNull ("/switch:", array, ";");
			
			Assert.AreEqual ("/switch:a;b;c", clb.ToString (), "A2");

			clb.AppendSwitchUnquotedIfNotNull ("/switch:", new string[] { "a'b", "c", "d" }, ";");
			Assert.AreEqual ("/switch:a;b;c /switch:a'b;c;d", clb.ToString(), "A3");
		}
Exemplo n.º 27
0
 private void GenerateArgumentBool(CommandLineBuilder builder, BaseProperty property, string value)
 {
     if (value == "true")
     {
         builder.AppendSwitchUnquotedIfNotNull(m_parsedBuildRule.SwitchPrefix, property.Switch);
     }
     else if (value == "false" && ((BoolProperty)property).ReverseSwitch != null)
     {
         builder.AppendSwitchUnquotedIfNotNull(m_parsedBuildRule.SwitchPrefix, ((BoolProperty)property).ReverseSwitch);
     }
 }
Exemplo n.º 28
0
		public void TestAppendSwitchUnquotedIfNotNull9 ()
		{
			clb = new CommandLineBuilder ();
			
			clb.AppendSwitchUnquotedIfNotNull ("/switch", items, null);
		}
Exemplo n.º 29
0
 private void GenerateArgumentEnum(CommandLineBuilder builder, BaseProperty property, string value)
 {
     var result = ((EnumProperty)property).AdmissibleValues.Find(x => (x.Name == value));
     if (result != null)
     {
         builder.AppendSwitchUnquotedIfNotNull(m_parsedBuildRule.SwitchPrefix, result.Switch);
     }
 }
Exemplo n.º 30
0
		public void TestEmbeddedQuotes9()
		{
			CommandLineBuilder clb = new CommandLineBuilder();
			clb.AppendSwitchUnquotedIfNotNull("foo", new TaskItem("a\"b"));
			clb.AppendSwitchUnquotedIfNotNull("foo", "a\"b");
			clb.AppendSwitchUnquotedIfNotNull("foo", new ITaskItem[] { new TaskItem ("xyz"), new TaskItem("a\"b") }, ":");
			clb.AppendSwitchUnquotedIfNotNull("foo", new string[] { "xyz", "a\"b" }, ":");
		}
Exemplo n.º 31
0
        /// <summary>
        /// Append each of the define constants to the command line.
        /// </summary>
        /// <param name="commandLine">Command line builder.</param>
        internal static void AppendExtensions(CommandLineBuilder commandLine, ITaskItem[] extensions, TaskLoggingHelper log)
        {
            if (extensions == null)
            {
                // No items
                return;
            }

            for (int i = 0; i < extensions.Length; i++)
            {
                string className = extensions[i].GetMetadata("Class");
                if (String.IsNullOrEmpty(className))
                {
                    log.LogError(String.Format("Missing the required property 'Class' for the extension {0}", extensions[i].ItemSpec));
                }

                commandLine.AppendSwitchUnquotedIfNotNull("-ext ", String.Concat(className, ",", extensions[i].ItemSpec));
            }
        }