예제 #1
0
  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)
예제 #2
0
    def execute(self, targets):
        if self.context.options.scalastyle_skip:
            self.context.log.debug('Skipping checkstyle.')
            return

        check_targets = list()
        for target in targets:
            for tgt in target.resolve():
                if isinstance(tgt, Target) and tgt.has_sources('.scala'):
                    check_targets.append(tgt)

        def filter_excludes(filename):
            if self._excludes:
                for exclude in self._excludes:
                    if exclude.match(filename):
                        return False
            return True

        scala_sources = list()
        for target in check_targets:

            def collect(filename):
                if filename.endswith('.scala'):
                    scala_sources.append(
                        os.path.join(target.target_base, filename))

            map(collect, filter(filter_excludes, target.sources))

        if scala_sources:

            def call(srcs):
                cp = self._jvm_tool_bootstrapper.get_jvm_tool_classpath(
                    self._scalastyle_bootstrap_key)
                return self.runjava(classpath=cp,
                                    main=Scalastyle._MAIN,
                                    args=['-c', self._scalastyle_config] +
                                    srcs)

            result = Xargs(call).execute(scala_sources)
            if result != 0:
                raise TaskError('java %s ... exited non-zero (%i)' %
                                (Scalastyle._MAIN, result))
예제 #3
0
 def setUp(self):
   super(XargsTest, self).setUp()
   self.call = self.mox.CreateMockAnything()
   self.xargs = Xargs(self.call)
예제 #4
0
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']))