示例#1
0
    def test_java_compile_produces_different_artifact_depending_on_java_version(
            self, strategy):
        # Ensure that running java compile with java 6 and then java 7
        # produces two different artifacts.

        with temporary_dir() as cache_dir:
            artifact_dir = os.path.join(
                cache_dir, JmakeCompile.stable_name(),
                'testprojects.src.java.org.pantsbuild.testproject.unicode.main.main'
            )
            config = {'cache.compile.java': {'write_to': [cache_dir]}}

            pants_run = self.run_pants([
                'compile.java', '--strategy={}'.format(strategy),
                'testprojects/src/java/org/pantsbuild/testproject/unicode/main'
            ], config)
            self.assert_success(pants_run)

            # One artifact for java 6
            self.assertEqual(len(os.listdir(artifact_dir)), 1)

            # Rerun for java 7
            pants_run = self.run_pants([
                'compile.java', '--target=1.7',
                '--strategy={}'.format(strategy),
                'testprojects/src/java/org/pantsbuild/testproject/unicode/main'
            ], config)
            self.assert_success(pants_run)

            # One artifact for java 6 and one for 7
            self.assertEqual(len(os.listdir(artifact_dir)), 2)
  def test_java_compile_produces_different_artifact_depending_on_java_version(self, strategy):
    # Ensure that running java compile with java 6 and then java 7
    # produces two different artifacts.

    with temporary_dir() as cache_dir:
      artifact_dir = os.path.join(cache_dir, JmakeCompile.stable_name(),
          'testprojects.src.java.org.pantsbuild.testproject.unicode.main.main')
      config = {'cache.compile.java': {'write_to': [cache_dir]}}

      pants_run = self.run_pants(['compile.java',
                                  '--strategy={}'.format(strategy),
                                  'testprojects/src/java/org/pantsbuild/testproject/unicode/main'],
                                 config)
      self.assert_success(pants_run)

      # One artifact for java 6
      self.assertEqual(len(os.listdir(artifact_dir)), 1)

      # Rerun for java 7
      pants_run = self.run_pants(['compile.java',
                                  '--target=1.7',
                                  '--strategy={}'.format(strategy),
                                  'testprojects/src/java/org/pantsbuild/testproject/unicode/main'],
                                 config)
      self.assert_success(pants_run)

      # One artifact for java 6 and one for 7
      self.assertEqual(len(os.listdir(artifact_dir)), 2)
示例#3
0
  def test_leave_one(self):
    """ Ensure that max-old of 1 removes all but one files"""

    with temporary_dir() as cache_dir:
      artifact_dir = os.path.join(cache_dir, JmakeCompile.stable_name(),
          'testprojects.src.java.org.pantsbuild.testproject.unicode.main.main')

      touch(os.path.join(artifact_dir, 'old_cache_test1'))
      touch(os.path.join(artifact_dir, 'old_cache_test2'))
      touch(os.path.join(artifact_dir, 'old_cache_test3'))
      touch(os.path.join(artifact_dir, 'old_cache_test4'))
      touch(os.path.join(artifact_dir, 'old_cache_test5'))

      config = {'cache.compile.java': {'write_to': [cache_dir]}}

      pants_run = self.run_pants(['compile.java',
                                  'testprojects/src/java/org/pantsbuild/testproject/unicode/main',
                                  '--cache-max-entries-per-target=1'],
                                 config=config)
      self.assert_success(pants_run)

      # One artifact for java 6
      self.assertEqual(len(os.listdir(artifact_dir)), 1)

      # Rerun for java 7
      pants_run = self.run_pants(['compile.java',
                                  '--target=1.7',
                                  'testprojects/src/java/org/pantsbuild/testproject/unicode/main',
                                  '--cache-max-entries-per-target=1'],
                                 config)
      self.assert_success(pants_run)

      # One artifact for java 7
      self.assertEqual(len(os.listdir(artifact_dir)), 1)
  def test_nocache(self, strategy):
    with temporary_dir() as cache_dir:
      bad_artifact_dir = os.path.join(cache_dir,
          JmakeCompile.stable_name(),
          'testprojects.src.java.org.pantsbuild.testproject.nocache.nocache')
      good_artifact_dir = os.path.join(cache_dir,
          JmakeCompile.stable_name(),
          'testprojects.src.java.org.pantsbuild.testproject.nocache.cache_me')
      config = {'cache.compile.java': {'write_to': [cache_dir]}}

      pants_run = self.run_pants(['compile.java',
                                  '--strategy={}'.format(strategy),
                                  'testprojects/src/java/org/pantsbuild/testproject/nocache::'],
                                 config)
      self.assert_success(pants_run)

      # The nocache target is labeled with no_cache so it should not be written to the
      # artifact cache.
      self.assertFalse(os.path.exists(bad_artifact_dir))
      # But cache_me should be written.
      self.assertEqual(len(os.listdir(good_artifact_dir)), 1)
示例#5
0
    def test_nocache(self, strategy):
        with temporary_dir() as cache_dir:
            bad_artifact_dir = os.path.join(
                cache_dir, JmakeCompile.stable_name(),
                'testprojects.src.java.org.pantsbuild.testproject.nocache.nocache'
            )
            good_artifact_dir = os.path.join(
                cache_dir, JmakeCompile.stable_name(),
                'testprojects.src.java.org.pantsbuild.testproject.nocache.cache_me'
            )
            config = {'cache.compile.java': {'write_to': [cache_dir]}}

            pants_run = self.run_pants([
                'compile.java', '--strategy={}'.format(strategy),
                'testprojects/src/java/org/pantsbuild/testproject/nocache::'
            ], config)
            self.assert_success(pants_run)

            # The nocache target is labeled with no_cache so it should not be written to the
            # artifact cache.
            self.assertFalse(os.path.exists(bad_artifact_dir))
            # But cache_me should be written.
            self.assertEqual(len(os.listdir(good_artifact_dir)), 1)
示例#6
0
    def test_java_compile_reads_resource_mapping(self, strategy):
        # Ensure that if an annotation processor produces a resource-mapping,
        # the artifact contains that resource mapping.

        with temporary_dir() as cache_dir:
            artifact_dir = os.path.join(
                cache_dir, JmakeCompile.stable_name(),
                'testprojects.src.java.org.pantsbuild.testproject.annotation.main.main'
            )
            config = {'cache.compile.java': {'write_to': [cache_dir]}}

            pants_run = self.run_pants([
                'compile.java', '--strategy={}'.format(strategy),
                'compile.apt', '--strategy={}'.format(strategy),
                'testprojects/src/java/org/pantsbuild/testproject/annotation/main'
            ], config)
            self.assert_success(pants_run)

            self.assertTrue(os.path.exists(artifact_dir))
            artifacts = os.listdir(artifact_dir)
            self.assertEqual(len(artifacts), 1)

            with temporary_dir() as extract_dir:
                TarArchiver.extract(os.path.join(artifact_dir, artifacts[0]),
                                    extract_dir)
                all_files = set()
                for dirpath, dirs, files in safe_walk(extract_dir):
                    for name in files:
                        path = os.path.join(dirpath, name)
                        all_files.add(path)

                # Locate the report file on the classpath.
                report_file_name = 'deprecation_report.txt'
                reports = [
                    f for f in all_files if f.endswith(report_file_name)
                ]
                self.assertEquals(
                    1, len(reports),
                    'Expected exactly one {} file; got: {}'.format(
                        report_file_name, all_files))

                with open(reports[0]) as fp:
                    annotated_classes = [
                        line.rstrip() for line in fp.read().splitlines()
                    ]
                    self.assertEquals(
                        {
                            'org.pantsbuild.testproject.annotation.main.Main',
                            'org.pantsbuild.testproject.annotation.main.Main$TestInnerClass'
                        }, set(annotated_classes))
示例#7
0
    def test_leave_none(self):
        """ Ensure that max-old of zero removes all files

    This test should ensure that conditional doesn't change to the simpler test of if max_old since
    we need to handle zero as well.
    """

        with temporary_dir() as cache_dir:
            artifact_dir = os.path.join(
                cache_dir, JmakeCompile.stable_name(),
                'testprojects.src.java.org.pantsbuild.testproject.unicode.main.main'
            )

            touch(os.path.join(artifact_dir, 'old_cache_test1'))
            touch(os.path.join(artifact_dir, 'old_cache_test2'))
            touch(os.path.join(artifact_dir, 'old_cache_test3'))
            touch(os.path.join(artifact_dir, 'old_cache_test4'))
            touch(os.path.join(artifact_dir, 'old_cache_test5'))

            config = {'cache.compile.java': {'write_to': [cache_dir]}}

            pants_run = self.run_pants(self.create_platform_args(6) + [
                'compile.java',
                'testprojects/src/java/org/pantsbuild/testproject/unicode/main',
                '--cache-max-entries-per-target=0'
            ],
                                       config=config)
            self.assert_success(pants_run)

            # Cache cleanup disabled for 0

            self.assertEqual(len(os.listdir(artifact_dir)), 6)

            # Rerun for java 7
            pants_run = self.run_pants(
                self.create_platform_args(7) + [
                    'compile.java',
                    'testprojects/src/java/org/pantsbuild/testproject/unicode/main',
                    '--cache-max-entries-per-target=0'
                ], config)
            self.assert_success(pants_run)

            # Cache cleanup disabled for 0
            self.assertEqual(len(os.listdir(artifact_dir)), 7)
  def test_java_compile_reads_resource_mapping(self, strategy):
    # Ensure that if an annotation processor produces a resource-mapping,
    # the artifact contains that resource mapping.

    with temporary_dir() as cache_dir:
      artifact_dir = os.path.join(cache_dir,
          JmakeCompile.stable_name(),
          'testprojects.src.java.org.pantsbuild.testproject.annotation.main.main')
      config = {'cache.compile.java': {'write_to': [cache_dir]}}

      pants_run = self.run_pants(['compile.java',
                                  '--strategy={}'.format(strategy),
                                  'compile.apt',
                                  '--strategy={}'.format(strategy),
                                  'testprojects/src/java/org/pantsbuild/testproject/annotation/main'],
                                 config)
      self.assert_success(pants_run)

      self.assertTrue(os.path.exists(artifact_dir))
      artifacts = os.listdir(artifact_dir)
      self.assertEqual(len(artifacts), 1)

      with temporary_dir() as extract_dir:
        TarArchiver.extract(os.path.join(artifact_dir, artifacts[0]), extract_dir)
        all_files = set()
        for dirpath, dirs, files in safe_walk(extract_dir):
          for name in files:
            path = os.path.join(dirpath, name)
            all_files.add(path)

        # Locate the report file on the classpath.
        report_file_name = 'deprecation_report.txt'
        reports = [f for f in all_files if f.endswith(report_file_name)]
        self.assertEquals(1, len(reports),
                          'Expected exactly one {} file; got: {}'.format(report_file_name,
                                                                         all_files))

        with open(reports[0]) as fp:
          annotated_classes = [line.rstrip() for line in fp.read().splitlines()]
          self.assertEquals(
            {'org.pantsbuild.testproject.annotation.main.Main',
             'org.pantsbuild.testproject.annotation.main.Main$TestInnerClass'},
            set(annotated_classes))
示例#9
0
  def test_leave_none(self):
    """ Ensure that max-old of zero removes all files

    This test should ensure that conditional doesn't change to the simpler test of if max_old since
    we need to handle zero as well.
    """

    with temporary_dir() as cache_dir:
      artifact_dir = os.path.join(cache_dir, JmakeCompile.stable_name(),
          'testprojects.src.java.org.pantsbuild.testproject.unicode.main.main')

      touch(os.path.join(artifact_dir, 'old_cache_test1'))
      touch(os.path.join(artifact_dir, 'old_cache_test2'))
      touch(os.path.join(artifact_dir, 'old_cache_test3'))
      touch(os.path.join(artifact_dir, 'old_cache_test4'))
      touch(os.path.join(artifact_dir, 'old_cache_test5'))

      config = {'cache.compile.java': {'write_to': [cache_dir]}}

      pants_run = self.run_pants(self.create_platform_args(6) +
                                 ['compile.java',
                                  'testprojects/src/java/org/pantsbuild/testproject/unicode/main',
                                  '--cache-max-entries-per-target=0'],
                                 config=config)
      self.assert_success(pants_run)

      # Cache cleanup disabled for 0

      self.assertEqual(len(os.listdir(artifact_dir)), 6)

      # Rerun for java 7
      pants_run = self.run_pants(self.create_platform_args(7) +
                                 ['compile.java',
                                  'testprojects/src/java/org/pantsbuild/testproject/unicode/main',
                                  '--cache-max-entries-per-target=0'],
                                 config)
      self.assert_success(pants_run)

      # Cache cleanup disabled for 0
      self.assertEqual(len(os.listdir(artifact_dir)), 7)