Changeset 6138

Show
Ignore:
Timestamp:
11/27/06 21:09:49
Author:
jan
Message:

more documentation

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/README

    r6128 r6138  
    3131== Installation 
    3232 
    33 You need to have Ruby and rubygems installed. On Debian systems (testing) this is a simple as: 
     33You need to have Ruby and rubygems installed. The Windows version of Ruby already ships with gem. 
     34On Debian systems (testing) you can install it using apt-get: 
    3435   
    3536  % apt-get install rubygems 
     
    5354== Usage 
    5455 
    55 A minimal Rakefile to compile Java files looks like this: 
     56A minimal Rakefile to compile Java files could look like this: 
    5657 
    5758        require 'jerbil' 
     
    7576in the repository. 
    7677 
    77   % svn co http://svn.trampolinesystems.com/jerbil/trunk/example 
     78  % svn checkout http://svn.trampolinesystems.com/jerbil/trunk/example 
    7879 
    7980== Advantages over Ant 
     
    8182See Martin Fowler's article[http://www.martinfowler.com/articles/rake.html] for a detailed 
    8283discussion on Rake vs. Ant. Besides the more compact build scripts you also get ability to 
    83 implement arbitrary Java interfaces in Ruby (see Jerbil::TestNG::TestListener for an example). 
     84implement arbitrary Java interfaces in Ruby (see Jerbil::TestNG::DefaultTestListener for an example). 
    8485Another possibility is build script metaprogramming, i.e. creating your tasks programmatically: 
    8586 
     
    102103 
    103104* Raven[http://raven.rubyforge.org/]: similar to Jerbil in scope, but different approach (invokes  
    104   javac directly, no Java-Ruby integration). 
     105  javac externally, no Java-Ruby integration). 
    105106  
    106107== FAQ 
  • trunk/Rakefile

    r6126 r6138  
    6464  rdoc.rdoc_files.include("README", "CHANGES", "TODO", "LICENSE", "lib/**/*.rb") 
    6565        rdoc.rdoc_dir = 'rdoc' 
     66  rdoc.template = 'externals/allison/allison.rb' 
    6667end 
    6768   
  • trunk/example/Rakefile

    r6103 r6138  
    8484 
    8585file ANNOTATED_CLASSES => [ :find_annotations ] 
    86 file PERSISTENCE_YML   => [ :find_annotations ] 
     86file ENTITIES_YML   => [ :find_annotations ] 
    8787desc "find annotations and write output to #{ANNOTATED_CLASSES}" 
    8888Jerbil::AptTask.new(:find_annotations) do |t| 
     
    9393    File.open(ANNOTATED_CLASSES, 'w') { |f| f << classes.to_yaml } 
    9494  end 
    95   t.annotated_classes_to_yaml('javax.persistence.Entity', PERSISTENCE_YML) 
     95  t.annotated_classes_to_yaml('javax.persistence.Entity', ENTITIES_YML) 
    9696end 
    9797 
     
    100100Jerbil::Hibernate::ExportSchemaTask.new(:export_schema) do |t| 
    101101  t.schemafile = DB_SCHEMA 
    102   t.persistencefile = PERSISTENCE_YML 
     102  t.entities_yml = ENTITIES_YML 
    103103end 
  • trunk/example/buildconfig.rb

    r6103 r6138  
    1414CLASSPATH           = FileList["./#{JAVA_BUILD_DIR}", "./lib/*.jar" ] 
    1515DB_SCHEMA           = File.join(BUILD_DIR, "schema.sql") 
    16 PERSISTENCE_YML     = File.join(BUILD_DIR, "persistence.yml") 
     16ENTITIES_YML         = File.join(BUILD_DIR, "entities.yml") 
  • trunk/externals

    • Property svn:externals set to allison svn://rubyforge.org/var/svn/allison/allison
  • trunk/lib/jerbil/apt_task.rb

    r6060 r6138  
    2222  class AptTask < JavacTask 
    2323 
     24                # A hash containing annotation types and handlers (code blocks). 
    2425    attr_accessor :annotations 
     26                 
     27                # Only process annotations, don't compile anything. 
    2528    attr_accessor :nocompile 
    2629     
  • trunk/lib/jerbil/hibernate_task.rb

    r6053 r6138  
    77module Jerbil  
    88  module Hibernate  
    9     # Generate a sql schema from EJB3/Hibernate-annotated classes using Hibernate's 
    10     # SchemaExport tool. 
     9    # Generates a SQL schema from EJB3/Hibernate-annotated classes using Hibernate's 
     10    # SchemaExport tool. Typically Jerbil::AptTask is used to compile source files and 
     11                # gather a list of entities which then gets serialized to a YAML file. 
     12                # ExportSchemaTask then reads this file and uses Hibernate's schema exporter to  
     13                # generate SQL 
    1114    # 
    1215    # == Example 
    1316    #   Jerbil::Hibernate::ExportSchemaTask.new(:export_schema) do |t| 
    1417    #       t.schemafile = "schema.sql" 
    15     #       t.persistencefile = PERSISTENCE_YML       
     18    #       t.entities_yml = ENTITIES_YML       
    1619    #   end 
    1720    class ExportSchemaTask < Rake::TaskLib 
     
    2023      attr_accessor :name 
    2124       
     25                        # SQL schema destination file (default: schema.sql) 
    2226      attr_accessor :schemafile 
    23       attr_accessor :persistencefile 
     27                         
     28                        # A file containing a list of entities (<em>javax.persitence.Entity</em>), 
     29                        # serialized as a list of strings (YAML format). 
     30      attr_accessor :entities_yml 
     31                         
     32                        # Classname implementing the db dialect, defaults to 
     33                        # <em>org.hibernate.dialect.MySQL5Dialect</em> 
    2434      attr_accessor :dialect 
     35                         
     36                        # SQL statements to be executed before generated sql. 
    2537      attr_accessor :preamble 
     38                         
     39                        # FQN of a package containing package-info.java to be used by 
     40                        # hibernate. 
    2641      attr_accessor :package 
    2742       
     
    3146        @package = nil 
    3247        @schemafile = "schema.sql" 
    33         @persistencefile = "persistence.yml" 
     48        @entities_yml = "entities.yml" 
    3449        @dialect = "org.hibernate.dialect.MySQL5Dialect" 
    3550                 
     
    3853      end 
    3954       
    40       def define 
     55      def define # :nodoc: 
    4156        task name => dependencies do |t|        
    4257     
    43           entities = File.open(persistencefile) {|f| YAML.load(f)} 
     58          entities = File.open(entities_yml) {|f| YAML.load(f)} 
    4459     
    4560          raise 'no annotated entities found!' if entities.empty? 
     
    5570          schema << "# generated by Jerbil::Hibernate::ExportSchemaTask at #{Time.new}\n\n" 
    5671           
    57           schema << preamble unless preamble.nil? 
     72          schema << preamble if preamble 
    5873           
    5974          schema << IO.read(schemafile) 
     
    6782        end 
    6883        file schemafile => name 
    69         task name => persistencefile 
     84        task name => entities_yml 
    7085      end   
    7186    end 
     
    137152          packages << pkg.getName if pkg && pkg.getAnnotations.length > 0 
    138153        end 
    139         packages << package unless package.nil? 
     154        packages << package if package 
    140155        packages.each { |pkg| acfg.addPackage(pkg) } 
    141156        acfg 
  • trunk/lib/jerbil/jar_task.rb

    r6053 r6138  
    2424    end 
    2525     
    26     def define 
     26    def define # :nodoc: 
    2727      jardir = File.dirname(filename) 
    2828      depends_on jardir 
  • trunk/lib/jerbil/java_helper.rb

    r6133 r6138  
    7474    # +build_dir+:: an optional directory (or list of directories) which will be used to resolve classes at runtime. 
    7575          # Available options: 
    76           # +:java_home+:: JDK path (defaults to ENV['JAVA_HOME'] 
    77           # +:java_opts+:: additional JVM arguments (defaults to ENV['JAVA_OPTS'] 
    78           # +:loggingprops+:: the location of a java.util.logging configuration file. 
    79           # +:enableassert+:: wheter to enable assertions (default: enabled) 
     76          # +java_home+:: JDK path (defaults to ENV['JAVA_HOME']) 
     77          # +java_opts+:: additional JVM arguments (defaults to ENV['JAVA_OPTS']) 
     78          # +loggingprops+:: the location of a java.util.logging configuration file. 
     79          # +enableassert+:: wheter to enable assertions (default: enabled) 
     80                # 
     81                # ==Example 
     82                # 
     83                #               load_jvm(FileList.new("lib/*.jar"), "build", :loggingprops => "logging.properties") 
     84                # 
    8085    def JavaHelper.load_jvm(classpath, build_dir = nil, options = {} ) 
    8186                         
     
    135140        raise 
    136141      end 
    137       
    138       #TODO: test javac main and raise if not found 
    139142    end 
    140143   
    141144    # Tries to guess the JDK path if JAVA_HOME is not set (Windows only).  
    142     def JavaHelper.guess_java_home      
     145    def JavaHelper.guess_java_home # :nodoc:   
    143146        if ENV['JAVA_HOME'].nil? && IS_WINDOWS 
    144147          begin 
     
    204207  # A JavaFileList is a specialisation of a standard Rake::FileList. 
    205208  # It includes additional methods to deal with build dirs, resources  
    206   # and other java specifics. 
     209  # and other Java related things. 
    207210  class JavaFileList < Rake::FileList 
    208211    attr_reader :srcdir 
     
    210213    attr_accessor :resource_patterns 
    211214     
    212     # srcdir:: the directory containing the Java source file.  
     215    # srcdir:: the directory containing the Java source files.  
    213216    # dstdir:: destination directory for class files (used by JavacTask). 
    214217    # extensions:: a list of extensions to treat as resources. The default is to treat 
     
    223226    end 
    224227     
    225     # Returns a list of all java source files formatted as java class names. 
     228    # Returns a list of all java source files formatted as Java class names. 
    226229    # For example src/org/foo/Baz -> org.foo.Baz. 
    227230    def to_classnames 
     
    283286    end         
    284287     
     288                # Returns a list of out-of-date files, based on timestamp comparison. 
    285289    def out_of_date 
    286290      return self.to_a unless (File.exists?(dstdir) and Dir.entries(dstdir).length > 2)       
     
    326330  #   JAVA_FILES = MultiJavaFileList.new(MODULES, JAVA_BUILD_DIR, SOURCE_DIR) 
    327331  # 
    328   # This will look for source files in +a/src+ and +b/src+, compiling into +classes+. 
     332  # This will look for source files in <em>a/src</em> and <em>b/src</em>, 
     333        # compiling into +classes+. 
    329334  class MultiJavaFileList 
    330335   
     
    428433 
    429434# make load_jvm available to toplevel 
     435# See JavaHelper.load_jvm. 
    430436def load_jvm(args, build_dir, options={}) 
    431437        Jerbil::JavaHelper.load_jvm(args, build_dir, options)                    
  • trunk/lib/jerbil/java_task.rb

    r6053 r6138  
    7777      
    7878     protected 
    79      def define 
     79     def define # :nodoc: 
    8080        #desc "run #{classname}" if Rake.application.last_comment.nil?       
    8181        task name => dependencies do |t| 
  • trunk/lib/jerbil/javac_task.rb

    r6133 r6138  
    55module Jerbil 
    66  # Compiles Java source files.  
    7   # The location of the source files and the destionation directory is encapsulated 
    8   # in a JavaFileList. 
     7  # The location of the source files and the destination directory is specified 
     8  # by a JavaFileList. 
    99  # 
    1010  # == Example 
     
    1212  #  desc "compile all java files" 
    1313  #  Jerbil::JavacTask.new(:compile) do |t| 
    14   #    t.java_files = Jerbil::JavaFileList.new("src", "classes") 
     14  #    t.java_files = JavaFileList.new("src", "classes") 
    1515  #    t.options :nowarn, :debug 
    1616  #  end 
     
    1919     
    2020    attr_accessor :name 
     21                 
     22                # A JavaFileList, specifying what to compile and where 
     23                # to write the output to. 
    2124    attr_accessor :java_files 
     25                 
    2226    attr_accessor :verbose 
    2327 
     
    3943    end 
    4044     
    41     def define 
     45    def define # :nodoc: 
    4246            desc "compile files in #{java_files.srcdir.to_a.join(', ')}" if Rake.application.last_comment.nil?      
    4347      task name => dependencies do |t| 
  • trunk/lib/jerbil/javadoc_task.rb

    r6054 r6138  
    2828     end 
    2929      
    30      def define 
     30     def define # :nodoc: 
    3131      desc "generate javadocs" if Rake.application.last_comment.nil? 
    3232      task name => dependencies do |t| 
  • trunk/lib/jerbil/jibx_task.rb

    r6053 r6138  
    44 
    55module Jerbil 
    6   # Compiles JIBX bindings. 
     6  # Compiles JIBX[http://jibx.sourceforge.net/] bindings. 
    77  # 
    88  # == Example 
     
    2424    end 
    2525     
    26     def define          
     26    def define # :nodoc:        
    2727      task name => dependencies do |t| 
    2828        compiler = Rjb::import('org.jibx.binding.Compile').new 
  • trunk/lib/jerbil/testng_task.rb

    r6097 r6138  
    77module Jerbil 
    88  module TestNG 
    9     # A Task to run testng tasks. 
     9    # A task to run testng[http://testng.org] test suites or individual tests. 
    1010    # 
    1111    # == Example 
     
    2323       
    2424      attr_accessor :name 
     25                         
     26                        # A JavaFileList specifing tests to run. TestNGTask will use 
     27                        # +to_classes+ to obtain the class files from the list. 
    2528      attr_accessor :tests 
     29                         
     30                        # Where the testng output should go. Default "test-output". 
    2631      attr_accessor :outputdir 
     32                         
     33                        # Whether to generate HTML reports. Defaults to +true+. 
    2734      attr_accessor :report 
     35                         
     36                        # A list of locations of testng suite.xml files.                 
    2837      attr_accessor :suites 
     38                         
     39                        # Working dir to use during test execution. 
    2940      attr_accessor :workingdir 
    30       attr_accessor :excludedgroups 
     41                         
     42                        # A list of test listeners to use. Defaults to DefaultTestListener  
     43                        # if empty. 
     44                        attr_accessor :listeners                                         
    3145       
    3246      def initialize(name) 
     
    3650        @report = true 
    3751        @suites = [] 
    38         @workingdir = nil 
    39         @excludedgroups = nil 
     52        @workingdir = nil  
     53                                @listeners = [] 
    4054        yield self if block_given? 
    4155        depends_on workingdir unless workingdir.nil? 
     
    4458      end 
    4559       
    46       def define 
     60      def define # :nodoc: 
    4761                desc "run testng tests" if Rake.application.last_comment.nil? 
    4862        task name => dependencies do |t| 
    4963          testng = Rjb::import('org.testng.TestNG').new_with_sig 'Z', false 
    5064          
    51           tl = TestListener.new 
    52           sl = SuiteListener.new 
     65          listeners << DefaultTestListener.new if listeners.empty? 
     66     
     67                                        sl = SuiteListener.new 
    5368           
    5469          #need to use _invoke because addListener has 3 different method signatures 
    5570          #using same name and return type 
    5671          #testng.addListener(Rjb::bind(tl, 'org.testng.ITestListener')) 
    57           testng._invoke('addListener', 'Lorg.testng.ITestListener;', Rjb::bind(tl, 'org.testng.ITestListener')) 
    58           #testng.addListener(Rjb::bind(sl, 'org.testng.ISuiteListener')) 
     72                                        listeners.each do |tl|   
     73            testng._invoke('addListener', 'Lorg.testng.ITestListener;', Rjb::bind(tl, 'org.testng.ITestListener')) 
     74          end 
     75                                         
     76                                        #testng.addListener(Rjb::bind(sl, 'org.testng.ISuiteListener')) 
    5977          testng._invoke('addListener', 'Lorg.testng.ISuiteListener;', Rjb::bind(sl, 'org.testng.ISuiteListener')) 
    6078                 
     
    8199          end 
    82100       
    83           raise "some tests failed: #{tl.failed_to_s}" unless testng.getStatus == 0 
     101                                        message = "some tests failed" 
     102                                        if listeners.first.kind_of?(DefaultTestListener) 
     103                                                message += ": #{listeners.first.failed_to_s}" 
     104                                        end 
     105          raise message unless testng.getStatus == 0 
    84106        end 
    85107        directory workingdir unless workingdir.nil? 
     
    89111     
    90112    # A TestNG test listener imlemented in ruby. It mimics Ruby's standard testrunner. 
    91     class TestListener 
     113    class DefaultTestListener 
    92114      include JavaHelper 
    93115 
    94116        attr_reader :failed_classes 
    95         def initialize 
     117        def initialize # :nodoc: 
    96118          @failed_classes = Set.new 
    97119          @outfile = nil 
     
    137159        end 
    138160      
    139         # Returns a list of all failed classes. 
     161        # Returns a string describing all failed classes. 
    140162        def failed_to_s 
    141163          @failed_classes.to_a.join(', ')