4 # An engine is informally defined as any subdirectory in vendor/plugins
5 # which ends in '_engine', '_bundle', or contains an 'init_engine.rb' file.
6 engine_base_dirs = ['vendor/plugins']
7 # The engine root may be different; if possible try to include
8 # those directories too
9 if Engines.const_defined?(:CONFIG)
10 engine_base_dirs << Engines::CONFIG[:root]
12 engine_base_dirs.map! {|d| [d + '/*_engine/*',
14 d + '/*/init_engine.rb']}.flatten!
15 engine_dirs = FileList.new(*engine_base_dirs)
16 engine_dirs.map do |engine|
17 File.basename(File.dirname(engine))
25 desc "Display version information about active engines"
26 task :info => :environment do
28 e = Engines.get(ENV["ENGINE"])
29 header = "Details for engine '#{e.name}':"
31 puts "-" * header.length
32 puts "Version: #{e.version}"
33 puts "Details: #{e.info}"
35 puts "Engines plugin: #{Engines.version}"
37 puts "#{e.name}: #{e.version}"
44 namespace :fixtures do
47 desc "Load plugin/engine fixtures into the current environment's database."
48 task :load => :environment do
49 require 'active_record/fixtures'
50 ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
51 plugin = ENV['ENGINE'] || '*'
52 Dir.glob(File.join(RAILS_ROOT, 'vendor', 'plugins', plugin, 'test', 'fixtures', '*.yml')).each do |fixture_file|
53 Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
63 desc "Migrate all engines. Target specific version with VERSION=x, specific engine with ENGINE=x"
64 task :engines => :environment do
65 engines_to_migrate = ENV["ENGINE"] ? [Engines.get(ENV["ENGINE"])].compact : Engines.active
66 if engines_to_migrate.empty?
67 puts "Couldn't find an engine called '#{ENV["ENGINE"]}'"
69 if ENV["VERSION"] && !ENV["ENGINE"]
70 # ignore the VERSION, since it makes no sense in this context; we wouldn't
71 # want to revert ALL engines to the same version because of a misttype
72 puts "Ignoring the given version (#{ENV["VERSION"]})."
73 puts "To control individual engine versions, use the ENGINE=<engine> argument"
75 engines_to_migrate.each do |engine|
76 Engines::EngineMigrator.current_engine = engine
77 migration_directory = File.join(engine.root, 'db', 'migrate')
78 if File.exist?(migration_directory)
79 puts "Migrating engine '#{engine.name}'"
80 Engines::EngineMigrator.migrate(migration_directory, ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
82 puts "The db/migrate directory for engine '#{engine.name}' appears to be missing."
83 puts "Should be: #{migration_directory}"
86 if ActiveRecord::Base.schema_format == :ruby && !engines_to_migrate.empty?
87 Rake::Task[:db_schema_dump].invoke
94 Engines::RakeTasks.all_engines.each do |engine_name|
95 desc "Migrate the '#{engine_name}' engine. Target specific version with VERSION=x"
96 task engine_name => :environment do
97 ENV['ENGINE'] = engine_name; Rake::Task['db:migrate:engines'].invoke
106 # this is just a rip-off from the plugin stuff in railties/lib/tasks/documentation.rake,
107 # because the default plugindoc stuff doesn't support subdirectories like <engine>/app or
108 # <engine>/component.
111 desc "Generate documation for all installed engines"
112 task :engines => Engines::RakeTasks.all_engines.map {|engine| "doc:engines:#{engine}"}
114 namespace :engines do
115 # Define doc tasks for each engine
116 Engines::RakeTasks.all_engines.each do |engine_name|
117 desc "Generation documentation for the '#{engine_name}' engine"
118 task engine_name => :environment do
119 engine_base = "vendor/plugins/#{engine_name}"
121 files = Rake::FileList.new
122 options << "-o doc/plugins/#{engine_name}"
123 options << "--title '#{engine_name.titlecase} Documentation'"
124 options << '--line-numbers --inline-source'
125 options << '--all' # include protected methods
128 files.include("#{engine_base}/lib/**/*.rb")
129 files.include("#{engine_base}/app/**/*.rb") # include the app directory
130 files.include("#{engine_base}/components/**/*.rb") # include the components directory
131 if File.exists?("#{engine_base}/README")
132 files.include("#{engine_base}/README")
133 options << "--main '#{engine_base}/README'"
135 files.include("#{engine_base}/CHANGELOG") if File.exists?("#{engine_base}/CHANGELOG")
137 options << files.to_s
139 sh %(rdoc #{options * ' '})
146 desc "Run the engine tests in vendor/plugins/**/test (or specify with ENGINE=name)"
147 # NOTE: we're using the Rails 1.0 non-namespaced task here, just to maintain
148 # compatibility with Rails 1.0
149 # TODO: make this work with Engines.config(:root)
151 namespace :engines do
152 Engines::RakeTasks.all_engines.each do |engine_name|
153 desc "Run the engine tests for '#{engine_name}'"
154 Rake::TestTask.new(engine_name => :prepare_test_database) do |t|
156 t.pattern = "vendor/plugins/#{engine_name}/test/**/*_test.rb"
162 Rake::TestTask.new(:engines => [:warn_about_multiple_engines_testing, :prepare_test_database]) do |t|
164 engines = ENV['ENGINE'] || '**'
165 t.pattern = "vendor/plugins/#{engines}/test/**/*_test.rb"
169 task :warn_about_multiple_engines_testing do
170 puts %{-~============== A Moste Polite Warninge ==================~-
171 You may experience issues testing multiple engines at once.
172 Please test engines individual for the moment.
173 -~===============( ... as you were ... )===================~-