Skip to content

Commit

Permalink
RuboCop autofixes on rakelib
Browse files Browse the repository at this point in the history
Also includes minor tweaks and restructures of the rakelib directory rakes
  • Loading branch information
luke-hill authored and p0deje committed Sep 29, 2019
1 parent 18efc72 commit 820df9d
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 160 deletions.
60 changes: 21 additions & 39 deletions rakelib/bazel.rake
Original file line number Diff line number Diff line change
@@ -1,53 +1,35 @@
require 'pp'
require 'open3'
require "rake/task"
require 'rake/task'
require 'rakelib/bazel/task'
require 'rakelib/rake/dsl'

module Bazel
def self.execute(kind, args, target, &block)
verbose = Rake::FileUtilsExt.verbose_flag
outs = []

cmd = %w(bazel) + [kind, target] + (args || [])
cmd_out = ""
Open3.popen2e(*cmd) do |stdin, stdouts, wait|
Thread.new do
while (line = stdouts.gets)
if line.chomp =~ /\s+(bazel-bin\/.+)/
outs << $1
class << self
def execute(kind, args, target, &block)
verbose = Rake::FileUtilsExt.verbose_flag
outs = []

cmd = %w[bazel] + [kind, target] + (args || [])
cmd_out = ''
Open3.popen2e(*cmd) do |stdin, stdouts, wait|
Thread.new do
while (line = stdouts.gets)
outs << Regexp.last_match(1) if line.chomp =~ %r{\s+(bazel-bin/.+)}
cmd_out << line
STDOUT.print line if verbose
end
cmd_out << line
STDOUT.print line if verbose
end
end

stdin.close
stdin.close

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

block.call(cmd_out) if block
block&.call(cmd_out)

if outs.length
puts "#{target} -> #{outs[0]}"
puts "#{target} -> #{outs[0]}" if outs.length
outs[0] if outs.length
end
outs[0] if outs.length
end
end

class BazelTask < Rake::Task
def needed?
true
end

def invoke(*args, &block)
self.out = Bazel::execute("build", ["--workspace_status_command=\"#{py_exe} scripts/build-info.py\""], name, &block)

block.call(cmd_out) if block
end
end
end

module Rake::DSL
def bazel(*args, &block)
Bazel::BazelTask.define_task(*args, &block)
end
end
13 changes: 13 additions & 0 deletions rakelib/bazel/task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Bazel
class Task < Rake::Task
def needed?
true
end

def invoke(*_args, &block)
self.out = Bazel::execute("build", ["--workspace_status_command=\"#{py_exe} scripts/build-info.py\""], name, &block)

block&.call(cmd_out)
end
end
end
134 changes: 73 additions & 61 deletions rakelib/copyright.rake
Original file line number Diff line number Diff line change
@@ -1,87 +1,99 @@
# frozen_string_literal: true

namespace :copyright do
task :update do
Copyright.Update(
FileList["javascript/**/*.js"].exclude(
"javascript/atoms/test/jquery.min.js",
"javascript/jsunit/**/*.js",
"javascript/node/selenium-webdriver/node_modules/**/*.js",
"javascript/selenium-core/lib/**/*.js",
"javascript/selenium-core/scripts/ui-element.js",
"javascript/selenium-core/scripts/ui-map-sample.js",
"javascript/selenium-core/scripts/user-extensions.js",
"javascript/selenium-core/scripts/xmlextras.js",
"javascript/selenium-core/xpath/**/*.js"))
Copyright.Update(
FileList["py/**/*.py"],
:style => "#")
Copyright.Update(
FileList["rb/**/*.rb"],
:style => "#",
:prefix => ["# frozen_string_literal: true\n", "\n"])
Copyright.Update(
FileList["java/**/*.java"])
Copyright.update(
FileList['javascript/**/*.js'].exclude(
'javascript/atoms/test/jquery.min.js',
'javascript/jsunit/**/*.js',
'javascript/node/selenium-webdriver/node_modules/**/*.js',
'javascript/selenium-core/lib/**/*.js',
'javascript/selenium-core/scripts/ui-element.js',
'javascript/selenium-core/scripts/ui-map-sample.js',
'javascript/selenium-core/scripts/user-extensions.js',
'javascript/selenium-core/scripts/xmlextras.js',
'javascript/selenium-core/xpath/**/*.js'
)
)
Copyright.update(
FileList['py/**/*.py'],
style: '#'
)
Copyright.update(
FileList['rb/**/*.rb'],
style: '#',
prefix: ["# frozen_string_literal: true\n", "\n"]
)
Copyright.update(
FileList['java/**/*.java']
)
end
end

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

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

notice_lines = Copyright::NOTICE.split(/\n/).map{|line|
(style + " " + line).rstrip + "\n"
}
notice_lines = notice.split(/\n/).map do |line|
"#{style} #{line}".rstrip + "\n"
end
notice_lines = Array(prefix) + notice_lines
notice = notice_lines.join("")
notice = notice_lines.join('')

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

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

if index == -1
puts "Adding notice to #{f}"
File.open(f, "w") do |f|
f.write(notice + "\n")
lines.each {|line| f.write(line) }
end
write_update_notice(file, lines, notice)
else
current = lines.shift(index + 1).join("")
current = lines.shift(index + 1).join('')
if current != notice
puts "Updating notice in #{f}"
File.open(f, "w") do |f|
f.write(notice)
lines.each {|line| f.write(line) }
end
write_update_notice(file, lines, notice)
end
end
end
end
module_function :Update

def write_update_notice(file, lines, notice)
puts "Adding notice to #{file}"
File.open(file, 'w') do |f|
f.write(notice + "\n")
lines.each { |line| f.write(line) }
end
end

def notice
<<~eos
Licensed to the Software Freedom Conservancy (SFC) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The SFC licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
eos
end
end
14 changes: 8 additions & 6 deletions rakelib/ide.rake
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# frozen_string_literal: true

namespace :side do
task :atoms => [
"//javascript/atoms/fragments:find-element",
task atoms: [
'//javascript/atoms/fragments:find-element'
] do
# TODO: move directly to IDE's directory once the repositories are merged
baseDir = "build/javascript/atoms"
baseDir = 'build/javascript/atoms'
mkdir_p baseDir

[
Rake::Task["//javascript/atoms/fragments:find-element"].out,
Rake::Task['//javascript/atoms/fragments:find-element'].out
].each do |atom|
name = File.basename(atom)

puts "Generating #{atom} as #{name}"
File.open(File.join(baseDir, name), "w") do |f|
File.open(File.join(baseDir, name), 'w') do |f|
f << "// GENERATED CODE - DO NOT EDIT\n"
f << "module.exports = "
f << 'module.exports = '
f << IO.read(atom).strip
f << ";\n"
end
Expand Down
24 changes: 13 additions & 11 deletions rakelib/jruby.rake
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
# frozen_string_literal: true

require 'open-uri'

jruby_version = "9.2.8.0"
jruby_version = '9.2.8.0'
jruby_gems = {
"inifile" => "3.0.0"
'inifile' => '3.0.0'
}

namespace :jruby do
desc "Update jruby version"
desc 'Update jruby version'
task :update do
jar_name = "jruby-complete-#{jruby_version}.jar"
url = "https://repo1.maven.org/maven2/org/jruby/jruby-complete/#{jruby_version}/#{jar_name}"

Dir.chdir('third_party/jruby') do
puts "Downloading #{jar_name} from #{url}..."
File.open(jar_name, "wb") do |write_file|
open(url, "rb") do |read_file|
File.open(jar_name, 'wb') do |write_file|
open(url, 'rb') do |read_file|
write_file.write(read_file.read)
end
end

puts "Installing gems..."
puts 'Installing gems...'
jruby_gems.each do |gem_name, gem_version|
sh "java", "-jar", jar_name, "-S", "gem", "install", "-i", "./#{gem_name}", gem_name, "-v", gem_version
sh "jar", "uf", jar_name, "-C", gem_name, "."
sh 'java', '-jar', jar_name, '-S', 'gem', 'install', '-i', "./#{gem_name}", gem_name, '-v', gem_version
sh 'jar', 'uf', jar_name, '-C', gem_name, '.'
rm_rf gem_name
end

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

mv jar_name, "jruby-complete.jar"
puts "Done!"
mv jar_name, 'jruby-complete.jar'
puts 'Done!'
end
end
end
38 changes: 19 additions & 19 deletions rakelib/node.rake
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
# frozen_string_literal: true

namespace :node do
task :atoms => [
"//javascript/atoms/fragments:is-displayed",
"//javascript/webdriver/atoms:get-attribute",
] do
baseDir = "javascript/node/selenium-webdriver/lib/atoms"
task atoms: %w(
//javascript/atoms/fragments:is-displayed
//javascript/webdriver/atoms:get-attribute
) do
baseDir = 'javascript/node/selenium-webdriver/lib/atoms'
mkdir_p baseDir

[
Rake::Task["//javascript/atoms/fragments:is-displayed"].out,
Rake::Task["//javascript/webdriver/atoms:get-attribute"].out,
Rake::Task['//javascript/atoms/fragments:is-displayed'].out,
Rake::Task['//javascript/webdriver/atoms:get-attribute'].out
].each do |atom|
name = File.basename(atom)

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

task :build do
sh "bazel build //javascript/node/selenium-webdriver"
sh 'bazel build //javascript/node/selenium-webdriver'
end

task :'dry-run' => [
"node:build",
task 'dry-run': [
'node:build'
] do
cmd = "bazel run javascript/node/selenium-webdriver:selenium-webdriver.pack"
sh cmd
sh 'bazel run javascript/node/selenium-webdriver:selenium-webdriver.pack'
end

task :deploy => [
"node:build",
task deploy: [
'node:build'
] do
cmd = "bazel run javascript/node/selenium-webdriver:selenium-webdriver.publish"
sh cmd
sh 'bazel run javascript/node/selenium-webdriver:selenium-webdriver.publish'
end

task :docs do
sh "node javascript/node/gendocs.js"
sh 'node javascript/node/gendocs.js'
end
end
Loading

0 comments on commit 820df9d

Please sign in to comment.