internal void GenerateCommandsAccordingToType(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch, bool recursive)
        {
            if ((commandLineToolSwitch.Parents.Count <= 0) || recursive)
            {
                switch (commandLineToolSwitch.Type)
                {
                case CommandLineToolSwitchType.Boolean:
                    this.EmitBooleanSwitch(clb, commandLineToolSwitch);
                    return;

                case CommandLineToolSwitchType.Integer:
                    this.EmitIntegerSwitch(clb, commandLineToolSwitch);
                    return;

                case CommandLineToolSwitchType.String:
                    this.EmitStringSwitch(clb, commandLineToolSwitch);
                    return;

                case CommandLineToolSwitchType.StringArray:
                    this.EmitStringArraySwitch(clb, commandLineToolSwitch);
                    return;

                case CommandLineToolSwitchType.ITaskItemArray:
                    EmitTaskItemArraySwitch(clb, commandLineToolSwitch);
                    return;
                }
                Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(false, "InternalError");
            }
        }
Esempio n. 2
0
        private static bool PerformSwitchValueSubstition(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch, string switchValue)
        {
            Regex regex = new Regex(@"\[value]", RegexOptions.IgnoreCase);
            Match match = regex.Match(commandLineToolSwitch.SwitchValue);

            if (match.Success)
            {
                string prefixToAppend = commandLineToolSwitch.SwitchValue.Substring(match.Index + match.Length, commandLineToolSwitch.SwitchValue.Length - (match.Index + match.Length));
                string valueToAppend;
                if (!switchValue.EndsWith("\\\\", StringComparison.OrdinalIgnoreCase) && switchValue.EndsWith("\\", StringComparison.OrdinalIgnoreCase) && prefixToAppend.Length > 0 && prefixToAppend[0] == '\"')
                {
                    // If the combined string would create \" then we need to escape it
                    // if the combined string would create \\" then we ignore it as as assume it is already escaped.
                    valueToAppend = commandLineToolSwitch.SwitchValue.Substring(0, match.Index) + switchValue + "\\" + prefixToAppend;
                }
                else
                {
                    valueToAppend = commandLineToolSwitch.SwitchValue.Substring(0, match.Index) + switchValue + prefixToAppend;
                }

                clb.AppendSwitch(valueToAppend);
                return(true);
            }

            return(false);
        }
 private void EmitStringSwitch(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch)
 {
     if (!this.PerformSwitchValueSubstition(clb, commandLineToolSwitch, commandLineToolSwitch.Value))
     {
         string switchName = string.Empty + commandLineToolSwitch.SwitchValue + commandLineToolSwitch.Separator;
         string source     = commandLineToolSwitch.Value;
         if (!commandLineToolSwitch.AllowMultipleValues)
         {
             source = source.Trim();
             if (source.Contains <char>(' ') && !source.StartsWith("\"", StringComparison.OrdinalIgnoreCase))
             {
                 source = "\"" + source;
                 if (source.EndsWith(@"\", StringComparison.OrdinalIgnoreCase) && !source.EndsWith(@"\\", StringComparison.OrdinalIgnoreCase))
                 {
                     source = source + "\\\"";
                 }
                 else
                 {
                     source = source + "\"";
                 }
             }
         }
         else
         {
             switchName = string.Empty;
             source     = commandLineToolSwitch.SwitchValue;
         }
         clb.AppendSwitchUnquotedIfNotNull(switchName, source);
     }
 }
 private void EmitReversibleBooleanSwitch(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch)
 {
     if (!string.IsNullOrEmpty(commandLineToolSwitch.ReverseSwitchValue))
     {
         string        str     = commandLineToolSwitch.BooleanValue ? commandLineToolSwitch.TrueSuffix : commandLineToolSwitch.FalseSuffix;
         StringBuilder builder = new StringBuilder();
         builder.Insert(0, str);
         builder.Insert(0, commandLineToolSwitch.Separator);
         builder.Insert(0, commandLineToolSwitch.TrueSuffix);
         builder.Insert(0, commandLineToolSwitch.ReverseSwitchValue);
         clb.AppendSwitch(builder.ToString());
     }
 }
 public void AddActiveSwitchToolValue(CommandLineToolSwitch switchToAdd)
 {
     if ((switchToAdd.Type != CommandLineToolSwitchType.Boolean) || switchToAdd.BooleanValue)
     {
         if (switchToAdd.SwitchValue != string.Empty)
         {
             this.ActiveToolSwitchesValues.Add(switchToAdd.SwitchValue, switchToAdd);
         }
     }
     else if (switchToAdd.ReverseSwitchValue != string.Empty)
     {
         this.ActiveToolSwitchesValues.Add(switchToAdd.ReverseSwitchValue, switchToAdd);
     }
 }
        internal bool VerifyDependenciesArePresent(CommandLineToolSwitch property)
        {
            if (property.Parents.Count <= 0)
            {
                return(true);
            }
            bool flag = false;

            foreach (string str in property.Parents)
            {
                flag = flag || this.HasSwitch(str);
            }
            return(flag);
        }
Esempio n. 7
0
 private static void EmitTaskItemArraySwitch(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch)
 {
     if (String.IsNullOrEmpty(commandLineToolSwitch.Separator))
     {
         foreach (ITaskItem itemName in commandLineToolSwitch.TaskItemArray)
         {
             clb.AppendSwitchIfNotNull(commandLineToolSwitch.SwitchValue, itemName.ItemSpec);
         }
     }
     else
     {
         clb.AppendSwitchIfNotNull(commandLineToolSwitch.SwitchValue, commandLineToolSwitch.TaskItemArray, commandLineToolSwitch.Separator);
     }
 }
 public void AddActiveSwitchToolValue(CommandLineToolSwitch switchToAdd)
 {
     if ((switchToAdd.Type != CommandLineToolSwitchType.Boolean) || switchToAdd.BooleanValue)
     {
         if (switchToAdd.SwitchValue != string.Empty)
         {
             this.ActiveToolSwitchesValues.Add(switchToAdd.SwitchValue, switchToAdd);
         }
     }
     else if (switchToAdd.ReverseSwitchValue != string.Empty)
     {
         this.ActiveToolSwitchesValues.Add(switchToAdd.ReverseSwitchValue, switchToAdd);
     }
 }
Esempio n. 9
0
 private static void EmitReversibleBooleanSwitch(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch)
 {
     // if the value is set to true, append whatever the TrueSuffix is set to.
     // Otherwise, append whatever the FalseSuffix is set to.
     if (!String.IsNullOrEmpty(commandLineToolSwitch.ReverseSwitchValue))
     {
         string        suffix = (commandLineToolSwitch.BooleanValue) ? commandLineToolSwitch.TrueSuffix : commandLineToolSwitch.FalseSuffix;
         StringBuilder val    = new StringBuilder();
         val.Insert(0, suffix);
         val.Insert(0, commandLineToolSwitch.Separator);
         val.Insert(0, commandLineToolSwitch.TrueSuffix);
         val.Insert(0, commandLineToolSwitch.ReverseSwitchValue);
         clb.AppendSwitch(val.ToString());
     }
 }
Esempio n. 10
0
        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);
        }
 private void EmitIntegerSwitch(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch)
 {
     if (commandLineToolSwitch.IsValid)
     {
         string switchValue = commandLineToolSwitch.Number.ToString(Thread.CurrentThread.CurrentCulture);
         if (!this.PerformSwitchValueSubstition(clb, commandLineToolSwitch, switchValue))
         {
             if (!string.IsNullOrEmpty(commandLineToolSwitch.Separator))
             {
                 clb.AppendSwitch(commandLineToolSwitch.SwitchValue + commandLineToolSwitch.Separator + switchValue);
             }
             else
             {
                 clb.AppendSwitch(commandLineToolSwitch.SwitchValue + switchValue);
             }
         }
     }
 }
 private void EmitBooleanSwitch(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch)
 {
     if (commandLineToolSwitch.BooleanValue)
     {
         if (!string.IsNullOrEmpty(commandLineToolSwitch.SwitchValue))
         {
             StringBuilder builder = new StringBuilder();
             builder.Insert(0, commandLineToolSwitch.Separator);
             builder.Insert(0, commandLineToolSwitch.TrueSuffix);
             builder.Insert(0, commandLineToolSwitch.SwitchValue);
             clb.AppendSwitch(builder.ToString());
         }
     }
     else
     {
         this.EmitReversibleBooleanSwitch(clb, commandLineToolSwitch);
     }
 }
Esempio n. 13
0
 /// <summary>
 /// Add the value for a switch to the list of active values
 /// </summary>
 public void AddActiveSwitchToolValue(CommandLineToolSwitch switchToAdd)
 {
     if (((switchToAdd.Type != CommandLineToolSwitchType.Boolean) ||
          (switchToAdd.BooleanValue == true)))
     {
         if ((switchToAdd.SwitchValue != String.Empty))
         {
             ActiveToolSwitchesValues.Add(switchToAdd.SwitchValue, switchToAdd);
         }
     }
     else
     {
         if ((switchToAdd.ReverseSwitchValue != String.Empty))
         {
             ActiveToolSwitchesValues.Add(switchToAdd.ReverseSwitchValue, switchToAdd);
         }
     }
 }
Esempio n. 14
0
 private static void EmitBooleanSwitch(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch)
 {
     if (commandLineToolSwitch.BooleanValue)
     {
         if (!String.IsNullOrEmpty(commandLineToolSwitch.SwitchValue))
         {
             StringBuilder val = new StringBuilder();
             val.Insert(0, commandLineToolSwitch.Separator);
             val.Insert(0, commandLineToolSwitch.TrueSuffix);
             val.Insert(0, commandLineToolSwitch.SwitchValue);
             clb.AppendSwitch(val.ToString());
         }
     }
     else
     {
         EmitReversibleBooleanSwitch(clb, commandLineToolSwitch);
     }
 }
Esempio n. 15
0
        private static void EmitStringArraySwitch(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch)
        {
            var stringList = new List <string>(commandLineToolSwitch.StringList.Length);

            for (int i = 0; i < commandLineToolSwitch.StringList.Length; ++i)
            {
                // Make sure the file doesn't contain escaped " (\")
                string value;
                if (commandLineToolSwitch.StringList[i].StartsWith("\"", StringComparison.OrdinalIgnoreCase) && commandLineToolSwitch.StringList[i].EndsWith("\"", StringComparison.OrdinalIgnoreCase))
                {
                    value = commandLineToolSwitch.StringList[i].Substring(1, commandLineToolSwitch.StringList[i].Length - 2).Trim();
                }
                else
                {
                    value = commandLineToolSwitch.StringList[i].Trim();
                }

                if (!String.IsNullOrEmpty(value))
                {
                    stringList.Add(value);
                }
            }

            string[] arrTrimStringList = stringList.ToArray();

            if (String.IsNullOrEmpty(commandLineToolSwitch.Separator))
            {
                foreach (string fileName in arrTrimStringList)
                {
                    if (!PerformSwitchValueSubstition(clb, commandLineToolSwitch, fileName))
                    {
                        clb.AppendSwitchIfNotNull(commandLineToolSwitch.SwitchValue, fileName);
                    }
                }
            }
            else
            {
                if (!PerformSwitchValueSubstition(clb, commandLineToolSwitch, String.Join(commandLineToolSwitch.Separator, arrTrimStringList)))
                {
                    clb.AppendSwitchIfNotNull(commandLineToolSwitch.SwitchValue, arrTrimStringList, commandLineToolSwitch.Separator);
                }
            }
        }
Esempio n. 16
0
 private static void EmitIntegerSwitch(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch)
 {
     if (commandLineToolSwitch.IsValid)
     {
         string numberAsString = commandLineToolSwitch.Number.ToString(System.Threading.Thread.CurrentThread.CurrentCulture);
         if (PerformSwitchValueSubstition(clb, commandLineToolSwitch, numberAsString))
         {
             return;
         }
         else if (!String.IsNullOrEmpty(commandLineToolSwitch.Separator))
         {
             clb.AppendSwitch(commandLineToolSwitch.SwitchValue + commandLineToolSwitch.Separator + numberAsString);
         }
         else
         {
             clb.AppendSwitch(commandLineToolSwitch.SwitchValue + numberAsString);
         }
     }
 }
Esempio n. 17
0
        private void GenerateStandardCommandLine(CommandLineBuilder builder, bool allOptionsMode)
        {
            // iterates through the list of set CommandLineToolSwitches
            foreach (string propertyName in _switchOrderList)
            {
                if (IsPropertySet(propertyName))
                {
                    CommandLineToolSwitch property = _activeCommandLineToolSwitches[propertyName];

                    if (allOptionsMode)
                    {
                        if (property.Type == CommandLineToolSwitchType.ITaskItemArray)
                        {
                            // If we are in all-options mode, we will ignore any "switches" which are item arrays.
                            continue;
                        }
                        else if (String.Equals(propertyName, "AdditionalOptions", StringComparison.OrdinalIgnoreCase))
                        {
                            // If we are handling the [AllOptions], then skip the AdditionalOptions, which is handled later.
                            continue;
                        }
                    }

                    // verify the dependencies
                    if (property.IncludeInCommandLine && VerifyDependenciesArePresent(property) && VerifyRequiredArgumentsArePresent(property, false))
                    {
                        GenerateCommandsAccordingToType(builder, property, false);
                    }
                }
                else if (String.Equals(propertyName, "AlwaysAppend", StringComparison.OrdinalIgnoreCase))
                {
                    builder.AppendSwitch(AlwaysAppend);
                }
            }

            if (!allOptionsMode)
            {
                // additional args should go on the end
                BuildAdditionalArgs(builder);
            }
        }
 private void GenerateStandardCommandLine(CommandLineBuilder builder, bool allOptionsMode)
 {
     foreach (string str in this.switchOrderList)
     {
         if (this.IsPropertySet(str))
         {
             CommandLineToolSwitch property = this.activeCommandLineToolSwitches[str];
             if ((!allOptionsMode || ((property.Type != CommandLineToolSwitchType.ITaskItemArray) && !string.Equals(str, "AdditionalOptions", StringComparison.OrdinalIgnoreCase))) && (this.VerifyDependenciesArePresent(property) && this.VerifyRequiredArgumentsArePresent(property, false)))
             {
                 this.GenerateCommandsAccordingToType(builder, property, false);
             }
         }
         else if (string.Equals(str, "AlwaysAppend", StringComparison.OrdinalIgnoreCase))
         {
             builder.AppendSwitch(this.AlwaysAppend);
         }
     }
     if (!allOptionsMode)
     {
         this.BuildAdditionalArgs(builder);
     }
 }
        private bool PerformSwitchValueSubstition(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch, string switchValue)
        {
            string str2;
            Match  match = new Regex(@"\[value]", RegexOptions.IgnoreCase).Match(commandLineToolSwitch.SwitchValue);

            if (!match.Success)
            {
                return(false);
            }
            string str = commandLineToolSwitch.SwitchValue.Substring(match.Index + match.Length, commandLineToolSwitch.SwitchValue.Length - (match.Index + match.Length));

            if ((!switchValue.EndsWith(@"\\", StringComparison.OrdinalIgnoreCase) && switchValue.EndsWith(@"\", StringComparison.OrdinalIgnoreCase)) && (str[0] == '"'))
            {
                str2 = commandLineToolSwitch.SwitchValue.Substring(0, match.Index) + switchValue + @"\" + str;
            }
            else
            {
                str2 = commandLineToolSwitch.SwitchValue.Substring(0, match.Index) + switchValue + str;
            }
            clb.AppendSwitch(str2);
            return(true);
        }
Esempio n. 20
0
        internal bool VerifyDependenciesArePresent(CommandLineToolSwitch property)
        {
            // check the dependency
            if (property.Parents.Count > 0)
            {
                // has a dependency, now check to see whether at least one parent is set
                // if it is set, add to the command line
                // otherwise, ignore it
                bool isSet = false;
                foreach (string parentName in property.Parents)
                {
                    isSet = isSet || HasSwitch(parentName);
                }

                return(isSet);
            }
            else
            {
                // no dependencies to account for
                return(true);
            }
        }
        private void EmitStringArraySwitch(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch)
        {
            List <string> list = new List <string>(commandLineToolSwitch.StringList.Length);

            for (int i = 0; i < commandLineToolSwitch.StringList.Length; i++)
            {
                string str;
                if (commandLineToolSwitch.StringList[i].StartsWith("\"", StringComparison.OrdinalIgnoreCase) && commandLineToolSwitch.StringList[i].EndsWith("\"", StringComparison.OrdinalIgnoreCase))
                {
                    str = commandLineToolSwitch.StringList[i].Substring(1, commandLineToolSwitch.StringList[i].Length - 2).Trim();
                }
                else
                {
                    str = commandLineToolSwitch.StringList[i].Trim();
                }
                if (!string.IsNullOrEmpty(str))
                {
                    list.Add(str);
                }
            }
            string[] strArray = list.ToArray();
            if (string.IsNullOrEmpty(commandLineToolSwitch.Separator))
            {
                foreach (string str2 in strArray)
                {
                    if (!this.PerformSwitchValueSubstition(clb, commandLineToolSwitch, str2))
                    {
                        clb.AppendSwitchIfNotNull(commandLineToolSwitch.SwitchValue, str2);
                    }
                }
            }
            else if (!this.PerformSwitchValueSubstition(clb, commandLineToolSwitch, string.Join(commandLineToolSwitch.Separator, strArray)))
            {
                clb.AppendSwitchIfNotNull(commandLineToolSwitch.SwitchValue, strArray, commandLineToolSwitch.Separator);
            }
        }
Esempio n. 22
0
        internal void GenerateCommandsAccordingToType(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch, bool recursive)
        {
            // if this property has a parent skip printing it as it was printed as part of the parent prop printing
            if (commandLineToolSwitch.Parents.Count > 0 && !recursive)
            {
                return;
            }

            switch (commandLineToolSwitch.Type)
            {
            case CommandLineToolSwitchType.Boolean:
                EmitBooleanSwitch(clb, commandLineToolSwitch);
                break;

            case CommandLineToolSwitchType.String:
                EmitStringSwitch(clb, commandLineToolSwitch);
                break;

            case CommandLineToolSwitchType.StringArray:
                EmitStringArraySwitch(clb, commandLineToolSwitch);
                break;

            case CommandLineToolSwitchType.Integer:
                EmitIntegerSwitch(clb, commandLineToolSwitch);
                break;

            case CommandLineToolSwitchType.ITaskItemArray:
                EmitTaskItemArraySwitch(clb, commandLineToolSwitch);
                break;

            default:
                // should never reach this point - if it does, there's a bug somewhere.
                ErrorUtilities.ThrowInternalError("InternalError");
                break;
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Substitute the value for the switch into the switch value where the [value] string is found, if it exists.
        /// </summary>
        private bool PerformSwitchValueSubstition(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch, string switchValue)
        {
            Regex regex = new Regex(@"\[value]", RegexOptions.IgnoreCase);
            Match match = regex.Match(commandLineToolSwitch.SwitchValue);
            if (match.Success)
            {
                string prefixToAppend = commandLineToolSwitch.SwitchValue.Substring(match.Index + match.Length, commandLineToolSwitch.SwitchValue.Length - (match.Index + match.Length));
                string valueToAppend;
                if (!switchValue.EndsWith("\\\\", StringComparison.OrdinalIgnoreCase) && switchValue.EndsWith("\\", StringComparison.OrdinalIgnoreCase) && prefixToAppend.Length > 0 && prefixToAppend[0] == '\"')
                {
                    // If the combined string would create \" then we need to escape it
                    // if the combined string would create \\" then we ignore it as as assume it is already escaped.
                    valueToAppend = commandLineToolSwitch.SwitchValue.Substring(0, match.Index) + switchValue + "\\" + prefixToAppend;
                }
                else
                {
                    valueToAppend = commandLineToolSwitch.SwitchValue.Substring(0, match.Index) + switchValue + prefixToAppend;
                }

                clb.AppendSwitch(valueToAppend);
                return true;
            }

            return false;
        }
Esempio n. 24
0
 /// <summary>
 /// Generates the commands for switches that have integers appended.
 /// </summary>
 /// <remarks>For integer switches (e.g., WarningLevel), the CommandLineToolSwitchName is emitted
 /// with the appropriate integer appended, as well as any arguments
 /// e.g., WarningLevel = "4" will emit /W4</remarks>
 private void EmitIntegerSwitch(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch)
 {
     if (commandLineToolSwitch.IsValid)
     {
         string numberAsString = commandLineToolSwitch.Number.ToString(System.Threading.Thread.CurrentThread.CurrentCulture);
         if (PerformSwitchValueSubstition(clb, commandLineToolSwitch, numberAsString))
         {
             return;
         }
         else if (!String.IsNullOrEmpty(commandLineToolSwitch.Separator))
         {
             clb.AppendSwitch(commandLineToolSwitch.SwitchValue + commandLineToolSwitch.Separator + numberAsString);
         }
         else
         {
             clb.AppendSwitch(commandLineToolSwitch.SwitchValue + numberAsString);
         }
     }
 }
Esempio n. 25
0
        /// <summary>
        /// Creates a generator that generates a command-line based on the specified Xaml file and parameters.
        /// </summary>
        public CommandLineGenerator(Rule rule, Dictionary<string, Object> parameterValues)
        {
            ErrorUtilities.VerifyThrowArgumentNull(rule, "rule");
            ErrorUtilities.VerifyThrowArgumentNull(parameterValues, "parameterValues");

            // Parse the Xaml file
            TaskParser parser = new TaskParser();
            bool success = parser.ParseXamlDocument(rule);
            ErrorUtilities.VerifyThrow(success, "Unable to parse specified file or contents.");

            // Generate the switch order list
            _switchOrderList = parser.SwitchOrderList;

            _activeCommandLineToolSwitches = new Dictionary<string, CommandLineToolSwitch>(StringComparer.OrdinalIgnoreCase);
            foreach (Property property in parser.Properties)
            {
                Object value = null;
                if (parameterValues.TryGetValue(property.Name, out value))
                {
                    CommandLineToolSwitch switchToAdd = new CommandLineToolSwitch();
                    if (!String.IsNullOrEmpty(property.Reversible) && String.Equals(property.Reversible, "true", StringComparison.OrdinalIgnoreCase))
                    {
                        switchToAdd.Reversible = true;
                    }

                    switchToAdd.IncludeInCommandLine = property.IncludeInCommandLine;
                    switchToAdd.Separator = property.Separator;
                    switchToAdd.DisplayName = property.DisplayName;
                    switchToAdd.Description = property.Description;
                    if (!String.IsNullOrEmpty(property.Required) && String.Equals(property.Required, "true", StringComparison.OrdinalIgnoreCase))
                    {
                        switchToAdd.Required = true;
                    }

                    switchToAdd.FallbackArgumentParameter = property.Fallback;
                    switchToAdd.FalseSuffix = property.FalseSuffix;
                    switchToAdd.TrueSuffix = property.TrueSuffix;
                    if (!String.IsNullOrEmpty(property.SwitchName))
                    {
                        switchToAdd.SwitchValue = property.Prefix + property.SwitchName;
                    }

                    switchToAdd.IsValid = true;

                    // Based on the switch type, cast the value and set as appropriate
                    switch (property.Type)
                    {
                        case PropertyType.Boolean:
                            switchToAdd.Type = CommandLineToolSwitchType.Boolean;
                            switchToAdd.BooleanValue = (bool)value;
                            if (!String.IsNullOrEmpty(property.ReverseSwitchName))
                            {
                                switchToAdd.ReverseSwitchValue = property.Prefix + property.ReverseSwitchName;
                            }

                            break;

                        case PropertyType.Integer:
                            switchToAdd.Type = CommandLineToolSwitchType.Integer;
                            switchToAdd.Number = (int)value;
                            if (!String.IsNullOrEmpty(property.Min))
                            {
                                if (switchToAdd.Number < Convert.ToInt32(property.Min, System.Threading.Thread.CurrentThread.CurrentCulture))
                                {
                                    switchToAdd.IsValid = false;
                                }
                            }

                            if (!String.IsNullOrEmpty(property.Max))
                            {
                                if (switchToAdd.Number > Convert.ToInt32(property.Max, System.Threading.Thread.CurrentThread.CurrentCulture))
                                {
                                    switchToAdd.IsValid = false;
                                }
                            }

                            break;

                        case PropertyType.ItemArray:
                            switchToAdd.Type = CommandLineToolSwitchType.ITaskItemArray;
                            switchToAdd.TaskItemArray = (ITaskItem[])value;
                            break;

                        case PropertyType.None:
                            break;

                        case PropertyType.String:
                            switchToAdd.Type = CommandLineToolSwitchType.String;
                            switchToAdd.ReverseSwitchValue = property.Prefix + property.ReverseSwitchName;
                            if (property.Values.Count > 0)
                            {
                                string enumValueToSelect = (string)value;

                                switchToAdd.Value = (string)value;
                                switchToAdd.AllowMultipleValues = true;

                                // Find the matching value in the enum
                                foreach (Value enumValue in property.Values)
                                {
                                    if (String.Equals(enumValue.Name, enumValueToSelect, StringComparison.OrdinalIgnoreCase))
                                    {
                                        if (!String.IsNullOrEmpty(enumValue.SwitchName))
                                        {
                                            switchToAdd.SwitchValue = enumValue.Prefix + enumValue.SwitchName;
                                        }
                                        else
                                        {
                                            switchToAdd = null;
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                switchToAdd.Value = (string)value;
                            }

                            break;

                        case PropertyType.StringArray:
                            switchToAdd.Type = CommandLineToolSwitchType.StringArray;
                            switchToAdd.StringList = (string[])value;
                            break;
                    }

                    if (switchToAdd != null)
                    {
                        _activeCommandLineToolSwitches[property.Name] = switchToAdd;
                    }
                }
            }
        }
Esempio n. 26
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);
        }
Esempio n. 27
0
 /// <summary>
 /// Add the value for a switch to the list of active values
 /// </summary>
 public void AddActiveSwitchToolValue(CommandLineToolSwitch switchToAdd)
 {
     if (((switchToAdd.Type != CommandLineToolSwitchType.Boolean)
                     || (switchToAdd.BooleanValue == true)))
     {
         if ((switchToAdd.SwitchValue != String.Empty))
         {
             ActiveToolSwitchesValues.Add(switchToAdd.SwitchValue, switchToAdd);
         }
     }
     else
     {
         if ((switchToAdd.ReverseSwitchValue != String.Empty))
         {
             ActiveToolSwitchesValues.Add(switchToAdd.ReverseSwitchValue, switchToAdd);
         }
     }
 }
Esempio n. 28
0
 /// <summary>
 /// Generates the switches that are nonreversible
 /// </summary>
 /// <remarks>A boolean switch is emitted if it is set to true. If it set to false, nothing is emitted.
 /// e.g. nologo = "true" will emit /Og, but nologo = "false" will emit nothing.</remarks>
 private void EmitBooleanSwitch(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch)
 {
     if (commandLineToolSwitch.BooleanValue)
     {
         if (!String.IsNullOrEmpty(commandLineToolSwitch.SwitchValue))
         {
             StringBuilder val = new StringBuilder();
             val.Insert(0, commandLineToolSwitch.Separator);
             val.Insert(0, commandLineToolSwitch.TrueSuffix);
             val.Insert(0, commandLineToolSwitch.SwitchValue);
             clb.AppendSwitch(val.ToString());
         }
     }
     else
     {
         EmitReversibleBooleanSwitch(clb, commandLineToolSwitch);
     }
 }
 public void ReplaceToolSwitch(CommandLineToolSwitch switchToAdd)
 {
     this.activeToolSwitches[switchToAdd.Name] = switchToAdd;
 }
Esempio n. 30
0
 /// <summary>
 /// Generates the command line for switches that are reversible
 /// </summary>
 /// <remarks>A reversible boolean switch will emit a certain switch if set to true, but emit that
 /// exact same switch with a flag appended on the end if set to false.
 /// e.g., GlobalOptimizations = "true" will emit /Og, and GlobalOptimizations = "false" will emit /Og-</remarks>
 private void EmitReversibleBooleanSwitch(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch)
 {
     // if the value is set to true, append whatever the TrueSuffix is set to.
     // Otherwise, append whatever the FalseSuffix is set to.
     if (!String.IsNullOrEmpty(commandLineToolSwitch.ReverseSwitchValue))
     {
         string suffix = (commandLineToolSwitch.BooleanValue) ? commandLineToolSwitch.TrueSuffix : commandLineToolSwitch.FalseSuffix;
         StringBuilder val = new StringBuilder();
         val.Insert(0, suffix);
         val.Insert(0, commandLineToolSwitch.Separator);
         val.Insert(0, commandLineToolSwitch.TrueSuffix);
         val.Insert(0, commandLineToolSwitch.ReverseSwitchValue);
         clb.AppendSwitch(val.ToString());
     }
 }
        public CommandLineGenerator(Rule rule, Dictionary <string, object> parameterValues)
        {
            this.activeCommandLineToolSwitches = new Dictionary <string, CommandLineToolSwitch>(StringComparer.OrdinalIgnoreCase);
            this.additionalOptions             = string.Empty;
            Microsoft.Build.Shared.ErrorUtilities.VerifyThrowArgumentNull(rule, "rule");
            Microsoft.Build.Shared.ErrorUtilities.VerifyThrowArgumentNull(parameterValues, "parameterValues");
            TaskParser parser = new TaskParser();

            Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(parser.ParseXamlDocument(rule), "Unable to parse specified file or contents.");
            this.switchOrderList = parser.SwitchOrderList;
            this.activeCommandLineToolSwitches = new Dictionary <string, CommandLineToolSwitch>(StringComparer.OrdinalIgnoreCase);
            foreach (Property property in parser.Properties)
            {
                object obj2 = null;
                if (parameterValues.TryGetValue(property.Name, out obj2))
                {
                    CommandLineToolSwitch switch2 = new CommandLineToolSwitch();
                    if (!string.IsNullOrEmpty(property.Reversible) && string.Equals(property.Reversible, "true", StringComparison.OrdinalIgnoreCase))
                    {
                        switch2.Reversible = true;
                    }
                    switch2.Separator   = property.Separator;
                    switch2.DisplayName = property.DisplayName;
                    switch2.Description = property.Description;
                    if (!string.IsNullOrEmpty(property.Required) && string.Equals(property.Required, "true", StringComparison.OrdinalIgnoreCase))
                    {
                        switch2.Required = true;
                    }
                    switch2.FallbackArgumentParameter = property.Fallback;
                    switch2.FalseSuffix = property.FalseSuffix;
                    switch2.TrueSuffix  = property.TrueSuffix;
                    if (!string.IsNullOrEmpty(property.SwitchName))
                    {
                        switch2.SwitchValue = property.Prefix + property.SwitchName;
                    }
                    switch2.IsValid = true;
                    switch (property.Type)
                    {
                    case PropertyType.Boolean:
                        switch2.Type         = CommandLineToolSwitchType.Boolean;
                        switch2.BooleanValue = (bool)obj2;
                        if (!string.IsNullOrEmpty(property.ReverseSwitchName))
                        {
                            switch2.ReverseSwitchValue = property.Prefix + property.ReverseSwitchName;
                        }
                        break;

                    case PropertyType.String:
                        switch2.Type = CommandLineToolSwitchType.String;
                        switch2.ReverseSwitchValue = property.Prefix + property.ReverseSwitchName;
                        if (property.Values.Count > 0)
                        {
                            string b = (string)obj2;
                            switch2.Value = (string)obj2;
                            switch2.AllowMultipleValues = true;
                            foreach (Value value2 in property.Values)
                            {
                                if (string.Equals(value2.Name, b, StringComparison.OrdinalIgnoreCase))
                                {
                                    if (!string.IsNullOrEmpty(value2.SwitchName))
                                    {
                                        switch2.SwitchValue = value2.Prefix + value2.SwitchName;
                                    }
                                    else
                                    {
                                        switch2 = null;
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            switch2.Value = (string)obj2;
                        }
                        break;

                    case PropertyType.Integer:
                        switch2.Type   = CommandLineToolSwitchType.Integer;
                        switch2.Number = (int)obj2;
                        if (!string.IsNullOrEmpty(property.Min) && (switch2.Number < Convert.ToInt32(property.Min, Thread.CurrentThread.CurrentCulture)))
                        {
                            switch2.IsValid = false;
                        }
                        if (!string.IsNullOrEmpty(property.Max) && (switch2.Number > Convert.ToInt32(property.Max, Thread.CurrentThread.CurrentCulture)))
                        {
                            switch2.IsValid = false;
                        }
                        break;

                    case PropertyType.StringArray:
                        switch2.Type       = CommandLineToolSwitchType.StringArray;
                        switch2.StringList = (string[])obj2;
                        break;

                    case PropertyType.ItemArray:
                        switch2.Type          = CommandLineToolSwitchType.ITaskItemArray;
                        switch2.TaskItemArray = (ITaskItem[])obj2;
                        break;
                    }
                    if (switch2 != null)
                    {
                        this.activeCommandLineToolSwitches[property.Name] = switch2;
                    }
                }
            }
        }
Esempio n. 32
0
 internal bool VerifyRequiredArgumentsArePresent(CommandLineToolSwitch property, bool throwOnError)
 {
     return(true);
 }
Esempio n. 33
0
 /// <summary>
 /// Verifies that the required args are present. This function throws if we have missing required args
 /// </summary>
 internal bool VerifyRequiredArgumentsArePresent(CommandLineToolSwitch property, bool throwOnError)
 {
     return true;
 }
Esempio n. 34
0
 /// <summary>
 /// Replace an existing switch with the specifed one of the same name. 
 /// </summary>
 public void ReplaceToolSwitch(CommandLineToolSwitch switchToAdd)
 {
     _activeToolSwitches[switchToAdd.Name] = switchToAdd;
 }
Esempio n. 35
0
 /// <summary>
 /// Emit a switch that's an array of task items
 /// </summary>
 private static void EmitTaskItemArraySwitch(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch)
 {
     if (String.IsNullOrEmpty(commandLineToolSwitch.Separator))
     {
         foreach (ITaskItem itemName in commandLineToolSwitch.TaskItemArray)
         {
             clb.AppendSwitchIfNotNull(commandLineToolSwitch.SwitchValue, itemName.ItemSpec);
         }
     }
     else
     {
         clb.AppendSwitchIfNotNull(commandLineToolSwitch.SwitchValue, commandLineToolSwitch.TaskItemArray, commandLineToolSwitch.Separator);
     }
 }
Esempio n. 36
0
        /// <summary>
        /// Generates the commands for the switches that may have an array of arguments
        /// The switch may be empty.
        /// </summary>
        /// <remarks>For stringarray switches (e.g., Sources), the CommandLineToolSwitchName (if it exists) is emitted
        /// along with each and every one of the file names separately (if no separator is included), or with all of the
        /// file names separated by the separator.
        /// e.g., AdditionalIncludeDirectores = "@(Files)" where Files has File1, File2, and File3, the switch
        /// /IFile1 /IFile2 /IFile3 or the switch /IFile1;File2;File3 is emitted (the latter case has a separator
        /// ";" specified)</remarks>
        private void EmitStringArraySwitch(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch)
        {
            List<string> stringList = new List<string>(commandLineToolSwitch.StringList.Length);
            for (int i = 0; i < commandLineToolSwitch.StringList.Length; ++i)
            {
                // Make sure the file doesn't contain escaped " (\")
                string value;
                if (commandLineToolSwitch.StringList[i].StartsWith("\"", StringComparison.OrdinalIgnoreCase) && commandLineToolSwitch.StringList[i].EndsWith("\"", StringComparison.OrdinalIgnoreCase))
                {
                    value = commandLineToolSwitch.StringList[i].Substring(1, commandLineToolSwitch.StringList[i].Length - 2).Trim();
                }
                else
                {
                    value = commandLineToolSwitch.StringList[i].Trim();
                }

                if (!String.IsNullOrEmpty(value))
                {
                    stringList.Add(value);
                }
            }

            string[] arrTrimStringList = stringList.ToArray();

            if (String.IsNullOrEmpty(commandLineToolSwitch.Separator))
            {
                foreach (string fileName in arrTrimStringList)
                {
                    if (!PerformSwitchValueSubstition(clb, commandLineToolSwitch, fileName))
                    {
                        clb.AppendSwitchIfNotNull(commandLineToolSwitch.SwitchValue, fileName);
                    }
                }
            }
            else
            {
                if (!PerformSwitchValueSubstition(clb, commandLineToolSwitch, String.Join(commandLineToolSwitch.Separator, arrTrimStringList)))
                {
                    clb.AppendSwitchIfNotNull(commandLineToolSwitch.SwitchValue, arrTrimStringList, commandLineToolSwitch.Separator);
                }
            }
        }
Esempio n. 37
0
        public CommandLineGenerator(Rule rule, Dictionary <string, Object> parameterValues)
        {
            ErrorUtilities.VerifyThrowArgumentNull(rule, nameof(rule));
            ErrorUtilities.VerifyThrowArgumentNull(parameterValues, nameof(parameterValues));

            // Parse the Xaml file
            var  parser  = new TaskParser();
            bool success = parser.ParseXamlDocument(rule);

            ErrorUtilities.VerifyThrow(success, "Unable to parse specified file or contents.");

            // Generate the switch order list
            _switchOrderList = parser.SwitchOrderList;

            foreach (Property property in parser.Properties)
            {
                if (parameterValues.TryGetValue(property.Name, out object value))
                {
                    var switchToAdd = new CommandLineToolSwitch();
                    if (!String.IsNullOrEmpty(property.Reversible) && String.Equals(property.Reversible, "true", StringComparison.OrdinalIgnoreCase))
                    {
                        switchToAdd.Reversible = true;
                    }

                    switchToAdd.IncludeInCommandLine = property.IncludeInCommandLine;
                    switchToAdd.Separator            = property.Separator;
                    switchToAdd.DisplayName          = property.DisplayName;
                    switchToAdd.Description          = property.Description;
                    if (!String.IsNullOrEmpty(property.Required) && String.Equals(property.Required, "true", StringComparison.OrdinalIgnoreCase))
                    {
                        switchToAdd.Required = true;
                    }

                    switchToAdd.FallbackArgumentParameter = property.Fallback;
                    switchToAdd.FalseSuffix = property.FalseSuffix;
                    switchToAdd.TrueSuffix  = property.TrueSuffix;
                    if (!String.IsNullOrEmpty(property.SwitchName))
                    {
                        switchToAdd.SwitchValue = property.Prefix + property.SwitchName;
                    }

                    switchToAdd.IsValid = true;

                    // Based on the switch type, cast the value and set as appropriate
                    switch (property.Type)
                    {
                    case PropertyType.Boolean:
                        switchToAdd.Type         = CommandLineToolSwitchType.Boolean;
                        switchToAdd.BooleanValue = (bool)value;
                        if (!String.IsNullOrEmpty(property.ReverseSwitchName))
                        {
                            switchToAdd.ReverseSwitchValue = property.Prefix + property.ReverseSwitchName;
                        }

                        break;

                    case PropertyType.Integer:
                        switchToAdd.Type   = CommandLineToolSwitchType.Integer;
                        switchToAdd.Number = (int)value;
                        if (!String.IsNullOrEmpty(property.Min))
                        {
                            if (switchToAdd.Number < Convert.ToInt32(property.Min, System.Threading.Thread.CurrentThread.CurrentCulture))
                            {
                                switchToAdd.IsValid = false;
                            }
                        }

                        if (!String.IsNullOrEmpty(property.Max))
                        {
                            if (switchToAdd.Number > Convert.ToInt32(property.Max, System.Threading.Thread.CurrentThread.CurrentCulture))
                            {
                                switchToAdd.IsValid = false;
                            }
                        }

                        break;

                    case PropertyType.ItemArray:
                        switchToAdd.Type          = CommandLineToolSwitchType.ITaskItemArray;
                        switchToAdd.TaskItemArray = (ITaskItem[])value;
                        break;

                    case PropertyType.None:
                        break;

                    case PropertyType.String:
                        switchToAdd.Type = CommandLineToolSwitchType.String;
                        switchToAdd.ReverseSwitchValue = property.Prefix + property.ReverseSwitchName;
                        if (property.Values.Count > 0)
                        {
                            string enumValueToSelect = (string)value;

                            switchToAdd.Value = (string)value;
                            switchToAdd.AllowMultipleValues = true;

                            // Find the matching value in the enum
                            foreach (Value enumValue in property.Values)
                            {
                                if (String.Equals(enumValue.Name, enumValueToSelect, StringComparison.OrdinalIgnoreCase))
                                {
                                    if (!String.IsNullOrEmpty(enumValue.SwitchName))
                                    {
                                        switchToAdd.SwitchValue = enumValue.Prefix + enumValue.SwitchName;
                                    }
                                    else
                                    {
                                        switchToAdd = null;
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            switchToAdd.Value = (string)value;
                        }

                        break;

                    case PropertyType.StringArray:
                        switchToAdd.Type       = CommandLineToolSwitchType.StringArray;
                        switchToAdd.StringList = (string[])value;
                        break;
                    }

                    if (switchToAdd != null)
                    {
                        _activeCommandLineToolSwitches[property.Name] = switchToAdd;
                    }
                }
            }
        }
Esempio n. 38
0
        private void GenerateTemplatedCommandLine(CommandLineBuilder builder)
        {
            // Match all instances of [asdf], where "asdf" can be any combination of any
            // characters *except* a [ or an ]. i.e., if "[ [ sdf ]" is passed, then we will
            // match "[ sdf ]"
            string          matchString = @"\[[^\[\]]+\]";
            Regex           regex       = new Regex(matchString, RegexOptions.ECMAScript);
            MatchCollection matches     = regex.Matches(CommandLineTemplate);

            int indexOfEndOfLastSubstitution = 0;

            foreach (Match match in matches)
            {
                if (match.Length == 0)
                {
                    continue;
                }

                // Because we match non-greedily, in the case where we have input such as "[[[[[foo]", the match will
                // be "[foo]".  However, if there are multiple '[' in a row, we need to do some escaping logic, so we
                // want to know what the first *consecutive* square bracket was.
                int indexOfFirstBracketInMatch = match.Index;

                // Indexing using "indexOfFirstBracketInMatch - 1" is safe here because it will always be
                // greater than indexOfEndOfLastSubstitution, which will always be 0 or greater.
                while (indexOfFirstBracketInMatch > indexOfEndOfLastSubstitution && CommandLineTemplate[indexOfFirstBracketInMatch - 1].Equals('['))
                {
                    indexOfFirstBracketInMatch--;
                }

                // Append everything we know we want to add -- everything between where the last substitution ended and
                // this match (including previous '[' that were not initially technically part of the match) begins.
                if (indexOfFirstBracketInMatch != indexOfEndOfLastSubstitution)
                {
                    builder.AppendTextUnquoted(CommandLineTemplate.Substring(indexOfEndOfLastSubstitution, indexOfFirstBracketInMatch - indexOfEndOfLastSubstitution));
                }

                // Now replace every "[[" with a literal '['.  We can do this by simply counting the number of '[' between
                // the first one and the start of the match, since by definition everything in between is an '['.
                // + 1 because match.Index is also a bracket.
                int openBracketsInARow = match.Index - indexOfFirstBracketInMatch + 1;

                if (openBracketsInARow % 2 == 0)
                {
                    // even number -- they all go away and the rest of the match is appended literally.
                    for (int i = 0; i < openBracketsInARow / 2; i++)
                    {
                        builder.AppendTextUnquoted("[");
                    }

                    builder.AppendTextUnquoted(match.Value.Substring(1, match.Value.Length - 1));
                }
                else
                {
                    // odd number -- all but one get merged two at a time, and the rest of the match is substituted.
                    for (int i = 0; i < (openBracketsInARow - 1) / 2; i++)
                    {
                        builder.AppendTextUnquoted("[");
                    }

                    // Determine which property the user has specified in the template.
                    string propertyName = match.Value.Substring(1, match.Value.Length - 2);
                    if (String.Equals(propertyName, "AllOptions", StringComparison.OrdinalIgnoreCase))
                    {
                        // When [AllOptions] is specified, we append all switch-type options.
                        CommandLineBuilder tempBuilder = new CommandLineBuilder(true);
                        GenerateStandardCommandLine(tempBuilder, true);
                        builder.AppendTextUnquoted(tempBuilder.ToString());
                    }
                    else if (String.Equals(propertyName, "AdditionalOptions", StringComparison.OrdinalIgnoreCase))
                    {
                        BuildAdditionalArgs(builder);
                    }
                    else if (IsPropertySet(propertyName))
                    {
                        CommandLineToolSwitch property = _activeCommandLineToolSwitches[propertyName];

                        // verify the dependencies
                        if (VerifyDependenciesArePresent(property) && VerifyRequiredArgumentsArePresent(property, false))
                        {
                            CommandLineBuilder tempBuilder = new CommandLineBuilder(true);
                            GenerateCommandsAccordingToType(tempBuilder, property, false);
                            builder.AppendTextUnquoted(tempBuilder.ToString());
                        }
                    }
                    else if (!PropertyExists(propertyName))
                    {
                        // If the thing enclosed in square brackets is not in fact a property, we
                        // don't want to replace it.
                        builder.AppendTextUnquoted('[' + propertyName + ']');
                    }
                }

                indexOfEndOfLastSubstitution = match.Index + match.Length;
            }

            builder.AppendTextUnquoted(CommandLineTemplate.Substring(indexOfEndOfLastSubstitution, CommandLineTemplate.Length - indexOfEndOfLastSubstitution));
        }
Esempio n. 39
0
        /// <summary>
        /// Generates a part of the command line depending on the type
        /// </summary>
        /// <remarks>Depending on the type of the switch, the switch is emitted with the proper values appended.
        /// e.g., File switches will append file names, directory switches will append filenames with "\" on the end</remarks>
        internal void GenerateCommandsAccordingToType(CommandLineBuilder clb, CommandLineToolSwitch commandLineToolSwitch, bool recursive)
        {
            // if this property has a parent skip printing it as it was printed as part of the parent prop printing
            if (commandLineToolSwitch.Parents.Count > 0 && !recursive)
            {
                return;
            }

            switch (commandLineToolSwitch.Type)
            {
                case CommandLineToolSwitchType.Boolean:
                    EmitBooleanSwitch(clb, commandLineToolSwitch);
                    break;
                case CommandLineToolSwitchType.String:
                    EmitStringSwitch(clb, commandLineToolSwitch);
                    break;
                case CommandLineToolSwitchType.StringArray:
                    EmitStringArraySwitch(clb, commandLineToolSwitch);
                    break;
                case CommandLineToolSwitchType.Integer:
                    EmitIntegerSwitch(clb, commandLineToolSwitch);
                    break;
                case CommandLineToolSwitchType.ITaskItemArray:
                    EmitTaskItemArraySwitch(clb, commandLineToolSwitch);
                    break;
                default:
                    // should never reach this point - if it does, there's a bug somewhere.
                    ErrorUtilities.VerifyThrow(false, "InternalError");
                    break;
            }
        }
        private void GenerateTemplatedCommandLine(CommandLineBuilder builder)
        {
            string          pattern    = @"\[[^\[\]]+\]";
            MatchCollection matchs     = new Regex(pattern, RegexOptions.ECMAScript).Matches(this.CommandLineTemplate);
            int             startIndex = 0;

            foreach (Match match in matchs)
            {
                if (match.Length == 0)
                {
                    continue;
                }
                int index = match.Index;
                goto Label_0059;
Label_0053:
                index--;
Label_0059:
                if (index > startIndex)
                {
                    char ch = this.CommandLineTemplate[index - 1];
                    if (ch.Equals('['))
                    {
                        goto Label_0053;
                    }
                }
                if (index != startIndex)
                {
                    builder.AppendTextUnquoted(this.CommandLineTemplate.Substring(startIndex, index - startIndex));
                }
                int num3 = (match.Index - index) + 1;
                if ((num3 % 2) == 0)
                {
                    for (int i = 0; i < (num3 / 2); i++)
                    {
                        builder.AppendTextUnquoted("[");
                    }
                    builder.AppendTextUnquoted(match.Value.Substring(1, match.Value.Length - 1));
                }
                else
                {
                    for (int j = 0; j < ((num3 - 1) / 2); j++)
                    {
                        builder.AppendTextUnquoted("[");
                    }
                    string a = match.Value.Substring(1, match.Value.Length - 2);
                    if (string.Equals(a, "AllOptions", StringComparison.OrdinalIgnoreCase))
                    {
                        CommandLineBuilder builder2 = new CommandLineBuilder(true);
                        this.GenerateStandardCommandLine(builder2, true);
                        builder.AppendTextUnquoted(builder2.ToString());
                    }
                    else if (string.Equals(a, "AdditionalOptions", StringComparison.OrdinalIgnoreCase))
                    {
                        this.BuildAdditionalArgs(builder);
                    }
                    else if (this.IsPropertySet(a))
                    {
                        CommandLineToolSwitch property = this.activeCommandLineToolSwitches[a];
                        if (this.VerifyDependenciesArePresent(property) && this.VerifyRequiredArgumentsArePresent(property, false))
                        {
                            CommandLineBuilder clb = new CommandLineBuilder(true);
                            this.GenerateCommandsAccordingToType(clb, property, false);
                            builder.AppendTextUnquoted(clb.ToString());
                        }
                    }
                    else if (!this.PropertyExists(a))
                    {
                        builder.AppendTextUnquoted('[' + a + ']');
                    }
                }
                startIndex = match.Index + match.Length;
            }
            builder.AppendTextUnquoted(this.CommandLineTemplate.Substring(startIndex, this.CommandLineTemplate.Length - startIndex));
        }
Esempio n. 41
0
        /// <summary>
        /// Verifies that the dependencies are present, and if the dependencies are present, or if the property
        /// doesn't have any dependencies, the switch gets emitted
        /// </summary>
        internal bool VerifyDependenciesArePresent(CommandLineToolSwitch property)
        {
            // check the dependency
            if (property.Parents.Count > 0)
            {
                // has a dependency, now check to see whether at least one parent is set
                // if it is set, add to the command line
                // otherwise, ignore it
                bool isSet = false;
                foreach (string parentName in property.Parents)
                {
                    isSet = isSet || HasSwitch(parentName);
                }

                return isSet;
            }
            else
            {
                // no dependencies to account for
                return true;
            }
        }