Repository: buildr Updated Branches: refs/heads/master 4fd3b06bc -> db57d6764
Move to Scala 2.11 Project: http://git-wip-us.apache.org/repos/asf/buildr/repo Commit: http://git-wip-us.apache.org/repos/asf/buildr/commit/c0e155b3 Tree: http://git-wip-us.apache.org/repos/asf/buildr/tree/c0e155b3 Diff: http://git-wip-us.apache.org/repos/asf/buildr/diff/c0e155b3 Branch: refs/heads/master Commit: c0e155b36bfe33873c7555cb87f51e7175bbf43d Parents: 4fd3b06 Author: Antoine Toulme <[email protected]> Authored: Sun Aug 14 18:37:47 2016 -0700 Committer: Antoine Toulme <[email protected]> Committed: Sun Aug 14 18:37:47 2016 -0700 ---------------------------------------------------------------------- doc/languages.textile | 34 -------------------- lib/buildr/scala.rb | 1 - lib/buildr/scala/bdd.rb | 43 +++++++++++++++++++++---- lib/buildr/scala/compiler.rb | 67 ++++++++------------------------------- lib/buildr/scala/tests.rb | 30 +++++++++++------- spec/sandbox.rb | 2 +- spec/scala/compiler_spec.rb | 67 +-------------------------------------- spec/scala/tests_spec.rb | 16 ++++------ 8 files changed, 76 insertions(+), 184 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/buildr/blob/c0e155b3/doc/languages.textile ---------------------------------------------------------------------- diff --git a/doc/languages.textile b/doc/languages.textile index b31d6ac..5e45546 100644 --- a/doc/languages.textile +++ b/doc/languages.textile @@ -238,8 +238,6 @@ h4. Fast Scala Compiler You may use @fsc@, the Fast Scala Compiler, which submits compilation jobs to a compilation daemon, by setting the environment variable @USE_FSC@ to @yes@. Note that @fsc@ _may_ cache class libraries -- don't forget to run @fsc -reset@ if you upgrade a library. -(Note @fsc@ is not compatible with @zinc@ incremental compilation.) - h4. Rebuild detection *Scala 2.7* @@ -270,38 +268,6 @@ To avoid unusual behavior, compiler-level change detection is disabled whenever *Scala 2.9 and later* -Starting with Buildr 1.4.8, Buildr integrates with the "Zinc":https://github.com/typesafehub/zinc incremental compilation wrapper for @scalac@. Incremental compilation can be enabled 3 ways, - -1) By setting the compiler's option directly, - -{% highlight ruby %} -compile.using :incremental => true - -compile.options.incremental = true # same as above -{% endhighlight %} - -Note that this won't enable incremental compilation for both @compile@ and @test.compile@, you would have to set options on both. For this reason, it's recommended that you set the option on the project instead (see below). - -2) By setting the project's @scalac_options.incremental@, - -{% highlight ruby %} -project.scalac_options.incremental = true -{% endhighlight %} - -3) By setting the global @scalac.incremental@ option, - -in your @buildfile@: - -{% highlight ruby %} -Buildr.settings.build['scalac.incremental'] = true -{% endhighlight %} - -or in your @build.yaml@: - -{% highlight yaml %} -scalac.incremental: true -{% endhighlight %} - h4. Support for different Scala versions Buildr defaults to the latest stable Scala version available at the time of the release if neither @SCALA_HOME@ nor the @scala.version@ build property are set. http://git-wip-us.apache.org/repos/asf/buildr/blob/c0e155b3/lib/buildr/scala.rb ---------------------------------------------------------------------- diff --git a/lib/buildr/scala.rb b/lib/buildr/scala.rb index a75cae3..8e767bc 100644 --- a/lib/buildr/scala.rb +++ b/lib/buildr/scala.rb @@ -15,7 +15,6 @@ ENV['SCALA_HOME'] ||= '/opt/local/share/scala/' if File.exist?('/opt/local/share/scala/lib/scala-compiler.jar') -Buildr.repositories.remote << 'http://oss.sonatype.org/content/repositories/releases' require 'buildr/scala/compiler' require 'buildr/scala/tests' http://git-wip-us.apache.org/repos/asf/buildr/blob/c0e155b3/lib/buildr/scala/bdd.rb ---------------------------------------------------------------------- diff --git a/lib/buildr/scala/bdd.rb b/lib/buildr/scala/bdd.rb index cac890d..c2a6f52 100644 --- a/lib/buildr/scala/bdd.rb +++ b/lib/buildr/scala/bdd.rb @@ -47,7 +47,14 @@ module Buildr::Scala #:nodoc: end def artifact - Buildr.settings.build['scala.specs.artifact'] || "specs_#{Buildr::Scala.version_without_build}" + custom = Buildr.settings.build['scala.specs.artifact'] + return custom unless custom.nil? + + if Buildr::Scala.version >= "2.11" + "specs_2.10" + else + "specs_#{Buildr::Scala.version_without_build}" + end end def dependencies @@ -56,7 +63,7 @@ module Buildr::Scala #:nodoc: # Add utility classes (e.g. SpecsSingletonRunner) and other dependencies @dependencies |= [ File.join(File.dirname(__FILE__)) ] + specs + - Check.dependencies + JUnit.dependencies + Scalac.dependencies + Check.dependencies + JUnit.dependencies + Scalac.dependencies + ["org.scala-lang.modules:scala-xml_2.11:jar:1.0.5"] end @dependencies end @@ -136,8 +143,10 @@ module Buildr::Scala #:nodoc: '1.5' when Buildr::Scala.version?("2.9") '1.11' + when Buildr::Scala.version?("2.10") + '1.12.3' else - '1.12.3' # default for Scala 2.10 and beyond + '3.7' # default for Scala 2.11 and beyond end class << self @@ -148,7 +157,7 @@ module Buildr::Scala #:nodoc: def specs custom = Buildr.settings.build['scala.specs2'] - [ (custom =~ /:/) ? custom : "org.specs2:#{artifact}:jar:#{version}" ] + [ (custom =~ /:/) ? custom : "org.specs2:#{artifact}:pom:#{version}" ] end def artifact @@ -156,14 +165,26 @@ module Buildr::Scala #:nodoc: when Buildr.settings.build['scala.specs2.artifact'] Buildr.settings.build['scala.specs2.artifact'] else - "specs2_#{Buildr::Scala.version_without_build}" + if Buildr::Scala.version < "2.11" + "specs2_#{Buildr::Scala.version_without_build_number}" + else + "specs2_#{Buildr::Scala.version_major_minor}" + end + end + end + + def type + if Buildr::Scala.version < "2.11" + "jar" + else + "pom" end end def scalaz_dependencies if Buildr::Scala.version?("2.8") [] - else + elsif Buildr::Scala.version < "2.11" default_version = "6.0.1" custom_version = Buildr.settings.build['scala.specs2-scalaz'] version = (custom_version =~ /:/) ? Buildr.artifact(custom_version).version : default_version @@ -173,6 +194,16 @@ module Buildr::Scala #:nodoc: custom_spec = Buildr.settings.build['scala.specs2-scalaz'] spec = [ (custom_spec =~ /:/) ? custom_spec : "org.specs2:#{artifact}:jar:#{version}" ] Buildr.transitive(spec, :scopes => [nil, "compile", "runtime", "provided", "optional"], :optional => true) + else + default_version = "7.2.2" + custom_version = Buildr.settings.build['scala.specs2-scalaz'] + version = (custom_version =~ /:/) ? Buildr.artifact(custom_version).version : default_version + + artifact = Buildr.settings.build['scala.specs2-scalaz.artifact'] || "scalaz-core_#{Buildr::Scala.version_major_minor}" + + custom_spec = Buildr.settings.build['scala.specs2-scalaz'] + spec = [ (custom_spec =~ /:/) ? custom_spec : "org.scalaz:#{artifact}:jar:#{version}" ] + [Buildr.transitive(spec, :scopes => [nil, "compile", "runtime", "provided", "optional"], :optional => true), "org.scala-lang.modules:scala-xml_2.11:jar:1.0.1"] end end http://git-wip-us.apache.org/repos/asf/buildr/blob/c0e155b3/lib/buildr/scala/compiler.rb ---------------------------------------------------------------------- diff --git a/lib/buildr/scala/compiler.rb b/lib/buildr/scala/compiler.rb index 0fc6147..c22cb27 100644 --- a/lib/buildr/scala/compiler.rb +++ b/lib/buildr/scala/compiler.rb @@ -15,7 +15,7 @@ # The Scala Module module Buildr::Scala - DEFAULT_VERSION = '2.9.2' + DEFAULT_VERSION = '2.11.8' class << self @@ -65,6 +65,12 @@ module Buildr::Scala def version_without_build version.split('-')[0] end + + # returns Scala version without tiny number. + # e.g. "2.11.8" => "2.11" + def version_major_minor + version.split('.')[0..1].join('.') + end end # Scalac compiler: @@ -81,9 +87,9 @@ module Buildr::Scala # * :other -- Array of options to pass to the Scalac compiler as is, e.g. -Xprint-types class Scalac < Buildr::Compiler::Base - DEFAULT_ZINC_VERSION = '0.1.0' - DEFAULT_SBT_VERSION = '0.12.0' - DEFAULT_JLINE_VERSION = '1.0' + DEFAULT_ZINC_VERSION = '1.0.0-X1' + DEFAULT_SBT_VERSION = '0.13.12' + DEFAULT_JLINE_VERSION = '2.14.2' class << self def scala_home @@ -115,9 +121,7 @@ module Buildr::Scala REQUIRES.artifacts.map(&:to_s) end - zinc_dependencies = ZINC_REQUIRES.artifacts.map(&:to_s) - - (scala_dependencies + zinc_dependencies).compact + scala_dependencies.compact end def use_fsc @@ -152,10 +156,8 @@ module Buildr::Scala end ZINC_REQUIRES = ArtifactNamespace.for(self) do |ns| - zinc_version = Buildr.settings.build['zinc.version'] || DEFAULT_ZINC_VERSION sbt_version = Buildr.settings.build['sbt.version'] || DEFAULT_SBT_VERSION jline_version = Buildr.settings.build['jline.version'] || DEFAULT_JLINE_VERSION - ns.zinc! "com.typesafe.zinc:zinc:jar:>=#{zinc_version}" ns.sbt_interface! "com.typesafe.sbt:sbt-interface:jar:>=#{sbt_version}" ns.incremental! "com.typesafe.sbt:incremental-compiler:jar:>=#{sbt_version}" ns.compiler_interface_sources! "com.typesafe.sbt:compiler-interface:jar:sources:>=#{sbt_version}" @@ -184,11 +186,7 @@ module Buildr::Scala end def compile(sources, target, dependencies) #:nodoc: - if zinc? - compile_with_zinc(sources, target, dependencies) - else - compile_with_scalac(sources, target, dependencies) - end + compile_with_scalac(sources, target, dependencies) end def compile_with_scalac(sources, target, dependencies) #:nodoc: @@ -243,37 +241,6 @@ module Buildr::Scala end end - def compile_with_zinc(sources, target, dependencies) #:nodoc: - - dependencies.unshift target - - cmd_args = [] - cmd_args << '-sbt-interface' << REQUIRES.sbt_interface.artifact - cmd_args << '-compiler-interface' << REQUIRES.compiler_interface_sources.artifact - cmd_args << '-scala-library' << dependencies.find { |d| d =~ /scala-library/ } - cmd_args << '-scala-compiler' << dependencies.find { |d| d =~ /scala-compiler/ } - cmd_args << '-classpath' << dependencies.join(File::PATH_SEPARATOR) - source_paths = sources.select { |source| File.directory?(source) } - cmd_args << '-Ssourcepath' << ("-S" + source_paths.join(File::PATH_SEPARATOR)) unless source_paths.empty? - cmd_args << '-d' << File.expand_path(target) - cmd_args += scalac_args - cmd_args << "-debug" if trace?(:scalac) - - cmd_args.map!(&:to_s) - - cmd_args += files_from_sources(sources) - - unless Buildr.application.options.dryrun - trace((['com.typesafe.zinc.Main.main'] + cmd_args).join(' ')) - - begin - Java::Commands.java 'com.typesafe.zinc.Main', *(cmd_args + [{ :classpath => Scalac.dependencies}]) - rescue => e - fail "Zinc compiler crashed:\n#{e.inspect}\n#{e.backtrace.join("\n")}" - end - end - end - protected # :nodoc: see Compiler:Base @@ -318,10 +285,6 @@ module Buildr::Scala private - def zinc? - (options[:incremental] || @project.scalac_options.incremental || (Buildr.settings.build['scalac.incremental'].to_s == "true")) - end - def count(file, pattern) count = 0 File.open(file, "r") do |infile| @@ -351,11 +314,7 @@ module Buildr::Scala args << "-optimise" if options[:optimise] args << "-target:jvm-" + options[:target].to_s if options[:target] args += Array(options[:other]) - if zinc? - args.map { |arg| "-S" + arg } + Array(options[:zinc_options]) - else - args - end + args end end http://git-wip-us.apache.org/repos/asf/buildr/blob/c0e155b3/lib/buildr/scala/tests.rb ---------------------------------------------------------------------- diff --git a/lib/buildr/scala/tests.rb b/lib/buildr/scala/tests.rb index 4d87502..f638cf4 100644 --- a/lib/buildr/scala/tests.rb +++ b/lib/buildr/scala/tests.rb @@ -39,8 +39,10 @@ module Buildr::Scala#:nodoc: '1.7' when Buildr::Scala.version?("2.8.1") '1.8' - else + when Buildr::Scala.version < "2.11" '1.10.0' + else + '1.12.5' end class << self @@ -53,7 +55,14 @@ module Buildr::Scala#:nodoc: end def artifact - Buildr.settings.build['scala.check.artifact'] || "scalacheck_#{Buildr::Scala.version_without_build}" + custom = Buildr.settings.build['scala.check.artifact'] + return custom if !!custom + case + when Buildr::Scala.version < "2.11" + "scalacheck_#{Buildr::Scala.version_without_build}" + else + "scalacheck_#{Buildr::Scala.version_major_minor}" + end end def dependencies @@ -92,8 +101,10 @@ module Buildr::Scala#:nodoc: VERSION = case when Buildr::Scala.version?(2.7) '1.3' - else + when Buildr::Scala.version < "2.11" '1.8' + else + '2.2.6' end class << self @@ -107,25 +118,20 @@ module Buildr::Scala#:nodoc: return custom if (custom =~ /:/) if Buildr::Scala.version?(2.7, 2.8) "org.scalatest:scalatest:jar:#{version}" - else + elsif Buildr::Scala.version < "2.11" "org.scalatest:scalatest_#{Buildr::Scala.version_without_build}:jar:#{version}" + else + "org.scalatest:scalatest_#{Buildr::Scala.version_major_minor}:jar:#{version}" end end def dependencies - [specs] + Check.dependencies + JMock.dependencies + JUnit.dependencies + Mockito.dependencies + [specs] + Check.dependencies + JMock.dependencies + JUnit.dependencies + Mockito.dependencies + ["org.scala-lang.modules:scala-xml_2.11:jar:1.0.5"] end def applies_to?(project) #:nodoc: !Dir[project.path_to(:source, :test, :scala, '**/*.scala')].empty? end - - private - def const_missing(const) - return super unless const == :REQUIRES # TODO: remove in 1.5 - Buildr.application.deprecated "Please use Scala::Test.dependencies/.version instead of ScalaTest::REQUIRES/VERSION" - dependencies - end end # annotation-based group inclusion http://git-wip-us.apache.org/repos/asf/buildr/blob/c0e155b3/spec/sandbox.rb ---------------------------------------------------------------------- diff --git a/spec/sandbox.rb b/spec/sandbox.rb index fe42192..f5ef09a 100644 --- a/spec/sandbox.rb +++ b/spec/sandbox.rb @@ -24,7 +24,7 @@ repositories.remote << 'https://oss.sonatype.org/content/groups/scala-tools' # Force Scala version for specs; don't want to rely on SCALA_HOME module Buildr::Scala - SCALA_VERSION_FOR_SPECS = ENV["SCALA_VERSION"] || "2.9.2" + SCALA_VERSION_FOR_SPECS = ENV["SCALA_VERSION"] || "2.11.8" end Buildr.settings.build['scala.version'] = Buildr::Scala::SCALA_VERSION_FOR_SPECS http://git-wip-us.apache.org/repos/asf/buildr/blob/c0e155b3/spec/scala/compiler_spec.rb ---------------------------------------------------------------------- diff --git a/spec/scala/compiler_spec.rb b/spec/scala/compiler_spec.rb index 3fc4556..d1b795d 100644 --- a/spec/scala/compiler_spec.rb +++ b/spec/scala/compiler_spec.rb @@ -267,31 +267,7 @@ share_as :ScalacCompiler_CommonOptions do end end - -describe 'scala compiler 2.8 options' do - - it_should_behave_like ScalacCompiler_CommonOptions - - def compile_task - @compile_task ||= define('foo').compile.using(:scalac) - end - - def scalac_args - compile_task.instance_eval { @compiler }.send(:scalac_args) - end - - it 'should use -g argument when debug option is true' do - compile_task.using(:debug=>true) - scalac_args.should include('-g') - end - - it 'should not use -g argument when debug option is false' do - compile_task.using(:debug=>false) - scalac_args.should_not include('-g') - end -end if Buildr::Scala.version?(2.8) - -describe 'scala compiler 2.9 options' do +describe 'scala compiler options' do it_should_behave_like ScalacCompiler_CommonOptions @@ -319,46 +295,5 @@ describe 'scala compiler 2.9 options' do scalac_args.should_not include('-g') end -end if Buildr::Scala.version?(2.9) - -if Java.java.lang.System.getProperty("java.runtime.version") >= "1.6" - -describe 'zinc compiler (enabled through Buildr.settings)' do - before :each do - Buildr.settings.build['scalac.incremental'] = true - end - - it 'should compile with zinc' do - write 'src/main/scala/com/example/Test.scala', 'package com.example; class Test { val i = 1 }' - project = define('foo') - compile_task = project.compile.using(:scalac) - compiler = compile_task.instance_eval { @compiler } - compiler.send(:zinc?).should eql(true) - compiler.should_receive(:compile_with_zinc).once - compile_task.invoke - end - - after :each do - Buildr.settings.build['scalac.incremental'] = nil - end - - it_should_behave_like ScalacCompiler end -describe 'zinc compiler (enabled through project.scala_options)' do - - it 'should compile with zinc' do - write 'src/main/scala/com/example/Test.scala', 'package com.example; class Test { val i = 1 }' - project = define('foo') - project.scalac_options.incremental = true - compile_task = project.compile.using(:scalac) - compiler = compile_task.instance_eval { @compiler } - compiler.send(:zinc?).should eql(true) - compiler.should_receive(:compile_with_zinc).once - compile_task.invoke - end -end - -elsif Buildr::VERSION >= '1.5' - raise "JVM version guard in #{__FILE__} should be removed since it is assumed that Java 1.5 is no longer supported." -end http://git-wip-us.apache.org/repos/asf/buildr/blob/c0e155b3/spec/scala/tests_spec.rb ---------------------------------------------------------------------- diff --git a/spec/scala/tests_spec.rb b/spec/scala/tests_spec.rb index ee80a60..49e7496 100644 --- a/spec/scala/tests_spec.rb +++ b/spec/scala/tests_spec.rb @@ -208,18 +208,14 @@ describe Buildr::Scala::ScalaTest do it 'should pass properties to Suite' do write 'src/test/scala/PropertyTestSuite.scala', <<-SCALA import org.scalatest._ - class PropertyTestSuite extends FunSuite { - var configMap = Map[String, Any]() - test("testProperty") { + import org.scalatest.fixture.FunSuite + import org.scalatest.fixture.ConfigMapFixture + + class PropertyTestSuite extends FunSuite with ConfigMapFixture { + + test("testProperty") { (configMap: Map[String, Any]) => assert(configMap("name") === "value") } - - protected override def runTests(testName: Option[String], reporter: Reporter, stopper: Stopper, - filter: Filter, configMap: Map[String, Any], - distributor: Option[Distributor], tracker: Tracker) { - this.configMap = configMap - super.runTests(testName, reporter, stopper, filter, configMap, distributor, tracker) - } } SCALA define('foo').test.using :properties=>{ 'name'=>'value' }
