25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/routes/scripts_pom_fixer.rb', line 25
def fix_poms
command = "find #{ Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE)} -name 'pom.xml'"
files = Brightpearl::Terminal::command_capture(command)
files = files[0].split("\n")
unless files.any?
Brightpearl::Terminal::error('No files found', ["The command: #{Brightpearl::Terminal::format_command(command)} didn't return any files.", 'It might be possible that the directory structure of our codebase has changed and this script needs to be updated.', nil, "Speak to #{Brightpearl::Terminal::format_highlight('Albert')}."], true)
end
files_to_change = []
files.each do |filename|
file_lines = File.open(filename, 'rb').read
file_lines.split("\n").each do |line|
if line.match(/<version>\d+\.\d+\.\d+-(.*)-(snapshot)<\/version>/i)
files_to_change << filename
end
end
end
unless files_to_change.any?
Brightpearl::Terminal::info('No feature-tagged POMs found', 'Nothing to un-snapshot.')
exit
end
unless Brightpearl::Terminal::prompt_yes_no('Un-snapshot POMs', generate_confirmation_text(files_to_change))
Brightpearl::Terminal::abort(nil, nil, true, false)
end
files_to_change.each do |filename|
Brightpearl::Terminal::output("Un-snapshotting: #{Brightpearl::Terminal::format_directory(filename)}")
contents = File.read(filename)
contents_new = contents.gsub(/-(.*)-SNAPSHOT/, '-SNAPSHOT')
File.open(filename, 'w') { |file| file.puts contents_new }
end
Brightpearl::Terminal::command('git status', Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE))
commit_message = "BP-0000 Un-snapshotted POMs on #{@git.current_branch_for_repo(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE))}."
if Brightpearl::Terminal::prompt_yes_no('Commit to GIT', ["This will commit your changes to GIT with message: #{Brightpearl::Terminal::format_highlight(commit_message)}"])
Brightpearl::Terminal::command(['git add .', "git commit -m '#{commit_message.gsub("'", "\\'")}'"], Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE))
else
Brightpearl::Terminal::info('Un-snapshotting complete', "Please note that your changes #{Brightpearl::Terminal::format_highlight('HAVE NOT')} been #{Brightpearl::Terminal::format_action('committed')} to Git.", false)
exit
end
if Brightpearl::Terminal::prompt_yes_no('Push changes to origin')
Brightpearl::Terminal::command('git push', Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE))
Brightpearl::Terminal::info('Un-snapshotting complete', "Your POMs have been un-snapshotted, the changes #{Brightpearl::Terminal::format_action('committed')} to Git and #{Brightpearl::Terminal::format_action('pushed')} to origin.")
else
Brightpearl::Terminal::info('Un-snapshotting complete', ["Your POMs have been un-snapshotted and the changes #{Brightpearl::Terminal::format_action('committed')} to Git.", 'However, nothing has been pushed to origin. You will need to do this manually.'], false)
end
end
|