Skip to content

Commit

Permalink
Using Parsers.Common to find the projects
Browse files Browse the repository at this point in the history
Added option to specify a specific solution (in case unit tests contain solutions).
Removed ProjectFile and subsequently the unit test project as we make use of the info from Parsers.
  • Loading branch information
MichielOda committed Feb 8, 2024
1 parent 339793d commit 2c08dd0
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 305 deletions.
5 changes: 1 addition & 4 deletions CICD.Tools.SDKChecker/CICD.Tools.SDKChecker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Locator" Version="1.5.5" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.5.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.5.0" />
<PackageReference Include="Skyline.DataMiner.CICD.FileSystem" Version="1.0.2" />
<PackageReference Include="Skyline.DataMiner.CICD.Parsers.Common" Version="1.0.8-b" />
<PackageReference Include="Skyline.DataMiner.CICD.Tools.Reporter" Version="1.0.1" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>
Expand Down
73 changes: 26 additions & 47 deletions CICD.Tools.SDKChecker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
using System.Linq;
using System.Threading.Tasks;

using Microsoft.Build.Locator;
using Microsoft.CodeAnalysis.MSBuild;

using Skyline.DataMiner.CICD.FileSystem;
using Skyline.DataMiner.CICD.Parsers.Common.VisualStudio;
using Skyline.DataMiner.CICD.Parsers.Common.VisualStudio.Projects;
using Skyline.DataMiner.CICD.Tools.Reporter;

/// <summary>
Expand Down Expand Up @@ -47,73 +46,53 @@ public static async Task<int> Main(string[] args)
IsRequired = false
};

var solutionFilePath = new Option<string>(
name: "--solution-filepath",
description: "The filepath to the solution.");

var rootCommand = new RootCommand("Returns any project not using SDK Style.")
{
workspaceOption,
repoSourceOption,
repoBranchOption,
solutionFilePath
};

rootCommand.SetHandler(Process, workspaceOption, repoSourceOption, repoBranchOption);
rootCommand.SetHandler(Process, workspaceOption, repoSourceOption, repoBranchOption, solutionFilePath);

await rootCommand.InvokeAsync(args);

return 0;
}

/// <summary>
/// Retrieves all projects not using SDK style.
/// </summary>
/// <param name="pathToSolution">Directory containing the .sln</param>
/// <returns>A collection of project names.</returns>
private static ISet<string> RetrieveLegacyStyleProjects(string pathToSolution)

private static async Task Process(string workspace, string repoName, string branch, string solutionFilepath)
{
if (!MSBuildLocator.IsRegistered)
{
MSBuildLocator.RegisterDefaults();
}
DevOpsMetrics metrics = new DevOpsMetrics();

HashSet<string> projectsWithLegacyStyle = new HashSet<string>();
foreach (var projectFile in GetProjects(pathToSolution))
if (String.IsNullOrWhiteSpace(solutionFilepath))
{
var projectFileProcessor = new ProjectFile(projectFile);
if (!projectFileProcessor.UsesSDKStyle())
{
projectsWithLegacyStyle.Add(Path.GetFileNameWithoutExtension(projectFile));
}
solutionFilepath = FileSystem.Instance.Directory.EnumerateFiles(workspace, "*.sln", SearchOption.AllDirectories).FirstOrDefault();
}

return projectsWithLegacyStyle;
}

private static IList<string> GetProjects(string solutionFilePath)
{
List<string> projects = new();

var workspace = MSBuildWorkspace.Create();

var solution = Task.Run(() => workspace.OpenSolutionAsync(solutionFilePath)).GetAwaiter().GetResult();

foreach (var project in solution.Projects)

if (String.IsNullOrWhiteSpace(solutionFilepath))
{
projects.Add(project.FilePath);
throw new InvalidOperationException("Could not locate a solution file (.sln) in workspace: " + workspace);
}

return projects;
}
Solution solution = Solution.Load(solutionFilepath);

private static async Task Process(string workspace, string repoName, string branch)
{
DevOpsMetrics metrics = new DevOpsMetrics();
var pathToSolution = FileSystem.Instance.Directory.EnumerateFiles(workspace, "*.sln", SearchOption.AllDirectories).FirstOrDefault();
if (String.IsNullOrWhiteSpace(pathToSolution))
List<string> legacyStyleProjects = new List<string>();
foreach (var projectInSolution in solution.Projects)
{
throw new InvalidOperationException("Could not located a solution file (.sln) in workspace: " + workspace);
}
var project = solution.LoadProject(projectInSolution);

var projectsWithPackageConfig = RetrieveLegacyStyleProjects(pathToSolution);
if (project is not { ProjectType: ProjectType.Sdk })
{
legacyStyleProjects.Add(projectInSolution.Name);
}
}

string output = String.Join("#", projectsWithPackageConfig);
string output = String.Join("#", legacyStyleProjects);

if (!String.IsNullOrWhiteSpace(output))
{
Expand Down
45 changes: 0 additions & 45 deletions CICD.Tools.SDKChecker/ProjectFile.cs

This file was deleted.

6 changes: 0 additions & 6 deletions Skyline.DataMiner.CICD.Tools.SDKChecker.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Skyline.DataMiner.CICD.Tools.SDKCheckerTests", "Skyline.DataMiner.CICD.Tools.SDKCheckerTests\Skyline.DataMiner.CICD.Tools.SDKCheckerTests.csproj", "{1A2091C7-5AF0-466D-8A4D-5C8BC4DC2D05}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -23,10 +21,6 @@ Global
{9AD7C19C-DF17-46A3-95D9-29949EE69D60}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9AD7C19C-DF17-46A3-95D9-29949EE69D60}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9AD7C19C-DF17-46A3-95D9-29949EE69D60}.Release|Any CPU.Build.0 = Release|Any CPU
{1A2091C7-5AF0-466D-8A4D-5C8BC4DC2D05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A2091C7-5AF0-466D-8A4D-5C8BC4DC2D05}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A2091C7-5AF0-466D-8A4D-5C8BC4DC2D05}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A2091C7-5AF0-466D-8A4D-5C8BC4DC2D05}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
40 changes: 0 additions & 40 deletions Skyline.DataMiner.CICD.Tools.SDKCheckerTests/ProjectFileTests.cs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 2c08dd0

Please sign in to comment.