spigoter 0.2.2 → 0.3.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.
data/.travis.yml CHANGED
@@ -2,6 +2,9 @@ language: ruby
2
2
  rvm:
3
3
  - 2.3.0 # My ruby version
4
4
  - 2.2.4
5
- before_install: gem install bundler
5
+ before_install:
6
+ - gem install bundler
7
+ - sudo apt-get -qq update
8
+ - sudo apt-get install git openjdk-7-jre-headless tar
6
9
  notifications:
7
10
  email: false
data/Guardfile CHANGED
@@ -52,7 +52,7 @@ guard :rspec, cmd: "bundle exec rspec" do
52
52
  file_changed = m.first.sub("lib/spigoter/", "").sub(".rb", "")
53
53
  "spec/#{file_changed}_spec.rb"
54
54
  end
55
- watch(/exe\/spigoter/) do |m|
55
+ watch(/exe\/spigoter/) do
56
56
  "spec/cli_spec.rb"
57
57
  end
58
58
 
data/README.md CHANGED
@@ -1,9 +1,13 @@
1
1
  # Spigoter
2
2
 
3
- [![Build Status](https://travis-ci.org/DanielRamosAcosta/spigoter.svg?branch=master)](https://travis-ci.org/DanielRamosAcosta/spigoter) [![Coverage Status](https://coveralls.io/repos/github/DanielRamosAcosta/spigoter/badge.svg?branch=master)](https://coveralls.io/github/DanielRamosAcosta/spigoter?branch=master) [![Dependency Status](https://gemnasium.com/DanielRamosAcosta/spigoter.svg)](https://gemnasium.com/DanielRamosAcosta/spigoter) [![Gem Version](https://badge.fury.io/rb/spigoter.svg)](https://badge.fury.io/rb/spigoter)
3
+ [![Gem Version](https://img.shields.io/gem/v/spigoter.svg?style=flat-square)](https://badge.fury.io/rb/spigoter)
4
+ [![Build Status](https://img.shields.io/travis/DanielRamosAcosta/spigoter.svg?style=flat-square)](https://travis-ci.org/DanielRamosAcosta/spigoter)
5
+ [![Coverage Status](https://img.shields.io/coveralls/DanielRamosAcosta/spigoter.svg?style=flat-square)](https://coveralls.io/github/DanielRamosAcosta/spigoter?branch=master)
6
+ [![Code Climate](https://img.shields.io/codeclimate/github/DanielRamosAcosta/spigoter.svg?style=flat-square)](https://codeclimate.com/github/DanielRamosAcosta/spigoter)
7
+ [![Dependency Status](https://img.shields.io/gemnasium/DanielRamosAcosta/spigoter.svg?style=flat-square)](https://gemnasium.com/DanielRamosAcosta/spigoter)
4
8
 
5
9
 
6
- Spigoter is a Ruby gem that gives you many tools make your server keepup easier.
10
+ Spigoter is a Ruby gem that gives you many tools in order to make your server keepup easier.
7
11
 
8
12
  ## Installation
9
13
 
@@ -14,59 +18,42 @@ gem install spigoter
14
18
  ## Features
15
19
 
16
20
  ### Run the server
17
- spigoter [--javaparam="-Xms1024M -Xmx4096M ..."]
21
+ spigoter start
18
22
 
19
23
  ### Update plugins
20
- spigoter {-u|--update} {all|plugin1,plugin2,...}
21
-
22
- ### Usage
23
- You have to drop a `plugin.json` file in the server root directory. There will be saved some relevant information of plugins, as well as some customization.
24
-
25
- Example:
26
-
27
- ```json
28
- [
29
- {
30
- "name": "Authme",
31
- "url": "http://mods.curse.com/bukkit-plugins/minecraft/authme-reloaded",
32
- "type": "curse",
33
- "last_update": "31-3-2016 - 0:40"
34
- },
35
- {
36
- "name": "BossShop",
37
- "url": "http://mods.curse.com/bukkit-plugins/minecraft/bossshop",
38
- "type": "curse",
39
- "last_update": "31-3-2016 - 0:40"
40
- },
41
- {
42
- "name": "ChestShop",
43
- "url": "https://www.spigotmc.org/resources/1-9-chestshop.19511/",
44
- "type": "spigotmc",
45
- "last_update": "31-3-2016 - 0:40"
46
- },
47
- {
48
- "name": "ChopTree",
49
- "url": "https://www.spigotmc.org/resources/choptree.2046/",
50
- "type": "spigotmc",
51
- "last_update": "31-3-2016 - 0:40"
52
- },
53
- {
54
- "name": "ClickSort",
55
- "url": "http://mods.curse.com/bukkit-plugins/minecraft/clicksort",
56
- "type": "curse",
57
- "last_update": "31-3-2016 - 0:40"
58
- },
59
- {
60
- "name": "Dynmap",
61
- "url": "http://dev.bukkit.org/media/files/911/888/dynmap-2.3-alpha-1.jar",
62
- "type": "direct",
63
- "keep_eye_on": "http://dev.bukkit.org/bukkit-plugins/dynmap/files/",
64
- "last_update": "31-3-2016 - 0:40"
65
- }
66
- ]
24
+ spigoter update [--list=plugin1,plugin2,...]
25
+
26
+ #### Usage
27
+ You have to drop a `plugin.yml` file in the server root directory. There will be saved some relevant information of plugins, as well as some customization.
28
+
29
+ Basic example:
30
+
31
+ ```yml
32
+ Authme:
33
+ type: curse
34
+ url: "http://mods.curse.com/bukkit-plugins/minecraft/authme-reloaded"
35
+ ChopTree:
36
+ type: spigotmc
37
+ url: "https://www.spigotmc.org/resources/choptree.2046/"
38
+ Dynmap:
39
+ type: devbukkit
40
+ url: "http://dev.bukkit.org/bukkit-plugins/dynmap/"
41
+ Essentials:
42
+ type: direct
43
+ url: "https://hub.spigotmc.org/jenkins/job/Spigot-Essentials/lastSuccessfulBuild/artifact/Essentials/target/Essentials-2.x-SNAPSHOT.jar"
44
+ keep_eye_on: "https://hub.spigotmc.org/jenkins/job/Spigot-Essentials/"
45
+ EssentialsChat:
46
+ type: direct
47
+ url: "https://hub.spigotmc.org/jenkins/job/Spigot-Essentials/lastSuccessfulBuild/artifact/EssentialsChat/target/EssentialsChat-2.x-SNAPSHOT.jar"
48
+ Multiverse-core:
49
+ keep_eye_on: "http://mods.curse.com/bukkit-plugins/minecraft/multiverse-core"
50
+ type: direct
51
+ url: "http://ci.onarandombox.com/job/Multiverse-Core/lastSuccessfulBuild/artifact/target/Multiverse-Core-2.5.jar"
52
+ Towny:
53
+ type: manual
54
+ url: "http://palmergames.com"
67
55
  ```
68
56
 
69
- I'm trying to switch to YAML.
70
57
  #### Currently suported plugin hosted sites
71
58
  * [Curse](http://mods.curse.com/bukkit-plugins/minecraft)
72
59
  * [BukkitDev](http://dev.bukkit.org/)
@@ -74,10 +61,11 @@ I'm trying to switch to YAML.
74
61
  #### Planned
75
62
  * [Spigot](https://www.spigotmc.org/)
76
63
  * Direct download
64
+ * Manual
77
65
  * Custom download via piping (first download, second unrar, then extract X file, ...)
78
66
 
79
- ### Compile Spigot and set version
80
- spigoter {-c|--compile} [lastest|1.9|1.8|...]
67
+ ### Update Spigot's version
68
+ spigoter compile [--version={1.9|1.8|...}]
81
69
 
82
70
  This command excecute the `buildtools .jar` in a `build`directory in the root server folder. Then, it'll replace the old version with the new one.
83
71
 
data/exe/spigoter CHANGED
@@ -1,24 +1,71 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'spigoter'
4
- require 'trollop'
5
-
6
-
7
- opts = Trollop::options do
8
- version "Spigoter v#{Spigoter::VERSION}"
9
- banner <<-EOS
10
- Spigoter, a command line utity for minecraft servers.
11
-
12
- Usage:
13
- spigoter [options]
14
- where [options] are:
15
- EOS
16
- opt :javaparm, 'Sets the java parameters', :default => '-Xms1024M -Xmx4096M -jar spigot.jar' #TODO: Poner esto aqui
17
- opt :compile, "Compiles spigot and sets the new version"
18
- opt :update, "Set permissons plugin"
19
- opt :version, "Get spigoter version"
4
+ require 'optparse'
5
+
6
+ options = {}
7
+
8
+ subtext = <<HELP
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
13
+
14
+ See '#{File.basename $0} COMMAND --help' for more information on a specific command.
15
+ HELP
16
+
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
25
+ end
26
+
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"
52
+ end
53
+ }
54
+
55
+ global.order!
56
+
57
+ command = ARGV.shift
58
+
59
+ begin
60
+ subcommands[command].order!
61
+ rescue
62
+ Log.error "Unrecognized subcommand or param, do #{File.basename $0} --help"
63
+ exit(1)
20
64
  end
21
65
 
22
- puts "Estas son las opciones: #{opts}"
66
+ #puts "Command: #{command} "
67
+ #p options
68
+ #puts "ARGV:"
69
+ #p ARGV
23
70
 
24
- Spigoter::CLI.main(opts)
71
+ Spigoter::CLI::run(command, options)
data/lib/spigoter.rb CHANGED
@@ -1,12 +1,14 @@
1
1
  require "spigoter/version"
2
2
  require "spigoter/log/log"
3
+ require 'spigoter/utils'
3
4
  require 'spigoter/plugins'
5
+ require 'spigoter/webapi/plugin'
4
6
  require 'spigoter/webapi/curse'
5
7
  require 'spigoter/webapi/devbukkit'
8
+ require 'spigoter/cli/cli'
6
9
  require 'spigoter/cli/cli_update'
7
10
  require 'spigoter/cli/cli_compile'
8
11
  require 'spigoter/cli/cli_start'
9
- require 'spigoter/cli/cli'
10
12
 
11
13
  module Spigoter
12
14
  # Your code goes here...
@@ -1,22 +1,18 @@
1
1
  module Spigoter
2
2
  module CLI
3
- def self.main(opts)
4
- Log.info "Estoy en la main, mi opts son: #{opts}"
5
- if(opts[:update])
6
- Spigoter::CLI.update(opts)
7
- return
8
- end
9
- if(opts[:compile])
10
- Spigoter::CLI.compile(opts)
11
- return
12
- end
13
- if(opts[:version])
14
- puts "Hola!"
15
- puts Spigoter::VERSION
16
- puts Spigoter::VERSION.class
17
- return
3
+ def self.run(command, opts={})
4
+ Run.new.task[command].call(opts)
5
+ end
6
+
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
+ }
18
15
  end
19
- Spigoter::CLI.start(opts)
20
16
  end
21
17
  end
22
18
  end
@@ -1,7 +1,36 @@
1
1
  module Spigoter
2
2
  module CLI
3
- def self.compile(opts)
4
- puts opts
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
5
34
  end
6
35
  end
7
36
  end
@@ -1,24 +1,22 @@
1
1
  module Spigoter
2
2
  module CLI
3
- def self.start(opts)
4
- unless which('java').nil?
5
- Log.info "Starting the server!"
6
- system("java #{opts[:javaparm]}")
7
- else
8
- Log.error "You don't have java in PATH"
9
- end
3
+ def self.start
4
+ return Start::start
10
5
  end
11
-
12
- def self.which(cmd)
13
- # http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
14
- exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
15
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
16
- exts.each { |ext|
17
- exe = File.join(path, "#{cmd}#{ext}")
18
- return exe if File.executable?(exe) && !File.directory?(exe)
19
- }
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
20
19
  end
21
- return nil
22
20
  end
23
21
  end
24
22
  end
@@ -1,27 +1,44 @@
1
1
  module Spigoter
2
2
  module CLI
3
- def self.update(opts)
4
- Log.info "Updating!"
5
- unless File.exists?('plugins.yml')
6
- Log.error "plugins.yml doesn't exists, please, create one"
7
- exit(1)
8
- end
9
- unless Dir.exists?('plugins')
10
- Log.error "plugins directory doesn't exists, please, create it"
11
- exit(1)
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
12
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
13
31
 
14
- file = File.read('plugins.yml')
15
- plugins = YAML.load(file)
16
- plugins.each do |name, data|
17
- begin
18
- Log.info "Starting to download #{name}"
19
- hash = Plugins.get_plugin(name, data)
20
- plugin_file = File.open("plugins/#{name}.jar", 'wb')
21
- plugin_file.write(hash[:file])
22
- Log.info "#{name} was downloaded correctly"
23
- rescue Exception => e
24
- Log.error "Unkown source #{data['type']}"
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
25
42
  end
26
43
  end
27
44
  end
@@ -1,18 +1,17 @@
1
1
  module Spigoter
2
2
  module Plugins
3
3
  def self.get_plugin(name, data)
4
+ f = nil
4
5
  case data['type']
5
6
  when 'curse'
6
- f = Spigoter::PluginCurse.new(data['url']).download
7
- hash = {:name => "#{name}.jar", :file => f}
8
- return hash
7
+ f = Spigoter::PluginCurse.new(data['url']).file
9
8
  when 'devbukkit'
10
- f = Spigoter::PluginBukkit.new(data['url']).download
11
- hash = {:name => "#{name}.jar", :file => f}
12
- return hash
9
+ f = Spigoter::PluginBukkit.new(data['url']).file
13
10
  else
14
11
  raise "Unkown source"
15
12
  end
13
+ hash = {:name => "#{name}.jar", :file => f}
14
+ return hash
16
15
  end
17
16
  end
18
17
  end