Module: Buildr::Scala

Defined in:
lib/buildr/scala/bdd.rb,
lib/buildr/scala/shell.rb,
lib/buildr/scala/tests.rb,
lib/buildr/scala/compiler.rb

Overview

The Scala Module

Defined Under Namespace

Modules: Check, Mockito, ProjectExtension Classes: ScalaShell, ScalaTest, Scalac, ScalacOptions, Specs2

Constant Summary collapse

DEFAULT_VERSION =
'2.11.8'

Class Method Summary collapse

Class Method Details

.installed_versionObject



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
# File 'lib/buildr/scala/compiler.rb', line 27

def installed_version
  unless @installed_version
    @installed_version = if Scalac.installed?
      begin
        # try to read the value from the properties file
        props = Zip::File.open(File.expand_path('lib/scala-library.jar', Scalac.scala_home)) do |zipfile|
          zipfile.read 'library.properties'
        end

        version_str = props.match(/version\.number\s*=\s*([^\s]+)/).to_a[1]

        if version_str
          md = version_str.match(/\d+\.\d[\d\.]*/) or
            fail "Unable to parse Scala version: #{version_str}"

          md[0].sub(/.$/, "") # remove trailing dot, if any
        end
      rescue => e
        warn "Unable to parse library.properties in $SCALA_HOME/lib/scala-library.jar: #{e}"
        nil
      end
    end
  end

  @installed_version
end

.versionObject



54
55
56
# File 'lib/buildr/scala/compiler.rb', line 54

def version
  Buildr.settings.build['scala.version'] || installed_version || DEFAULT_VERSION
end

.version?(*v) ⇒ Boolean

check if version matches any of the given prefixes

Returns:

  • (Boolean)


59
60
61
# File 'lib/buildr/scala/compiler.rb', line 59

def version?(*v)
  v.any? { |v| version.index(v.to_s) == 0 }
end

.version_major_minorObject

returns Scala version without tiny number. e.g. “2.11.8” => “2.11”



71
72
73
# File 'lib/buildr/scala/compiler.rb', line 71

def version_major_minor
  version.split('.')[0..1].join('.')
end

.version_strObject



22
23
24
25
# File 'lib/buildr/scala/compiler.rb', line 22

def version_str
  warn 'Use of Scala.version_str is deprecated. Use Scala.version instead'
  version
end

.version_without_buildObject

returns Scala version without build number. e.g. “2.9.0-1” => “2.9.0”



65
66
67
# File 'lib/buildr/scala/compiler.rb', line 65

def version_without_build
  version.split('-')[0]
end