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/lib/spigoter/utils.rb
CHANGED
@@ -1,26 +1,89 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
|
3
3
|
module Spigoter
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
4
|
+
# Module with some methods commons to everyone.
|
5
|
+
# @author Daniel Ramos Acosta <danielramosacosta@hotmail.com>
|
6
|
+
module Utils
|
7
|
+
def self.download(url)
|
8
|
+
open(url).read
|
9
|
+
rescue
|
10
|
+
raise "Can't download anything from #{url}, check internet or URL?"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.loadyaml(path)
|
14
|
+
raise "File #{path} doesn't exists" unless File.exist?(path)
|
15
|
+
|
16
|
+
opts = YAML.load(File.open(path).read)
|
17
|
+
|
18
|
+
raise "Malformed YAML file #{path}" unless opts.class == Hash
|
19
|
+
opts
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.which(cmd)
|
23
|
+
# http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
|
24
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
25
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
26
|
+
exts.each do |ext|
|
27
|
+
exe = File.join(path, "#{cmd}#{ext}")
|
28
|
+
return exe if File.executable?(exe) && !File.directory?(exe)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.symbolize(hash)
|
35
|
+
new_hash = {}
|
36
|
+
hash.each { |k, v| new_hash[k.to_sym] = v }
|
37
|
+
new_hash
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.fill_opts_config
|
41
|
+
raise "spigoter.yml doesn't exists, do 'spigoter init'" unless File.exist?('spigoter.yml')
|
42
|
+
|
43
|
+
opts = loadyaml('spigoter.yml')
|
44
|
+
|
45
|
+
opts = {} if opts.nil?
|
46
|
+
opts['Spigoter'] = {} if opts['Spigoter'].nil?
|
47
|
+
opts = Spigoter::Utils.symbolize(opts['Spigoter'])
|
48
|
+
default_opts(opts)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.default_opts(opts)
|
52
|
+
opts[:build_dir] = 'build' if opts[:build_dir].nil?
|
53
|
+
opts[:plugins_dir] = 'plugins' if opts[:plugins_dir].nil?
|
54
|
+
opts[:javaparams] = '-Xms1G -Xmx2G' if opts[:javaparams].nil?
|
55
|
+
opts[:spigot_version] = Spigoter::SPIGOT_VERSION if opts[:spigot_version].nil?
|
56
|
+
opts
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.get_plugins(opts = {})
|
60
|
+
raise "spigoter.yml doesn't exists, do 'spigoter init'" unless File.exist?('plugins.yml')
|
61
|
+
|
62
|
+
plugins_data = loadyaml('plugins.yml')['Plugins']
|
63
|
+
plugins_data = normalize_plugins(plugins_data)
|
64
|
+
truncate_to_list(plugins_data, opts)
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.normalize_plugins(plugins)
|
68
|
+
plugins = symbolize(plugins)
|
69
|
+
|
70
|
+
plugins.each do |key, plugin|
|
71
|
+
plugins[key] = symbolize(plugin)
|
72
|
+
plugins[key][:type] = plugins[key][:type].to_sym
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.truncate_to_list(plugin, opts)
|
77
|
+
leftovers = {}
|
78
|
+
if !opts[:list].nil? && !opts[:list].empty?
|
79
|
+
list = opts[:list] # If a list cames in opts, use it
|
80
|
+
list.each do |key|
|
81
|
+
leftovers[key] = plugin[key]
|
82
|
+
end
|
83
|
+
else
|
84
|
+
leftovers = plugin
|
85
|
+
end
|
86
|
+
leftovers
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/spigoter/version.rb
CHANGED
@@ -2,34 +2,36 @@ require 'open-uri'
|
|
2
2
|
require 'logging'
|
3
3
|
|
4
4
|
module Spigoter
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
# Class that represent a Curse plugin.
|
6
|
+
# @author Daniel Ramos Acosta <danielramosacosta@hotmail.com>
|
7
|
+
class PluginCurse < Plugin
|
8
|
+
def initialize(website)
|
9
|
+
raise "Bad URL #{website}" if website.match(%r{^http://mods.curse.com/bukkit-plugins/minecraft/[a-z\-]+$}).nil?
|
10
|
+
super(website)
|
11
|
+
end
|
8
12
|
|
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
|
-
end
|
35
|
-
end
|
13
|
+
def download_page
|
14
|
+
return @download_page unless @download_page.nil?
|
15
|
+
@download_page = Spigoter::Utils.download("#{@url}/download")
|
16
|
+
end
|
17
|
+
|
18
|
+
def download_url
|
19
|
+
return @download_url unless @download_url.nil?
|
20
|
+
download_page
|
21
|
+
@download_url = %r{(?<download_url>http://addons\.curse\.cursecdn\.com.+\.jar)}
|
22
|
+
.match(@download_page)[:download_url]
|
23
|
+
end
|
24
|
+
|
25
|
+
def version
|
26
|
+
return @version unless @version.nil?
|
27
|
+
@version = /Newest File: (?<version>.+)</.match(@main_page)[:version]
|
28
|
+
end
|
29
|
+
|
30
|
+
def name
|
31
|
+
return @name unless @name.nil?
|
32
|
+
@name = Regexp.new('Main Title -->\s*<H2 >\s*(?<name>.+)</H2>').match(@main_page)[:name]
|
33
|
+
end
|
34
|
+
|
35
|
+
private :download_page, :download_url
|
36
|
+
end
|
37
|
+
end
|
@@ -2,32 +2,36 @@ require 'open-uri'
|
|
2
2
|
require 'logging'
|
3
3
|
|
4
4
|
module Spigoter
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
# Class that represent a devBukkit plugin.
|
6
|
+
# @author Daniel Ramos Acosta <danielramosacosta@hotmail.com>
|
7
|
+
class PluginBukkit < Plugin
|
8
|
+
def initialize(website)
|
9
|
+
raise "Bad URL #{website}" if website.match(%r{http://dev.bukkit.org/bukkit-plugins/[a-z\-]+/?}).nil?
|
10
|
+
super(website)
|
11
|
+
end
|
8
12
|
|
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
|
-
end
|
13
|
+
def download_page
|
14
|
+
return @download_page unless @download_page.nil?
|
15
|
+
matches = @main_page.match(/"user-action user-action-download">\s+<a href="(?<download_page_url>.+)">Download/)
|
16
|
+
url_download_page = matches[:download_page_url]
|
17
|
+
@download_page = open("http://dev.bukkit.org/#{url_download_page}").read
|
18
|
+
end
|
19
|
+
|
20
|
+
def download_url
|
21
|
+
return @download_url unless @download_url.nil?
|
22
|
+
download_page
|
23
|
+
@download_url = /href="(?<download_url>.+)">Download/.match(@download_page)[:download_url]
|
24
|
+
end
|
25
|
+
|
26
|
+
def version
|
27
|
+
return @version unless @version.nil?
|
28
|
+
download_page
|
29
|
+
@version = %r{3">\s*<h1>\s+(?<version>.+)\s+</h1>}.match(@download_page)[:version]
|
30
|
+
end
|
31
|
+
|
32
|
+
def name
|
33
|
+
return @name unless @name.nil?
|
34
|
+
@name = %r{</div>\s*<h1>\s*(?<name>.+)\s*</h1>\s*</header>}.match(@main_page)[:name]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -2,28 +2,40 @@ require 'open-uri'
|
|
2
2
|
require 'logging'
|
3
3
|
|
4
4
|
module Spigoter
|
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
|
-
|
5
|
+
# Generalized plugin.
|
6
|
+
# @author Daniel Ramos Acosta <danielramosacosta@hotmail.com>
|
7
|
+
class Plugin
|
8
|
+
def initialize(website)
|
9
|
+
@url = website # Url of the plugin
|
10
|
+
# @main_page # Mainpage content
|
11
|
+
# @name # Name of the plugin
|
12
|
+
# @download_page # Content of the download page
|
13
|
+
# @download_url # Download url of the plugin
|
14
|
+
# @regexp # Regexp that matches the URL
|
15
|
+
# @file # Where the file is stored
|
16
|
+
main_page # preload main_page
|
17
|
+
end
|
18
|
+
|
19
|
+
def main_page
|
20
|
+
return @main_page unless @main_page.nil?
|
21
|
+
@main_page = Spigoter::Utils.download(@url)
|
22
|
+
end
|
23
|
+
|
24
|
+
def download_url
|
25
|
+
@url # Dummy method, just to test
|
26
|
+
end
|
27
|
+
|
28
|
+
def file
|
29
|
+
return @file unless @file.nil?
|
30
|
+
@file = Spigoter::Utils.download(download_url) # download_url is implemented in child class
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.list
|
34
|
+
{
|
35
|
+
curse: Spigoter::PluginCurse,
|
36
|
+
devbukkit: Spigoter::PluginBukkit,
|
37
|
+
spigot: Spigoter::PluginSpigot
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'logging'
|
3
|
+
|
4
|
+
module Spigoter
|
5
|
+
# Class that represent a devBukkit plugin.
|
6
|
+
# @author Daniel Ramos Acosta <danielramosacosta@hotmail.com>
|
7
|
+
class PluginSpigot < Plugin
|
8
|
+
def initialize(website)
|
9
|
+
raise "Bad URL #{website}" if website.match(%r{https://www.spigotmc.org/resources/[a-z0-9\-]+/?}).nil?
|
10
|
+
super(website)
|
11
|
+
end
|
12
|
+
|
13
|
+
def download_url
|
14
|
+
return @download_url unless @download_url.nil?
|
15
|
+
uri = /<a href="(?<download_url>resources.+)" class="inner">/.match(@main_page)[:download_url]
|
16
|
+
@download_url = "https://www.spigotmc.org/#{uri}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def version
|
20
|
+
return @version unless @version.nil?
|
21
|
+
@version = %r{class="muted">(?<version>.+)</span>}.match(@main_page)[:version]
|
22
|
+
end
|
23
|
+
|
24
|
+
def name
|
25
|
+
return @name unless @name.nil?
|
26
|
+
@name = /<h1>(?<name>.+?)\s*<span class="muted">/.match(@main_page)[:name]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/spigoter.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spigoter/version'
|
2
|
+
require 'spigoter/log/log'
|
3
3
|
require 'spigoter/utils'
|
4
|
-
require 'spigoter/plugins'
|
5
4
|
require 'spigoter/webapi/plugin'
|
6
5
|
require 'spigoter/webapi/curse'
|
7
6
|
require 'spigoter/webapi/devbukkit'
|
7
|
+
require 'spigoter/webapi/spigot'
|
8
8
|
require 'spigoter/cli/cli'
|
9
9
|
require 'spigoter/cli/cli_update'
|
10
10
|
require 'spigoter/cli/cli_compile'
|
11
11
|
require 'spigoter/cli/cli_start'
|
12
|
+
require 'spigoter/cli/cli_init'
|
12
13
|
|
13
14
|
module Spigoter
|
14
|
-
|
15
|
+
SPIGOT_VERSION = 'latest'.freeze
|
15
16
|
end
|
data/spigoter.gemspec
CHANGED
@@ -14,6 +14,8 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.homepage = "https://github.com/DanielRamosAcosta/spigoter"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
|
+
spec.required_ruby_version = '>= 2.2.4'
|
18
|
+
|
17
19
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
20
|
# delete this section to allow pushing this gem to any host.
|
19
21
|
if spec.respond_to?(:metadata)
|
@@ -36,6 +38,7 @@ Gem::Specification.new do |spec|
|
|
36
38
|
spec.add_development_dependency "coveralls", "~> 0.8"
|
37
39
|
spec.add_development_dependency "yard", "~> 0.8"
|
38
40
|
spec.add_development_dependency "codeclimate-test-reporter", "~> 0.5.0"
|
41
|
+
spec.add_development_dependency "rubocop", "~> 0.39.0"
|
39
42
|
|
40
43
|
spec.add_runtime_dependency "logging", "~> 2.1"
|
41
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spigoter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Ramos
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: 0.5.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.39.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.39.0
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: logging
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -159,6 +173,7 @@ extensions: []
|
|
159
173
|
extra_rdoc_files: []
|
160
174
|
files:
|
161
175
|
- ".codeclimate.yml"
|
176
|
+
- ".editorconfig"
|
162
177
|
- ".gitignore"
|
163
178
|
- ".rspec"
|
164
179
|
- ".rubocop.yml"
|
@@ -175,15 +190,16 @@ files:
|
|
175
190
|
- lib/spigoter.rb
|
176
191
|
- lib/spigoter/cli/cli.rb
|
177
192
|
- lib/spigoter/cli/cli_compile.rb
|
193
|
+
- lib/spigoter/cli/cli_init.rb
|
178
194
|
- lib/spigoter/cli/cli_start.rb
|
179
195
|
- lib/spigoter/cli/cli_update.rb
|
180
196
|
- lib/spigoter/log/log.rb
|
181
|
-
- lib/spigoter/plugins.rb
|
182
197
|
- lib/spigoter/utils.rb
|
183
198
|
- lib/spigoter/version.rb
|
184
199
|
- lib/spigoter/webapi/curse.rb
|
185
200
|
- lib/spigoter/webapi/devbukkit.rb
|
186
201
|
- lib/spigoter/webapi/plugin.rb
|
202
|
+
- lib/spigoter/webapi/spigot.rb
|
187
203
|
- pkg/.gitignore
|
188
204
|
- spigoter.gemspec
|
189
205
|
- tmp/.gitignore
|
@@ -200,7 +216,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
200
216
|
requirements:
|
201
217
|
- - ">="
|
202
218
|
- !ruby/object:Gem::Version
|
203
|
-
version:
|
219
|
+
version: 2.2.4
|
204
220
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
221
|
requirements:
|
206
222
|
- - ">="
|
data/lib/spigoter/plugins.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module Spigoter
|
2
|
-
module Plugins
|
3
|
-
def self.get_plugin(name, data)
|
4
|
-
f = nil
|
5
|
-
case data['type']
|
6
|
-
when 'curse'
|
7
|
-
f = Spigoter::PluginCurse.new(data['url']).file
|
8
|
-
when 'devbukkit'
|
9
|
-
f = Spigoter::PluginBukkit.new(data['url']).file
|
10
|
-
else
|
11
|
-
raise "Unkown source"
|
12
|
-
end
|
13
|
-
hash = {:name => "#{name}.jar", :file => f}
|
14
|
-
return hash
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|