* Parameters.cs (ProcessProperty): Handle invalid syntax.
[mono.git] / mcs / tools / xbuild / Parameters.cs
index 5a8b8951b137a6c487dfb1efd81f3877e497ab53..81b93ebfc0b947561290cad73adfb57e8bbfdd55 100644 (file)
@@ -88,7 +88,7 @@ namespace Mono.XBuild.CommandLine {
                                }
                                string responseFilename = Path.GetFullPath (s.Substring (1));
                                if (responseFiles.ContainsKey (responseFilename))
-                                       throw new CommandLineException ("We already have " + responseFilename + "file.", 0001);
+                                       ErrorUtilities.ReportError (1, String.Format ("We already have {0} file.", responseFilename));
                                responseFiles [responseFilename] = responseFilename;
                                LoadResponseFile (responseFilename);
                        }
@@ -97,9 +97,7 @@ namespace Mono.XBuild.CommandLine {
                                LoadResponseFile (responseFile);
                        }
                        foreach (string s in flatArguments) {
-                               if (s [0] == '/') {
-                                       ParseFlatArgument (s);
-                               } else
+                               if (s [0] != '/' || !ParseFlatArgument (s))
                                        remainingArguments.Add (s);
                        }
                        if (remainingArguments.Count == 0) {
@@ -107,15 +105,15 @@ namespace Mono.XBuild.CommandLine {
                                if (files.Length > 0)
                                        projectFile = files [0];
                                else
-                                       throw new CommandLineException ("No .proj file specified and no found in current directory.", 0003);
+                                       ErrorUtilities.ReportError (3, "No .proj file specified and no found in current directory.");
                        } else if (remainingArguments.Count == 1) {
                                projectFile = (string) remainingArguments [0];
                        } else {
-                               throw new CommandLineException ("Too many project files specified.", 0004);
+                               ErrorUtilities.ReportError (4, "Too many project files specified");
                        }
                }
                
-               private void LoadResponseFile (string filename)
+               void LoadResponseFile (string filename)
                {
                        StreamReader sr = null;
                        string line;
@@ -129,6 +127,10 @@ namespace Mono.XBuild.CommandLine {
                                         for (int i = 0; i < t; i++) {
                                                 char c = line [i];
 
+                                               if (c == '#')
+                                                       // comment, ignore rest of the line
+                                                       break;
+
                                                 if (c == '"' || c == '\'') {
                                                         char end = c;
 
@@ -152,27 +154,30 @@ namespace Mono.XBuild.CommandLine {
                                                 sb.Length = 0;
                                         }
                                 }
-                        } catch (Exception ex) {
-                                throw new CommandLineException ("Error during loading response file.", ex, 0002);
-                        } finally {
+                        } catch (Exception) {
+                               // FIXME: we lose exception message
+                               ErrorUtilities.ReportError (2, "Error during loading response file.");
+                       } finally {
                                 if (sr != null)
                                         sr.Close ();
                         }
                }
                
-               private void ParseFlatArgument (string s)
+               private bool ParseFlatArgument (string s)
                {
                        switch (s) {
                        case "/help":
                        case "/h":
                        case "/?":
-                               throw new CommandLineException ("Show usage", 0006);
+                               ErrorUtilities.ShowUsage ();
+                               break;
                        case "/nologo":
                                noLogo = true;
                                break;
                        case "/version":
                        case "/ver":
-                               throw new CommandLineException ("Show version", 0005);
+                               ErrorUtilities.ShowVersion (true);
+                               break;
                        case "/noconsolelogger":
                        case "/noconlog":
                                noConsoleLogger = true;
@@ -184,24 +189,23 @@ namespace Mono.XBuild.CommandLine {
                        default:
                                if (s.StartsWith ("/target:") || s.StartsWith ("/t:")) {
                                        ProcessTarget (s);
-                               }
-                               if (s.StartsWith ("/property:") || s.StartsWith ("/p:")) {
-                                       ProcessProperty (s);
-                               }
-                               if (s.StartsWith ("/logger:") || s.StartsWith ("/l:")) {
+                               } else if (s.StartsWith ("/property:") || s.StartsWith ("/p:")) {
+                                       if (!ProcessProperty (s))
+                                               return false;
+                               } else  if (s.StartsWith ("/logger:") || s.StartsWith ("/l:")) {
                                        ProcessLogger (s);
-                               }
-                               if (s.StartsWith ("/verbosity:") || s.StartsWith ("/v:")) {
+                               } else if (s.StartsWith ("/verbosity:") || s.StartsWith ("/v:")) {
                                        ProcessVerbosity (s);
-                               }
-                               if (s.StartsWith ("/consoleloggerparameters:") || s.StartsWith ("/clp:")) {
+                               } else if (s.StartsWith ("/consoleloggerparameters:") || s.StartsWith ("/clp:")) {
                                        ProcessConsoleLoggerParameters (s);
-                               }
-                               if (s.StartsWith ("/validate:") || s.StartsWith ("/val:")) {
+                               } else if (s.StartsWith ("/validate:") || s.StartsWith ("/val:")) {
                                        ProcessValidate (s);
-                               }
+                               } else
+                                       return false;
                                break;
                        }
+
+                       return true;
                }
                
                internal void ProcessTarget (string s)
@@ -210,15 +214,28 @@ namespace Mono.XBuild.CommandLine {
                        targets = temp [1].Split (';');
                }
                
-               internal void ProcessProperty (string s)
+               internal bool ProcessProperty (string s)
                {
                        string[] parameter, splittedProperties, property;
                        parameter = s.Split (':');
+                       if (parameter.Length != 2) {
+                               ErrorUtilities.ReportError (5, "Property name and value expected as /p:<prop name>=<prop value>");
+                               return false;
+                       }
+
                        splittedProperties = parameter [1].Split (';');
                        foreach (string st in splittedProperties) {
+                               if (st.IndexOf ('=') < 0) {
+                                       ErrorUtilities.ReportError (5,
+                                                       "Invalid syntax. Property name and value expected as " +
+                                                       "<prop name>=[<prop value>]");
+                                       return false;
+                               }
                                property = st.Split ('=');
-                               properties.AddNewProperty (property [0], property [1]);
+                               properties.SetProperty (property [0], property.Length == 2 ? property [1] : "");
                        }
+
+                       return true;
                }
                
                internal void ProcessLogger (string s)
@@ -316,4 +333,4 @@ namespace Mono.XBuild.CommandLine {
        }
 }
 
-#endif
\ No newline at end of file
+#endif