diff --git a/build.gradle b/build.gradle index b9f843a9b16..f71190ee653 100644 --- a/build.gradle +++ b/build.gradle @@ -817,10 +817,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") + } } } diff --git a/rakelib/lint.rake b/rakelib/lint.rake index c3aa4df45f0..f8d5eea0845 100644 --- a/rakelib/lint.rake +++ b/rakelib/lint.rake @@ -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) @@ -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 \ No newline at end of file diff --git a/rubyUtils.gradle b/rubyUtils.gradle index 94d020543c2..c515ee2df6b 100644 --- a/rubyUtils.gradle +++ b/rubyUtils.gradle @@ -151,17 +151,18 @@ 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 + rake['${task}'].invoke(${rakeArgs}) """ ) }