Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -784,10 +784,16 @@ class JDKDetails {
}

tasks.register("lint") {
// Calls rake's 'lint' task
description = "Lint Ruby source files. Use -PrubySource=file1.rb,file2.rb to specify files"
dependsOn installDevelopmentGems
doLast {
rake(projectDir, buildDir, 'lint:report')
if (project.hasProperty("rubySource")) {
// Split the comma-separated files and pass them as separate arguments
def files = project.property("rubySource").split(",")
rake(projectDir, buildDir, "lint:report", *files)
} else {
rake(projectDir, buildDir, "lint:report")
}
}
}

Expand Down
30 changes: 27 additions & 3 deletions rakelib/artifacts.rake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# specific language governing permissions and limitations
# under the License.

require 'shellwords'

namespace "artifact" do
SNAPSHOT_BUILD = ENV["RELEASE"] != "1"
VERSION_QUALIFIER = ENV["VERSION_QUALIFIER"].to_s.strip.empty? ? nil : ENV["VERSION_QUALIFIER"]
Expand Down Expand Up @@ -127,12 +129,34 @@ namespace "artifact" do
result
end

# execute Kernel#system call,checking the exist status of the executed command and eventually reporting as exception
##
# @override safe_system([env,] command... [,options])
# execute Kernel#system call,checking the exit status of the executed command and eventually reporting as exception
def safe_system(*args)
if !system(*args)
status = $?
command = args.dup # avoid mutating input for reporting
env = command.size > 1 && command.first.kind_of?(Hash) ? command.shift : {}
options = command.size > 1 && command.last.kind_of?(Hash) ? command.pop : {}
fail("unsupported options #{options}") unless options.empty?

# Normalize command to a single string from either a multi-word string
# or an array of individual words
command = command.size > 1 ? Shellwords.join(command.map(&:to_s)) : command.first.to_s

# prepend the environment
env.each do |k,v|
command.prepend("#{Shellwords.escape(k.to_s)}=#{Shellwords.escape(v.to_s)} ")
end

output = `#{command} 2>&1`
status = $?

if !status.success?
puts "Command failed: #{args.inspect}"
puts "Output: #{output}"
raise "Got exit status #{status.exitstatus} attempting to execute #{args.inspect}!"
end

true
end

desc "Generate rpm, deb, tar and zip artifacts"
Expand Down
47 changes: 31 additions & 16 deletions rakelib/lint.rake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

namespace "lint" do
module RuboCLI
def self.run!(*args)
Expand All @@ -25,28 +24,44 @@ namespace "lint" do
end
end

# task that runs lint report
desc "Report all Lint Cops"
task "report" do
RuboCLI.run!("--lint")
desc "Report all Lint Cops. Optional: Specify one or more files"
task :report, [:file] do |t, args|
files = [args[:file], *args.extras].compact

if files.empty?
RuboCLI.run!("--lint")
else
puts "Running lint report on specific files: #{files.join(', ')}"
RuboCLI.run!("--lint", *files)
end
end

# Tasks automatically fixes a Cop passed as a parameter (e.g. Lint/DeprecatedClassMethods)
# TODO: Add a way to autocorrect all cops, and not just the one passed as parameter
desc "Automatically fix all instances of a Cop passed as a parameter"
task "correct", [:cop] do |t, args|
# Tasks automatically fixes a Cop passed as a parameter
desc "Automatically fix all instances of a Cop passed as a parameter. Optional: Specify one or more files"
task :correct, [:cop] do |t, args|
if args[:cop].to_s.empty?
puts "No Cop has been provided, aborting..."
exit(0)
else
puts "Attempting to correct Lint issues for: #{args[:cop].to_s}"
RuboCLI.run!("--autocorrect-all", "--only", args[:cop].to_s)
files = args.extras
if files.empty?
puts "Attempting to correct Lint issues for: #{args[:cop]}"
RuboCLI.run!("--autocorrect-all", "--only", args[:cop])
else
puts "Attempting to correct Lint issues for #{args[:cop]} in files: #{files.join(', ')}"
RuboCLI.run!("--autocorrect-all", "--only", args[:cop], *files)
end
end
end

# task that automatically fixes code formatting
desc "Automatically fix Layout Cops"
task "format" do
RuboCLI.run!("--fix-layout")
desc "Automatically fix Layout Cops. Optional: Specify one or more files"
task :format, [:file] do |t, args|
files = [args[:file], *args.extras].compact
if files.empty?
RuboCLI.run!("--fix-layout")
else
puts "Running format fixes on specific files: #{files.join(', ')}"
RuboCLI.run!("--fix-layout", *files)
end
end
end
end
19 changes: 13 additions & 6 deletions rubyUtils.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,24 @@ void buildGem(File projectDir, File buildDir, String gemspec) {
* @param projectDir Gradle projectDir
* @param buildDir Gradle buildDir
* @param plugin Plugin to run specs for
* @param args CLI arguments to pass to rspec
* @param args Optional arguments to pass to the rake task
*/
void rake(File projectDir, File buildDir, String task) {
void rake(File projectDir, File buildDir, String task, String... args) {
executeJruby projectDir, buildDir, { ScriptingContainer jruby ->
jruby.currentDirectory = projectDir
jruby.runScriptlet("require 'rake'; require 'time'")
def rakeArgs = args ? "'${args.join("','")}'" : ""
jruby.runScriptlet("""
rake = Rake.application
rake.init
rake.load_rakefile
rake['${task}'].invoke
begin
rake = Rake.application
rake.init
rake.load_rakefile
rake['${task}'].invoke(${rakeArgs})
rescue => e
puts "Rake task error: #{e.class}: #{e.message}"
puts "Backtrace: #{e.backtrace.join("\\n")}"
raise e
end
"""
)
}
Expand Down