diff --git a/src/CTA.FeatureDetection.Common/packages.lock.json b/src/CTA.FeatureDetection.Common/packages.lock.json index d05c9bf9..975f246b 100644 --- a/src/CTA.FeatureDetection.Common/packages.lock.json +++ b/src/CTA.FeatureDetection.Common/packages.lock.json @@ -54,12 +54,12 @@ }, "Codelyzer.Analysis": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "iynKNXyC15wF0u9ZUTr4cKAmdYa1470AaGtvACuULL2BRK3VMHpzE01a/UvKbulKSXq0cZYaEMX+GrOlMVJuDQ==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "5t+uGKQVjm85toghCUBsM69wUfTVBxhYT+eCuZLceMiK4TbJ7MJwfCEfai3Qj41mnJ8g4yPIsMyGkCAARF/F0g==", "dependencies": { - "Codelyzer.Analysis.Build": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.CSharp": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.VisualBasic": "2.4.71-alpha-g6b1f22778c", + "Codelyzer.Analysis.Build": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.CSharp": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.VisualBasic": "2.4.72-alpha-g154f8975ce", "CommandLineParser": "2.8.0", "Microsoft.Build.Utilities.Core": "17.1.0", "Microsoft.Extensions.Logging.Console": "6.0.0", @@ -69,23 +69,23 @@ }, "Codelyzer.Analysis.Build": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "+senXLbp84O5oiiT1hp/B+AzCDSo7/+C+1KkDQlNrMBANBseSpcoXVacYigGTGHbSK79V16ahIlvAjpE9e9RBA==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "Ymx4lk0aILNUnjK/Ln7DvY84fV8rkeHbRjvXqmkMZvYgB35WtRSMw2qKMbmXUxeNP+evogviHgt6Cmcafn2n6Q==", "dependencies": { "Buildalyzer": "4.1.4", "Buildalyzer.Logger": "4.1.4", "Buildalyzer.Workspaces": "4.1.4", - "Codelyzer.Analysis.Common": "2.4.71-alpha-g6b1f22778c", + "Codelyzer.Analysis.Common": "2.4.72-alpha-g154f8975ce", "Microsoft.Extensions.Logging": "6.0.0", "NuGet.Packaging": "6.0.0" } }, "Codelyzer.Analysis.Common": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "4nEVXfTc/FFzxkEulKOSd2s/2uh4bcTVbCncPCp4BZpf5qKLLXeLwf4VBzS/PFo6T5Y2D3A1F9kRlub74dLSXQ==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "PNRf7eXbink/4MpEzUorwPZqiw0oh/Ac3hML5Q3+peCsWq8SWxy0Xj8eHfoxlQjaJ9tqkhWz1wzTx15wfmMUPw==", "dependencies": { - "Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c", + "Codelyzer.Analysis.Model": "2.4.72-alpha-g154f8975ce", "Microsoft.Build": "17.0.0", "Microsoft.VisualStudio.Setup.Configuration.Interop": "3.1.2196", "Newtonsoft.Json": "13.0.1" @@ -93,17 +93,17 @@ }, "Codelyzer.Analysis.CSharp": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "Q5Fs/FoDo6tz14aWEMCENHEjgTKJojE2/Wd1jSbFmjV8a8q27q6sk2gqMT5FcTO86THzt+GFeKq8b7FF8w2MoQ==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "EknM1pQWlGb0dCZaPTdl4dJ35OV9Np2CgZ98iXPWKSSGjk+0TdJSPikQ6skbJ2iiqogyOpuycfJ5CXv64gx0VA==", "dependencies": { - "Codelyzer.Analysis.Common": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c" + "Codelyzer.Analysis.Common": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.Model": "2.4.72-alpha-g154f8975ce" } }, "Codelyzer.Analysis.Model": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "Ma1ACdIXjWStzw7ImhowEsI4E9p2fNhiANgP8FU0uegQSZOaA4x/IaUU0Aij5s5mCTbNVPX6Z5j89g2+L9YftA==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "rBpfp+QH75M5c4cOY/nMc1Kd7trfiDQfl86CZbS0nbe2fteK9F+V0t2wpEBKlitm/STD+NyBcED4jm013u8H8Q==", "dependencies": { "Microsoft.CodeAnalysis": "4.1.0", "Microsoft.CodeAnalysis.CSharp": "4.1.0", @@ -114,11 +114,11 @@ }, "Codelyzer.Analysis.VisualBasic": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "Hxpzw8CXD+oKN47DnYqgoajIucyAIrEW8YOdwcJgT+RGyJ9biLentcSws/9yzVgoIQWV042ppIKp7PlgwRGrJA==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "taucX8Bw2QpqMDJRhoRx0AhXq8n6WTNwtvz/FbxAgQszwV4FrcAnEl6yrngB0kYumaABHSsjy/vFjmd6vCwsGw==", "dependencies": { - "Codelyzer.Analysis.Common": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c" + "Codelyzer.Analysis.Common": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.Model": "2.4.72-alpha-g154f8975ce" } }, "CommandLineParser": { @@ -1711,8 +1711,8 @@ "cta.rules.config": { "type": "Project", "dependencies": { - "Codelyzer.Analysis": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c", + "Codelyzer.Analysis": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.Model": "2.4.72-alpha-g154f8975ce", "Microsoft.Extensions.Logging": "6.0.0", "Microsoft.Extensions.Logging.Abstractions": "6.0.0", "Microsoft.Extensions.Logging.Console": "6.0.0", diff --git a/src/CTA.Rules.Config/CTA.Rules.Config.csproj b/src/CTA.Rules.Config/CTA.Rules.Config.csproj index a1e0bb35..55e26924 100644 --- a/src/CTA.Rules.Config/CTA.Rules.Config.csproj +++ b/src/CTA.Rules.Config/CTA.Rules.Config.csproj @@ -5,8 +5,8 @@ - - + + diff --git a/src/CTA.Rules.Models/packages.lock.json b/src/CTA.Rules.Models/packages.lock.json index ac41963b..181f99dd 100644 --- a/src/CTA.Rules.Models/packages.lock.json +++ b/src/CTA.Rules.Models/packages.lock.json @@ -60,12 +60,12 @@ }, "Codelyzer.Analysis": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "iynKNXyC15wF0u9ZUTr4cKAmdYa1470AaGtvACuULL2BRK3VMHpzE01a/UvKbulKSXq0cZYaEMX+GrOlMVJuDQ==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "5t+uGKQVjm85toghCUBsM69wUfTVBxhYT+eCuZLceMiK4TbJ7MJwfCEfai3Qj41mnJ8g4yPIsMyGkCAARF/F0g==", "dependencies": { - "Codelyzer.Analysis.Build": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.CSharp": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.VisualBasic": "2.4.71-alpha-g6b1f22778c", + "Codelyzer.Analysis.Build": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.CSharp": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.VisualBasic": "2.4.72-alpha-g154f8975ce", "CommandLineParser": "2.8.0", "Microsoft.Build.Utilities.Core": "17.1.0", "Microsoft.Extensions.Logging.Console": "6.0.0", @@ -75,23 +75,23 @@ }, "Codelyzer.Analysis.Build": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "+senXLbp84O5oiiT1hp/B+AzCDSo7/+C+1KkDQlNrMBANBseSpcoXVacYigGTGHbSK79V16ahIlvAjpE9e9RBA==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "Ymx4lk0aILNUnjK/Ln7DvY84fV8rkeHbRjvXqmkMZvYgB35WtRSMw2qKMbmXUxeNP+evogviHgt6Cmcafn2n6Q==", "dependencies": { "Buildalyzer": "4.1.4", "Buildalyzer.Logger": "4.1.4", "Buildalyzer.Workspaces": "4.1.4", - "Codelyzer.Analysis.Common": "2.4.71-alpha-g6b1f22778c", + "Codelyzer.Analysis.Common": "2.4.72-alpha-g154f8975ce", "Microsoft.Extensions.Logging": "6.0.0", "NuGet.Packaging": "6.0.0" } }, "Codelyzer.Analysis.Common": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "4nEVXfTc/FFzxkEulKOSd2s/2uh4bcTVbCncPCp4BZpf5qKLLXeLwf4VBzS/PFo6T5Y2D3A1F9kRlub74dLSXQ==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "PNRf7eXbink/4MpEzUorwPZqiw0oh/Ac3hML5Q3+peCsWq8SWxy0Xj8eHfoxlQjaJ9tqkhWz1wzTx15wfmMUPw==", "dependencies": { - "Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c", + "Codelyzer.Analysis.Model": "2.4.72-alpha-g154f8975ce", "Microsoft.Build": "17.0.0", "Microsoft.VisualStudio.Setup.Configuration.Interop": "3.1.2196", "Newtonsoft.Json": "13.0.1" @@ -99,17 +99,17 @@ }, "Codelyzer.Analysis.CSharp": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "Q5Fs/FoDo6tz14aWEMCENHEjgTKJojE2/Wd1jSbFmjV8a8q27q6sk2gqMT5FcTO86THzt+GFeKq8b7FF8w2MoQ==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "EknM1pQWlGb0dCZaPTdl4dJ35OV9Np2CgZ98iXPWKSSGjk+0TdJSPikQ6skbJ2iiqogyOpuycfJ5CXv64gx0VA==", "dependencies": { - "Codelyzer.Analysis.Common": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c" + "Codelyzer.Analysis.Common": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.Model": "2.4.72-alpha-g154f8975ce" } }, "Codelyzer.Analysis.Model": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "Ma1ACdIXjWStzw7ImhowEsI4E9p2fNhiANgP8FU0uegQSZOaA4x/IaUU0Aij5s5mCTbNVPX6Z5j89g2+L9YftA==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "rBpfp+QH75M5c4cOY/nMc1Kd7trfiDQfl86CZbS0nbe2fteK9F+V0t2wpEBKlitm/STD+NyBcED4jm013u8H8Q==", "dependencies": { "Microsoft.CodeAnalysis": "4.1.0", "Microsoft.CodeAnalysis.CSharp": "4.1.0", @@ -120,11 +120,11 @@ }, "Codelyzer.Analysis.VisualBasic": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "Hxpzw8CXD+oKN47DnYqgoajIucyAIrEW8YOdwcJgT+RGyJ9biLentcSws/9yzVgoIQWV042ppIKp7PlgwRGrJA==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "taucX8Bw2QpqMDJRhoRx0AhXq8n6WTNwtvz/FbxAgQszwV4FrcAnEl6yrngB0kYumaABHSsjy/vFjmd6vCwsGw==", "dependencies": { - "Codelyzer.Analysis.Common": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c" + "Codelyzer.Analysis.Common": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.Model": "2.4.72-alpha-g154f8975ce" } }, "CommandLineParser": { @@ -1717,8 +1717,8 @@ "cta.rules.config": { "type": "Project", "dependencies": { - "Codelyzer.Analysis": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c", + "Codelyzer.Analysis": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.Model": "2.4.72-alpha-g154f8975ce", "Microsoft.Extensions.Logging": "6.0.0", "Microsoft.Extensions.Logging.Abstractions": "6.0.0", "Microsoft.Extensions.Logging.Console": "6.0.0", diff --git a/src/CTA.Rules.PortCore/PortCoreUtils.cs b/src/CTA.Rules.PortCore/PortCoreUtils.cs new file mode 100644 index 00000000..b20c972e --- /dev/null +++ b/src/CTA.Rules.PortCore/PortCoreUtils.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using System.Linq; +using Codelyzer.Analysis; +using Codelyzer.Analysis.Model; +using CTA.Rules.Models; + +namespace CTA.Rules.PortCore; + +public class PortCoreUtils +{ + public static HashSet GetReferencesForProject(AnalyzerResult analyzerResult) + { + var allReferences = new HashSet(); + var projectResult = analyzerResult.ProjectResult; + + projectResult?.SourceFileResults?.SelectMany(s => s.References)?.Select(r => r.Namespace).Distinct().ToList().ForEach(currentReference=> { + if (currentReference != null && !allReferences.Contains(currentReference)) + { + allReferences.Add(currentReference); + } + }); + + projectResult?.SourceFileResults?.SelectMany(s => s.Children.OfType())?.Select(u=>u.Identifier).Distinct().ToList().ForEach(currentReference => { + if (currentReference != null && !allReferences.Contains(currentReference)) + { + allReferences.Add(currentReference); + } + }); + + projectResult?.SourceFileResults?.SelectMany(s => s.Children.OfType())?.Select(u => u.Identifier).Distinct().ToList().ForEach(currentReference => + { + if (currentReference != null && !allReferences.Contains(currentReference)) + { + allReferences.Add(currentReference); + } + }); + + return allReferences; + } +} diff --git a/src/CTA.Rules.PortCore/ProjectPort.cs b/src/CTA.Rules.PortCore/ProjectPort.cs index b9513b01..a10cf4f8 100644 --- a/src/CTA.Rules.PortCore/ProjectPort.cs +++ b/src/CTA.Rules.PortCore/ProjectPort.cs @@ -56,23 +56,8 @@ private void InitRules(PortCoreConfiguration projectConfiguration, AnalyzerResul _solutionPort.CopyOverrideRules(projectConfiguration.RulesDir); } projectConfiguration.RulesDir = Constants.RulesDefaultPath; - var projectResult = analyzerResult.ProjectResult; - - projectResult?.SourceFileResults?.SelectMany(s => s.References)?.Select(r => r.Namespace).Distinct().ToList().ForEach(currentReference => - { - if (currentReference != null && !ProjectReferences.Contains(currentReference)) - { - ProjectReferences.Add(currentReference); - } - }); - - projectResult?.SourceFileResults?.SelectMany(s => s.Children.OfType())?.Select(u => u.Identifier).Distinct().ToList().ForEach(currentReference => - { - if (currentReference != null && !ProjectReferences.Contains(currentReference)) - { - ProjectReferences.Add(currentReference); - } - }); + + ProjectReferences.UnionWith(PortCoreUtils.GetReferencesForProject(analyzerResult)); ProjectReferences.Add(Constants.ProjectRecommendationFile); } diff --git a/src/CTA.Rules.PortCore/SolutionPort.cs b/src/CTA.Rules.PortCore/SolutionPort.cs index 436dfd14..d860e771 100644 --- a/src/CTA.Rules.PortCore/SolutionPort.cs +++ b/src/CTA.Rules.PortCore/SolutionPort.cs @@ -218,23 +218,10 @@ private void InitRules(List solutionConfiguration, List a.ProjectResult?.ProjectFilePath == projectConfiguration.ProjectPath) - .ProjectResult; - - projectResult?.SourceFileResults?.SelectMany(s => s.References)?.Select(r => r.Namespace).Distinct().ToList().ForEach(currentReference=> { - if (currentReference != null && !allReferences.Contains(currentReference)) - { - allReferences.Add(currentReference); - } - }); - - projectResult?.SourceFileResults?.SelectMany(s => s.Children.OfType())?.Select(u=>u.Identifier).Distinct().ToList().ForEach(currentReference => { - if (currentReference != null && !allReferences.Contains(currentReference)) - { - allReferences.Add(currentReference); - } - }); + allReferences.UnionWith(PortCoreUtils.GetReferencesForProject( + analyzerResults.FirstOrDefault(a => + a.ProjectResult?.ProjectFilePath == + projectConfiguration.ProjectPath))); } AddWCFReferences(projectConfiguration); diff --git a/src/CTA.Rules.Update/ProjectRewriters/ProjectRewriter.cs b/src/CTA.Rules.Update/ProjectRewriters/ProjectRewriter.cs index 5e074137..631ba7c4 100644 --- a/src/CTA.Rules.Update/ProjectRewriters/ProjectRewriter.cs +++ b/src/CTA.Rules.Update/ProjectRewriters/ProjectRewriter.cs @@ -78,6 +78,7 @@ public ProjectRewriter(IDEProjectResult projectResult, ProjectConfiguration proj Version = p.Value.Item2 }).ToList() }; + _projectLanguage = VisualBasicUtils.IsVisualBasicProject(ProjectConfiguration.ProjectPath) ? ProjectLanguage.VisualBasic : ProjectLanguage.Csharp; } /// diff --git a/tst/CTA.Rules.Test/UtilsTest.cs b/tst/CTA.Rules.Test/UtilsTest.cs index 7f0a5750..ce817b89 100644 --- a/tst/CTA.Rules.Test/UtilsTest.cs +++ b/tst/CTA.Rules.Test/UtilsTest.cs @@ -5,7 +5,10 @@ using System.IO; using System.Linq; using System.Threading.Tasks; +using Codelyzer.Analysis; +using Codelyzer.Analysis.Model; using CTA.Rules.Common.Helpers; +using CTA.Rules.PortCore; namespace CTA.Rules.Test { @@ -121,5 +124,34 @@ public void Test_Is_VisualBasic_Project() Assert.IsTrue(VisualBasicUtils.IsVisualBasicProject("C://user/john/repos/test.vbproj")); Assert.IsFalse(VisualBasicUtils.IsVisualBasicProject("vbprojproject.cs")); } + + [Test] + public void TestLoadReferencesFromProject() + { + var analyzeResult = new AnalyzerResult + { + ProjectResult = new ProjectWorkspace("dummy.csproj") + { + SourceFileResults = new UstList() + { + new RootUstNode() + { + Children = new UstList + { + new ImportsStatement { Identifier = "Newtonsoft.Json"}, + new UsingDirective {Identifier = "BouncyCastle.NetCore"} + }, + References = new UstList() + { + new Reference() {Namespace = "BouncyCastle.NetCore"} + } + } + } + } + }; + + var references = PortCoreUtils.GetReferencesForProject(analyzeResult); + Assert.IsTrue(references.Count == 2); + } } } \ No newline at end of file diff --git a/tst/CTA.Rules.Test/VisualBasicTests.cs b/tst/CTA.Rules.Test/VisualBasicTests.cs index caeeea5c..1285ac20 100644 --- a/tst/CTA.Rules.Test/VisualBasicTests.cs +++ b/tst/CTA.Rules.Test/VisualBasicTests.cs @@ -85,6 +85,9 @@ public void TestMixedClassLibrary() Assert.IsTrue(projresults.Count() == 2); //check both projects ported Assert.IsTrue(projresults.All(content => content.Contains("net5.0"))); + Assert.IsTrue(slnResults.ProjectResults + .Find(p => p.CsProjectPath.EndsWith(".vbproj")) + .CsProjectContent.Contains("BouncyCastle.NetCore")); } } }