Skip to content

Commit

Permalink
[GR-17457] Update copyright years in markdown files
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/3611
  • Loading branch information
eregon committed Jan 11, 2023
2 parents 8e8dec8 + 2f47571 commit e8875c4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion LICENCE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TruffleRuby Licence

TruffleRuby is copyright (c) 2013-2022 Oracle and/or its affiliates, and is made
TruffleRuby is copyright (c) 2013-2023 Oracle and/or its affiliates, and is made
available to you under the terms of any one of the following three licenses:

* Eclipse Public License version 2.0, or
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ For known vulnerabilities in Ruby, please refer to the [known-cves](doc/user/kno

## Licence

TruffleRuby is copyright (c) 2013-2022 Oracle and/or its affiliates, and is made
TruffleRuby is copyright (c) 2013-2023 Oracle and/or its affiliates, and is made
available to you under the terms of any one of the following three licenses:

* Eclipse Public License version 2.0, or
Expand Down
2 changes: 1 addition & 1 deletion doc/legal/legal.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use TruffleRuby.

## TruffleRuby

TruffleRuby is copyright (c) 2013-2022 Oracle and/or its
TruffleRuby is copyright (c) 2013-2023 Oracle and/or its
affiliates, and is made available to you under the terms of any one of the
following three licenses:

Expand Down
25 changes: 17 additions & 8 deletions tool/update_copyright.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@
'.h' => JAVA_COPYRIGHT,
}

EXTENSIONS = %w[.java .rb .c .h]
EXTENSIONS = %w[.java .rb .c .h .md]

COPYRIGHT = /Copyright \(c\) (?<year1>\d{4})(?:, (?<year2>\d{4}))* Oracle\b/
COPYRIGHT = /(?<copyright>Copyright) \(c\) (?<year1>\d{4})(?:(?<sep>, )(?<year2>\d{4}))? Oracle\b/
COPYRIGHT_MARKDOWN = /(?<copyright>copyright) \(c\) (?<year1>\d{4})(?:(?<sep>-)(?<year2>\d{4}))? Oracle\b/

OTHER_COPYRIGHTS = [
/Copyright \(c\) \d{4}(?:-\d{4})?,? Evan Phoenix/,
Expand All @@ -66,6 +67,9 @@
test/truffle
tool/generate
spec/truffle
LICENCE.md
README.md
doc/legal/legal.md
] + [__FILE__]

excludes = %w[
Expand Down Expand Up @@ -115,24 +119,29 @@
}

paths.each do |file|
header = File.read(file, 400)
ext = File.extname(file)
md = ext == '.md'
header = File.read(file, *(400 unless md))

unless COPYRIGHT =~ header
copyright_regexp = md ? COPYRIGHT_MARKDOWN : COPYRIGHT

unless copyright_regexp =~ header
next if md
if OTHER_COPYRIGHTS.none? { |copyright| copyright =~ header }
puts "Adding copyright in #{file}"
File.write(file, NEW_COPYRIGHT[File.extname(file)]+File.read(file))
File.write(file, NEW_COPYRIGHT[ext]+File.read(file))
end
next
end

year1, year2 = $~[:year1], $~[:year2]
copyright, year1, sep, year2 = $~[:copyright], $~[:year1], $~[:sep], $~[:year2]
year1 = Integer(year1)
year2 = Integer(year2 || year1)

if year > year2
contents = File.read(file)
years = "#{year1}, #{year}"
contents.sub!(COPYRIGHT, "Copyright (c) #{years} Oracle")
years = "#{year1}#{sep}#{year}"
contents.sub!(copyright_regexp, "#{copyright} (c) #{years} Oracle")
File.write(file, contents)

puts "Updated year in #{file}"
Expand Down

0 comments on commit e8875c4

Please sign in to comment.