Esempio n. 1
0
        public Rewriter(SemanticModel semanticModel, CodeTemplate template, ArtifactOutput output, ErrorAggregator aggregator)
        {
            this._semanticModel = semanticModel;
            this._output        = output;
            this._template      = template;
            this._aggregator    = aggregator;

            this._indentType   = _template.TypeIndent;
            this._indentMember = _template.MemberIndent;
        }
Esempio n. 2
0
        public Rewriter(SemanticModel semanticModel, CodeTemplate template, ArtifactOutput output, ErrorAggregator aggregator)
        {
            this._semanticModel = semanticModel;
            this._output = output;
            this._template = template;
            this._aggregator = aggregator;

            this._indentType = _template.TypeIndent;
            this._indentMember = _template.MemberIndent;
        }
Esempio n. 3
0
        public void InitializeCompiler(string csprojPath, CompileOptions options = null, string supressWarnings = "")
        {
            _options = (options != null) ? options : CompileOptions.DEFAULT;

            _options.StdError.Information($"{Constants.SharpJs} compile: project: {Path.GetFileNameWithoutExtension(csprojPath)}, configuration: {options.ProjectConfig}", true);

            string[] numbers = supressWarnings.Split(',', StringSplitOptions.RemoveEmptyEntries);
            var      q       = from n in numbers
                               select int.Parse(n);

            _aggregator = new ErrorAggregator(q);


            #region Parse C# project file
            _startPath = Path.GetDirectoryName(csprojPath);
            XDoc doc = XDoc.LoadFromFile(csprojPath);
            doc.AddNamespace("x", "http://schemas.microsoft.com/developer/msbuild/2003");

            _outputScript = doc.GetStringValue(@"x:PropertyGroup/x:AssemblyName") + ArtifactsFactory.JavaScriptFileExtension;


            var  cfgList     = doc.NavigateToList(@"x:PropertyGroup[@Condition]");
            bool configExist = false;
            foreach (var cfg in cfgList)
            {
                string condition = cfg.GetStringValue("@Condition");
                if (condition.Contains(options.ProjectConfig))
                {
                    var outpath = cfg.GetStringValue("x:OutputPath");
                    _outputDir  = Path.Combine(_startPath, outpath);
                    configExist = true;
                    break;
                }
            }
            if (!configExist)
            {
                _aggregator.AppendIssue(CompileIssue.CreateNoLocationIssue(IssueType.Error, IssueId.BuildConfigError, options.ProjectConfig));
                return;
            }

            //Note:Project ref, get the assembly name and should be able to found under output
            var rl = doc.NavigateToList(@"x:ItemGroup/x:ProjectReference");
            foreach (var r in rl)
            {
                var  refPrjPath = r.GetStringValue(@"@Include");
                XDoc xref       = XDoc.LoadFromFile(Path.Combine(_startPath, refPrjPath));
                xref.AddNamespace("x", "http://schemas.microsoft.com/developer/msbuild/2003");
                var libName = xref.GetStringValue(@"x:PropertyGroup/x:AssemblyName");

                string assemblyPath = Path.GetFullPath(Path.Combine(_outputDir, libName + ".dll"));

                _refPathList.Add(assemblyPath);
                CheckAssembly(assemblyPath);
            }

            rl = doc.NavigateToList(@"x:ItemGroup/x:Reference");
            foreach (var r in rl)
            {
                string hint = r.GetStringValue(@"x:HintPath");
                if (!string.IsNullOrEmpty(hint))//Note: Add external assembly.
                {
                    string assemblyPath = Path.GetFullPath(Path.Combine(_startPath, hint));
                    _refPathList.Add(assemblyPath);
                    if (!CheckAssembly(assemblyPath))
                    {
                        var issue = CompileIssue.CreateNoLocationIssue(IssueType.Warning, IssueId.InvalidAssembly, assemblyPath);
                        _aggregator.AppendIssue(issue);
                    }
                }
            }

            //Note:Item to be compiled.
            var cl = doc.NavigateToList(@"x:ItemGroup/x:Compile");
            foreach (var c in cl)
            {
                string path = c.GetStringValue("@Include");
                if (path == @"Properties\AssemblyInfo.cs")
                {
                    continue;
                }
                _compilePathList.Add(Path.Combine(_startPath, path));
            }

            _template = CodeTemplate.Parse(Path.Combine(_startPath, @"Properties\template.xml"));
            #endregion
        }
Esempio n. 4
0
        public void InitializeCompiler(string csprojPath, CompileOptions options = null, string supressWarnings = "")
        {
            _options = (options != null) ? options : CompileOptions.DEFAULT;

            _options.StdError.Information($"{Constants.SharpJs} compile: project: {Path.GetFileNameWithoutExtension(csprojPath)}, configuration: {options.ProjectConfig}", true);

            string[] numbers = supressWarnings.Split(',', StringSplitOptions.RemoveEmptyEntries);
            var q = from n in numbers
                    select int.Parse(n);
            _aggregator = new ErrorAggregator(q);


            #region Parse C# project file
            _startPath = Path.GetDirectoryName(csprojPath);
            XDoc doc = XDoc.LoadFromFile(csprojPath);
            doc.AddNamespace("x", "http://schemas.microsoft.com/developer/msbuild/2003");

            _outputScript = doc.GetStringValue(@"x:PropertyGroup/x:AssemblyName") + ArtifactsFactory.JavaScriptFileExtension;


            var cfgList = doc.NavigateToList(@"x:PropertyGroup[@Condition]");
            bool configExist = false;
            foreach (var cfg in cfgList)
            {
                string condition = cfg.GetStringValue("@Condition");
                if (condition.Contains(options.ProjectConfig))
                {
                    var outpath = cfg.GetStringValue("x:OutputPath");
                    _outputDir = Path.Combine(_startPath, outpath);
                    configExist = true;
                    break;
                }
            }
            if (!configExist)
            {
                _aggregator.AppendIssue(CompileIssue.CreateNoLocationIssue(IssueType.Error, IssueId.BuildConfigError, options.ProjectConfig));
                return;
            }

            //Note:Project ref, get the assembly name and should be able to found under output
            var rl = doc.NavigateToList(@"x:ItemGroup/x:ProjectReference");
            foreach (var r in rl)
            {
                var refPrjPath = r.GetStringValue(@"@Include");
                XDoc xref = XDoc.LoadFromFile(Path.Combine(_startPath, refPrjPath));
                xref.AddNamespace("x", "http://schemas.microsoft.com/developer/msbuild/2003");
                var libName = xref.GetStringValue(@"x:PropertyGroup/x:AssemblyName");

                string assemblyPath = Path.GetFullPath(Path.Combine(_outputDir, libName + ".dll"));

                _refPathList.Add(assemblyPath);
                CheckAssembly(assemblyPath);
            }

            rl = doc.NavigateToList(@"x:ItemGroup/x:Reference");
            foreach (var r in rl)
            {
                string hint = r.GetStringValue(@"x:HintPath");
                if (!string.IsNullOrEmpty(hint))//Note: Add external assembly.
                {
                    string assemblyPath = Path.GetFullPath(Path.Combine(_startPath, hint));
                    _refPathList.Add(assemblyPath);
                    if (!CheckAssembly(assemblyPath))
                    {
                        var issue = CompileIssue.CreateNoLocationIssue(IssueType.Warning, IssueId.InvalidAssembly, assemblyPath);
                        _aggregator.AppendIssue(issue);
                    }
                }
            }

            //Note:Item to be compiled.
            var cl = doc.NavigateToList(@"x:ItemGroup/x:Compile");
            foreach (var c in cl)
            {
                string path = c.GetStringValue("@Include");
                if (path == @"Properties\AssemblyInfo.cs")
                    continue;
                _compilePathList.Add(Path.Combine(_startPath, path));
            }

            _template = CodeTemplate.Parse(Path.Combine(_startPath, @"Properties\template.xml"));
            #endregion
        }