lib/reality/generators/buildr_integration.rb
# This method is called from a Rake or Buildr task to configure the Buildr
# project so that it knows the location of all the generated artifacts and
# adds them to the appropriate compile paths etc.
This method is called from a Rake or Buildr task to configure the Buildr
project so that it knows the location of all the generated artifacts and
adds them to the appropriate compile paths etc.
This method is called from a Rake or Buildr task to configure the Buildr project so that it knows the location of all the generated artifacts and adds them to the appropriate compile paths etc .
def configure_buildr_project(buildr_project, generator_task, templates, target_dir)
          if buildr_project.nil?
            task('clean') do
              rm_rf target_dir
            end
          else
            buildr_project.clean { rm_rf target_dir }
            file(File.expand_path(target_dir) => [generator_task])
            if templates.any? { |template| template.output_path =~ /^main\/java\/.*/ }
              main_java_dir = "#{target_dir}/main/java"
              file(main_java_dir => [generator_task]) do
                mkdir_p main_java_dir
              end
              buildr_project.compile.using :javac
              buildr_project.compile.from main_java_dir
              buildr_project.iml.main_generated_source_directories << main_java_dir if buildr_project.iml?
            end
            if templates.any? { |template| template.output_path =~ /^main\/resources\/.*/ }
              main_resources_dir = "#{target_dir}/main/resources"
              file(main_resources_dir => [generator_task]) do
                mkdir_p main_resources_dir
              end
              buildr_project.resources.enhance([generator_task])
              buildr_project.resources.filter.into buildr_project.path_to(:target, :main, :resources) unless buildr_project.resources.target
              buildr_project.resources do |t|
                t.enhance do
                  if File.exist?(main_resources_dir)
                    FileUtils.mkdir_p buildr_project.resources.target.to_s
                    FileUtils.cp_r "#{main_resources_dir}/.", buildr_project.resources.target.to_s
                  end
                end
              end
              buildr_project.iml.main_generated_resource_directories << main_resources_dir if buildr_project.iml?
            end
            if templates.any? { |template| template.output_path =~ /^main\/webapp\/.*/ }
              webapp_dir = File.expand_path("#{target_dir}/main/webapp")
              buildr_project.assets.enhance([generator_task])
              buildr_project.assets.paths << file(webapp_dir => [generator_task]) do
                mkdir_p webapp_dir
              end
            end
            if templates.any? { |template| template.output_path =~ /^test\/java\/.*/ }
              test_java_dir = "#{target_dir}/test/java"
              file(test_java_dir => [generator_task]) do
                mkdir_p test_java_dir
              end
              buildr_project.test.compile.from test_java_dir
              buildr_project.iml.test_generated_source_directories << test_java_dir if buildr_project.iml?
            end
            if templates.any? { |template| template.output_path =~ /^test\/resources\/.*/ }
              test_resources_dir = "#{target_dir}/test/resources"
              file(test_resources_dir => [generator_task]) do
                mkdir_p test_resources_dir
              end
              buildr_project.test.resources.enhance([generator_task])
              buildr_project.test.resources.filter.into buildr_project.path_to(:target, :test, :resources) unless buildr_project.test.resources.target
              buildr_project.test.resources do |t|
                t.enhance do
                  if File.exist?(test_resources_dir)
                    FileUtils.mkdir_p buildr_project.test.resources.target.to_s
                    FileUtils.cp_r "#{test_resources_dir}/.", buildr_project.test.resources.target.to_s
                  end
                end
              end
              buildr_project.iml.test_generated_resource_directories << test_resources_dir if buildr_project.iml?
            end
          end
        end
def configure_buildr_project ( buildr_project , generator_task , templates , target_dir ) if buildr_project . nil? task ( 'clean' ) do rm_rf target_dir end else buildr_project . clean { rm_rf target_dir } file ( File . expand_path ( target_dir ) => [ generator_task ] ) if templates . any? { | template | template . output_path =~ / ^main \/ java \/ .* / } main_java_dir = "#{target_dir}/main/java" file ( main_java_dir => [ generator_task ] ) do mkdir_p main_java_dir end buildr_project . compile . using :javac buildr_project . compile . from main_java_dir buildr_project . iml . main_generated_source_directories << main_java_dir if buildr_project . iml? end if templates . any? { | template | template . output_path =~ / ^main \/ resources \/ .* / } main_resources_dir = "#{target_dir}/main/resources" file ( main_resources_dir => [ generator_task ] ) do mkdir_p main_resources_dir end buildr_project . resources . enhance ( [ generator_task ] ) buildr_project . resources . filter . into buildr_project . path_to ( :target , :main , :resources ) unless buildr_project . resources . target buildr_project . resources do | t | t . enhance do if File . exist? ( main_resources_dir ) FileUtils . mkdir_p buildr_project . resources . target . to_s FileUtils . cp_r "#{main_resources_dir}/." , buildr_project . resources . target . to_s end end end buildr_project . iml . main_generated_resource_directories << main_resources_dir if buildr_project . iml? end if templates . any? { | template | template . output_path =~ / ^main \/ webapp \/ .* / } webapp_dir = File . expand_path ( "#{target_dir}/main/webapp" ) buildr_project . assets . enhance ( [ generator_task ] ) buildr_project . assets . paths << file ( webapp_dir => [ generator_task ] ) do mkdir_p webapp_dir end end if templates . any? { | template | template . output_path =~ / ^test \/ java \/ .* / } test_java_dir = "#{target_dir}/test/java" file ( test_java_dir => [ generator_task ] ) do mkdir_p test_java_dir end buildr_project . test . compile . from test_java_dir buildr_project . iml . test_generated_source_directories << test_java_dir if buildr_project . iml? end if templates . any? { | template | template . output_path =~ / ^test \/ resources \/ .* / } test_resources_dir = "#{target_dir}/test/resources" file ( test_resources_dir => [ generator_task ] ) do mkdir_p test_resources_dir end buildr_project . test . resources . enhance ( [ generator_task ] ) buildr_project . test . resources . filter . into buildr_project . path_to ( :target , :test , :resources ) unless buildr_project . test . resources . target buildr_project . test . resources do | t | t . enhance do if File . exist? ( test_resources_dir ) FileUtils . mkdir_p buildr_project . test . resources . target . to_s FileUtils . cp_r "#{test_resources_dir}/." , buildr_project . test . resources . target . to_s end end end buildr_project . iml . test_generated_resource_directories << test_resources_dir if buildr_project . iml? end end end
This method is called from a Rake or Buildr task to configure the Buildr
project so that it knows the location of all the generated artifacts and
adds them to the appropriate compile paths etc.
This method is called from a Rake or Buildr task to configure the Buildr project so that it knows the location of all the generated artifacts and adds them to the appropriate compile paths etc .
# Is there java source generated in project? # Need to force this as it may have already been cached and thus will not recalculate # Is there resources generated in project? # Is there assets generated in project? # Is there test java source generated in project? # Need to force this as it may have already been cached and thus will not recalculate # Is there resources generated in project?
buildr_project
<not_specific>
generator_task
<not_specific>
templates
<not_specific>
target_dir
<not_specific>