| Class | Raven::JavacTask |
| In: |
lib/raven/java_tasks.rb
|
| Parent: | Rake::Task |
Executes Javac by passing it everything it needs. Stuff like a classpath and sources. The classpath is built by checking the prerequisites of the javac task. When a prerequisite is a dependency declaration (dependency task), it takes each declared Gems and adds the jar files found in them to the classpath.
Can be customized by adding directories to the build_path using the << operator (if none defined, default is src/main/java).
# File lib/raven/java_tasks.rb, line 46
46: def execute
47: super
48: @classpath = Raven.build_cp(prerequisites)
49: @classpath << "target/classes"
50: @build_path = ["src/main/java"] unless @build_path
51:
52: puts "Building path #{@build_path.join(' ')}" if RakeFileUtils.verbose_flag
53:
54: Dir.mkdir("target") unless File.exist?("target")
55: Dir.mkdir("target/classes") unless File.exist?("target/classes")
56: # Getting the source files to compile. Filtrating sources already
57: # compiled having a fresh enough class
58: source_files = @build_path.collect do |d|
59: puts "Warning: build path #{d} doesn't exist!" unless File.exist? d
60: Dir.glob("#{d}/**/*.java").select do |java|
61: classfile = 'target/classes/' + java[d.length, (java.length - 5 - d.length)] + '.class'
62: File.exist?(classfile) ? File.stat(java).mtime > File.stat(classfile).mtime : true
63: end
64: end.flatten
65:
66: if (source_files.size > 0)
67: # Getting only package names, it shortens the command line
68: source_pkg = Set.new
69: source_files.each { |src| source_pkg << File.join(File.dirname(src), '*.java') }
70: # Executing javac
71: puts "javac -classpath \"#{@classpath.join(CP_SEP)}\" -sourcepath \"#{@build_path.join(CP_SEP)}\" -d target/classes #{source_pkg.to_a.join(' ')}" if RakeFileUtils.verbose_flag
72: `javac -classpath "#{@classpath.join(CP_SEP)}" -sourcepath "#{@build_path.join(CP_SEP)}" -d target/classes #{source_pkg.to_a.join(' ')}`
73: unless $?.exitstatus == 0
74: puts "Build failed, see above errors."
75: exit
76: end
77: else
78: puts 'All class files are up to date.' if RakeFileUtils.verbose_flag
79: end
80: end