public void BeforeCompile(IBeforeCompileContext context)
        {
            JObject rawProjectFile = null;
            using (var fs = File.OpenRead(context.ProjectContext.ProjectFilePath))
            {
                rawProjectFile = JObject.Load(new JsonTextReader(new StreamReader(fs)));
            }

            var excludePatterns = PatternsCollectionHelper.GetPatternsCollection(
                rawProjectFile,
                context.ProjectContext.ProjectDirectory,
                context.ProjectContext.ProjectFilePath,
                "exclude",
                DefaultExcludePatterns);

            var matcher = new Matcher();
            matcher.AddInclude("**/*.resx").AddExcludePatterns(excludePatterns);

            var resXFiles = matcher.GetResultsInFullPath(context.ProjectContext.ProjectDirectory);

            foreach (var resXFile in resXFiles)
            {
                WriteResourceFile(resXFile);
            }
        }
Esempio n. 2
0
        public bool Build()
        {
            var projectFilesFinder = new Matcher();

            // Resolve all the project names
            var projectFilesToBuild = new List<string>();
            foreach(var pattern in _buildOptions.ProjectPatterns)
            {
                if (pattern.Contains("*"))
                {
                    // Requires globbing
                    projectFilesFinder.AddInclude(NormalizeGlobbingPattern(pattern));
                }
                else
                {
                    projectFilesToBuild.Add(pattern);
                }
            }

            var rootDirectory = Directory.GetCurrentDirectory();
            var patternSearchFolder = new DirectoryInfoWrapper(new DirectoryInfo(rootDirectory));
            var globbingProjects = projectFilesFinder.Execute(patternSearchFolder).Files.Select(file =>
                Path.Combine(rootDirectory, file));
            projectFilesToBuild.AddRange(globbingProjects);

            var sw = Stopwatch.StartNew();

            _cacheContextAccessor = new CacheContextAccessor();
            _cache = new Cache(_cacheContextAccessor);

            var globalSucess = true;
            foreach (var project in projectFilesToBuild)
            {
                var buildSuccess = BuildInternal(project);
                globalSucess &= buildSuccess;
            }

            _buildOptions.Reports.Information.WriteLine($"Total build time elapsed: { sw.Elapsed }");
            _buildOptions.Reports.Information.WriteLine($"Total projects built: { projectFilesToBuild.Count }");

            return globalSucess;
        }
        private bool ScanForProjects()
        {
            _logger.LogInformation(string.Format("Scanning '{0}' for DNX projects", _env.Path));

            var anyProjects = false;

            // Single project in this folder
            var projectInThisFolder = Path.Combine(_env.Path, "project.json");

            if (File.Exists(projectInThisFolder))
            {
                if (_context.TryAddProject(projectInThisFolder))
                {
                    _logger.LogInformation(string.Format("Found project '{0}'.", projectInThisFolder));

                    anyProjects = true;
                }
            }
            else
            {
                IEnumerable<string> paths;
#if DNX451
                if (_options.Dnx.Projects != "**/project.json")
                {
                    var matcher = new Matcher();
                    matcher.AddIncludePatterns(_options.Dnx.Projects.Split(';'));
                    paths = matcher.GetResultsInFullPath(_env.Path);
                }
                else
                {
                    paths = _directoryEnumerator.SafeEnumerateFiles(_env.Path, "project.json");
                }
#else
                // The matcher works on CoreCLR but Omnisharp still targets aspnetcore50 instead of
                // dnxcore50
                paths = _directoryEnumerator.SafeEnumerateFiles(_env.Path, "project.json");
#endif
                foreach (var path in paths)
                {
                    string projectFile = null;

                    if (Path.GetFileName(path) == "project.json")
                    {
                        projectFile = path;
                    }
                    else
                    {
                        projectFile = Path.Combine(path, "project.json");
                        if (!File.Exists(projectFile))
                        {
                            projectFile = null;
                        }
                    }

                    if (string.IsNullOrEmpty(projectFile))
                    {
                        continue;
                    }

                    if (!_context.TryAddProject(projectFile))
                    {
                        continue;
                    }

                    _logger.LogInformation(string.Format("Found project '{0}'.", projectFile));

                    anyProjects = true;
                }
            }

            return anyProjects;
        }
Esempio n. 4
0
        internal static IEnumerable<PhysicalPackageFile> CollectAdditionalFiles(DirectoryInfoBase rootDirectory, IEnumerable<PackIncludeEntry> projectFileGlobs, string projectFilePath, IList<DiagnosticMessage> diagnostics)
        {
            foreach (var entry in projectFileGlobs)
            {
                // Evaluate the globs on the right
                var matcher = new Matcher();
                matcher.AddIncludePatterns(entry.SourceGlobs);
                var results = matcher.Execute(rootDirectory);
                var files = results.Files.ToList();

                // Check for illegal characters
                if (string.IsNullOrEmpty(entry.Target))
                {
                    diagnostics.Add(new DiagnosticMessage(
                        $"Invalid '{ProjectFilesCollection.PackIncludePropertyName}' section. The target '{entry.Target}' is invalid, " +
                        "targets must either be a file name or a directory suffixed with '/'. " +
                        "The root directory of the package can be specified by using a single '/' character.",
                        projectFilePath,
                        DiagnosticMessageSeverity.Error,
                        entry.Line,
                        entry.Column));
                    continue;
                }

                if (entry.Target.Split('/').Any(s => s.Equals(".") || s.Equals("..")))
                {
                    diagnostics.Add(new DiagnosticMessage(
                        $"Invalid '{ProjectFilesCollection.PackIncludePropertyName}' section. " +
                        $"The target '{entry.Target}' contains path-traversal characters ('.' or '..'). " +
                        "These characters are not permitted in target paths.",
                        projectFilePath,
                        DiagnosticMessageSeverity.Error,
                        entry.Line,
                        entry.Column));
                    continue;
                }

                // Check the arity of the left
                if (entry.Target.EndsWith("/"))
                {
                    var dir = entry.Target.Substring(0, entry.Target.Length - 1).Replace('/', Path.DirectorySeparatorChar);

                    foreach (var file in files)
                    {
                        yield return new PhysicalPackageFile()
                        {
                            SourcePath = Path.Combine(rootDirectory.FullName, PathUtility.GetPathWithDirectorySeparator(file.Path)),
                            TargetPath = Path.Combine(dir, PathUtility.GetPathWithDirectorySeparator(file.Stem))
                        };
                    }
                }
                else
                {
                    // It's a file. If the glob matched multiple things, we're sad :(
                    if (files.Count > 1)
                    {
                        // Arity mismatch!
                        string sourceValue = entry.SourceGlobs.Length == 1 ?
                            $"\"{entry.SourceGlobs[0]}\"" :
                            ("[" + string.Join(",", entry.SourceGlobs.Select(v => $"\"{v}\"")) + "]");
                        diagnostics.Add(new DiagnosticMessage(
                            $"Invalid '{ProjectFilesCollection.PackIncludePropertyName}' section. " +
                            $"The target '{entry.Target}' refers to a single file, but the pattern {sourceValue} " +
                            "produces multiple files. To mark the target as a directory, suffix it with '/'.",
                            projectFilePath,
                            DiagnosticMessageSeverity.Error,
                            entry.Line,
                            entry.Column));
                    }
                    else
                    {
                        yield return new PhysicalPackageFile()
                        {
                            SourcePath = Path.Combine(rootDirectory.FullName, files[0].Path),
                            TargetPath = PathUtility.GetPathWithDirectorySeparator(entry.Target)
                        };
                    }
                }
            }
        }