Class: RakeJava::JavacTask

Inherits:
Rake::Task
  • Object
show all
Includes:
RakeJavaUtil
Defined in:
lib/rakejava.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RakeJavaUtil

#path_esc, #path_sep, #popd, #pushd, #pushd_stack, #separate, #space_sep, #winderz?

Constructor Details

#initialize(name, app) ⇒ JavacTask

Returns a new instance of JavacTask.



145
146
147
148
149
150
151
# File 'lib/rakejava.rb', line 145

def initialize name, app
   super
   @src = []
   @srcpath = []
   @bootpath = []
   @classpath = []
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



142
143
144
# File 'lib/rakejava.rb', line 142

def args
  @args
end

#bootpathObject

Returns the value of attribute bootpath.



142
143
144
# File 'lib/rakejava.rb', line 142

def bootpath
  @bootpath
end

#classpathObject

Returns the value of attribute classpath.



142
143
144
# File 'lib/rakejava.rb', line 142

def classpath
  @classpath
end

#debugObject

Returns the value of attribute debug.



143
144
145
# File 'lib/rakejava.rb', line 143

def debug
  @debug
end

#destObject

Returns the value of attribute dest.



142
143
144
# File 'lib/rakejava.rb', line 142

def dest
  @dest
end

#dest_verObject

Returns the value of attribute dest_ver.



143
144
145
# File 'lib/rakejava.rb', line 143

def dest_ver
  @dest_ver
end

#srcObject

Returns the value of attribute src.



142
143
144
# File 'lib/rakejava.rb', line 142

def src
  @src
end

#src_verObject

Returns the value of attribute src_ver.



143
144
145
# File 'lib/rakejava.rb', line 143

def src_ver
  @src_ver
end

Instance Method Details

#changed_only(sources) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/rakejava.rb', line 199

def changed_only sources
   # Retuns the files that have newer .java files than .class files
   changed = []
   sources.each do |src_file|
      mod_time = File.mtime(src_file)
      base = File.basename(src_file, ".java")
      parent = File.dirname(src_file)
      classfiles = []
      
      if @dest
         base_path = parent[sources.root.length+1..-1]
         classfiles = Dir["#{@dest}/#{base_path}/#{base}*.class"]
      else
         # Look next to it
         classfiles = Dir["#{parent}/#{base}*.class"]
      end
         
      unless classfiles.empty?
         classfiles.each do |classfile|
            if File.mtime(classfile) < mod_time
               changed << src_file
               break
            end
         end
      else
         changed << src_file
      end
   end
   changed
end

#execute(args = nil) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/rakejava.rb', line 153

def execute args=nil
   super
   files = src_files
   
   unless files.empty?
      srcpath = @src.map { |src| src.root }

      @bootpath.flatten!
      @classpath.flatten!
      
      cmd = "javac"
      cmd << " -bootclasspath #{path_sep(@bootpath)}" unless @bootpath.empty?
      cmd << " #{@args}"                              if @args
      cmd << " -classpath #{path_sep(@classpath)}"    unless @classpath.empty?
      cmd << " -g"                                    if @debug
      cmd << " -source #{@src_ver}"                   if @src_ver
      cmd << " -target #{@dest_ver}"                  if @dest_ver
      cmd << " -sourcepath #{path_sep(srcpath)}"      if srcpath
      cmd << " -d #{@dest}"                           if @dest
      cmd << " #{space_sep(files)}"
      
      max_cmd_len = 500
      if cmd.length < max_cmd_len
         puts cmd
      else
         puts cmd[0..max_cmd_len] + "..."
      end
      puts "Compiling #{files.length} file(s)"
      system "#{cmd}"
      puts
   else
      puts "No files to compile"
   end
   
end

#src_filesObject



189
190
191
192
193
194
195
196
197
# File 'lib/rakejava.rb', line 189

def src_files
   files = []
   
   @src.each do |source|
      files << changed_only(source)
   end
   
   files.flatten
end