Class: Buildr::Groovy::Groovyc

Inherits:
Compiler::Base show all
Defined in:
lib/buildr/groovy/compiler.rb

Overview

Groovyc compiler:

compile.using(:groovyc)

You need to require ‘buildr/groovy/compiler’ if you need to use this compiler.

Used by default if .groovy files are found in the src/main/groovy directory (or src/test/groovy) and sets the target directory to target/classes (or target/test/classes).

Groovyc is a joint compiler, this means that when selected for a project, this compiler is used to compile both groovy and java sources. It’s recommended that Groovy sources are placed in the src/main/groovy directory, even though this compiler also looks in src/main/java

Groovyc accepts the following options:

  • :encoding – Encoding of source files

  • :verbose – Asks the compiler for verbose output, true when running in verbose mode.

  • :fork – Whether to execute groovyc using a spawned instance of the JVM; defaults to no

  • :memoryInitialSize – The initial size of the memory for the underlying VM, if using fork mode; ignored otherwise.

    Defaults to the standard VM memory setting. (Examples: 83886080, 81920k, or 80m)
    
  • :memoryMaximumSize – The maximum size of the memory for the underlying VM, if using fork mode; ignored otherwise.

    Defaults to the standard VM memory setting. (Examples: 83886080, 81920k, or 80m)
    
  • :listfiles – Indicates whether the source files to be compiled will be listed; defaults to no

  • :stacktrace – If true each compile error message will contain a stacktrace

  • :warnings – 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.

  • :optimise – Generates faster bytecode by applying optimisations to the program.

  • :source – Source code compatibility.

  • :target – Bytecode compatibility.

  • :javac – Hash of options passed to the ant javac task

Constant Summary collapse

REQUIRES =

The groovyc compiler jars are added to classpath at load time, if you want to customize artifact versions, you must set them on the

artifact_ns['Buildr::Compiler::Groovyc'].groovy = '1.5.4'

namespace before this file is required.

ArtifactNamespace.for(self) do |ns|
  ns.groovy!       'org.codehaus.groovy:groovy:jar:>=1.5.3'
  ns.commons_cli!  'commons-cli:commons-cli:jar:>=1.0'
  ns.asm!          'asm:asm:jar:>=2.2'
  ns.antlr!        'antlr:antlr:jar:>=2.7.7'
end
ANT_TASK =
'org.codehaus.groovy.ant.Groovyc'
GROOVYC_OPTIONS =
[:encoding, :verbose, :fork, :memoryInitialSize, :memoryMaximumSize, :listfiles, :stacktrace]
JAVAC_OPTIONS =
[:optimise, :warnings, :debug, :deprecation, :source, :target, :javac]
OPTIONS =
GROOVYC_OPTIONS + JAVAC_OPTIONS

Instance Attribute Summary

Attributes inherited from Compiler::Base

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Compiler::Base

#dependencies, #needed?, specify, to_sym

Constructor Details

#initialize(project, options) ⇒ Groovyc

:nodoc:



89
90
91
92
93
94
95
96
97
# File 'lib/buildr/groovy/compiler.rb', line 89

def initialize(project, options) #:nodoc:
  super
  options[:debug] = Buildr.options.debug if options[:debug].nil?
  options[:deprecation] ||= false
  options[:optimise] ||= false
  options[:verbose] ||= Buildr.application.options.trace if options[:verbose].nil?
  options[:warnings] = verbose if options[:warnings].nil?
  options[:javac] = OpenObject.new if options[:javac].nil?
end

Class Method Details

.applies_to?(project, task) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


76
77
78
79
80
81
# File 'lib/buildr/groovy/compiler.rb', line 76

def applies_to?(project, task) #:nodoc:
  paths = task.sources + [sources].flatten.map { |src| Array(project.path_to(:source, task.usage, src.to_sym)) }
  paths.flatten!
  # Just select if we find .groovy files
  paths.any? { |path| !Dir["#{path}/**/*.groovy"].empty? }
end

.dependenciesObject

:nodoc:



72
73
74
# File 'lib/buildr/groovy/compiler.rb', line 72

def dependencies #:nodoc:
  REQUIRES.artifacts
end

Instance Method Details

#compile(sources, target, dependencies) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/buildr/groovy/compiler.rb', line 100

def compile(sources, target, dependencies) #:nodoc:
  return if Buildr.application.options.dryrun
  Buildr.ant 'groovyc' do |ant|
    classpath = dependencies
    ant.taskdef :name => 'groovyc', :classname => ANT_TASK, :classpath => classpath.join(File::PATH_SEPARATOR)
    ant.groovyc groovyc_options(sources, target) do
      sources.each { |src| ant.src :path => src }
      ant.classpath do
        classpath.each { |dep| ant.pathelement :path => dep }
      end
      ant.javac(javac_options)
    end
  end
end