Class: Doubleshot::Compiler

Inherits:
Object show all
Defined in:
lib/doubleshot/compiler.rb,
lib/doubleshot/compiler/classpath.rb

Defined Under Namespace

Classes: Classpath

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, target) ⇒ Compiler

Returns a new instance of Compiler.



7
8
9
10
11
# File 'lib/doubleshot/compiler.rb', line 7

def initialize(source, target)
  @source = Pathname(source.to_s)
  @target = Pathname(target.to_s)
  @classpath = Classpath.new
end

Instance Attribute Details

#classpathObject (readonly)

Returns the value of attribute classpath.



13
14
15
# File 'lib/doubleshot/compiler.rb', line 13

def classpath
  @classpath
end

#sourceObject (readonly)

Returns the value of attribute source.



13
14
15
# File 'lib/doubleshot/compiler.rb', line 13

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



13
14
15
# File 'lib/doubleshot/compiler.rb', line 13

def target
  @target
end

Instance Method Details

#build!(add_target_to_current_classpath = false) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/doubleshot/compiler.rb', line 21

def build!(add_target_to_current_classpath = false)
  @target.mkdir unless @target.exist?

  # The JRuby ant integration throws JRuby Persistence
  # warnings that you can't supress, so we run it
  # inside of a Kernel#silence block.
  silence do
    # Since the ant.path block is instance_evaled,
    # the following line is a hack to ensure we have
    # access to the contents of @classpath.
    classpath = @classpath
    ant.path id: "classpath" do
      classpath.each do |path|
        fileset dir: path
      end
    end

    ant.javac srcdir:     @source.to_s,
      destdir:            @target.to_s,
      debug:              "yes",
      includeantruntime:  "no",
      classpathref:       "classpath"
  end

  $CLASSPATH << @target.to_url if add_target_to_current_classpath
  self
end

#pending?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/doubleshot/compiler.rb', line 15

def pending?
  sources = Pathname::glob(@source + "**/*.java")
  targets = Pathname::glob(@target + "**/*.class")
  !sources.empty? && (targets.empty? || sources.map(&:mtime).max > targets.map(&:mtime).max)
end