Changeset 6138
- Timestamp:
- 11/27/06 21:09:49
- Files:
-
- trunk/README (modified) (5 diffs)
- trunk/Rakefile (modified) (1 diff)
- trunk/example/Rakefile (modified) (3 diffs)
- trunk/example/buildconfig.rb (modified) (1 diff)
- trunk/externals (modified) (1 prop)
- trunk/lib/jerbil/apt_task.rb (modified) (1 diff)
- trunk/lib/jerbil/hibernate_task.rb (modified) (7 diffs)
- trunk/lib/jerbil/jar_task.rb (modified) (1 diff)
- trunk/lib/jerbil/java_helper.rb (modified) (8 diffs)
- trunk/lib/jerbil/java_task.rb (modified) (1 diff)
- trunk/lib/jerbil/javac_task.rb (modified) (4 diffs)
- trunk/lib/jerbil/javadoc_task.rb (modified) (1 diff)
- trunk/lib/jerbil/jibx_task.rb (modified) (2 diffs)
- trunk/lib/jerbil/testng_task.rb (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/README
r6128 r6138 31 31 == Installation 32 32 33 You need to have Ruby and rubygems installed. On Debian systems (testing) this is a simple as: 33 You need to have Ruby and rubygems installed. The Windows version of Ruby already ships with gem. 34 On Debian systems (testing) you can install it using apt-get: 34 35 35 36 % apt-get install rubygems … … 53 54 == Usage 54 55 55 A minimal Rakefile to compile Java files lookslike this:56 A minimal Rakefile to compile Java files could look like this: 56 57 57 58 require 'jerbil' … … 75 76 in the repository. 76 77 77 % svn c ohttp://svn.trampolinesystems.com/jerbil/trunk/example78 % svn checkout http://svn.trampolinesystems.com/jerbil/trunk/example 78 79 79 80 == Advantages over Ant … … 81 82 See Martin Fowler's article[http://www.martinfowler.com/articles/rake.html] for a detailed 82 83 discussion 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).84 implement arbitrary Java interfaces in Ruby (see Jerbil::TestNG::DefaultTestListener for an example). 84 85 Another possibility is build script metaprogramming, i.e. creating your tasks programmatically: 85 86 … … 102 103 103 104 * 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). 105 106 106 107 == FAQ trunk/Rakefile
r6126 r6138 64 64 rdoc.rdoc_files.include("README", "CHANGES", "TODO", "LICENSE", "lib/**/*.rb") 65 65 rdoc.rdoc_dir = 'rdoc' 66 rdoc.template = 'externals/allison/allison.rb' 66 67 end 67 68 trunk/example/Rakefile
r6103 r6138 84 84 85 85 file ANNOTATED_CLASSES => [ :find_annotations ] 86 file PERSISTENCE_YML => [ :find_annotations ]86 file ENTITIES_YML => [ :find_annotations ] 87 87 desc "find annotations and write output to #{ANNOTATED_CLASSES}" 88 88 Jerbil::AptTask.new(:find_annotations) do |t| … … 93 93 File.open(ANNOTATED_CLASSES, 'w') { |f| f << classes.to_yaml } 94 94 end 95 t.annotated_classes_to_yaml('javax.persistence.Entity', PERSISTENCE_YML)95 t.annotated_classes_to_yaml('javax.persistence.Entity', ENTITIES_YML) 96 96 end 97 97 … … 100 100 Jerbil::Hibernate::ExportSchemaTask.new(:export_schema) do |t| 101 101 t.schemafile = DB_SCHEMA 102 t. persistencefile = PERSISTENCE_YML102 t.entities_yml = ENTITIES_YML 103 103 end trunk/example/buildconfig.rb
r6103 r6138 14 14 CLASSPATH = FileList["./#{JAVA_BUILD_DIR}", "./lib/*.jar" ] 15 15 DB_SCHEMA = File.join(BUILD_DIR, "schema.sql") 16 PERSISTENCE_YML = File.join(BUILD_DIR, "persistence.yml")16 ENTITIES_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 22 22 class AptTask < JavacTask 23 23 24 # A hash containing annotation types and handlers (code blocks). 24 25 attr_accessor :annotations 26 27 # Only process annotations, don't compile anything. 25 28 attr_accessor :nocompile 26 29 trunk/lib/jerbil/hibernate_task.rb
r6053 r6138 7 7 module Jerbil 8 8 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 11 14 # 12 15 # == Example 13 16 # Jerbil::Hibernate::ExportSchemaTask.new(:export_schema) do |t| 14 17 # t.schemafile = "schema.sql" 15 # t. persistencefile = PERSISTENCE_YML18 # t.entities_yml = ENTITIES_YML 16 19 # end 17 20 class ExportSchemaTask < Rake::TaskLib … … 20 23 attr_accessor :name 21 24 25 # SQL schema destination file (default: schema.sql) 22 26 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> 24 34 attr_accessor :dialect 35 36 # SQL statements to be executed before generated sql. 25 37 attr_accessor :preamble 38 39 # FQN of a package containing package-info.java to be used by 40 # hibernate. 26 41 attr_accessor :package 27 42 … … 31 46 @package = nil 32 47 @schemafile = "schema.sql" 33 @ persistencefile = "persistence.yml"48 @entities_yml = "entities.yml" 34 49 @dialect = "org.hibernate.dialect.MySQL5Dialect" 35 50 … … 38 53 end 39 54 40 def define 55 def define # :nodoc: 41 56 task name => dependencies do |t| 42 57 43 entities = File.open( persistencefile) {|f| YAML.load(f)}58 entities = File.open(entities_yml) {|f| YAML.load(f)} 44 59 45 60 raise 'no annotated entities found!' if entities.empty? … … 55 70 schema << "# generated by Jerbil::Hibernate::ExportSchemaTask at #{Time.new}\n\n" 56 71 57 schema << preamble unless preamble.nil?72 schema << preamble if preamble 58 73 59 74 schema << IO.read(schemafile) … … 67 82 end 68 83 file schemafile => name 69 task name => persistencefile84 task name => entities_yml 70 85 end 71 86 end … … 137 152 packages << pkg.getName if pkg && pkg.getAnnotations.length > 0 138 153 end 139 packages << package unless package.nil?154 packages << package if package 140 155 packages.each { |pkg| acfg.addPackage(pkg) } 141 156 acfg trunk/lib/jerbil/jar_task.rb
r6053 r6138 24 24 end 25 25 26 def define 26 def define # :nodoc: 27 27 jardir = File.dirname(filename) 28 28 depends_on jardir trunk/lib/jerbil/java_helper.rb
r6133 r6138 74 74 # +build_dir+:: an optional directory (or list of directories) which will be used to resolve classes at runtime. 75 75 # 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 # 80 85 def JavaHelper.load_jvm(classpath, build_dir = nil, options = {} ) 81 86 … … 135 140 raise 136 141 end 137 138 #TODO: test javac main and raise if not found139 142 end 140 143 141 144 # 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: 143 146 if ENV['JAVA_HOME'].nil? && IS_WINDOWS 144 147 begin … … 204 207 # A JavaFileList is a specialisation of a standard Rake::FileList. 205 208 # It includes additional methods to deal with build dirs, resources 206 # and other java specifics.209 # and other Java related things. 207 210 class JavaFileList < Rake::FileList 208 211 attr_reader :srcdir … … 210 213 attr_accessor :resource_patterns 211 214 212 # srcdir:: the directory containing the Java source file .215 # srcdir:: the directory containing the Java source files. 213 216 # dstdir:: destination directory for class files (used by JavacTask). 214 217 # extensions:: a list of extensions to treat as resources. The default is to treat … … 223 226 end 224 227 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. 226 229 # For example src/org/foo/Baz -> org.foo.Baz. 227 230 def to_classnames … … 283 286 end 284 287 288 # Returns a list of out-of-date files, based on timestamp comparison. 285 289 def out_of_date 286 290 return self.to_a unless (File.exists?(dstdir) and Dir.entries(dstdir).length > 2) … … 326 330 # JAVA_FILES = MultiJavaFileList.new(MODULES, JAVA_BUILD_DIR, SOURCE_DIR) 327 331 # 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+. 329 334 class MultiJavaFileList 330 335 … … 428 433 429 434 # make load_jvm available to toplevel 435 # See JavaHelper.load_jvm. 430 436 def load_jvm(args, build_dir, options={}) 431 437 Jerbil::JavaHelper.load_jvm(args, build_dir, options) trunk/lib/jerbil/java_task.rb
r6053 r6138 77 77 78 78 protected 79 def define 79 def define # :nodoc: 80 80 #desc "run #{classname}" if Rake.application.last_comment.nil? 81 81 task name => dependencies do |t| trunk/lib/jerbil/javac_task.rb
r6133 r6138 5 5 module Jerbil 6 6 # Compiles Java source files. 7 # The location of the source files and the desti onation directory is encapsulated8 # ina JavaFileList.7 # The location of the source files and the destination directory is specified 8 # by a JavaFileList. 9 9 # 10 10 # == Example … … 12 12 # desc "compile all java files" 13 13 # Jerbil::JavacTask.new(:compile) do |t| 14 # t.java_files = J erbil::JavaFileList.new("src", "classes")14 # t.java_files = JavaFileList.new("src", "classes") 15 15 # t.options :nowarn, :debug 16 16 # end … … 19 19 20 20 attr_accessor :name 21 22 # A JavaFileList, specifying what to compile and where 23 # to write the output to. 21 24 attr_accessor :java_files 25 22 26 attr_accessor :verbose 23 27 … … 39 43 end 40 44 41 def define 45 def define # :nodoc: 42 46 desc "compile files in #{java_files.srcdir.to_a.join(', ')}" if Rake.application.last_comment.nil? 43 47 task name => dependencies do |t| trunk/lib/jerbil/javadoc_task.rb
r6054 r6138 28 28 end 29 29 30 def define 30 def define # :nodoc: 31 31 desc "generate javadocs" if Rake.application.last_comment.nil? 32 32 task name => dependencies do |t| trunk/lib/jerbil/jibx_task.rb
r6053 r6138 4 4 5 5 module Jerbil 6 # Compiles JIBX bindings.6 # Compiles JIBX[http://jibx.sourceforge.net/] bindings. 7 7 # 8 8 # == Example … … 24 24 end 25 25 26 def define 26 def define # :nodoc: 27 27 task name => dependencies do |t| 28 28 compiler = Rjb::import('org.jibx.binding.Compile').new trunk/lib/jerbil/testng_task.rb
r6097 r6138 7 7 module Jerbil 8 8 module TestNG 9 # A Task to run testng tasks.9 # A task to run testng[http://testng.org] test suites or individual tests. 10 10 # 11 11 # == Example … … 23 23 24 24 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. 25 28 attr_accessor :tests 29 30 # Where the testng output should go. Default "test-output". 26 31 attr_accessor :outputdir 32 33 # Whether to generate HTML reports. Defaults to +true+. 27 34 attr_accessor :report 35 36 # A list of locations of testng suite.xml files. 28 37 attr_accessor :suites 38 39 # Working dir to use during test execution. 29 40 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 31 45 32 46 def initialize(name) … … 36 50 @report = true 37 51 @suites = [] 38 @workingdir = nil 39 @excludedgroups = nil 52 @workingdir = nil 53 @listeners = [] 40 54 yield self if block_given? 41 55 depends_on workingdir unless workingdir.nil? … … 44 58 end 45 59 46 def define 60 def define # :nodoc: 47 61 desc "run testng tests" if Rake.application.last_comment.nil? 48 62 task name => dependencies do |t| 49 63 testng = Rjb::import('org.testng.TestNG').new_with_sig 'Z', false 50 64 51 tl = TestListener.new 52 sl = SuiteListener.new 65 listeners << DefaultTestListener.new if listeners.empty? 66 67 sl = SuiteListener.new 53 68 54 69 #need to use _invoke because addListener has 3 different method signatures 55 70 #using same name and return type 56 71 #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')) 59 77 testng._invoke('addListener', 'Lorg.testng.ISuiteListener;', Rjb::bind(sl, 'org.testng.ISuiteListener')) 60 78 … … 81 99 end 82 100 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 84 106 end 85 107 directory workingdir unless workingdir.nil? … … 89 111 90 112 # A TestNG test listener imlemented in ruby. It mimics Ruby's standard testrunner. 91 class TestListener113 class DefaultTestListener 92 114 include JavaHelper 93 115 94 116 attr_reader :failed_classes 95 def initialize 117 def initialize # :nodoc: 96 118 @failed_classes = Set.new 97 119 @outfile = nil … … 137 159 end 138 160 139 # Returns a list ofall failed classes.161 # Returns a string describing all failed classes. 140 162 def failed_to_s 141 163 @failed_classes.to_a.join(', ')
