bigkeeper 0.9.5 → 0.9.6

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: d2c790477569b7ef766f52666eb1982cb4ff288f
4
- data.tar.gz: 5dc5ce6dbd8b9df51738e95186c61b1b5b74ac9f
3
+ metadata.gz: 875ec925ad5aa51547b3f7ab27520f5e1f8d42d2
4
+ data.tar.gz: '08f1cfdb43165274549e93edcc5680b56f2b4de4'
5
5
  SHA512:
6
- metadata.gz: e7aa2ffcb35da4cb67157b505e5006b314f8e0ff91e5f2f8162bb6042e0ce3bc6188316a2a3454a7349c0fd25abe6225a53a7d1605ab9dc84c867516746e5e42
7
- data.tar.gz: 507ccf37d559e6379c3b66d620138dfc2037b17cee586c1baf4625379c59dd63fc6d9a2bb3d74b0778d365a21eecff6316b3ab35131f6f1f388e0933fc77aa19
6
+ metadata.gz: 5731521b8fe9eeb01d64428ad71a01ad7e8e32cdfcf0fccb9ad957028fc1e90ce90b7ac1f6d9862b3028da06ac6174c857a4cab76601d21ad0865ffb0f4e3e05
7
+ data.tar.gz: 6095dfb363e7d84b48794ea1aaeab0edd28e7cb759fa4009ead8907818cce789190d14d3f318807eff3f92de03de4ac6c77b7fa0249ea08c43615d3826578a8e
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bigkeeper (0.9.4)
4
+ bigkeeper (0.9.6)
5
5
  big_resources
6
6
  big_stash (~> 0.1)
7
7
  cocoapods
data/bin/big CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- #require "bundler/setup"
3
+ # require "bundler/setup"
4
4
  require "big_keeper"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
@@ -1,136 +1,45 @@
1
1
  require 'big_keeper/dependency/dep_operator'
2
- require 'big_keeper/util/gradle_operator'
2
+ require 'big_keeper/util/gradle_module_operator'
3
+ require 'big_keeper/util/gradle_file_operator'
3
4
  require 'big_keeper/model/operate_type'
4
5
 
5
6
  module BigKeeper
6
7
  # Operator for podfile
7
8
  class DepGradleOperator < DepOperator
8
9
 
9
- PATH_VERSION_CONFIG = "doc/config/version-config.gradle"
10
- LOCAL_MODULE_BUILD = "module/module.gradle"
11
- GLOBAL_MODULE_BUILD = "module/global.gradle"
10
+ BUILD_GRADLE = "app/build.gradle"
11
+ SETTINGS_GRADLE = "settings.gradle"
12
12
 
13
13
  def backup
14
- GradleOperator.new(@path).backup
15
14
  end
16
15
 
17
16
  def recover
18
- GradleOperator.new(@path).recover
19
- end
17
+ build_file = "#{@path}/#{BUILD_GRADLE}"
18
+ settings_file = "#{@path}/#{SETTINGS_GRADLE}"
19
+ GradleFileOperator.new(@path, @user).recover_bigkeeper_config_file(build_file)
20
+ GradleFileOperator.new(@path, @user).recover_bigkeeper_config_file(settings_file)
20
21
 
21
- def update_project_config(modules, type)
22
- raise "You should override this method in subclass."
22
+ cache_operator = CacheOperator.new(@path)
23
+ cache_operator.clean
23
24
  end
24
25
 
25
26
  def update_module_config(module_name, module_operate_type)
26
- update_local_depend(module_name, module_operate_type)
27
- update_project_version_config(module_name, module_operate_type)
28
- module_full_path = BigkeeperParser.module_full_path(@path, @user, module_name)
29
- GradleOperator.new(module_full_path).update_version_config(module_name, module_operate_type)
30
- end
31
-
32
- def update_project_version_config(module_name, module_operate_type)
33
- temp_file = Tempfile.new('.version-config.gradle.tmp')
34
- begin
35
- File.open("#{@path}/#{PATH_VERSION_CONFIG}", 'r') do |file|
36
- file.each_line do |line|
37
- new_line = generate_version_config_of_line(
38
- line,
39
- module_name,
40
- module_operate_type)
41
- temp_file.puts(new_line)
42
- end
43
- end
44
- temp_file.close
45
- FileUtils.mv(temp_file.path, "#{@path}/#{PATH_VERSION_CONFIG}")
46
- ensure
47
- temp_file.close
48
- temp_file.unlink
49
- end
50
- end
51
-
52
- def update_local_depend(module_name, module_operate_type)
53
- if !File.exist?("#{@path}/#{LOCAL_MODULE_BUILD}")
54
- FileUtils.cp("#{@path}/#{GLOBAL_MODULE_BUILD}", "#{@path}/#{LOCAL_MODULE_BUILD}")
55
- end
56
- temp_file = Tempfile.new('.module.gradle.tmp')
57
- begin
58
- File.open("#{@path}/#{LOCAL_MODULE_BUILD}", 'r') do |file|
59
- file.each_line do |line|
60
- new_line = generate_local_depend_of_line(
61
- line,
62
- module_name,
63
- module_operate_type)
64
- temp_file.puts(new_line)
65
- end
66
- end
67
- temp_file.close
68
- FileUtils.mv(temp_file.path, "#{@path}/#{LOCAL_MODULE_BUILD}")
69
- ensure
70
- temp_file.close
71
- temp_file.unlink
27
+ if ModuleOperateType::ADD == module_operate_type
28
+ GradleModuleOperator.new(@path, @user, module_name).update_module(ModuleOperateType::ADD)
29
+ elsif ModuleOperateType::DELETE == module_operate_type
30
+ GradleModuleOperator.new(@path, @user, module_name).recover()
31
+ elsif ModuleOperateType::FINISH == module_operate_type
32
+ GradleModuleOperator.new(@path, @user, module_name).update_module(ModuleOperateType::FINISH)
33
+ elsif ModuleOperateType::PUBLISH == module_operate_type
34
+ GradleModuleOperator.new(@path, @user, module_name).recover()
72
35
  end
73
36
  end
74
37
 
75
- def generate_version_config_of_line(line, module_name, module_operate_type)
76
- if line.downcase.match(/([\s\S]*)#{module_name.downcase.gsub('-','')}version(\s*)=(\s*)('|")(\S*)('|")([\s\S]*)/)
77
- branch_name = GitOperator.new.current_branch(@path)
78
- version_name = ''
79
- # Get version part of source.addition
80
-
81
- if ModuleOperateType::ADD == module_operate_type
82
- version_name = branch_name.sub(/([\s\S]*)\/([\s\S]*)/){ $2 }+'-SNAPSHOT'
83
- elsif ModuleOperateType::FINISH == module_operate_type
84
- version_name = branch_name.sub(/([\s\S]*)\/([\s\S]*)/){ $2 }
85
- elsif ModuleOperateType::DELETE == module_operate_type
86
- return origin_config_of_module(module_name)
87
- else
88
- version_name = branch_name.sub(/([\s\S]*)\/(\d+.\d+.\d+)_([\s\S]*)/){ $2 }
89
- end
90
- return line.sub(/([\s\S]*)Version(\s*)=(\s*)('|")(\S*)('|")([\s\S]*)/){
91
- "#{$1}Version = '#{version_name}'"}
92
- end
93
- line
94
- end
95
-
96
- def generate_local_depend_of_line(line, module_name, module_operate_type)
97
- if line.downcase.match(/([\s\S]*):module:#{module_name.downcase.gsub('-','')}([\s\S]*)/)
98
- if ModuleOperateType::ADD == module_operate_type
99
- line = line.gsub('//','')
100
- else
101
- line = line.gsub('//','')
102
- line = '//' + line
103
- end
104
- end
105
- line
106
- end
107
-
108
- def origin_config_of_module(module_name)
109
- origin_config = ''
110
- File.open("#{@path}/.bigkeeper/#{PATH_VERSION_CONFIG}", 'r') do |file|
111
- file.each_line do |line|
112
- if line.downcase.match(/([\s\S]*)#{module_name.downcase.gsub('-','')}version(\s*)=(\s*)('|")(\S*)('|")([\s\S]*)/)
113
- origin_config = line
114
- break
115
- end
116
- end
117
- end
118
- origin_config.chop
119
- end
120
-
121
38
  def install(modules, type, should_update)
122
- if OperateType::SWITCH == type
123
- all_modules = BigkeeperParser.module_names
124
-
125
- #close all
126
- all_modules.each do |module_name|
127
- update_local_depend(module_name, ModuleOperateType::DELETE)
128
- end
129
-
130
- #open modules
131
- modules.each do |module_name|
132
- update_local_depend(module_name, ModuleOperateType::ADD)
133
- end
39
+ if OperateType::START == type || OperateType::UPDATE == type || OperateType::SWITCH == type || OperateType::FINISH == type
40
+ GradleFileOperator.new(@path, @user).update_home_depends("#{@path}/#{BUILD_GRADLE}", "#{@path}/#{SETTINGS_GRADLE}",type)
41
+ elsif OperateType::PUBLISH == type
42
+ recover()
134
43
  end
135
44
  end
136
45
 
@@ -219,6 +219,18 @@ module BigKeeper
219
219
  @@config[:modules][module_name][:git]
220
220
  end
221
221
 
222
+ def self.module_source(module_name)
223
+ @@config[:modules][module_name][:mod_path]
224
+ end
225
+
226
+ def self.module_maven(module_name)
227
+ @@config[:modules][module_name][:maven_group] + ':' + @@config[:modules][module_name][:maven_artifact]
228
+ end
229
+
230
+ def self.module_maven_artifact(module_name)
231
+ @@config[:modules][module_name][:maven_artifact]
232
+ end
233
+
222
234
  def self.module_pulls(module_name)
223
235
  @@config[:modules][module_name][:pulls]
224
236
  end
@@ -19,7 +19,9 @@ module BigKeeper
19
19
  end
20
20
 
21
21
  def clean
22
- FileUtils.rm_r(@cache_path)
22
+ if File.exist?(@cache_path)
23
+ FileUtils.rm_r(@cache_path)
24
+ end
23
25
  end
24
26
  end
25
27
 
@@ -110,7 +110,7 @@ module BigKeeper
110
110
 
111
111
  def discard(path)
112
112
  Dir.chdir(path) do
113
- `git checkout . && git clean -xdf`
113
+ `git checkout . && git clean -df`
114
114
  end
115
115
  end
116
116
 
@@ -0,0 +1,26 @@
1
+ module BigKeeper
2
+ class GradleConentGenerator
3
+ def self.generate_bigkeeper_settings_gradle_content()
4
+ "
5
+ //bigkeeper config start
6
+ Properties properties = new Properties()
7
+ properties.load(new File('local.properties').newDataInputStream())
8
+ if (\'true\' == properties.getProperty(\'ENABLE_BIGKEEPER_LOCAL\')) {
9
+ \tapply from: \'./.bigkeeper/bigkeeper_settings.gradle\'
10
+ }
11
+ //bigkeeper config end"
12
+ end
13
+
14
+ def self.generate_bigkeeper_build_gradle_content()
15
+ "
16
+ //bigkeeper config start
17
+ Properties properties = new Properties()
18
+ properties.load(project.rootProject.file('local.properties').newDataInputStream())
19
+ if (\'true\' != properties.getProperty(\'ENABLE_BIGKEEPER_LOCAL\')) {
20
+ \tapply from: \'../.bigkeeper/bigkeeper_build.gradle\'
21
+ }
22
+ //bigkeeper config end
23
+ "
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,338 @@
1
+ require 'big_keeper/util/logger'
2
+ require 'big_keeper/util/gradle_content_generator'
3
+
4
+ module BigKeeper
5
+ class GradleFileOperator
6
+ @path
7
+ @user
8
+ def initialize(path, user)
9
+ @path = path
10
+ @user = user
11
+ end
12
+
13
+ def get_module_depends(build_file, module_name)
14
+ Logger.highlight("get module #{module_name} depends ...")
15
+ depend_modules = []
16
+ modules = ModuleCacheOperator.new(@path).all_path_modules
17
+ File.open(build_file, 'r') do |file|
18
+ file.each_line do |line|
19
+ modules.each do |name|
20
+ if line.strip().index('//') != 0 && !line.include?(BigkeeperParser.module_maven(module_name)) && !depend_modules.include?(name) && line.include?(BigkeeperParser.module_maven(name))
21
+ depend_modules << name
22
+ end
23
+ end
24
+ end
25
+ end
26
+ print "module #{module_name} depends: "
27
+ p depend_modules
28
+ depend_modules
29
+ end
30
+
31
+ def update_module_settings(module_name, settings_file, depend_modules)
32
+ module_full_path = BigkeeperParser.module_full_path(@path, @user, module_name)
33
+ cache_path = File.expand_path("#{module_full_path}/.bigkeeper")
34
+ big_settings_file = "#{cache_path}/bigkeeper_settings.gradle"
35
+
36
+ if depend_modules.empty? && !File.exist?(big_settings_file)
37
+ return
38
+ end
39
+
40
+ result = ''
41
+ depend_modules.each do |name|
42
+ artifact_id = BigkeeperParser.module_maven_artifact(name)
43
+ source = BigkeeperParser.module_source(name)
44
+ result << "include \':module:#{artifact_id}\'\nproject(':module:#{artifact_id}').projectDir = new File(rootProject.projectDir, '../#{name}/#{source}')\n"
45
+ end
46
+
47
+ dest_path = File.dirname(big_settings_file)
48
+ FileUtils.mkdir_p(dest_path) unless File.exist?(dest_path)
49
+ file = File.new(big_settings_file, 'w')
50
+ begin
51
+ file << result
52
+ file.close
53
+ ensure
54
+ file.close
55
+ end
56
+
57
+ if has_bigkeeper_config(settings_file)
58
+ return
59
+ end
60
+
61
+ temp_file = Tempfile.new('.settings.gradle.tmp')
62
+ begin
63
+ File.open(settings_file, 'r') do |file|
64
+ file.each_line do |line|
65
+ temp_file.puts(line)
66
+ end
67
+ end
68
+ temp_file.puts(GradleConentGenerator.generate_bigkeeper_settings_gradle_content())
69
+ temp_file.close
70
+ FileUtils.mv(temp_file.path, settings_file)
71
+ ensure
72
+ temp_file.close
73
+ temp_file.unlink
74
+ end
75
+ end
76
+
77
+ def update_module_build(build_file, module_name, depend_modules, version_name)
78
+ module_full_path = BigkeeperParser.module_full_path(@path, @user, module_name)
79
+ cache_path = File.expand_path("#{module_full_path}/.bigkeeper")
80
+ big_build_file = "#{cache_path}/bigkeeper_build.gradle"
81
+
82
+ if depend_modules.empty? && !File.exist?(big_build_file)
83
+ return
84
+ end
85
+
86
+ result = "configurations.all {\n\tresolutionStrategy {\n"
87
+ depend_modules.each do |name|
88
+ module_maven = BigkeeperParser.module_maven(name)
89
+ result << "\t\tforce \'#{module_maven}:#{version_name}-SNAPSHOT\'\n"
90
+ end
91
+ result << "\t}\n}\n"
92
+
93
+ dest_path = File.dirname(big_build_file)
94
+ FileUtils.mkdir_p(dest_path) unless File.exist?(dest_path)
95
+ file = File.new(big_build_file, 'w')
96
+ begin
97
+ file << result
98
+ file.close
99
+ ensure
100
+ file.close
101
+ end
102
+
103
+ if has_bigkeeper_config(build_file)
104
+ return
105
+ end
106
+
107
+ temp_file = Tempfile.new('.build.gradle.tmp')
108
+ begin
109
+ File.open(build_file, 'r') do |file|
110
+ file.each_line do |line|
111
+ temp_file.puts(line)
112
+ end
113
+ end
114
+ temp_file.puts(GradleConentGenerator.generate_bigkeeper_build_gradle_content())
115
+ temp_file.close
116
+ FileUtils.mv(temp_file.path, build_file)
117
+ ensure
118
+ temp_file.close
119
+ temp_file.unlink
120
+ end
121
+ end
122
+
123
+ def get_home_depends()
124
+ path_modules = ModuleCacheOperator.new(@path).all_path_modules
125
+ git_modules = ModuleCacheOperator.new(@path).all_git_modules
126
+ path_modules | git_modules
127
+ end
128
+
129
+ def update_home_settings(settings_file, depend_modules)
130
+ cache_path = File.expand_path("#{@path}/.bigkeeper")
131
+ big_settings_file = "#{cache_path}/bigkeeper_settings.gradle"
132
+
133
+ if depend_modules.empty? && !File.exist?(big_settings_file)
134
+ return
135
+ end
136
+
137
+ result = ''
138
+ depend_modules.each do |name|
139
+ artifact_id = BigkeeperParser.module_maven(name).split(':')[1]
140
+ path = BigkeeperParser.module_full_path(@path, @user, name)
141
+ source = BigkeeperParser.module_source(name)
142
+ result << "include \':module:#{artifact_id}\'\nproject(':module:#{artifact_id}').projectDir = new File(rootProject.projectDir, '../#{name}/#{source}')\n"
143
+ end
144
+
145
+ dest_path = File.dirname(big_settings_file)
146
+ FileUtils.mkdir_p(dest_path) unless File.exist?(dest_path)
147
+ file = File.new(big_settings_file, 'w')
148
+ begin
149
+ file << result
150
+ file.close
151
+ ensure
152
+ file.close
153
+ end
154
+
155
+ if has_bigkeeper_config(settings_file)
156
+ return
157
+ end
158
+
159
+ temp_file = Tempfile.new('.settings.gradle.tmp')
160
+ begin
161
+ File.open(settings_file, 'r') do |file|
162
+ file.each_line do |line|
163
+ temp_file.puts(line)
164
+ end
165
+ end
166
+ temp_file.puts(GradleConentGenerator.generate_bigkeeper_settings_gradle_content())
167
+ temp_file.close
168
+ FileUtils.mv(temp_file.path, settings_file)
169
+ ensure
170
+ temp_file.close
171
+ temp_file.unlink
172
+ end
173
+ end
174
+
175
+ def update_home_build(build_file, depend_modules, version_name)
176
+ cache_path = File.expand_path("#{@path}/.bigkeeper")
177
+ big_build_file = "#{cache_path}/bigkeeper_build.gradle"
178
+
179
+ if depend_modules.empty? && !File.exist?(big_build_file)
180
+ return
181
+ end
182
+
183
+ result = "configurations.all {\n\tresolutionStrategy {\n"
184
+ depend_modules.each do |module_name|
185
+ module_maven = BigkeeperParser.module_maven(module_name)
186
+ result << "\t\tforce \'#{module_maven}:#{version_name}-SNAPSHOT\'\n"
187
+ end
188
+ result << "\t}\n}\n"
189
+
190
+ dest_path = File.dirname(big_build_file)
191
+ FileUtils.mkdir_p(dest_path) unless File.exist?(dest_path)
192
+ file = File.new(big_build_file, 'w')
193
+ begin
194
+ file << result
195
+ file.close
196
+ ensure
197
+ file.close
198
+ end
199
+
200
+ if has_bigkeeper_config(build_file)
201
+ return
202
+ end
203
+
204
+ temp_file = Tempfile.new('.build.gradle.tmp')
205
+ begin
206
+ File.open(build_file, 'r') do |file|
207
+ file.each_line do |line|
208
+ temp_file.puts(line)
209
+ end
210
+ end
211
+ temp_file.puts(GradleConentGenerator.generate_bigkeeper_build_gradle_content())
212
+ temp_file.close
213
+ FileUtils.mv(temp_file.path, build_file)
214
+ ensure
215
+ temp_file.close
216
+ temp_file.unlink
217
+ end
218
+ end
219
+
220
+ def update_module_version_name(build_file, version_name)
221
+ temp_file = Tempfile.new('.build.gradle.tmp')
222
+ isModifyPom = false
223
+ isBigkeeperScript = false
224
+ isBigkeeperBackupScript = false
225
+ hasBigkeeperBackup = false
226
+ begin
227
+ File.open(build_file, 'r') do |file|
228
+ file.each_line do |line|
229
+ if line.include?('modifyPom')
230
+ isModifyPom = true
231
+ elsif line.include?('bigkeeper config start')
232
+ isBigkeeperScript = true
233
+ elsif line.include?('bigkeeper config end')
234
+ isBigkeeperScript = false
235
+ elsif line.include?('bigkeeper config backup start')
236
+ isBigkeeperBackupScript = true
237
+ hasBigkeeperBackup = true
238
+ elsif line.include?('bigkeeper config backup end')
239
+ isBigkeeperBackupScript = false
240
+ end
241
+
242
+ if isModifyPom && !isBigkeeperBackupScript && line.match(/[\s\S]*version[\s\S]*/)
243
+ if !hasBigkeeperBackup
244
+ temp_file.puts("\t\t//bigkeeper config backup start")
245
+ temp_file.puts("\t\t//"+line.strip)
246
+ temp_file.puts("\t\t//bigkeeper config backup end")
247
+ end
248
+
249
+ if isBigkeeperScript
250
+ temp_file.puts("\t\tversion \'#{version_name}\'")
251
+ else
252
+ temp_file.puts("\t\t//bigkeeper config start")
253
+ temp_file.puts("\t\tversion \'#{version_name}\'")
254
+ temp_file.puts("\t\t//bigkeeper config end")
255
+ end
256
+ isModifyPom = false
257
+ else
258
+ temp_file.puts(line)
259
+ end
260
+ end
261
+ end
262
+ temp_file.close
263
+ FileUtils.mv(temp_file.path, build_file)
264
+ ensure
265
+ temp_file.close
266
+ temp_file.unlink
267
+ end
268
+ end
269
+
270
+ def update_module_depends(build_file, settings_file, module_name, version_name)
271
+ depend_modules = get_module_depends(build_file, module_name)
272
+ update_module_settings(module_name, settings_file, depend_modules)
273
+ update_module_build(build_file, module_name, depend_modules, version_name)
274
+ end
275
+
276
+ def update_home_depends(build_file, settings_file, type)
277
+ depend_modules = get_home_depends()
278
+ update_home_settings(settings_file, depend_modules)
279
+ update_home_build(build_file, depend_modules, generate_version_name(type))
280
+ end
281
+
282
+ def generate_version_name(type)
283
+ branch_name = GitOperator.new.current_branch(@path)
284
+ version_name = ''
285
+ if OperateType::FINISH == type
286
+ version_name = branch_name.sub(/([\s\S]*)\/(\d+.\d+.\d+)_([\s\S]*)/){ $2 }
287
+ else
288
+ version_name = branch_name.sub(/([\s\S]*)\/([\s\S]*)/){ $2 }
289
+ end
290
+ version_name
291
+ end
292
+
293
+ def recover_bigkeeper_config_file(bigkeeper_config_file)
294
+ if !File.exist?(bigkeeper_config_file)
295
+ return
296
+ end
297
+ temp_file = Tempfile.new('.bigkeeper_config.tmp')
298
+ isBigkeeperScript = false
299
+ isBigkeeperBackupScript = false
300
+ begin
301
+ File.open(bigkeeper_config_file, 'r') do |file|
302
+ file.each_line do |line|
303
+ if line.include?('bigkeeper config start')
304
+ isBigkeeperScript = true
305
+ elsif line.include?('bigkeeper config end')
306
+ isBigkeeperScript = false
307
+ elsif line.include?('bigkeeper config backup start')
308
+ isBigkeeperBackupScript = true
309
+ elsif line.include?('bigkeeper config backup end')
310
+ isBigkeeperBackupScript = false
311
+ elsif isBigkeeperBackupScript
312
+ temp_file.puts(line.gsub('//',''))
313
+ elsif !isBigkeeperScript
314
+ temp_file.puts(line)
315
+ end
316
+ end
317
+ end
318
+ temp_file.close
319
+ FileUtils.mv(temp_file.path, bigkeeper_config_file)
320
+ ensure
321
+ temp_file.close
322
+ temp_file.unlink
323
+ end
324
+ end
325
+
326
+ def has_bigkeeper_config(file)
327
+ File.open(file, 'r') do |file|
328
+ file.each_line do |line|
329
+ if line.include?('bigkeeper config start')
330
+ return true
331
+ end
332
+ end
333
+ end
334
+ false
335
+ end
336
+
337
+ end
338
+ end
@@ -0,0 +1,69 @@
1
+ require 'big_keeper/util/cache_operator'
2
+ require 'big_keeper/util/gradle_file_operator'
3
+ require 'big_keeper/util/bigkeeper_parser'
4
+
5
+ module BigKeeper
6
+ # Operator for podfile
7
+ class GradleModuleOperator
8
+ @path
9
+ @user
10
+ @module_name
11
+
12
+ BUILD_GRADLE = "build.gradle"
13
+ SETTINGS_GRADLE = "settings.gradle"
14
+
15
+ def initialize(path, user, module_name)
16
+ @path = path
17
+ @user = user
18
+ @module_name = module_name
19
+ end
20
+
21
+ def backup
22
+ end
23
+
24
+ ## TODO
25
+ def recover()
26
+ module_full_path = BigkeeperParser.module_full_path(@path, @user, @module_name)
27
+ source = BigkeeperParser.module_source(@module_name)
28
+ build_file = "#{module_full_path}/#{source}/#{BUILD_GRADLE}"
29
+ settings_file = "#{module_full_path}/#{SETTINGS_GRADLE}"
30
+ GradleFileOperator.new(@path, @user).recover_bigkeeper_config_file(build_file)
31
+ GradleFileOperator.new(@path, @user).recover_bigkeeper_config_file(settings_file)
32
+
33
+ cache_operator = CacheOperator.new(module_full_path)
34
+ cache_operator.clean
35
+ end
36
+
37
+ def update_module(module_operate_type)
38
+ update_module_depends(module_operate_type)
39
+ update_module_version_name(module_operate_type)
40
+ end
41
+
42
+ def update_module_depends(module_operate_type)
43
+ module_full_path = BigkeeperParser.module_full_path(@path, @user, @module_name)
44
+ source = BigkeeperParser.module_source(@module_name)
45
+ version_name = generate_version_name(module_operate_type)
46
+ build_file = "#{module_full_path}/#{source}/#{BUILD_GRADLE}"
47
+ settings_file = "#{module_full_path}/#{SETTINGS_GRADLE}"
48
+ GradleFileOperator.new(@path, @user).update_module_depends(build_file, settings_file, @module_name, version_name)
49
+ end
50
+
51
+ def update_module_version_name(module_operate_type)
52
+ module_full_path = BigkeeperParser.module_full_path(@path, @user, @module_name)
53
+ source = BigkeeperParser.module_source(@module_name)
54
+ GradleFileOperator.new(@path, @user).update_module_version_name("#{module_full_path}/#{source}/#{BUILD_GRADLE}", generate_version_name(module_operate_type))
55
+ end
56
+
57
+ def generate_version_name(module_operate_type)
58
+ branch_name = GitOperator.new.current_branch(@path)
59
+ version_name = ''
60
+ if ModuleOperateType::ADD == module_operate_type
61
+ version_name = branch_name.sub(/([\s\S]*)\/([\s\S]*)/){ $2 }
62
+ elsif ModuleOperateType::FINISH == module_operate_type
63
+ version_name = branch_name.sub(/([\s\S]*)\/(\d+.\d+.\d+)_([\s\S]*)/){ $2 }
64
+ end
65
+ return version_name
66
+ end
67
+
68
+ end
69
+ end
@@ -1,3 +1,3 @@
1
1
  module BigKeeper
2
- VERSION = "0.9.5"
2
+ VERSION = "0.9.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigkeeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - mmoaay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-11 00:00:00.000000000 Z
11
+ date: 2019-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -298,7 +298,9 @@ files:
298
298
  - lib/big_keeper/util/file_operator.rb
299
299
  - lib/big_keeper/util/git_operator.rb
300
300
  - lib/big_keeper/util/gitflow_operator.rb
301
- - lib/big_keeper/util/gradle_operator.rb
301
+ - lib/big_keeper/util/gradle_content_generator.rb
302
+ - lib/big_keeper/util/gradle_file_operator.rb
303
+ - lib/big_keeper/util/gradle_module_operator.rb
302
304
  - lib/big_keeper/util/info_plist_operator.rb
303
305
  - lib/big_keeper/util/leancloud_logger.rb
304
306
  - lib/big_keeper/util/list_generator.rb
@@ -1,86 +0,0 @@
1
- require 'big_keeper/util/cache_operator'
2
-
3
- module BigKeeper
4
- # Operator for podfile
5
- class GradleOperator
6
-
7
- PATH_VERSION_CONFIG = "doc/config/version-config.gradle"
8
-
9
- def initialize(path)
10
- @path = path
11
- end
12
-
13
- def backup
14
- cache_operator = CacheOperator.new(@path)
15
- cache_operator.save(PATH_VERSION_CONFIG)
16
- end
17
-
18
- def recover()
19
- cache_operator = CacheOperator.new(@path)
20
- # cache_operator.load(PATH_VERSION_CONFIG)
21
- cache_operator.clean
22
- end
23
-
24
- def update_version_config(module_name, module_operate_type)
25
- module_full_path = BigkeeperParser.module_full_path(@path, @user, module_name)
26
- if module_operate_type == ModuleOperateType::ADD
27
- GradleOperator.new(module_full_path).backup
28
- end
29
-
30
- temp_file = Tempfile.new('.version-config.gradle.tmp')
31
- begin
32
- File.open("#{@path}/#{PATH_VERSION_CONFIG}", 'r') do |file|
33
- file.each_line do |line|
34
- new_line = generate_version_config_of_line(
35
- line,
36
- module_name,
37
- module_operate_type)
38
- temp_file.puts(new_line)
39
- end
40
- end
41
- temp_file.close
42
- FileUtils.mv(temp_file.path, "#{@path}/#{PATH_VERSION_CONFIG}")
43
- ensure
44
- temp_file.close
45
- temp_file.unlink
46
- end
47
-
48
- if module_operate_type == ModuleOperateType::PUBLISH
49
- GradleOperator.new(module_full_path).recover
50
- end
51
- end
52
-
53
- def generate_version_config_of_line(line, module_name, module_operate_type)
54
- if line.downcase.match(/([\s\S]*)#{module_name.downcase.gsub('-','')}version(\s*)=(\s*)('|")(\S*)('|")([\s\S]*)/)
55
- branch_name = GitOperator.new.current_branch(@path)
56
- version_name = ''
57
-
58
- if ModuleOperateType::DELETE == module_operate_type
59
- return origin_config_of_module(module_name)
60
- elsif ModuleOperateType::PUBLISH == module_operate_type
61
- version_name = branch_name.sub(/([\s\S]*)\/(\d+.\d+.\d+)_([\s\S]*)/){ $2 }
62
- else
63
- version_name = branch_name.sub(/([\s\S]*)\/([\s\S]*)/){ $2 }
64
- end
65
- return line.sub(/([\s\S]*)Version(\s*)=(\s*)('|")(\S*)('|")([\s\S]*)/){
66
- "#{$1}Version = '#{version_name}'"}
67
- end
68
- line
69
- end
70
-
71
- def origin_config_of_module(module_name)
72
- origin_config = ''
73
- File.open("#{@path}/.bigkeeper/#{PATH_VERSION_CONFIG}", 'r') do |file|
74
- file.each_line do |line|
75
- if line.downcase.match(/([\s\S]*)#{module_name.downcase.gsub('-','')}version(\s*)=(\s*)('|")(\S*)('|")([\s\S]*)/)
76
- origin_config = line
77
- break
78
- end
79
- end
80
- end
81
- origin_config.chop
82
- end
83
-
84
- private :generate_version_config_of_line, :origin_config_of_module
85
- end
86
- end