module Buildr::Hibernate

Provides Hibernate Doclet and schema export tasks. Require explicitly using require "buildr/hibernate".

Constants

REQUIRES

Public Class Methods

doclet(options) → AntProject click to toggle source

Uses XDoclet to generate HBM files form annotated source files. Options include:

  • :sources – Directory (or directories) containing source files.

  • :target – The target directory.

  • :excludetags – Tags to exclude (see HibernateDocletTask)

For example:

doclet :sources=>compile.sources, :target=>compile.target, :excludedtags=>"@version,@author,@todo"
# File addon/buildr/hibernate.rb, line 45
def doclet(options)
  options[:sources].each { |src| file(src).invoke }
  ant "hibernatedoclet" do |ant|
    ant.taskdef :name=>"hibernatedoclet", :classname=>"xdoclet.modules.hibernate.HibernateDocletTask", :classpath=>options[:classpath]
    ant.hibernatedoclet :destdir=>options[:target].to_s, :excludedtags=>options[:excludedtags], :force=>"true" do
      ant.hibernate :version=>"3.0"
      options[:sources].map(&:to_s).each do |source|
        ant.fileset :dir=>source.to_s, :includes=>"**/*.java"
      end
    end
  end
end
schemaexport(properties) { ... } → AntProject click to toggle source

Runs the Hibernate SchemaExportTask with the specified properties. For example:

Buildr::Hibernate.schemaexport(:properties=>properties.to_s, :quiet=>"yes", :text=>"yes", :delimiter=>";",
  :drop=>"no", :create=>"yes", :output=>target) do
  fileset :dir=>source.to_s, :includes=>"**/*.hbm.xml"
end
# File addon/buildr/hibernate.rb, line 66
def schemaexport(classpath, options = nil)
  ant "schemaexport" do |ant|
    ant.taskdef :name=>"schemaexport", :classname=>"org.hibernate.tool.hbm2ddl.SchemaExportTask", :classpath=>classpath
    ant.schemaexport(options) { yield ant if block_given? } if options
  end
end

Public Instance Methods

hibernate_doclet(options?) → task click to toggle source

Runs the hibernate doclet on the source files and creates HBM files in the target directory. By default runs on all source files, but you can limit it to a given package using the :package options. You can also pass other options to the doclet task.

For example:

resources hibernate_doclet(:package=>"org.apache.ode.store.hib", :excludedtags=>"@version,@author,@todo")
# File addon/buildr/hibernate.rb, line 88
def hibernate_doclet(options = {})
  if options[:package]
    depends = compile.sources.map { |src| FileList[File.join(src.to_s, options[:package].gsub(".", "/"), "*.java")] }.flatten
  else
    depends = compile.sources.map { |src| FileList[File.join(src.to_s, "**/*.java")] }.flatten
  end
  file("target/hbm.timestamp"=>depends) do |task|
    Hibernate.doclet({ :sources=>compile.sources, :target=>compile.target, :classpath => hib_resolve_classpath }.merge(options))
    write task.name
  end
end
hibernate_requires() click to toggle source
# File addon/buildr/hibernate.rb, line 75
def hibernate_requires()
  @requires ||= REQUIRES.dup
end
hibernate_schemaexport(path) → task click to toggle source
hibernate_schemaexport(path) { |task, ant| .. } → task

Returns an new file task with an accessor (ant) to an AntProject that defines the schemaexport task. If called with a block, the task will yield to the block passing both itself and the Ant project.

See schemaexport.

For example:

hibernate_schemaexport "derby.sql" do |task, ant|
  ant.schemaexport :properties=>"derby.properties", :output=>task.name,
    :delimiter=>";", :drop=>"no", :create=>"yes" do
    fileset(:dir=>compile.sources.first) { include :name=>"**/*.hbm.xml" } }
  end
end
# File addon/buildr/hibernate.rb, line 116
def hibernate_schemaexport(args, &block)
  path, arg_names, deps = Rake.application.resolve_args([args])
  file(path).enhance { |task|
    unless task.respond_to? :ant #this is a hack. A better way to do the job is to create a real task for all this.
      class << task ; attr_accessor :ant ; end
      task.ant = Hibernate.schemaexport(hib_resolve_classpath)
    end
  }

  if block
    file(path).enhance(deps) { |task| block.call task, task.ant }
  else
    file(path).enhance deps
  end
end

Protected Instance Methods

hib_resolve_classpath() click to toggle source

This will download all the required artifacts before returning a classpath, and we want to do this only once.

# File addon/buildr/hibernate.rb, line 135
def hib_resolve_classpath
  Buildr.artifacts(hibernate_requires.to_a).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
end