Skip to content

Commit

Permalink
Migrate checkstyle and scalastyle to new-style options.
Browse files Browse the repository at this point in the history
Testing Done:
CI passed.

Reviewed at https://rbcommons.com/s/twitter/r/1231/
  • Loading branch information
Benjy committed Oct 29, 2014
1 parent 14eaac5 commit a02bc85
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
12 changes: 4 additions & 8 deletions src/python/pants/backend/jvm/tasks/checkstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ def _is_checked(target):
return target.is_java and not target.is_synthetic

@classmethod
def setup_parser(cls, option_group, args, mkflag):
super(Checkstyle, cls).setup_parser(option_group, args, mkflag)

option_group.add_option(mkflag("skip"), mkflag("skip", negate=True),
dest="checkstyle_skip", default=False,
action="callback", callback=mkflag.set_bool,
help="[%default] Skip checkstyle.")
def register_options(cls, register):
super(Checkstyle, cls).register_options(register)
register('--skip', action='store_true', legacy='checkstyle_skip', help='Skip checkstyle.')

def __init__(self, *args, **kwargs):
super(Checkstyle, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -61,7 +57,7 @@ def prepare(self, round_manager):
round_manager.require_data('exclusives_groups')

def execute(self):
if self.context.options.checkstyle_skip:
if self.get_options().skip:
return
targets = self.context.targets(self._is_checked)
with self.invalidated(targets) as invalidation_check:
Expand Down
12 changes: 4 additions & 8 deletions src/python/pants/backend/jvm/tasks/scalastyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,9 @@ class Scalastyle(NailgunTask, JvmToolTaskMixin):
_scalastyle_excludes = None

@classmethod
def setup_parser(cls, option_group, args, mkflag):
super(Scalastyle, cls).setup_parser(option_group, args, mkflag)

option_group.add_option(mkflag("skip"), mkflag("skip", negate=True),
dest="scalastyle_skip", default=False,
action="callback", callback=mkflag.set_bool,
help="[%default] Skip scalastyle.")
def register_options(cls, register):
super(Scalastyle, cls).register_options(register)
register('--skip', action='store_true', legacy='scalastyle_skip', help='Skip scalastyle.')

def __init__(self, *args, **kwargs):
super(Scalastyle, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -118,7 +114,7 @@ def _initialize_config(self):

@property
def _should_skip(self):
return self.context.options.scalastyle_skip
return self.get_options().skip

def _get_non_synthetic_scala_targets(self, targets):
return filter(
Expand Down
14 changes: 9 additions & 5 deletions tests/python/pants_test/backend/jvm/tasks/test_scalastyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ def task_type(cls):
#

def _with_skip_option(self):
return dict(scalastyle_skip=True)
return {
self.options_scope: { 'skip': True }
}

def _with_no_skip_option(self):
return dict(scalastyle_skip=False)
return {
self.options_scope: { 'skip': False }
}

def _create_scalastyle_config_file(self, rules=None):
# put a default rule there if rules are not specified.
Expand Down Expand Up @@ -64,14 +68,14 @@ def _create_context(self, config=None, options=None):
config: {config}
excludes:
'''.format(config=self._create_scalastyle_config_file())),
options=options or self._with_no_skip_option())
new_options=options or self._with_no_skip_option())

def _create_scalastyle_task(self, config=None, options=None):
return Scalastyle(self._create_context(config, options), self.build_root)
return self.create_task(self._create_context(config, options), self.build_root)

def _create_scalastyle_task_from_context(self, context=None):
if context:
return Scalastyle(context, self.build_root)
return self.create_task(context, self.build_root)
else:
return self._create_scalastyle_task()

Expand Down
2 changes: 1 addition & 1 deletion tests/python/pants_test/tasks/test_bundle_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def tearDown(self):

def test_bundle_create_init(self):
options = {
'bundle': {
self.options_scope: {
'deployjar': None,
'archive_prefix': None,
'archive': None
Expand Down

0 comments on commit a02bc85

Please sign in to comment.