private void HandleOutputDataReceived(string data)
        {
            if (string.IsNullOrEmpty(data))
            {
                return;
            }

            try
            {
                Match match = GeneratedFileMessageFormat.Match(data);
                if (!match.Success)
                {
                    _buildMessages.Add(new BuildMessage(data));
                    return;
                }

                string fileName = match.Groups["OUTPUT"].Value;
                if (LanguageSourceExtensions.Contains(Path.GetExtension(fileName), StringComparer.OrdinalIgnoreCase))
                {
                    GeneratedCodeFiles.Add(match.Groups["OUTPUT"].Value);
                }
            }
            catch (Exception ex)
            {
                if (Antlr4ClassGenerationTask.IsFatalException(ex))
                {
                    throw;
                }

                _buildMessages.Add(new BuildMessage(ex.Message));
            }
        }
        private void HandleOutputDataReceivedFirstTime(object sender, DataReceivedEventArgs e)
        {
            string dep = e.Data as string;

            if (string.IsNullOrEmpty(dep))
            {
                return;
            }
            // Parse the dep string as "file-name1 : file-name2". Strip off the name
            // file-name1 and cache it.
            try
            {
                Match match = GeneratedFileMessageFormatJavaTool.Match(dep);
                if (!match.Success)
                {
                    return;
                }
                string fileName = match.Groups["OUTPUT"].Value;
                if (LanguageSourceExtensions.Contains(Path.GetExtension(fileName), StringComparer.OrdinalIgnoreCase))
                {
                    GeneratedCodeFiles.Add(match.Groups["OUTPUT"].Value);
                }
            }
            catch (Exception ex)
            {
                if (Antlr4ClassGenerationTask.IsFatalException(ex))
                {
                    throw;
                }

                _buildMessages.Add(new BuildMessage(ex.Message));
            }
        }
Beispiel #3
0
        private void HandleOutputDataReceived(string data)
        {
            if (string.IsNullOrEmpty(data))
            {
                return;
            }

            try
            {
                Match match = GeneratedFileMessageFormat.Match(data);
                if (!match.Success)
                {
                    this.AddDiagnostic(DiagnosticSeverity.Info, -1, null, -1, -1, data);
                    return;
                }

                string fileName = match.Groups["OUTPUT"].Value;
                if (LanguageSourceExtensions != null && LanguageSourceExtensions.Contains(Path.GetExtension(fileName), StringComparer.OrdinalIgnoreCase))
                {
                    GeneratedCodeFiles.Add(match.Groups["OUTPUT"].Value);
                }
            }
            catch (Exception ex)
            {
                this.AddDiagnostic(DiagnosticSeverity.Error, -1, null, -1, -1, ex.ToString().Replace('\r', ' ').Replace('\n', ' '));
            }
        }
Beispiel #4
0
        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 (DebugGrammar)
                {
                    args.Add("-debug");
                }

                if (ProfileGrammar)
                {
                    args.Add("-profile");
                }

                if (!string.IsNullOrEmpty(TargetLanguage))
                {
                    args.Add("-language");
                    args.Add(TargetLanguage);
                }

                args.AddRange(SourceCodeFiles);

                using (LoggingTraceListener traceListener = new LoggingTraceListener(_buildMessages))
                {
                    SetTraceListener(traceListener);
                    ProcessArgs(args.ToArray());
                    process();
                }

                _generatedCodeFiles.AddRange(GetGeneratedFiles().Where(file => LanguageSourceExtensions.Contains(Path.GetExtension(file), StringComparer.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;
            }
        }