Esempio n. 1
0
    def _java_compile_produces_valid_analysis_file(self, workdir):
        # A bug was introduced where if a java compile was run twice, the second
        # time the global_analysis.valid file would incorrectly be empty.

        pants_run = self.run_pants_with_workdir(
            ["compile", "testprojects/src/java/org/pantsbuild/testproject/unicode/main"], workdir
        )
        self.assert_success(pants_run)

        # Parse the analysis file from the compilation.
        analysis_file = os.path.join(workdir, "compile", "jvm", "java", "analysis", "global_analysis.valid")
        parser = JMakeAnalysisParser()
        analysis = parser.parse_from_path(analysis_file)

        # Ensure we have entries in the analysis file.
        self.assertEquals(len(analysis.pcd_entries), 2)
  def _java_compile_produces_valid_analysis_file(self, workdir):
    # A bug was introduced where if a java compile was run twice, the second
    # time the global_analysis.valid file would incorrectly be empty.

    pants_run = self.run_pants_with_workdir(
      ['goal', 'compile', 'testprojects/src/java/com/pants/testproject/unicode/main'],
      workdir)
    self._assert_run_success(pants_run)

    # Parse the analysis file from the compilation.
    analysis_file = os.path.join(workdir, 'compile', 'jvm', 'java', 'analysis', 'global_analysis.valid')
    parser = JMakeAnalysisParser('not_used')
    analysis = parser.parse_from_path(analysis_file)

    # Ensure we have entries in the analysis file.
    self.assertEquals(len(analysis.pcd_entries), 2)
Esempio n. 3
0
    def _java_compile_produces_valid_analysis_file(self, workdir):
        # A bug was introduced where if a java compile was run twice, the second
        # time the global_analysis.valid file would incorrectly be empty.

        pants_run = self.run_pants_with_workdir([
            'compile',
            'testprojects/src/java/org/pantsbuild/testproject/unicode/main'
        ], workdir)
        self.assert_success(pants_run)

        # Parse the analysis file from the compilation.
        analysis_file = os.path.join(workdir, 'compile', 'jvm', 'java',
                                     'analysis', 'global_analysis.valid')
        parser = JMakeAnalysisParser()
        analysis = parser.parse_from_path(analysis_file)

        # Ensure we have entries in the analysis file.
        self.assertEquals(len(analysis.pcd_entries), 2)
Esempio n. 4
0
 def create_analysis_tools(self):
     return AnalysisTools(self.context,
                          JMakeAnalysisParser(self._classes_dir),
                          JMakeAnalysis)
Esempio n. 5
0
 def create_analysis_tools(self):
     return AnalysisTools(self.context.java_home, self.ivy_cache_dir,
                          JMakeAnalysisParser(self._classes_dir),
                          JMakeAnalysis)
Esempio n. 6
0
 def create_analysis_tools(self):
     return AnalysisTools(self.context.java_home, JMakeAnalysisParser(),
                          JMakeAnalysis)
Esempio n. 7
0
 def parse_analyis(name):
     return JMakeAnalysisParser().parse_from_path(
         get_test_analysis_path(name))
Esempio n. 8
0
    def test_simple(self):
        def get_test_analysis_path(name):
            return os.path.join(os.path.dirname(__file__), 'testdata',
                                'simple', name)

        def get_analysis_text(name):
            with open(get_test_analysis_path(name), 'r') as fp:
                return fp.read()

        def parse_analyis(name):
            return JMakeAnalysisParser().parse_from_path(
                get_test_analysis_path(name))

        def analysis_to_string(analysis):
            buf = StringIO.StringIO()
            analysis.write(buf)
            return buf.getvalue()

        with environment_as(JMAKE_SORTED_ANALYSIS='1'):
            full_analysis = parse_analyis('simple.analysis')

            analysis_splits = full_analysis.split([
                [
                    b'/src/pants/examples/src/java/org/pantsbuild/example/hello/greet/Greeting.java'
                ],
                [
                    b'/src/pants/examples/src/java/org/pantsbuild/example/hello/main/HelloMain.java'
                ],
            ])
            self.assertEquals(len(analysis_splits), 2)

            def compare_split(i):
                expected_filename = 'simple_split{0}.analysis'.format(i)

                # First compare as objects.
                expected_analyis = parse_analyis(expected_filename)
                self.assertTrue(
                    expected_analyis.is_equal_to(analysis_splits[i]))

                # Then compare as text.
                expected = get_analysis_text(expected_filename)
                actual = analysis_to_string(analysis_splits[i])
                self.assertMultiLineEqual(expected, actual)

            compare_split(0)
            compare_split(1)

            # Now merge and check that we get what we started with.
            merged_analysis = JMakeAnalysis.merge(analysis_splits)
            # Check that they compare as objects.
            self.assertTrue(full_analysis.is_equal_to(merged_analysis))
            # Check that they compare as text.
            expected = get_analysis_text('simple.analysis')
            actual = analysis_to_string(merged_analysis)
            self.assertMultiLineEqual(expected, actual)

            # Now check rebasing.
            orig = iter(get_analysis_text('simple.analysis').splitlines(True))
            expected_rebased = get_analysis_text('simple.rebased.analysis')
            buf = StringIO.StringIO()
            JMakeAnalysisParser().rebase(orig, buf, b'/src/pants',
                                         b'$PANTS_HOME')
            rebased = buf.getvalue()
            self.assertMultiLineEqual(expected_rebased, rebased)