- # Spoutcraft development Rake tasks
- # Usage: rake -T
- #
- # These tasks assume the following folder structure:
- # spoutcraft/
- # lib/
- # spoutcraft-api.jar A compatible SpoutcraftAPI package
- # mcp/ Minecraft Coder Pack
- # conf/ Symlink to ../conf
- # lib/ Symlink to ../lib
- # mojang/ Folders corresponding to Minecraft versions
- # 1.1/bin/ This Minecraft version's bin folder
- #
- # Your workflow will probably look something like this:
- #
- # 1. rake mcp:setup
- # 2. rake mcp:decompile
- # 3. Make some changes to the Spoutcraft source
- # 4. rake mcp:merge
- # 5. rake mcp:recompile
- # 6. rake mcp:reobfuscate
- # 7. rake mcp:client to test your changes
- #
- # Rinse and repeat!
- require "fileutils"
- require "logger"
- require "open3"
- require "pathname"
- require "shellwords"
- module Spoutcraft
- VERSION = "1.1"
- class << self
- attr_accessor :root, :logger
- def capture(command, options = {})
- options = { :chdir => root }.merge(options)
- debug "Executing `#{command}`..."
- output, status = Open3.capture2e(command.to_s, :chdir => options[:chdir])
- method = if status.exitstatus != 0 then :error else :debug end
- output.each_line { |line| send(method, line.chomp) }
- send method, "Exited with status #{status.exitstatus} (PID #{status.pid})"
- [output, status]
- end
- end
- module MCP
- class << self
- def root
- Spoutcraft.root.join("mcp")
- end
- def run(command, *args)
- command = root.join("#{command}.sh")
- die! "Script not found: #{command}" unless command.exist?
- command = "#{command} #{args.join(" ")}" unless args.empty?
- Spoutcraft.capture(command, :chdir => root)
- end
- end
- end
- end
- def log(level, *args)
- Spoutcraft.logger.send(level, args.join(" "))
- end
- def error(*args)
- log(:error, *args)
- end
- def info(*args)
- log(:info, *args)
- end
- def debug(*args)
- log(:debug, *args)
- end
- def debug?
- $DEBUG
- end
- def die!(message = nil)
- error message if message
- error "Rake task stopped"
- exit 1
- end
- Spoutcraft.root = Pathname.new(File.dirname(__FILE__))
- Spoutcraft.logger = Logger.new(STDOUT)
- Spoutcraft.logger.level = if debug? then Logger::DEBUG else Logger::INFO end
- FileUtils = FileUtils::Verbose if debug?
- namespace :mcp do
- desc "Clean build artifacts"
- task :clean do
- Spoutcraft::MCP.run(:cleanup, "--force")
- FileUtils.rm_rf(Spoutcraft::MCP.root.join("jars", "bin").to_s)
- end
- desc "Copy Minecraft libraries and inject Spoutcraft resources"
- task :setup do
- source_path = Spoutcraft.root.join("mojang", Spoutcraft::VERSION, "bin")
- dest_path = Spoutcraft::MCP.root.join("jars")
- FileUtils.rm_rf(dest_path.join("bin").to_s)
- FileUtils.cp_r(source_path.to_s, dest_path.to_s)
- source_path = File.join("res", "*")
- dest_path = Spoutcraft::MCP.root.join("jars", "bin", "minecraft.jar")
- command = "jar -uvf #{dest_path.to_s.shellescape} #{source_path}"
- Spoutcraft.capture(command)
- end
- desc "Decompile and unobfuscate Minecraft source code"
- task :decompile do
- Spoutcraft::MCP.run(:decompile)
- end
- desc "Merge Spoutcraft and MCP source code and resources"
- task :merge do
- source_path = Spoutcraft.root.join("src")
- dest_path = Spoutcraft::MCP.root.join("src")
- command = "ditto -V #{source_path.to_s.shellescape} #{dest_path.to_s.shellescape}"
- Spoutcraft.capture(command)
- end
- desc "Recompile Minecraft source code"
- task :recompile do
- Spoutcraft::MCP.run(:recompile)
- end
- desc "Reobfuscate compiled Minecraft source code"
- task :reobfuscate do
- Spoutcraft::MCP.run(:reobfuscate)
- end
- desc "Run client"
- task :client do
- Spoutcraft::MCP.run(:startclient)
- end
- desc "Run server"
- task :server do
- Spoutcraft::MCP.run(:startserver)
- end
- desc "Merge source, recompile, and run client"
- task :test => [:merge, :recompile, :client]
- namespace :update do
- desc "Update MCP"
- task :mcp do
- Spoutcraft::MCP.run(:updatemcp)
- end
- desc "Update MD5s"
- task :md5 do
- Spoutcraft::MCP.run(:updatemd5)
- end
- desc "Update names"
- task :names do
- Spoutcraft::MCP.run(:updatenames)
- end
- end
- end