Changeset 6133
- Timestamp:
- 11/27/06 18:13:15
- Files:
-
- trunk/lib/jerbil/java_helper.rb (modified) (9 diffs)
- trunk/lib/jerbil/javac_task.rb (modified) (1 diff)
- trunk/test/test_java_helper.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/jerbil/java_helper.rb
r6132 r6133 12 12 module Jerbil 13 13 IS_WINDOWS = RUBY_PLATFORM =~ /mswin|mingw/i 14 JAVA_PATH_SEPERATOR = IS_WINDOWS ? ';' : ':' 15 DIR_SEP = IS_WINDOWS ? "\\" : "/" 16 DIR_SEP_FOR_SUBSTITUTION = IS_WINDOWS ? "\\\\" : "/" 14 JAVA_PATH_SEPARATOR = File::PATH_SEPARATOR 17 15 18 16 # The JavaHelper module provides common helper functionality needed across different … … 228 226 # For example src/org/foo/Baz -> org.foo.Baz. 229 227 def to_classnames 230 # remove the initial directory and separator 231 sub = srcdir + DIR_SEP_FOR_SUBSTITUTION 232 paths = self.pathmap("%{^#{sub},}X") 233 234 paths.gsub!(DIR_SEP, ".") 235 #paths.gsub!("/", "." ) 228 # remove the initial directory and separator 229 paths = self.pathmap("%{^#{srcdir_quoted}/?,}X") 230 paths.gsub!("/", ".") 236 231 end 237 232 … … 239 234 # load the specified classes into the virtual machine. 240 235 def to_classes 241 classnames = to_classnames 236 classnames = to_classnames 242 237 classes = classnames.map {|name| Rjb::import(name)} 243 238 classes.to_a … … 249 244 # For example src/org/foo/Baz.java -> classes/org/foo/Baz.class. 250 245 def to_classfiles 251 self.pathmap("%{^#{srcdir },#{dstdir}}X.class")246 self.pathmap("%{^#{srcdir_quoted},#{dstdir}}X.class") 252 247 end 253 248 … … 273 268 # Calls block once for each resource found in +srcdir+, passing 274 269 # the source and destination file as parameter. 275 def resource_and_target # :yields: resource,target 270 def resource_and_target # :yields: resource,target 276 271 resources.each do | r | 277 target = r.sub(/#{srcdir }/, dstdir)272 target = r.sub(/#{srcdir_quoted}/, dstdir) 278 273 yield r, target if block_given? 279 274 end … … 284 279 def source_and_target # :yields: src,target 285 280 self.each do |file| 286 yield file, file.pathmap("%{^#{srcdir },#{dstdir}}X.class")281 yield file, file.pathmap("%{^#{srcdir_quoted},#{dstdir}}X.class") 287 282 end 288 end 283 end 289 284 290 285 def out_of_date … … 314 309 exts.to_a.each {|ext| add_extension(ext)} 315 310 end 311 312 private 313 def srcdir_quoted 314 Regexp.quote(srcdir) 315 end 316 316 end 317 317 … … 342 342 343 343 def sourcepath 344 self.srcdir.join(JAVA_PATH_SEP ERATOR)344 self.srcdir.join(JAVA_PATH_SEPARATOR) 345 345 end 346 346 … … 407 407 # Returns the filelist formatted as Java classpath. 408 408 # ("/tmp/foo.jar:/tmp/baz.jar") 409 def to_cp(sep = Jerbil::JAVA_PATH_SEP ERATOR)409 def to_cp(sep = Jerbil::JAVA_PATH_SEPARATOR) 410 410 self.join(sep) 411 411 end trunk/lib/jerbil/javac_task.rb
r6104 r6133 47 47 parms += [ "-sourcepath", java_files.sourcepath ] if java_files.sourcepath 48 48 49 parms << "-verbose" if verbose 49 parms << "-verbose" if verbose 50 parms += extra_args.collect {|a|a.to_s} if extra_args 50 51 52 files = gather_filenames 53 51 54 # must do this to prevent javac bombing out on the file package-info.java 52 55 # due to known javac bug 6198196 - 53 # http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6198196 54 java_files.gsub!( "/", "\\" ) if Jerbil::IS_WINDOWS 55 56 parms += extra_args.collect {|a|a.to_s} if extra_args 57 parms += gather_filenames 58 56 # http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6198196 57 if Jerbil::IS_WINDOWS 58 files.map! {|fn| fn.sub("/", "\\")} 59 end 60 61 parms += files 62 59 63 #require 'pp' 60 64 #pp parms trunk/test/test_java_helper.rb
r6131 r6133 30 30 assert_equal 'java.util.Map', cf[1].getName 31 31 end 32 32 33 33 34 def test_to_cp … … 38 39 39 40 def test_javafiles 40 flist = JavaFileList.new(File.join(File.dirname(__FILE__), "../example/src"), "../example/build") 41 assert_equal 5, flist.to_classnames.length, flist.to_classnames 41 flist = JavaFileList.new( 42 File.join(File.dirname(__FILE__), "..", "example", "src"), 43 File.join(File.dirname(__FILE__), "..", "example", "build")) 44 45 classnames = flist.to_classnames 46 assert_equal 5, classnames.length, classnames 42 47 assert_equal 1, flist.resources.length, flist.resources 48 49 assert_equal ['jerbil.example.JerbilEntity', 50 'jerbil.example.Jerbiliser', 51 'jerbil.example.Main', 52 'jerbil.example.Main2', 53 'jerbil.example.MyAnnotation'], classnames.sort 54 55 #assert_equal ['./../example/src/jerbil/example/example.properties'], 56 # flist.resources.sort 43 57 44 58 #flist.source_and_target do |s,t|
