Class: Buildr::Compiler::Ajc

Inherits:
Base
  • Object
show all
Defined in:
lib/ajc.rb

Constant Summary collapse

REQUIRES =
Buildr.struct(
  #:aspectj => "org.aspectj:aspectjrt:jar:1.6.9",
  #:aspectjlib => "org.aspectj:aspectjlib:jar:1.6.2",
  #:aspectjweaver => "org.aspectj:aspectjweaver:jar:1.6.9",
	:aspectjtools => "org.aspectj:aspectjtools:jar:1.6.9"
)
OPTIONS =
[:warnings, :debug, :deprecation, :source, :target, :lint, :other, :Xlint, :aspectpath, :verbose]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, options) ⇒ Ajc

:nodoc:



26
27
28
29
# File 'lib/ajc.rb', line 26

def initialize(project, options) #:nodoc:
  super
  @project = project
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



24
25
26
# File 'lib/ajc.rb', line 24

def project
  @project
end

Instance Method Details

#compile(sources, target, dependencies) ⇒ Object

:nodoc:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ajc.rb', line 31

def compile(sources, target, dependencies) #:nodoc:
  return if Buildr.application.options.dryrun

  info "options: #{options.inspect}"
  info "sources: #{sources.inspect}"
  info "dependencies: #{dependencies}"

  options[:source] ||= "1.6"

  cmd_args = []
  cmd_args << '-d' << File.expand_path(target)

  cmd_args << '-classpath' << dependencies.join(File::PATH_SEPARATOR) unless dependencies.empty?

  in_paths = sources.select { |source| File.directory?(source) }
  puts "inpath: #{in_paths.inspect}"
  cmd_args << '-inpath' << in_paths.join(File::PATH_SEPARATOR) unless in_paths.empty?

  cmd_args += javac_args

  cmd_args += files_from_sources(sources)

  aspect_path = []
  if options[:aspectpath] and not options[:aspectpath].empty?
    dependencies.each { |dep| options[:aspectpath].each { |regex| aspect_path<< dep if Regexp.new(regex).match dep}  }
  end
  aspect_path << options[:test_apspectpath] if options[:test_apspectpath]
  info "aspect path: #{aspect_path.inspect}"
  cmd_args << '-aspectpath' << aspect_path.join(File::PATH_SEPARATOR)

  Java.load # may be called by other extension before...so this has no effect

  messages = Java.org.aspectj.bridge.MessageHandler.new
  Java.org.aspectj.tools.ajc.Main.new.run(cmd_args.to_java(Java.java.lang.String), messages)

  messages.get_unmodifiable_list_view.each { |i| info i } if options[:verbose]
  messages.get_warnings.each { |w| warn w }
  messages.get_errors.each { |e| error e }
  
  fail 'Failed to compile, see errors above' if messages.get_errors.length > 0
end