OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/lib/tasks/copyright.rake

269 lines
8.8 KiB

#-- encoding: UTF-8
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2021 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# 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.
#
# See docs/COPYRIGHT.rdoc for more details.
#++
namespace :copyright do
def short_copyright(format, options = {})
case format
when :ruby, :rb
short_copyright_line('#', options)
when :js, :sass, :ts
short_copyright_line('//', options)
when :css
short_copyright_surrounding('/*', '*/', options)
when :sql
short_copyright_line('-- ', options)
when :erb
short_copyright_surrounding('<%#', '#%>', options)
when :rdoc
"----------\n#{short_copyright_line(' ', options)}\n----------\n".gsub(' -- copyright', "==== copyright\n")
when :md
short_copyright_surrounding('<!--', '-->', options)
else
raise "Undefined format #{format}"
end
end
def copyright_file(options = {})
path = 'docs/COPYRIGHT_short.rdoc'
if options[:path]
path = File.join(options[:path], 'docs/COPYRIGHT_short.rdoc') if File.exists?(File.join(options[:path],
'docs/COPYRIGHT_short.rdoc'))
path = File.join(options[:path], 'docs/COPYRIGHT_short.md') if File.exists?(File.join(options[:path],
'docs/COPYRIGHT_short.md'))
end
path
end
def short_copyright_surrounding(open, close, options = {})
short_copyright = File.read copyright_file(options)
"#{open}-- copyright\n#{short_copyright}\n++#{close}"
end
def short_copyright_line(sign, options = {})
short_copyright = File.readlines(copyright_file(options)).collect do |line|
"#{sign} #{line}".rstrip
end.join("\n")
"#{sign}-- copyright\n#{short_copyright}\n#{sign}++"
end
def exluded_paths
%w(
app/assets/javascripts/lib/
app/assets/javascripts/locales/
coverage
frontend/bower_components
frontend/node_modules
frontend/vendor
frontend/coverage
frontend/tmp
tmp
)
end
def copyright_regexp(format)
case format
when :ruby, :rb
/\A(?<shebang>#![^\n]+\n)?(?<additional>.*)?#--\s*copyright.*?\+\+/m
when :js, :css, :sass, :ts
/\A(?<shebang>#![^\n]+\n)?(?<additional>.*)?\/\/\s*--\s*copyright.*?\/\/\s*\+\+/m
when :erb
/\A(?<shebang>#![^\n]+\n)?(?<additional>.*)?<%#--\s*copyright.*?\+\+#%>/m
when :rdoc
/(?<shebang>)?(?<additional>.*)?-{10}\n={4} copyright\n\n[\s\S]*?\+\+\n-{10}\n\z/
when :md, :html
/\A(?<shebang>#![^\n]+\n)?(?<additional>.*)?<!----\s*copyright.*?\+\+-->/m
when :sql
/\A(?<shebang>#![^\n]+\n)?(?<additional>.*)?-- --\s*copyright.*?\+\+/m
else
raise "Undefined format #{format}"
end
end
def rewrite_copyright(ending, additional_excludes, format, path, options = {})
regexp = options[:regex] || copyright_regexp(format)
path = '.' if path.nil?
copyright = options[:copyright] || short_copyright(format, path: path)
file_list = options[:file_list] || Dir[File.absolute_path(path) + "/**/*.#{ending}"]
excluded = exluded_paths.concat(additional_excludes)
raise 'Path not found' unless Dir.exists?(path)
file_list.each do |file_name|
# Skip 3rd party code
next if excluded.any? { |e| file_name.include?(e) }
file_content = File.read(file_name)
if file_content.match(regexp)
file_content.gsub!(regexp, '\k<shebang>' + '\k<additional>' + copyright)
else
puts "#{file_name} does not match regexp. Missing copyright notice?"
end
File.open(file_name, 'w') do |file|
file.write file_content
end
end
end
desc 'Update special files, which do not have an ending'
task :update_special_files, :arg1 do |_task, args|
# ruby-like files
file_list = %w{Gemfile Rakefile config.ru .travis.yml .gitignore}.map do |f|
File.absolute_path f
end
rewrite_copyright('rb', [], :rb, args[:arg1], file_list: file_list)
end
desc 'Update the copyright on .rb source files'
task :update_rb, :arg1 do |_task, args|
6 years ago
excluded = (%w(acts_as_tree rfpdf verification).map { |dir| "lib/plugins/#{dir}" })
rewrite_copyright('rb', excluded, :rb, args[:arg1])
end
desc 'Update the copyright on .rake source files'
task :update_rake, :arg1 do |_task, args|
rewrite_copyright('rake', [], :rb, args[:arg1])
end
desc 'Update the copyright on .yml source files'
task :update_yml, :arg1 do |_task, args|
rewrite_copyright('yml', [], :rb, args[:arg1])
end
desc 'Update the copyright on .yml.example source files'
task :update_yml_example, :arg1 do |_task, args|
rewrite_copyright('yml.example', [], :rb, args[:arg1])
end
desc 'Update the copyright on .rb.example source files'
task :update_rb_example, :arg1 do |_task, args|
rewrite_copyright('rb.example', [], :rb, args[:arg1])
end
desc 'Update the copyright on .rjs source files'
task :update_rjs, :arg1 do |_task, args|
rewrite_copyright('rjs', [], :rb, args[:arg1])
end
desc 'Update the copyright on .feature source files'
task :update_feature, :arg1 do |_task, args|
rewrite_copyright('feature', [], :rb, args[:arg1])
end
desc 'Update the copyright on .css source files'
task :update_css, :arg1 do |_task, args|
excluded = []
rewrite_copyright('css', excluded, :css, args[:arg1])
end
desc 'Update the copyright on .css.erb source files'
task :update_css_erb, :arg1 do |_task, args|
excluded = []
rewrite_copyright('css.erb', excluded, :css, args[:arg1])
end
desc 'Update the copyright on .sass source files'
task :update_sass, :arg1 do |_task, args|
excluded = %w(
app/assets/stylesheets/default.css.sass
)
rewrite_copyright('sass', excluded, :sass, args[:arg1])
end
desc 'Update the copyright on .sql source files'
task :update_sql, :arg1 do |_task, args|
rewrite_copyright('sql', [], :sql, args[:arg1])
end
desc 'Update the copyright on .js source files'
task :update_js, :arg1 do |_task, args|
Move asset pipeline javascripts to frontend (#8482) * ove reporting and reporting_engine js to frontend page * Replace webhook assets javascript * Add path augment service to dynamically load scripts * Remove JS-Files that are not used/not needed any more * Include AugmentingModule correctly * Remove special handling for checkbox selection which is outdated and two jquery libs that are not used any more * Load scripts dynamically that are not needed globally * Move plugin JS to frontend * Move toggable fieldsets to global listeners * Move top-menu to global listeners and convert to TS * Move action_menu to frontend and port to TS * Move settings listener to frontend * Remove global js assets that were not used anyway * Move date range to timelog dynamic script where it's still used until removed * Move colors to global-listeners and port to TS * Replace tooltip with simple form instructions on the one place used Tooltips were only used at the one place in our application, when changing a users password. We can simply remove it there and use a modern solution the next time we need a tooltip * Move danger zone validation to frontend and port to TS * Move colorcontrast to backlogs vendor where it's used now * Remove contents of application.js.erb * Move project and user scripts to dynamically loaded * Move onboarding tour to dynamically loaded * Use correct syntax for jQuery so that $ is known keyword within this function * Fix onboarding tour * Fix onboarding tour for scrum tour * Fix specs after moving JS * Remove application.js.erb * Move locales and ckeditor to the frontend to dynamically load * Remove bundles caches These are no longer being used since angular cli * Ensure locales are exported before angular Co-authored-by: Henriette Darge <h.darge@openproject.com>
4 years ago
excluded = []
rewrite_copyright('js', excluded, :js, args[:arg1])
end
desc 'Update the copyright on .js.erb source files'
task :update_js_erb, :arg1 do |_task, args|
excluded = ['app/assets/javascripts/application.js.erb']
rewrite_copyright('js.erb', excluded, :erb, args[:arg1])
end
desc 'Update the copyright on .rdoc source files'
task :update_rdoc, :arg1 do |_task, args|
excluded = ['README.rdoc',
'docs/COPYRIGHT.rdoc',
'docs/COPYING.rdoc',
'docs/COPYRIGHT_short.rdoc']
rewrite_copyright('rdoc', excluded, :rdoc, args[:arg1], position: :bottom)
end
desc 'Update the copyright on .html.erb source files'
task :update_html_erb, :arg1 do |_task, args|
rewrite_copyright('html.erb', [], :erb, args[:arg1])
end
desc 'Update the copyright on .json.erb source files'
task :update_json_erb, :arg1 do |_task, args|
rewrite_copyright('json.erb', [], :erb, args[:arg1])
end
desc 'Update the copyright on .atom.builder source files'
task :update_atom_builder, :arg1 do |_task, args|
rewrite_copyright('atom.builder', [], :rb, args[:arg1])
end
desc 'Update the copyright on .text.erb source files'
task :update_text_erb, :arg1 do |_task, args|
rewrite_copyright('text.erb', [], :erb, args[:arg1])
end
desc 'Update the copyright on .ts source files'
task :update_typescript, :arg1 do |_task, args|
rewrite_copyright('ts', [], :ts, args[:arg1])
end
desc 'Update the copyright on all source files'
task :update, :arg1 do |_task, args|
%w{
css rb js js_erb css_erb html_erb json_erb text_erb atom_builder rake
feature rdoc rjs sql yml yml_example rb_example special_files sass
}.each do |t|
Rake::Task['copyright:update_' + t.to_s].invoke(args[:arg1])
end
end
end