Skip to content

Commit

Permalink
Merge pull request #763 from aws/longachr-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cslong authored Jul 1, 2022
2 parents ca176d6 + 861281d commit abdb1dc
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 82 deletions.
46 changes: 23 additions & 23 deletions src/CTA.FeatureDetection.Common/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -69,41 +69,41 @@
},
"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"
}
},
"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",
Expand All @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/CTA.Rules.Config/CTA.Rules.Config.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Codelyzer.Analysis" Version="2.4.71-alpha-g6b1f22778c" />
<PackageReference Include="Codelyzer.Analysis.Model" Version="2.4.71-alpha-g6b1f22778c" />
<PackageReference Include="Codelyzer.Analysis" Version="2.4.72-alpha-g154f8975ce" />
<PackageReference Include="Codelyzer.Analysis.Model" Version="2.4.72-alpha-g154f8975ce" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
Expand Down
46 changes: 23 additions & 23 deletions src/CTA.Rules.Models/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -75,41 +75,41 @@
},
"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"
}
},
"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",
Expand All @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
40 changes: 40 additions & 0 deletions src/CTA.Rules.PortCore/PortCoreUtils.cs
Original file line number Diff line number Diff line change
@@ -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<string> GetReferencesForProject(AnalyzerResult analyzerResult)
{
var allReferences = new HashSet<string>();
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<UsingDirective>())?.Select(u=>u.Identifier).Distinct().ToList().ForEach(currentReference => {
if (currentReference != null && !allReferences.Contains(currentReference))
{
allReferences.Add(currentReference);
}
});

projectResult?.SourceFileResults?.SelectMany(s => s.Children.OfType<ImportsStatement>())?.Select(u => u.Identifier).Distinct().ToList().ForEach(currentReference =>
{
if (currentReference != null && !allReferences.Contains(currentReference))
{
allReferences.Add(currentReference);
}
});

return allReferences;
}
}
19 changes: 2 additions & 17 deletions src/CTA.Rules.PortCore/ProjectPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsingDirective>())?.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);
}

Expand Down
21 changes: 4 additions & 17 deletions src/CTA.Rules.PortCore/SolutionPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,23 +218,10 @@ private void InitRules(List<PortCoreConfiguration> solutionConfiguration, List<A
CopyOverrideRules(projectConfiguration.RulesDir);
}
projectConfiguration.RulesDir = Constants.RulesDefaultPath;
var projectResult = analyzerResults
.FirstOrDefault(a => 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<UsingDirective>())?.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);

Expand Down
1 change: 1 addition & 0 deletions src/CTA.Rules.Update/ProjectRewriters/ProjectRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public ProjectRewriter(IDEProjectResult projectResult, ProjectConfiguration proj
Version = p.Value.Item2
}).ToList()
};
_projectLanguage = VisualBasicUtils.IsVisualBasicProject(ProjectConfiguration.ProjectPath) ? ProjectLanguage.VisualBasic : ProjectLanguage.Csharp;
}

/// <summary>
Expand Down
32 changes: 32 additions & 0 deletions tst/CTA.Rules.Test/UtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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<RootUstNode>()
{
new RootUstNode()
{
Children = new UstList<UstNode>
{
new ImportsStatement { Identifier = "Newtonsoft.Json"},
new UsingDirective {Identifier = "BouncyCastle.NetCore"}
},
References = new UstList<Reference>()
{
new Reference() {Namespace = "BouncyCastle.NetCore"}
}
}
}
}
};

var references = PortCoreUtils.GetReferencesForProject(analyzeResult);
Assert.IsTrue(references.Count == 2);
}
}
}
3 changes: 3 additions & 0 deletions tst/CTA.Rules.Test/VisualBasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
}

0 comments on commit abdb1dc

Please sign in to comment.