public bool Execute()
{
try
{
Assembly antlrAssembly = Assembly.LoadFrom(AntlrToolPath);
Type antlrToolType = antlrAssembly.GetType("Antlr3.AntlrTool");
Type errorManagerType = antlrAssembly.GetType("Antlr3.Tool.ErrorManager");
object tool = Activator.CreateInstance(antlrAssembly.GetType("Antlr3.AntlrTool"), new object[] { Path.GetDirectoryName(AntlrToolPath) });
Action process = (Action)Delegate.CreateDelegate(typeof(Action), tool, antlrToolType.GetMethod("Process"));
Action<string[]> ProcessArgs = (Action<string[]>)Delegate.CreateDelegate(typeof(Action<string[]>), tool, antlrToolType.GetMethod("ProcessArgs"));
Func<IList<string>> GetGeneratedFiles = (Func<IList<string>>)Delegate.CreateDelegate(typeof(Func<IList<string>>), tool, antlrToolType.GetProperty("GeneratedFiles").GetGetMethod());
Func<int> GetNumErrors = (Func<int>)Delegate.CreateDelegate(typeof(Func<int>), errorManagerType.GetMethod("GetNumErrors"));
Action<TraceListener> SetTraceListener = (Action<TraceListener>)Delegate.CreateDelegate(typeof(Action<TraceListener>), errorManagerType.GetProperty("ExternalListener").GetSetMethod());
TimeSpan conversionTimeout = TimeSpan.FromSeconds(10);
List<string> args =
new List<string>()
{
"-Xconversiontimeout", ((int)conversionTimeout.TotalMilliseconds).ToString(),
"-fo", OutputPath,
"-message-format", "vs2005"
};
if (!String.IsNullOrEmpty(LibPaths))
{
args.Add("-lib");
args.Add(LibPaths);
}
args.AddRange(SourceCodeFiles);
using (LoggingTraceListener traceListener = new LoggingTraceListener(_buildMessages))
{
SetTraceListener(traceListener);
ProcessArgs(args.ToArray());
process();
}
_generatedCodeFiles.AddRange(GetGeneratedFiles().Where(file => Path.GetExtension(file).Equals(".cs", StringComparison.OrdinalIgnoreCase)));
int errorCount = GetNumErrors();
return errorCount == 0;
}
catch (Exception e)
{
if (e is TargetInvocationException && e.InnerException != null)
e = e.InnerException;
_buildMessages.Add(new BuildMessage(e.Message));
throw;
}
}