wonko_the_sane 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/bin/wonko_the_sane +12 -28
  3. data/data/sources.json +0 -5
  4. data/lib/wonko_the_sane.rb +6 -26
  5. data/lib/wonko_the_sane/input/base_input.rb +5 -10
  6. data/lib/wonko_the_sane/input/forge_installer_profile_input.rb +29 -47
  7. data/lib/wonko_the_sane/input/forgefiles_mods_input.rb +4 -7
  8. data/lib/wonko_the_sane/input/jenkins_input.rb +11 -15
  9. data/lib/wonko_the_sane/input/mojang_input.rb +52 -61
  10. data/lib/wonko_the_sane/{reader_writer.rb → new_format.rb} +31 -35
  11. data/lib/wonko_the_sane/old_format.rb +123 -0
  12. data/lib/wonko_the_sane/registry.rb +38 -23
  13. data/lib/wonko_the_sane/rules.rb +6 -6
  14. data/lib/wonko_the_sane/timestamps.rb +4 -4
  15. data/lib/wonko_the_sane/tools/update_nem.rb +20 -18
  16. data/lib/wonko_the_sane/util/configuration.rb +54 -2
  17. data/lib/wonko_the_sane/util/deep_storage_cache.rb +10 -8
  18. data/lib/wonko_the_sane/util/extraction_cache.rb +5 -4
  19. data/lib/wonko_the_sane/util/file_hash_cache.rb +6 -6
  20. data/lib/wonko_the_sane/util/http_cache.rb +50 -105
  21. data/lib/wonko_the_sane/util/maven_identifier.rb +8 -14
  22. data/lib/wonko_the_sane/util/task_stack.rb +7 -6
  23. data/lib/wonko_the_sane/{version_parser.rb → util/version_parser.rb} +10 -14
  24. data/lib/wonko_the_sane/version.rb +1 -1
  25. data/lib/wonko_the_sane/versionlists/base_version_list.rb +22 -15
  26. data/lib/wonko_the_sane/versionlists/curse_version_list.rb +15 -16
  27. data/lib/wonko_the_sane/versionlists/forge_version_list.rb +34 -37
  28. data/lib/wonko_the_sane/versionlists/forgefiles_mods_list.rb +3 -7
  29. data/lib/wonko_the_sane/versionlists/jenkins_version_list.rb +6 -15
  30. data/lib/wonko_the_sane/versionlists/liteloader_version_list.rb +18 -28
  31. data/lib/wonko_the_sane/versionlists/vanilla_legacy_version_list.rb +6 -6
  32. data/lib/wonko_the_sane/versionlists/vanilla_version_list.rb +6 -8
  33. data/lib/wonko_the_sane/wonko_version.rb +32 -12
  34. metadata +71 -15
  35. data/lib/wonko_the_sane/wonkoweb_uploader.rb +0 -162
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40c75f8cc35f2cedea382f8b22f0373f9199ab60
4
- data.tar.gz: 419906fc73b134f8ddc6d994d2bab5ec8d277840
3
+ metadata.gz: 7aa648a065bfbc6fea0c7f581308ae4466a578fb
4
+ data.tar.gz: b7049aa48d98789256ce1cb5142553f43e29a34e
5
5
  SHA512:
6
- metadata.gz: bcba25e623bf105bc2aa37d9572e3a542ffc58c4eaa30f50d8dc576aa6af10a9472175736e4460687d24564e977070de45935b037001b39be6b7f2ea972f3a25
7
- data.tar.gz: 52fd86ab7abd1262bf6b2096ef67e89a83641157b8fb9106787a2d71d4916d17bf85f1d0cecf369b64e0c8b6baa126c51302a84f281549851f32179744553e0c
6
+ metadata.gz: e3140975588a58455426f638079786fed82ef3e0a525811ed11f0117083a2e8da6095806fc0bce1586f9c32f858cb202f9024d90a9535b80696687df71cb45b8
7
+ data.tar.gz: 400710a7384eb938b851c8c018746d3fbc0b3ffe57e0c070b82cf559d270aea6d69212cbe62ed3bc041fb393d6369b475aefbd69109e42908a5cb92314788872
data/bin/wonko_the_sane CHANGED
@@ -34,40 +34,34 @@ OptionParser.new do |opts|
34
34
  opts.banner = 'Usage: main.rb [options]'
35
35
 
36
36
  opts.on '-rID', '--refresh=ID', 'Refresh the specified list' do |id|
37
- foundList = false
38
- WonkoTheSane.lists.each do |list|
39
- if list.artifact == id
37
+ list = WonkoTheSane.lists.find { |l| l.artifact == id }
38
+ if list.nil?
39
+ Logging.logger['General'].warn "Couldn't find the specified list #{id.cyan}"
40
+ else
40
41
  TaskStack.push(Proc.new do
41
42
  Logging.logger[list.artifact].info 'Refreshing'
42
43
  list.refresh
43
- Logging.logger[list.artifact].error list.lastError if list.lastError
44
+ Logging.logger[list.artifact].error list.last_error if list.last_error
44
45
  end)
45
- foundList = true
46
- end
47
46
  end
48
-
49
- Logging.logger['General'].warn "Couldn't find the specified list #{id.cyan}" if !foundList
50
47
  end
51
48
  opts.on '-a', '--refresh-all', 'Refresh all lists' do
52
49
  WonkoTheSane.lists.each do |list|
53
50
  TaskStack.push(Proc.new do
54
51
  Logging.logger[list.artifact].info 'Refreshing'
55
52
  list.refresh
56
- Logging.logger[list.artifact].error list.lastError if list.lastError
53
+ Logging.logger[list.artifact].error list.last_error if list.last_error
57
54
  end)
58
55
  end
59
56
  end
60
57
  opts.on '--invalidate=ID', 'Invalidates all versions on the specified list' do |id|
61
- foundList = false
62
- WonkoTheSane.lists.each do |list|
63
- if list.artifact == id
64
- Logging.logger[list.artifact].info 'Invalidating'
65
- list.invalidate
66
- foundList = true
67
- end
58
+ list = WonkoTheSane.lists.find { |l| l.artifact == id }
59
+ if list.nil?
60
+ Logging.logger['General'].warn "Couldn't find the specified list #{id.cyan}"
61
+ else
62
+ Logging.logger[list.artifact].info 'Invalidating'
63
+ list.invalidate
68
64
  end
69
-
70
- Logging.logger['General'].warn "Couldn't find the specified list #{id.cyan}" if !foundList
71
65
  end
72
66
  opts.on '--invalidate-all', 'Invalidates all versions on all lists' do
73
67
  WonkoTheSane.lists.each do |list|
@@ -83,15 +77,6 @@ OptionParser.new do |opts|
83
77
  opts.on '--update-nem', 'Updates sources.json with data from NEM' do
84
78
  update_nem
85
79
  end
86
- opts.on '--set-config=VAL', 'Sets a configuration value' do |val|
87
- parts = val.match /([^:=]*)([:=](.*))?/
88
- if parts.length == 4 && !parts[3].nil?
89
- Settings[parts[1]] = parts[3]
90
- else
91
- Settings.delete parts[1]
92
- end
93
- Settings.save! WonkoTheSane.settings_file
94
- end
95
80
  opts.on '-h', '--help', 'Prints this help' do
96
81
  puts opts
97
82
  exit
@@ -99,4 +84,3 @@ OptionParser.new do |opts|
99
84
  end.parse!
100
85
 
101
86
  TaskStack.pop_all
102
- WonkoTheSane.wonkoweb_uploader.upload_changes!
data/data/sources.json CHANGED
@@ -171,11 +171,6 @@
171
171
  "url": "http://jamesmckay.id.au:8080",
172
172
  "artifact": "Power%20Converters"
173
173
  },
174
- {
175
- "uid": "galacticraft",
176
- "url": "http://ci.micdoodle8.com:8080",
177
- "artifact": "Galacticraft-1.7"
178
- },
179
174
  {
180
175
  "uid": "artifice",
181
176
  "url": "http://76.72.175.100:8080",
@@ -10,9 +10,8 @@ require 'digest'
10
10
  require 'date'
11
11
  require 'time'
12
12
  require 'oga'
13
- require 'configliere'
14
- require 'httparty'
15
13
  require 'active_support/core_ext/hash/indifferent_access'
14
+ require 'active_support/core_ext/object/blank'
16
15
 
17
16
  require 'wonko_the_sane/version'
18
17
  require 'wonko_the_sane/tools/update_nem'
@@ -24,6 +23,7 @@ require 'wonko_the_sane/util/file_hash_cache'
24
23
  require 'wonko_the_sane/util/http_cache'
25
24
  require 'wonko_the_sane/util/maven_identifier'
26
25
  require 'wonko_the_sane/util/task_stack'
26
+ require 'wonko_the_sane/util/version_parser'
27
27
 
28
28
  require 'wonko_the_sane/input/base_input'
29
29
  require 'wonko_the_sane/input/forge_installer_profile_input'
@@ -40,13 +40,12 @@ require 'wonko_the_sane/versionlists/liteloader_version_list'
40
40
  require 'wonko_the_sane/versionlists/vanilla_legacy_version_list'
41
41
  require 'wonko_the_sane/versionlists/vanilla_version_list'
42
42
 
43
- require 'wonko_the_sane/wonkoweb_uploader'
44
- require 'wonko_the_sane/reader_writer'
43
+ require 'wonko_the_sane/new_format'
44
+ require 'wonko_the_sane/old_format'
45
45
  require 'wonko_the_sane/registry'
46
46
  require 'wonko_the_sane/rules'
47
47
  require 'wonko_the_sane/timestamps'
48
48
  require 'wonko_the_sane/version_index'
49
- require 'wonko_the_sane/version_parser'
50
49
  require 'wonko_the_sane/wonko_version'
51
50
 
52
51
  module WonkoTheSane
@@ -82,26 +81,7 @@ module WonkoTheSane
82
81
  def self.configuration
83
82
  @configuration ||= Util::Configuration.new
84
83
  end
85
- private_class_method :configuration
86
84
  end
87
85
 
88
- Settings.use :config_block, :encrypted, :prompt, :define
89
- Settings({
90
- aws: {
91
- client_id: nil,
92
- client_secret: nil
93
- },
94
- wonkoweb: {
95
- host: nil,
96
- email: nil,
97
- token: nil
98
- }
99
- })
100
- Settings.define 'aws.client_id', encrypted: true
101
- Settings.define 'aws.client_secret', encrypted: true
102
- Settings.define 'wonkoweb.host'
103
- Settings.define 'wonkoweb.name'
104
- Settings.define 'wonkoweb.token', encrypted: true
105
- Settings.read WonkoTheSane.settings_file
106
- Settings[:encrypt_pass] = ENV['ENCRYPT_PASS'] || (print 'Password: '; pwd = STDIN.noecho(&:gets).chomp; puts; pwd)
107
- Settings.resolve!
86
+ WonkoTheSane.configuration.load_from_file 'wts.yml' if File.exists? 'wts.yml'
87
+ WonkoTheSane.configuration.load_from_env
@@ -14,7 +14,6 @@ class BaseSanitizer
14
14
  sanitizers.each do |sanitizer|
15
15
  tmp = []
16
16
  output.each do |file|
17
- #puts "Running #{sanitizer.to_s} on #{file.id}"
18
17
  result = sanitizer.sanitize(file.clone)
19
18
  if result.is_a? Array
20
19
  tmp = tmp + result
@@ -24,29 +23,25 @@ class BaseSanitizer
24
23
  end
25
24
  output = tmp
26
25
  end
27
- return output
26
+ output
28
27
  end
29
28
  end
30
29
 
31
30
  class DownloadsFixer < BaseSanitizer
32
31
  def self.sanitize(file)
33
32
  file.client.downloads.map! do |download|
34
- if not download.size or not download.sha256 or download.sha256 == ''
35
- url = download.internalUrl ? download.internalUrl : download.url
36
- info = WonkoTheSane::Util::DeepStorageCache.get_info url, ctxt: file.uid
33
+ if !download.size || download.sha256.blank?
34
+ info = WonkoTheSane::Util::DeepStorageCache.get_info download.usable_url, ctxt: file.uid
37
35
  download.size = info[:size]
38
36
  download.sha256 = info[:sha256]
39
- download
40
37
  end
41
38
  download
42
39
  end
43
40
  file.server.downloads.map! do |download|
44
- if not download.size or not download.sha256 or download.sha256 == ''
45
- url = download.internalUrl ? download.internalUrl : download.url
46
- info = WonkoTheSane::Util::DeepStorageCache.get_info url, ctxt: file.uid
41
+ if !download.size || download.sha256.blank?
42
+ info = WonkoTheSane::Util::DeepStorageCache.get_info download.usable_url, ctxt: file.uid
47
43
  download.size = info[:size]
48
44
  download.sha256 = info[:sha256]
49
- download
50
45
  end
51
46
  download
52
47
  end
@@ -16,9 +16,7 @@ class ForgeInstallerProfileInput < BaseInput
16
16
  file.client.minecraftArguments = info[:minecraftArguments]
17
17
  file.client.assets = info[:assets]
18
18
  file.requires << Referenced.new('net.minecraft', object[:install][:minecraft])
19
- libraries = info[:libraries].map do |obj|
20
- MojangInput.sanetize_mojang_library obj
21
- end.flatten 1
19
+ libraries = info[:libraries].map { |obj| MojangInput.sanitize_mojang_library obj }.flatten 1
22
20
  file.client.downloads = libraries
23
21
  file.common.folders['minecraft/mods'] = ['mc.forgemods']
24
22
  file.common.folders['minecraft/mods'] << 'mc.forgecoremods' if object[:install][:minecraft].match /[^1]*1\.[0-6]/
@@ -27,7 +25,13 @@ class ForgeInstallerProfileInput < BaseInput
27
25
  file.server.launchMethod = 'java.mainClass'
28
26
  file.server.extra[:forgeLibraryName] = %W(net.minecraftforge:forge:#{object[:install][:minecraft]}-#{version}:universal net.minecraftforge:forge:#{object[:install][:minecraft]}-#{version} net.minecraftforge:forge:#{version}:universal net.minecraftforge:forge:#{version} net.minecraftforge:minecraftforge:#{object[:install][:minecraft]}-#{version}:universal net.minecraftforge:minecraftforge:#{object[:install][:minecraft]}-#{version} net.minecraftforge:minecraftforge:#{version}:universal net.minecraftforge:minecraftforge:#{version})
29
27
 
30
- return BaseSanitizer.sanitize file, MojangExtractTweakersSanitizer, MojangSplitLWJGLSanitizer, ForgeRemoveMinecraftSanitizer, ForgeFixJarSanitizer, ForgePackXZUrlsSanitizer, ForgeServerMainClassSanitizer
28
+ BaseSanitizer.sanitize file,
29
+ MojangExtractTweakersSanitizer,
30
+ MojangSplitLWJGLSanitizer,
31
+ ForgeRemoveMinecraftSanitizer,
32
+ ForgeFixJarSanitizer,
33
+ ForgePackXZUrlsSanitizer,
34
+ ForgeServerMainClassSanitizer
31
35
  end
32
36
  end
33
37
 
@@ -36,17 +40,12 @@ class ForgeFixJarSanitizer < BaseSanitizer
36
40
  file.client.downloads.map! do |lib|
37
41
  ident = WonkoTheSane::Util::MavenIdentifier.new(lib.name)
38
42
  ident.artifact = 'forge' if 'net.minecraftforge' == ident.group && 'minecraftforge' == ident.artifact
39
- if ['forge', 'fml'].include?(ident.artifact) && ['net.minecraftforge', 'cpw.mods'].include?(ident.group)
40
- mcversion = nil
41
- file.requires.each do |req|
42
- if req.uid == 'net.minecraft'
43
- mcversion = req.version
44
- end
45
- end
43
+ if %w(forge fml).include?(ident.artifact) && %w(net.minecraftforge cpw.mods).include?(ident.group)
44
+ mcversion = file.requires.find { |r| r.uid == 'net.minecraft' }.version rescue nil
46
45
  lib = lib.clone
47
46
  ident.classifier = 'universal'
48
47
  ident.version = "#{mcversion}-#{ident.version}" unless ident.version.start_with? "#{mcversion}"
49
- lib.name = ident.to_name()
48
+ lib.name = ident.to_name
50
49
  end
51
50
  lib
52
51
  end
@@ -59,53 +58,41 @@ class ForgeRemoveMinecraftSanitizer < BaseSanitizer
59
58
  def self.sanitize(file)
60
59
  return nil if file.uid == 'org.lwjgl' # remove lwjgl, it's managed by minecraft
61
60
  return file if file.uid != 'net.minecraftforge'
62
- mcversion = nil
63
- file.requires.each do |req|
64
- if req.uid == 'net.minecraft'
65
- mcversion = req.version
66
- end
67
- end
61
+ mcversion = file.requires.find { |r| r.uid == 'net.minecraft' }.version rescue nil
62
+
68
63
  minecraft = Registry.instance.retrieve 'net.minecraft', mcversion
69
- if not minecraft
64
+ if minecraft.nil?
70
65
  # if we can't find the wanted version on the first try we try reloading the list to see if we get something
71
- WonkoTheSane.lists.each do |list|
72
- list.refresh if list.artifact == 'net.minecraft'
73
- end
66
+ WonkoTheSane.lists.find { |l| l.artifact == 'net.minecraft' }.refresh
74
67
  minecraft = Registry.instance.retrieve 'net.minecraft', mcversion
75
68
  end
69
+
76
70
  if minecraft
77
71
  file.client.mainClass = nil if minecraft.client.mainClass == file.client.mainClass
78
72
  file.client.minecraftArguments = nil if minecraft.client.minecraftArguments == file.client.minecraftArguments
79
73
  file.client.assets = nil if minecraft.client.assets == file.client.assets
80
- file.client.downloads.select! do |lib|
81
- nil == minecraft.client.downloads.find do |mcLib|
82
- lib.name == mcLib.name
83
- end
74
+ file.client.downloads.reject! do |lib|
75
+ minecraft.client.downloads.find { |mcLib| lib.name == mcLib.name } != nil
84
76
  end
85
- file.requires.select! do |req|
86
- if minecraft.requires
87
- nil == minecraft.requires.find do |mcReq|
88
- req == mcReq
89
- end
90
- else
91
- true
92
- end
77
+ file.requires.reject! do |req|
78
+ minecraft.requires.find { |mcReq| req == mcReq } != nil
93
79
  end
94
80
  else
95
81
  # don't know which version of minecraft this is, so we can't know which parts to eliminate
96
82
  end
83
+
97
84
  file
98
85
  end
99
86
  end
100
87
 
101
88
  class ForgePackXZUrlsSanitizer < BaseSanitizer
102
- @@packXZLibs = ['org.scala-lang', 'com.typesafe', 'com.typesafe.akka']
89
+ class << self; attr_accessor :pack_xz_libs; end
90
+ self.pack_xz_libs = ['org.scala-lang', 'com.typesafe', 'com.typesafe.akka']
103
91
 
104
92
  def self.sanitize(file)
105
93
  file.client.downloads.map! do |lib|
106
- if @@packXZLibs.include? WonkoTheSane::Util::MavenIdentifier.new(lib.name).group
107
- lib = lib.clone
108
- lib.mavenBaseUrl = 'http://repo.spongepowered.org/maven/'
94
+ if self.pack_xz_libs.include? WonkoTheSane::Util::MavenIdentifier.new(lib.name).group
95
+ lib.maven_base_url = 'http://repo.spongepowered.org/maven/'
109
96
  end
110
97
  lib
111
98
  end
@@ -117,16 +104,11 @@ class ForgeServerMainClassSanitizer < BaseSanitizer
117
104
  def self.sanitize(file)
118
105
  file.server.downloads.each do |download|
119
106
  if file.server.extra[:forgeLibraryName].include? download.name
120
- url = download.internalUrl ? download.internalUrl : download.url
121
- libFile = HTTPCache.file(url, ctxt: file.uid, check_stale: false)
107
+ lib_file = HTTPCache.file(download.usable_url, ctxt: file.uid, check_stale: false)
122
108
  # Handle entries one by one
123
- text = ExtractionCache.get(libFile, :zip, 'META-INF/MANIFEST.MF')
124
- lines = text.lines
125
- lines.each do |l|
126
- if l =~ /Main-Class: (.*)/
127
- file.server.mainClass = $1.strip
128
- end
129
- end
109
+ text = ExtractionCache.get(lib_file, :zip, 'META-INF/MANIFEST.MF')
110
+ match = text.lines.find { |l| l.match /Main-Class: (.*)/ }
111
+ file.server.mainClass = match[1] unless match.nil?
130
112
  end
131
113
  end
132
114
  file
@@ -9,22 +9,19 @@ class ForgeFilesModsInput < BaseInput
9
9
  file.uid = @artifact
10
10
  file.version = version
11
11
  file.time = data[:info]
12
+ file.requires << Referenced.new('net.minecraft', data[:mcver])
12
13
 
13
- f = data[:files].find do |file|
14
- type = file[:buildtype].downcase
15
- (file[:ext] == 'jar' or file[:ext] == 'zip') and (type == 'universal' or type == 'client' or type == 'main') #not type.include? 'src' and not type.include? 'deobf' and not type.include? 'api' and not type.include? 'backup'
16
- end
17
- if not f
14
+ f = data[:files].find { |f| %w(jar zip).include?(f[:ext]) && %(universal client main).include?(f[:buildtype].downcase) }
15
+ if f.nil?
18
16
  logger.warn 'No file found for ' + file.uid + ' version ' + file.version
19
17
  return []
20
18
  end
21
- file.requires << Referenced.new('net.minecraft', f[:mcver])
22
19
 
23
20
  dl = FileDownload.new
24
21
  dl.url = f[:url]
25
22
  dl.destination = "mods/#{file.uid}-#{file.version}.jar"
26
23
  file.common.downloads << dl
27
24
 
28
- return BaseSanitizer.sanitize file
25
+ BaseSanitizer.sanitize file
29
26
  end
30
27
  end
@@ -1,30 +1,27 @@
1
1
  class JenkinsInput < BaseInput
2
- def initialize(artifact, fileRegex)
2
+ def initialize(artifact, file_regex)
3
3
  @artifact = artifact
4
- @fileRegex = fileRegex
4
+ @file_regex = file_regex
5
5
  end
6
6
 
7
7
  def parse(data)
8
- if data[:result] != 'SUCCESS'
9
- return nil
10
- end
8
+ return nil if data[:result] != 'SUCCESS'
11
9
 
12
10
  file = WonkoVersion.new
13
-
14
11
  file.uid = @artifact
15
12
  file.version = data[:number].to_s
16
13
  file.time = data[:timestamp]
17
14
 
18
15
  artifact = data[:artifacts].find do |art|
19
16
  path = art[:fileName]
20
- if @fileRegex
21
- path.match @fileRegex
17
+ if @file_regex
18
+ path.match @file_regex
22
19
  else
23
- not path.include? '-api.' and not path.include? '-deobf.' and not path.include? '-dev.' and not path.include? '-javadoc.' and not path.include? '-library.' and not path.include? '-sources.' and not path.include? '-src.' and not path.include? '-util.'
20
+ %w(-api. -deobf. -dev. -javadoc. -library. -sources. -src. -util.).find { |infix| path.include? infix }.nil?
24
21
  end
25
22
  end
26
23
 
27
- if not artifact
24
+ if artifact.nil?
28
25
  logger.warn 'No valid artifact found for ' + file.version
29
26
  else
30
27
  dl = FileDownload.new
@@ -33,14 +30,13 @@ class JenkinsInput < BaseInput
33
30
  file.common.downloads << dl
34
31
  end
35
32
 
36
- return BaseSanitizer.sanitize file
33
+ BaseSanitizer.sanitize file
37
34
  end
38
35
 
39
36
  private
37
+
40
38
  def clean_url(url)
41
- if url[url.length - 1] == '/'
42
- url[url.length - 1] = ''
43
- end
44
- return url
39
+ url[url.length - 1] = '' if url[url.length - 1] == '/'
40
+ url
45
41
  end
46
42
  end
@@ -1,77 +1,72 @@
1
- def allowedPlatformsForRules(rules)
1
+ def allowed_platforms_for_rules(rules)
2
2
  possible = ['win32', 'win64', 'lin32', 'lin64', 'osx64']
3
3
 
4
4
  allowed = possible
5
5
  if rules
6
6
  rules.each do |rule|
7
- if rule.action == :allow
8
- if rule.is_a? OsRule
9
- if rule.os == 'windows'
10
- allowed << 'win32'
11
- allowed << 'win64'
12
- elsif rule.os == 'linux'
13
- allowed << 'lin32'
14
- allowed << 'lin64'
15
- elsif rule.os == 'osx'
16
- allowed << 'osx64'
17
- end
18
- elsif rule.is_a? ImplicitRule
7
+ if rule.is_a? ImplicitRule
8
+ if rule.action == :allow
19
9
  allowed = possible
10
+ else
11
+ allowed = []
20
12
  end
21
- elsif rule.action == :disallow
22
- if rule.is_a? OsRule
23
- if rule.os == 'windows'
13
+ elsif rule.is_a? OsRule
14
+ if rule.action == :allow
15
+ case rule.os
16
+ when 'windows'
17
+ allowed << 'win32' << 'win64'
18
+ when 'linux'
19
+ allowed << 'lin32' << 'lin64'
20
+ when 'osx'
21
+ allowed << 'osx64'
22
+ end
23
+ elsif rule.action == :disallow
24
+ case rule.os
25
+ when 'windows'
24
26
  allowed.delete 'win32'
25
27
  allowed.delete 'win64'
26
- elsif rule.os == 'linux'
28
+ when 'linux'
27
29
  allowed.delete 'lin32'
28
30
  allowed.delete 'lin64'
29
- elsif rule.os == 'osx'
31
+ when 'osx'
30
32
  allowed.delete 'osx64'
31
33
  end
32
- elsif rule.is_a? ImplicitRule
33
- allowed = []
34
34
  end
35
35
  end
36
36
  end
37
37
  end
38
38
 
39
- return allowed
39
+ allowed
40
40
  end
41
41
 
42
42
  class MojangInput
43
43
  # reads a general mojang-style library
44
- def self.sanetize_mojang_library(object)
45
- lib = if object.key? :natives then VersionLibraryNative.new else VersionLibrary.new end
44
+ def self.sanitize_mojang_library(object)
45
+ lib = object.key?(:natives) ? VersionLibraryNative.new : VersionLibrary.new
46
46
  lib.name = object[:name]
47
- lib.mavenBaseUrl = object.key?(:url) ? object[:url] : 'https://libraries.minecraft.net/'
48
-
47
+ lib.maven_base_url = object.key?(:url) ? object[:url] : 'https://libraries.minecraft.net/'
49
48
  lib.rules = object[:rules].map do |obj| Rule.from_json obj end if object[:rules]
50
49
 
51
50
  libs = []
52
- if not lib.is_a? VersionLibraryNative
51
+ if !lib.is_a? VersionLibraryNative
53
52
  libs << lib
54
53
  else
55
- nativeIds = {}
56
- if object.key? :natives
57
- natives = object[:natives]
58
- if natives.key? :windows
59
- nativeIds['win32'] = natives[:windows].gsub "${arch}", '32'
60
- nativeIds['win64'] = natives[:windows].gsub "${arch}", '64'
61
- end
62
- if natives.key? :linux
63
- nativeIds['lin32'] = natives[:linux].gsub "${arch}", '32'
64
- nativeIds['lin64'] = natives[:linux].gsub "${arch}", '64'
65
- end
66
- if natives.key? :osx
67
- nativeIds['osx64'] = natives[:osx].gsub "${arch}", '64'
68
- end
54
+ native_ids = {}
55
+ natives = object[:natives]
56
+ if natives.key? :windows
57
+ native_ids['win32'] = natives[:windows].gsub "${arch}", '32'
58
+ native_ids['win64'] = natives[:windows].gsub "${arch}", '64'
59
+ end
60
+ if natives.key? :linux
61
+ native_ids['lin32'] = natives[:linux].gsub "${arch}", '32'
62
+ native_ids['lin64'] = natives[:linux].gsub "${arch}", '64'
63
+ end
64
+ if natives.key? :osx
65
+ native_ids['osx64'] = natives[:osx].gsub "${arch}", '64'
69
66
  end
70
67
 
71
- allowedPlatformsForRules(lib.rules).uniq.each do |platform|
72
- if not nativeIds.key? platform
73
- next
74
- end
68
+ allowed_platforms_for_rules(lib.rules).uniq.each do |platform|
69
+ next unless native_ids.key? platform
75
70
 
76
71
  native = lib.clone
77
72
  native.rules = [
@@ -81,12 +76,12 @@ class MojangInput
81
76
  nil,
82
77
  {'win32': '32', 'win64': '64', 'lin32': '32', 'lin64': '64', 'osx64': '64'}[platform.to_sym])
83
78
  ]
84
- native.url = native.url.sub '.jar', ('-' + nativeIds[platform] + '.jar')
79
+ native.url = native.url.sub '.jar', ('-' + native_ids[platform] + '.jar')
85
80
  libs << native
86
81
  end
87
82
  end
88
83
 
89
- return libs
84
+ libs
90
85
  end
91
86
 
92
87
  def initialize(artifact)
@@ -97,7 +92,7 @@ class MojangInput
97
92
  object = data.class == Hash ? data : JSON.parse(data, symbolize_names: true)
98
93
 
99
94
  if object[:minimumLauncherVersion] and object[:minimumLauncherVersion] > 14
100
- # TODO log error
95
+ logger.warn 'To high minimumLauncherVersion encountered for ' + object[:id] + ': ' + object[:minimumLauncherVersion]
101
96
  return []
102
97
  end
103
98
 
@@ -111,9 +106,7 @@ class MojangInput
111
106
  file.client.assets = object[:assets]
112
107
  file.client.minecraftArguments = object[:minecraftArguments]
113
108
  file.client.jarModTarget = "net.minecraft:minecraft:#{file.version}"
114
- file.client.downloads = object[:libraries].map do |obj|
115
- MojangInput.sanetize_mojang_library obj
116
- end.flatten 1
109
+ file.client.downloads = object[:libraries].map { |obj| MojangInput.sanitize_mojang_library obj }.flatten 1
117
110
  main_lib = VersionLibrary.new
118
111
  main_lib.name = "net.minecraft:minecraft:#{file.version}"
119
112
  main_lib.url = 'http://s3.amazonaws.com/Minecraft.Download/versions/' + file.version + '/' + file.version + '.jar'
@@ -134,7 +127,7 @@ class MojangInput
134
127
  file.client.folders['minecraft/saves'] = ['mc.saves.region'] if file.time >= 1298325600 and file.time < 1330552800
135
128
  file.client.folders['minecraft/saves'] = ['mc.saves.infdev'] if file.time >= 1291327200 and file.time < 1298325600
136
129
 
137
- return BaseSanitizer.sanitize file, MojangSplitLWJGLSanitizer
130
+ BaseSanitizer.sanitize file, MojangSplitLWJGLSanitizer
138
131
  end
139
132
  end
140
133
 
@@ -142,28 +135,28 @@ class MojangExtractTweakersSanitizer < BaseSanitizer
142
135
  def self.sanitize(file)
143
136
  file.client.tweakers = file.client.minecraftArguments.scan(/--tweakClass ([^ ]*)/).flatten
144
137
  file.client.minecraftArguments = file.client.minecraftArguments.gsub /\ ?--tweakClass ([^ ]*)/, ''
145
- return file
138
+ file
146
139
  end
147
140
  end
148
141
 
149
142
  # extract lwjgl specific libraries and natives
150
143
  class MojangSplitLWJGLSanitizer < BaseSanitizer
151
- @@lwjglList = ['org.lwjgl', 'net.java.jinput', 'net.java.jutils']
152
- @@lwjglExtras = ['net.java.jinput', 'net.java.jutils']
144
+ class << self; attr_accessor :lwjgl_list, :lwjgl_extras; end
145
+ self.lwjgl_list = %w(org.lwjgl net.java.jinput net.java.jutils)
146
+ self.lwjgl_extras = %w(net.java.jinput net.java.jutils)
153
147
 
154
148
  def self.sanitize(file)
155
149
  file.requires = [] if file.requires.nil?
156
150
  file.requires << Referenced.new('org.lwjgl')
157
151
 
158
152
  extras = [] # [Download]
159
- versioned = {} # String => [Download]
153
+ versioned = Hash.new { |hash, key| hash[key] = [] } # String => [Download]
160
154
  file.client.downloads.select! do |lib|
161
- nil == @@lwjglList.find do |lwjglCandidate|
162
- if lib.name.include? lwjglCandidate
163
- if @@lwjglExtras.include? lib.maven.group
155
+ nil == self.lwjgl_list.find do |lwjgl_candidate|
156
+ if lib.name.include? lwjgl_candidate
157
+ if self.lwjgl_extras.include? lib.maven.group
164
158
  extras << lib
165
159
  else
166
- versioned[lib.maven.version] ||= []
167
160
  versioned[lib.maven.version] << lib
168
161
  end
169
162
  true
@@ -190,8 +183,6 @@ end
190
183
 
191
184
  class MojangTraitsSanitizer < BaseSanitizer
192
185
  def self.sanitize(file)
193
- if file.uid == 'net.minecraft'
194
- end
195
186
  file
196
187
  end
197
188
  end