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::Groovy::Groovyc).groovy = '1.7.1'

namespace before this file is required.

ArtifactNamespace.for(self) do |ns|
  ns.groovy!       'org.codehaus.groovy:groovy:jar:>=1.7.5'
  ns.commons_cli!  'commons-cli:commons-cli:jar:>=1.2'
  ns.asm!          'asm:asm:jar:>=3.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:



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

def initialize(project, options) #:nodoc:
  super
  options[:debug] = Buildr.options.debug if options[:debug].nil?
  options[:deprecation] ||= false
  options[:optimise] ||= false
  options[:verbose] ||= trace?(:groovyc) 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)


87
88
89
90
91
92
# File 'lib/buildr/groovy/compiler.rb', line 87

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:



83
84
85
# File 'lib/buildr/groovy/compiler.rb', line 83

def dependencies #:nodoc:
  REQUIRES.artifacts
end

Instance Method Details

#compile(sources, target, dependencies) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/buildr/groovy/compiler.rb', line 115

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