You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by as...@apache.org on 2008/01/17 08:24:04 UTC

svn commit: r612741 - in /incubator/buildr/trunk: CHANGELOG lib/java/compilers.rb lib/java/jruby.rb

Author: assaf
Date: Wed Jan 16 23:24:02 2008
New Revision: 612741

URL: http://svn.apache.org/viewvc?rev=612741&view=rev
Log:
Upgraded Scalac to new compiler API, not tested, though

Modified:
    incubator/buildr/trunk/CHANGELOG
    incubator/buildr/trunk/lib/java/compilers.rb
    incubator/buildr/trunk/lib/java/jruby.rb

Modified: incubator/buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/CHANGELOG?rev=612741&r1=612740&r2=612741&view=diff
==============================================================================
--- incubator/buildr/trunk/CHANGELOG (original)
+++ incubator/buildr/trunk/CHANGELOG Wed Jan 16 23:24:02 2008
@@ -16,6 +16,7 @@
 * Changed: The way packaging is handled: package_as_[type] is now called once for a given package with the exact file name.  If packaging requires a change to the specifiction (e.g. a different file type than the package type), add a package_as_[type]_spec method.
 * Changed: The default packaging type is inferred from the compiler, and without a compiler, defaults to :zip.
 * Changed: JUnit test framework now runs on all classes that extend junit.framework.TestCase.
+* Changed: Scalac compiler now used by the regular compile task, the scalac task is deprecated.
 * Removed: Prepare tasks removed.
 * Removed: All deprecated features since 1.1.  If you've seen warnings before, except the build to break.
 * Fixed: Artifact.pom resolves artifact without classifier, i.e org.testng:testng:jar:jdk15:5.1 uses org.testng:testng:pom:5.1 (Tommy).

Modified: incubator/buildr/trunk/lib/java/compilers.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/compilers.rb?rev=612741&r1=612740&r2=612741&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/compilers.rb (original)
+++ incubator/buildr/trunk/lib/java/compilers.rb Wed Jan 16 23:24:02 2008
@@ -13,9 +13,9 @@
     # and sets the target directory to target/classes (or target/test/classes).
     #
     # Accepts the following options:
-    # * :wranings -- Issue warnings when compiling.  True when running in verbose mode.
-    # * :debug    -- Generates bytecode with debugging information.  Set from the debug environment
-    #                variable/global option.
+    # * :wranings    -- Issue warnings when compiling.  True when running in verbose mode.
+    # * :debug       -- Generates bytecode with debugging information.  Set from the debug
+    #                   environment variable/global option.
     # * :deprecation -- If true, shows deprecation messages.  False by default.
     # * :source      -- Source code compatibility.
     # * :target      -- Bytecode compatibility.
@@ -79,11 +79,68 @@
     # and sets the target directory to target/classes (or target/test/classes).
     #
     # Accepts the following options:
+    # * :warnings    -- Generate warnings if true (opposite of -nowarn).
+    # * :deprecation -- Output source locations where deprecated APIs are used.
+    # * :source      -- Source compatibility with specified release.
+    # * :target      -- Class file compatibility with specified release.
+    # * :lint        -- Value to pass to xlint argument. Use true to enable default lint
+    #                   options, or pass a specific setting as string or array of strings.
+    # * :debug       -- Generate debugging info.
+    # * :other       -- Array of options to pass to the Scalac compiler as is.
     class Scalac < Base
 
-      OPTIONS = []
+      OPTIONS = [:warnings, :deprecation, :source, :target, :lint, :debug, :other]
 
       specify :language=>:scala, :target=>'classes', :target_ext=>'class', :packaging=>:jar
+
+      def initialize(options) #:nodoc:
+        super
+      end
+
+      def compile(sources, target, dependencies) #:nodoc:
+        check_options options, OPTIONS
+        home = ENV['SCALA_HOME'] or fail 'Missing SCALA_HOME environment variable'
+        fail 'Invalid SCALA_HOME environment variable' unless File.directory?(home)
+
+        cmd_args = []
+        cmd_args << '-cp' << (dependencies + FileList["#{home}/lib/*"]).join(File::PATH_SEPARATOR)
+        use_fsc = !(ENV["USE_FSC"] =~ /^(no|off|false)$/i)
+        source_paths = sources.select { |source| File.directory?(source) }
+        cmd_args << '-sourcepath' << source_paths.join(File::PATH_SEPARATOR) unless source_paths.empty?
+        cmd_args << '-d' << File.expand_path(target)
+        cmd_args += scalac_args
+        cmd_args += files_from_sources(sources)
+
+        unless Rake.application.options.dryrun
+          puts (['scalac'] + cmd_args).join(' ') if Rake.application.options.trace
+          if use_fsc
+            system(([File.expand_path('bin/fsc', home)] + cmd_args).join(' '))
+          else
+            Java.load
+            Java.scala.tools.nsc.Main.main(cmd_args.to_java(Java.java.lang.String)) == 0 or
+              fail 'Failed to compile, see errors above'
+          end
+        end
+      end
+
+    private
+
+      # Returns Scalac command line arguments from the set of options.
+      def scalac_args #:nodoc:
+        args = []
+        args << "-nowarn" unless options[:warnings]
+        args << "-verbose" if Rake.application.options.trace
+        args << "-g" if options[:debug]
+        args << "-deprecation" if options[:deprecation]
+        args << "-source" << options[:source].to_s if options[:source]
+        args << "-target:jvm-" + options[:target].to_s if options[:target]
+        case options[:lint]
+          when Array  then args << "-Xlint:#{options[:lint].join(',')}"
+          when String then args << "-Xlint:#{options[:lint]}"
+          when true   then args << "-Xlint"
+        end
+        args + Array(options[:other])
+      end
 
     end
   end

Modified: incubator/buildr/trunk/lib/java/jruby.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/jruby.rb?rev=612741&r1=612740&r2=612741&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/jruby.rb (original)
+++ incubator/buildr/trunk/lib/java/jruby.rb Wed Jan 16 23:24:02 2008
@@ -134,7 +134,7 @@
 
 module Buildr
   class ZipTask
-    # RubyZip doesn't work on JRuby.
+    # RubyZip doesn't work on JRuby, so we'll use java.util.zip instead.
     def create_from(file_map) #:nodoc:
       out = Java.java.io.FileOutputStream.new(name)
       zip = Java.java.util.zip.ZipOutputStream.new(out)