]> source.dussan.org Git - redmine.git/commitdiff
Fix plugin assets are no longer copied under plugin name (#36218, #29914, #32938).
authorMarius Balteanu <marius.balteanu@zitec.com>
Thu, 25 Nov 2021 21:34:40 +0000 (21:34 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Thu, 25 Nov 2021 21:34:40 +0000 (21:34 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@21295 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/plugin_loader.rb
test/fixtures/plugins/foo_plugin/assets/stylesheets/foo.css [new file with mode: 0644]
test/unit/lib/redmine/plugin_loader_test.rb [new file with mode: 0644]

index 43219a116204d53674dee24e98be258ce26ba62f..7b05a8a3d72b7ed1f1bb6ed6e810d97086ea27c1 100644 (file)
@@ -38,21 +38,24 @@ module Redmine
     def mirror_assets
       return unless has_assets_dir?
 
+      destination = File.join(PluginLoader.public_directory, File.basename(@dir))
+
       source_files = Dir["#{assets_dir}/**/*"]
       source_dirs = source_files.select { |d| File.directory?(d)}
       source_files -= source_dirs
       unless source_files.empty?
-        base_target_dir = File.join(PluginLoader.public_directory, File.dirname(source_files.first).gsub(assets_dir, ''))
+        base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(assets_dir, ''))
         begin
           FileUtils.mkdir_p(base_target_dir)
         rescue => e
           raise "Could not create directory #{base_target_dir}: " + e.message
         end
       end
+
       source_dirs.each do |dir|
         # strip down these paths so we have simple, relative paths we can
         # add to the destination
-        target_dir = File.join(PluginLoader.public_directory, dir.gsub(assets_dir, ''))
+        target_dir = File.join(destination, dir.gsub(assets_dir, ''))
         begin
           FileUtils.mkdir_p(target_dir)
         rescue => e
@@ -60,7 +63,7 @@ module Redmine
         end
       end
       source_files.each do |file|
-        target = File.join(PluginLoader.public_directory, file.gsub(assets_dir, ''))
+        target = File.join(destination, file.gsub(assets_dir, ''))
         unless File.exist?(target) && FileUtils.identical?(file, target)
           FileUtils.cp(file, target)
         end
diff --git a/test/fixtures/plugins/foo_plugin/assets/stylesheets/foo.css b/test/fixtures/plugins/foo_plugin/assets/stylesheets/foo.css
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/unit/lib/redmine/plugin_loader_test.rb b/test/unit/lib/redmine/plugin_loader_test.rb
new file mode 100644 (file)
index 0000000..43d1005
--- /dev/null
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+# Redmine - project management software
+# Copyright (C) 2006-2021  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+require File.expand_path('../../../../test_helper', __FILE__)
+
+class Redmine::PluginLoaderTest < ActiveSupport::TestCase
+  def setup
+    clear_public
+
+    @klass = Redmine::PluginLoader
+    @klass.directory = Rails.root.join('test/fixtures/plugins')
+    @klass.public_directory = Rails.root.join('tmp/public/plugin_assets')
+    @klass.load
+  end
+
+  def teardown
+    clear_public
+  end
+
+  def test_create_assets_reloader
+    plugin_assets = @klass.create_assets_reloader
+    plugin_assets.execute.inspect
+
+    assert File.exist?("#{@klass.public_directory}/foo_plugin")
+    assert File.exist?("#{@klass.public_directory}/foo_plugin/stylesheets/foo.css")
+  end
+
+  def clear_public
+    FileUtils.rm_rf 'tmp/public'
+  end
+end