Buildr Integration

Domgen is typically configured so that each time a project is built, domgen loads repository and generates any required artifacts as part of the build process. Domgen provides some rake tasks to support this use case. These rake tasks detect the presence of Buildr and if present will offer additional functionality as part of the build.

Loading the repository

Assuming domgen is braided into the vendor/plugins/domgen directory, the developer will typically create a tasks/domgen.rake file. This file will define a task that loads the repository definition. By convention the repository definition is stored in a file named architecture.rb in the base directory of the project.

workspace_dir = File.expand_path(File.dirname(__FILE__) + '/..')
domgen_dir = File.expand_path("#{workspace_dir}/vendor/plugins/domgen/lib")
$LOAD_PATH.unshift(domgen_dir)

# Load domgen
require 'domgen'

# Define the task "domgen:load" that loads the reposiory
# from the default location (../architecture.rb)
Domgen::Build.define_load_task

The developer can also pass a parameter to the define_load_task method that specifies the location of the repository definition.

workspace_dir = File.expand_path(File.dirname(__FILE__) + '/..')
domgen_dir = File.expand_path("#{workspace_dir}/vendor/plugins/domgen/lib")
$LOAD_PATH.unshift(domgen_dir)

# Load domgen
require 'domgen'

# Define the task "domgen:load" that loads the reposiory
# from the file "../src/architecture.rb"
Domgen::Build.define_load_task("#{workspace_dir}/src/architecture.rb")

Defining generator tasks

If a task generates code or assets that are compiled or packaged within a particular project then then the method Domgen::Build.define_generate_task should be invoked within the block that defines the project. The first parameter is an array of generators that are to be run. These task will generate the source code within the projects base directory and will automatically add the source to the project paths as appropriate. The tasks will have a name that is prefixed by the project tasks.

define 'myproject' do
  # Generate the JPA and EJB artifacts for project
  Domgen::Build.define_generate_task([:ejb, :jpa])

  ....
end

If however the generator is independent of any particular project, it is more appropriate to define the generator task in the tasks/domgen.rake. As the generators are outside of projects it is also required that additional configuration be supplied. Projects with a database typically define the generators for sql in the following manner:

Domgen::Build.define_generate_task([:mssql], :key => :sql, :target_dir => 'database/generated')
:repository_key The name of the repository to run generators for. If there is a single repository then the repository name is the default value.
:target_dir The base directory in which to generate artifacts, relative to the buildfile. Defaults is derived from buildr project path and :key value.
:key The string name used when naming the task and used if deriving a default directory. Defaults to the local project name if a buildr project is specified or the task is defined within a project else it defaults to 'default'.
:buildr_project The associated buildr project that is used to derive defaults and is extended to add paths to when source is generated. Defaults to the containing buildr project or nil.
Options that can be supplied to Domgen::Build.define_generate_task method

Defining XMI generator

Due to legacy reasons, the XMI generator uses a separate method to define the xmi task.

Domgen::Build.define_generate_xmi_task
:repository_key The name of the repository to run generators for. If there is a single repository then the repository name is the default value.
:filename The name of the xmi file that is generated by task. Default is derived from the buildr project if specified, or the top level project if there is only one and the task is defined outside the project.
:key The string name used when naming the task and used if deriving a default directory. Defaults to the local project name if a buildr project is specified or the task is defined within a project else it defaults to 'xmi'.
:buildr_project The associated buildr project that is used to derive defaults. Defaults to the containing buildr project or the top level project if there is only one.
Options that can be supplied to Domgen::Build.define_generate_xmi_task method