kookeeper 3.0.0 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/.gitignore +8 -0
- data/.idea/bigkeeper.iml +68 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/Gemfile.lock +68 -48
- data/big_keeper.gemspec +3 -3
- data/bin/big +1 -1
- data/bin/koo +1 -1
- data/lib/big_keeper/command/feature&hotfix/delete.rb +1 -1
- data/lib/big_keeper/command/feature&hotfix/finish.rb +2 -2
- data/lib/big_keeper/command/feature&hotfix/list.rb +1 -1
- data/lib/big_keeper/command/feature&hotfix/publish.rb +2 -2
- data/lib/big_keeper/command/feature&hotfix/start.rb +2 -2
- data/lib/big_keeper/command/feature&hotfix/switch.rb +2 -2
- data/lib/big_keeper/command/feature&hotfix/update.rb +2 -2
- data/lib/big_keeper/command/pod/podfile.rb +13 -16
- data/lib/big_keeper/command/pod.rb +5 -18
- data/lib/big_keeper/command/release/home.rb +1 -2
- data/lib/big_keeper/command/release/module.rb +0 -4
- data/lib/big_keeper/command/release.rb +0 -25
- data/lib/big_keeper/dependency/dep_gradle_operator.rb +29 -47
- data/lib/big_keeper/dependency/dep_operator.rb +1 -17
- data/lib/big_keeper/dependency/dep_pod_operator.rb +10 -10
- data/lib/big_keeper/model/operate_type.rb +0 -3
- data/lib/big_keeper/service/git_service.rb +2 -3
- data/lib/big_keeper/service/module_service.rb +0 -65
- data/lib/big_keeper/util/bigkeeper_parser.rb +1 -17
- data/lib/big_keeper/util/cache_operator.rb +4 -6
- data/lib/big_keeper/util/file_operator.rb +1 -1
- data/lib/big_keeper/util/git_operator.rb +4 -25
- data/lib/big_keeper/util/gradle_operator.rb +209 -0
- data/lib/big_keeper/util/leancloud_logger.rb +7 -19
- data/lib/big_keeper/util/list_generator.rb +2 -2
- data/lib/big_keeper/util/logger.rb +1 -2
- data/lib/big_keeper/util/podfile_detector.rb +44 -35
- data/lib/big_keeper/util/podfile_module.rb +1 -1
- data/lib/big_keeper/util/podfile_operator.rb +8 -16
- data/lib/big_keeper/version.rb +1 -1
- data/lib/big_keeper.rb +9 -19
- metadata +14 -25
- data/.github/ISSUE_TEMPLATE.md +0 -20
- data/.gitignore +0 -50
- data/.travis.yml +0 -19
- data/Rakefile +0 -2
- data/lib/big_keeper/command/client.rb +0 -50
- data/lib/big_keeper/command/init.rb +0 -36
- data/lib/big_keeper/command/release/finish.rb +0 -36
- data/lib/big_keeper/command/release/publish.rb +0 -4
- data/lib/big_keeper/command/release/start.rb +0 -78
- data/lib/big_keeper/util/command_line_util.rb +0 -9
- data/lib/big_keeper/util/gradle_content_generator.rb +0 -26
- data/lib/big_keeper/util/gradle_file_operator.rb +0 -339
- data/lib/big_keeper/util/gradle_module_operator.rb +0 -70
- data/lib/big_keeper/util/lockfile_parser.rb +0 -143
- data/lib/big_keeper/util/version_config_operator.rb +0 -29
- data/resources/template/Bigkeeper +0 -23
@@ -1,71 +1,53 @@
|
|
1
1
|
require 'big_keeper/dependency/dep_operator'
|
2
|
-
require 'big_keeper/util/
|
3
|
-
require 'big_keeper/util/gradle_file_operator'
|
4
|
-
require 'big_keeper/model/operate_type'
|
5
|
-
require 'big_keeper/util/version_config_operator'
|
2
|
+
require 'big_keeper/util/gradle_operator'
|
6
3
|
|
7
4
|
module BigKeeper
|
8
5
|
# Operator for podfile
|
9
6
|
class DepGradleOperator < DepOperator
|
10
7
|
|
11
|
-
BUILD_GRADLE = "app/build.gradle"
|
12
|
-
SETTINGS_GRADLE = "settings.gradle"
|
13
|
-
|
14
8
|
def backup
|
9
|
+
GradleOperator.new(@path).backup
|
10
|
+
modules = ModuleCacheOperator.new(@path).all_path_modules
|
11
|
+
modules.each do |module_name|
|
12
|
+
module_full_path = BigkeeperParser.module_full_path(@path, @user, module_name)
|
13
|
+
GradleOperator.new(module_full_path).backup
|
14
|
+
end
|
15
15
|
end
|
16
16
|
|
17
17
|
def recover
|
18
|
-
|
19
|
-
settings_file = "#{@path}/#{SETTINGS_GRADLE}"
|
20
|
-
GradleFileOperator.new(@path, @user).recover_bigkeeper_config_file(build_file)
|
21
|
-
GradleFileOperator.new(@path, @user).recover_bigkeeper_config_file(settings_file)
|
22
|
-
|
23
|
-
cache_operator = CacheOperator.new(@path)
|
24
|
-
cache_operator.clean
|
18
|
+
GradleOperator.new(@path).recover(true, false)
|
25
19
|
end
|
26
20
|
|
27
21
|
def update_module_config(module_name, module_operate_type)
|
22
|
+
module_full_path = BigkeeperParser.module_full_path(@path, @user, module_name)
|
23
|
+
|
24
|
+
# get modules
|
28
25
|
if ModuleOperateType::ADD == module_operate_type
|
29
|
-
|
26
|
+
GradleOperator.new(module_full_path).backup
|
27
|
+
|
28
|
+
add_modules = ModuleCacheOperator.new(@path).add_path_modules
|
29
|
+
GradleOperator.new(module_full_path).update_build_config(module_name, add_modules, ModuleOperateType::ADD)
|
30
|
+
GradleOperator.new(module_full_path).update_settings_config(module_name, add_modules, ModuleOperateType::ADD, @user)
|
31
|
+
|
32
|
+
del_modules = ModuleCacheOperator.new(@path).del_path_modules
|
33
|
+
GradleOperator.new(module_full_path).update_build_config(module_name, del_modules, ModuleOperateType::DELETE)
|
34
|
+
GradleOperator.new(module_full_path).update_settings_config(module_name, del_modules, ModuleOperateType::DELETE, @user)
|
30
35
|
elsif ModuleOperateType::DELETE == module_operate_type
|
31
|
-
|
36
|
+
GradleOperator.new(module_full_path).recover(true, true)
|
32
37
|
elsif ModuleOperateType::FINISH == module_operate_type
|
33
|
-
|
38
|
+
modules = ModuleCacheOperator.new(@path).all_path_modules
|
39
|
+
GradleOperator.new(module_full_path).update_build_config(module_name, modules, ModuleOperateType::FINISH)
|
34
40
|
elsif ModuleOperateType::PUBLISH == module_operate_type
|
35
|
-
|
41
|
+
modules = ModuleCacheOperator.new(@path).all_git_modules
|
42
|
+
GradleOperator.new(module_full_path).update_build_config(module_name, modules, ModuleOperateType::PUBLISH)
|
43
|
+
GradleOperator.new(module_full_path).recover(true, false)
|
36
44
|
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def install(modules, type, should_update)
|
40
|
-
if OperateType::START == type || OperateType::UPDATE == type || OperateType::SWITCH == type || OperateType::FINISH == type
|
41
|
-
GradleFileOperator.new(@path, @user).update_home_depends("#{@path}/#{BUILD_GRADLE}", "#{@path}/#{SETTINGS_GRADLE}",type)
|
42
|
-
elsif OperateType::PUBLISH == type
|
43
|
-
recover()
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def release_module_start(modules, module_name, version)
|
48
|
-
module_full_path = BigkeeperParser.module_full_path(@path, @user, module_name)
|
49
|
-
version_config_file = "#{module_full_path}/doc/config/version-config.gradle"
|
50
|
-
version = "#{version}-SNAPSHOT" unless version.include?'SNAPSHOT'
|
51
|
-
VersionConfigOperator.change_version(version_config_file, modules, version)
|
52
|
-
end
|
53
|
-
|
54
|
-
def release_module_finish(modules, module_name, version)
|
55
|
-
module_full_path = BigkeeperParser.module_full_path(@path, @user, module_name)
|
56
|
-
version_config_file = "#{module_full_path}/doc/config/version-config.gradle"
|
57
|
-
VersionConfigOperator.change_version(version_config_file, modules, version)
|
58
|
-
end
|
59
45
|
|
60
|
-
|
61
|
-
|
62
|
-
version = "#{version}-SNAPSHOT" unless version.include?'SNAPSHOT'
|
63
|
-
VersionConfigOperator.change_version(version_config_file, modules, version)
|
46
|
+
GradleOperator.new(@path).update_build_config('', [module_name], module_operate_type)
|
47
|
+
GradleOperator.new(@path).update_settings_config('', [module_name], module_operate_type, @user)
|
64
48
|
end
|
65
49
|
|
66
|
-
def
|
67
|
-
version_config_file = "#{@path}/doc/config/version-config.gradle"
|
68
|
-
VersionConfigOperator.change_version(version_config_file, modules, version)
|
50
|
+
def install(should_update)
|
69
51
|
end
|
70
52
|
|
71
53
|
def open
|
@@ -21,23 +21,7 @@ module BigKeeper
|
|
21
21
|
raise "You should override this method in subclass."
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
raise "You should override this method in subclass."
|
26
|
-
end
|
27
|
-
|
28
|
-
def release_module_finish(modules, module_name, version)
|
29
|
-
raise "You should override this method in subclass."
|
30
|
-
end
|
31
|
-
|
32
|
-
def release_home_start(modules, version)
|
33
|
-
raise "You should override this method in subclass."
|
34
|
-
end
|
35
|
-
|
36
|
-
def release_home_finish(modules, version)
|
37
|
-
raise "You should override this method in subclass."
|
38
|
-
end
|
39
|
-
|
40
|
-
def install(modules, type, should_update)
|
24
|
+
def install(should_update)
|
41
25
|
raise "You should override this method in subclass."
|
42
26
|
end
|
43
27
|
|
@@ -20,10 +20,10 @@ module BigKeeper
|
|
20
20
|
|
21
21
|
def update_module_config(module_name, module_operate_type)
|
22
22
|
file = "#{@path}/Podfile"
|
23
|
-
temp_file = Tempfile.new('.Podfile.tmp'
|
23
|
+
temp_file = Tempfile.new('.Podfile.tmp')
|
24
24
|
|
25
25
|
begin
|
26
|
-
File.open(file, 'r'
|
26
|
+
File.open(file, 'r') do |file|
|
27
27
|
file.each_line do |line|
|
28
28
|
temp_file.puts generate_module_config(line, module_name, module_operate_type)
|
29
29
|
end
|
@@ -36,7 +36,7 @@ module BigKeeper
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def install(
|
39
|
+
def install(should_update)
|
40
40
|
PodOperator.pod_install(@path, should_update)
|
41
41
|
end
|
42
42
|
|
@@ -45,10 +45,10 @@ module BigKeeper
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def generate_module_config(line, module_name, module_operate_type)
|
48
|
-
line.sub(/(\s*)pod(\s*)('|")#{module_name}(
|
48
|
+
line.sub(/(\s*)pod(\s*)('|")#{module_name}('|")([\s\S]*)/){
|
49
49
|
if ModuleOperateType::ADD == module_operate_type
|
50
50
|
module_path = BigkeeperParser.module_path(@user, module_name)
|
51
|
-
"#{$1}pod '#{module_name}
|
51
|
+
"#{$1}pod '#{module_name}', :path => '#{module_path}'"
|
52
52
|
elsif ModuleOperateType::DELETE == module_operate_type
|
53
53
|
origin_config_of_module = origin_config_of_module(module_name)
|
54
54
|
if origin_config_of_module.empty?
|
@@ -59,21 +59,21 @@ module BigKeeper
|
|
59
59
|
elsif ModuleOperateType::FINISH == module_operate_type
|
60
60
|
module_git = BigkeeperParser.module_git(module_name)
|
61
61
|
branch_name = GitOperator.new.current_branch(@path)
|
62
|
-
"#{$1}pod '#{module_name}
|
62
|
+
"#{$1}pod '#{module_name}', :git => '#{module_git}', :branch => '#{branch_name}'"
|
63
63
|
elsif ModuleOperateType::PUBLISH == module_operate_type
|
64
64
|
module_git = BigkeeperParser.module_git(module_name)
|
65
65
|
branch_name = GitOperator.new.current_branch(@path)
|
66
66
|
base_branch_name = GitflowType.base_branch(GitService.new.current_branch_type(@path))
|
67
|
-
"#{$1}pod '#{module_name}
|
67
|
+
"#{$1}pod '#{module_name}', :git => '#{module_git}', :branch => '#{base_branch_name}'"
|
68
68
|
elsif ModuleOperateType::RELEASE == module_operate_type
|
69
69
|
module_git = BigkeeperParser.module_git(module_name)
|
70
70
|
lastest_tag, is_spec = find_lastest_tag(module_name)
|
71
71
|
if is_spec == true
|
72
72
|
Logger.default("#{module_name} lastest tag is #{lastest_tag}, this tag has published.")
|
73
|
-
"#{$1}pod '#{module_name}
|
73
|
+
"#{$1}pod '#{module_name}', '#{lastest_tag}'"
|
74
74
|
else
|
75
75
|
Logger.default("#{module_name} lastest tag is #{lastest_tag}, this tag not publish.")
|
76
|
-
"#{$1}pod '#{module_name}
|
76
|
+
"#{$1}pod '#{module_name}', :git => '#{module_git}', :tag => '#{lastest_tag}'"
|
77
77
|
end
|
78
78
|
else
|
79
79
|
line
|
@@ -84,7 +84,7 @@ module BigKeeper
|
|
84
84
|
def origin_config_of_module(module_name)
|
85
85
|
origin_config = ''
|
86
86
|
|
87
|
-
File.open("#{@path}/.bigkeeper/Podfile", 'r'
|
87
|
+
File.open("#{@path}/.bigkeeper/Podfile", 'r') do |file|
|
88
88
|
file.each_line do |line|
|
89
89
|
if line =~ /(\s*)pod(\s*)('|")#{module_name}('|")([\s\S]*)/
|
90
90
|
origin_config = line
|
@@ -14,7 +14,7 @@ module BigKeeper
|
|
14
14
|
if !git.has_remote_branch(path, branch_name) && !git.has_local_branch(path, branch_name)
|
15
15
|
|
16
16
|
verify_special_branch(path, 'master')
|
17
|
-
verify_special_branch(path, 'develop')
|
17
|
+
#verify_special_branch(path, 'develop')
|
18
18
|
|
19
19
|
GitflowOperator.new.verify_git_flow(path)
|
20
20
|
|
@@ -114,9 +114,8 @@ module BigKeeper
|
|
114
114
|
def branchs_with_type(path, type)
|
115
115
|
branchs = []
|
116
116
|
Dir.chdir(path) do
|
117
|
-
IO.popen('git branch -
|
117
|
+
IO.popen('git branch -r') do | io |
|
118
118
|
io.each do | line |
|
119
|
-
branchs << line.gsub('\n', '') if line.include?('develop')
|
120
119
|
branchs << line.gsub(/\s/, '') if line =~ /[\s\S]*#{GitflowType.name(type)}*/
|
121
120
|
end
|
122
121
|
end
|
@@ -154,71 +154,6 @@ module BigKeeper
|
|
154
154
|
result_dic
|
155
155
|
end
|
156
156
|
|
157
|
-
def release_check_changed(path, user, module_name)
|
158
|
-
module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
|
159
|
-
|
160
|
-
git = GitOperator.new
|
161
|
-
if !File.exist? module_full_path
|
162
|
-
Logger.default("No local repository for module '#{module_name}', clone it...")
|
163
|
-
module_git = BigkeeperParser.module_git(module_name)
|
164
|
-
git.clone(File.expand_path("#{module_full_path}/../"), module_git)
|
165
|
-
end
|
166
|
-
GitService.new.verify_checkout_pull(module_full_path, 'develop')
|
167
|
-
git.check_remote_branch_diff(module_full_path, 'develop', 'master')
|
168
|
-
end
|
169
|
-
|
170
|
-
def release_start(path, user, modules, module_name, version)
|
171
|
-
module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
|
172
|
-
|
173
|
-
git = GitOperator.new
|
174
|
-
if !File.exist? module_full_path
|
175
|
-
Logger.default("No local repository for module '#{module_name}', clone it...")
|
176
|
-
module_git = BigkeeperParser.module_git(module_name)
|
177
|
-
git.clone(File.expand_path("#{module_full_path}/../"), module_git)
|
178
|
-
end
|
179
|
-
#stash module
|
180
|
-
StashService.new.stash(module_full_path, GitOperator.new.current_branch(module_full_path), module_name)
|
181
|
-
# delete cache
|
182
|
-
CacheOperator.new(module_full_path).clean()
|
183
|
-
# checkout develop
|
184
|
-
GitService.new.verify_checkout_pull(module_full_path, 'develop')
|
185
|
-
DepService.dep_operator(path, user).release_module_start(modules, module_name, version)
|
186
|
-
|
187
|
-
# Push home changes to remote
|
188
|
-
Logger.highlight("Push branch 'develop' for #{module_name}...")
|
189
|
-
GitService.new.verify_push(
|
190
|
-
module_full_path,
|
191
|
-
"release start for #{version}",
|
192
|
-
'develop',
|
193
|
-
"#{module_name}")
|
194
|
-
end
|
195
|
-
|
196
|
-
def release_finish(path, user, modules, module_name, version)
|
197
|
-
module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
|
198
|
-
|
199
|
-
git = GitOperator.new
|
200
|
-
if !File.exist? module_full_path
|
201
|
-
Logger.default("No local repository for module '#{module_name}', clone it...")
|
202
|
-
module_git = BigkeeperParser.module_git(module_name)
|
203
|
-
git.clone(File.expand_path("#{module_full_path}/../"), module_git)
|
204
|
-
end
|
205
|
-
#stash module
|
206
|
-
StashService.new.stash(module_full_path, GitOperator.new.current_branch(module_full_path), module_name)
|
207
|
-
# delete cache
|
208
|
-
CacheOperator.new(module_full_path).clean()
|
209
|
-
# checkout develop
|
210
|
-
GitService.new.verify_checkout_pull(module_full_path, 'develop')
|
211
|
-
DepService.dep_operator(path, user).release_module_finish(modules, module_name, version)
|
212
|
-
|
213
|
-
# Push home changes to remote
|
214
|
-
Logger.highlight("Push branch 'develop' for #{module_name}...")
|
215
|
-
GitService.new.verify_push(
|
216
|
-
module_full_path,
|
217
|
-
"release finish for #{version}",
|
218
|
-
'develop',
|
219
|
-
"#{module_name}")
|
220
|
-
end
|
221
|
-
|
222
157
|
private :verify_module
|
223
158
|
end
|
224
159
|
end
|
@@ -50,7 +50,7 @@ module BigKeeper
|
|
50
50
|
|
51
51
|
Logger.error("Can't find a Bigkeeper file in current directory.") if !FileOperator.definitely_exists?(bigkeeper)
|
52
52
|
|
53
|
-
content = File.read
|
53
|
+
content = File.read bigkeeper
|
54
54
|
content.gsub!(/version\s/, 'BigKeeper::version ')
|
55
55
|
content.gsub!(/user\s/, 'BigKeeper::user ')
|
56
56
|
content.gsub!(/home\s/, 'BigKeeper::home ')
|
@@ -219,22 +219,6 @@ 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
|
-
|
234
|
-
def self.module_version_alias(module_name)
|
235
|
-
@@config[:modules][module_name][:version_alias]
|
236
|
-
end
|
237
|
-
|
238
222
|
def self.module_pulls(module_name)
|
239
223
|
@@config[:modules][module_name][:pulls]
|
240
224
|
end
|
@@ -19,9 +19,7 @@ module BigKeeper
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def clean
|
22
|
-
|
23
|
-
FileUtils.rm_r(@cache_path)
|
24
|
-
end
|
22
|
+
FileUtils.rm_r(@cache_path)
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
@@ -32,8 +30,8 @@ module BigKeeper
|
|
32
30
|
FileUtils.mkdir_p(@cache_path) unless File.exist?(@cache_path)
|
33
31
|
|
34
32
|
if File.exist?("#{@cache_path}/module.cache")
|
35
|
-
file = File.open("#{@cache_path}/module.cache", 'r'
|
36
|
-
@modules = JSON.load(file.read()
|
33
|
+
file = File.open("#{@cache_path}/module.cache", 'r')
|
34
|
+
@modules = JSON.load(file.read())
|
37
35
|
file.close
|
38
36
|
else
|
39
37
|
@modules = {"git" => {"all" => [], "current" => []}, "path" => {"all" => [], "add" => [], "del" => [], "current" => []}}
|
@@ -110,7 +108,7 @@ module BigKeeper
|
|
110
108
|
end
|
111
109
|
|
112
110
|
def cache_modules
|
113
|
-
file = File.new("#{@cache_path}/module.cache", 'w'
|
111
|
+
file = File.new("#{@cache_path}/module.cache", 'w')
|
114
112
|
file << @modules.to_json
|
115
113
|
file.close
|
116
114
|
end
|
@@ -110,7 +110,7 @@ module BigKeeper
|
|
110
110
|
|
111
111
|
def discard(path)
|
112
112
|
Dir.chdir(path) do
|
113
|
-
`git checkout . && git clean -
|
113
|
+
`git checkout . && git clean -xdf`
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
@@ -127,14 +127,7 @@ module BigKeeper
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def user
|
130
|
-
|
131
|
-
cn_reg = /[\u4e00-\u9fa5]{1}/
|
132
|
-
cn_arr = name.scan(cn_reg)
|
133
|
-
if cn_arr.count > 0
|
134
|
-
Logger.error("git config user.name has Chinese character")
|
135
|
-
else
|
136
|
-
name.gsub(/[^0-9A-Za-z]/, '').downcase
|
137
|
-
end
|
130
|
+
`git config user.name`.chop
|
138
131
|
end
|
139
132
|
|
140
133
|
def tag(path, version)
|
@@ -181,22 +174,6 @@ module BigKeeper
|
|
181
174
|
end
|
182
175
|
end
|
183
176
|
|
184
|
-
def check_remote_branch_diff(path, branch, compare_branch)
|
185
|
-
fetch(path)
|
186
|
-
compare_branch_commits = Array.new
|
187
|
-
IO.popen("cd '#{path}';git log --left-right #{branch}...origin/#{compare_branch} --pretty=oneline") do |io|
|
188
|
-
io.each do |line|
|
189
|
-
compare_branch_commits.push(line) unless (line.include? '>') && (line.include? "Merge branch \'#{branch}\'")
|
190
|
-
end
|
191
|
-
end
|
192
|
-
if compare_branch_commits.size > 0
|
193
|
-
return true
|
194
|
-
else
|
195
|
-
return false
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
# TODO: 需要改造,util方法不应该有业务逻辑
|
200
177
|
def check_diff(path, branch, compare_branch)
|
201
178
|
compare_branch_commits = Array.new
|
202
179
|
IO.popen("cd '#{path}'; git log --left-right #{branch}...#{compare_branch} --pretty=oneline") do |io|
|
@@ -239,4 +216,6 @@ module BigKeeper
|
|
239
216
|
|
240
217
|
end
|
241
218
|
|
219
|
+
# p GitOperator.new.user
|
220
|
+
# BigStash::StashOperator.new("/Users/mmoaay/Documents/eleme/BigKeeperMain").list
|
242
221
|
end
|
@@ -0,0 +1,209 @@
|
|
1
|
+
require 'big_keeper/util/cache_operator'
|
2
|
+
|
3
|
+
module BigKeeper
|
4
|
+
# Operator for podfile
|
5
|
+
class GradleOperator
|
6
|
+
def initialize(path)
|
7
|
+
@path = path
|
8
|
+
end
|
9
|
+
|
10
|
+
def backup
|
11
|
+
cache_operator = CacheOperator.new(@path)
|
12
|
+
|
13
|
+
cache_operator.save('settings.gradle')
|
14
|
+
|
15
|
+
Dir.glob("#{@path}/*/build.gradle").each do |build_gradle_file_path|
|
16
|
+
build_gradle_file = build_gradle_file_path.gsub!(/#{@path}/, '')
|
17
|
+
cache_operator.save(build_gradle_file)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def recover(settings_config, build_config)
|
22
|
+
cache_operator = CacheOperator.new(@path)
|
23
|
+
|
24
|
+
cache_operator.load('settings.gradle') if settings_config
|
25
|
+
|
26
|
+
if build_config
|
27
|
+
Dir.glob("#{@path}/*/build.gradle").each do |build_gradle_file_path|
|
28
|
+
build_gradle_file = build_gradle_file_path.gsub!(/#{@path}/, '')
|
29
|
+
cache_operator.load(build_gradle_file)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
cache_operator.clean
|
34
|
+
end
|
35
|
+
|
36
|
+
def update_settings_config(current_module_name, modules, module_operate_type, user)
|
37
|
+
return if modules.empty?
|
38
|
+
|
39
|
+
if ModuleOperateType::ADD == module_operate_type
|
40
|
+
modules.each do |module_name|
|
41
|
+
next if current_module_name == module_name
|
42
|
+
|
43
|
+
File.open("#{@path}/settings.gradle", 'a') do |file|
|
44
|
+
file.puts "\r\ninclude ':module:#{module_name.downcase}'\r\n"
|
45
|
+
file.puts "project(':module:#{module_name.downcase}')." \
|
46
|
+
"projectDir = new File(rootProject.projectDir," \
|
47
|
+
"'#{BigkeeperParser.module_path(user, module_name)}/#{module_name.downcase}-lib')\r\n"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
else
|
51
|
+
modules.each do |module_name|
|
52
|
+
next if current_module_name == module_name
|
53
|
+
temp_file = Tempfile.new('.settings.gradle.tmp')
|
54
|
+
begin
|
55
|
+
File.open("#{@path}/settings.gradle", 'r') do |file|
|
56
|
+
file.each_line do |line|
|
57
|
+
unless line =~ /(\s*)include(\s*)('|")(\S*):#{module_name.downcase}('|")(\S*)/ ||
|
58
|
+
line =~ /(\s*)project\(('|")(\S*):#{module_name.downcase}('|")\).(\S*)/
|
59
|
+
temp_file.puts(line)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
temp_file.close
|
64
|
+
FileUtils.mv(temp_file.path, "#{@path}/settings.gradle")
|
65
|
+
ensure
|
66
|
+
temp_file.close
|
67
|
+
temp_file.unlink
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def update_build_config(current_module_name, modules, module_operate_type)
|
74
|
+
return if modules.empty?
|
75
|
+
|
76
|
+
Dir.glob("#{@path}/*/build.gradle").each do |file_path|
|
77
|
+
modules.each do |module_name|
|
78
|
+
next if current_module_name == module_name
|
79
|
+
|
80
|
+
temp_file = Tempfile.new('.build.gradle.tmp')
|
81
|
+
begin
|
82
|
+
version_flag = false
|
83
|
+
version_index = 0
|
84
|
+
|
85
|
+
File.open(file_path, 'r') do |file|
|
86
|
+
file.each_line do |line|
|
87
|
+
new_line, version_index, version_flag = generate_build_config(
|
88
|
+
line,
|
89
|
+
module_name,
|
90
|
+
module_operate_type,
|
91
|
+
version_index,
|
92
|
+
version_flag)
|
93
|
+
|
94
|
+
temp_file.puts(new_line)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
temp_file.close
|
98
|
+
FileUtils.mv(temp_file.path, file_path)
|
99
|
+
ensure
|
100
|
+
temp_file.close
|
101
|
+
temp_file.unlink
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def generate_build_config(line, module_name, module_operate_type, version_index, version_flag)
|
108
|
+
new_line = line
|
109
|
+
|
110
|
+
version_flag = true if line.downcase.include? 'modifypom'
|
111
|
+
if version_flag
|
112
|
+
version_index += 1 if line.include? '{'
|
113
|
+
version_index -= 1 if line.include? '}'
|
114
|
+
|
115
|
+
version_flag = false if 0 == version_flag
|
116
|
+
|
117
|
+
new_line = generate_version_config(line, module_name, module_operate_type)
|
118
|
+
else
|
119
|
+
new_line = generate_compile_config(line, module_name, module_operate_type)
|
120
|
+
end
|
121
|
+
|
122
|
+
[new_line, version_index, version_flag]
|
123
|
+
end
|
124
|
+
|
125
|
+
def generate_version_config(line, module_name, module_operate_type)
|
126
|
+
if ModuleOperateType::FINISH == module_operate_type || ModuleOperateType::PUBLISH == module_operate_type
|
127
|
+
branch_name = GitOperator.new.current_branch(@path)
|
128
|
+
full_name = ''
|
129
|
+
|
130
|
+
# Get version part of source.addition
|
131
|
+
if ModuleOperateType::PUBLISH == module_operate_type
|
132
|
+
full_name = branch_name.sub(/([\s\S]*)\/(\d+.\d+.\d+)_([\s\S]*)/){ $2 }
|
133
|
+
else
|
134
|
+
full_name = branch_name.sub(/([\s\S]*)\/([\s\S]*)/){ $2 }
|
135
|
+
end
|
136
|
+
|
137
|
+
line.sub(/(\s*)version ('|")(\S*)('|")([\s\S]*)/){
|
138
|
+
"#{$1}version '#{full_name}'#{$5}"
|
139
|
+
}
|
140
|
+
else
|
141
|
+
line
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def generate_compile_config(line, module_name, module_operate_type)
|
146
|
+
if ModuleOperateType::ADD == module_operate_type
|
147
|
+
line.sub(/(\s*)compile(\s*)('|")(\S*):#{module_name.downcase}:(\S*)('|")(\S*)/){
|
148
|
+
"#{$1}compile project(':module:#{module_name.downcase}')"
|
149
|
+
}
|
150
|
+
elsif ModuleOperateType::DELETE == module_operate_type
|
151
|
+
line.sub(/(\s*)([\s\S]*)('|")(\S*):#{module_name.downcase}:(\S*)('|")(\S*)/){
|
152
|
+
origin_config_of_module = origin_config_of_module(module_name)
|
153
|
+
if origin_config_of_module.empty?
|
154
|
+
line
|
155
|
+
else
|
156
|
+
origin_config_of_module
|
157
|
+
end
|
158
|
+
}
|
159
|
+
elsif ModuleOperateType::FINISH == module_operate_type || ModuleOperateType::PUBLISH == module_operate_type
|
160
|
+
branch_name = GitOperator.new.current_branch(@path)
|
161
|
+
full_name = ''
|
162
|
+
|
163
|
+
# Get version part of source.addition
|
164
|
+
if ModuleOperateType::PUBLISH == module_operate_type
|
165
|
+
full_name = branch_name.sub(/([\s\S]*)\/(\d+.\d+.\d+)_([\s\S]*)/){ $2 }
|
166
|
+
else
|
167
|
+
full_name = branch_name.sub(/([\s\S]*)\/([\s\S]*)/){ $2 }
|
168
|
+
end
|
169
|
+
line.sub(/(\s*)([\s\S]*)('|")(\S*):#{module_name.downcase}(:\S*)*('|")(\S*)/){
|
170
|
+
if $2.downcase.include? 'modulecompile'
|
171
|
+
"#{$1}moduleCompile '#{prefix_of_module(module_name)}:#{module_name.downcase}:#{full_name}-SNAPSHOT'"
|
172
|
+
else
|
173
|
+
"#{$1}compile '#{prefix_of_module(module_name)}:#{module_name.downcase}:#{full_name}-SNAPSHOT'"
|
174
|
+
end
|
175
|
+
}
|
176
|
+
else
|
177
|
+
line
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def origin_config_of_module(module_name)
|
182
|
+
origin_config = ''
|
183
|
+
|
184
|
+
Dir.glob("#{@path}/.bigkeeper/*/build.gradle").each do |file|
|
185
|
+
File.open(file, 'r') do |file|
|
186
|
+
file.each_line do |line|
|
187
|
+
if line =~ /(\s*)([\s\S]*)('|")(\S*):#{module_name.downcase}:(\S*)('|")(\S*)/
|
188
|
+
origin_config = line
|
189
|
+
break
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
break unless origin_config.empty?
|
194
|
+
end
|
195
|
+
|
196
|
+
origin_config.chop
|
197
|
+
end
|
198
|
+
|
199
|
+
def prefix_of_module(module_name)
|
200
|
+
origin_config = origin_config_of_module(module_name)
|
201
|
+
prefix = origin_config.sub(/(\s*)([\s\S]*)('|")(\S*)#{module_name.downcase}(\S*)('|")(\S*)/){
|
202
|
+
$4
|
203
|
+
}
|
204
|
+
prefix.chop
|
205
|
+
end
|
206
|
+
|
207
|
+
private :generate_build_config, :generate_compile_config, :generate_version_config, :origin_config_of_module, :prefix_of_module
|
208
|
+
end
|
209
|
+
end
|