bukin 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -34,8 +34,15 @@ You can specify specific versions of a plugin or server to install. Craftbukkit
34
34
  plugin 'worldedit', '5.5.5'
35
35
  plugin 'worldguard', '5.7.3'
36
36
 
37
+ By default, bukin will try to download jar files from bukkit dev. If only zip files are available, it will automatically extract all jar files from it. If you want to specify what files are extracted from a zip file, use the `extract` option. It takes a [ruby regular expression](http://ruby-doc.org/core-1.9.3/Regexp.html) used to match file names in the zip file.
38
+
39
+ plugin 'permissionsex', '1.19.5', :extract => /PermissionsEx.*\.jar/
40
+
41
+ Plugins or servers can also be downloaded from Jenkins. Just specify the base url for Jenkins and a [ruby regular expression](http://ruby-doc.org/core-1.9.3/Regexp.html) matching the file you want to download. If no file is specified, bukin will download the first one listed.
42
+
43
+ server 'spigot', 'build-844', :jenkins => 'http://ci.md-5.net', :file => /spigot\.jar/
44
+
37
45
  Need something custom? Use the `download` option. Version is optional but will display when the plugin is downloading.
38
46
 
39
- server 'craftbukkit', 'spigot-735', download: 'http://ci.md-5.net/job/Spigot/735/artifact/Spigot-Server/target/spigot.jar'
40
- plugin 'mycustomplugin', '2.4', download: 'http://example.com/My-Custom-Plugin.jar'
47
+ plugin 'mycustomplugin', '2.4', :download => 'http://example.com/My-Custom-Plugin.jar'
41
48
 
@@ -30,7 +30,7 @@ class Bukin::Bukfile
30
30
  options = args.last.is_a?(Hash) ? args.pop : {}
31
31
  version = args.pop || nil
32
32
 
33
- @server_info = { name: name, version: version }.merge(options)
33
+ @server_info = { :name => name, :version => version }.merge(options)
34
34
  end
35
35
 
36
36
  def plugin(name, *args)
@@ -41,6 +41,6 @@ class Bukin::Bukfile
41
41
  options = args.last.is_a?(Hash) ? args.pop : {}
42
42
  version = args.pop || nil
43
43
 
44
- @plugins_info << { name: name, version: version }.merge(options)
44
+ @plugins_info << { :name => name, :version => version }.merge(options)
45
45
  end
46
46
  end
@@ -3,6 +3,8 @@ require 'bukin/installer'
3
3
  require 'bukin/bukfile'
4
4
  require 'bukin/providers/bukget'
5
5
  require 'bukin/providers/bukkit_dl'
6
+ require 'bukin/providers/direct_dl'
7
+ require 'bukin/providers/jenkins'
6
8
 
7
9
  class Bukin::CLI < Thor
8
10
 
@@ -17,20 +19,58 @@ class Bukin::CLI < Thor
17
19
  plugins = bukfile.plugins_info
18
20
 
19
21
  # Grab information from the various providers
22
+ direct_dl = Bukin::DirectDl.new
23
+ jenkins = Bukin::Jenkins.new
20
24
  bukkit_dl = Bukin::BukkitDl.new
21
25
  bukget = Bukin::Bukget.new
22
26
 
23
- section "Fetching information from #{bukkit_dl.url}" do
24
- bukkit_dl.resolve_info(server)
27
+ # Server info
28
+ if direct_dl.usable(server)
29
+ direct_dl.resolve_info(server)
30
+ elsif jenkins.usable(server)
31
+ section "Fetching information from #{jenkins.url(server)}" do
32
+ jenkins.resolve_info(server)
33
+ end
34
+ else
35
+ section "Fetching information from #{bukkit_dl.url}" do
36
+ bukkit_dl.resolve_info(server)
37
+ end
38
+ end
39
+
40
+ # Plugins info
41
+ direct_dl_plugins = []
42
+ jenkins_plugins = []
43
+ bukget_plugins = []
44
+
45
+ plugins.each do |plugin|
46
+ if direct_dl.usable(plugin)
47
+ direct_dl_plugins << plugin
48
+ elsif jenkins.usable(plugin)
49
+ jenkins_plugins << plugin
50
+ else
51
+ bukget_plugins << plugin
52
+ end
53
+ end
54
+
55
+ direct_dl_plugins.each do |plugin|
56
+ direct_dl.resolve_info(plugin)
57
+ end
58
+
59
+ jenkins_plugins.each do |plugin|
60
+ section "Fetching information from #{jenkins.url(plugin)}" do
61
+ jenkins.resolve_info(plugin)
62
+ end
25
63
  end
26
64
 
27
65
  section "Fetching information from #{bukget.url}" do
28
- plugins.map do |plugin|
29
- plugin[:server] ||= server[:name]
30
- begin
31
- bukget.resolve_info(plugin)
32
- rescue OpenURI::HTTPError => ex
33
- raise Bukin::BukinError, "There was an error downloading #{plugin[:name]} (#{plugin[:version]}).\n#{ex.message}"
66
+ bukget_plugins.each do |plugin|
67
+ plugins.each do |plugin|
68
+ plugin[:server] ||= 'craftbukkit'
69
+ begin
70
+ bukget.resolve_info(plugin)
71
+ rescue OpenURI::HTTPError => ex
72
+ raise Bukin::BukinError, "There was an error downloading #{plugin[:name]} (#{plugin[:version]}).\n#{ex.message}"
73
+ end
34
74
  end
35
75
  end
36
76
  end
@@ -39,12 +79,12 @@ class Bukin::CLI < Thor
39
79
  installer = Bukin::Installer.new(Dir.pwd, true)
40
80
 
41
81
  downloading server[:name], server[:display_version] do
42
- installer.install(:server, bukkit_dl, server)
82
+ installer.install(:server, server)
43
83
  end
44
84
 
45
85
  plugins.each do |plugin|
46
86
  downloading plugin[:name], plugin[:version] do
47
- installer.install(:plugin, bukget, plugin)
87
+ installer.install(:plugin, plugin)
48
88
  end
49
89
  end
50
90
  end
@@ -7,10 +7,10 @@ class Bukin::Installer
7
7
  if use_lockfile
8
8
  @lockfile = Bukin::Lockfile.new
9
9
  end
10
- @paths = { server: path, plugin: "#{path}/plugins" }
10
+ @paths = { :server => path, :plugin => "#{path}/plugins" }
11
11
  end
12
12
 
13
- def install(type, provider, data)
13
+ def install(type, data)
14
14
  unless @paths.keys.include?(type)
15
15
  raise(ArgumentError, "You must specify one of the following types to install: #{@paths.keys.to_s}")
16
16
  end
@@ -41,12 +41,12 @@ class Bukin::Installer
41
41
 
42
42
  def extract_files(file_data, path, match)
43
43
  file_names = []
44
- file = Tempfile.new('bukin')
44
+ tempfile = Tempfile.new('bukin')
45
45
  begin
46
- file.write(file_data)
47
- file.close
46
+ tempfile.write(file_data)
47
+ tempfile.close
48
48
 
49
- Zip::ZipFile.open(file.path) do |zipfile|
49
+ Zip::ZipFile.open(tempfile.path) do |zipfile|
50
50
  jars = zipfile.find_all {|file| file.name =~ match}
51
51
  jars.each do |file|
52
52
  file.extract(path + '/' + file.name) { true }
@@ -54,8 +54,8 @@ class Bukin::Installer
54
54
  end
55
55
  end
56
56
  ensure
57
- file.close
58
- file.unlink
57
+ tempfile.close
58
+ tempfile.unlink
59
59
  end
60
60
  file_names
61
61
  end
@@ -15,11 +15,6 @@ class Bukin::BukkitDl
15
15
  end
16
16
 
17
17
  def resolve_info(data)
18
- if data[:download]
19
- data[:display_version] = data[:version]
20
- return data
21
- end
22
-
23
18
  name = data[:name]
24
19
  version = data[:version] || 'latest-rb'
25
20
 
@@ -0,0 +1,12 @@
1
+
2
+ # Api for direct downloads
3
+ class Bukin::DirectDl
4
+ def usable(data)
5
+ !!data[:download]
6
+ end
7
+
8
+ def resolve_info(data)
9
+ data[:display_version] = data[:version]
10
+ data
11
+ end
12
+ end
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+
3
+ # Api for downloading from jenkins
4
+ class Bukin::Jenkins
5
+
6
+ def usable(data)
7
+ !!data[:jenkins]
8
+ end
9
+
10
+ def url(data)
11
+ data[:jenkins]
12
+ end
13
+
14
+ def resolve_info(data)
15
+ name = data[:name]
16
+ version = data[:version] || 'lastSuccessfulBuild'
17
+
18
+ if version =~ /^build-(.*)$/
19
+ base_path = "#{data[:jenkins]}/job/#{name}/#{$1}"
20
+ url = "#{base_path}/api/json"
21
+ info = JSON.parse(open(url).read)
22
+
23
+ download_info = if data[:file]
24
+ info['artifacts'].find do |artifact|
25
+ artifact['fileName'] =~ data[:file]
26
+ end
27
+ else
28
+ info['artifacts'].first
29
+ end
30
+
31
+ data[:version] = data[:display_version] = version
32
+ data[:download] = "#{base_path}/artifact/#{download_info['relativePath']}"
33
+ else
34
+ raise Bukin::InstallError, "The plugin #{name} (#{version}) has an improper version format for downloading from Jenkins. It should be in the form of 'build-<number>'"
35
+ end
36
+ data
37
+ end
38
+ end
@@ -11,12 +11,11 @@ end
11
11
  def download_file(url, content_disposition = false)
12
12
  open(url, "User-Agent" => "Bukin #{Bukin::VERSION}") do |download|
13
13
  file_name = if download.meta['content-disposition']
14
- download.meta['content-disposition']
15
- .match(/filename=(\"?)(.+)\1/)[2]
16
- .force_encoding("UTF-8")
14
+ download.meta['content-disposition'].match(/filename=(\"?)(.+)\1/)[2]
17
15
  else
18
16
  File.basename(url)
19
17
  end
18
+ file_name = file_name.force_encoding('UTF-8') if file_name.respond_to?(:force_encoding)
20
19
  data = download.read
21
20
  return data, file_name
22
21
  end
@@ -1,3 +1,3 @@
1
1
  module Bukin
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bukin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-06 00:00:00.000000000 Z
12
+ date: 2013-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -83,6 +83,8 @@ files:
83
83
  - lib/bukin/lockfile.rb
84
84
  - lib/bukin/providers/bukget.rb
85
85
  - lib/bukin/providers/bukkit_dl.rb
86
+ - lib/bukin/providers/direct_dl.rb
87
+ - lib/bukin/providers/jenkins.rb
86
88
  - lib/bukin/utils.rb
87
89
  - lib/bukin/version.rb
88
90
  homepage: http://github.com/Nullreff/bukin