nicksieger / jruby-rack

Rack for JRuby and Java appservers

This URL has Read+Write access

jruby-rack / Rakefile
100644 94 lines (75 sloc) 2.686 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#--
# Copyright 2007-2008 Sun Microsystems, Inc.
# This source code is available under the MIT license.
# See the file LICENSE.txt for details.
#++
 
require 'rake/clean'
 
if ENV['JRUBY_PARENT_CLASSPATH']
  classpath = []
  ENV['JRUBY_PARENT_CLASSPATH'].split(File::PATH_SEPARATOR).each {|p| classpath << p}
else
  require 'rbconfig'
  classpath = Dir["src/main/lib/*.jar"] + [File.join(Config::CONFIG['libdir'], Config::CONFIG['LIBRUBY'])]
end
classpath.unshift "target/classes", "target/test-classes"
classpath.each {|p| $CLASSPATH << p}
ENV['CLASSPATH'] = classpath.join(File::PATH_SEPARATOR)
 
CLEAN << 'target'
 
directory 'target/classes'
 
desc "Compile java classes"
task :compile => "target/classes" do |t|
  sh "javac -source 1.5 -target 1.5 -d #{t.prerequisites.first} #{Dir['src/main/java/**/*.java'].join(' ')}"
end
 
directory 'target/test-classes'
 
desc "Compile classes used for test/spec"
task :compilespec => "target/test-classes" do |t|
  sh "javac -source 1.5 -target 1.5 -d #{t.prerequisites.first} #{Dir['src/spec/java/**/*.java'].join(' ')}"
end
 
desc "Unpack the rack gem"
task :unpack_gem => "target" do |t|
  Dir.chdir(t.prerequisites.first) do
    unless File.directory?("rack")
      ruby "-S", "gem", "unpack", FileList["../src/main/lib/rack*.gem"].first
      mv FileList["rack-*"].first, "rack"
    end
  end
end
 
version_file = 'src/main/ruby/jruby/rack/version.rb'
load version_file
 
task :update_version do
  if ENV["VERSION"] && ENV["VERSION"] != JRuby::Rack::VERSION
    lines = File.readlines(version_file)
    lines.each {|l| l.sub!(/VERSION =.*$/, %{VERSION = "#{ENV["VERSION"]}"})}
    File.open(version_file, "wb") {|f| f.puts *lines }
  end
end
 
desc "Copy resources"
task :resources => ["target/classes", :unpack_gem, :update_version] do |t|
  ['src/main/ruby', 'target/rack/lib'].each do |dir|
    FileList["#{dir}/*"].each do |f|
      cp_r f, t.prerequisites.first
    end
  end
  meta_inf = File.join(t.prerequisites.first, "META-INF")
  mkdir_p meta_inf
  cp "src/main/tld/jruby-rack.tld", meta_inf
end
 
task :speconly do
  if ENV['SKIP_SPECS'] && !ENV['SKIP_SPECS'].empty?
    puts "Skipping specs due to SKIP_SPECS=#{ENV['SKIP_SPECS']}"
  else
    ruby "-S", "spec", "--format", "specdoc", *FileList["src/spec/ruby/**/*_spec.rb"].to_a
  end
end
 
desc "Run specs"
task :spec => [:compile, :resources, :compilespec, :speconly]
 
task :test => :spec
 
file "target/jruby-rack-#{JRuby::Rack::VERSION}.jar" => :spec do |t|
  sh "jar cf #{t.name} -C target/classes ."
end
 
desc "Create the jar"
task :jar => "target/jruby-rack-#{JRuby::Rack::VERSION}.jar"
 
task :default => :jar
 
task :classpath do
  puts "export CLASSPATH=#{ENV['CLASSPATH']}"
end