Skip to content

Commit 6b4e6de

Browse files
committed
For #401, add a new rake task to update the copyright notices in all source code
./go copyright:update This task ensures the copyright notice dictated in CONTRIBUTING.md is applied at the top of every file and standardizes on a line-comment format. The task currently covers the java/, py/, and javascript/ trees. Close #405.
1 parent 8f56eaf commit 6b4e6de

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

Rakefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ require 'rake-tasks/selenium'
3939
require 'rake-tasks/se-ide'
4040
require 'rake-tasks/ie_code_generator'
4141
require 'rake-tasks/ci'
42+
require 'rake-tasks/copyright'
4243

4344
require 'rake-tasks/gecko_sdks'
4445

@@ -715,6 +716,36 @@ task :authors do
715716
sh "(git log --use-mailmap --format='%aN <%aE>' ; cat .OLD_AUTHORS) | sort -uf > AUTHORS"
716717
end
717718

719+
namespace :copyright do
720+
task :update do
721+
Copyright.Update(
722+
FileList["javascript/**/*.js"].exclude(
723+
"javascript/atoms/test/jquery.min.js",
724+
"javascript/firefox-driver/extension/components/httpd.js",
725+
"javascript/jsunit/**/*.js",
726+
"javascript/node/selenium-webdriver/node_modules/**/*.js",
727+
"javascript/selenium-core/lib/**/*.js",
728+
"javascript/selenium-core/scripts/ui-element.js",
729+
"javascript/selenium-core/scripts/ui-map-sample.js",
730+
"javascript/selenium-core/scripts/user-extensions.js",
731+
"javascript/selenium-core/scripts/xmlextras.js",
732+
"javascript/selenium-core/xpath/**/*.js"))
733+
Copyright.Update(
734+
FileList["py/**/*.py"],
735+
:style => "#",
736+
:prefix => "#!/usr/bin/python\n#\n")
737+
Copyright.Update(
738+
FileList["java/**/*.java"].exclude(
739+
"java/client/src/org/openqa/selenium/internal/Base64Encoder.java",
740+
"java/client/test/org/openqa/selenium/internal/Base64EncoderTest.java",
741+
"java/server/src/cybervillains/**/*.java",
742+
"java/server/src/org/openqa/selenium/server/FrameGroupCommandQueueSet.java",
743+
"java/server/src/org/openqa/selenium/server/FutureFileResource.java",
744+
"java/server/src/org/openqa/selenium/server/ProxyHandler.java"
745+
))
746+
end
747+
end
748+
718749
at_exit do
719750
if File.exist?(".git") && !Platform.windows?
720751
sh "sh .git-fixfiles"

rake-tasks/copyright.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
module Copyright
2+
NOTICE = <<-eos
3+
Licensed to the Software Freedom Conservancy (SFC) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The SFC licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
eos
20+
21+
def Update(files, options = {})
22+
style = options[:style] || "//"
23+
prefix = options[:prefix] || nil
24+
25+
notice = Copyright::NOTICE.split(/\n/).map{|line|
26+
(style + " " + line).rstrip + "\n"
27+
}.join("")
28+
notice = prefix + notice unless prefix.nil?
29+
30+
files.each do |f|
31+
lines = IO.readlines(f)
32+
33+
index = -1
34+
lines.any? {|line|
35+
done = true
36+
if line.index(style) == 0
37+
index += 1
38+
done = false
39+
end
40+
done
41+
}
42+
if index == -1
43+
puts "Adding notice to #{f}"
44+
File.open(f, "w") do |f|
45+
f.write(notice + "\n")
46+
lines.each {|line| f.write(line) }
47+
end
48+
else
49+
current = lines.shift(index + 1).join("")
50+
if current != notice
51+
puts "Updating notice in #{f}"
52+
File.open(f, "w") do |f|
53+
f.write(notice)
54+
lines.each {|line| f.write(line) }
55+
end
56+
end
57+
end
58+
end
59+
end
60+
module_function :Update
61+
end

0 commit comments

Comments
 (0)