Beispiel #1
0
    def test_dynamic_pom_genmode__goldfile(self):
        """
        Test goldfile mode with dynamic pom gen.
        """
        ws = workspace.Workspace(
            "some/path", """
  native.maven_jar(
    name = "aopalliance_aopalliance",
    artifact = "aopalliance:aopalliance:1.0",
  )
  native.maven_jar(
    name = "com_google_guava_guava",
    artifact = "com.google.guava:guava:20.0",
  )""", [], exclusions.src_exclusions())
        artifact_def = buildpom.maven_artifact("g1", "a2", "1.2.3")
        artifact_def = buildpom._augment_art_def_values(
            artifact_def, None, "pack1", None, None, pomgenmode.DYNAMIC)
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)

        pomgen = pom.DynamicPomGen(ws, artifact_def, dep, TEST_POM_TEMPLATE)

        org_function = bazel.query_java_library_deps_attributes
        try:
            bazel.query_java_library_deps_attributes = lambda r, p: (
                "@com_google_guava_guava//jar",
                "@aopalliance_aopalliance//jar",
            )
            _, _, deps = pomgen.process_dependencies()
            pomgen.register_dependencies(deps)

            generated_pom = pomgen.gen(pom.PomContentType.GOLDFILE)

            self.assertIn(
                """<groupId>g1</groupId>
    <artifactId>a2</artifactId>
    <version>***</version>
    <packaging>jar</packaging>""", generated_pom)

            self.assertIn(
                """<groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>20.0</version>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>""", generated_pom)

            aop_index = generated_pom.index("aopalliance")
            guava_index = generated_pom.index("guava")
            self.assertTrue(guava_index > aop_index)  # deps are sorted
        finally:
            bazel.query_java_library_deps_attributes = org_function
Beispiel #2
0
    def test_dynamic_pom__do_not_include_deps(self):
        """
        Tests the seldomly used "include_deps = False" BUILD.pom attribute.
        """
        ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(),
                                 maveninstallinfo.NOOP, pomcontent.NOOP)
        artifact_def = buildpom.MavenArtifactDef("g1",
                                                 "a2",
                                                 "1.2.3",
                                                 include_deps=False)
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)
        pomgen = pom.DynamicPomGen(ws, artifact_def, dep, "")

        org_function = bazel.query_java_library_deps_attributes
        try:
            bazel.query_java_library_deps_attributes = lambda r, p: 1 / 0  # fails
            pomgen.process_dependencies()
            generated_pom = pomgen.gen(pom.PomContentType.RELEASE)

            self.assertNotIn("dependencies", generated_pom)
        finally:
            bazel.query_java_library_deps_attributes = org_function
Beispiel #3
0
    def test_dyamic_pom__no_dep_management(self):
        """
        If there are not registered transitives, we don't generate
        a dependencyManagement section.
        """
        # we need to overwrite what the default setUp method did to remove all
        # transitives
        f = dependency.new_dep_from_maven_art_str
        query_result = [
            (f("com.google.guava:guava:23.0", "maven"), [], []),
        ]
        orig_bazel_parse_maven_install = bazel.parse_maven_install
        bazel.parse_maven_install = lambda name, path: query_result
        artifact_def = buildpom.maven_artifact("g1", "a2", "1.2.3")
        artifact_def = buildpom._augment_art_def_values(
            artifact_def, None, "pack1", None, None, pomgenmode.DYNAMIC)
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)
        ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(),
                                 self._mocked_mvn_install_info("maven"),
                                 pomcontent.NOOP)
        pomgen = pom.DynamicPomGen(ws, artifact_def, dep, TEST_POM_TEMPLATE)
        org_function = bazel.query_java_library_deps_attributes
        try:
            bazel.query_java_library_deps_attributes = lambda r, p: (
                "@maven//:com_google_guava_guava", )
            _, _, deps = pomgen.process_dependencies()
            pomgen.register_dependencies(deps)

            generated_pom = pomgen.gen(pom.PomContentType.RELEASE)

            self.assertIn(
                """<dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>23.0</version>""", generated_pom)
            self.assertNotIn("<dependencyManagement>", generated_pom)

        finally:
            bazel.query_java_library_deps_attributes = org_function
Beispiel #4
0
    def test_dynamic_pom__remove_description_token_if_no_value(self):
        """
        Tests that the #{description} token is removed if no description value
        is provided.
        """
        exepcted_pom = """<project>
</project>
"""
        pc = pomcontent.PomContent()
        # pc.description IS NOT set here - that's the point of this test
        ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(),
                                 maveninstallinfo.NOOP, pc)
        pom_template = """<project>
#{description}
</project>
"""
        artifact_def = buildpom.maven_artifact("g1", "a2", "1.2.3")
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)
        pomgen = pom.DynamicPomGen(ws, artifact_def, dep, pom_template)

        generated_pom = pomgen.gen(pom.PomContentType.RELEASE)

        self.assertEqual(exepcted_pom, generated_pom)
Beispiel #5
0
    def test_dynamic_pom__gen_description(self):
        """
        Tests that the <description> element is correctly added, if requested.
        """
        exepcted_pom = """<project>
    <description>
        this is a cool description
    </description>

</project>
"""
        pc = pomcontent.PomContent()
        pc.description = "this is a cool description"
        ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(),
                                 maveninstallinfo.NOOP, pc)
        pom_template = """<project>
#{description}
</project>
"""
        artifact_def = buildpom.maven_artifact("g1", "a2", "1.2.3")
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)
        pomgen = pom.DynamicPomGen(ws, artifact_def, dep, pom_template)
        generated_pom = pomgen.gen(pom.PomContentType.RELEASE)
        self.assertEqual(exepcted_pom, generated_pom)
Beispiel #6
0
    def test_dynamic_pom__sanity(self):
        """
        Ensures that dynamic pom generation isn't totally broken.
        """
        ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(),
                                 self._mocked_mvn_install_info("maven"),
                                 pomcontent.NOOP)
        artifact_def = buildpom.maven_artifact("g1", "a2", "1.2.3")
        artifact_def = buildpom._augment_art_def_values(
            artifact_def, None, "pack1", None, None, pomgenmode.DYNAMIC)
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)
        pomgen = pom.DynamicPomGen(ws, artifact_def, dep, TEST_POM_TEMPLATE)

        org_function = bazel.query_java_library_deps_attributes
        try:
            bazel.query_java_library_deps_attributes = lambda r, p: (
                "@maven//:com_google_guava_guava",
                "@maven//:aopalliance_aopalliance",
                "@maven//:ch_qos_logback_logback_classic", "@maven//:gt2_t2")
            _, _, deps = pomgen.process_dependencies()
            pomgen.register_dependencies(deps)
            generated_pom = pomgen.gen(pom.PomContentType.RELEASE)

            self.assertIn(
                """<groupId>g1</groupId>
    <artifactId>a2</artifactId>
    <version>1.2.3</version>
    <packaging>jar</packaging>""", generated_pom)

            self.assertIn(
                """<groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>23.0</version>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>""", generated_pom)

            self.assertIn(
                """<groupId>aopalliance</groupId>
            <artifactId>aopalliance</artifactId>
            <version>1.0.0</version>
            <exclusions>
                <exclusion>
                    <groupId>ge1</groupId>
                    <artifactId>e1</artifactId>
                </exclusion>
            </exclusions>""", generated_pom)

            self.assertIn(
                """<dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
        </dependency>""", generated_pom)

            self.assertIn(
                """    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>gt1</groupId>
                <artifactId>t1</artifactId>
                <version>1.0.0</version>
            </dependency>""", generated_pom)

            # deps are BUILD file order
            aop_index = generated_pom.index(
                "<artifactId>aopalliance</artifactId>")
            guava_index = generated_pom.index("<artifactId>guava</artifactId>")
            self.assertTrue(guava_index < aop_index)

            # gt2:t2 is a transitive to guava, but because it is also
            # referenced explicitly, it is excluded from <dependencyManagement>
            depman_index = generated_pom.index("<dependencyManagement>")
            t2_index = generated_pom.index("<artifactId>t2</artifactId>")
            self.assertTrue(t2_index < depman_index)  # t2 is not managed
            self.assertEqual(
                1, generated_pom.count("<artifactId>t2</artifactId>"))
        finally:
            bazel.query_java_library_deps_attributes = org_function