Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

Commit

Permalink
Add --verbose and --quiet options to compile.scalastyle
Browse files Browse the repository at this point in the history
This adds new `--verbose` and `--quiet` options to the `compile.scalastyle` goal, which get threaded directly to scalastyle, as requested in issue pantsbuild#1888.

Note: `scalastyle` currently accepts but ignores the `--verbose` option (See: scalastyle/scalastyle#159).  However, I include it anyway for when that issue is eventually fixed.

Testing Done:
$ ./pants test tests/python/pants_test/tasks:scalastyle_integration # Newly added integration test passes
    $ ./pants test tests/python/pants_test:all # Unit tests pass

I'm relying on Travis for the remaining integration tests

Bugs closed: 2172

Reviewed at https://rbcommons.com/s/twitter/r/2799/
  • Loading branch information
Gabriella439 authored and jsirois committed Sep 12, 2015
1 parent 1fd2293 commit 5fdf71d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
6 changes: 6 additions & 0 deletions examples/src/scala/org/pantsbuild/example/styleissue/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

scala_library(name = 'styleissue',
sources = ['StyleIssue.scala'],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).

package org.pantsbuild.example.hello.styleissue;

// A program designed to deliberately fail a scalastyle check
class StyleIssue {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<scalastyle>
<check level="error" class="org.scalastyle.file.FileTabChecker" enabled="true" />
</scalastyle>
16 changes: 15 additions & 1 deletion src/python/pants/backend/jvm/tasks/scalastyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def register_options(cls, register):
'(relative to the repo root) matches any of these regexes.')
register('--jvm-options', action='append', metavar='<option>...', advanced=True,
help='Run scalastyle with these extra jvm options.')
register('--verbose', action='store_true', default=False,
help='Enable verbose scalastyle output.')
register('--quiet', action='store_true', default=False,
help='Silence scalastyle error messages.')
cls.register_jvm_tool(register, 'scalastyle')

@classmethod
Expand Down Expand Up @@ -126,6 +130,8 @@ def execute(self):
invalid_targets = [vt.target for vt in invalidation_check.invalid_vts]

scalastyle_config = self.validate_scalastyle_config()
scalastyle_verbose = self.get_options().verbose
scalastyle_quiet = self.get_options().quiet
scalastyle_excluder = self.create_file_excluder()

self.context.log.debug('Non synthetic scala targets to be checked:')
Expand All @@ -139,11 +145,19 @@ def execute(self):

if scala_sources:
def call(srcs):
def to_java_boolean(x):
return str(x).lower()

cp = self.tool_classpath('scalastyle')
scalastyle_args = [
'-c', scalastyle_config,
'-v', to_java_boolean(scalastyle_verbose),
'-q', to_java_boolean(scalastyle_quiet),
]
return self.runjava(classpath=cp,
main=self._MAIN,
jvm_options=self.get_options().jvm_options,
args=['-c', scalastyle_config] + srcs)
args=scalastyle_args + srcs)

result = Xargs(call).execute(scala_sources)
if result != 0:
Expand Down
19 changes: 19 additions & 0 deletions tests/python/pants_test/tasks/test_scalastyle_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,22 @@ def test_scalastyle_cached(self):
# implying there was as a cache hit
self.assertNotIn('abc_Scalastyle_compile_scalastyle will write to local artifact cache',
pants_run.stdout_data)

def test_scalastyle_without_quiet(self):
scalastyle_args = [
'compile.scalastyle',
'--config=examples/src/scala/org/pantsbuild/example/styleissue/style.xml',
'examples/src/scala/org/pantsbuild/example/styleissue',
]
pants_run = self.run_pants(scalastyle_args)
self.assertIn('Found 2 errors', pants_run.stdout_data)

def test_scalastyle_with_quiet(self):
scalastyle_args = [
'compile.scalastyle',
'--config=examples/src/scala/org/pantsbuild/example/styleissue/style.xml',
'--quiet',
'examples/src/scala/org/pantsbuild/example/styleissue',
]
pants_run = self.run_pants(scalastyle_args)
self.assertNotIn('Found 2 errors', pants_run.stdout_data)

0 comments on commit 5fdf71d

Please sign in to comment.