Module: Spigoter::CLI::Compile

Defined in:
lib/spigoter/cli/cli_compile.rb

Overview

Module for compiling Spigot

Author:

Class Method Summary collapse

Class Method Details

.compileObject



11
12
13
# File 'lib/spigoter/cli/cli_compile.rb', line 11

def self.compile
  ->(*) { main }
end

.compile_spigot(opts) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/spigoter/cli/cli_compile.rb', line 53

def self.compile_spigot(opts)
  Log.info "Compiling spigot version #{opts[:spigot_version]}"
  exit_status = system("java -jar BuildTools.jar --rev #{opts[:spigot_version]}")

  if exit_status != true
    Log.error 'There was an error while compiling Spigot'
    exit(1)
  end
end

.dependenciesObject



30
31
32
33
34
35
# File 'lib/spigoter/cli/cli_compile.rb', line 30

def self.dependencies
  if Spigoter::Utils.which('javac').nil? || Spigoter::Utils.which('git').nil?
    Log.error "You don't have javac or git in PATH"
    exit(1)
  end
end

.download_buildtoolsObject



44
45
46
47
48
49
50
51
# File 'lib/spigoter/cli/cli_compile.rb', line 44

def self.download_buildtools
  unless File.exist?('BuildTools.jar')
    file = Spigoter::Utils.download('https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar')
    File.open('BuildTools.jar', 'wb') do |f|
      f.write(file)
    end
  end
end

.import_optsObject



37
38
39
40
41
42
# File 'lib/spigoter/cli/cli_compile.rb', line 37

def self.import_opts
  Spigoter::Utils.fill_opts_config
rescue
  Log.error 'There is an error in spigoter.yml'
  exit(1)
end

.mainObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/spigoter/cli/cli_compile.rb', line 15

def self.main(*)
  Log.info 'Compiling Spigot!'
  dependencies
  opts = import_opts

  FileUtils.mkdir_p 'build'
  Dir.chdir('build') do
    download_buildtools
    FileUtils.rm_rf(Dir.glob('spigot*.jar'))
    compile_spigot(opts)
  end

  FileUtils.cp(Dir['build/spigot*.jar'].first, 'spigot.jar')
end