// 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;
using System.Collections;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Text;
+using System.Text.RegularExpressions;
using System.Threading;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
string stdOutEncoding;
string workingDirectory;
string scriptFile;
+
+ Func<string, bool> errorMatcher, warningMatcher;
public Exec ()
{
protected internal override void AddCommandLineCommands (CommandLineBuilderExtension commandLine)
{
if (IsRunningOnWindows)
- commandLine.AppendSwitch ("/c");
+ commandLine.AppendSwitch ("/q /c");
if (!String.IsNullOrEmpty (command)) {
scriptFile = Path.GetTempFileName ();
+ if (IsRunningOnWindows)
+ scriptFile = scriptFile + ".bat";
using (StreamWriter sw = new StreamWriter (scriptFile)) {
sw.Write (command);
}
string commandLineCommands)
{
try {
+ errorMatcher = GetTryMatchRegexFunc (CustomErrorRegularExpression, true);
+ warningMatcher = GetTryMatchRegexFunc (CustomWarningRegularExpression, false);
return base.ExecuteTool (pathToTool, responseFileCommands, commandLineCommands);
} finally {
if (scriptFile != null)
Log.LogMessage (MessageImportance.Normal, "Executing: " + command);
}
- protected override void LogEventsFromTextOutput (string singleLine, MessageImportance importance)
+ protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance)
{
- Log.LogMessage (importance, singleLine);
+ if (IgnoreStandardErrorWarningFormat ||
+ (!errorMatcher (singleLine) && !warningMatcher (singleLine)))
+ Log.LogMessage (messageImportance, singleLine);
+ }
+
+ // @is_error_type - log as errors, else warnings
+ Func<string, bool> GetTryMatchRegexFunc (string regex_str, bool is_error_type)
+ {
+ bool is_bad = false;
+ Regex regex = null;
+ return (singleLine) => {
+ if (String.IsNullOrEmpty (regex_str) || is_bad)
+ return false;
+
+ try {
+ if (regex == null)
+ regex = new Regex (regex_str, RegexOptions.Compiled);
+ } catch (ArgumentException ae) {
+ Log.LogError ("The regular expression specified for '{0}' is invalid : {1}",
+ is_error_type ? "errors" : "warnings", ae.Message);
+ Log.LogMessage (MessageImportance.Low, "The regular expression specified for '{0}' is invalid : {1}",
+ is_error_type ? "errors" : "warnings", ae.ToString ());
+
+ is_bad = true;
+ return false;
+ }
+
+ if (!regex.Match (singleLine).Success)
+ return false;
+
+ if (is_error_type)
+ Log.LogError (singleLine);
+ else
+ Log.LogWarning (singleLine);
+ return true;
+ };
}
[MonoTODO]
[Required]
public string Command {
get { return command; }
- set { command = value; }
+ set {
+ command = value;
+ if (Path.DirectorySeparatorChar == '/')
+ command = command.Replace ("\r\n", "\n");
+ }
}
public bool IgnoreExitCode {
protected override MessageImportance StandardOutputLoggingImportance {
get { return base.StandardOutputLoggingImportance; }
}
+
+ public bool IgnoreStandardErrorWarningFormat { get; set; }
+
+ public string CustomErrorRegularExpression { get; set; }
+
+ public string CustomWarningRegularExpression { get; set; }
[MonoTODO]
[Output]
}
}
-
-#endif