Skip to content

Commit

Permalink
Update copyright:update task to work with rb frozen string literal pr…
Browse files Browse the repository at this point in the history
…agma
  • Loading branch information
twalpole committed Mar 6, 2019
1 parent d2cd99b commit a5f241f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@ namespace :copyright do
:style => "#")
Copyright.Update(
FileList["rb/**/*.rb"],
:style => "#")
:style => "#",
:prefix => ["# frozen_string_literal: true\n", "\n"])
Copyright.Update(
FileList["java/**/*.java"])
end
Expand Down
11 changes: 6 additions & 5 deletions rake-tasks/copyright.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,24 @@ module Copyright
specific language governing permissions and limitations
under the License.
eos

def Update(files, options = {})
style = options[:style] || "//"
prefix = options[:prefix] || nil

notice = Copyright::NOTICE.split(/\n/).map{|line|
notice_lines = Copyright::NOTICE.split(/\n/).map{|line|
(style + " " + line).rstrip + "\n"
}.join("")
notice = prefix + notice unless prefix.nil?
}
notice_lines = Array(prefix) + notice_lines
notice = notice_lines.join("")

files.each do |f|
lines = IO.readlines(f)

index = -1
lines.any? {|line|
done = true
if line.index(style) == 0
if (line.index(style) == 0) ||
(notice_lines[index + 1] && (line.index(notice_lines[index + 1]) == 0))
index += 1
done = false
end
Expand Down

0 comments on commit a5f241f

Please sign in to comment.