From 8df82c5499612a23ce7b93edb8256ccd185c89bc Mon Sep 17 00:00:00 2001 From: Greg Villicana Date: Tue, 25 Jan 2022 19:05:16 -0800 Subject: [PATCH] Fix Pod detection for missing podspecs --- .../cocoapods/PodComponentDetector.cs | 15 +++++++++++---- .../PodDetectorTest.cs | 5 ++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/cocoapods/PodComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/cocoapods/PodComponentDetector.cs index 81edabc2e..90c02a025 100644 --- a/src/Microsoft.ComponentDetection.Detectors/cocoapods/PodComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/cocoapods/PodComponentDetector.cs @@ -25,7 +25,7 @@ public class PodComponentDetector : FileComponentDetector public override IEnumerable SupportedComponentTypes { get; } = new[] { ComponentType.Pod, ComponentType.Git }; - public override int Version { get; } = 1; + public override int Version { get; } = 2; private class Pod : IYamlConvertible { @@ -300,10 +300,17 @@ private void ProcessPodfileLock( foreach (var dependency in pod.Value) { - var dependencyKey = podSpecs[dependency.Podspec]; - if (dependencyKey != pod.Key) + if (podSpecs.TryGetValue(dependency.Podspec, out string dependencyKey)) { - dependenciesMap[pod.Key].Add(podSpecs[dependency.Podspec]); + if (dependencyKey != pod.Key) + { + var temp = podSpecs[dependency.Podspec]; + dependenciesMap[pod.Key].Add(podSpecs[dependency.Podspec]); + } + } + else + { + Logger.LogWarning($"Missing podspec declaration. podspec={dependency.Podspec}, version={dependency.PodVersion}"); } } } diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/PodDetectorTest.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/PodDetectorTest.cs index 166b82354..f0fdbae50 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/PodDetectorTest.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/PodDetectorTest.cs @@ -53,6 +53,8 @@ public async Task TestPodDetector_DetectorRecognizePodComponents() - AzureData (= 0.5.0) - KeychainAccess (3.2.1) - Willow (5.2.1) + - Auth (1.44.1): + - MissingDep (= 5.0.0) DEPENDENCIES: - AzureMobile (~> 0.5.0) @@ -73,13 +75,14 @@ public async Task TestPodDetector_DetectorRecognizePodComponents() Assert.AreEqual(ProcessingResultCode.Success, scanResult.ResultCode); var detectedComponents = componentRecorder.GetDetectedComponents(); - Assert.AreEqual(5, detectedComponents.Count()); + Assert.AreEqual(6, detectedComponents.Count()); AssertPodComponentNameAndVersion(detectedComponents, "AzureCore", "0.5.0"); AssertPodComponentNameAndVersion(detectedComponents, "AzureData", "0.5.0"); AssertPodComponentNameAndVersion(detectedComponents, "AzureMobile", "0.5.0"); AssertPodComponentNameAndVersion(detectedComponents, "KeychainAccess", "3.2.1"); AssertPodComponentNameAndVersion(detectedComponents, "Willow", "5.2.1"); + AssertPodComponentNameAndVersion(detectedComponents, "Auth", "1.44.1"); } [TestMethod]