Changeset 6019

Show
Ignore:
Timestamp:
11/08/06 23:52:12
Author:
jan
Message:

jerbil gem builds ok

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Rakefile

    r6010 r6019  
    44require 'rake/rdoctask' 
    55 
    6  
    76task :default => :test  
    8  
    9 Rake::TestTask.new do |t| 
    10   t.libs << "test" 
    11   t.test_files = FileList['test/test*.rb'] 
    12   t.verbose = false 
    13 end 
    14  
    15  
    16 desc "install sample Rakefile. Specify your SRC=x and TESTSRC=y for your source file locations." 
    17 task :install do |t| 
    18  
    19   dstfile = File.join(Rake.original_dir, "../Rakefile") 
    20      
    21   raise "\n#{dstfile} already exists, delete it first to proceed\n" if File.exists?(dstfile) 
    22    
    23   src = ENV['SRC'] || "src" 
    24   testsrc = ENV['TESTSRC'] || "testsrc" 
    25    
    26   rfile = File.read('Rakefile.jerbil') 
    27    
    28   rfile.gsub!(/##SRC##/, src) 
    29   rfile.gsub!(/##TESTSRC##/, testsrc) 
    30    
    31   File.open( dstfile, 'w' ) do |f| 
    32     f << rfile 
    33   end   
    34    
    35   puts "created sample Rakefile in #{dstfile}" 
    36 end 
    377 
    388def read_version 
     
    5323  s.requirements << 'rjb' 
    5424  s.requirements << 'JDK 5.0' 
    55   files = FileList['lib/*.rb', 'lib/jerbil/*.rb', 'samples/**/*',  
    56                    'test/*.rb', 'classloader/*' 'COPYING', 'ChangeLog', 'README'] 
    57    
     25  files = FileList['lib/**/*', 'test/*.rb', 'buildsupport/**/*', 'classloader/*', 'COPYING', 'ChangeLog', 'README'] 
     26  s.has_rdoc = false 
    5827  s.files = files 
    5928  s.test_files = FileList['test/*.rb'] 
     
    7443end 
    7544   
     45Rake::TestTask.new do |t| 
     46  t.libs << "test" 
     47  t.test_files = FileList['test/test*.rb'] 
     48  t.verbose = false 
     49end 
     50 
     51desc "compile the classloader" 
    7652task :compile_classloader do |t| 
    7753  javac = "javac" 
  • trunk/classloader/JerbilClassLoader.java

    r5865 r6019  
    33import java.io.IOException; 
    44import java.io.ByteArrayOutputStream; 
     5import java.io.ByteArrayInputStream; 
    56import java.io.InputStream; 
     7import java.util.Arrays; 
    68 
    79/** 
    8  * TODO: comment 
     10 * <p>A classloader which is used by the jerbil build system to dynamically 
     11 * add classes to the running VM, after they've been built.</p> 
     12 * 
     13 * <p>The initial build paths must be set using the system property 
     14 * <code>jerbil.build.root</code> (classpath-like).</p> 
    915 */ 
    1016public class JerbilClassLoader extends ClassLoader { 
    1117   
    12     private static final boolean debug = Boolean.getBoolean( "jerbil.debug" ); 
    13      
     18    private final boolean debug = Boolean.getBoolean( "jerbil.debug" ); 
     19    private final String[] roots; 
     20 
    1421    public JerbilClassLoader(ClassLoader parent) { 
    1522        super( parent ); 
     23        String root = System.getProperty( "jerbil.build.root" ); 
     24        if ( root == null ) { 
     25            throw new IllegalArgumentException("Need to set system property build.root!"); 
     26        } 
     27        roots = root.split(":"); 
     28        debug("initialised with root paths " + Arrays.asList(roots)); 
    1629    } 
    1730 
    1831    public Class<?> findClass(String name) throws 
    1932            ClassNotFoundException { 
    20                
    21         if (debug) { 
    22           System.err.println( "findClass(" + name + ")" ); 
    23         } 
    24          
     33        debug( "findClass(" + name + ")" ); 
    2534        byte[] classBytes = findClassBytes( name ); 
    2635        return defineClass( name, classBytes, 
    2736                0, classBytes.length ); 
     37    } 
     38 
     39    public InputStream getResourceAsStream(String name) { 
     40        debug("getResourceAsStream(" + name + ")"); 
     41 
     42        File f = null; 
     43        for (String root : roots) { 
     44            File aFile = new File(root, name); 
     45            if ( aFile.exists()) { 
     46                f = aFile; 
     47                debug("resolved to " + aFile.toString()); 
     48                break; 
     49            } 
     50        } 
     51 
     52        if (f != null) { 
     53            try { 
     54                return new ByteArrayInputStream(readBytes(new FileInputStream(f))); 
     55            } catch (Exception e) {/*falltrough*/} 
     56        } 
     57 
     58        return super.getResourceAsStream(name); 
    2859    } 
    2960 
     
    3263        try 
    3364        { 
    34             String root = System.getProperty( "build.root" ); 
    35             if ( root == null ) 
    36             { 
    37                 throw new ClassNotFoundException( "Class " + className + " not found: set build.root" ); 
     65            File f = null; 
     66            for (String root : roots) { 
     67                String pathName = root + 
     68                        File.separatorChar + className. 
     69                        replace( '.', File.separatorChar ) 
     70                        + ".class"; 
     71 
     72                File aFile = new File(pathName); 
     73                if (aFile.exists()) { 
     74                    f = aFile; 
     75                    debug("resolved to " + aFile.toString()); 
     76                    break; 
     77                } 
     78           } 
     79 
     80            if (f == null)  { 
     81                throw new ClassNotFoundException("Class " + className + " not found"); 
    3882            } 
    39             String pathName = root + 
    40                     File.separatorChar + className. 
    41                     replace( '.', File.separatorChar ) 
    42                     + ".class"; 
     83            return readBytes(new FileInputStream(f)); 
     84        } 
     85        catch ( IOException e ) 
     86        { 
     87            throw new ClassNotFoundException( "Class " + className + " not found: I/O", e ); 
     88        } 
     89    } 
    4390 
    44             in = new FileInputStream( pathName ); 
    45  
    46             ByteArrayOutputStream out = new ByteArrayOutputStream(); 
    47             byte[] buffer = new byte[16384]; 
    48  
    49             int c; 
     91    private byte[] readBytes(InputStream in) throws IOException { 
     92        ByteArrayOutputStream out = new ByteArrayOutputStream(); 
     93        byte[] buffer = new byte[16384]; 
     94        int c; 
     95        try { 
    5096            while ((c = in.read( buffer )) >= 0) 
    5197            { 
     
    5399            } 
    54100            return out.toByteArray(); 
    55         } 
    56         catch ( IOException e ) 
    57         { 
    58             throw new ClassNotFoundException( "Class " + className + " not found: I/O", e ); 
    59         } 
    60         finally 
    61         { 
    62             if ( in != null ) 
     101        } finally { 
     102           if ( in != null ) 
    63103            { 
    64104                try 
     
    71111        } 
    72112    } 
     113 
     114    private void debug(String s) { 
     115        if (debug) { 
     116            System.err.println(getClass().getSimpleName() + ": " + s); 
     117        } 
     118    } 
    73119} 
  • trunk/lib/jerbil/java_helper.rb

    r6010 r6019  
    6363  end 
    6464   
    65   def load_vm(classpath, loggingprops = nil, build_dir = nil )  
     65  def load_vm(classpath, build_dir = nil, loggingprops = nil )  
    6666    #need verbose java exceptions 
    6767    $VERBOSE = true 
     68   
     69    #include tools.jar from JDK (needed for javac etc.) 
     70    java_home = ENV['JAVA_HOME'] 
     71    classpath.include(File.join(java_home, "lib", "tools.jar")) if java_home     
    6872    #include build jars and custom classloader 
    69      
    70     java_home = ENV['JAVA_HOME'] 
    71     classpath.include(File.join(java_home, "lib", "tools.jar")) if java_home 
    72      
    7373    classpath.include(File.join(File.dirname(__FILE__), "../../buildsupport/*.jar")) 
    7474    classpath.include(File.join(File.dirname(__FILE__), "../../classloader")) unless build_dir.nil? 
     
    9191     
    9292    if build_dir 
    93         jvmargs += [ "-Djava.system.class.loader=JerbilClassLoader",  
    94         "-Dbuild.root=#{build_dir}", "-Djerbil.debug=false" ]  
    95     end 
    96          
     93      jvmargs += [ "-Djava.system.class.loader=JerbilClassLoader",  
     94        "-Djerbil.build.root=#{build_dir.to_a.join(':')}", "-Djerbil.debug=false" ]  
     95    else       
     96      $stderr << "jerbil: build_dir not set: dynamic classloading is disabled\n" if Rake.application.options.trace 
     97    end 
     98          
    9799    begin 
    98100        Rjb::load(classpath.to_cp, jvmargs) 
     
    101103      raise 
    102104    end 
    103      
     105    
    104106    #TODO: test javac main and raise if not found 
    105107  end 
  • trunk/sample/Rakefile

    r5865 r6019  
     1$:.unshift File.join( File.dirname(__FILE__),  "..", "lib" ) 
     2 
    13require 'rake' 
    2 Dir[File.join(Rake.original_dir, "..", "lib", "*.rb")].each {|f| require f} 
     4require 'jerbil' 
    35require 'buildconfig' 
    46