jenkins-peace 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.pullreview.yml +8 -0
- data/.travis.yml +12 -0
- data/AUTHORS +2 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +8 -0
- data/LICENSE +19 -0
- data/README.md +69 -0
- data/Rakefile +28 -0
- data/bin/jenkins.peace +5 -0
- data/jenkins-peace.gemspec +29 -0
- data/lib/jenkins/peace.rb +133 -0
- data/lib/jenkins/peace/cli.rb +91 -0
- data/lib/jenkins/peace/console_logger.rb +34 -0
- data/lib/jenkins/peace/content_downloader.rb +71 -0
- data/lib/jenkins/peace/thor_extensions.rb +86 -0
- data/lib/jenkins/peace/version.rb +5 -0
- data/lib/jenkins/peace/war_file.rb +151 -0
- data/lib/jenkins_peace.rb +7 -0
- data/spec/lib/console_logger_spec.rb +33 -0
- data/spec/lib/content_downloader_spec.rb +81 -0
- data/spec/lib/jenkins_peace_spec.rb +194 -0
- data/spec/lib/thor_extensions_spec.rb +101 -0
- data/spec/lib/war_file_spec.rb +156 -0
- data/spec/spec_helper.rb +43 -0
- metadata +161 -0
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Jenkins::Peace::ThorExtensions do
|
4
|
+
|
5
|
+
VALID_LIST = [[
|
6
|
+
"\e[32m1.629\e[0m",
|
7
|
+
File.join(ENV['HOME'], '.jenkins', 'war-files', '1.629', 'jenkins.war'),
|
8
|
+
File.join(ENV['HOME'], '.jenkins', 'wars', '1.629', 'WEB-INF', 'lib', 'jenkins-core-1.629.jar'),
|
9
|
+
"\e[31mfalse\e[0m"
|
10
|
+
]]
|
11
|
+
|
12
|
+
|
13
|
+
def build_klass
|
14
|
+
klass = Class.new(Thor)
|
15
|
+
klass.send(:include, Jenkins::Peace::ThorExtensions)
|
16
|
+
klass.new([])
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:helper) { build_klass }
|
20
|
+
|
21
|
+
|
22
|
+
describe '.green' do
|
23
|
+
it 'should render green message' do
|
24
|
+
allow_any_instance_of(Thor::Shell::Color).to receive(:can_display_colors?).and_return(true)
|
25
|
+
expect(helper.green('foo')).to eq "\e[32mfoo\e[0m"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
describe '.red' do
|
31
|
+
it 'should render red message' do
|
32
|
+
allow_any_instance_of(Thor::Shell::Color).to receive(:can_display_colors?).and_return(true)
|
33
|
+
expect(helper.red('bar')).to eq "\e[31mbar\e[0m"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
describe '.bold' do
|
39
|
+
it 'should render bold message' do
|
40
|
+
allow_any_instance_of(Thor::Shell::Color).to receive(:can_display_colors?).and_return(true)
|
41
|
+
expect(helper.bold('boo')).to eq "\e[1mboo\e[0m"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
describe '.formated_headers' do
|
47
|
+
it 'should render colored headers' do
|
48
|
+
allow_any_instance_of(Thor::Shell::Color).to receive(:can_display_colors?).and_return(true)
|
49
|
+
expect(helper.formated_headers).to eq ["\e[1mVersion\e[0m", "\e[1mLocation\e[0m", "\e[1mClasspath\e[0m", "\e[1mInstalled\e[0m"]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
describe '.download_it_first!' do
|
55
|
+
it 'should display help message' do
|
56
|
+
expect(helper).to receive(:say).with("War file doesn't exist, you should install it first with : jenkins.peace install <version>", :yellow)
|
57
|
+
expect(helper).to receive(:say).with('Exiting !', :yellow)
|
58
|
+
helper.download_it_first!
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
describe '.yes_no_question' do
|
64
|
+
describe 'should ask question to user' do
|
65
|
+
context 'when answer is yes' do
|
66
|
+
it 'should continue' do
|
67
|
+
expect(helper).to receive(:yes?).with('ok?', :bold).and_return(true)
|
68
|
+
expect(helper).to receive(:say).with('Done !', :green)
|
69
|
+
helper.yes_no_question('ok?')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when answer is no' do
|
74
|
+
it 'should stop' do
|
75
|
+
expect(helper).to receive(:yes?).with('ok?', :bold).and_return(false)
|
76
|
+
expect(helper).to receive(:say).with('Canceled !', :yellow)
|
77
|
+
helper.yes_no_question('ok?')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
describe '.formated_war_files_list' do
|
85
|
+
context 'when no wars file are installed' do
|
86
|
+
it 'should return an empty array' do
|
87
|
+
expect_any_instance_of(Jenkins::Peace).to receive(:all_war_files).and_return([])
|
88
|
+
expect(helper.formated_war_files_list).to eq []
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'when wars file are installed' do
|
93
|
+
it 'should return a formated war files list (an array of array)' do
|
94
|
+
allow_any_instance_of(Thor::Shell::Color).to receive(:can_display_colors?).and_return(true)
|
95
|
+
expect(Jenkins::Peace).to receive(:list).and_return([Jenkins::Peace.build_war_file('1.629')])
|
96
|
+
expect(helper.formated_war_files_list).to eq VALID_LIST
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Jenkins::Peace::WarFile do
|
4
|
+
|
5
|
+
def build_war_file(version)
|
6
|
+
Jenkins::Peace.build_war_file(version)
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
def base_dir
|
11
|
+
File.join(WAR_FILES_CACHE, '1.630')
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def lib_dir
|
16
|
+
File.join(WAR_UNPACKED_CACHE, '1.630')
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def location
|
21
|
+
File.join(WAR_FILES_CACHE, '1.630', 'jenkins.war')
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def classpath
|
26
|
+
File.join(WAR_UNPACKED_CACHE, '1.630', 'WEB-INF/lib/jenkins-core-1.630.jar')
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def url
|
31
|
+
'http://mirrors.jenkins-ci.org/war/1.630/jenkins.war'
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
let(:war_file) { build_war_file('1.630') }
|
36
|
+
|
37
|
+
it { expect(war_file.base_dir).to eq base_dir }
|
38
|
+
it { expect(war_file.lib_dir).to eq lib_dir }
|
39
|
+
it { expect(war_file.location).to eq location }
|
40
|
+
it { expect(war_file.classpath).to eq classpath }
|
41
|
+
it { expect(war_file.url).to eq url }
|
42
|
+
it { expect(war_file.file_name).to eq 'jenkins.war' }
|
43
|
+
|
44
|
+
|
45
|
+
describe '#latest_version?' do
|
46
|
+
it 'should return true if version is latest' do
|
47
|
+
war_file = build_war_file('latest')
|
48
|
+
expect(war_file.latest_version?).to be true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
describe '#real_version' do
|
54
|
+
context 'when version is numeric' do
|
55
|
+
it 'should return the real version' do
|
56
|
+
war_file = build_war_file('1.630')
|
57
|
+
expect(war_file.real_version).to eq '1.630'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when version is latest' do
|
62
|
+
it 'should return the real version' do
|
63
|
+
war_file = build_war_file('latest')
|
64
|
+
expect(war_file).to receive(:find_core_librairy).and_return('jenkins-core-1.631.jar')
|
65
|
+
expect(war_file.real_version).to eq '1.631'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
describe '#install!' do
|
72
|
+
it 'should install war file' do
|
73
|
+
expect(war_file).to receive(:download!)
|
74
|
+
expect(war_file).to receive(:unpack!)
|
75
|
+
war_file.install!
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
describe '#download!' do
|
81
|
+
it 'should download war file' do
|
82
|
+
expect(FileUtils).to receive(:mkdir_p).with(base_dir)
|
83
|
+
expect(war_file).to receive(:fetch_content).with(url, location)
|
84
|
+
war_file.download!
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
describe '#remove!' do
|
90
|
+
it 'should remove war file' do
|
91
|
+
expect(FileUtils).to receive(:rm_rf).with(base_dir)
|
92
|
+
expect(FileUtils).to receive(:rm_rf).with(lib_dir)
|
93
|
+
war_file.remove!
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
describe '#unpack!' do
|
99
|
+
it 'should unpack war file' do
|
100
|
+
expect(FileUtils).to receive(:mkdir_p).with(lib_dir)
|
101
|
+
expect(war_file).to receive(:execute_command).with("cd #{lib_dir} && jar xvf #{location}")
|
102
|
+
war_file.unpack!
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
describe '#exists?' do
|
108
|
+
it 'should return true if war file exists' do
|
109
|
+
expect(File).to receive(:exists?).with(location)
|
110
|
+
war_file.exists?
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
describe '#unpacked?' do
|
116
|
+
it 'should return true if war file has been unpacked' do
|
117
|
+
expect(File).to receive(:exists?).with(lib_dir).and_return(true)
|
118
|
+
expect(File).to receive(:exists?).with(classpath)
|
119
|
+
war_file.unpacked?
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
describe '#installed?' do
|
125
|
+
it 'should return true if war file has been installed' do
|
126
|
+
expect(war_file).to receive(:exists?).and_return(true)
|
127
|
+
expect(war_file).to receive(:unpacked?)
|
128
|
+
war_file.installed?
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
describe '#build_command_line' do
|
134
|
+
it 'should return the command line to start the server' do
|
135
|
+
expect(FileUtils).to receive(:mkdir_p)
|
136
|
+
expect(war_file.build_command_line).to eq SERVER_COMMAND_LINE
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
describe '#start!' do
|
142
|
+
it 'should start the Jenkins server' do
|
143
|
+
expect(FileUtils).to receive(:mkdir_p)
|
144
|
+
expect(war_file).to receive(:exec).with(*SERVER_COMMAND_LINE)
|
145
|
+
war_file.start!
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'when kill option is passed' do
|
149
|
+
it 'should send 0 on socket' do
|
150
|
+
expect(TCPSocket).to receive(:open).with('localhost', 4000)
|
151
|
+
war_file.start!(kill: true, control: 4000)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'simplecov'
|
3
|
+
require 'rspec'
|
4
|
+
require 'codeclimate-test-reporter'
|
5
|
+
require 'pullreview/coverage_reporter'
|
6
|
+
|
7
|
+
## Configure SimpleCov
|
8
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
9
|
+
SimpleCov::Formatter::HTMLFormatter,
|
10
|
+
CodeClimate::TestReporter::Formatter,
|
11
|
+
PullReview::Coverage::Formatter
|
12
|
+
])
|
13
|
+
|
14
|
+
## Start Simplecov
|
15
|
+
SimpleCov.start do
|
16
|
+
add_filter '/spec/'
|
17
|
+
end
|
18
|
+
|
19
|
+
## Configure RSpec
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.color = true
|
22
|
+
config.fail_fast = false
|
23
|
+
config.expect_with :rspec do |c|
|
24
|
+
c.syntax = :expect
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
ENV['RACK_ENV'] = 'test'
|
29
|
+
require 'jenkins_peace'
|
30
|
+
|
31
|
+
JENKINS_WAR_URL = 'http://mirrors.jenkins-ci.org/war/'
|
32
|
+
BASE_PATH = File.join(ENV['HOME'], '.jenkins')
|
33
|
+
WAR_FILES_CACHE = File.join(ENV['HOME'], '.jenkins', 'war-files')
|
34
|
+
WAR_UNPACKED_CACHE = File.join(ENV['HOME'], '.jenkins', 'wars')
|
35
|
+
SERVER_PATH = File.join(ENV['HOME'], '.jenkins', 'server')
|
36
|
+
SERVER_COMMAND_LINE = [
|
37
|
+
'java',
|
38
|
+
"-Djava.io.tmpdir=#{File.join(SERVER_PATH, 'javatmp')}",
|
39
|
+
'-jar',
|
40
|
+
File.join(WAR_FILES_CACHE, '1.630', 'jenkins.war'),
|
41
|
+
'--httpPort=3001',
|
42
|
+
'--controlPort=3002'
|
43
|
+
]
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jenkins-peace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicolas Rodriguez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
name: rake
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
name: thor
|
34
|
+
prerelease: false
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
name: tty-table
|
48
|
+
prerelease: false
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
name: ruby-progressbar
|
62
|
+
prerelease: false
|
63
|
+
type: :runtime
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
name: rspec
|
76
|
+
prerelease: false
|
77
|
+
type: :development
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
name: simplecov
|
90
|
+
prerelease: false
|
91
|
+
type: :development
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Download and install a specific version of the Jenkins war file which can be used for either running a server, or for plugin development
|
98
|
+
email:
|
99
|
+
- nrodriguez@jbox-web.com
|
100
|
+
executables:
|
101
|
+
- jenkins.peace
|
102
|
+
extensions:
|
103
|
+
- Rakefile
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- ".gitignore"
|
107
|
+
- ".pullreview.yml"
|
108
|
+
- ".travis.yml"
|
109
|
+
- AUTHORS
|
110
|
+
- CHANGELOG.md
|
111
|
+
- Gemfile
|
112
|
+
- LICENSE
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- bin/jenkins.peace
|
116
|
+
- jenkins-peace.gemspec
|
117
|
+
- lib/jenkins/peace.rb
|
118
|
+
- lib/jenkins/peace/cli.rb
|
119
|
+
- lib/jenkins/peace/console_logger.rb
|
120
|
+
- lib/jenkins/peace/content_downloader.rb
|
121
|
+
- lib/jenkins/peace/thor_extensions.rb
|
122
|
+
- lib/jenkins/peace/version.rb
|
123
|
+
- lib/jenkins/peace/war_file.rb
|
124
|
+
- lib/jenkins_peace.rb
|
125
|
+
- spec/lib/console_logger_spec.rb
|
126
|
+
- spec/lib/content_downloader_spec.rb
|
127
|
+
- spec/lib/jenkins_peace_spec.rb
|
128
|
+
- spec/lib/thor_extensions_spec.rb
|
129
|
+
- spec/lib/war_file_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
homepage: http://jbox-web.github.io/jenkins-peace/
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.4.8
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Fetch and use a specific Jenkins version with Rubygems
|
155
|
+
test_files:
|
156
|
+
- spec/lib/console_logger_spec.rb
|
157
|
+
- spec/lib/content_downloader_spec.rb
|
158
|
+
- spec/lib/jenkins_peace_spec.rb
|
159
|
+
- spec/lib/thor_extensions_spec.rb
|
160
|
+
- spec/lib/war_file_spec.rb
|
161
|
+
- spec/spec_helper.rb
|