"Fossies" - the Fresh Open Source Software Archive 
Member "selenium-selenium-4.8.1/rake_tasks/copyright.rb" (17 Feb 2023, 2425 Bytes) of package /linux/www/selenium-selenium-4.8.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 # frozen_string_literal: true
2
3 class Copyright
4 def initialize(comment_characters: '//', prefix: nil)
5 @comment_characters = comment_characters
6 @prefix = prefix
7 end
8
9 def update(files)
10 files.each do |file|
11 lines = IO.readlines(file)
12
13 index = -1
14 lines.any? do |line|
15 done = true
16 if starts_with_comment_character?(line) || valid_copyright_notice_line?(line, index)
17 index += 1
18 done = false
19 end
20 done
21 end
22
23 if index == -1
24 write_update_notice(file, lines, copyright_notice)
25 else
26 current = lines.shift(index + 1).join('')
27 if current != copyright_notice
28 write_update_notice(file, lines, copyright_notice)
29 end
30 end
31 end
32 end
33
34 def starts_with_comment_character?(line)
35 line.index(@comment_characters)&.zero?
36 end
37
38 def valid_copyright_notice_line?(line, index)
39 copyright_notice_lines[index + 1] &&
40 line.index(copyright_notice_lines[index + 1])&.zero?
41 end
42
43 def copyright_notice
44 copyright_notice_lines.join('')
45 end
46
47 def copyright_notice_lines
48 @copyright_notice_lines ||= Array(@prefix) + commented_notice_lines
49 end
50
51 def commented_notice_lines
52 notice_lines.map do |line|
53 "#{@comment_characters} #{line}".rstrip + "\n"
54 end
55 end
56
57 def notice_lines
58 notice.split(/\n/)
59 end
60
61 def write_update_notice(file, lines, notice)
62 puts "Adding notice to #{file}"
63 File.open(file, 'w') do |f|
64 f.write(notice + "\n")
65 lines.each { |line| f.write(line) }
66 end
67 end
68
69 def notice
70 <<~eos
71 Licensed to the Software Freedom Conservancy (SFC) under one
72 or more contributor license agreements. See the NOTICE file
73 distributed with this work for additional information
74 regarding copyright ownership. The SFC licenses this file
75 to you under the Apache License, Version 2.0 (the
76 "License"); you may not use this file except in compliance
77 with the License. You may obtain a copy of the License at
78
79 http://www.apache.org/licenses/LICENSE-2.0
80
81 Unless required by applicable law or agreed to in writing,
82 software distributed under the License is distributed on an
83 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
84 KIND, either express or implied. See the License for the
85 specific language governing permissions and limitations
86 under the License.
87 eos
88 end
89 end