Inheritance: System.MarshalByRefObject
        private AntlrClassGenerationTaskInternal CreateBuildTaskWrapper()
        {
            var wrapper = new AntlrClassGenerationTaskInternal();

            IList <string> sourceCodeFiles = null;

            if (this.SourceCodeFiles != null)
            {
                sourceCodeFiles = new List <string>(SourceCodeFiles.Length);
                foreach (ITaskItem taskItem in SourceCodeFiles)
                {
                    sourceCodeFiles.Add(taskItem.ItemSpec);
                }
            }

            if (this.TokensFiles != null && this.TokensFiles.Length > 0)
            {
                Directory.CreateDirectory(OutputPath);

                HashSet <string> copied = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                foreach (ITaskItem taskItem in TokensFiles)
                {
                    string fileName = taskItem.ItemSpec;
                    if (!File.Exists(fileName))
                    {
                        Log.LogError("The tokens file '{0}' does not exist.", fileName);
                        continue;
                    }

                    string vocabName = Path.GetFileNameWithoutExtension(fileName);
                    if (!copied.Add(vocabName))
                    {
                        Log.LogWarning("The tokens file '{0}' conflicts with another tokens file in the same project.", fileName);
                        continue;
                    }

                    string target = Path.Combine(OutputPath, Path.GetFileName(fileName));
                    if (!Path.GetExtension(target).Equals(".tokens", StringComparison.OrdinalIgnoreCase))
                    {
                        Log.LogError("The destination for the tokens file '{0}' did not have the correct extension '.tokens'.", target);
                        continue;
                    }

                    File.Copy(fileName, target, true);
                    File.SetAttributes(target, File.GetAttributes(target) & ~FileAttributes.ReadOnly);
                }
            }

            wrapper.AntlrToolPath            = AntlrToolPath;
            wrapper.SourceCodeFiles          = sourceCodeFiles;
            wrapper.TargetLanguage           = TargetLanguage;
            wrapper.OutputPath               = OutputPath;
            wrapper.RootNamespace            = RootNamespace;
            wrapper.GeneratedSourceExtension = GeneratedSourceExtension;
            wrapper.LanguageSourceExtensions = LanguageSourceExtensions;
            wrapper.DebugGrammar             = DebugGrammar;
            wrapper.ProfileGrammar           = ProfileGrammar;
            return(wrapper);
        }
        private AntlrClassGenerationTaskInternal CreateBuildTaskWrapper(AppDomain domain)
        {
            AntlrClassGenerationTaskInternal wrapper = (AntlrClassGenerationTaskInternal)domain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(AntlrClassGenerationTaskInternal).FullName);

            IList <string> sourceCodeFiles = null;

            if (this.SourceCodeFiles != null)
            {
                sourceCodeFiles = new List <string>(SourceCodeFiles.Length);
                foreach (ITaskItem taskItem in SourceCodeFiles)
                {
                    sourceCodeFiles.Add(taskItem.ItemSpec);
                }
            }

            if (this.TokensFiles != null && this.TokensFiles.Length > 0)
            {
                HashSet <string> copied = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                foreach (ITaskItem taskItem in TokensFiles)
                {
                    string fileName = taskItem.ItemSpec;
                    if (!File.Exists(fileName))
                    {
                        Log.LogError("The tokens file '{0}' does not exist.", fileName);
                        continue;
                    }

                    string vocabName = Path.GetFileNameWithoutExtension(fileName);
                    if (!copied.Add(vocabName))
                    {
                        Log.LogWarning("The tokens file '{0}' conflicts with another tokens file in the same project.", fileName);
                        continue;
                    }

                    string target = Path.Combine(OutputPath, Path.GetFileName(fileName));
                    if (!Path.GetExtension(target).Equals(".tokens", StringComparison.OrdinalIgnoreCase))
                    {
                        Log.LogError("The destination for the tokens file '{0}' did not have the correct extension '.tokens'.", target);
                        continue;
                    }

                    File.Copy(fileName, target, true);
                    File.SetAttributes(target, File.GetAttributes(target) & ~FileAttributes.ReadOnly);
                }
            }

            wrapper.AntlrToolPath            = AntlrToolPath;
            wrapper.SourceCodeFiles          = sourceCodeFiles;
            wrapper.LibPaths                 = LibPaths;
            wrapper.Language                 = Language;
            wrapper.OutputPath               = OutputPath;
            wrapper.RootNamespace            = RootNamespace;
            wrapper.GeneratedSourceExtension = GeneratedSourceExtension;
            return(wrapper);
        }
        public override bool Execute()
        {
            bool success;

            if (!Path.IsPathRooted(AntlrToolPath))
            {
                AntlrToolPath = Path.Combine(Path.GetDirectoryName(BuildEngine.ProjectFileOfTaskNode), AntlrToolPath);
            }

            if (!Path.IsPathRooted(BuildTaskPath))
            {
                BuildTaskPath = Path.Combine(Path.GetDirectoryName(BuildEngine.ProjectFileOfTaskNode), BuildTaskPath);
            }

            try
            {
                AntlrClassGenerationTaskInternal wrapper = CreateBuildTaskWrapper();

                _lock.Wait();
                try
                {
                    success = wrapper.Execute();
                }
                finally
                {
                    _lock.Release();
                }

                if (success)
                {
                    _generatedCodeFiles.AddRange(wrapper.GeneratedCodeFiles.Select(file => (ITaskItem) new TaskItem(file)));
                }

                foreach (BuildMessage message in wrapper.BuildMessages)
                {
                    ProcessBuildMessage(message);
                }
            }
            catch (Exception exception)
            {
                if (IsFatalException(exception))
                {
                    throw;
                }

                ProcessExceptionAsBuildMessage(exception);
                success = false;
            }

            return(success);
        }
Esempio n. 4
0
        public override bool Execute()
        {
            AppDomain domain = null;
            bool      success;

            if (!Path.IsPathRooted(AntlrToolPath))
            {
                AntlrToolPath = Path.Combine(Path.GetDirectoryName(BuildEngine.ProjectFileOfTaskNode), AntlrToolPath);
            }

            if (!Path.IsPathRooted(BuildTaskPath))
            {
                BuildTaskPath = Path.Combine(Path.GetDirectoryName(BuildEngine.ProjectFileOfTaskNode), BuildTaskPath);
            }

            try
            {
                domain = GetAntlrTaskAppDomain();
                AntlrClassGenerationTaskInternal wrapper = CreateBuildTaskWrapper(domain);
                success = wrapper.Execute();

                if (success)
                {
                    _generatedCodeFiles.AddRange(wrapper.GeneratedCodeFiles.Select(file => (ITaskItem) new TaskItem(file)));
                }

                foreach (BuildMessage message in wrapper.BuildMessages)
                {
                    ProcessBuildMessage(message);
                }
            }
            catch (Exception exception)
            {
                if (IsFatalException(exception))
                {
                    throw;
                }

                ProcessExceptionAsBuildMessage(exception);
                success = false;
            }
            finally
            {
                if (domain != null && domain != _sharedAppDomain)
                {
                    AppDomain.Unload(domain);
                }
            }

            return(success);
        }
Esempio n. 5
0
        public override bool Execute()
        {
            AppDomain domain = null;
            bool      success;

            try
            {
                AppDomainSetup info = new AppDomainSetup
                {
                    ApplicationBase    = BuildTaskPath,
                    LoaderOptimization = LoaderOptimization.MultiDomainHost,
                    ShadowCopyFiles    = "true"
                };

                string friendlyName = "AntlrClassGenerationDomain_" + Guid.NewGuid();
                domain = AppDomain.CreateDomain(friendlyName, AppDomain.CurrentDomain.Evidence, info, new NamedPermissionSet("FullTrust"), new StrongName[0]);
                AntlrClassGenerationTaskInternal wrapper = CreateBuildTaskWrapper(domain);
                success = wrapper.Execute();

                if (success)
                {
                    _generatedCodeFiles.AddRange(wrapper.GeneratedCodeFiles.Select(file => (ITaskItem) new TaskItem(file)));
                }

                foreach (BuildMessage message in wrapper.BuildMessages)
                {
                    ProcessBuildMessage(message);
                }
            }
            catch (Exception exception)
            {
                if (IsFatalException(exception))
                {
                    throw;
                }

                ProcessExceptionAsBuildMessage(exception);
                success = false;
            }
            finally
            {
                if (domain != null)
                {
                    AppDomain.Unload(domain);
                }
            }

            return(success);
        }
Esempio n. 6
0
        public override bool Execute()
        {
            AppDomain domain = null;
            bool      success;

            try
            {
                domain = GetAntlrTaskAppDomain();
                AntlrClassGenerationTaskInternal wrapper = CreateBuildTaskWrapper(domain);
                success = wrapper.Execute();

                if (success)
                {
                    _generatedCodeFiles.AddRange(wrapper.GeneratedCodeFiles.Select(file => (ITaskItem) new TaskItem(file)));
                }

                foreach (BuildMessage message in wrapper.BuildMessages)
                {
                    ProcessBuildMessage(message);
                }
            }
            catch (Exception exception)
            {
                if (IsFatalException(exception))
                {
                    throw;
                }

                ProcessExceptionAsBuildMessage(exception);
                success = false;
            }
            finally
            {
                if (domain != null && domain != _sharedAppDomain)
                {
                    AppDomain.Unload(domain);
                }
            }

            return(success);
        }