Skip to content

Commit cf09a3b

Browse files
committed
Fixes #71. Properly concatenate the Podfile and Podfile.lock paths and add unit tests.
Signed-off-by: Kyle Hammond <[email protected]>
1 parent 4d463c3 commit cf09a3b

File tree

6 files changed

+87
-2
lines changed

6 files changed

+87
-2
lines changed

lib/cyclonedx/cocoapods/podfile_analyzer.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ def load_one_plugin(plugin_name)
105105
def validate_options(project_dir, options)
106106
raise PodfileParsingError, "#{options[:path]} is not a valid directory." unless File.directory?(project_dir)
107107

108-
options[:podfile_path] = "#{project_dir}Podfile"
108+
options[:podfile_path] = project_dir + 'Podfile'
109109
unless File.exist?(options[:podfile_path])
110110
raise PodfileParsingError, "Missing Podfile in #{project_dir}. Please use the --path option if " \
111111
'not running from the CocoaPods project directory.'
112112
end
113113

114-
options[:podfile_lock_path] = "#{project_dir}Podfile.lock"
114+
options[:podfile_lock_path] = project_dir + 'Podfile.lock'
115115
return if File.exist?(options[:podfile_lock_path])
116116

117117
raise PodfileParsingError, "Missing Podfile.lock, please run 'pod install' before generating BOM"
@@ -142,6 +142,8 @@ def dependencies_for_pod(podname_array, podfile, lockfile)
142142
end
143143

144144
def initialize_cocoapods_config(project_dir)
145+
# First, reset the ::Pod::Config instance in case we need to use this analyzer on multiple pods
146+
::Pod::Config.instance = nil
145147
::Pod::Config.instance.installation_root = project_dir
146148
end
147149

spec/cyclonedx/cocoapods/podfile_analyzer_spec.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,55 @@
3535
@logger = Logger.new(@log)
3636
end
3737

38+
context 'Calling ensure_podfile_and_lock_are_present' do
39+
it 'with bad path should raise an error' do
40+
analyzer = CycloneDX::CocoaPods::PodfileAnalyzer.new(logger: @logger)
41+
42+
options = {
43+
path: 'bad_path_that_does_not_exist'
44+
}
45+
expect do
46+
analyzer.ensure_podfile_and_lock_are_present(options)
47+
end.to raise_error(CycloneDX::CocoaPods::PodfileParsingError,
48+
'bad_path_that_does_not_exist is not a valid directory.')
49+
end
50+
51+
it 'with SimplePod fixture should succeed' do
52+
analyzer = CycloneDX::CocoaPods::PodfileAnalyzer.new(logger: @logger)
53+
54+
options = {
55+
path: fixtures + 'SimplePod/'
56+
}
57+
podfile, lockfile = analyzer.ensure_podfile_and_lock_are_present(options)
58+
expect(podfile).not_to be_nil
59+
expect(lockfile).not_to be_nil
60+
end
61+
62+
it 'with EmptyPodfile fixture should raise a "Missing Manifest.lock" error' do
63+
analyzer = CycloneDX::CocoaPods::PodfileAnalyzer.new(logger: @logger)
64+
65+
options = {
66+
path: fixtures + 'EmptyPodfile/'
67+
}
68+
expect do
69+
analyzer.ensure_podfile_and_lock_are_present(options)
70+
end.to raise_error(CycloneDX::CocoaPods::PodfileParsingError,
71+
"Missing Manifest.lock, please run 'pod install' before generating BOM")
72+
end
73+
74+
it 'with PluginPod fixture should log a warning when trying to load the plugin' do
75+
analyzer = CycloneDX::CocoaPods::PodfileAnalyzer.new(logger: @logger)
76+
77+
options = {
78+
path: fixtures + 'PluginPod/'
79+
}
80+
expect(@logger).to receive(:warn).with(/Failed to load plugin fake_plugin_that_does_not_exist./)
81+
podfile, lockfile = analyzer.ensure_podfile_and_lock_are_present(options)
82+
expect(podfile).not_to be_nil
83+
expect(lockfile).not_to be_nil
84+
end
85+
end
86+
3887
context 'parsing pods' do
3988
context 'when created with standard parameters' do
4089
it 'should handle no pods correctly' do

spec/fixtures/PluginPod/Podfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
platform :osx, '11.0'
2+
3+
plugin 'fake_plugin_that_does_not_exist'
4+
5+
target 'SampleProject' do
6+
end

spec/fixtures/PluginPod/Podfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
PODFILE CHECKSUM: ac84235e3de4f55461564bd177c404d01b1c09ee
2+
3+
COCOAPODS: 1.15.2

spec/fixtures/PluginPod/Pods/Manifest.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/fixtures/SimplePod/Pods/Manifest.lock

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)