Beispiel #1
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))
Beispiel #2
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)
Beispiel #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)
Beispiel #4
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)
Beispiel #5
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)
Beispiel #6
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")
Beispiel #7
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)
Beispiel #8
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)
Beispiel #9
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)
Beispiel #10
0
    def parse_maven_artifact_def(self, package):
        """
        Parses the Maven metadata files files in the specified package and 
        returns a MavenArtifactDef instance.

        Returns None if there is no BUILD.pom file at the specified path.
        """
        if package in self._package_to_artifact_def:
            return self._package_to_artifact_def[package]
        art_def = buildpom.parse_maven_artifact_def(self.repo_root_path, package)
        if art_def is not None:
            art_def = artifactprocessor.augment_artifact_def(self.repo_root_path, art_def, self.source_exclusions)
        # cache result, next time it is returned from cache
        self._package_to_artifact_def[package] = art_def
        return art_def
Beispiel #11
0
    def test_artifact_without_changes_always_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,
            change_detection=False)

        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.assertEqual(releasereason.ReleaseReason.ALWAYS,
                         art_def.release_reason)
Beispiel #12
0
    def test_test_changes_are_ignored(self):
        """
        We are assuming the de-facto Maven directory structure standard:
            src/main/... - prod code
            src/test/... - tests
        """
        src_exclusions = exclusions.src_exclusions(relative_paths=("src/test",))
        package = "pack"
        repo_root_path = self._setup_repo_with_package(package)
        self._touch_file_at_path(repo_root_path, package, "MVN-INF", "BUILD.pom.released")
        self._touch_file_at_path(repo_root_path, package, "src/main", "MyClass.java")
        self._touch_file_at_path(repo_root_path, package, "src/test", "MyTest.java")
        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 test class and commit - that change should be ignored
        self._touch_file_at_path(repo_root_path, package, "src/test", "MyTest.java")
        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)