class Sinicum::Runner::RunnerCli
Constants
- RUNNER_TMP_DIR
- SINICUM_ENV_NAME
- WEBAPP_BASE_DIR
Public Instance Methods
run(args)
click to toggle source
# File lib/sinicum-runner/runner_cli.rb, line 12 def run(args) parse_args(args) check_environment setup_directories build_webapp unless @options.skip_build start_tomcat unless @options.only_build end
Private Instance Methods
build_webapp()
click to toggle source
# File lib/sinicum-runner/runner_cli.rb, line 40 def build_webapp current_dir = FileUtils.pwd FileUtils.cd(magnolia_module_dir) run_command("#{SINICUM_ENV_NAME}=#{@options.environment} " + "mvn --batch-mode -Dmaven.test.skip=true clean package war:exploded") ensure FileUtils.cd(current_dir) end
check_environment()
click to toggle source
# File lib/sinicum-runner/runner_cli.rb, line 22 def check_environment check_for_file("pom.xml") check_for_file("Gemfile") check_for_file(File.join(magnolia_module_dir, "pom.xml")) end
check_for_file(file)
click to toggle source
# File lib/sinicum-runner/runner_cli.rb, line 32 def check_for_file(file) unless File.exists?(file) puts "Required file #{file} not found. Please check if you are running the command " + "from the Rails root directory." exit 1 end end
find_first_element(document, path)
click to toggle source
# File lib/sinicum-runner/runner_cli.rb, line 124 def find_first_element(document, path) element = nil document.elements.each(path) do |el| element = el break end unless element puts "No element with the path #{path} found pom.xml" exit 1 end element end
jar_location()
click to toggle source
# File lib/sinicum-runner/runner_cli.rb, line 65 def jar_location loc = "#{File.dirname(__FILE__)}/../java/sinicum-runner-#{runner_jar_version}.jar" File.expand_path(loc) end
magnolia_module_dir()
click to toggle source
# File lib/sinicum-runner/runner_cli.rb, line 78 def magnolia_module_dir unless @magnolia_module_dir pom = File.new("pom.xml") doc = REXML::Document.new(pom) @magnolia_module_dir = File.expand_path( find_first_element(doc, "/project/modules/module").text) end @magnolia_module_dir end
magnolia_module_name()
click to toggle source
# File lib/sinicum-runner/runner_cli.rb, line 92 def magnolia_module_name unless @magnolia_module_name pom = File.new(File.join(magnolia_module_dir, "pom.xml")) doc = REXML::Document.new(pom) @magnolia_module_name = find_first_element(doc, "/project/artifactId").text end @magnolia_module_name end
magnolia_module_version()
click to toggle source
# File lib/sinicum-runner/runner_cli.rb, line 101 def magnolia_module_version unless @magnolia_module_version pom = File.new(File.join(magnolia_module_dir, "pom.xml")) doc = REXML::Document.new(pom) element = find_first_element(doc, "/project/version") unless element find_first_element(doc, "/project/parent/version") end @magnolia_module_version = element.text end @magnolia_module_version end
parse_args(args)
click to toggle source
# File lib/sinicum-runner/runner_cli.rb, line 137 def parse_args(args) @options = Options.new(args) end
run_command(command, options = nil)
click to toggle source
# File lib/sinicum-runner/runner_cli.rb, line 141 def run_command(command, options = nil) if options ret_value = system(command, *options) else ret_value = system(command) end raise "Error running command '#{command}'" unless ret_value end
runner_dir()
click to toggle source
# File lib/sinicum-runner/runner_cli.rb, line 61 def runner_dir File.expand_path(RUNNER_TMP_DIR) end
runner_jar_version()
click to toggle source
# File lib/sinicum-runner/runner_cli.rb, line 70 def runner_jar_version unless @runner_jar_version @runner_jar_version = version_from_pom( File.join(File.dirname(__FILE__), "..", "..", "pom.xml")) end @runner_jar_version end
setup_directories()
click to toggle source
# File lib/sinicum-runner/runner_cli.rb, line 28 def setup_directories FileUtils.mkdir(runner_dir) unless File.exists?(runner_dir) end
start_tomcat()
click to toggle source
# File lib/sinicum-runner/runner_cli.rb, line 49 def start_tomcat options = [] options.concat(@options.to_jvm_options) options.concat(["-jar", jar_location, "--basedir", runner_dir, "--appbase", webapp_directory_path]) options.concat(@options.to_option_args) ret_value = system({ SINICUM_ENV_NAME => @options.environment }, "java", *options) puts "" exit 1 unless ret_value ret_value end
version_from_pom(path)
click to toggle source
# File lib/sinicum-runner/runner_cli.rb, line 114 def version_from_pom(path) version = nil if File.exists?(path) pom = File.new(path) doc = REXML::Document.new(pom) version = find_first_element(doc, "/project/version").text end version end
webapp_directory_path()
click to toggle source
# File lib/sinicum-runner/runner_cli.rb, line 88 def webapp_directory_path File.join(WEBAPP_BASE_DIR, @options.environment, @options.environment) end