2 // Parameters.cs: Class that contains information about command line parameters
5 // Marek Sieradzki (marek.sieradzki@gmail.com)
7 // (C) 2005 Marek Sieradzki
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
32 using System.Collections;
34 using Microsoft.Build.BuildEngine;
35 using Microsoft.Build.Framework;
36 using Microsoft.Build.Utilities;
38 namespace Mono.XBuild.CommandLine {
39 public class Parameters {
41 string consoleLoggerParameters;
46 LoggerVerbosity loggerVerbosity;
50 BuildPropertyGroup properties;
51 IList remainingArguments;
52 Hashtable responseFiles;
55 string validationSchema;
59 public Parameters (string binPath)
61 consoleLoggerParameters = "";
63 displayVersion = true;
64 loggers = new ArrayList ();
65 loggerVerbosity = LoggerVerbosity.Normal;
66 noConsoleLogger = false;
68 properties = new BuildPropertyGroup ();
69 targets = new string [0];
71 responseFile = Path.Combine (binPath, "xbuild.rsp");
74 public void ParseArguments (string[] args)
76 bool autoResponse = true;
77 flatArguments = new ArrayList ();
78 remainingArguments = new ArrayList ();
79 responseFiles = new Hashtable ();
80 foreach (string s in args) {
81 if (s.StartsWith ("/noautoresponse") || s.StartsWith ("/noautorsp")) {
86 flatArguments.Add (s);
89 string responseFilename = Path.GetFullPath (s.Substring (1));
90 if (responseFiles.ContainsKey (responseFilename))
91 ErrorUtilities.ReportError (1, String.Format ("We already have {0} file.", responseFilename));
92 responseFiles [responseFilename] = responseFilename;
93 LoadResponseFile (responseFilename);
95 if (autoResponse == true) {
96 // FIXME: we do not allow nested auto response file
97 LoadResponseFile (responseFile);
99 foreach (string s in flatArguments) {
101 ParseFlatArgument (s);
103 remainingArguments.Add (s);
105 if (remainingArguments.Count == 0) {
106 string[] files = Directory.GetFiles (Directory.GetCurrentDirectory (), "*.??proj");
107 if (files.Length > 0)
108 projectFile = files [0];
110 ErrorUtilities.ReportError (3, "No .proj file specified and no found in current directory.");
111 } else if (remainingArguments.Count == 1) {
112 projectFile = (string) remainingArguments [0];
114 ErrorUtilities.ReportError (4, "Too many project files specified");
118 private void LoadResponseFile (string filename)
120 StreamReader sr = null;
123 sr = new StreamReader (filename);
124 StringBuilder sb = new StringBuilder ();
126 while ((line = sr.ReadLine ()) != null) {
129 for (int i = 0; i < t; i++) {
132 if (c == '"' || c == '\'') {
135 for (i++; i < t; i++) {
142 } else if (c == ' ') {
144 flatArguments.Add (sb.ToString ());
151 flatArguments.Add (sb.ToString ());
155 } catch (Exception) {
156 // FIXME: we lose exception message
157 ErrorUtilities.ReportError (2, "Error during loading response file.");
164 private void ParseFlatArgument (string s)
170 ErrorUtilities.ShowUsage ();
177 ErrorUtilities.ShowVersion (true);
179 case "/noconsolelogger":
181 noConsoleLogger = true;
188 if (s.StartsWith ("/target:") || s.StartsWith ("/t:")) {
191 if (s.StartsWith ("/property:") || s.StartsWith ("/p:")) {
194 if (s.StartsWith ("/logger:") || s.StartsWith ("/l:")) {
197 if (s.StartsWith ("/verbosity:") || s.StartsWith ("/v:")) {
198 ProcessVerbosity (s);
200 if (s.StartsWith ("/consoleloggerparameters:") || s.StartsWith ("/clp:")) {
201 ProcessConsoleLoggerParameters (s);
203 if (s.StartsWith ("/validate:") || s.StartsWith ("/val:")) {
210 internal void ProcessTarget (string s)
212 string[] temp = s.Split (':');
213 targets = temp [1].Split (';');
216 internal void ProcessProperty (string s)
218 string[] parameter, splittedProperties, property;
219 parameter = s.Split (':');
220 splittedProperties = parameter [1].Split (';');
221 foreach (string st in splittedProperties) {
222 property = st.Split ('=');
223 properties.AddNewProperty (property [0], property [1]);
227 internal void ProcessLogger (string s)
229 loggers.Add (new LoggerInfo (s));
232 internal void ProcessVerbosity (string s)
234 string[] temp = s.Split (':');
238 loggerVerbosity = LoggerVerbosity.Quiet;
242 loggerVerbosity = LoggerVerbosity.Minimal;
246 loggerVerbosity = LoggerVerbosity.Normal;
250 loggerVerbosity = LoggerVerbosity.Detailed;
254 loggerVerbosity = LoggerVerbosity.Diagnostic;
259 internal void ProcessConsoleLoggerParameters (string s)
261 consoleLoggerParameters = s;
264 internal void ProcessValidate (string s)
268 temp = s.Split (':');
269 validationSchema = temp [1];
271 public bool DisplayHelp {
272 get { return displayHelp; }
276 get { return noLogo; }
279 public bool DisplayVersion {
280 get { return displayVersion; }
283 public string ProjectFile {
284 get { return projectFile; }
287 public string[] Targets {
288 get { return targets; }
291 public BuildPropertyGroup Properties {
292 get { return properties; }
295 public IList Loggers {
296 get { return loggers; }
299 public LoggerVerbosity LoggerVerbosity {
300 get { return loggerVerbosity; }
303 public string ConsoleLoggerParameters {
304 get { return consoleLoggerParameters; }
307 public bool NoConsoleLogger {
308 get { return noConsoleLogger; }
311 public bool Validate {
312 get { return validate; }
315 public string ValidationSchema {
316 get { return validationSchema; }