Example #1
0
        protected override int Execute()
        {
            var currentModuleDirectory = Helper.GetModuleDirectory(Directory.GetCurrentDirectory());
            var currentModule = Path.GetFileName(currentModuleDirectory);

            if (!File.Exists(project))
            {
                var all = Yaml.GetCsprojsList(currentModule);
                var maybe = all.FirstOrDefault(f =>
                    string.Equals(Path.GetFileName(f), project, StringComparison.CurrentCultureIgnoreCase));
                if (maybe != null)
                    project = maybe;
            }

            if (!File.Exists(project))
            {
                ConsoleWriter.WriteError($"Project file '{project}' does not exist.");
                return -1;
            }

            var moduleToInsert = Helper.TryFixModuleCase(dep.Name);
            dep = new Dep(moduleToInsert, dep.Treeish, dep.Configuration);
            var configuration = dep.Configuration;

            if (!Helper.HasModule(moduleToInsert))
            {
                ConsoleWriter.WriteError($"Can't find module '{moduleToInsert}'");
                return -1;
            }

            if (!Directory.Exists(Path.Combine(Helper.CurrentWorkspace, moduleToInsert)))
                GetAndBuild(dep);

            Log.Debug(
                $"{moduleToInsert + (configuration == null ? "" : Helper.ConfigurationDelimiter + configuration)} -> {project}");

            CheckBranch();

            Log.Info("Getting install data for " + moduleToInsert + Helper.ConfigurationDelimiter + configuration);
            var installData = InstallParser.Get(moduleToInsert, configuration);
            if (!installData.BuildFiles.Any())
            {
                ConsoleWriter.WriteWarning($"No install files found in '{moduleToInsert}'");
                return 0;
            }

            AddModuleToCsproj(installData);
            if (testReplaces)
                return hasReplaces ? -1 : 0;

            if (!File.Exists(Path.Combine(currentModuleDirectory, Helper.YamlSpecFile)))
                throw new CementException(
                    "No module.yaml file. You should patch deps file manually or convert old spec to module.yaml (cm convert-spec)");
            DepsPatcherProject.PatchDepsForProject(currentModuleDirectory, dep, project);
            return 0;
        }
Example #2
0
        protected override int Execute()
        {
            var currentModuleDirectory = Helper.GetModuleDirectory(Directory.GetCurrentDirectory());
            var currentModule          = Path.GetFileName(currentModuleDirectory);

            PackageUpdater.UpdatePackages();
            project = Yaml.GetProjectFileName(project, currentModule);

            var moduleToInsert = Helper.TryFixModuleCase(dep.Name);

            dep = new Dep(moduleToInsert, dep.Treeish, dep.Configuration);
            var configuration = dep.Configuration;

            if (!Helper.HasModule(moduleToInsert))
            {
                ConsoleWriter.WriteError($"Can't find module '{moduleToInsert}'");
                return(-1);
            }

            if (!Directory.Exists(Path.Combine(Helper.CurrentWorkspace, moduleToInsert)))
            {
                GetAndBuild(dep);
            }

            Log.Debug(
                $"{moduleToInsert + (configuration == null ? "" : Helper.ConfigurationDelimiter + configuration)} -> {project}");

            CheckBranch();

            Log.Info("Getting install data for " + moduleToInsert + Helper.ConfigurationDelimiter + configuration);
            var installData = InstallParser.Get(moduleToInsert, configuration);

            if (!installData.BuildFiles.Any())
            {
                ConsoleWriter.WriteWarning($"No install files found in '{moduleToInsert}'");
                return(0);
            }

            AddModuleToCsproj(installData);
            if (testReplaces)
            {
                return(hasReplaces ? -1 : 0);
            }

            if (!File.Exists(Path.Combine(currentModuleDirectory, Helper.YamlSpecFile)))
            {
                throw new CementException(
                          "No module.yaml file. You should patch deps file manually or convert old spec to module.yaml (cm convert-spec)");
            }
            DepsPatcherProject.PatchDepsForProject(currentModuleDirectory, dep, project);
            return(0);
        }
Example #3
0
        protected override int Execute()
        {
            var moduleDirectory = Helper.GetModuleDirectory(Directory.GetCurrentDirectory());

            if (moduleSolutionName == null)
            {
                var possibleModuleSolutions = Yaml.GetSolutionList(moduleDirectory);
                if (possibleModuleSolutions.Count != 1)
                {
                    throw new BadArgumentException("Unable to resolve sln-file, please specify path to one");
                }
                moduleSolutionName = possibleModuleSolutions[0];
            }
            var moduleSolutionPath = Path.GetFullPath(moduleSolutionName);

            if (!moduleSolutionPath.EndsWith(".sln"))
            {
                throw new BadArgumentException(moduleSolutionPath + " is not sln-file");
            }
            if (!File.Exists(moduleSolutionPath))
            {
                throw new BadArgumentException(moduleSolutionPath + " is not exist");
            }

            var analyzerModuleName = Helper.TryFixModuleCase(analyzerModule.Name);

            analyzerModule = new Dep(analyzerModuleName, analyzerModule.Treeish, analyzerModule.Configuration);
            var configuration = analyzerModule.Configuration;

            if (!Directory.Exists(Path.Combine(Helper.CurrentWorkspace, analyzerModuleName)) || !Helper.HasModule(analyzerModuleName))
            {
                throw new CementException($"Can't find module '{analyzerModuleName}'");
            }

            Log.Debug($"{analyzerModuleName + (configuration == null ? "" : Helper.ConfigurationDelimiter + configuration)} -> {moduleSolutionName}");

            CheckBranch();

            Log.Info("Getting install data for " + analyzerModuleName + Helper.ConfigurationDelimiter + configuration);
            var installData = InstallParser.Get(analyzerModuleName, configuration);

            if (!installData.BuildFiles.Any())
            {
                ConsoleWriter.WriteWarning($"No install files found in '{analyzerModuleName}'");
                return(0);
            }

            var csprojFiles           = GetCsprojFiles(moduleSolutionPath);
            var csprojAndRulesetPairs = csprojFiles
                                        .Select(projectFile => new
            {
                Csproj  = projectFile,
                Ruleset = new RulesetFile(Path.ChangeExtension(projectFile.FilePath, "ruleset"))
            })
                                        .ToList();

            foreach (var pair in csprojAndRulesetPairs)
            {
                foreach (var installItem in installData.BuildFiles)
                {
                    if (installItem.EndsWith(".ruleset"))
                    {
                        var analyzerModuleRulesetPath = Path.GetFullPath(Path.Combine(Helper.CurrentWorkspace, installItem));
                        pair.Ruleset.Include(analyzerModuleRulesetPath);
                    }
                }

                pair.Csproj.BindRuleset(pair.Ruleset);

                foreach (var installItem in installData.BuildFiles)
                {
                    if (installItem.EndsWith(".dll"))
                    {
                        var analyzerModuleDllPath = Path.GetFullPath(Path.Combine(Helper.CurrentWorkspace, installItem));
                        pair.Csproj.AddAnalyzer(analyzerModuleDllPath);
                    }
                }
            }

            if (!File.Exists(Path.Combine(moduleDirectory, Helper.YamlSpecFile)))
            {
                throw new CementException("No module.yaml file. You should patch deps file manually or convert old spec to module.yaml (cm convert-spec)");
            }
            DepsPatcherProject.PatchDepsForSolution(moduleDirectory, analyzerModule, moduleSolutionPath);

            foreach (var pair in csprojAndRulesetPairs)
            {
                pair.Csproj.Save();
                pair.Ruleset.Save();
            }

            ConsoleWriter.WriteOk($"Add {analyzerModuleName} to {Path.GetFileName(moduleSolutionPath)} successfully completed");
            return(0);
        }