jenkins-peace 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83adb7855da16bf2491e373d1f1a63eb7246ace0
4
+ data.tar.gz: 68800057f45f6e45ffc3a3b66d6a85ff1ac008c1
5
+ SHA512:
6
+ metadata.gz: b4259c305059ff23b05ef402e3db85c98cc2ac806a01052a41c5d021a968779d27c5cc38cfecf9a20eed5fdfb3f6d6bcf87e30df44959c6849c85e1e94b544aa
7
+ data.tar.gz: f8b7108210e1ddb0426f863eab337689b31598fe17cf036b995a8c483b1b4adc032205d47a9c0f9807345e14c06cefeec2e2e54295c3bb0803ca884125f65187
@@ -0,0 +1,3 @@
1
+ /*.gem
2
+ /*.lock
3
+ /coverage
@@ -0,0 +1,8 @@
1
+ ---
2
+ rules:
3
+ ignore:
4
+ - extra_blank_line_detected
5
+ - missing_class_documentation
6
+ - missing_method_documentation
7
+ - use_a_logger
8
+ - reduce_number_of_params
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ script: bundle exec rake spec
5
+ rvm:
6
+ - 2.3.1
7
+ - 2.2.5
8
+ - jruby-1.7.20
9
+ - jruby-9.0.5.0
10
+ env:
11
+ global:
12
+ - JRUBY_OPTS="--debug"
data/AUTHORS ADDED
@@ -0,0 +1,2 @@
1
+ Charles Lowell <cowboyd@thefrontside.net>
2
+ Nicolas Rodriguez <nrodriguez@jbox-web.com>
@@ -0,0 +1,5 @@
1
+ ## CHANGELOG
2
+
3
+ ### 1.0.0 - 2015-09-19
4
+
5
+ First release!
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'codeclimate-test-reporter', require: false
7
+ gem 'pullreview-coverage', require: false
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ The MIT License (MIT)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,69 @@
1
+ ## Jenkins ~~War~~ Peace
2
+
3
+ [![GitHub license](https://img.shields.io/github/license/jbox-web/jenkins-peace.svg)](https://github.com/jbox-web/jenkins-peace/blob/master/LICENSE)
4
+ [![GitHub release](https://img.shields.io/github/release/jbox-web/jenkins-peace.svg)](https://github.com/jbox-web/jenkins-peace/releases/latest)
5
+ [![Gem](https://img.shields.io/gem/v/jenkins-peace.svg)](https://rubygems.org/gems/jenkins-peace/versions/1.0.0)
6
+ [![Gem](https://img.shields.io/gem/dtv/jenkins-peace.svg)](https://rubygems.org/gems/jenkins-peace/versions/1.0.0)
7
+ [![Build Status](https://travis-ci.org/jbox-web/jenkins-peace.svg?branch=master)](https://travis-ci.org/jbox-web/jenkins-peace)
8
+ [![Code Climate](https://codeclimate.com/github/jbox-web/jenkins-peace/badges/gpa.svg)](https://codeclimate.com/github/jbox-web/jenkins-peace)
9
+ [![Test Coverage](https://codeclimate.com/github/jbox-web/jenkins-peace/badges/coverage.svg)](https://codeclimate.com/github/jbox-web/jenkins-peace/coverage)
10
+ [![Dependency Status](https://gemnasium.com/jbox-web/jenkins-peace.svg)](https://gemnasium.com/jbox-web/jenkins-peace)
11
+ [![PullReview stats](https://www.pullreview.com/github/jbox-web/jenkins-peace/badges/master.svg?)](https://www.pullreview.com/github/jbox-web/jenkins-peace/reviews/master)
12
+
13
+ ### A small console application to manage Jenkins war files, easy, and in peace ;)
14
+
15
+ This gem aims to replace [jenkins-war](https://rubygems.org/gems/jenkins-war/versions/1.514) to manage Jenkins war files.
16
+
17
+ The previous version of this gem used to embed the war file directly in the GitHub repo which could lead to very long download time.
18
+
19
+ This one uses a cache directory to store Jenkins war files (```/<home directory>/.jenkins/war-files```).
20
+
21
+
22
+ ## Installation
23
+
24
+ ```ruby
25
+ gem install jenkins-peace
26
+ ```
27
+
28
+ No need to add it to your Gemfile, it will be globally available.
29
+
30
+ ## Usage
31
+
32
+ ```sh
33
+ Commands:
34
+ jenkins.peace clean # Remove all war files
35
+ jenkins.peace download <version> # Download war file corresponding to version passed in params
36
+ jenkins.peace help [COMMAND] # Describe available commands or one specific command
37
+ jenkins.peace infos # Display infos about this gem
38
+ jenkins.peace install <version> # Install war file corresponding to version passed in params (will download then unpack war file)
39
+ jenkins.peace latest # Display infos about the latest version of war file installed
40
+ jenkins.peace list # List war files installed
41
+ jenkins.peace remove <version> # Remove war file corresponding to version passed in params
42
+ jenkins.peace server <version> # Start a server with the war file corresponding to version passed in params
43
+ jenkins.peace unpack <version> # Unpack war file corresponding to version passed in params
44
+ ```
45
+
46
+ ## Example
47
+
48
+ ```sh
49
+ nicolas@desktop:~$ jenkins.peace list
50
+ +------------------+-------------------------------------------------------+-------------------------------------------------------------------------+-------------+
51
+ | Version | Location | Classpath | Installed |
52
+ +------------------+-------------------------------------------------------+-------------------------------------------------------------------------+-------------+
53
+ | latest (1.629) | /home/nicolas/.jenkins/war-files/latest/jenkins.war | /home/nicolas/.jenkins/wars/latest/WEB-INF/lib/jenkins-core-1.629.jar | true |
54
+ | 1.628 | /home/nicolas/.jenkins/war-files/1.628/jenkins.war | /home/nicolas/.jenkins/wars/1.628/WEB-INF/lib/jenkins-core-1.628.jar | true |
55
+ +------------------+-------------------------------------------------------+-------------------------------------------------------------------------+-------------+
56
+ ```
57
+
58
+ ## Contributors
59
+
60
+ A big thank to [them](https://github.com/jbox-web/jenkins-peace/blob/master/AUTHORS) for their contribution!
61
+
62
+ ## Contribute
63
+
64
+ You can contribute to this plugin in many ways such as :
65
+
66
+ * Helping with documentation
67
+ * Contributing code (features or bugfixes)
68
+ * Reporting a bug
69
+ * Submitting translations
@@ -0,0 +1,28 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake'
5
+ require 'rspec/core/rake_task'
6
+
7
+ desc 'Start unit tests'
8
+ task test: :spec
9
+ task :spec do
10
+ RSpec::Core::RakeTask.new(:spec) do |config|
11
+ config.rspec_opts = '--color'
12
+ end
13
+ Rake::Task['spec'].invoke
14
+ end
15
+
16
+ desc 'Install latest Jenkins war file'
17
+ task default: :prepare
18
+ task :prepare do
19
+ begin
20
+ require 'bundler/setup'
21
+ require 'jenkins_peace'
22
+ Jenkins::Peace::ConsoleLogger.new().info("Installing Jenkins war file version : 'latest'")
23
+ Jenkins::Peace.install('latest')
24
+ Jenkins::Peace::ConsoleLogger.new().info('Done !')
25
+ rescue
26
+ puts "Failed to install Jenkins war, you'll have to install it yourself with 'jenkins.peace install <version>'"
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'jenkins_peace'
4
+
5
+ Jenkins::Peace::CLI.start(ARGV)
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'jenkins/peace/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'jenkins-peace'
7
+ s.version = Jenkins::Peace::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Nicolas Rodriguez']
10
+ s.email = ['nrodriguez@jbox-web.com']
11
+ s.homepage = 'http://jbox-web.github.io/jenkins-peace/'
12
+ s.summary = %q{Fetch and use a specific Jenkins version with Rubygems}
13
+ s.description = %q{Download and install a specific version of the Jenkins war file which can be used for either running a server, or for plugin development}
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.extensions = ['Rakefile']
20
+ s.require_paths = ['lib']
21
+
22
+ s.add_runtime_dependency 'rake'
23
+ s.add_runtime_dependency 'thor'
24
+ s.add_runtime_dependency 'tty-table'
25
+ s.add_runtime_dependency 'ruby-progressbar'
26
+
27
+ s.add_development_dependency 'rspec'
28
+ s.add_development_dependency 'simplecov'
29
+ end
@@ -0,0 +1,133 @@
1
+ require 'pathname'
2
+
3
+ module Jenkins
4
+ module Peace
5
+ extend self
6
+
7
+ def jenkins_war_url
8
+ 'http://mirrors.jenkins-ci.org/war/'
9
+ end
10
+
11
+
12
+ def base_path
13
+ File.join(ENV['HOME'], '.jenkins')
14
+ end
15
+
16
+
17
+ def war_files_cache
18
+ File.join(base_path, 'war-files')
19
+ end
20
+
21
+
22
+ def war_unpacked_cache
23
+ File.join(base_path, 'wars')
24
+ end
25
+
26
+
27
+ def server_path
28
+ File.join(base_path, 'server')
29
+ end
30
+
31
+
32
+ def infos
33
+ {
34
+ jenkins_war_url: jenkins_war_url,
35
+ base_path: base_path,
36
+ war_files_cache: war_files_cache,
37
+ war_unpacked_cache: war_unpacked_cache,
38
+ server_path: server_path
39
+ }
40
+ end
41
+
42
+
43
+ def latest_war_file
44
+ return nil if all_war_files_as_object.empty?
45
+ all_war_files_as_object.select { |f| f.installed? }.first
46
+ end
47
+
48
+
49
+ def latest_version
50
+ latest_war_file ? latest_war_file.classpath : nil
51
+ end
52
+
53
+
54
+ def list
55
+ all_war_files_as_object
56
+ end
57
+
58
+
59
+ def download(version, overwrite = false, url = nil)
60
+ war_file = build_war_file(version, url)
61
+ war_file = check_for_presence_and_execute(war_file, :download!, overwrite)
62
+ war_file
63
+ end
64
+
65
+
66
+ def install(version, overwrite = false, url = nil)
67
+ war_file = build_war_file(version, url)
68
+ war_file = check_for_presence_and_execute(war_file, :install!, overwrite)
69
+ war_file
70
+ end
71
+
72
+
73
+ def unpack(version, overwrite = false)
74
+ war_file = build_war_file(version)
75
+ war_file = check_for_presence_and_execute(war_file, :unpack!, overwrite)
76
+ war_file
77
+ end
78
+
79
+
80
+ def remove(version)
81
+ war_file = build_war_file(version)
82
+ war_file.remove! if war_file.exists?
83
+ war_file
84
+ end
85
+
86
+
87
+ def clean!
88
+ all_war_files_as_object.map(&:remove!)
89
+ end
90
+
91
+
92
+ def build_war_file(version, url = nil)
93
+ options = build_war_file_options
94
+ options = options.merge(base_url: url) unless url.nil?
95
+ WarFile.new(version, options)
96
+ end
97
+
98
+
99
+ def all_war_files
100
+ FileUtils.mkdir_p war_files_cache unless File.exists?(war_files_cache)
101
+ Pathname.new(war_files_cache).children.select { |c| c.directory? }
102
+ end
103
+
104
+
105
+ def check_for_presence_and_execute(war_file, method, overwrite = false)
106
+ if !war_file.exists?
107
+ war_file.send(method)
108
+ elsif war_file.exists? && overwrite
109
+ war_file.send(method)
110
+ end
111
+ war_file
112
+ end
113
+
114
+
115
+ private
116
+
117
+
118
+ def build_war_file_options
119
+ { base_url: jenkins_war_url, base_path: war_files_cache, lib_path: war_unpacked_cache, server_path: server_path, logger: ConsoleLogger.new }
120
+ end
121
+
122
+
123
+ def all_war_files_sorted
124
+ all_war_files.sort.reverse
125
+ end
126
+
127
+
128
+ def all_war_files_as_object
129
+ all_war_files_sorted.map { |f| build_war_file(File.basename(f)) }
130
+ end
131
+
132
+ end
133
+ end
@@ -0,0 +1,91 @@
1
+ require 'tty-table'
2
+ require 'thor'
3
+
4
+ module Jenkins
5
+ module Peace
6
+ class CLI < Thor
7
+
8
+ include Jenkins::Peace::ThorExtensions
9
+
10
+ desc 'infos', 'Display infos about this gem'
11
+
12
+ def infos
13
+ say
14
+ table = TTY::Table.new rows: Jenkins::Peace.infos.to_a
15
+ puts table.render(:basic, padding: [0, 2])
16
+ say
17
+ end
18
+
19
+
20
+ desc 'latest', 'Display infos about the latest version of war file installed'
21
+
22
+ def latest
23
+ return warn 'No Jenkins war files installed' unless Jenkins::Peace.latest_version
24
+ info Jenkins::Peace.latest_version
25
+ end
26
+
27
+
28
+ desc 'list', 'List war files installed'
29
+
30
+ def list
31
+ return warn 'No Jenkins war files installed' if Jenkins::Peace.list.empty?
32
+ table = TTY::Table.new header: formated_headers, rows: formated_war_files_list
33
+ puts table.render(:ascii, padding: [0, 2])
34
+ end
35
+
36
+
37
+ desc 'download <version>', 'Download war file corresponding to version passed in params'
38
+
39
+ def download(version)
40
+ check_conflicts_and_call_method(:download, version)
41
+ end
42
+
43
+
44
+ desc 'unpack <version>', 'Unpack war file corresponding to version passed in params'
45
+
46
+ def unpack(version)
47
+ check_conflicts_and_call_method(:unpack, version, :unpacked?) do |war_file|
48
+ return download_it_first! unless war_file.exists?
49
+ end
50
+ end
51
+
52
+
53
+ desc 'install <version>', 'Install war file corresponding to version passed in params (will download then unpack war file)'
54
+
55
+ def install(version)
56
+ check_conflicts_and_call_method(:install, version)
57
+ end
58
+
59
+
60
+ desc 'remove <version>', 'Remove war file corresponding to version passed in params'
61
+
62
+ def remove(version)
63
+ Jenkins::Peace.remove(version)
64
+ success_message
65
+ end
66
+
67
+
68
+ desc 'clean', 'Remove all war files'
69
+
70
+ def clean
71
+ yes_no_question('Are you sure?') { Jenkins::Peace.clean! }
72
+ end
73
+
74
+
75
+ desc 'server <version>', 'Start a server with the war file corresponding to version passed in params'
76
+
77
+ method_option :home, aliases: '-h', default: File.join(ENV['HOME'], '.jenkins', 'server'), type: :string, desc: 'Use this directory to store server data'
78
+ method_option :port, aliases: '-p', default: 3001, type: :numeric, desc: 'Port for server (default 3001)'
79
+ method_option :control, aliases: '-c', default: 3002, type: :numeric, desc: 'Shutdown/Control port (default 3002)'
80
+ method_option :daemon, aliases: '-d', default: false, type: :boolean, desc: 'Daemonize'
81
+ method_option :kill, aliases: '-k', default: false, type: :boolean, desc: 'Kill'
82
+ method_option :logfile, aliases: '-l', default: File.join(Dir.pwd, 'jenkins.log'), type: :string, desc: 'Redirect log messages to this file'
83
+
84
+ def server(version)
85
+ war_file = Jenkins::Peace.build_war_file(version)
86
+ war_file.exists? ? war_file.start!(options) : download_it_first!
87
+ end
88
+
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,34 @@
1
+ module Jenkins
2
+ module Peace
3
+ class ConsoleLogger
4
+
5
+ RED = "\e[31m"
6
+ GREEN = "\e[32m"
7
+ YELLOW = "\e[33m"
8
+ CLEAR = "\e[0m"
9
+
10
+ attr_reader :logger
11
+
12
+
13
+ def initialize(logger = $stdout)
14
+ @logger = logger
15
+ end
16
+
17
+
18
+ def info(message)
19
+ logger << "#{GREEN}#{message}#{CLEAR}\n"
20
+ end
21
+
22
+
23
+ def warn(message)
24
+ logger << "#{YELLOW}#{message}#{CLEAR}\n"
25
+ end
26
+
27
+
28
+ def error(message)
29
+ logger << "#{RED}#{message}#{CLEAR}\n"
30
+ end
31
+
32
+ end
33
+ end
34
+ end