1
+ # frozen_string_literal: true
2
+
1
3
#-- copyright
2
4
# OpenProject is an open source project management software.
3
5
# Copyright (C) the OpenProject GmbH
@@ -101,6 +103,15 @@ namespace :copyright do
101
103
end
102
104
end
103
105
106
+ def missing_copyright_regexp ( format )
107
+ case format
108
+ when :ruby , :rb
109
+ /\A (?<shebang>#![^\n ]+\n \n ?)?(?<additional># frozen_string_literal: (?:true|false)\n \n ?)?\n */m
110
+ else
111
+ raise "Format #{ format } is not yet supported for copyright creation"
112
+ end
113
+ end
114
+
104
115
def rewrite_copyright ( ending , additional_excluded_globs , format , path , options = { } ) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
105
116
regexp = options [ :regex ] || copyright_regexp ( format )
106
117
path = "." if path . nil?
@@ -119,6 +130,13 @@ namespace :copyright do
119
130
file_content = File . read ( file_name )
120
131
if file_content . match ( regexp )
121
132
file_content . gsub! ( regexp , "\\ k<shebang>\\ k<additional>#{ copyright } " )
133
+ elsif options [ :create ]
134
+ if file_content . include? ( "OpenProject is a fork of ChiliProject" )
135
+ puts "#{ file_name } does not match regexp, but seems to have a copyright header!"
136
+ next
137
+ end
138
+
139
+ file_content . gsub! ( missing_copyright_regexp ( format ) , "\\ k<shebang>\\ k<additional>#{ copyright } \n \n " )
122
140
else
123
141
puts "#{ file_name } does not match regexp. Missing copyright notice?"
124
142
end
@@ -137,21 +155,22 @@ namespace :copyright do
137
155
.gitignore
138
156
]
139
157
140
- rewrite_copyright ( "rb" , [ ] , :rb , args [ :path ] , file_list :)
158
+ rewrite_copyright ( "rb" , [ ] , :rb , args [ :path ] , file_list :, create : true )
141
159
end
142
160
143
161
desc "Update the copyright on .rb source files"
144
162
task :update_rb , :path do |_task , args |
145
163
excluded = %w[
146
- lib_static/plugins/{acts_as_tree,rfpdf,verification}
164
+ lib_static/plugins/{acts_as_tree,rfpdf,verification}/**/*
165
+ lib/chronic_duration.rb
147
166
]
148
167
149
- rewrite_copyright ( "rb" , excluded , :rb , args [ :path ] )
168
+ rewrite_copyright ( "rb" , excluded , :rb , args [ :path ] , create : true )
150
169
end
151
170
152
171
desc "Update the copyright on .rake source files"
153
172
task :update_rake , :path do |_task , args |
154
- rewrite_copyright ( "rake" , [ ] , :rb , args [ :path ] )
173
+ rewrite_copyright ( "rake" , [ ] , :rb , args [ :path ] , create : true )
155
174
end
156
175
157
176
desc "Update the copyright on .yml source files"
@@ -161,27 +180,27 @@ namespace :copyright do
161
180
modules/*/config/locales/crowdin/*.yml
162
181
]
163
182
164
- rewrite_copyright ( "yml" , excluded , :rb , args [ :path ] )
183
+ rewrite_copyright ( "yml" , excluded , :rb , args [ :path ] , create : true )
165
184
end
166
185
167
186
desc "Update the copyright on .yml.example source files"
168
187
task :update_yml_example , :path do |_task , args |
169
- rewrite_copyright ( "yml.example" , [ ] , :rb , args [ :path ] )
188
+ rewrite_copyright ( "yml.example" , [ ] , :rb , args [ :path ] , create : true )
170
189
end
171
190
172
191
desc "Update the copyright on .rb.example source files"
173
192
task :update_rb_example , :path do |_task , args |
174
- rewrite_copyright ( "rb.example" , [ ] , :rb , args [ :path ] )
193
+ rewrite_copyright ( "rb.example" , [ ] , :rb , args [ :path ] , create : true )
175
194
end
176
195
177
196
desc "Update the copyright on .rjs source files"
178
197
task :update_rjs , :path do |_task , args |
179
- rewrite_copyright ( "rjs" , [ ] , :rb , args [ :path ] )
198
+ rewrite_copyright ( "rjs" , [ ] , :rb , args [ :path ] , create : true )
180
199
end
181
200
182
201
desc "Update the copyright on .feature source files"
183
202
task :update_feature , :path do |_task , args |
184
- rewrite_copyright ( "feature" , [ ] , :rb , args [ :path ] )
203
+ rewrite_copyright ( "feature" , [ ] , :rb , args [ :path ] , create : true )
185
204
end
186
205
187
206
desc "Update the copyright on .css source files"
0 commit comments