spigoter 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Spigoter
2
2
 
3
- [![Gem Version](https://img.shields.io/gem/v/spigoter.svg?style=flat-square)](https://badge.fury.io/rb/spigoter)
3
+ [![Gem Version](https://img.shields.io/gem/v/spigoter.svg?style=flat-square)](https://rubygems.org/gems/spigoter)
4
+ [![Gem Downloads](https://img.shields.io/gem/dt/spigoter.svg?style=flat-square)](https://rubygems.org/gems/spigoter)
4
5
  [![Build Status](https://img.shields.io/travis/DanielRamosAcosta/spigoter.svg?style=flat-square)](https://travis-ci.org/DanielRamosAcosta/spigoter)
5
6
  [![Coverage Status](https://img.shields.io/coveralls/DanielRamosAcosta/spigoter.svg?style=flat-square)](https://coveralls.io/github/DanielRamosAcosta/spigoter?branch=master)
6
7
  [![Code Climate](https://img.shields.io/codeclimate/github/DanielRamosAcosta/spigoter.svg?style=flat-square)](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
- start [options] starts the server
11
- update [options] updates plugin
12
- compile [options] compiles spigot and replaces as the current version
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 $0} COMMAND --help' for more information on a specific command.
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
- opts.banner = "Usage: #{File.basename $0} <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
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
- 'init' => OptionParser.new do |opts|
29
- opts.banner = "Usage: #{File.basename $0} 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 $0} start"
34
- opts.separator "\nStarts the server"
35
- end,
36
- 'update' => OptionParser.new do |opts|
37
- opts.banner = "Usage: #{File.basename $0} 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 $0} update [options]"
48
- opts.on("-v", "--version version", "version of spigot to compile (lastest by default)") do |par|
49
- options[:version] = par
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
- subcommands[command].order!
60
+ subcommands[command].order!
61
61
  rescue
62
- Log.error "Unrecognized subcommand or param, do #{File.basename $0} --help"
63
- exit(1)
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::run(command, options)
71
+ Spigoter::CLI.run(command).call(options)
@@ -1,18 +1,23 @@
1
1
  module Spigoter
2
- module CLI
3
- def self.run(command, opts={})
4
- Run.new.task[command].call(opts)
5
- end
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
- class Run
8
- attr_reader :task
9
- def initialize
10
- @task = {
11
- 'update' => Spigoter::CLI.update,
12
- 'compile' => Spigoter::CLI.compile,
13
- 'start' => Spigoter::CLI.start
14
- }
15
- end
16
- end
17
- end
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
- module CLI
3
- def self.compile
4
- return Compile::compile
5
- end
6
- module Compile
7
- def self.compile
8
- return lambda do |opts|
9
- main(opts)
10
- end
11
- end
12
- def self.main(opts = {})
13
- if !Spigoter::Utils.which('java').nil? and !Spigoter::Utils.which('git').nil?
14
- Log.info "Compiling Spigot!"
15
- FileUtils.mkdir_p 'build'
16
- Dir.chdir('build')
17
- unless File.exist?('BuildTools.jar')
18
- file = Spigoter::Utils.download('https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar')
19
- File.open('BuildTools.jar', 'wb').write(file)
20
- end
21
- if opts[:version].nil?
22
- Log.info "Compiling lastest spigot version"
23
- system("java -jar BuildTools.jar")
24
- else
25
- Log.info "Compiling spigot version #{opts[:version]}"
26
- system("java -jar BuildTools.jar --rev #{opts[:version]}")
27
- end
28
- Dir.chdir('..')
29
- FileUtils.cp(Dir['build/spigot*.jar'].first, 'spigot.jar')
30
- else
31
- Log.error "You don't have java or git in PATH"
32
- end
33
- end
34
- end
35
- end
36
- end
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
- module CLI
3
- def self.start
4
- return Start::start
5
- end
6
- module Start
7
- def self.start
8
- return lambda do |opts|
9
- main(opts)
10
- end
11
- end
12
- def self.main(opts = {})
13
- unless Spigoter::Utils.which('java').nil?
14
- Log.info "Starting the server!"
15
- system("java #{opts[:javaparm]} -jar spigot.jar")
16
- else
17
- Log.error "You don't have java in PATH"
18
- end
19
- end
20
- end
21
- end
22
- end
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
- module CLI
3
- def self.update
4
- return Update::update
5
- end
6
- module Update
7
- def self.update
8
- return lambda do |opts|
9
- main(opts)
10
- end
11
- end
12
- def self.main(opts)
13
- Log.info "Updating!"
14
- unless File.exist?('plugins.yml')
15
- Log.error "plugins.yml doesn't exists, please, create one (you can use spigoter init)"
16
- exit(1)
17
- end
18
- unless Dir.exist?('plugins')
19
- Log.error "plugins directory doesn't exists, please, create it"
20
- exit(1)
21
- end
22
-
23
- file = File.read('plugins.yml')
24
- plugins_data = YAML.load(file)
25
- list = plugins_data.keys
26
- unless opts[:list].nil?
27
- unless opts[:list].empty?
28
- list = opts[:list]
29
- end
30
- end
31
-
32
- list.each do |plugin|
33
- begin
34
- Log.info "Starting to download #{plugin}"
35
- hash = Plugins.get_plugin(plugin, plugins_data[plugin])
36
- plugin_file = File.open("plugins/#{plugin}.jar", 'wb')
37
- plugin_file.write(hash[:file])
38
- Log.info "#{plugin} was downloaded correctly"
39
- rescue
40
- Log.error "Unkown source #{plugins_data[plugin]['type']}"
41
- end
42
- end
43
- end
44
- end
45
- end
46
- end
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
@@ -1,37 +1,39 @@
1
1
  require 'logging'
2
2
 
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
- )
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
- Logging.appenders.stdout(
16
- 'stdout',
17
- :layout => Logging.layouts.pattern(
18
- :pattern => '[%d] %-5l %c: %m\n',
19
- :color_scheme => 'bright'
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
- @log = Logging.logger['Spigoter']
25
- @log.add_appenders 'stdout'
26
- @log.level = :info
24
+ @log = Logging.logger['Spigoter']
25
+ @log.add_appenders 'stdout'
26
+ @log.level = :info
27
27
 
28
- def self.info(msg)
29
- @log.info msg
30
- end
31
- def self.warn(msg)
32
- @log.warn msg
33
- end
34
- def self.error(msg)
35
- @log.error msg
36
- end
37
- end
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