예제 #1
0
    def test_artifact_with_changes_since_last_release__modified_file(self):
        package = "pack1/pack2"
        repo_root_path = self._setup_repo_with_package(package)
        self._touch_file_at_path(repo_root_path, package, "", "Blah.java")
        self._commit(repo_root_path)
        current_artifact_hash = git.get_dir_hash(repo_root_path, [package],
                                                 exclusions.src_exclusions())
        art_def = buildpom.MavenArtifactDef(
            "g1",
            "a1",
            "1.1.0",
            released_version="1.2.0",
            bazel_package=package,
            released_artifact_hash=current_artifact_hash)
        # modify an existing file:
        self._touch_file_at_path(repo_root_path, package, "", "Blah.java")
        self._commit(repo_root_path)

        art_def = artifactprocessor.augment_artifact_def(
            repo_root_path, art_def, exclusions.src_exclusions())

        self.assertNotEqual(None, art_def.requires_release)
        self.assertTrue(art_def.requires_release,
                        "Expected artifact to require release")
        self.assertIs(releasereason.ReleaseReason.ARTIFACT,
                      art_def.release_reason)
예제 #2
0
    def test_parse_src_dep_with_changes_since_last_release(self):
        """
        Verifies that a source dependency label is correctly parsed into a 
        Dependency instance.

        The source dependency has a BUILD.pom.released file that indicates
        that changes have been made since the last release; therefore
        the dependency instance should point to the monorepo source artifact.
        """
        version = "1.2.3"
        released_version = "1.2.0"
        package_name = "package1"
        group_id = "group1"
        artifact_id = "art1"
        repo_root = tempfile.mkdtemp("monorepo")
        self._touch_file_at_path(repo_root, "", "MVN-INF", "LIBRARY.root")
        self._write_build_pom(repo_root, package_name, artifact_id, group_id, version)
        self._setup_repo(repo_root)
        package_hash = git.get_dir_hash(repo_root, [package_name], exclusions.src_exclusions())
        self._write_build_pom_released(repo_root, package_name, released_version, package_hash)
        self._touch_file_at_path(repo_root, package_name, "", "myfile")
        self._commit(repo_root)
        ws = workspace.Workspace(repo_root, [], exclusions.src_exclusions(),
                                 maveninstallinfo.NOOP,
                                 pom_content=pomcontent.NOOP)

        deps = ws.parse_dep_labels(["//%s" % package_name])

        self.assertEqual(1, len(deps))
        self.assertEqual(group_id, deps[0].group_id)
        self.assertEqual(artifact_id, deps[0].artifact_id)
        self.assertFalse(deps[0].external)
        self.assertEqual(version, deps[0].version)
        self.assertEqual(package_name, deps[0].bazel_package)
예제 #3
0
    def test_pom_released_changes_are_ignored(self):
        package = "a/b/c"
        repo_root_path = self._setup_repo_with_package(package)
        self._touch_file_at_path(repo_root_path, package, "MVN-INF",
                                 "pom.xml.released")
        self._touch_file_at_path(repo_root_path, package, "", "some_file")
        self._commit(repo_root_path)
        current_artifact_hash = git.get_dir_hash(repo_root_path, [package],
                                                 exclusions.src_exclusions())
        art_def = buildpom.MavenArtifactDef(
            "g1",
            "a1",
            "1.1.0",
            bazel_package=package,
            released_version="1.2.0",
            released_artifact_hash=current_artifact_hash)
        # update pom.xml.released and commit - that change should be ignored
        self._touch_file_at_path(repo_root_path, package, "MVN-INF",
                                 "pom.xml.released")
        self._commit(repo_root_path)

        art_def = artifactprocessor.augment_artifact_def(
            repo_root_path, art_def, exclusions.src_exclusions())

        self.assertNotEqual(None, art_def.requires_release)
        self.assertFalse(art_def.requires_release)
예제 #4
0
    def test_nested_metadata_file_changes_are_ignored(self):
        """
        lib/a1/src/...
        lib/a1/MVN-INF/...
        lib/a1/a2/src/...
        lib/a1/a2/MVN-INF/...

        Changes to files in lib/a1/a2/MVN-INF should be ignored by
        lib/a1's hash calculation.
        """
        a1_package = "lib/a1"
        a2_package = "lib/a1/a2"
        repo_root_path = self._setup_repo_with_package(a1_package)
        self._touch_file_at_path(repo_root_path, a1_package, "MVN-INF", "BUILD.pom.released")
        self._touch_file_at_path(repo_root_path, a1_package, "", "some_file")

        self._touch_file_at_path(repo_root_path, a2_package, "MVN-INF", "BUILD.pom.released")
        self._touch_file_at_path(repo_root_path, a2_package, "", "some_file")

        self._commit(repo_root_path)

        a1_hash = git.get_dir_hash(repo_root_path, a1_package, exclusions.src_exclusions())
        # modify file under a2 metadata - should be ignored
        self._touch_file_at_path(repo_root_path, a2_package, "MVN-INF", "BUILD.pom.released")
        self._commit(repo_root_path)

        updated_a1_hash = git.get_dir_hash(repo_root_path, a1_package, exclusions.src_exclusions())

        self.assertEqual(a1_hash, updated_a1_hash)
예제 #5
0
    def test_update_BUILD_pom_released__set_artifact_hash_to_current(self):
        pack1 = "somedir/p1"
        pack2 = "somedir/p2"
        repo_root = tempfile.mkdtemp("monorepo")
        pack1_path = os.path.join(repo_root, pack1)
        os.makedirs(os.path.join(pack1_path))
        pack2_path = os.path.join(repo_root, pack2)
        os.makedirs(os.path.join(pack2_path))
        self._write_build_pom_released(pack1_path, "1.0.0", "aaa")
        self._write_build_pom_released(pack2_path, "1.0.0", "bbb")
        self._setup_repo(repo_root)
        self._commit(repo_root)
        self._touch_file_at_path(repo_root, pack1, "blah1")
        self._commit(repo_root)
        pack1_hash = git.get_dir_hash(repo_root, pack1,
                                      exclusions.src_exclusions())
        self._touch_file_at_path(repo_root, pack2, "blah2")
        self._commit(repo_root)
        pack2_hash = git.get_dir_hash(repo_root, pack2,
                                      exclusions.src_exclusions())
        self.assertNotEqual(pack1_hash, pack2_hash)

        buildpomupdate.update_released_artifact(repo_root, [pack1, pack2],
                                                exclusions.src_exclusions(),
                                                use_current_artifact_hash=True)

        with open(os.path.join(pack1_path, "MVN-INF", "BUILD.pom.released"),
                  "r") as f:
            content = f.read()
            self.assertIn('artifact_hash = "%s"' % pack1_hash, content)
        with open(os.path.join(pack2_path, "MVN-INF", "BUILD.pom.released"),
                  "r") as f:
            content = f.read()
            self.assertIn('artifact_hash = "%s"' % pack2_hash, content)
예제 #6
0
    def test_artifact_with_changes_since_last_release__local_edits(self):
        """
        We added uncommitted change detection to improve the local developer
        experience: any artifact that has uncommitted changes should get marked
        as needing to be released.
        """
        package = "pack1/pack2"
        repo_root_path = self._setup_repo_with_package(package)
        current_artifact_hash = git.get_dir_hash(repo_root_path, [package],
                                                 exclusions.src_exclusions())
        art_def = buildpom.MavenArtifactDef(
            "g1",
            "a1",
            "1.1.0",
            released_version="1.2.0",
            bazel_package=package,
            released_artifact_hash=current_artifact_hash)
        # add a new file ...
        self._touch_file_at_path(repo_root_path, package, "", "Foo.java")
        # ... but DON't commit

        art_def = artifactprocessor.augment_artifact_def(
            repo_root_path, art_def, exclusions.src_exclusions())

        self.assertNotEqual(None, art_def.requires_release)
        self.assertTrue(art_def.requires_release,
                        "Expected artifact to require release")
        self.assertIs(releasereason.ReleaseReason.UNCOMMITTED_CHANGES,
                      art_def.release_reason)
예제 #7
0
    def test_additional_change_detected_packages__not_set(self):
        package1 = "path/pack1"  # change detected (by default)
        package2 = "path/pack2"  # ignored
        repo_root_path = self._setup_repo_with_package(package1)
        self._add_package(repo_root_path, package2)
        self._touch_file_at_path(repo_root_path, package1, "", "Blah.java")
        self._touch_file_at_path(repo_root_path, package2, "", "Blah.java")
        self._commit(repo_root_path)
        current_artifact_hash = git.get_dir_hash(repo_root_path, [package1],
                                                 exclusions.src_exclusions())
        art_def = buildpom.MavenArtifactDef(
            "g1",
            "a1",
            "1.1.0",
            released_version="1.2.0",
            bazel_package=package1,
            released_artifact_hash=current_artifact_hash)
        # modify an existing file in package2 - since we are not explicitly
        # detecting changes in it, it shouldn't matter:
        self._touch_file_at_path(repo_root_path, package2, "", "Blah.java")
        self._commit(repo_root_path)

        art_def = artifactprocessor.augment_artifact_def(
            repo_root_path, art_def, exclusions.src_exclusions())

        self.assertNotEqual(None, art_def.requires_release)
        self.assertFalse(art_def.requires_release,
                         "Artifact should not be released")
예제 #8
0
    def test_artifact_without_changes_since_last_release(self):
        repo_root_path = self._setup_repo_with_package("pack1/pack2")
        current_artifact_hash = git.get_dir_hash(repo_root_path, "pack1/pack2", exclusions.src_exclusions())
        art_def = buildpom.MavenArtifactDef("g1", "a1", "1.1.0", bazel_package="pack1/pack2", released_version="1.2.0", released_artifact_hash=current_artifact_hash)
        
        art_def = artifactprocessor.augment_artifact_def(repo_root_path, art_def, exclusions.src_exclusions())

        self.assertNotEqual(None, art_def.requires_release)
        self.assertFalse(art_def.requires_release)
        self.assertEqual(None, art_def.release_reason)
예제 #9
0
    def test_library_root(self):
        repo_root = tempfile.mkdtemp("monorepo")
        art_def_1 = buildpom.MavenArtifactDef("g1", "a1", "1.0.0", bazel_package="lib1/pack1")
        self._touch_file_at_path(repo_root, "lib1", "MVN-INF", "LIBRARY.root")
        art_def_2 = buildpom.MavenArtifactDef("g1", "a2", "1.0.0", bazel_package="foo/lib2/pack1")
        self._touch_file_at_path(repo_root, "foo/lib2", "MVN-INF", "LIBRARY.root")

        art_def_1 = artifactprocessor.augment_artifact_def(repo_root, art_def_1, exclusions.src_exclusions())
        art_def_2 = artifactprocessor.augment_artifact_def(repo_root, art_def_2, exclusions.src_exclusions())

        self.assertEqual("lib1", art_def_1.library_path)
        self.assertEqual("foo/lib2", art_def_2.library_path)
예제 #10
0
    def test_template_var_sub(self):
        """
        Verifies variable substitution in a pom template.
        """
        ws = workspace.Workspace(
            "some/path", """
            native.maven_jar(
                name = "ch_qos_logback_logback_classic",
                artifact = "ch.qos.logback:logback-classic:1.4.4",
            )""", [], exclusions.src_exclusions())
        artifact_def = buildpom.maven_artifact("groupId", "artifactId",
                                               "1.2.3")
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)
        pomgen = pom.TemplatePomGen(ws,
                                    artifact_def,
                                    dep,
                                    template_content="""
            logback_old_syntax #{ch_qos_logback_logback_classic.version}
            logback_new_syntax #{ch.qos.logback:logback-classic:version}
            monorepo artifact version #{version}""")

        generated_pom = pomgen.gen()

        self.assertIn("logback_old_syntax 1.4.4", generated_pom)
        self.assertIn("logback_new_syntax 1.4.4", generated_pom)
        self.assertIn("monorepo artifact version 1.2.3", generated_pom)
예제 #11
0
    def test_dot_gitignore_changes_are_ignored(self):
        src_exclusions = exclusions.src_exclusions(file_names=(".gitignore", ))
        package = "a/b/c"
        repo_root_path = self._setup_repo_with_package(package)
        self._touch_file_at_path(repo_root_path, package, "MVN-INF",
                                 "BUILD.pom")
        self._touch_file_at_path(repo_root_path, package, "f", ".gitignore")
        self._commit(repo_root_path)
        current_artifact_hash = git.get_dir_hash(repo_root_path, [package],
                                                 src_exclusions)
        art_def = buildpom.MavenArtifactDef(
            "g1",
            "a1",
            "1.1.0",
            bazel_package=package,
            released_version="1.2.0",
            released_artifact_hash=current_artifact_hash)
        # update .md file - that change should be ignored
        self._touch_file_at_path(repo_root_path, package, "f", ".gitignore")
        self._commit(repo_root_path)

        art_def = artifactprocessor.augment_artifact_def(
            repo_root_path, art_def, src_exclusions)

        self.assertNotEqual(None, art_def.requires_release)
        self.assertFalse(art_def.requires_release)
예제 #12
0
    def test_template_var_sub__conflicting_gav__ext_and_BUILDpom(self):
        """
        Verifies error handling when gavs are conflicting between external deps
        and what is set in BUILD.pom files.
        """
        ws = workspace.Workspace(
            "some/path", """
            native.maven_jar(
                name = "name",
                artifact = "g:a:20",
            )""", [], exclusions.src_exclusions())
        artifact_def = buildpom.maven_artifact("groupId", "artifactId",
                                               "1.2.3")
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)
        pomgen = pom.TemplatePomGen(ws,
                                    artifact_def,
                                    dep,
                                    template_content="""
            srpc #{g:a:version}""")
        art = buildpom.MavenArtifactDef("g", "a", "1", bazel_package="a/b/c")
        d = dependency.MonorepoDependency(art, bazel_target=None)
        pomgen.register_dependencies_globally(set([d]), set())

        with self.assertRaises(Exception) as ctx:
            pomgen.gen()

        self.assertIn(
            "Found multiple artifacts with the same groupId:artifactId",
            str(ctx.exception))
        self.assertIn("g:a", str(ctx.exception))
예제 #13
0
    def test_normalize_deps__skip_pomgen_mode_allows_refs_to_same_package(
            self):
        ws = workspace.Workspace("so/path", [],
                                 exclusions.src_exclusions(),
                                 maveninstallinfo.NOOP,
                                 pom_content=pomcontent.NOOP)
        package = "a/b/c"
        art1 = buildpom.MavenArtifactDef("g1",
                                         "a1",
                                         "1",
                                         bazel_package=package,
                                         pom_generation_mode=pomgenmode.SKIP)
        dep1 = dependency.MonorepoDependency(art1, bazel_target=None)
        art2 = buildpom.MavenArtifactDef("g2",
                                         "a2",
                                         "1",
                                         bazel_package=package)
        dep2 = dependency.MonorepoDependency(art2, bazel_target=None)
        art3 = buildpom.MavenArtifactDef("g1",
                                         "a1",
                                         "1",
                                         bazel_package="d/e/f")
        dep3 = dependency.MonorepoDependency(art3, bazel_target=None)
        dep4 = dependency.ThirdPartyDependency("name", "g101", "a101", "1")

        # the result of this method is based on bazel_package comparison
        deps = ws.normalize_deps(art1, [dep1, dep2, dep3, dep4])

        self.assertEqual([dep1, dep2, dep3, dep4], deps)
예제 #14
0
    def test_template_var_sub__ext_deps_with_same_versions(self):
        """
        Ensures that external dependencies (jars) that have the same gav, but
        are defined multiple times in different maven_install rules, can
        be referenced.
        """
        ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(),
                                 self._mocked_mvn_install_info("maven"),
                                 pomcontent.NOOP)
        artifact_def = buildpom.maven_artifact("groupId", "artifactId",
                                               "1.4.4")
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)
        artifact_def.custom_pom_template_content = """
1 v1 #{@maven//:org_apache_maven_same_version.version}
2 v2 #{@maven2//:org_apache_maven_same_version.version}
3 v  #{org_apache_maven_same_version.version}
4 v  #{org.apache.maven:same-version:version}

"""
        pomgen = pom.TemplatePomGen(ws, artifact_def, dep)

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

        self.assertIn("1 v1 1.0.0", generated_pom)
        self.assertIn("2 v2 1.0.0", generated_pom)
        self.assertIn("3 v  1.0.0", generated_pom)
        self.assertIn("4 v  1.0.0", generated_pom)
예제 #15
0
    def test_template_genmode__goldfile(self):
        """
        Verifies version omissions when genmode is GOLDFILE.
        """
        ws = workspace.Workspace(
            "some/path", """
            native.maven_jar(
                name = "ch_qos_logback_logback_classic",
                artifact = "ch.qos.logback:logback-classic:1.4.4",
            )""", [], exclusions.src_exclusions())
        artifact_def = buildpom.maven_artifact("groupId", "artifactId",
                                               "1.2.3")
        srpc_artifact_def = buildpom.maven_artifact("com.grail.srpc",
                                                    "srpc-api", "5.6.7")
        srpc_artifact_def = buildpom._augment_art_def_values(
            srpc_artifact_def, None, "pack1", None, None, pomgenmode.DYNAMIC)
        dep = dependency.new_dep_from_maven_artifact_def(srpc_artifact_def)
        pomgen = pom.TemplatePomGen(ws,
                                    artifact_def,
                                    dep,
                                    template_content="""
            this artifact version #{version}
            logback #{ch.qos.logback:logback-classic:version}
            srpc #{com.grail.srpc:srpc-api:version}""")
        pomgen.register_dependencies_globally(
            set([
                dependency.MonorepoDependency(srpc_artifact_def,
                                              bazel_target=None)
            ]), set())

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

        self.assertIn("this artifact version ***", generated_pom)
        self.assertIn("logback 1.4.4", generated_pom)
        self.assertIn("srpc ***", generated_pom)
예제 #16
0
    def test_template_var_sub__multiple_ext_deps_with_same_ga_diff_vers(self):
        """
        Verifies that pomgen is NOT OK with multiple external deps with the same
        groupId/artifactId but with a different version (as this would break
        the #{<groupId>:<artifactId>:version} syntax).
        """
        ws = workspace.Workspace(
            "some/path", """
            native.maven_jar(
                name = "name1",
                artifact = "g:a:20",
            )

            native.maven_jar(
                name = "name2",
                artifact = "g:a:21",
            )

        """, [], exclusions.src_exclusions())
        artifact_def = buildpom.maven_artifact("groupId", "artifactId",
                                               "1.2.3")
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)
        pomgen = pom.TemplatePomGen(ws,
                                    artifact_def,
                                    dep,
                                    template_content="""
            srpc #{g:a:version}""")

        with self.assertRaises(Exception) as ctx:
            pomgen.gen()

        self.assertIn(
            "Found multiple artifacts with the same groupId:artifactId",
            str(ctx.exception))
        self.assertIn("g:a", str(ctx.exception))
예제 #17
0
    def test_template_var_sub__multiple_ext_deps_with_same_gav(self):
        """
        Verifies that pomgen is ok with multiple external deps with the same
        gav. This is an edge case, where the WORKSPACE file defines 2 (or more)
        differnently named maven_jars, that all point back to the same artifact.
        """
        ws = workspace.Workspace(
            "some/path", """
            native.maven_jar(
                name = "name1",
                artifact = "g:a:20",
            )

            native.maven_jar(
                name = "name2",
                artifact = "g:a:20",
            )

        """, [], exclusions.src_exclusions())
        artifact_def = buildpom.maven_artifact("groupId", "artifactId",
                                               "1.2.3")
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)
        pomgen = pom.TemplatePomGen(ws,
                                    artifact_def,
                                    dep,
                                    template_content="""
            srpc #{g:a:version}""")

        pomgen.gen()
예제 #18
0
    def test_src_dep_without_build_pom(self):
        """
        Verifies we correctly produce an error when a monorepo src ref is 
        missing a BUILD.pom file.
        """
        artifact_version = "1.2.3"
        package_name = "package"
        group_id = "group1"
        artifact_id = "art1"
        repo_root = tempfile.mkdtemp("monorepo")
        self._touch_file_at_path(repo_root, "", "MVN-INF", "LIBRARY.root")
        self._write_build_pom(repo_root, package_name, artifact_id, group_id, artifact_version)
        bad_package_name = "bad_package"
        os.mkdir(os.path.join(repo_root, bad_package_name)) # no BUILD.pom

        ws = workspace.Workspace(repo_root, [], exclusions.src_exclusions(),
                                 maveninstallinfo.NOOP,
                                 pom_content=pomcontent.NOOP)

        with self.assertRaises(Exception) as ctx:
            deps = ws.parse_dep_labels(["//%s" % package_name,
                                        "//%s" % bad_package_name])

        self.assertIn("no BUILD.pom", str(ctx.exception))
        self.assertIn(bad_package_name, str(ctx.exception))
예제 #19
0
    def test_template_var_sub__monorepo_deps(self):
        """
        Verifies references to monorepo versions in a pom template.
        """
        ws = workspace.Workspace("some/path", "", [],
                                 exclusions.src_exclusions())
        artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId",
                                                 "1.2.3")
        srpc_artifact_def = buildpom.MavenArtifactDef("com.grail.srpc",
                                                      "srpc-api", "5.6.7")
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)
        pomgen = pom.TemplatePomGen(ws,
                                    artifact_def,
                                    dep,
                                    template_content="""
            srpc #{com.grail.srpc:srpc-api:version}""")
        pomgen.register_dependencies_globally(
            set([
                dependency.MonorepoDependency(srpc_artifact_def,
                                              bazel_target=None)
            ]), set())

        generated_pom = pomgen.gen()

        self.assertIn("srpc 5.6.7", generated_pom)
예제 #20
0
    def test_parse_src_dep_with_target(self):
        """
        Verifies that a source dependency label is correctly parsed into a 
        Dependency instance, when the source dependency includes a target
        """
        artifact_version = "1.2.3"
        package_name = "package1"
        group_id = "group1"
        artifact_id = "art1"
        repo_root = tempfile.mkdtemp("monorepo")
        self._touch_file_at_path(repo_root, "", "MVN-INF", "LIBRARY.root")
        self._write_build_pom(repo_root, package_name, artifact_id, group_id, artifact_version)
        ws = workspace.Workspace(repo_root, [], exclusions.src_exclusions(),
                                 maveninstallinfo.NOOP,
                                 pom_content=pomcontent.NOOP)

        deps = ws.parse_dep_labels(["//%s:my_cool_target" % package_name])

        self.assertEqual(1, len(deps))
        self.assertEqual(group_id, deps[0].group_id)
        self.assertEqual(artifact_id, deps[0].artifact_id)
        self.assertEqual(artifact_version, deps[0].version)
        self.assertFalse(deps[0].external)
        self.assertEqual(package_name, deps[0].bazel_package)
        self.assertEqual("my_cool_target", deps[0].bazel_target)
예제 #21
0
    def test_depman_pom__sanity(self):
        """
        Ensures that dependency management pom generation isn't totally broken.
        """
        ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(),
                                 maveninstallinfo.NOOP, pomcontent.NOOP)
        artifact_def = buildpom.MavenArtifactDef(
            "g1", "a2", "1.2.3", gen_dependency_management_pom=True)
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)
        pomgen = pom.DependencyManagementPomGen(ws, artifact_def, dep,
                                                TEST_POM_TEMPLATE)
        guava = dependency.new_dep_from_maven_art_str("google:guava:1", "guav")
        force = dependency.new_dep_from_maven_art_str("force:commons:1",
                                                      "forc")

        pomgen.register_dependencies_transitive_closure__artifact((
            guava,
            force,
        ))
        generated_pom = pomgen.gen(pom.PomContentType.RELEASE)

        self.assertIn("<packaging>pom</packaging>", generated_pom)
        self.assertIn("<dependencyManagement>", generated_pom)
        self.assertIn("<artifactId>guava</artifactId>", generated_pom)
        self.assertIn("<artifactId>commons</artifactId>", generated_pom)
예제 #22
0
    def test_one_lib_changed__lib_b__pom_changes_only(self):
        """
        B a2's pom changed since it was last released.
        """
        self._write_file(
            self.repo_root_path, "libs/b/a2", "MVN-INF", "pom.xml.released",
            """<project> <dependencies> ... </dependencies> </project>""")
        self._write_file(self.repo_root_path, "libs/b/a2", "MVN-INF",
                         POM_TEMPLATE_FILE, "<project></project>")
        self._commit(self.repo_root_path)
        released_artifact_hash = git.get_dir_hash(self.repo_root_path,
                                                  ["libs/b/a2"],
                                                  exclusions.src_exclusions())
        self._write_build_pom_released(self.repo_root_path, "libs/b/a2",
                                       "1.0.0", released_artifact_hash)

        result = self.crawler.crawl(["libs/a/a1"])

        self.assertEqual(
            set(["libs/a/a1", "libs/a/a2", "libs/b/a1", "libs/b/a2"]),
            set([p.artifact_def.bazel_package for p in result.pomgens]))
        node_a_a1 = result.nodes[0]
        self.assertIs(node_a_a1.artifact_def.release_reason,
                      rr.ReleaseReason.TRANSITIVE)
        node_b_a1 = node_a_a1.children[0]
        self.assertEqual("libs/b/a1", node_b_a1.artifact_def.bazel_package)
        self.assertIs(node_b_a1.artifact_def.release_reason,
                      rr.ReleaseReason.POM)
예제 #23
0
    def test_template__deps_config_setion_is_removed(self):
        """
        Verifies that the special dependency config section is removed
        from the pom template when it is processed.
        """
        pom_template = """
<project>
    <dependencyManagement>
        <dependencies>
__pomgen.start_dependency_customization__
__pomgen.end_dependency_customization__
        </dependencies>
    </dependencyManagement>
</project>
"""

        expected_pom = """
<project>
    <dependencyManagement>
        <dependencies>
        </dependencies>
    </dependencyManagement>
</project>
"""
        ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(),
                                 maveninstallinfo.NOOP, pomcontent.NOOP)
        artifact_def = buildpom.maven_artifact("groupId", "artifactId",
                                               "1.2.3")
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)
        artifact_def.custom_pom_template_content = pom_template
        pomgen = pom.TemplatePomGen(ws, artifact_def, dep)

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

        self.assertEqual(expected_pom, generated_pom)
예제 #24
0
    def test_template_genmode__goldfile(self):
        """
        Verifies version omissions when genmode is GOLDFILE.
        """
        ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(),
                                 self._mocked_mvn_install_info("maven"),
                                 pomcontent.NOOP)
        artifact_def = buildpom.maven_artifact("groupId", "artifactId",
                                               "1.2.3")
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)
        srpc_artifact_def = buildpom.maven_artifact("com.grail.srpc",
                                                    "srpc-api", "5.6.7")
        srpc_artifact_def = buildpom._augment_art_def_values(
            srpc_artifact_def, None, "pack1", None, None, pomgenmode.DYNAMIC)
        srpc_dep = dependency.MonorepoDependency(srpc_artifact_def,
                                                 bazel_target=None)
        artifact_def.custom_pom_template_content = """
this artifact version #{version}
logback coord #{ch.qos.logback:logback-classic:version}
logback qualified #{@maven//:ch_qos_logback_logback_classic.version}
logback unqualified #{ch_qos_logback_logback_classic.version}
srpc #{com.grail.srpc:srpc-api:version}
"""
        pomgen = pom.TemplatePomGen(ws, artifact_def, dep)
        pomgen.register_dependencies_transitive_closure__library(
            set([srpc_dep]))
        generated_pom = pomgen.gen(pomcontenttype=pom.PomContentType.GOLDFILE)

        self.assertIn("this artifact version ***", generated_pom)
        self.assertIn("logback coord 1.2.3", generated_pom)
        self.assertIn("logback qualified 1.2.3", generated_pom)
        self.assertIn("logback unqualified 1.2.3", generated_pom)
        self.assertIn("srpc ***", generated_pom)
예제 #25
0
    def test_template_var_sub__conflicting_gav__ext_and_BUILDpom(self):
        """
        Verifies error handling when gavs are conflicting between external deps
        and what is set in BUILD.pom files.
        """
        ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(),
                                 self._mocked_mvn_install_info("maven"),
                                 pomcontent.NOOP)
        artifact_def = buildpom.maven_artifact("groupId", "artifactId",
                                               "1.2.3")
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)
        artifact_def.custom_pom_template_content = "srpc #{g:a:version}"
        pomgen = pom.TemplatePomGen(ws, artifact_def, dep)
        art = buildpom.MavenArtifactDef("com.google.guava",
                                        "guava",
                                        "26.0",
                                        bazel_package="a/b/c")
        d = dependency.MonorepoDependency(art, bazel_target=None)
        pomgen.register_dependencies_transitive_closure__library(set([d]))

        with self.assertRaises(Exception) as ctx:
            pomgen.gen(pom.PomContentType.RELEASE)

        self.assertIn(
            "Found multiple artifacts with the same groupId:artifactId",
            str(ctx.exception))
        self.assertIn("com.google.guava:guava", str(ctx.exception))
예제 #26
0
    def test_template__unencountered_deps(self):
        """
        Verifies that declared deps that are not crawled can be referenced
        using the pomgen.unencountered_deps property.
        """
        pom_template = """
<project>
    <dependencyManagement>
        <dependencies>
__pomgen.start_dependency_customization__
            <dependency>
                <artifactId>art1</artifactId>
                <groupId>group1</groupId>
                <version>1.0.0</version>
                <exclusions>
                    <exclusion>
                        <artifactId>ea1</artifactId>
                        <groupId>eg1</groupId>
                    </exclusion>
                </exclusions>
            </dependency>
__pomgen.end_dependency_customization__
#{pomgen.unencountered_dependencies}
        </dependencies>
    </dependencyManagement>
</project>
"""

        expected_pom = """
<project>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <artifactId>art1</artifactId>
                <groupId>group1</groupId>
                <version>1.0.0</version>
                <exclusions>
                    <exclusion>
                        <artifactId>ea1</artifactId>
                        <groupId>eg1</groupId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>
"""
        ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(),
                                 maveninstallinfo.NOOP, pomcontent.NOOP)
        artifact_def = buildpom.maven_artifact("groupId", "artifactId",
                                               "1.2.3")
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)
        artifact_def.custom_pom_template_content = pom_template
        pomgen = pom.TemplatePomGen(ws, artifact_def, dep)

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

        self.assertEqual(expected_pom, generated_pom)
예제 #27
0
    def test_artifact_def_without_relased_artifact_hash(self):        
        art_def = buildpom.MavenArtifactDef("g1", "a1", "1.0.0", bazel_package="")
        repo_root = tempfile.mkdtemp("monorepo")
        self._touch_file_at_path(repo_root, "", "MVN-INF", "LIBRARY.root")
        self.assertIs(None, art_def.released_artifact_hash)

        art_def = artifactprocessor.augment_artifact_def(repo_root, art_def, exclusions.src_exclusions())

        self.assertTrue(art_def.requires_release)
예제 #28
0
    def test_missing_library_root_file(self):
        repo_root = tempfile.mkdtemp("monorepo")
        art_def_1 = buildpom.MavenArtifactDef("g1", "a1", "1.0.0", bazel_package="lib1/pack1")

        with self.assertRaises(Exception) as ctx:
            artifactprocessor.augment_artifact_def(repo_root, art_def_1, exclusions.src_exclusions())

        self.assertIn("Did not find LIBRARY.root at", str(ctx.exception))
        self.assertIn("or any parent dir", str(ctx.exception))
예제 #29
0
    def test_template__library_transitives(self):
        """
        Verifies that transitive dependencies can be referenced using the
        property pomgen.transitive_closure_of_library_dependencies.
        """
        pom_template = """
<project>
    <dependencyManagement>
        <dependencies>
#{pomgen.transitive_closure_of_library_dependencies}
        </dependencies>
    </dependencyManagement>
</project>
"""

        expected_pom = """
<project>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.grail.srpc</groupId>
                <artifactId>srpc-api</artifactId>
                <version>5.6.7</version>
            </dependency>
            <dependency>
                <groupId>cg</groupId>
                <artifactId>ca</artifactId>
                <version>0.0.1</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>
"""
        ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(),
                                 maveninstallinfo.NOOP, pomcontent.NOOP)
        artifact_def = buildpom.maven_artifact("groupId", "artifactId",
                                               "1.2.3")
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)
        artifact_def.custom_pom_template_content = pom_template
        pomgen = pom.TemplatePomGen(ws, artifact_def, dep)
        srpc_artifact_def = buildpom.MavenArtifactDef("com.grail.srpc",
                                                      "srpc-api",
                                                      "5.6.7",
                                                      bazel_package="a/b/c")
        internal_dep = dependency.MonorepoDependency(srpc_artifact_def,
                                                     bazel_target=None)

        external_dep = dependency.ThirdPartyDependency("name", "cg", "ca",
                                                       "0.0.1")
        pomgen.register_dependencies_transitive_closure__library(
            set([external_dep, internal_dep]))

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

        self.assertEqual(expected_pom, generated_pom)
예제 #30
0
    def test_template__crawled_external_deps__configured_attributes(self):
        """
        Verifies that "classifier" and "scope" are correcly set in the generated
        pom.
        """
        pom_template = """
<project>
    <dependencyManagement>
        <dependencies>
__pomgen.start_dependency_customization__
            <dependency>
                <artifactId>ca</artifactId>
                <groupId>cg</groupId>
                <version>0.0.1</version>
                <scope>test</scope>
                <classifier>sources</classifier>
            </dependency>
__pomgen.end_dependency_customization__
#{pomgen.transitive_closure_of_library_dependencies}
        </dependencies>
    </dependencyManagement>
</project>
"""

        expected_pom = """
<project>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>cg</groupId>
                <artifactId>ca</artifactId>
                <version>0.0.1</version>
                <classifier>sources</classifier>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>
"""
        ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(),
                                 maveninstallinfo.NOOP, pomcontent.NOOP)
        artifact_def = buildpom.maven_artifact("groupId", "artifactId",
                                               "1.2.3")
        dep = dependency.new_dep_from_maven_artifact_def(artifact_def)
        artifact_def.custom_pom_template_content = pom_template
        pomgen = pom.TemplatePomGen(ws, artifact_def, dep)
        crawled_dep = dependency.ThirdPartyDependency("name", "cg", "ca",
                                                      "0.0.1")
        pomgen.register_dependencies_transitive_closure__library(
            set([crawled_dep]))

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

        self.assertEqual(expected_pom, generated_pom)