Author: msierad
Date: 2006-09-20 08:57:41 -0400 (Wed, 20 Sep 2006)
New Revision: 65706

Added:
   trunk/mcs/tools/xbuild/ErrorUtilities.cs
Modified:
   trunk/mcs/tools/xbuild/ChangeLog
   trunk/mcs/tools/xbuild/Main.cs
   trunk/mcs/tools/xbuild/Parameters.cs
   trunk/mcs/tools/xbuild/xbuild.exe.sources
Log:
2006-09-20  Marek Sieradzki  <[EMAIL PROTECTED]>

    * Parameters.cs, Main.cs, ErrorUtilities.cs: Moved error handling to
        new file and started to use ErrorUtilities.ReportError ()
        instead of throw and catch. (In cases where xbuild should quit
        instantly)



Modified: trunk/mcs/tools/xbuild/ChangeLog
===================================================================
--- trunk/mcs/tools/xbuild/ChangeLog    2006-09-20 12:39:21 UTC (rev 65705)
+++ trunk/mcs/tools/xbuild/ChangeLog    2006-09-20 12:57:41 UTC (rev 65706)
@@ -1,3 +1,10 @@
+2006-09-20  Marek Sieradzki  <[EMAIL PROTECTED]>
+
+       * Parameters.cs, Main.cs, ErrorUtilities.cs: Moved error handling to
+       new file and started to use ErrorUtilities.ReportError ()
+       instead of throw and catch. (In cases where xbuild should quit
+       instantly)
+
 2006-06-25  Marek Sieradzki  <[EMAIL PROTECTED]>
 
        * Makefile, xbuild/Microsoft.CSharp.Targets: Renamed to

Added: trunk/mcs/tools/xbuild/ErrorUtilities.cs
===================================================================
--- trunk/mcs/tools/xbuild/ErrorUtilities.cs    2006-09-20 12:39:21 UTC (rev 
65705)
+++ trunk/mcs/tools/xbuild/ErrorUtilities.cs    2006-09-20 12:57:41 UTC (rev 
65706)
@@ -0,0 +1,185 @@
+//
+// ErrorUtilities.cs: Functions that print out errors, warnings, help etc.
+//
+// Author:
+//   Marek Sieradzki ([EMAIL PROTECTED])
+//
+// (C) 2006 Marek Sieradzki
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+#if NET_2_0
+
+using System;
+
+namespace Mono.XBuild.CommandLine {
+       public static class ErrorUtilities {
+
+               static string[] usage = {
+                       "",
+                       "Syntax:              xbuild.exe [options] [project 
file]",
+                       "",
+                       "Description:         Builds the specified targets in 
the project file. If",
+                       "                     a project file is not specified, 
MSBuild searches the",
+                       "                     current working directory for a 
file that has a file",
+                       "                     extension that ends in \"proj\" 
and uses that file.",
+                       "",
+                       "Switches:",
+                       "",
+                       "  /help              Display this usage message. 
(Short form: /? or /h)",
+                       "",
+                       "  /nologo            Do not display the startup banner 
and copyright message.",
+                       "",
+                       "  /version           Display version information only. 
(Short form: /ver)",
+                       "",
+                       "  @<file>            Insert command-line settings from 
a text file. To specify",
+                       "                     multiple response files, specify 
each response file",
+                       "                     separately.",
+                       "",
+                       "  /noautoresponse    Do not auto-include the 
MSBuild.rsp file. (Short form:",
+                       "                     /noautorsp)",
+                       "",
+                       "  /target:<targets>  Build these targets in this 
project. Use a semicolon or a",
+                       "                     comma to separate multiple 
targets, or specify each",
+                       "                     target separately. (Short form: 
/t)",
+                       "                     Example:",
+                       "                       /target:Resources;Compile",
+                       "",
+                       "  /property:<n>=<v>  Set or override these 
project-level properties. <n> is",
+                       "                     the property name, and <v> is the 
property value. Use a",
+                       "                     semicolon or a comma to separate 
multiple properties, or",
+                       "                     specify each property separately. 
(Short form: /p)",
+                       "                     Example:",
+                       @"                       
/property:WarningLevel=2;OutDir=bin\Debug\",
+                       "",
+                       "  /logger:<logger>   Use this logger to log events 
from MSBuild. To specify",
+                       "                     multiple loggers, specify each 
logger separately.",
+                       "                     The <logger> syntax is:",
+                       "                        [<logger class>,]<logger 
assembly>[;<logger parameters>]",
+                       "                     The <logger class> syntax is:",
+                       "                        [<partial or full 
namespace>.]<logger class name>",
+                       "                     The <logger assembly> syntax is:",
+                       "                        {<assembly name>[,<strong 
name>] | <assembly file>}",
+                       "                     The <logger parameters> are 
optional, and are passed",
+                       "                     to the logger exactly as you 
typed them. (Short form: /l)",
+                       "                     Examples:",
+                       "                       
/logger:XMLLogger,MyLogger,Version=1.0.2,Culture=neutral",
+                       @"                       
/logger:XMLLogger,C:\Loggers\MyLogger.dll;OutputAsHTML",
+                       "",
+                       "  /verbosity:<level> Display this amount of 
information in the event log.",
+                       "                     The available verbosity levels 
are: q[uiet], m[inimal],",
+                       "                     n[ormal], d[etailed], and 
diag[nostic]. (Short form: /v)",
+                       "                     Example:",
+                       "                       /verbosity:quiet",
+                       "",
+                       "  /consoleloggerparameters:<parameters>",
+                       "                     Parameters to console logger. 
(Short form: /clp)",
+                       "                     The available parameters are:",
+                       "                        PerformanceSummary--show time 
spent in tasks, targets",
+                       "                            and projects.",
+                       "                        NoSummary--don't show error 
and warning summary at the",
+                       "                            end.",
+                       "                     Example:",
+                       "                        
/consoleloggerparameters:PerformanceSummary;NoSummary",
+                       "",
+                       "  /noconsolelogger   Disable the default console 
logger and do not log events",
+                       "                     to the console. (Short form: 
/noconlog)",
+                       "",
+                       "  /validate          Validate the project against the 
default schema. (Short",
+                       "                     form: /val)",
+                       "",
+                       "  /validate:<schema> Validate the project against the 
specified schema. (Short",
+                       "                     form: /val)",
+                       "                     Example:",
+                       "                       
/validate:MyExtendedBuildSchema.xsd",
+                       "",
+                       "Examples:",
+                       "",
+                       "        MSBuild MyApp.sln /t:Rebuild 
/p:Configuration=Release",
+                       "        MSBuild MyApp.csproj /t:Clean 
/p:Configuration=Debug",
+
+               };
+               
+               static string[] version = {
+                       "XBuild Engine Version 0.1",
+                       String.Format ("Mono, Version {0}", Consts.MonoVersion),
+                       "Copyright (C) Marek Sieradzki 2005. All rights 
reserved.",
+               };
+
+               
+               static public void ReportError (int errorNum, string msg)
+               {
+                       Console.WriteLine (String.Format ("MSBUILD: error 
MSBUILD{0:0000}: {1}", errorNum, msg));
+                       Environment.Exit (1);
+               }
+
+               static public void ReportWarning (int errorNum, string msg)
+               {
+                       Console.WriteLine (String.Format ("MSBUILD: warning 
MSBUILD{0:0000}: {1}", errorNum, msg));
+               }
+
+                static public void ReportInvalidArgument (string option, 
string value)
+               {
+                        ReportError (1012, String.Format ("'{0}' is not a 
valid setting for option '{1}'", value, option));
+                }
+
+                static public void ReportMissingArgument (string option)
+               {
+                        ReportError (1003, String.Format ("Compiler option 
'{0}' must be followed by an argument", option));
+                }
+
+                static public void ReportNotImplemented (string option)
+               {
+                        ReportError (0, String.Format ("Compiler option '{0}' 
is not implemented", option));
+                }
+ 
+                static public void ReportMissingFileSpec (string option)
+               {
+                        ReportError (1008, String.Format ("Missing file 
specification for '{0}' command-line option", option));
+                }
+
+                static public void ReportMissingText (string option)
+               {
+                        ReportError (1010, String.Format ("Missing ':<text>' 
for '{0}' option", option));
+                }
+
+               static public void ShowUsage ()
+               {
+                       Display (usage);
+                       Environment.Exit (0);
+                       
+               }
+
+               static public void ShowVersion (bool exit)
+               {
+                       Display (version);
+                       if (exit)
+                               Environment.Exit (0);
+               }
+
+               static private void Display (string[] array)
+               {
+                       foreach (string s in array)
+                               Console.WriteLine (s);
+               }
+       }
+}
+
+#endif


Property changes on: trunk/mcs/tools/xbuild/ErrorUtilities.cs
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native

Modified: trunk/mcs/tools/xbuild/Main.cs
===================================================================
--- trunk/mcs/tools/xbuild/Main.cs      2006-09-20 12:39:21 UTC (rev 65705)
+++ trunk/mcs/tools/xbuild/Main.cs      2006-09-20 12:57:41 UTC (rev 65706)
@@ -70,7 +70,7 @@
                                parameters.ParseArguments (args);
                                
                                if (parameters.DisplayVersion == true)
-                                       Display (version);
+                                       ErrorUtilities.ShowVersion (false);
                                
                                engine  = new Engine (binPath);
                                
@@ -107,194 +107,19 @@
                                
                                result = engine.BuildProject (project, 
parameters.Targets, new Hashtable ());
                        }
-                       catch (CommandLineException cex) {
-                               switch (cex.ErrorCode) {
-                               case 1:
-                                       ReportErrorFromException (cex);
-                                       break;
-                               case 2:
-                                       ReportErrorFromException (cex);
-                                       break;
-                               case 3:
-                                       if (parameters.NoLogo)
-                                               ReportErrorFromException (cex);
-                                       else {
-                                               Display (version);
-                                               Display (usage);
-                                       }
-                                       break;
-                               case 4:
-                                       ReportErrorFromException (cex);
-                                       break;
-                               case 5:
-                                       Version ();
-                                       break;
-                               case 6:
-                                       Usage ();
-                                       break;
-                               case 7:
-                                       ReportErrorFromException (cex);
-                                       break;
-                               default:
-                                       throw;
-                               }
+                       
+                       catch (Exception) {
+                               throw;
                        }
-                       catch (InvalidProjectFileException ipfe ) {
-                               ReportError (0008, ipfe.Message);
-                       }
-                       catch (Exception ex) {
-                               ReportError (0, String.Format 
("{0}\n{1}",ex.Message, ex.StackTrace));
-                       }
+                       
                        finally {
                                if (engine != null)
                                        engine.UnregisterAllLoggers ();
 
-                               Environment.Exit ((result ? 0 : 1));
+                               Environment.Exit (result ? 0 : 1);
                        }
 
                }
-               
-               private void Display (string[] array) {
-                       foreach (string s in array)
-                               Console.WriteLine (s);
-               }
-               
-               private void Version ()
-               {
-                       Display (version);
-                       Environment.Exit (0);
-               }
-               
-               private void Usage ()
-               {
-                       Display (version);
-                       Display (usage);
-                       Environment.Exit (0);
-               }
-               
-               private void ReportErrorFromException (CommandLineException cex)
-               {
-                       ReportError (cex.ErrorCode, cex.Message);
-               }
-               
-                private void ReportError (int errorNum, string msg) {
-                        Console.WriteLine (String.Format ("MSBUILD: error 
MSBUILD{0:0000}: {1}", errorNum, msg));
-                        Environment.Exit (1);
-                }
-
-                private void ReportWarning (int errorNum, string msg) {
-                        Console.WriteLine (String.Format ("MSBUILD: warning 
MSBUILD{0:0000}: {1}", errorNum, msg));
-                }
-
-                private void ReportInvalidArgument (string option, string 
value) {
-                        ReportError (1012, String.Format ("'{0}' is not a 
valid setting for option '{1}'", value, option));
-                }
-
-                private void ReportMissingArgument (string option) {
-                        ReportError (1003, String.Format ("Compiler option 
'{0}' must be followed by an argument", option));
-                }
-
-                private void ReportNotImplemented (string option) {
-                        ReportError (0, String.Format ("Compiler option '{0}' 
is not implemented", option));
-                }
-
-                private void ReportMissingFileSpec (string option) {
-                        ReportError (1008, String.Format ("Missing file 
specification for '{0}' command-line option", option));
-                }
-
-                private void ReportMissingText (string option) {
-                        ReportError (1010, String.Format ("Missing ':<text>' 
for '{0}' option", option));
-                }
-
-               string[] usage = {
-                       "",
-                       "Syntax:              xbuild.exe [options] [project 
file]",
-                       "",
-                       "Description:         Builds the specified targets in 
the project file. If",
-                       "                     a project file is not specified, 
MSBuild searches the",
-                       "                     current working directory for a 
file that has a file",
-                       "                     extension that ends in \"proj\" 
and uses that file.",
-                       "",
-                       "Switches:",
-                       "",
-                       "  /help              Display this usage message. 
(Short form: /? or /h)",
-                       "",
-                       "  /nologo            Do not display the startup banner 
and copyright message.",
-                       "",
-                       "  /version           Display version information only. 
(Short form: /ver)",
-                       "",
-                       "  @<file>            Insert command-line settings from 
a text file. To specify",
-                       "                     multiple response files, specify 
each response file",
-                       "                     separately.",
-                       "",
-                       "  /noautoresponse    Do not auto-include the 
MSBuild.rsp file. (Short form:",
-                       "                     /noautorsp)",
-                       "",
-                       "  /target:<targets>  Build these targets in this 
project. Use a semicolon or a",
-                       "                     comma to separate multiple 
targets, or specify each",
-                       "                     target separately. (Short form: 
/t)",
-                       "                     Example:",
-                       "                       /target:Resources;Compile",
-                       "",
-                       "  /property:<n>=<v>  Set or override these 
project-level properties. <n> is",
-                       "                     the property name, and <v> is the 
property value. Use a",
-                       "                     semicolon or a comma to separate 
multiple properties, or",
-                       "                     specify each property separately. 
(Short form: /p)",
-                       "                     Example:",
-                       @"                       
/property:WarningLevel=2;OutDir=bin\Debug\",
-                       "",
-                       "  /logger:<logger>   Use this logger to log events 
from MSBuild. To specify",
-                       "                     multiple loggers, specify each 
logger separately.",
-                       "                     The <logger> syntax is:",
-                       "                        [<logger class>,]<logger 
assembly>[;<logger parameters>]",
-                       "                     The <logger class> syntax is:",
-                       "                        [<partial or full 
namespace>.]<logger class name>",
-                       "                     The <logger assembly> syntax is:",
-                       "                        {<assembly name>[,<strong 
name>] | <assembly file>}",
-                       "                     The <logger parameters> are 
optional, and are passed",
-                       "                     to the logger exactly as you 
typed them. (Short form: /l)",
-                       "                     Examples:",
-                       "                       
/logger:XMLLogger,MyLogger,Version=1.0.2,Culture=neutral",
-                       @"                       
/logger:XMLLogger,C:\Loggers\MyLogger.dll;OutputAsHTML",
-                       "",
-                       "  /verbosity:<level> Display this amount of 
information in the event log.",
-                       "                     The available verbosity levels 
are: q[uiet], m[inimal],",
-                       "                     n[ormal], d[etailed], and 
diag[nostic]. (Short form: /v)",
-                       "                     Example:",
-                       "                       /verbosity:quiet",
-                       "",
-                       "  /consoleloggerparameters:<parameters>",
-                       "                     Parameters to console logger. 
(Short form: /clp)",
-                       "                     The available parameters are:",
-                       "                        PerformanceSummary--show time 
spent in tasks, targets",
-                       "                            and projects.",
-                       "                        NoSummary--don't show error 
and warning summary at the",
-                       "                            end.",
-                       "                     Example:",
-                       "                        
/consoleloggerparameters:PerformanceSummary;NoSummary",
-                       "",
-                       "  /noconsolelogger   Disable the default console 
logger and do not log events",
-                       "                     to the console. (Short form: 
/noconlog)",
-                       "",
-                       "  /validate          Validate the project against the 
default schema. (Short",
-                       "                     form: /val)",
-                       "",
-                       "  /validate:<schema> Validate the project against the 
specified schema. (Short",
-                       "                     form: /val)",
-                       "                     Example:",
-                       "                       
/validate:MyExtendedBuildSchema.xsd",
-                       "",
-                       "Examples:",
-                       "",
-                       "        MSBuild MyApp.sln /t:Rebuild 
/p:Configuration=Release",
-                       "        MSBuild MyApp.csproj /t:Clean 
/p:Configuration=Debug",
-               };
-               
-               string[] version = {
-                       "XBuild Engine Version 0.1",
-                       String.Format ("Mono, Version {0}", Consts.MonoVersion),
-                       "Copyright (C) Marek Sieradzki 2005. All rights 
reserved.",
-               };
        }
 }
 

Modified: trunk/mcs/tools/xbuild/Parameters.cs
===================================================================
--- trunk/mcs/tools/xbuild/Parameters.cs        2006-09-20 12:39:21 UTC (rev 
65705)
+++ trunk/mcs/tools/xbuild/Parameters.cs        2006-09-20 12:57:41 UTC (rev 
65706)
@@ -88,7 +88,7 @@
                                }
                                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);
                        }
@@ -107,11 +107,11 @@
                                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");
                        }
                }
                
@@ -152,9 +152,10 @@
                                                 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 ();
                         }
@@ -166,13 +167,15 @@
                        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;
@@ -316,4 +319,4 @@
        }
 }
 
-#endif
\ No newline at end of file
+#endif

Modified: trunk/mcs/tools/xbuild/xbuild.exe.sources
===================================================================
--- trunk/mcs/tools/xbuild/xbuild.exe.sources   2006-09-20 12:39:21 UTC (rev 
65705)
+++ trunk/mcs/tools/xbuild/xbuild.exe.sources   2006-09-20 12:57:41 UTC (rev 
65706)
@@ -2,6 +2,7 @@
 ../../class/Microsoft.Build.Framework/Mono.XBuild.Framework/AssemblyLoadInfo.cs
 AssemblyInfo.cs
 CommandLineException.cs
+ErrorUtilities.cs
 LoggerInfo.cs
 Main.cs
 Parameters.cs

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to