Skip to content

Commit 820df9d

Browse files
luke-hillp0deje
authored andcommitted
RuboCop autofixes on rakelib
Also includes minor tweaks and restructures of the rakelib directory rakes
1 parent 18efc72 commit 820df9d

File tree

8 files changed

+178
-160
lines changed

8 files changed

+178
-160
lines changed

rakelib/bazel.rake

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,35 @@
11
require 'pp'
22
require 'open3'
3-
require "rake/task"
3+
require 'rake/task'
4+
require 'rakelib/bazel/task'
5+
require 'rakelib/rake/dsl'
46

57
module Bazel
6-
def self.execute(kind, args, target, &block)
7-
verbose = Rake::FileUtilsExt.verbose_flag
8-
outs = []
9-
10-
cmd = %w(bazel) + [kind, target] + (args || [])
11-
cmd_out = ""
12-
Open3.popen2e(*cmd) do |stdin, stdouts, wait|
13-
Thread.new do
14-
while (line = stdouts.gets)
15-
if line.chomp =~ /\s+(bazel-bin\/.+)/
16-
outs << $1
8+
class << self
9+
def execute(kind, args, target, &block)
10+
verbose = Rake::FileUtilsExt.verbose_flag
11+
outs = []
12+
13+
cmd = %w[bazel] + [kind, target] + (args || [])
14+
cmd_out = ''
15+
Open3.popen2e(*cmd) do |stdin, stdouts, wait|
16+
Thread.new do
17+
while (line = stdouts.gets)
18+
outs << Regexp.last_match(1) if line.chomp =~ %r{\s+(bazel-bin/.+)}
19+
cmd_out << line
20+
STDOUT.print line if verbose
1721
end
18-
cmd_out << line
19-
STDOUT.print line if verbose
2022
end
21-
end
2223

23-
stdin.close
24+
stdin.close
2425

25-
raise "#{cmd.join(' ')} failed with exit code: #{wait.value.exitstatus}" unless wait.value.success?
26+
raise "#{cmd.join(' ')} failed with exit code: #{wait.value.exitstatus}" unless wait.value.success?
2627

27-
block.call(cmd_out) if block
28+
block&.call(cmd_out)
2829

29-
if outs.length
30-
puts "#{target} -> #{outs[0]}"
30+
puts "#{target} -> #{outs[0]}" if outs.length
31+
outs[0] if outs.length
3132
end
32-
outs[0] if outs.length
33-
end
34-
end
35-
36-
class BazelTask < Rake::Task
37-
def needed?
38-
true
3933
end
40-
41-
def invoke(*args, &block)
42-
self.out = Bazel::execute("build", ["--workspace_status_command=\"#{py_exe} scripts/build-info.py\""], name, &block)
43-
44-
block.call(cmd_out) if block
45-
end
46-
end
47-
end
48-
49-
module Rake::DSL
50-
def bazel(*args, &block)
51-
Bazel::BazelTask.define_task(*args, &block)
5234
end
5335
end

rakelib/bazel/task.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Bazel
2+
class Task < Rake::Task
3+
def needed?
4+
true
5+
end
6+
7+
def invoke(*_args, &block)
8+
self.out = Bazel::execute("build", ["--workspace_status_command=\"#{py_exe} scripts/build-info.py\""], name, &block)
9+
10+
block&.call(cmd_out)
11+
end
12+
end
13+
end

rakelib/copyright.rake

Lines changed: 73 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,99 @@
1+
# frozen_string_literal: true
2+
13
namespace :copyright do
24
task :update do
3-
Copyright.Update(
4-
FileList["javascript/**/*.js"].exclude(
5-
"javascript/atoms/test/jquery.min.js",
6-
"javascript/jsunit/**/*.js",
7-
"javascript/node/selenium-webdriver/node_modules/**/*.js",
8-
"javascript/selenium-core/lib/**/*.js",
9-
"javascript/selenium-core/scripts/ui-element.js",
10-
"javascript/selenium-core/scripts/ui-map-sample.js",
11-
"javascript/selenium-core/scripts/user-extensions.js",
12-
"javascript/selenium-core/scripts/xmlextras.js",
13-
"javascript/selenium-core/xpath/**/*.js"))
14-
Copyright.Update(
15-
FileList["py/**/*.py"],
16-
:style => "#")
17-
Copyright.Update(
18-
FileList["rb/**/*.rb"],
19-
:style => "#",
20-
:prefix => ["# frozen_string_literal: true\n", "\n"])
21-
Copyright.Update(
22-
FileList["java/**/*.java"])
5+
Copyright.update(
6+
FileList['javascript/**/*.js'].exclude(
7+
'javascript/atoms/test/jquery.min.js',
8+
'javascript/jsunit/**/*.js',
9+
'javascript/node/selenium-webdriver/node_modules/**/*.js',
10+
'javascript/selenium-core/lib/**/*.js',
11+
'javascript/selenium-core/scripts/ui-element.js',
12+
'javascript/selenium-core/scripts/ui-map-sample.js',
13+
'javascript/selenium-core/scripts/user-extensions.js',
14+
'javascript/selenium-core/scripts/xmlextras.js',
15+
'javascript/selenium-core/xpath/**/*.js'
16+
)
17+
)
18+
Copyright.update(
19+
FileList['py/**/*.py'],
20+
style: '#'
21+
)
22+
Copyright.update(
23+
FileList['rb/**/*.rb'],
24+
style: '#',
25+
prefix: ["# frozen_string_literal: true\n", "\n"]
26+
)
27+
Copyright.update(
28+
FileList['java/**/*.java']
29+
)
2330
end
2431
end
2532

2633
module Copyright
27-
NOTICE = <<-eos
28-
Licensed to the Software Freedom Conservancy (SFC) under one
29-
or more contributor license agreements. See the NOTICE file
30-
distributed with this work for additional information
31-
regarding copyright ownership. The SFC licenses this file
32-
to you under the Apache License, Version 2.0 (the
33-
"License"); you may not use this file except in compliance
34-
with the License. You may obtain a copy of the License at
35-
36-
http://www.apache.org/licenses/LICENSE-2.0
34+
module_function
3735

38-
Unless required by applicable law or agreed to in writing,
39-
software distributed under the License is distributed on an
40-
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
41-
KIND, either express or implied. See the License for the
42-
specific language governing permissions and limitations
43-
under the License.
44-
eos
45-
def Update(files, options = {})
46-
style = options[:style] || "//"
36+
def update(files, options = {})
37+
style = options[:style] || '//'
4738
prefix = options[:prefix] || nil
4839

49-
notice_lines = Copyright::NOTICE.split(/\n/).map{|line|
50-
(style + " " + line).rstrip + "\n"
51-
}
40+
notice_lines = notice.split(/\n/).map do |line|
41+
"#{style} #{line}".rstrip + "\n"
42+
end
5243
notice_lines = Array(prefix) + notice_lines
53-
notice = notice_lines.join("")
44+
notice = notice_lines.join('')
5445

55-
files.each do |f|
56-
lines = IO.readlines(f)
46+
files.each do |file|
47+
lines = IO.readlines(file)
5748

5849
index = -1
59-
lines.any? {|line|
50+
lines.any? do |line|
6051
done = true
61-
if (line.index(style) == 0) ||
62-
(notice_lines[index + 1] && (line.index(notice_lines[index + 1]) == 0))
52+
if (line.index(style).zero?) ||
53+
(notice_lines[index + 1] && (line.index(notice_lines[index + 1]).zero?))
6354
index += 1
6455
done = false
6556
end
6657
done
67-
}
58+
end
59+
6860
if index == -1
69-
puts "Adding notice to #{f}"
70-
File.open(f, "w") do |f|
71-
f.write(notice + "\n")
72-
lines.each {|line| f.write(line) }
73-
end
61+
write_update_notice(file, lines, notice)
7462
else
75-
current = lines.shift(index + 1).join("")
63+
current = lines.shift(index + 1).join('')
7664
if current != notice
77-
puts "Updating notice in #{f}"
78-
File.open(f, "w") do |f|
79-
f.write(notice)
80-
lines.each {|line| f.write(line) }
81-
end
65+
write_update_notice(file, lines, notice)
8266
end
8367
end
8468
end
8569
end
86-
module_function :Update
70+
71+
def write_update_notice(file, lines, notice)
72+
puts "Adding notice to #{file}"
73+
File.open(file, 'w') do |f|
74+
f.write(notice + "\n")
75+
lines.each { |line| f.write(line) }
76+
end
77+
end
78+
79+
def notice
80+
<<~eos
81+
Licensed to the Software Freedom Conservancy (SFC) under one
82+
or more contributor license agreements. See the NOTICE file
83+
distributed with this work for additional information
84+
regarding copyright ownership. The SFC licenses this file
85+
to you under the Apache License, Version 2.0 (the
86+
"License"); you may not use this file except in compliance
87+
with the License. You may obtain a copy of the License at
88+
89+
http://www.apache.org/licenses/LICENSE-2.0
90+
91+
Unless required by applicable law or agreed to in writing,
92+
software distributed under the License is distributed on an
93+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
94+
KIND, either express or implied. See the License for the
95+
specific language governing permissions and limitations
96+
under the License.
97+
eos
98+
end
8799
end

rakelib/ide.rake

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1+
# frozen_string_literal: true
2+
13
namespace :side do
2-
task :atoms => [
3-
"//javascript/atoms/fragments:find-element",
4+
task atoms: [
5+
'//javascript/atoms/fragments:find-element'
46
] do
57
# TODO: move directly to IDE's directory once the repositories are merged
6-
baseDir = "build/javascript/atoms"
8+
baseDir = 'build/javascript/atoms'
79
mkdir_p baseDir
810

911
[
10-
Rake::Task["//javascript/atoms/fragments:find-element"].out,
12+
Rake::Task['//javascript/atoms/fragments:find-element'].out
1113
].each do |atom|
1214
name = File.basename(atom)
1315

1416
puts "Generating #{atom} as #{name}"
15-
File.open(File.join(baseDir, name), "w") do |f|
17+
File.open(File.join(baseDir, name), 'w') do |f|
1618
f << "// GENERATED CODE - DO NOT EDIT\n"
17-
f << "module.exports = "
19+
f << 'module.exports = '
1820
f << IO.read(atom).strip
1921
f << ";\n"
2022
end

rakelib/jruby.rake

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
1+
# frozen_string_literal: true
2+
13
require 'open-uri'
24

3-
jruby_version = "9.2.8.0"
5+
jruby_version = '9.2.8.0'
46
jruby_gems = {
5-
"inifile" => "3.0.0"
7+
'inifile' => '3.0.0'
68
}
79

810
namespace :jruby do
9-
desc "Update jruby version"
11+
desc 'Update jruby version'
1012
task :update do
1113
jar_name = "jruby-complete-#{jruby_version}.jar"
1214
url = "https://repo1.maven.org/maven2/org/jruby/jruby-complete/#{jruby_version}/#{jar_name}"
1315

1416
Dir.chdir('third_party/jruby') do
1517
puts "Downloading #{jar_name} from #{url}..."
16-
File.open(jar_name, "wb") do |write_file|
17-
open(url, "rb") do |read_file|
18+
File.open(jar_name, 'wb') do |write_file|
19+
open(url, 'rb') do |read_file|
1820
write_file.write(read_file.read)
1921
end
2022
end
2123

22-
puts "Installing gems..."
24+
puts 'Installing gems...'
2325
jruby_gems.each do |gem_name, gem_version|
24-
sh "java", "-jar", jar_name, "-S", "gem", "install", "-i", "./#{gem_name}", gem_name, "-v", gem_version
25-
sh "jar", "uf", jar_name, "-C", gem_name, "."
26+
sh 'java', '-jar', jar_name, '-S', 'gem', 'install', '-i', "./#{gem_name}", gem_name, '-v', gem_version
27+
sh 'jar', 'uf', jar_name, '-C', gem_name, '.'
2628
rm_rf gem_name
2729
end
2830

29-
puts "Bumping VERSION..."
31+
puts 'Bumping VERSION...'
3032
version = `java -jar #{jar_name} -v`.split("\n").first
3133
File.write('VERSION', "#{version}\n")
3234

33-
mv jar_name, "jruby-complete.jar"
34-
puts "Done!"
35+
mv jar_name, 'jruby-complete.jar'
36+
puts 'Done!'
3537
end
3638
end
3739
end

rakelib/node.rake

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1+
# frozen_string_literal: true
2+
13
namespace :node do
2-
task :atoms => [
3-
"//javascript/atoms/fragments:is-displayed",
4-
"//javascript/webdriver/atoms:get-attribute",
5-
] do
6-
baseDir = "javascript/node/selenium-webdriver/lib/atoms"
4+
task atoms: %w(
5+
//javascript/atoms/fragments:is-displayed
6+
//javascript/webdriver/atoms:get-attribute
7+
) do
8+
baseDir = 'javascript/node/selenium-webdriver/lib/atoms'
79
mkdir_p baseDir
810

911
[
10-
Rake::Task["//javascript/atoms/fragments:is-displayed"].out,
11-
Rake::Task["//javascript/webdriver/atoms:get-attribute"].out,
12+
Rake::Task['//javascript/atoms/fragments:is-displayed'].out,
13+
Rake::Task['//javascript/webdriver/atoms:get-attribute'].out
1214
].each do |atom|
1315
name = File.basename(atom)
1416

1517
puts "Generating #{atom} as #{name}"
16-
File.open(File.join(baseDir, name), "w") do |f|
18+
File.open(File.join(baseDir, name), 'w') do |f|
1719
f << "// GENERATED CODE - DO NOT EDIT\n"
18-
f << "module.exports = "
20+
f << 'module.exports = '
1921
f << IO.read(atom).strip
2022
f << ";\n"
2123
end
2224
end
2325
end
2426

2527
task :build do
26-
sh "bazel build //javascript/node/selenium-webdriver"
28+
sh 'bazel build //javascript/node/selenium-webdriver'
2729
end
2830

29-
task :'dry-run' => [
30-
"node:build",
31+
task 'dry-run': [
32+
'node:build'
3133
] do
32-
cmd = "bazel run javascript/node/selenium-webdriver:selenium-webdriver.pack"
33-
sh cmd
34+
sh 'bazel run javascript/node/selenium-webdriver:selenium-webdriver.pack'
3435
end
3536

36-
task :deploy => [
37-
"node:build",
37+
task deploy: [
38+
'node:build'
3839
] do
39-
cmd = "bazel run javascript/node/selenium-webdriver:selenium-webdriver.publish"
40-
sh cmd
40+
sh 'bazel run javascript/node/selenium-webdriver:selenium-webdriver.publish'
4141
end
4242

4343
task :docs do
44-
sh "node javascript/node/gendocs.js"
44+
sh 'node javascript/node/gendocs.js'
4545
end
4646
end

0 commit comments

Comments
 (0)