def try_bundle()

in source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/java/bundling.py [0:0]


    def try_bundle(self, output_dir: str, options: BundlingOptions) -> bool:
        source = Path(self.to_bundle).absolute()

        is_gradle_build = (source / "gradlew").exists()
        if not is_gradle_build:
            raise UnsupportedBuildEnvironment("please use a gradle project")

        # Run Tests
        if self.gradle_test:
            self._invoke_local_command(
                name="gradle",
                command=["./gradlew", self.gradle_test],
                cwd=source,
            )

        # Run Build
        self._invoke_local_command(
            name="gradle",
            command=["./gradlew", self.gradle_task],
            cwd=source,
        )

        # if the distribution path is a path - it should only contain one jar or zip
        if self.distribution_path.is_dir():
            children = [child for child in self.distribution_path.iterdir()]
            if len(children) != 1:
                raise ValueError(
                    "if the distribution path is a path it should only contain one jar or zip file"
                )
            if children[0].suffix not in (".jar", ".zip"):
                raise ValueError(
                    "the distribution path does not include a single .jar or .zip file"
                )
            copytree(self.distribution_path, output_dir)
        elif self.distribution_path.is_file():
            suffix = self.distribution_path.suffix
            if suffix not in (".jar", ".zip"):
                raise ValueError("the distribution file is not a .zip or .jar file")
            shutil.copy(self.distribution_path, output_dir)

        return True