[xbuild] Implement FileLogger . Fix #676650 .
[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[] version = {
36                         String.Format ("XBuild Engine Version {0}", Consts.MonoVersion),
37                         String.Format ("Mono, Version {0}", Consts.MonoVersion),
38                         "Copyright (C) Marek Sieradzki 2005-2008, Novell 2008-2011.",
39                 };
40
41                 
42                 static public void ReportError (int errorNum, string msg)
43                 {
44                         Console.WriteLine (String.Format ("MSBUILD: error MSBUILD{0:0000}: {1}", errorNum, msg));
45                         Environment.Exit (1);
46                 }
47
48                 static public void ReportWarning (int errorNum, string msg)
49                 {
50                         Console.WriteLine (String.Format ("MSBUILD: warning MSBUILD{0:0000}: {1}", errorNum, msg));
51                 }
52
53                 static public void ReportInvalidArgument (string option, string value)
54                 {
55                         ReportError (1012, String.Format ("'{0}' is not a valid setting for option '{1}'", value, option));
56                 }
57
58                 static public void ReportMissingArgument (string option)
59                 {
60                         ReportError (1003, String.Format ("Compiler option '{0}' must be followed by an argument", option));
61                 }
62
63                 static public void ReportNotImplemented (string option)
64                 {
65                         ReportError (0, String.Format ("Compiler option '{0}' is not implemented", option));
66                 }
67  
68                 static public void ReportMissingFileSpec (string option)
69                 {
70                         ReportError (1008, String.Format ("Missing file specification for '{0}' command-line option", option));
71                 }
72
73                 static public void ReportMissingText (string option)
74                 {
75                         ReportError (1010, String.Format ("Missing ':<text>' for '{0}' option", option));
76                 }
77
78                 static public void ShowUsage ()
79                 {
80                         Display (version);
81                         Console.WriteLine ("xbuild [options] [project-file]");
82                         Console.WriteLine (
83                                 "    /version           Show the xbuild version\n" +
84                                 "    /noconsolelogger   Disable the default console logger\n" +
85                                 "    /target:T1[,TN]    List of targets to build\n" +
86                                 "    /property:Name=Value\n" +
87                                 "                       Set or override project properties\n" +
88                                 "    /logger:<logger>   Custom logger to log events\n" +
89                                 "    /verbosity:<level> Logger verbosity level : quiet, minimal, normal, detailed, diagnostic\n" +
90                                 "    /validate          Validate the project file against the schema\n" +
91                                 "    /validate:<schema> Validate the project file against the specified schema\n" +
92                                 "    /consoleloggerparameters:<params>\n" +
93                                 "    /clp:<params>\n" +
94                                 "                       Parameters for the console logger\n" +
95                                 "    /fileloggerparameters[n]:<params>\n" +
96                                 "    /flp[n]:<params>\n" +
97                                 "                       Parameters for the file logger, eg. LogFile=foo.log\n" +
98                                 "    /nologo            Don't show the initial banner\n" +
99                                 "    /help              Show this help\n"
100                                 );
101                         Environment.Exit (0);
102                 }
103
104                 static public void ShowVersion (bool exit)
105                 {
106                         Display (version);
107                         if (exit)
108                                 Environment.Exit (0);
109                 }
110
111                 static private void Display (string[] array)
112                 {
113                         foreach (string s in array)
114                                 Console.WriteLine (s);
115                 }
116         }
117 }
118
119 #endif