Class: Jenkins::Peace::WarFile
- Inherits:
-
Object
- Object
- Jenkins::Peace::WarFile
- Defined in:
- lib/jenkins/peace/war_file.rb
Constant Summary collapse
- JENKINS_VERSION_REGEX =
/jenkins-core-(1\.\d{3}).jar/
Instance Attribute Summary collapse
-
#base_dir ⇒ Object
readonly
Returns the value of attribute base_dir.
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#klass_path ⇒ Object
readonly
Returns the value of attribute klass_path.
-
#lib_dir ⇒ Object
readonly
Returns the value of attribute lib_dir.
-
#lib_path ⇒ Object
readonly
Returns the value of attribute lib_path.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#plugins_path ⇒ Object
readonly
Returns the value of attribute plugins_path.
-
#server_path ⇒ Object
readonly
Returns the value of attribute server_path.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #build_command_line(options = {}) ⇒ Object
- #classpath ⇒ Object
- #download! ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(version, opts = {}) ⇒ WarFile
constructor
A new instance of WarFile.
- #install! ⇒ Object
- #installed? ⇒ Boolean
- #latest_version? ⇒ Boolean
- #real_version ⇒ Object
- #remove! ⇒ Object
- #start!(options = {}) ⇒ Object
- #unpack! ⇒ Object
- #unpacked? ⇒ Boolean
Constructor Details
#initialize(version, opts = {}) ⇒ WarFile
Returns a new instance of WarFile.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jenkins/peace/war_file.rb', line 25 def initialize(version, opts = {}) @version = version @lib_path = opts.fetch(:lib_path, '') @base_path = opts.fetch(:base_path, '') @base_url = opts.fetch(:base_url, '') @server_path = opts.fetch(:server_path, '') @logger = opts.fetch(:logger, $stdout) @file_name = 'jenkins.war' @base_dir = File.join(base_path, version) @lib_dir = File.join(lib_path, version) @klass_path = File.join(lib_dir, '**/*.jar') @plugins_path = File.join(lib_dir, 'WEB-INF', 'plugins') @location = File.join(base_dir, file_name) @url = File.join(base_url, version, file_name) end |
Instance Attribute Details
#base_dir ⇒ Object (readonly)
Returns the value of attribute base_dir.
17 18 19 |
# File 'lib/jenkins/peace/war_file.rb', line 17 def base_dir @base_dir end |
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
11 12 13 |
# File 'lib/jenkins/peace/war_file.rb', line 11 def base_path @base_path end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
12 13 14 |
# File 'lib/jenkins/peace/war_file.rb', line 12 def base_url @base_url end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
16 17 18 |
# File 'lib/jenkins/peace/war_file.rb', line 16 def file_name @file_name end |
#klass_path ⇒ Object (readonly)
Returns the value of attribute klass_path.
19 20 21 |
# File 'lib/jenkins/peace/war_file.rb', line 19 def klass_path @klass_path end |
#lib_dir ⇒ Object (readonly)
Returns the value of attribute lib_dir.
18 19 20 |
# File 'lib/jenkins/peace/war_file.rb', line 18 def lib_dir @lib_dir end |
#lib_path ⇒ Object (readonly)
Returns the value of attribute lib_path.
10 11 12 |
# File 'lib/jenkins/peace/war_file.rb', line 10 def lib_path @lib_path end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
21 22 23 |
# File 'lib/jenkins/peace/war_file.rb', line 21 def location @location end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
14 15 16 |
# File 'lib/jenkins/peace/war_file.rb', line 14 def logger @logger end |
#plugins_path ⇒ Object (readonly)
Returns the value of attribute plugins_path.
20 21 22 |
# File 'lib/jenkins/peace/war_file.rb', line 20 def plugins_path @plugins_path end |
#server_path ⇒ Object (readonly)
Returns the value of attribute server_path.
13 14 15 |
# File 'lib/jenkins/peace/war_file.rb', line 13 def server_path @server_path end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
22 23 24 |
# File 'lib/jenkins/peace/war_file.rb', line 22 def url @url end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
9 10 11 |
# File 'lib/jenkins/peace/war_file.rb', line 9 def version @version end |
Instance Method Details
#build_command_line(options = {}) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/jenkins/peace/war_file.rb', line 112 def build_command_line( = {}) home = .fetch(:home, server_path) port = .fetch(:port, 3001).to_i control = .fetch(:control, 3002).to_i daemon = .fetch(:daemon, false) logfile = .fetch(logfile, nil) java_tmp = File.join(home, 'javatmp') FileUtils.mkdir_p java_tmp ENV['HUDSON_HOME'] = home cmd = ['java', "-Djava.io.tmpdir=#{java_tmp}", '-jar', location] cmd << '--daemon' if daemon cmd << "--httpPort=#{port}" cmd << "--controlPort=#{control}" cmd << "--logfile=#{File.(logfile)}" if logfile cmd end |
#classpath ⇒ Object
55 56 57 |
# File 'lib/jenkins/peace/war_file.rb', line 55 def classpath File.join(lib_dir, 'WEB-INF', 'lib', "jenkins-core-#{real_version}.jar") end |
#download! ⇒ Object
75 76 77 78 |
# File 'lib/jenkins/peace/war_file.rb', line 75 def download! FileUtils.mkdir_p base_dir fetch_content(url, location) end |
#exists? ⇒ Boolean
60 61 62 |
# File 'lib/jenkins/peace/war_file.rb', line 60 def exists? File.exists?(location) end |
#install! ⇒ Object
81 82 83 84 |
# File 'lib/jenkins/peace/war_file.rb', line 81 def install! download! unpack! end |
#installed? ⇒ Boolean
70 71 72 |
# File 'lib/jenkins/peace/war_file.rb', line 70 def installed? exists? && unpacked? end |
#latest_version? ⇒ Boolean
43 44 45 |
# File 'lib/jenkins/peace/war_file.rb', line 43 def latest_version? version == 'latest' end |
#real_version ⇒ Object
48 49 50 51 52 |
# File 'lib/jenkins/peace/war_file.rb', line 48 def real_version return version unless latest_version? klass = find_core_librairy klass.nil? ? nil : klass.match(JENKINS_VERSION_REGEX)[1] end |
#remove! ⇒ Object
87 88 89 90 |
# File 'lib/jenkins/peace/war_file.rb', line 87 def remove! FileUtils.rm_rf base_dir FileUtils.rm_rf lib_dir end |
#start!(options = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/jenkins/peace/war_file.rb', line 99 def start!( = {}) control = .fetch(:control, 3002).to_i kill = .fetch(:kill, false) if kill TCPSocket.open('localhost', control) { |sock| sock.write('0') } else command = build_command_line() exec(*command) end end |
#unpack! ⇒ Object
93 94 95 96 |
# File 'lib/jenkins/peace/war_file.rb', line 93 def unpack! FileUtils.mkdir_p(lib_dir) execute_command("cd #{lib_dir} && jar xvf #{location}") end |
#unpacked? ⇒ Boolean
65 66 67 |
# File 'lib/jenkins/peace/war_file.rb', line 65 def unpacked? File.exists?(lib_dir) && File.exists?(classpath) end |