require 'rake'
require 'rake/testtask'
require 'rake/clean'
require 'rake/gempackagetask'
require 'rake/rdoctask'
require 'tools/rakehelp'
require 'fileutils'
include FileUtils

setup_tests
setup_clean ["pkg", "lib/*.bundle", "lib/profligacy/*.class", "*.gem", ".config", "lib/profligacy/parser.jar"]

setup_rdoc ['README', 'LICENSE', 'COPYING', 'lib/**/*.rb', 'doc/**/*.rdoc']

desc "Does a full compile, test run"
task :default => ["lib/profligacy/parser.jar", :test]

version="1.0"
name="profligacy"

setup_gem(name, version) do |spec|
  spec.summary = "Profligacy The Swing Reducer."
  spec.description = spec.summary
  spec.author="Zed A. Shaw"
  spec.files += Dir.glob("resources/**/*")
  spec.files += Dir.glob("lib/**/*.rl")
  spec.files += Dir.glob("lib/**/*.java")
  spec.files += Dir.glob("lib/**/*.class")
  spec.files += Dir.glob("lib/**/*.jar")
  spec.platform = "jruby"
end

file "lib/profligacy/LELParser.java" => ["lib/profligacy/LELParser.rl"] do
  sh %{/usr/local/bin/ragel -J lib/profligacy/LELParser.rl | /usr/local/bin/rlgen-java -o lib/profligacy/LELParser.java}
end

file "lib/profligacy/LELParser.class" => ["lib/profligacy/LELParser.java"] do
  sh %{javac -target 1.5 lib/profligacy/LELParser.java}
end

file "lib/profligacy/parser.jar" => ["lib/profligacy/LELParser.class"] do
  Dir.chdir("lib") do 
    sh %{jar -cf profligacy/parser.jar profligacy/*.class}
  end
end

task :install => [:test, :package] do
  sh %{sudo gem install pkg/#{name}-#{version}.gem}
end

task :uninstall => [:clean] do
  sh %{sudo gem uninstall #{name}}
end

task :site do
  sh %{pushd doc/site; webgen; popd}
  sh %{rsync -av doc/rdoc doc/site/output/* rubyforge.org:/var/www/gforge-projects/ihate/profligacy}
end

task :project => [:clean, :default, :test, :rdoc, :package, :site]
