Skip to content

Instantly share code, notes, and snippets.

@aboisvert
Created November 11, 2011 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aboisvert/1359643 to your computer and use it in GitHub Desktop.
Save aboisvert/1359643 to your computer and use it in GitHub Desktop.
Apache Buildr "buildfile" for Scalatra project
require 'extensions/kernel' if RUBY_VERSION =~ /1.8/
require 'buildr/scala'
require_relative 'explode'
load 'scalatra.rb'
VERSION_NUMBER = "2.1.0-SNAPSHOT"
repositories.remote << "http://www.ibiblio.org/maven2/"
repositories.remote << "https://oss.sonatype.org/content/repositories/snapshots"
repositories.remote << "https://oss.sonatype.org/service/local/staging/deploy/maven2"
repositories.remote << "http://repo.fusesource.com/nexus/content/repositories/snapshots"
repositories.remote << "http://repo1.maven.org/maven2/"
repositories.release_to = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
scala_version = Buildr::Scala.version
ANTI_XML = "com.codecommit:anti-xml_#{scala_version}:jar:0.2"
ATMOSPHERE = transitive("org.atmosphere:atmosphere-runtime:jar:0.7.2")
BASE64 = "net.iharderui :base64:jar:2.3.8"
COMMONS = struct(
:fileupload => "commons-fileupload:commons-fileupload:jar:1.2.1",
:io => "commons-io:commons-io:jar:2.0.1",
:lang3 => "org.apache.commons:commons-lang3:jar:3.0.1"
)
JETTY = grouping("org.eclipse.jetty", "8.0.0.v20110901", %w{test-jetty-servlet jetty-websocket jetty-webapp})
LIFT_JSON = begin
json_version = Buildr::Scala.version?("2.9.1") ? "2.4-M4" : "2.4-M3"
"net.liftweb:lift-json_#{scala_version}:jar:#{json_version}"
end
MOCKITO = "org.mockito:mockito-all:jar:1.8.5"
SCALATE = transitive("org.fusesource.scalate:scalate-core:jar:1.6.0-SNAPSHOT")
SERVLET_API = "javax.servlet:javax.servlet-api:jar:3.0.1"
SOCKET_IO = "org.scalatra.socketio-java:socketio-core:jar:2.0.0"
define "scalatra" do
project.version = VERSION_NUMBER
project.group = "org.scalatra"
define "testing", :base_dir => "test" do
compile.with JETTY.test_jetty_servlet, MOCKITO, COMMONS.lang3
package(:jar, :id => 'scalatra-test')
end
define "scalatest" do
compile.with Buildr::ScalaTest.dependencies, transitive(project("testing")), Buildr::TestNG.dependencies
package :jar
end
define "specs" do
compile.with Buildr::Scala::Specs.dependencies, transitive(project("testing"))
package :jar
end
define "specs2" do
compile.with Buildr::Scala::Specs2.dependencies, transitive(project("testing"))
package :jar
end
define "core" do
compile.with SERVLET_API
test.compile.with %w{testing scalatest specs specs2}.map { |p| transitive(project(p)) }
package :jar
end
define "anti-xml" do
compile.with ANTI_XML, transitive(project("core"))
test.compile.with transitive(project("specs2"))
package :jar
end
define "auth" do
compile.with transitive(project("core")), BASE64
test.compile.with transitive(project("specs"))
test.exclude '*ScentrySpec$'
package :jar
end
define "fileupload" do
compile.with COMMONS.fileupload, COMMONS.io, transitive(project("core"))
test.with transitive(project("scalatest"))
package :jar
end
define "lift-json" do
compile.with LIFT_JSON, transitive(project("core"))
test.compile.with %w{testing scalatest specs}.map { |p| transitive(project(p)) }
package :jar
end
define "scalate" do
compile.with transitive(project("core")), SCALATE
test.compile.with %w{testing scalatest specs specs2}.map { |p| transitive(project(p)) }
package :jar
end
define "example" do
compile.with ATMOSPHERE, JETTY.jetty_webapp,
%w{core auth fileupload scalate socketio}.map { |p| transitive(project(p)) }
package(:war).tap do |war|
war.explode :target => _("target/webapps/example")
end
end
define "socketio" do
compile.with transitive(project("core")), SOCKET_IO, JETTY.jetty_websocket
package :jar
end
end
# Customizations for the Scalatra project
# Create a struct based on group, version and set of artifacts.
#
# e.g.
# example = grouping("org.example", "1.2", %w{foo bar baz})
#
# example.foo => transitive("org.example:foo:jar:1.2")
# example.bar => transitive("org.example:bar:jar:1.2")
# ...
#
def grouping(group, version, artifacts)
artifacts = Hash[*(artifacts.map { |a| [a.gsub("-", "_"), a] }.flatten)]
artifacts.keys.inject(Struct.new("#{group}-#{version}".to_sym, *(artifacts.keys)).new) do |struct, sym|
struct[sym] = transitive("#{group}:#{artifacts[sym]}:jar:#{version}")
struct
end
end
# Project customization: if src/test/scala directory exists, test using
# any Scala framework (ScalaTest, Specs, Spec2)
module ScalatraDefaults
include Buildr::Extension
before_define do |project|
test_dir = project.path_to("src/test/scala")
if File.exist?(test_dir)
project.test.using :multitest, :frameworks => [
Buildr::Scala::ScalaTest,
Buildr::Scala::Specs,
Buildr::Scala::Specs2
]
project.test.compile.from test_dir
end
test_resources = project.path_to("src/test/resources")
if File.exist?(test_resources)
project.test.resources.from test_resources
end
end
end
# Apply defaults to all projects
class Buildr::Project
include ScalatraDefaults
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment