summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2018-02-19 19:20:53 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2018-02-26 16:06:49 +0200
commit5bb435d0e75ad84e2fc379208cc36a25a4574453 (patch)
treee65d8278aa37adb8467e05e4bbf15094b43b870c
parentb985fe95b6c30bc83725e9b5e18a79a8ceb900d3 (diff)
downloadgitlab-ce-5bb435d0e75ad84e2fc379208cc36a25a4574453.tar.gz
Remove plugin initializer and add plugins:validate rake task
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/services/system_hooks_service.rb2
-rw-r--r--config/initializers/9_plugins.rb29
-rw-r--r--lib/gitlab/plugin.rb25
-rw-r--r--lib/tasks/plugins.rake15
4 files changed, 41 insertions, 30 deletions
diff --git a/app/services/system_hooks_service.rb b/app/services/system_hooks_service.rb
index 71de74e5a82..ba46c0074e4 100644
--- a/app/services/system_hooks_service.rb
+++ b/app/services/system_hooks_service.rb
@@ -13,7 +13,7 @@ class SystemHooksService
end
# Execute external plugins
- PLUGINS.each do |plugin|
+ Gitlab::Plugin.all.each do |plugin|
begin
plugin.new.execute(data)
rescue => e
diff --git a/config/initializers/9_plugins.rb b/config/initializers/9_plugins.rb
deleted file mode 100644
index 9f252ccd296..00000000000
--- a/config/initializers/9_plugins.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-class PluginsSystem
- attr_accessor :plugins, :files
-
- def initialize
- @files = Dir.glob(Rails.root.join('plugins', '*_plugin.rb'))
- end
-
- def valid_plugins
- files.map do |file|
- file_name = File.basename(file, '.rb')
-
- # Just give sample data to method and expect it to not crash.
- begin
- klass = Object.const_get(file_name.classify)
- klass.new.execute(Gitlab::DataBuilder::Push::SAMPLE_DATA)
- rescue => e
- Rails.logger.warn("GitLab -> Plugins -> #{file_name} raised an exception during boot check. #{e}")
- next
- else
- Rails.logger.info "GitLab -> Plugins -> #{file_name} passed boot check"
- klass
- end
- end
- end
-end
-
-# Load external plugins from /plugins directory
-# and set into PLUGINS variable
-PLUGINS = PluginsSystem.new.valid_plugins
diff --git a/lib/gitlab/plugin.rb b/lib/gitlab/plugin.rb
new file mode 100644
index 00000000000..cbc57a5cce3
--- /dev/null
+++ b/lib/gitlab/plugin.rb
@@ -0,0 +1,25 @@
+module Gitlab
+ module Plugin
+ def self.all
+ files.map do |file|
+ file_name = File.basename(file, '.rb')
+
+ # Just give sample data to method and expect it to not crash.
+ begin
+ klass = Object.const_get(file_name.classify)
+ klass.new.execute(Gitlab::DataBuilder::Push::SAMPLE_DATA)
+ rescue => e
+ Rails.logger.warn("GitLab -> Plugins -> #{file_name} raised an exception during boot check. #{e}")
+ next
+ else
+ Rails.logger.info "GitLab -> Plugins -> #{file_name} passed validation check"
+ klass
+ end
+ end
+ end
+
+ def self.files
+ Dir.glob(Rails.root.join('plugins', '*_plugin.rb'))
+ end
+ end
+end
diff --git a/lib/tasks/plugins.rake b/lib/tasks/plugins.rake
index fac6070ea9b..8728e232c9c 100644
--- a/lib/tasks/plugins.rake
+++ b/lib/tasks/plugins.rake
@@ -22,4 +22,19 @@ namespace :plugins do
puts "Failed to save #{file_path}."
end
end
+
+ desc 'Validate existing plugins'
+ task validate: :environment do
+ puts 'Validating plugins from /plugins directory'
+
+ Gitlab::Plugin.all.each do |plugin|
+ begin
+ plugin.new.execute(Gitlab::DataBuilder::Push::SAMPLE_DATA)
+ rescue => e
+ puts "- #{plugin} raised an exception during boot check. #{e}"
+ else
+ puts "- #{plugin} passed validation check"
+ end
+ end
+ end
end