xcres 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c693c63079477f934beba5d70aeeeb474ba89d3c
4
- data.tar.gz: 37daa9576e22f68af31f1fcea2d8931287fadce2
3
+ metadata.gz: 66662fa71e28ebba0f9e8709d34eaa747884acd5
4
+ data.tar.gz: 848102aa3b625215e7523bfec8e216e6c9d2b80f
5
5
  SHA512:
6
- metadata.gz: 59d34106718f0effdf97806992013b312b0e064f6577fc8ee8ae99e995d78aba7bd1567b899024e9731d7fcac60dcdf8ba25e5a54d38d341046e610fd5942915
7
- data.tar.gz: 207373fdbeea3645e865910b744aeda5539b69ab4553773e3da4443e7440fa7d21158cb69afd10b27ecd623adbd8f494cbe772104bce718ef71677c754b619c0
6
+ metadata.gz: 22ab34d31c641dfae88fe78ef6e5c19e9a60e6b1244f269f511343b7a6f72461640c7cf8d6b845b414dba357a27a981c85de16a42879dfa69bcd7804fc790467
7
+ data.tar.gz: 477d6500c3aa810f1d97f04203e00965cbe0ab11b2c9f2977a5ccaecc090d9c2250a721da0e009298bf32fb3a3bc5adce0ea82eefde001abfd5f2df8cbe5c475
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xcres (0.4.3)
4
+ xcres (0.4.4)
5
5
  activesupport (>= 3.2.15, < 4)
6
6
  clamp (~> 0.6.3)
7
7
  colored (~> 1.2)
@@ -153,8 +153,12 @@ module XCRes
153
153
  #
154
154
  def native_dev_languages
155
155
  @native_dev_languages ||= absolute_info_plist_paths.map do |path|
156
- read_plist_key(path, :CFBundleDevelopmentRegion)
157
- end.to_set
156
+ begin
157
+ read_plist_key(path, :CFBundleDevelopmentRegion)
158
+ rescue ArgumentError => e
159
+ warn e
160
+ end
161
+ end.compact.to_set
158
162
  end
159
163
 
160
164
  # Extracts a given key from a plist file given as a path
@@ -168,10 +172,11 @@ module XCRes
168
172
  # @return [String]
169
173
  #
170
174
  def read_plist_key(path, key)
175
+ raise ArgumentError, "File '#{path}' doesn't exist" unless path.exist?
171
176
  raise ArgumentError, 'Path is required, but nil' if path.nil?
172
177
  raise ArgumentError, 'Key is required, but nil' if key.nil?
173
- out = `/usr/libexec/PlistBuddy -c "Print :#{key}" "#{path}"`.chomp
174
- raise ArgumentError, out unless $?.success?
178
+ out = `/usr/libexec/PlistBuddy -c "Print :#{key}" "#{path}" 2>&1`.chomp
179
+ raise ArgumentError, "Error reading plist: #{out}" unless $?.success?
175
180
  out
176
181
  end
177
182
 
@@ -215,18 +220,6 @@ module XCRes
215
220
  end
216
221
  end
217
222
 
218
- # Get relative file paths
219
- #
220
- # @return [Array<Pathname>]
221
- #
222
- def strings_file_paths
223
- project_dir = project.path + '..'
224
- project_dir_realpath = project_dir.realpath
225
- strings_file_refs.map(&:real_path).map do |path|
226
- project_dir + path.relative_path_from(project_dir_realpath) rescue path
227
- end
228
- end
229
-
230
223
  # Read a file and collect all its keys
231
224
  #
232
225
  # @param [Pathname] path
data/lib/xcres/logger.rb CHANGED
@@ -108,20 +108,21 @@ class XCRes::Logger
108
108
 
109
109
  # Print a warning log message in yellow color
110
110
  #
111
- # @param [String] message
111
+ # @param [String|Exception] message_or_exception
112
112
  # the message, which can have format placeholders
113
113
  #
114
114
  # @param [#to_s...] format_args
115
115
  # will be passed as right hand side to the percent operator,
116
116
  # which will fill the format placeholders used in the message
117
117
  #
118
- def warn message, *format_args
118
+ def warn message_or_exception, *format_args
119
+ message, _ = coerce_to_message(message_or_exception)
119
120
  inform_colored '⚠' + ' ' + message, :yellow, *format_args
120
121
  end
121
122
 
122
123
  # Print a log message to indicate failure of an operation in red color
123
124
  #
124
- # @param [String|Exception] message
125
+ # @param [String|Exception] message_or_exception
125
126
  # The message, which can have format placeholders,
126
127
  # can also be a kind of Exception, then its message would been
127
128
  # used instead. The backtrace will be only printed, if the verbose
@@ -131,13 +132,8 @@ class XCRes::Logger
131
132
  # will be passed as right hand side to the percent operator,
132
133
  # which will fill the format placeholders used in the message
133
134
  #
134
- def fail message, *format_args
135
- exception = nil
136
- if message.kind_of? Exception
137
- exception = message
138
- message = exception.message
139
- end
140
-
135
+ def fail message_or_exception, *format_args
136
+ message, exception = coerce_to_message(message_or_exception)
141
137
  inform_colored '✗' + ' ' + message, :red, *format_args
142
138
 
143
139
  if verbose? && exception != nil
@@ -145,4 +141,29 @@ class XCRes::Logger
145
141
  end
146
142
  end
147
143
 
144
+ private
145
+
146
+ # Coerces the given message or an exception to a string, and yields them as
147
+ # separated parameters to a block, which allows further handling.
148
+ #
149
+ # @param [#to_s] message_or_exception
150
+ # Can be a String message or an exception
151
+ #
152
+ # @return [String,Exception?] message,exception
153
+ # An array on first place is either the first argument or the
154
+ # exception's message. If the given argument +message_or_exception+
155
+ # is an exception, then it is the second element in the result.
156
+ #
157
+ def coerce_to_message(message_or_exception)
158
+ exception = nil
159
+ if message_or_exception.kind_of? Exception
160
+ exception = message_or_exception
161
+ message = exception.message
162
+ else
163
+ message = message_or_exception.to_s
164
+ end
165
+
166
+ return message, exception
167
+ end
168
+
148
169
  end
data/lib/xcres/version.rb CHANGED
@@ -4,6 +4,6 @@ module XCRes
4
4
  #
5
5
  # XCRes’s version, following [semver](http://semver.org).
6
6
  #
7
- VERSION = "0.4.3"
7
+ VERSION = "0.4.4"
8
8
 
9
9
  end
@@ -1,3 +1,3 @@
1
1
  xcres version --verbose --no-ansi 2>&1
2
2
  Ⓥ Verbose mode is enabled.
3
- 0.4.3
3
+ 0.4.4
@@ -83,18 +83,150 @@ describe 'XCRes::StringsAnalyzer' do
83
83
  end
84
84
  end
85
85
 
86
- describe "#find_strings_file_refs" do
86
+ describe "with fixture project" do
87
87
  before do
88
88
  @target = app_target
89
89
  @analyzer = subject.new(@target)
90
+ @analyzer.logger = stub('Logger', :log)
91
+ @analyzer.expects(:warn).never
92
+ @analyzer.expects(:error).never
90
93
  end
91
94
 
92
- it 'should return the strings files of the fixture project' do
93
- strings_files = @analyzer.find_file_refs_by_extname('.strings')
94
- strings_files.count.should.be.eql?(3)
95
- strings_files[0].path.should.be.eql?('en.lproj/InfoPlist.strings')
96
- strings_files[1].path.should.be.eql?('en.lproj/Localizable.strings')
97
- strings_files[2].path.should.be.eql?('de.lproj/Localizable.strings')
95
+ describe "#strings_file_refs" do
96
+ it 'should return the strings files of the fixture project' do
97
+ strings_files = @analyzer.strings_file_refs
98
+ strings_files.count.should.be.eql?(3)
99
+ strings_files[0].path.should.be.eql?('en.lproj/InfoPlist.strings')
100
+ strings_files[1].path.should.be.eql?('en.lproj/Localizable.strings')
101
+ strings_files[2].path.should.be.eql?('de.lproj/Localizable.strings')
102
+ end
103
+ end
104
+
105
+ describe '#derive_used_languages' do
106
+ it 'should find used languages' do
107
+ languages = @analyzer.derive_used_languages(@analyzer.strings_file_refs)
108
+ languages.should == ['en', 'de'].to_set
109
+ end
110
+ end
111
+
112
+ describe '#used_languages' do
113
+ it 'should return english and german as used languages' do
114
+ @analyzer.used_languages.should == ['en', 'de'].to_set
115
+ end
116
+ end
117
+
118
+ describe '#info_plist_paths' do
119
+ it 'should return a set with the configured paths of the project' do
120
+ @analyzer.info_plist_paths.should == [Pathname('Example/Example-Info.plist')].to_set
121
+ end
122
+ end
123
+
124
+ describe '#absolute_info_plist_paths' do
125
+ it 'should resolve the path if it is relative' do
126
+ @analyzer.absolute_project_file_path('Info.plist')
127
+ .relative_path_from(fixture_path)
128
+ .should == Pathname('Example/Info.plist')
129
+ end
130
+
131
+ it 'should resolve the path if $SRCROOT is used' do
132
+ @analyzer.absolute_project_file_path('$SRCROOT/Info.plist')
133
+ .relative_path_from(fixture_path)
134
+ .should == Pathname('Example/Info.plist')
135
+ end
136
+ end
137
+
138
+ describe '#native_dev_languages' do
139
+ it 'should return english' do
140
+ @analyzer.native_dev_languages.should == ['en'].to_set
141
+ end
142
+
143
+ describe 'with non-configured Info.plist' do
144
+ it 'should warn on missing plists' do
145
+ @target.build_configurations[0].build_settings['INFOPLIST_FILE'] = 'NonExisting.plist'
146
+ @analyzer.expects(:warn).once
147
+ @analyzer.native_dev_languages.should == ['en'].to_set
148
+ end
149
+ end
150
+ end
151
+
152
+ describe '#read_plist_key' do
153
+ before do
154
+ @plist_path = fixture_path + 'Example/Example/Example-Info.plist'
155
+ end
156
+
157
+ it 'should read and return existing keys' do
158
+ @analyzer.read_plist_key(@plist_path, :CFBundleDevelopmentRegion)
159
+ .should == 'en'
160
+ end
161
+
162
+ it 'should raise an ArgumentError on non-existing files' do
163
+ plist_path = Pathname('NonExisting.plist')
164
+ proc do
165
+ @analyzer.read_plist_key(plist_path, :XCResNonExistingKey)
166
+ end.should.raise(ArgumentError).message
167
+ .should == "File 'NonExisting.plist' doesn't exist"
168
+ end
169
+
170
+ it 'should raise an ArgumentError on non-existing keys' do
171
+ proc do
172
+ @analyzer.read_plist_key(@plist_path, :XCResNonExistingKey)
173
+ end.should.raise(ArgumentError).message
174
+ .should == 'Error reading plist: Print: Entry, ":XCResNonExistingKey", Does Not Exist'
175
+ end
176
+ end
177
+
178
+ describe '#absolute_project_file_path' do
179
+ it 'should treat relative paths correctly' do
180
+ @analyzer.absolute_project_file_path('Info.plist')
181
+ .relative_path_from(fixture_path)
182
+ .should == Pathname('Example/Info.plist')
183
+ end
184
+
185
+ it 'should replace $SRCROOT with project path' do
186
+ @analyzer.absolute_project_file_path('$SRCROOT/Info.plist')
187
+ .relative_path_from(fixture_path)
188
+ .should == Pathname('Example/Info.plist')
189
+ end
190
+
191
+ it 'should replace ${SRCROOT} with project path' do
192
+ @analyzer.absolute_project_file_path('${SRCROOT}/Info.plist')
193
+ .relative_path_from(fixture_path)
194
+ .should == Pathname('Example/Info.plist')
195
+ end
196
+
197
+ it 'should replace $(SRCROOT) with project path' do
198
+ @analyzer.absolute_project_file_path('$(SRCROOT)/Info.plist')
199
+ .relative_path_from(fixture_path)
200
+ .should == Pathname('Example/Info.plist')
201
+ end
202
+ end
203
+
204
+ describe '#selected_strings_file_refs' do
205
+ describe 'for english development language' do
206
+ before do
207
+ @analyzer.stubs(:languages).returns ['en']
208
+ end
209
+
210
+ it 'should return the selected strings file refs' do
211
+ strings_files = @analyzer.selected_strings_file_refs
212
+ strings_files.count.should.be.eql?(2)
213
+ strings_files[0].path.should.be.eql?('en.lproj/InfoPlist.strings')
214
+ strings_files[1].path.should.be.eql?('en.lproj/Localizable.strings')
215
+ end
216
+ end
217
+
218
+ describe 'for german development language' do
219
+ before do
220
+ @analyzer.stubs(:languages).returns ['de']
221
+ end
222
+
223
+ it 'should return the selected strings file refs' do
224
+ @analyzer.stubs(:languages).returns ['de']
225
+ strings_files = @analyzer.selected_strings_file_refs
226
+ strings_files.count.should.be.eql?(1)
227
+ strings_files[0].path.should.be.eql?('de.lproj/Localizable.strings')
228
+ end
229
+ end
98
230
  end
99
231
  end
100
232
 
@@ -122,6 +122,11 @@ describe 'XCRes::LoggerSpec' do
122
122
  @logger.warn 'test'
123
123
  out.should.be.eql? "\e[33m⚠ test\e[0m"
124
124
  end
125
+
126
+ it 'accepts an Exception as message' do
127
+ @logger.warn StandardError.new('test')
128
+ out.should.be.eql? "\e[33m⚠ test\e[0m"
129
+ end
125
130
  end
126
131
 
127
132
  describe '#fail' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcres
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marius Rackwitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-26 00:00:00.000000000 Z
11
+ date: 2014-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler