Changeset 6131

Show
Ignore:
Timestamp:
11/27/06 15:07:57
Author:
jan
Message:

windows compat enhancements

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jerbil/java_helper.rb

    r6104 r6131  
    7474    # Loads the java virtual machine. This method should only be invoked once, typically 
    7575    # before task definitions in a Rakefile. If the environment variable +JAVA_OPTS+ is 
    76        # set, it will be treated as extra parameter for the initial VM load. 
     76    # set, it will be treated as extra parameter for the initial VM load. 
    7777    # 
    7878    # +classpath+:: a Rake::FileList containing the initial classpath.  
    79        # +build_dir+:: an optional directory (or list of directories) which will be used to resolve classes at runtime. 
    80         # Available options: 
    81         # +:java_home+:: JDK path (defaults to ENV['JAVA_HOME'] 
    82         # +:java_opts+:: additional JVM arguments (defaults to ENV['JAVA_OPTS'] 
    83         # +:loggingprops+:: the location of a java.util.logging configuration file. 
    84         # +:enableassert+:: wheter to enable assertions (default: enabled) 
     79    # +build_dir+:: an optional directory (or list of directories) which will be used to resolve classes at runtime. 
     80          # Available options: 
     81          # +:java_home+:: JDK path (defaults to ENV['JAVA_HOME'] 
     82          # +:java_opts+:: additional JVM arguments (defaults to ENV['JAVA_OPTS'] 
     83          # +:loggingprops+:: the location of a java.util.logging configuration file. 
     84          # +:enableassert+:: wheter to enable assertions (default: enabled) 
    8585    def JavaHelper.load_jvm(classpath, build_dir = nil, options = {} ) 
    8686                         
    87           defaultopts = { :enableassert => true } 
    88          options = defaultopts.merge(options.dup) 
     87            defaultopts = { :enableassert => true } 
     88      options = defaultopts.merge(options.dup) 
    8989           
    9090      #need verbose java exceptions 
     
    9292    
    9393      #include tools.jar from JDK (needed for javac etc.) 
    94       java_home = ENV['JAVA_HOME'] || options[:java_home]  
     94      guess_java_home 
     95       
     96      java_home =  options[:java_home] || ENV['JAVA_HOME'] 
     97       
     98      puts "using JDK in #{java_home}" if Rake.application.options.trace 
     99       
    95100      classpath.include(File.join(java_home, "lib", "tools.jar")) if java_home     
    96       #include build jars and custom classloader 
    97       classpath.include(File.join(File.dirname(__FILE__), "../../buildsupport/*.jar")) 
     101      #include custom classloader 
    98102      classpath.include(File.join(File.dirname(__FILE__), "../../classloader")) if build_dir 
    99103       
    100            
    101104      jvmargs = []     
    102          jvmargs << "-ea" if options[:enableassert] 
     105      jvmargs << "-ea" if options[:enableassert] 
    103106      jvmargs << "-Djava.util.logging.config.file=#{options[:loggingprops].to_s}" if options[:loggingprops]  
    104107        
     
    126129      end 
    127130            
    128          java_opts = ENV['JAVA_OPTS'] || options[:java_opts] 
    129          jvmargs.unshift(java_opts) if java_opts 
    130           
    131          puts jvmargs if ENV['JERBIL_DEBUG'] 
    132        
    133          begin 
     131      java_opts = ENV['JAVA_OPTS'] || options[:java_opts] 
     132      jvmargs.unshift(java_opts) if java_opts 
     133       
     134      puts jvmargs if ENV['JERBIL_DEBUG'] 
     135            
     136      begin 
    134137        Rjb::load(classpath.to_cp, jvmargs) 
    135       rescue  
     138      rescue  
    136139        $stderr << "could not load java vm: make sure JAVA_HOME is set correctly!\n" 
    137140        raise 
     
    140143      #TODO: test javac main and raise if not found 
    141144    end 
    142   end 
     145   
     146    # Tries to guess the JDK path if JAVA_HOME is not set (Windows only).  
     147    def JavaHelper.guess_java_home      
     148        if ENV['JAVA_HOME'].nil? && IS_WINDOWS 
     149          begin 
     150            require 'win32/registry' 
     151            Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\JavaSoft\Java Development Kit\1.5') do |reg| 
     152              ENV['JAVA_HOME'] = reg['JavaHome'] 
     153            end 
     154          rescue   
     155          end 
     156        end 
     157    end 
     158     
     159  end # module JavaHelper 
    143160   
    144161  ###################################################################### 
  • trunk/test/test_java_helper.rb

    r6060 r6131  
    2020   
    2121    def test_to_classes 
     22      JavaHelper.guess_java_home 
    2223      flist = JavaFileList.new("src","dst") 
    2324      flist.add("java/lang/String.java")