class AppCommand::ReleaseBlufin

Private Class Methods

copy_blufin_java(path_blufin_java, path_blufin_java_framework, minify_exclude_file, minify_ignore_file, verbose = false, quick = false) click to toggle source

This method copies all of the blufin-java code into blufin-framework and performs various mutation/minification operations. @return void

# File lib/routes/release_blufin.rb, line 280
def self.copy_blufin_java(path_blufin_java, path_blufin_java_framework, minify_exclude_file, minify_ignore_file, verbose = false, quick = false)
    exclude_files = []
    Blufin::Files::read_file(minify_exclude_file).each { |line| exclude_files << line.strip } if Blufin::Files::file_exists(minify_exclude_file)
    ignore_files = []
    Blufin::Files::read_file(minify_ignore_file).each { |line| ignore_files << line.strip } if Blufin::Files::file_exists(minify_ignore_file)
    # Wipe out the framework path.
    system("cd #{path_blufin_java_framework} && rm -r ./* >/dev/null 2>&1")
    Blufin::Files::get_files_in_dir(path_blufin_java).each do |file|
        # Skip POM files and .gitignore.
        next if file.strip =~ /\/pom\.xml\s*$/
        next if file.strip =~ /^\.gitignore$/
        exclude = false
        exclude_files.each do |exclude_file|
            if file.strip =~ /(#{exclude_file.strip.gsub(/\*/, '')})/
                exclude = true
                break
            end
        end
        next if exclude
        ignore = false
        ignore_files.each do |ignore_file|
            if file.strip =~ /(#{ignore_file.strip.gsub(/\*/, '')})/
                ignore = true
                break
            end
        end
        file_split = file.split('/')
        unless file_split[6] == 'target'
            file_target = file.gsub(path_blufin_java, path_blufin_java_framework)
            begin
                if !ignore && !quick && file.strip =~ /\.java$/ && file !~ /src\/test\/java\// && file !~ /ebay/ && file !~ /blufin-blank/
                    puts "\x1B[38;5;246m#{file}\x1B[0m" if verbose
                    Blufin::Files::write_file(file_target, [])

                    # TODO - Put this somehwere more reliable, like possibly in the OPT folder...
                    unless system("java -jar ~/Repos/blufin/assets/bin/blufin-minifier-1.0.0.jar --in #{file} --out #{file_target} --mode compact > /dev/null 2>&1")
                        write_framework_file(file, file_target)
                    end

                else
                    puts "\x1B[38;5;240m#{file}\x1B[0m" if verbose
                    write_framework_file(file, file_target)
                end
            rescue
            end
        end
    end
end
remove_tests(path_blufin_java_framework, verbose = false) click to toggle source

This method removes all Tests from the blufin-framework repo. @return void

# File lib/routes/release_blufin.rb, line 331
def self.remove_tests(path_blufin_java_framework, verbose = false)
    Blufin::Files::get_dirs_in_dir(path_blufin_java_framework).each do |dir|
        test_directory = "#{dir}/src/test"
        puts "\x1B[38;5;198m  Removing:\x1B[0m \x1B[38;5;240m#{test_directory}\x1B[0m" if verbose
        system("rm -rf #{test_directory}") if Blufin::Files::path_exists(test_directory)
    end
end
write_framework_file(source_file, target_file, lines = nil) click to toggle source

Write a file without doing any conversions. @return void

# File lib/routes/release_blufin.rb, line 341
def self.write_framework_file(source_file, target_file, lines = nil)
    if lines.nil?
        lines = Blufin::Files::read_file(source_file)
        lines.map! { |n| n.gsub("\n", '') }
    end
    Blufin::Files::write_file(target_file, lines)
end

Public Instance Methods

execute() click to toggle source
# File lib/routes/release_blufin.rb, line 5
def execute


    begin

        @opts = command_options
        @args = arguments

        @threads = []

        @version_release = nil
        @version_current = '0.0.0'
        @version_color   = 33

        @path_blufin_aws            = Blufin::Config::get_path('Paths', 'BlufinAWS')
        @path_blufin_java           = Blufin::Config::get_path('Paths', 'BlufinJava')
        @path_blufin_java_labs      = Blufin::Config::get_path('Paths', 'BlufinJavaLabs')
        @path_blufin_java_framework = Blufin::Config::get_path('Paths', 'BlufinJavaFramework') # TODO - DEPRECATE THIS!
        @path_blufin_ruby           = Blufin::Config::get_path('Paths', 'BlufinRuby')
        @blufin_version_file        = "#{@path_blufin_ruby}/blufin/lib/version.rb"
        @blufin_java_version_file   = "#{@path_blufin_java}/maven.yml"
        @blufin_labs_version_file   = "#{@path_blufin_java_labs}/app-infrastructure/maven.yml"

        @minify_exclude_file = "#{@path_blufin_java}/minify-exclude.txt" # Does not copy across.
        @minify_ignore_file  = "#{@path_blufin_java}/minify-ignore.txt" # Copies across but does not alter file.

        opts_validate
        opts_routing

    rescue => e

        Blufin::Terminal::print_exception(e)

    end

end
opts_routing() click to toggle source
# File lib/routes/release_blufin.rb, line 111
def opts_routing

    begin

        # Get user to choose new version.
        # @version_release = prompt_for_new_version

        # Confirm new version.
        # Blufin::Terminal::prompt_yes_no("New Blufin version is   \x1B[38;5;240m\xe2\x86\x92\x1B[0m \x1B[38;5;#{@version_color}m#{@version_release}\x1B[0m")

        # Change all the versions on all the repos to the new one.
        # change_versions_on_files(@version_release)

        # Build blufin-java/blufin-labs to regenerate the POMs with new version.
        # execute_command('bf s g bf', @path_blufin_ruby)

        # Copy all the files from blufin-java to public repository. This performs minor obfuscation and minification.
        # Blufin::Terminal::execute_proc("Copying/obfuscating #{Blufin::Terminal::format_directory(@path_blufin_java)} to \xe2\x86\x92 #{Blufin::Terminal::format_directory(@path_blufin_java_framework)} (and removing tests).", Proc.new { |args|
        #     AppCommand::ReleaseBlufin::copy_blufin_java(@path_blufin_java, @path_blufin_java_framework, @minify_exclude_file, @minify_ignore_file)
        #     AppCommand::ReleaseBlufin::remove_tests(@path_blufin_java_framework)
        #     true
        # })

        # TODO - Writing POM files always includes blank + ebay...

        yml_java_pom_writer = Blufin::YmlJavaPomWriter.new(@yml_maven.data_blufin)
        yml_java_pom_writer.write_poms_blufin(@path_blufin_java_framework)

        # TODO - REMOVE
        # abort_the_mission(@path_blufin_aws, @path_blufin_java, @path_blufin_java_framework, @path_blufin_java_labs)

        exit

        Blufin::Files::get_dirs_in_dir(@path_blufin_java_framework).each do |path|

            mod      = path.split('/')[path.split('/').length - 1]
            mod_path = "#{@path_blufin_java_framework}/#{mod}"
            # mod_title = 'N/A'
            #
            # Blufin::Files::read_file("#{mod_path}/pom.xml").each do |line|
            #     if line =~ /^\s*<name>(.*)<\/name>\s*$/
            #         mod_title = line.gsub(/^\s*<name>/, '').gsub(/<\/name>\s*$/, '')
            #     end
            # end

            execute_command('mvn clean test', mod_path)

        end

        exit

            # TODO - Build the final validation screen first, so you know what to aim for...
            # Show final validation screen (after which is the point of no return).

            # Run -> git commit "Release: v1.0.0"
            # Run -> git tag v1.0.0

    rescue => e

        # TODO - Add Prompt.
        # abort_the_mission(@path_blufin_aws, @path_blufin_java, @path_blufin_java_framework, @path_blufin_java_labs)

        Blufin::Terminal::print_exception(e)

    end

end
opts_validate() click to toggle source
# File lib/routes/release_blufin.rb, line 42
def opts_validate

    system('clear')

    # TODO - Check Maven installed with version above 3.6
    # TODO - Check MySQL is running (required for integration testing)

    # TODO - Uncomment.
    [@path_blufin_aws,
    # @path_blufin_java,
    # @path_blufin_java_labs,
    # @path_blufin_java_framework,
    # @path_blufin_ruby
    ].each do |path|

        path = File.expand_path(path)
        Blufin::Terminal::error('Path does not exist', path, true) unless Blufin::Files::path_exists(path)
        git_status = Blufin::Terminal::command_capture('git status', path, false)[0]
        clean_repo = git_status.to_s == "On branch master\nYour branch is up to date with 'origin/master'.\n\nnothing to commit, working tree clean\n"
        Blufin::Terminal::error("#{Blufin::Terminal::format_directory(path)} is either not #{Blufin::Terminal::format_highlight('clean')} or not on #{Blufin::Terminal::format_highlight('master')}.", git_status.split("\n"), true) unless clean_repo

    end

    # Check that blufin-java/minify-exclude.txt file exists.
    exists_exclude = Blufin::Files::file_exists(@minify_exclude_file)
    exists_ignore  = Blufin::Files::file_exists(@minify_ignore_file)
    if !exists_exclude || !exists_ignore
        Blufin::Terminal::error('Files required for release process are missing:', [
            "#{exists_exclude ? "\x1B[38;5;46m  Found\x1B[0m" : "\x1B[38;5;196mMissing\x1B[0m"} \xe2\x86\x92 #{Blufin::Terminal::format_directory(@minify_exclude_file)}",
            "#{exists_ignore ? "\x1B[38;5;46m  Found\x1B[0m" : "\x1B[38;5;196mMissing\x1B[0m"} \xe2\x86\x92 #{Blufin::Terminal::format_directory(@minify_ignore_file)}"
        ], true)
    end

    # Gets Blufin Version from -> /Users/Albert/Repos/blufin/blufin/lib/version.rb
    blufin_version = get_blufin_version(@blufin_version_file)
    Blufin::Terminal::error("Could not extract valid version number from #{Blufin::Terminal::format_directory(@blufin_version_file)}", ["Found: #{blufin_version.inspect}"]) unless blufin_version =~ /^\d+\.\d+\.\d+(-SNAPSHOT)?$/i

    # Gets Blufin-Java Version from -> /Users/Albert/Repos/blufin-java/maven.yml
    blufin_java_version = get_blufin_java_version(@blufin_java_version_file)
    Blufin::Terminal::error("Could not extract valid version number from #{Blufin::Terminal::format_directory(@blufin_java_version_file)}", ["Found: #{blufin_java_version.inspect}"]) unless blufin_java_version =~ /^\d+\.\d+\.\d+(-SNAPSHOT)?$/i

    # Gets Blufin-Labs Version from -> /Users/Albert/Repos/repos-blufin/blufin-labs/app-infrastructure/maven.yml
    blufin_labs_version = get_blufin_java_version(@blufin_java_version_file)
    Blufin::Terminal::error("Could not extract valid version number from #{Blufin::Terminal::format_directory(@blufin_labs_version_file)}", ["Found: #{blufin_labs_version.inspect}"]) unless blufin_labs_version =~ /^\d+\.\d+\.\d+(-SNAPSHOT)?$/i

    dir_max_length = [@blufin_version_file.length, @blufin_java_version_file.length, @blufin_labs_version_file.length].max

    # Checks that all the versions are the same.
    Blufin::Terminal::error('Version mismatch:', [
        "#{Blufin::Terminal::format_directory(@blufin_version_file.ljust(dir_max_length, ' '))} \xe2\x86\x92 \x1B[38;5;#{@version_color}m#{blufin_version}\x1B[0m",
        "#{Blufin::Terminal::format_directory(@blufin_java_version_file.ljust(dir_max_length, ' '))} \xe2\x86\x92 \x1B[38;5;#{@version_color}m#{blufin_java_version}\x1B[0m",
        "#{Blufin::Terminal::format_directory(@blufin_labs_version_file.ljust(dir_max_length, ' '))} \xe2\x86\x92 \x1B[38;5;#{@version_color}m#{blufin_labs_version}\x1B[0m"
    ], true) unless [blufin_version, blufin_java_version, blufin_labs_version].uniq!.length == 1

    @version_current = blufin_version.gsub(/(-SNAPSHOT)?$/i, '')

    @site = Blufin::Site::DEFAULT_SITE

    # Must go first because it contains the most important configuration data.
    Blufin::SiteEmbedded::init(Blufin::ScannerJavaEmbeddedObjects::new(@site, @error_handler).get_data)

    @error_handler = Blufin::YmlErrorHandler.new(@site)

    @yml_maven = Blufin::YmlMavenValidator.new(@site, @error_handler)

    @error_handler.display_errors_if_any(true)

end

Private Instance Methods

abort_the_mission(path_blufin_aws, path_blufin_java, path_blufin_java_framework, path_blufin_java_labs) click to toggle source

If something goes wrong or we don't want to do the release, this will revert EVERYTHING! @return void

# File lib/routes/release_blufin.rb, line 235
def abort_the_mission(path_blufin_aws, path_blufin_java, path_blufin_java_framework, path_blufin_java_labs)
    Blufin::Terminal::info('Reverting the following repositories:', %w(blufin-aws blufin-java blufin-blufin-framework blufin-labs))
    # Blufin::Terminal::execute('git reset --hard HEAD', path_blufin_aws)
    Blufin::Terminal::execute('git reset --hard HEAD', path_blufin_java)
    # Blufin::Terminal::execute('git reset --hard HEAD', path_blufin_java_framework)
    Blufin::Terminal::execute('git reset --hard HEAD', path_blufin_java_labs)
end
change_versions_on_files(version) click to toggle source

Change all the places were the Blufin version is stored. @return void

# File lib/routes/release_blufin.rb, line 272
def change_versions_on_files(version)
    Blufin::Files::write_line_to_file(@blufin_version_file, "BLUFIN_VERSION = '#{version}'", /^\s*BLUFIN_VERSION\s*=\s*'0.0.0(-SNAPSHOT)?'\s*$/, false, true)
    Blufin::Files::write_line_to_file(@blufin_java_version_file, "    version: #{version}", /^\s+(version:)\s*#{@version_current}(-SNAPSHOT)?$/, false, true)
    Blufin::Files::write_line_to_file(@blufin_labs_version_file, "    version: #{version}", /^\s+(version:)\s*#{@version_current}(-SNAPSHOT)?$/, false, true)
end
execute_command(command, path) click to toggle source

Proxy function that bombs-out soon as an execution fails. @return void

# File lib/routes/release_blufin.rb, line 183
def execute_command(command, path)
    unless Blufin::Terminal::execute(command, path)
        Blufin::Terminal::error('Something went wrong.', 'Please look at above failures.', true)
    end
end
get_blufin_java_version(path_to_file) click to toggle source

Gets the version number from Blufin ruby gem. @return string

# File lib/routes/release_blufin.rb, line 257
def get_blufin_java_version(path_to_file)
    previous_was_blufin = false
    Blufin::Files::read_file(path_to_file).each do |line|
        line = line.strip
        if previous_was_blufin
            if line.strip.length > 0
                return line.gsub(/version:\s*/, '')
            end
        end
        previous_was_blufin = true if line =~ /blufin:/
    end
end
get_blufin_version(path_to_file) click to toggle source

Gets the version number from Blufin ruby gem. @return string

# File lib/routes/release_blufin.rb, line 245
def get_blufin_version(path_to_file)
    Blufin::Files::read_file(path_to_file).each do |line|
        if line.strip.length > 0
            line = line.gsub("BLUFIN_VERSION = '", '')
            line = line.chomp("'")
            return line
        end
    end
end
get_versions(current_version) click to toggle source

Calculate major, minor, point-release version numbers. @return array

# File lib/routes/release_blufin.rb, line 220
def get_versions(current_version)
    vs = current_version.split('.')
    raise RuntimeError, "Expected version parts to be 3, got: #{vs.length} (#{vs.inspect})" unless vs.length == 3
    mj = vs[0].to_i
    mn = vs[1].to_i
    pr = vs[2].to_i
    {
        :mj => "#{mj + 1}.0.0",
        :mn => "#{mj}.#{mn + 1}.0",
        :pr => "#{mj}.#{mn}.#{pr + 1}",
    }
end
prompt_for_new_version() click to toggle source

This prompts the user to select a new version number. @return void

# File lib/routes/release_blufin.rb, line 191
def prompt_for_new_version
    puts
    puts "     \x1B[38;5;240m Last Blufin release version was \xe2\x86\x92\x1B[0m \x1B[38;5;33m#{@version_current}\x1B[0m"
    puts
    version            = get_versions(@version_current)
    version_choices    = [
        "\x1B[38;5;198m1)\x1B[0m Bump major version            \xe2\x86\x92 \x1B[38;5;#{@version_color}m#{version[:mj]}\x1B[0m",
        "\x1B[38;5;198m2)\x1B[0m Bump minor version \x1B[38;5;246m(default)\x1B[0m  \xe2\x86\x92 \x1B[38;5;#{@version_color}m#{version[:mn]}\x1B[0m",
        "\x1B[38;5;198m3)\x1B[0m Bump point-release version    \xe2\x86\x92 \x1B[38;5;#{@version_color}m#{version[:pr]}\x1B[0m"
    ]
    validation_proc    = Proc.new { |value| %w(1 2 3).include?(value.to_s.upcase) || value.strip == '' }
    validation_message = "Value must either be \x1B[38;5;220m1, 2,\x1B[0m or \x1B[38;5;220m3\x1B[0m"
    version_chosen     = Blufin::Terminal::prompt_for_input('CHOOSE VERSION', 'Choose next Blufin release version:', version_choices, validation_proc, validation_message).to_s.upcase
    case version_chosen
        when '1'
            return version[:mj]
        when ''
            return version[:mn]
        when '2'
            return version[:mn]
        when '3'
            return version[:pr]
        else
            raise RuntimeError, "Could not determine version from user input: #{version_chosen}"
    end
end