2007-05-10 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / tools / xbuild / ErrorUtilities.cs
1 //
2 // ErrorUtilities.cs: Functions that print out errors, warnings, help etc.
3 //
4 // Author:
5 //   Marek Sieradzki (marek.sieradzki@gmail.com)
6 //
7 // (C) 2006 Marek Sieradzki
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 #if NET_2_0
29
30 using System;
31
32 namespace Mono.XBuild.CommandLine {
33         public static class ErrorUtilities {
34
35                 static string[] usage = {
36                         "",
37                         "Syntax:              xbuild.exe [options] [project file]",
38                         "",
39                         "Description:         Builds the specified targets in the project file. If",
40                         "                     a project file is not specified, MSBuild searches the",
41                         "                     current working directory for a file that has a file",
42                         "                     extension that ends in \"proj\" and uses that file.",
43                         "",
44                         "Switches:",
45                         "",
46                         "  /help              Display this usage message. (Short form: /? or /h)",
47                         "",
48                         "  /nologo            Do not display the startup banner and copyright message.",
49                         "",
50                         "  /version           Display version information only. (Short form: /ver)",
51                         "",
52                         "  @<file>            Insert command-line settings from a text file. To specify",
53                         "                     multiple response files, specify each response file",
54                         "                     separately.",
55                         "",
56                         "  /noautoresponse    Do not auto-include the MSBuild.rsp file. (Short form:",
57                         "                     /noautorsp)",
58                         "",
59                         "  /target:<targets>  Build these targets in this project. Use a semicolon or a",
60                         "                     comma to separate multiple targets, or specify each",
61                         "                     target separately. (Short form: /t)",
62                         "                     Example:",
63                         "                       /target:Resources;Compile",
64                         "",
65                         "  /property:<n>=<v>  Set or override these project-level properties. <n> is",
66                         "                     the property name, and <v> is the property value. Use a",
67                         "                     semicolon or a comma to separate multiple properties, or",
68                         "                     specify each property separately. (Short form: /p)",
69                         "                     Example:",
70                         @"                       /property:WarningLevel=2;OutDir=bin\Debug\",
71                         "",
72                         "  /logger:<logger>   Use this logger to log events from MSBuild. To specify",
73                         "                     multiple loggers, specify each logger separately.",
74                         "                     The <logger> syntax is:",
75                         "                        [<logger class>,]<logger assembly>[;<logger parameters>]",
76                         "                     The <logger class> syntax is:",
77                         "                        [<partial or full namespace>.]<logger class name>",
78                         "                     The <logger assembly> syntax is:",
79                         "                        {<assembly name>[,<strong name>] | <assembly file>}",
80                         "                     The <logger parameters> are optional, and are passed",
81                         "                     to the logger exactly as you typed them. (Short form: /l)",
82                         "                     Examples:",
83                         "                       /logger:XMLLogger,MyLogger,Version=1.0.2,Culture=neutral",
84                         @"                       /logger:XMLLogger,C:\Loggers\MyLogger.dll;OutputAsHTML",
85                         "",
86                         "  /verbosity:<level> Display this amount of information in the event log.",
87                         "                     The available verbosity levels are: q[uiet], m[inimal],",
88                         "                     n[ormal], d[etailed], and diag[nostic]. (Short form: /v)",
89                         "                     Example:",
90                         "                       /verbosity:quiet",
91                         "",
92                         "  /consoleloggerparameters:<parameters>",
93                         "                     Parameters to console logger. (Short form: /clp)",
94                         "                     The available parameters are:",
95                         "                        PerformanceSummary--show time spent in tasks, targets",
96                         "                            and projects.",
97                         "                        NoSummary--don't show error and warning summary at the",
98                         "                            end.",
99                         "                     Example:",
100                         "                        /consoleloggerparameters:PerformanceSummary;NoSummary",
101                         "",
102                         "  /noconsolelogger   Disable the default console logger and do not log events",
103                         "                     to the console. (Short form: /noconlog)",
104                         "",
105                         "  /validate          Validate the project against the default schema. (Short",
106                         "                     form: /val)",
107                         "",
108                         "  /validate:<schema> Validate the project against the specified schema. (Short",
109                         "                     form: /val)",
110                         "                     Example:",
111                         "                       /validate:MyExtendedBuildSchema.xsd",
112                         "",
113                         "Examples:",
114                         "",
115                         "        MSBuild MyApp.sln /t:Rebuild /p:Configuration=Release",
116                         "        MSBuild MyApp.csproj /t:Clean /p:Configuration=Debug",
117
118                 };
119                 
120                 static string[] version = {
121                         "XBuild Engine Version 0.1",
122                         String.Format ("Mono, Version {0}", Consts.MonoVersion),
123                         "Copyright (C) Marek Sieradzki 2005. All rights reserved.",
124                 };
125
126                 
127                 static public void ReportError (int errorNum, string msg)
128                 {
129                         Console.WriteLine (String.Format ("MSBUILD: error MSBUILD{0:0000}: {1}", errorNum, msg));
130                         Environment.Exit (1);
131                 }
132
133                 static public void ReportWarning (int errorNum, string msg)
134                 {
135                         Console.WriteLine (String.Format ("MSBUILD: warning MSBUILD{0:0000}: {1}", errorNum, msg));
136                 }
137
138                 static public void ReportInvalidArgument (string option, string value)
139                 {
140                         ReportError (1012, String.Format ("'{0}' is not a valid setting for option '{1}'", value, option));
141                 }
142
143                 static public void ReportMissingArgument (string option)
144                 {
145                         ReportError (1003, String.Format ("Compiler option '{0}' must be followed by an argument", option));
146                 }
147
148                 static public void ReportNotImplemented (string option)
149                 {
150                         ReportError (0, String.Format ("Compiler option '{0}' is not implemented", option));
151                 }
152  
153                 static public void ReportMissingFileSpec (string option)
154                 {
155                         ReportError (1008, String.Format ("Missing file specification for '{0}' command-line option", option));
156                 }
157
158                 static public void ReportMissingText (string option)
159                 {
160                         ReportError (1010, String.Format ("Missing ':<text>' for '{0}' option", option));
161                 }
162
163                 static public void ShowUsage ()
164                 {
165                         Display (usage);
166                         Environment.Exit (0);
167                         
168                 }
169
170                 static public void ShowVersion (bool exit)
171                 {
172                         Display (version);
173                         if (exit)
174                                 Environment.Exit (0);
175                 }
176
177                 static private void Display (string[] array)
178                 {
179                         foreach (string s in array)
180                                 Console.WriteLine (s);
181                 }
182         }
183 }
184
185 #endif