Maven migration (first draft)

This commit is contained in:
Graham Triggs 2015-11-19 23:47:41 +00:00
parent da79ac3e1d
commit fee48b0b50
1711 changed files with 662 additions and 0 deletions

View file

@ -0,0 +1,141 @@
=begin
--------------------------------------------------------------------------------
Check for the required parameters of base directory, username, email address,
revision label and candidate label.
Offer to run the licenser to be sure that we are ready to go.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
=end
$: << File.dirname(File.expand_path(__FILE__))
require '_common'
#
# ------------------------------------------------------------------------------------
# Runs the licenser against both VIVO and Vitro, and shows the results.
# ------------------------------------------------------------------------------------
#
class LicenserCaller
def call_licenser(property_file)
properties = PropertyFileReader.read(property_file)
l = Licenser.new(properties)
l.process
l.report(properties)
return l.success?
end
def initialize()
require "#{Settings.vitro_path}/utilities/licenser/licenser"
require "#{Settings.vitro_path}/utilities/licenser/property_file_reader"
puts "Scanning VIVO..."
vivo_success = call_licenser("#{Settings.vivo_path}/config/licenser/licenser.properties")
puts "Scanning Vitro..."
vitro_success = call_licenser("#{Settings.vitro_path}/webapp/config/licenser/licenser.properties")
if vivo_success && vitro_success
puts "Licenser was successful"
else
puts "Licenser found problems"
end
end
end
#
# Show the current value of the setting, ask for a replacement value, validate it, and set it.
#
def do_setting(getter, validator, setter, label, format="a string")
v1 = getter.call
currently = v1.empty? ? "Currently not set" : "Currently '#{v1}'"
v2 = prompt "#{label}?\n(#{format})\n(#{currently})"
v2 = v1 if v2.empty?
v2 = validator.call(v2)
if v2.empty?
raise InputException.new("Can't run without #{label}")
elsif v1 == v2
puts "Keeping #{label} as '#{v2}'"
puts
else
puts "Setting #{label} to '#{v2}'"
setter.call(v2)
puts
end
v2
end
def get_base_directory()
do_setting(
Settings.method(:base_directory),
Settings.method(:confirm_base_directory),
Settings.method(:base_directory=),
"Git base directory",
"holds Vitro and VIVO repositories")
end
def get_user_name()
do_setting(
Settings.method(:username),
Settings.method(:confirm_username),
Settings.method(:username=),
"Git user.name")
end
def get_email()
do_setting(
Settings.method(:email),
Settings.method(:confirm_email),
Settings.method(:email=),
"Git user.email")
end
def get_release_label()
do_setting(
Settings.method(:release_label),
Settings.method(:confirm_release_label),
Settings.method(:release_label=),
"Release label",
"like '3.2' or '3.2.1'")
end
def get_candidate_label()
do_setting(
Settings.method(:candidate_label),
Settings.method(:confirm_candidate_label),
Settings.method(:candidate_label=),
"Release candidate label",
"like 'rc1' or 'tc3' or 'final'")
end
def run_licenser()
puts "It's a good idea to check the licenses before proceeding."
yn = prompt "Ready to run the licenser? (y/n)"
if (yn.downcase == 'y')
LicenserCaller.new()
else
puts "OK - forget it."
end
end
#
# ------------------------------------------------------------------------------------
# Main method
# ------------------------------------------------------------------------------------
#
begin
get_base_directory()
get_user_name()
get_email()
get_release_label()
get_candidate_label()
run_licenser()
rescue BadState
puts
puts "#{$!.message} - Aborting."
puts
end

View file

@ -0,0 +1,52 @@
=begin
--------------------------------------------------------------------------------
Get the branch name.
If either repository already contains the branch, complain.
Otherwise, pull develop to the latest commit and create the branches. Don't push.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
=end
$: << File.dirname(File.expand_path(__FILE__))
require '_common'
#
# Create a branch by this name in this repository.
#
def create_branch(dir, branch)
Dir.chdir(dir) do |path|
approve_and_execute([
"git checkout develop",
"git pull",
"git checkout -b #{branch}"
], "in #{path}")
end
end
#
# ------------------------------------------------------------------------------------
# Main method
# ------------------------------------------------------------------------------------
#
begin
branch = Settings.branch_name
vivo_path = Settings.vivo_path
vitro_path = Settings.vitro_path
raise BadState.new("Branches are not created for test candidates.") if is_test_candidate?()
raise BadState.new("Branch #{branch} already exists in VIVO.") if branch_exists?(vivo_path, branch)
raise BadState.new("Branch #{branch} already exists in Vitro.") if branch_exists?(vitro_path, branch)
get_permission_and_go("OK to create branches named '#{branch}'?") do
puts "Creating branches"
create_branch(vivo_path, branch)
create_branch(vitro_path, branch)
end
rescue BadState
puts "#{$!.message} - Aborting."
end

View file

@ -0,0 +1,58 @@
=begin
--------------------------------------------------------------------------------
Get the branch name and the tag name.
If either repository doesn't contain the branch, complain.
If either repository already contains the tag, complain.
Otherwise, Checkout the branch, pull the branch to the latest commit (if it is
tracking a remote branch) and create the tag. Don't push.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
=end
$: << File.dirname(File.expand_path(__FILE__))
require '_common'
#
# Create a tag by this name in this repository.
#
def create_tag(dir, branch, tag, message)
Dir.chdir(dir) do |path|
cmds = ["git checkout #{branch}",
"git pull",
"git tag -a #{tag} -m '#{message}'"
]
cmds.delete_at(1) unless remote_branch_exists?(path, branch)
approve_and_execute(cmds, "in #{path}")
end
end
#
# ------------------------------------------------------------------------------------
# Main method
# ------------------------------------------------------------------------------------
#
begin
branch = Settings.branch_name
tag = Settings.tag_name
message = Settings.tag_message
vivo_path = Settings.vivo_path
vitro_path = Settings.vitro_path
raise BadState.new("Branch #{branch} doesn't exist in VIVO.") unless branch_exists?(vivo_path, branch)
raise BadState.new("Branch #{branch} doesn't exist in Vitro.") unless branch_exists?(vitro_path, branch)
raise BadState.new("Tag #{tag} already exists in VIVO.") if tag_exists?(vivo_path, tag)
raise BadState.new("Tag #{tag} already exists in Vitro.") if tag_exists?(vitro_path, tag)
get_permission_and_go("OK to create tags named '#{tag}' '#{message}'?") do
puts "Creating tags"
create_tag(vivo_path, branch, tag, message)
create_tag(vitro_path, branch, tag, message)
end
rescue BadState
puts "#{$!.message} - Aborting."
end

View file

@ -0,0 +1,78 @@
=begin
--------------------------------------------------------------------------------
Get the tag name.
If either repository doesn't contain the tag, complain.
Otherwise, checkout the tag, copy the files to an appropriate area.
The files are specified so hidden files will not be copied, but this only works
at the top levels. So the .git directories are omitted, as well as some Eclipse
artifacts and Mac OS artifacts. However, this only works at the top levels.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
=end
$: << File.dirname(File.expand_path(__FILE__))
require '_common'
#
# Get the VIVO files and the Vitro files, and remove the .git directories.
#
def export_files(vivo_path, vitro_path, tag, branch, export_dir)
Dir.chdir(vivo_path) do |path|
cmds = ["git checkout #{branch}",
"git pull",
]
cmds.delete_at(1) unless remote_branch_exists?(path, branch)
approve_and_execute(cmds, "in #{path}")
end
Dir.chdir(vitro_path) do |path|
cmds = ["git checkout #{branch}",
"git pull",
]
cmds.delete_at(1) unless remote_branch_exists?(path, branch)
approve_and_execute(cmds, "in #{path}")
end
approve_and_execute([
"rm -Rf #{File.expand_path("..", export_dir)}",
"mkdir -pv #{export_dir}",
"cp -R #{vivo_path}/* #{export_dir}",
"mkdir -pv #{export_dir}/vitro-core",
"cp -R #{vitro_path}/* #{export_dir}/vitro-core",
])
end
#
# ------------------------------------------------------------------------------------
# Main method
# ------------------------------------------------------------------------------------
#
begin
tag = Settings.tag_name
branch = Settings.branch_name
vivo_path = Settings.vivo_path
vitro_path = Settings.vitro_path
export_dir = Settings.export_dir
raise BadState.new("Tag #{tag} doesn't exist in VIVO.") unless tag_exists?(vivo_path, tag)
raise BadState.new("Tag #{tag} doesn't exist in Vitro.") unless tag_exists?(vitro_path, tag)
if File.directory?(export_dir)
p = "OK to overwrite export area at #{export_dir} ?"
else
p = "OK to create export area at #{export_dir} ?"
end
get_permission_and_go(p) do
puts "Building export area"
export_files(vivo_path, vitro_path, tag, branch, export_dir)
end
rescue BadState
puts "#{$!.message} - Aborting."
end

View file

@ -0,0 +1,62 @@
=begin
--------------------------------------------------------------------------------
Figure the revision info and store it in the export directory, for both VIVO
and Vitro.
If the tags don't exist in either repository, or if the export directory is not
populated, complain.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
=end
$: << File.dirname(File.expand_path(__FILE__))
require '_common'
#
# Get the revision information from Git and store it in the export directory.
#
def create_revision_info(git_path, info_file_path, tag)
Dir.chdir(git_path) do |path|
commit = `git show-ref --tags --hash=7 #{tag}`.strip
puts "Writing '#{tag} ~ #{commit}' to #{info_file_path}"
File.open(info_file_path, "w") do |f|
f.puts tag
f.puts commit
end
end
end
#
# ------------------------------------------------------------------------------------
# Main method
# ------------------------------------------------------------------------------------
#
begin
tag = Settings.tag_name
vivo_path = Settings.vivo_path
vitro_path = Settings.vitro_path
export_dir = Settings.export_dir
vivo_revision_info_path = Settings.vivo_revision_info_path
vitro_revision_info_path = Settings.vitro_revision_info_path
raise BadState.new("Tag #{tag} doesn't exist in VIVO.") unless tag_exists?(vivo_path, tag)
raise BadState.new("Tag #{tag} doesn't exist in Vitro.") unless tag_exists?(vitro_path, tag)
raise BadState.new("Files have not been exported to #{export_dir}") unless File.directory?(export_dir)
if File.exist?(vivo_revision_info_path) || File.exist?(vitro_revision_info_path)
p = "OK to overwrite revision_info at these paths? \n #{vivo_revision_info_path} \n #{vitro_revision_info_path} ?"
else
p = "OK to write revision_info at these paths? \n #{vivo_revision_info_path} \n #{vitro_revision_info_path} ?"
end
get_permission_and_go(p) do
puts "Building revision info"
create_revision_info(vivo_path, vivo_revision_info_path, tag)
create_revision_info(vitro_path, vitro_revision_info_path, tag)
end
rescue BadState
puts "#{$!.message} - Aborting."
end

View file

@ -0,0 +1,15 @@
=begin
--------------------------------------------------------------------------------
Create PDF versions of the Installation Instructions and the Upgrade Guide,
from the VIVONEXT Wiki space.
Store them in the docs directory.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
=end
puts "-------------------------------------------------------------------"
puts " Not automated yet. Get Installation and Upgrade PDFs and put "
puts " them into the /doc directory. "
puts "-------------------------------------------------------------------"

View file

@ -0,0 +1,60 @@
=begin
--------------------------------------------------------------------------------
Create TAR and ZIP files for both VIVO and Vitro.
Complain if the files have not been exported, or the revision info doesn't exist.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
=end
$: << File.dirname(File.expand_path(__FILE__))
require '_common'
#
# Zip up the VIVO distribution. Extract the Vitro distribution and zip that.
#
def create_distribution_files(export_dir, vivo_filename, vitro_filename)
export_parent_dir = File.dirname(export_dir)
Dir.chdir(export_parent_dir) do |path|
cmds = [
"cp -r #{vivo_filename}/vitro-core #{vitro_filename}",
"zip -rq #{vivo_filename}.zip #{vivo_filename}",
"tar -czf #{vivo_filename}.tar.gz #{vivo_filename}",
"zip -rq #{vitro_filename}.zip #{vitro_filename}",
"tar -czf #{vitro_filename}.tar.gz #{vitro_filename}"
]
cmds.insert(0, "rm -r #{vitro_filename}") if File.exist?(vitro_filename)
approve_and_execute(cmds)
end
end
#
# ------------------------------------------------------------------------------------
# Main method
# ------------------------------------------------------------------------------------
#
begin
tag = Settings.tag_name
vivo_path = Settings.vivo_path
vitro_path = Settings.vitro_path
export_dir = Settings.export_dir
vivo_revision_info_path = Settings.vivo_revision_info_path
vitro_revision_info_path = Settings.vitro_revision_info_path
vivo_filename = Settings.vivo_distribution_filename
vitro_filename = Settings.vitro_distribution_filename
raise BadState.new("Files have not been exported to #{export_dir}") unless File.directory?(export_dir)
raise BadState.new("Revision information file does not exist at #{vivo_revision_info_path}") unless File.exist?(vivo_revision_info_path)
raise BadState.new("Revision information file does not exist at #{vitro_revision_info_path}") unless File.exist?(vitro_revision_info_path)
get_permission_and_go("OK to create distribution files in #{export_dir} ?") do
puts "Creating distribution files"
create_distribution_files(export_dir, vivo_filename, vitro_filename)
end
rescue BadState
puts "#{$!.message} - Aborting."
end

View file

@ -0,0 +1,57 @@
=begin
--------------------------------------------------------------------------------
Merge the maintenance branches into the master branchs, and create the final
release tags.
This will only work if the release candidate is "final", and if the maintenance
branches already exist.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
=end
$: << File.dirname(File.expand_path(__FILE__))
require '_common'
#
# Merge the maintenance branch to the master branch and create the tag.
#
def merge_branch_to_master(branch, tag, message, repo_path)
Dir.chdir(repo_path) do |path|
cmds = [
"git checkout master",
"git merge --no-ff -Xtheirs #{branch}",
"git tag -a -f #{tag} -m '#{message}'"
]
cmds.insert(0, "git branch master origin/master") unless branch_exists?(path, "master")
approve_and_execute(cmds, "in #{path}")
end
end
#
# ------------------------------------------------------------------------------------
# Main method
# ------------------------------------------------------------------------------------
#
begin
branch = Settings.branch_name
candidate_label = Settings.confirm_candidate_label(Settings.candidate_label)
tag = Settings.tag_name
message = Settings.tag_message
vivo_path = Settings.vivo_path
vitro_path = Settings.vitro_path
raise BadState.new("Only the final release gets merged to the master branch.") unless candidate_label == "final"
raise BadState.new("Branch #{branch} doesn't exist in VIVO.") unless branch_exists?(vivo_path, branch)
raise BadState.new("Branch #{branch} doesn't exist in Vitro.") unless branch_exists?(vitro_path, branch)
get_permission_and_go("OK to merge the #{tag} tags to the master branches?") do
puts "Merging tags"
merge_branch_to_master(branch, tag, message, vivo_path)
merge_branch_to_master(branch, tag, message, vitro_path)
end
rescue BadState
puts "#{$!.message} - Aborting."
end

View file

@ -0,0 +1,39 @@
=begin
--------------------------------------------------------------------------------
Push any branches, tags, or merges back to GitHub.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
=end
$: << File.dirname(File.expand_path(__FILE__))
require '_common'
#
# Merge the maintenance branch to the master branch and create the tag.
#
def push_to_origin(repo_path)
Dir.chdir(repo_path) do |path|
approve_and_execute(["git push --all", "git push --tags"], "in #{path}")
end
end
#
# ------------------------------------------------------------------------------------
# Main method
# ------------------------------------------------------------------------------------
#
begin
vivo_path = Settings.vivo_path
vitro_path = Settings.vitro_path
get_permission_and_go("OK to push changes to the origin?") do
puts "Merging tags"
push_to_origin(vivo_path)
push_to_origin(vitro_path)
end
rescue BadState
puts "#{$!.message} - Aborting."
end

View file

@ -0,0 +1,260 @@
=begin
--------------------------------------------------------------------------------
Methods and classes used by the scripts.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
=end
#
# ------------------------------------------------------------------------------------
# This exception class says that we aren't happy with the state of things.
# ------------------------------------------------------------------------------------
#
class BadState < Exception
end
#
# ------------------------------------------------------------------------------------
# A class with methods for handling the settings.
# ------------------------------------------------------------------------------------
#
class Settings
#
# The settings themselves: getters, setters, and validators.
#
def self.base_directory
`git config --get --global vivo.release.basedirectory`.strip
end
def self.base_directory=(dir)
`git config --global vivo.release.basedirectory #{dir}`
end
def self.confirm_base_directory(path)
expanded = File.expand_path(path)
vivo_git = File.expand_path("VIVO/.git", expanded)
vitro_git = File.expand_path("Vitro/.git", expanded)
raise BadState.new("#{expanded} is not a directory") unless File.directory?(expanded)
raise BadState.new("#{expanded} doesn't contain a VIVO repository") unless File.directory?(vivo_git)
raise BadState.new("#{expanded} doesn't contain a Vitro repository") unless File.directory?(vitro_git)
expanded
end
def self.username
`git config --get --global user.name`.strip
end
def self.username=(name)
`git config --global user.name #{name}`
end
def self.confirm_username(name)
# any string will do.
name
end
def self.email
`git config --get --global user.email`.strip
end
def self.email=(address)
`git config --global user.email #{address}`
end
def self.confirm_email(address)
# any string will do.
address
end
def self.release_label
`git config --get --global vivo.releaselabel`.strip
end
def self.release_label=(label)
`git config --global vivo.releaselabel #{label}`
end
def self.confirm_release_label(label)
raise BadState.new("Incorrect format for release label - '#{label}'") unless label =~ /^\d\.\d(\.\d)?$/
label
end
def self.candidate_label
`git config --get --global vivo.candidatelabel`.strip
end
def self.candidate_label=(label)
`git config --global vivo.candidatelabel #{label}`
end
def self.confirm_candidate_label(label)
raise BadState.new("Incorrect format for candidate label - '#{label}'") unless label =~ /^(rc\d+|tc\d+|final)$/
label
end
#
# Values derived from the settings.
#
# The name of the maintenance branch. Looks like "maint-rel-4.2" even for releases like "4.2.1"
# Test candidates for major releases are built on the develop branch.
def self.branch_name
if is_test_candidate?()
"develop"
else
release_label = Settings.confirm_release_label(Settings.release_label)
major_release = release_label[0..2]
"maint-rel-#{major_release}"
end
end
# The name of the Git tag. Looks like "rel-1.9-tc2" or "rel-1.9" (for final)
def self.tag_name
release_label = Settings.confirm_release_label(Settings.release_label)
label = Settings.confirm_candidate_label(Settings.candidate_label)
suffix = label == "final" ? "" : "-#{label}"
"rel-#{release_label}#{suffix}"
end
# The message for the Git tag. Looks like "Release 1.9 rc5 tag"
def self.tag_message
release_label = Settings.confirm_release_label(Settings.release_label)
candidate_label = Settings.confirm_candidate_label(Settings.candidate_label)
"Release #{release_label} #{candidate_label} tag"
end
# Where is the local VIVO repository? Looks like "/Users/jeb228/git/VIVO"
def self.vivo_path
base_directory = Settings.confirm_base_directory(Settings.base_directory)
File.expand_path("VIVO", base_directory)
end
# Where is the local Vitro repository? Looks like "/Users/jeb228/git/Vitro"
def self.vitro_path
base_directory = Settings.confirm_base_directory(Settings.base_directory)
File.expand_path("Vitro", base_directory)
end
# Where will the distribution files be created? Looks like "/Users/jeb228/git/release_4.9/tc5/vivo-rel-4.9-tc5"
def self.export_dir
base_directory = Settings.confirm_base_directory(Settings.base_directory)
release_label = Settings.confirm_release_label(Settings.release_label)
candidate_label = Settings.confirm_candidate_label(Settings.candidate_label)
tag_name = Settings.tag_name
File.expand_path("release_#{release_label}/#{candidate_label}/vivo-#{tag_name}", base_directory)
end
# Where to store the file for revision info in VIVO
def self.vivo_revision_info_path
File.expand_path("revisionInfo", Settings.export_dir)
end
# Where to store the file for revision info in VIVO
def self.vitro_revision_info_path
File.expand_path("vitro-core/revisionInfo", Settings.export_dir)
end
# Looks like "vivo-rel-4.9-tc3" or "vivo-rel-4.9" for final
def self.vivo_distribution_filename
"vivo-#{Settings.tag_name}"
end
# Looks like "vitro-rel-4.9-tc3" or "vitro-rel-4.9" for final
def self.vitro_distribution_filename
"vitro-#{Settings.tag_name}"
end
end
#
# ------------------------------------------------------------------------------------
# Confirmation methods.
# ------------------------------------------------------------------------------------
#
def is_test_candidate?()
Settings.confirm_candidate_label(Settings.candidate_label)[0..0] == 't'
end
def is_final_release?()
Settings.confirm_candidate_label(Settings.candidate_label) == 'final'
end
#
# ------------------------------------------------------------------------------------
# General-purpose methods.
# ------------------------------------------------------------------------------------
#
def prompt(p)
print("#{p} ")
gets.strip
end
def echo_command(c)
puts ">>>>>> #{c}"
`#{c}`
end
def get_permission_and_go(p)
puts
yn = prompt("#{p} (y/n)")
if yn.downcase == 'y'
puts
yield
puts
else
puts
puts "OK - forget it."
puts
end
end
def approve_and_execute(cmds, prompt="")
if prompt.empty?
puts "Execute these commands?"
else
puts "Execute these commands? (#{prompt})"
end
puts ">>>>> #{cmds.join("\n>>>>> ")}"
yn = prompt "(y/n)"
raise BadState.new("OK") if (yn.downcase != 'y')
cmds.each do |cmd|
puts ">>>>> #{cmd}"
puts `#{cmd}`
raise BadState.new("Command failed: code #{$?.exitstatus}") unless $?.success?
end
puts
end
def branch_exists?(dir, branch)
Dir.chdir(dir) do |path|
re = Regexp.new("\\b#{branch}\\b")
`git branch`.index(re)
end
end
def remote_branch_exists?(dir, branch)
Dir.chdir(dir) do |path|
re = Regexp.new("remotes/origin/#{branch}\\b")
`git branch -a`.index(re)
end
end
def tag_exists?(dir, tag)
Dir.chdir(dir) do |path|
re = Regexp.new("^#{tag}$")
`git tag`.index(re)
end
end