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.



153
154
155
156
157
158
159
# File 'lib/rakejava.rb', line 153

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

Instance Attribute Details

#argsObject

Returns the value of attribute args.



150
151
152
# File 'lib/rakejava.rb', line 150

def args
  @args
end

#bootpathObject

Returns the value of attribute bootpath.



150
151
152
# File 'lib/rakejava.rb', line 150

def bootpath
  @bootpath
end

#classpathObject

Returns the value of attribute classpath.



150
151
152
# File 'lib/rakejava.rb', line 150

def classpath
  @classpath
end

#debugObject

Returns the value of attribute debug.



151
152
153
# File 'lib/rakejava.rb', line 151

def debug
  @debug
end

#destObject

Returns the value of attribute dest.



150
151
152
# File 'lib/rakejava.rb', line 150

def dest
  @dest
end

#dest_verObject

Returns the value of attribute dest_ver.



151
152
153
# File 'lib/rakejava.rb', line 151

def dest_ver
  @dest_ver
end

#srcObject

Returns the value of attribute src.



150
151
152
# File 'lib/rakejava.rb', line 150

def src
  @src
end

#src_verObject

Returns the value of attribute src_ver.



151
152
153
# File 'lib/rakejava.rb', line 151

def src_ver
  @src_ver
end

Instance Method Details

#changed_only(sources) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/rakejava.rb', line 207

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



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
188
189
190
191
192
193
194
195
# File 'lib/rakejava.rb', line 161

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



197
198
199
200
201
202
203
204
205
# File 'lib/rakejava.rb', line 197

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