spigoter 0.3.0 → 0.4.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 +4 -4
- data/.editorconfig +29 -0
- data/.gitignore +2 -1
- data/.rubocop.yml +15 -1152
- data/README.md +2 -1
- data/exe/spigoter +43 -43
- data/lib/spigoter/cli/cli.rb +21 -16
- data/lib/spigoter/cli/cli_compile.rb +61 -35
- data/lib/spigoter/cli/cli_init.rb +63 -0
- data/lib/spigoter/cli/cli_start.rb +35 -21
- data/lib/spigoter/cli/cli_update.rb +56 -45
- data/lib/spigoter/log/log.rb +33 -31
- data/lib/spigoter/utils.rb +86 -23
- data/lib/spigoter/version.rb +1 -1
- data/lib/spigoter/webapi/curse.rb +32 -30
- data/lib/spigoter/webapi/devbukkit.rb +32 -28
- data/lib/spigoter/webapi/plugin.rb +37 -25
- data/lib/spigoter/webapi/spigot.rb +29 -0
- data/lib/spigoter.rb +5 -4
- data/spigoter.gemspec +3 -0
- metadata +20 -4
- data/lib/spigoter/plugins.rb +0 -17
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Spigoter
|
2
2
|
|
3
|
-
[](https://
|
3
|
+
[](https://rubygems.org/gems/spigoter)
|
4
|
+
[](https://rubygems.org/gems/spigoter)
|
4
5
|
[](https://travis-ci.org/DanielRamosAcosta/spigoter)
|
5
6
|
[](https://coveralls.io/github/DanielRamosAcosta/spigoter?branch=master)
|
6
7
|
[](https://codeclimate.com/github/DanielRamosAcosta/spigoter)
|
data/exe/spigoter
CHANGED
@@ -7,49 +7,49 @@ options = {}
|
|
7
7
|
|
8
8
|
subtext = <<HELP
|
9
9
|
COMMAND are:
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
start [options] starts the server
|
11
|
+
update [options] updates plugin
|
12
|
+
compile [options] compiles spigot and replaces as the current version
|
13
13
|
|
14
|
-
See '#{File.basename $
|
14
|
+
See '#{File.basename $PROGRAM_NAME} COMMAND --help' for more information on a specific command.
|
15
15
|
HELP
|
16
16
|
|
17
17
|
global = OptionParser.new do |opts|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
opts.banner = "Usage: #{File.basename $PROGRAM_NAME} <COMMAND> [options]"
|
19
|
+
opts.separator ''
|
20
|
+
opts.separator subtext
|
21
|
+
opts.on_tail('-v', '--version', 'Show version information about this program and quit.') do
|
22
|
+
puts "Spigoter v#{Spigoter::VERSION}"
|
23
|
+
exit
|
24
|
+
end
|
25
25
|
end
|
26
26
|
|
27
27
|
subcommands = {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
opts.separator "\nCompiles spigot and sets it as the current version"
|
28
|
+
'init' => OptionParser.new do |opts|
|
29
|
+
opts.banner = "Usage: #{File.basename $PROGRAM_NAME} init"
|
30
|
+
opts.separator "\nCreates a new spigoter.yml for you"
|
31
|
+
end,
|
32
|
+
'start' => OptionParser.new do |opts|
|
33
|
+
opts.banner = "Usage: #{File.basename $PROGRAM_NAME} start"
|
34
|
+
opts.separator "\nStarts the server"
|
35
|
+
end,
|
36
|
+
'update' => OptionParser.new do |opts|
|
37
|
+
opts.banner = "Usage: #{File.basename $PROGRAM_NAME} update [options]"
|
38
|
+
opts.on('-l', '--list=[x,y,z]', Array, 'list of plugins to update') do |par|
|
39
|
+
options[:list] = par
|
40
|
+
end
|
41
|
+
opts.on('-f', '--force', 'forces to updates all plugins, even if no new version was found') do |par|
|
42
|
+
options[:force] = par
|
43
|
+
end
|
44
|
+
opts.separator "\nUpdates the plugins"
|
45
|
+
end,
|
46
|
+
'compile' => OptionParser.new do |opts|
|
47
|
+
opts.banner = "Usage: #{File.basename $PROGRAM_NAME} update [options]"
|
48
|
+
opts.on('-v', '--version version', 'version of spigot to compile (lastest by default)') do |par|
|
49
|
+
options[:version] = par
|
52
50
|
end
|
51
|
+
opts.separator "\nCompiles spigot and sets it as the current version"
|
52
|
+
end
|
53
53
|
}
|
54
54
|
|
55
55
|
global.order!
|
@@ -57,15 +57,15 @@ global.order!
|
|
57
57
|
command = ARGV.shift
|
58
58
|
|
59
59
|
begin
|
60
|
-
|
60
|
+
subcommands[command].order!
|
61
61
|
rescue
|
62
|
-
|
63
|
-
|
62
|
+
Log.error "Unrecognized subcommand or param, do #{File.basename $PROGRAM_NAME} --help"
|
63
|
+
exit(1)
|
64
64
|
end
|
65
65
|
|
66
|
-
#puts "Command: #{command} "
|
67
|
-
#p options
|
68
|
-
#puts "ARGV:"
|
69
|
-
#p ARGV
|
66
|
+
# puts "Command: #{command} "
|
67
|
+
# p options
|
68
|
+
# puts "ARGV:"
|
69
|
+
# p ARGV
|
70
70
|
|
71
|
-
Spigoter::CLI
|
71
|
+
Spigoter::CLI.run(command).call(options)
|
data/lib/spigoter/cli/cli.rb
CHANGED
@@ -1,18 +1,23 @@
|
|
1
1
|
module Spigoter
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
# This module encloses all CLI commands.
|
3
|
+
# @author Daniel Ramos Acosta <danielramosacosta@hotmail.com>
|
4
|
+
module CLI
|
5
|
+
def self.run(command)
|
6
|
+
Run.new.task[command]
|
7
|
+
end
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
9
|
+
# Class for running tasks.
|
10
|
+
# @author Daniel Ramos Acosta <danielramosacosta@hotmail.com>
|
11
|
+
class Run
|
12
|
+
attr_reader :task
|
13
|
+
def initialize
|
14
|
+
@task = {
|
15
|
+
'update' => Spigoter::CLI.update,
|
16
|
+
'compile' => Spigoter::CLI.compile,
|
17
|
+
'start' => Spigoter::CLI.start,
|
18
|
+
'init' => Spigoter::CLI.init
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,36 +1,62 @@
|
|
1
1
|
module Spigoter
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
2
|
+
# This module encloses all CLI commands.
|
3
|
+
# @author Daniel Ramos Acosta <danielramosacosta@hotmail.com>
|
4
|
+
module CLI
|
5
|
+
def self.compile
|
6
|
+
Compile.compile
|
7
|
+
end
|
8
|
+
# Module for compiling Spigot
|
9
|
+
# @author Daniel Ramos Acosta <danielramosacosta@hotmail.com>
|
10
|
+
module Compile
|
11
|
+
def self.compile
|
12
|
+
->(*) { main }
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.main(*)
|
16
|
+
Log.info 'Compiling Spigot!'
|
17
|
+
dependencies
|
18
|
+
opts = import_opts
|
19
|
+
|
20
|
+
FileUtils.mkdir_p 'build'
|
21
|
+
Dir.chdir('build') do
|
22
|
+
download_buildtools
|
23
|
+
FileUtils.rm_rf(Dir.glob('spigot*.jar'))
|
24
|
+
compile_spigot(opts)
|
25
|
+
end
|
26
|
+
|
27
|
+
FileUtils.cp(Dir['build/spigot*.jar'].first, 'spigot.jar')
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.dependencies
|
31
|
+
if Spigoter::Utils.which('javac').nil? || Spigoter::Utils.which('git').nil?
|
32
|
+
Log.error "You don't have javac or git in PATH"
|
33
|
+
exit(1)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.import_opts
|
38
|
+
Spigoter::Utils.fill_opts_config
|
39
|
+
rescue
|
40
|
+
Log.error 'There is an error in spigoter.yml'
|
41
|
+
exit(1)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.download_buildtools
|
45
|
+
unless File.exist?('BuildTools.jar')
|
46
|
+
file = Spigoter::Utils.download('https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar')
|
47
|
+
File.open('BuildTools.jar', 'wb').write(file)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.compile_spigot(opts)
|
52
|
+
Log.info "Compiling spigot version #{opts[:spigot_version]}"
|
53
|
+
exit_status = system("java -jar BuildTools.jar --rev #{opts[:spigot_version]}")
|
54
|
+
|
55
|
+
if exit_status != true
|
56
|
+
Log.error 'There was an error while compiling Spigot'
|
57
|
+
exit(1)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Spigoter
|
2
|
+
# This module encloses all CLI commands.
|
3
|
+
# @author Daniel Ramos Acosta <danielramosacosta@hotmail.com>
|
4
|
+
module CLI
|
5
|
+
def self.init
|
6
|
+
Init.init
|
7
|
+
end
|
8
|
+
# Module for generating the necessary files.
|
9
|
+
# @author Daniel Ramos Acosta <danielramosacosta@hotmail.com>
|
10
|
+
module Init
|
11
|
+
def self.init
|
12
|
+
->(*) { main }
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.main(*)
|
16
|
+
Log.info 'Generating files!'
|
17
|
+
File.exist?('spigoter.yml') ? Log.warn('spigoter.yml alredy exists') : generate_spigoter
|
18
|
+
File.exist?('plugins.yml') ? Log.warn('plugins.yml alredy exists') : generate_plugins
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.generate_spigoter
|
22
|
+
open('spigoter.yml', 'w+') do |f|
|
23
|
+
f << "---\n"
|
24
|
+
f << "Spigoter:\n"
|
25
|
+
f << " build_dir: build\n"
|
26
|
+
f << " plugins_dir: plugins\n"
|
27
|
+
f << " javaparams: \"-Xms1G -Xmx2G\"\n"
|
28
|
+
f << " spigot_version: latest\n"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.generate_plugins
|
33
|
+
if Dir.exist?('plugins') && !Dir['plugins/*.jar'].empty?
|
34
|
+
generate_with_plugins
|
35
|
+
else
|
36
|
+
generate_empty
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.generate_with_plugins
|
41
|
+
open('plugins.yml', 'w+') do |f|
|
42
|
+
f << "---\n"
|
43
|
+
f << "Plugins:\n"
|
44
|
+
Dir['plugins/*.jar'].each do |plg|
|
45
|
+
f << " #{File.basename(plg).gsub(/.jar/, '')}:\n"
|
46
|
+
f << " # type: {curse|devbukkit|....}\n"
|
47
|
+
f << " # url: http://something.com\n"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.generate_empty
|
53
|
+
open('plugins.yml', 'w+') do |f|
|
54
|
+
f << "---\n"
|
55
|
+
f << "Plugins:\n"
|
56
|
+
f << " # Plugin1:\n"
|
57
|
+
f << " # type: {curse|devbukkit|....}\n"
|
58
|
+
f << " # url: http://something.com\n"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -1,22 +1,36 @@
|
|
1
1
|
module Spigoter
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
2
|
+
# This module encloses all CLI commands.
|
3
|
+
# @author Daniel Ramos Acosta <danielramosacosta@hotmail.com>
|
4
|
+
module CLI
|
5
|
+
def self.start
|
6
|
+
Start.start
|
7
|
+
end
|
8
|
+
# Module for starting the server.
|
9
|
+
# @author Daniel Ramos Acosta <danielramosacosta@hotmail.com>
|
10
|
+
module Start
|
11
|
+
def self.start
|
12
|
+
->(opts = {}) { main(opts) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.main(opts)
|
16
|
+
Log.info 'Starting the server!'
|
17
|
+
dependencies
|
18
|
+
opts = {}
|
19
|
+
begin
|
20
|
+
opts = Spigoter::Utils.fill_opts_config
|
21
|
+
rescue => e
|
22
|
+
Log.error e.message
|
23
|
+
exit(1)
|
24
|
+
end
|
25
|
+
system("java #{opts[:javaparms]} -jar spigot.jar")
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.dependencies
|
29
|
+
if Spigoter::Utils.which('java').nil?
|
30
|
+
Log.error "You don't have java in PATH"
|
31
|
+
exit(1)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,46 +1,57 @@
|
|
1
1
|
module Spigoter
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
2
|
+
# This module encloses all CLI commands.
|
3
|
+
# @author Daniel Ramos Acosta <danielramosacosta@hotmail.com>
|
4
|
+
module CLI
|
5
|
+
def self.update
|
6
|
+
Update.update
|
7
|
+
end
|
8
|
+
# Module for updating plugins
|
9
|
+
# @author Daniel Ramos Acosta <danielramosacosta@hotmail.com>
|
10
|
+
module Update
|
11
|
+
def self.update
|
12
|
+
->(opts = {}) { main(opts) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.main(opts = {})
|
16
|
+
Log.info 'Updating!'
|
17
|
+
dependencies
|
18
|
+
plugins_data = Spigoter::Utils.get_plugins(opts)
|
19
|
+
|
20
|
+
plugins_data.each do |name, data|
|
21
|
+
objeto = get_plugin(name, data)
|
22
|
+
next unless !objeto.nil? && (objeto.class < Spigoter::Plugin)
|
23
|
+
|
24
|
+
File.open("plugins/#{name}.jar", 'w+b') do |f|
|
25
|
+
f.write(objeto.file)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.dependencies
|
31
|
+
unless File.exist?('plugins.yml')
|
32
|
+
Log.error "plugins.yml doesn't exists, please, create one (you can use spigoter init)"
|
33
|
+
exit(1)
|
34
|
+
end
|
35
|
+
|
36
|
+
unless Dir.exist?('plugins')
|
37
|
+
Log.error "plugins directory doesn't exists, please, create it"
|
38
|
+
exit(1)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.get_plugin(name, data)
|
43
|
+
Log.info "Updating plugin: #{name}"
|
44
|
+
plugin_type = data[:type]
|
45
|
+
|
46
|
+
if Spigoter::Plugin.list[plugin_type].nil?
|
47
|
+
Log.error "Plugin type #{plugin_type} doesn't exists!"
|
48
|
+
exit(1)
|
49
|
+
end
|
50
|
+
|
51
|
+
Spigoter::Plugin.list[plugin_type].new(data[:url])
|
52
|
+
rescue => e
|
53
|
+
Log.error e.message
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/spigoter/log/log.rb
CHANGED
@@ -1,37 +1,39 @@
|
|
1
1
|
require 'logging'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
Logging.color_scheme('bright',
|
4
|
+
levels: {
|
5
|
+
info: :green,
|
6
|
+
warn: :yellow,
|
7
|
+
error: :red,
|
8
|
+
fatal: [:white, :on_red]
|
9
|
+
},
|
10
|
+
date: :blue,
|
11
|
+
logger: :cyan,
|
12
|
+
message: :magenta
|
13
|
+
)
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
)
|
21
|
-
)
|
15
|
+
Logging.appenders.stdout('stdout',
|
16
|
+
layout: Logging.layouts.pattern(pattern: '[%l] %c: %m\n',
|
17
|
+
color_scheme: 'bright'
|
18
|
+
)
|
19
|
+
)
|
22
20
|
|
21
|
+
# Module for logging all things, info warnings and errors.
|
22
|
+
# @author Daniel Ramos Acosta <danielramosacosta@hotmail.com>
|
23
23
|
module Log
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
@log = Logging.logger['Spigoter']
|
25
|
+
@log.add_appenders 'stdout'
|
26
|
+
@log.level = :info
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
28
|
+
def self.info(msg)
|
29
|
+
@log.info msg
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.warn(msg)
|
33
|
+
@log.warn msg
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.error(msg)
|
37
|
+
@log.error msg
|
38
|
+
end
|
39
|
+
end
|