Esempio n. 1
0
        protected override (bool isSuccess, SError error) HandleProject(Config config, string repoPath, string projectPath)
        {
            // TODO: setting to warn of duplicates when treating git files in a case-insensitive manner . . .
            // Because `thing.txt` and `Thing.txt` could theoretically both exist . . .

            HashSet <string> filesTrackedByGit          = GitHelper.GetFilesFromGitForProject(repoPath, projectPath);
            HashSet <string> filesIncludedInProjectFile = ProjectFileHelper.GetFilesFromProjectFile(projectPath, out HashSet <string> duplicates);
            string           projectName = ProjectFileHelper.GetProjectFileName(projectPath);

            // Filter out project files, because project files do not include themselves . . .
            var self = FileHelper.NormalizePath(Path.GetRelativePath(repoPath, projectPath));

            filesTrackedByGit.Remove(self);

            // Remove any other files our config says we can ignore before we compare . . .
            filesTrackedByGit.RemoveWhere(config.IsIgnorable);

            // Project files are case-insensitive . . .
            // But git is case-sensitive . . .
            var filesNotIncludedInProjectFile = filesTrackedByGit.Where(m => !filesIncludedInProjectFile.Contains(m, StringComparer.CurrentCultureIgnoreCase)).ToList();

            if (filesNotIncludedInProjectFile?.Any() == true)
            {
                _errorOccurred = true;

                Log($"{projectName}:");
                foreach (var file in filesNotIncludedInProjectFile)
                {
                    LogError($" ({Ordinal}) \t{file}", includePrefix: false);
                    Ordinal++;
                }
                NL();
            }
            else
            {
                Log($"'{projectName}' is not missing any files.");
                NL();
            }

            if (ShouldCheckForDuplicates)
            {
                if (duplicates?.Any() == true)
                {
                    Log($"{projectName}:");
                    foreach (var duplicate in duplicates)
                    {
                        LogError($" ({Ordinal}) \t DUPLICATE {duplicate}", includePrefix: false);
                        Ordinal++;
                    }
                }
            }

            return(Success);
        }
Esempio n. 2
0
        protected override (bool isSuccess, SError error) HandleProject(Config config, string repoPath, string projectPath)
        {
            ProjectFileHelper.GetProjectFileParentDirName(projectPath, out string absoluteProjectFileParentDirPath);
            var projName = ProjectFileHelper.GetProjectFileName(projectPath);

            var packageRefs  = GetPackageReferencesFromProjectFile(projectPath);
            var packagesConf = GetPackagesFromPackagesDotConfig(projectPath);

            if (ShouldLookForPackagesMissingFromProjectFile)
            {
                var missingPackages = packagesConf.Where(p => !packageRefs.Any(r => r.Name == p.Name));
                if (missingPackages?.Any() == true)
                {
                    Log($"'{projName}' project file missing references:");
                    foreach (var missingPackage in missingPackages)
                    {
                        Log($"\t{missingPackage.Name}.{missingPackage.Version}");
                        NumMissing++;
                    }
                    NL();
                }
            }

            var primaryDependencies = packageRefs.Where(p => packagesConf.Any(c => c.Name == p.Name));

            if (ShouldPrintPotentialHintPathDiscrepancies)
            {
                foreach (var primaryDep in primaryDependencies)
                {
                    var  relevantConf      = packagesConf.First(c => c.Name == primaryDep.Name);
                    var  projectedHintPath = relevantConf.ProjectHintPath(config);
                    var  hintPath          = primaryDep.HintPath?.Path;
                    bool hasHintPath       = hintPath != null;

                    if (hasHintPath && ShouldCheckPackagesOnDisk)
                    {
                        // HintPaths are relative, so we need to make the path absolute . . .
                        string absoluteHintPath = Path.GetFullPath(hintPath, absoluteProjectFileParentDirPath);
                        if (!File.Exists(absoluteHintPath))
                        {
                            AddMissingPackageOccurrence(absoluteHintPath, projName);
                        }
                    }

                    bool isFine = true;
                    if (hasHintPath && !string.Equals(hintPath, projectedHintPath, StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (ShouldIgnoreTargetFrameworks)
                        {
                            var agnosticHintPath      = MakeAgnosticHintPath(hintPath, primaryDep.Name);
                            var agnosticProjectedPath = MakeAgnosticHintPath(projectedHintPath, relevantConf.Name);

                            if (string.Equals(agnosticHintPath, agnosticProjectedPath, StringComparison.InvariantCultureIgnoreCase))
                            {
                                goto isFineHandler;
                            }
                        }
                        isFine = false;
                        NumDiscrepancies++;
                        Log($"{projName}'s '{primaryDep.Name}':");
                        Log("HP:\t" + hintPath);
                        Log("GP:\t" + projectedHintPath);
                        NL();
                    }
                    else if (!hasHintPath)
                    {
                        isFine = false;
                        Log($"{projName}'s '{primaryDep.Name}' has no hint path");
                        NL();
                        NumNoHPs++;
                    }

isFineHandler:
                    if (isFine)
                    {
                        NumFine++;
                    }
                }
            }

            return(Success);
        }