def checkstyle(self, sources, targets): egroups = self.context.products.get_data('exclusives_groups') etag = egroups.get_group_key_for_target(targets[0]) classpath = self._jvm_tool_bootstrapper.get_jvm_tool_classpath(self._checkstyle_bootstrap_key) cp = egroups.get_classpath_for_group(etag) classpath.extend(jar for conf, jar in cp if conf in self._confs) args = [ '-c', self._configuration_file, '-f', 'plain' ] if self._properties: properties_file = os.path.join(self._work_dir, 'checkstyle.properties') with safe_open(properties_file, 'w') as pf: for k, v in self._properties.items(): pf.write('%s=%s\n' % (k, v)) args.extend(['-p', properties_file]) # We've hit known cases of checkstyle command lines being too long for the system so we guard # with Xargs since checkstyle does not accept, for example, @argfile style arguments. def call(xargs): return self.runjava(classpath=classpath, main=CHECKSTYLE_MAIN, args=args + xargs, workunit_name='checkstyle') checks = Xargs(call) return checks.execute(sources)
class XargsTest(mox.MoxTestBase): def setUp(self): super(XargsTest, self).setUp() self.call = self.mox.CreateMockAnything() self.xargs = Xargs(self.call) def test_execute_nosplit_success(self): self.call(['one', 'two', 'three', 'four']).AndReturn(0) self.mox.ReplayAll() self.assertEqual(0, self.xargs.execute(['one', 'two', 'three', 'four'])) def test_execute_nosplit_raise(self): exception = Exception() self.call(['one', 'two', 'three', 'four']).AndRaise(exception) self.mox.ReplayAll() with pytest.raises(Exception) as raised: self.xargs.execute(['one', 'two', 'three', 'four']) self.assertTrue(exception is raised.value) def test_execute_nosplit_fail(self): self.call(['one', 'two', 'three', 'four']).AndReturn(42) self.mox.ReplayAll() self.assertEqual(42, self.xargs.execute(['one', 'two', 'three', 'four'])) TOO_BIG = OSError(errno.E2BIG, os.strerror(errno.E2BIG)) def test_execute_split(self): self.call(['one', 'two', 'three', 'four']).AndRaise(self.TOO_BIG) self.call(['one', 'two']).AndReturn(0) self.call(['three', 'four']).AndReturn(0) self.mox.ReplayAll() self.assertEqual(0, self.xargs.execute(['one', 'two', 'three', 'four'])) def test_execute_uneven(self): self.call(['one', 'two', 'three']).AndRaise(self.TOO_BIG) # TODO(John Sirois): We really don't care if the 1st call gets 1 argument or 2, we just # care that all arguments get passed just once via exactly 2 rounds of call - consider making # this test less brittle to changes in the chunking logic. self.call(['one']).AndReturn(0) self.call(['two', 'three']).AndReturn(0) self.mox.ReplayAll() self.assertEqual(0, self.xargs.execute(['one', 'two', 'three'])) def test_execute_split_multirecurse(self): self.call(['one', 'two', 'three', 'four']).AndRaise(self.TOO_BIG) self.call(['one', 'two']).AndRaise(self.TOO_BIG) self.call(['one']).AndReturn(0) self.call(['two']).AndReturn(0) self.call(['three', 'four']).AndReturn(0) self.mox.ReplayAll() self.assertEqual(0, self.xargs.execute(['one', 'two', 'three', 'four'])) def test_execute_split_fail_fast(self): self.call(['one', 'two', 'three', 'four']).AndRaise(self.TOO_BIG) self.call(['one', 'two']).AndReturn(42) self.mox.ReplayAll() self.assertEqual(42, self.xargs.execute(['one', 'two', 'three', 'four'])) def test_execute_split_fail_slow(self): self.call(['one', 'two', 'three', 'four']).AndRaise(self.TOO_BIG) self.call(['one', 'two']).AndReturn(0) self.call(['three', 'four']).AndReturn(42) self.mox.ReplayAll() self.assertEqual(42, self.xargs.execute(['one', 'two', 'three', 'four']))