|  | 
| 1 | 1 | # Copyright (c) 2022 - 2025, Oracle and/or its affiliates. All rights reserved. | 
| 2 |  | -# Copyright (c) 2022 - 2025, Oracle and/or its affiliates. All rights reserved. | 
| 3 | 2 | # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/. | 
| 4 | 3 | 
 | 
| 5 | 4 | """This module contains the Gradle class which inherits BaseBuildTool. | 
| @@ -70,94 +69,6 @@ def is_detected(self, repo_path: str) -> bool: | 
| 70 | 69 |         gradle_config_files = self.build_configs + self.entry_conf | 
| 71 | 70 |         return any(file_exists(repo_path, file) for file in gradle_config_files) | 
| 72 | 71 | 
 | 
| 73 |  | -    def prepare_config_files(self, wrapper_path: str, build_dir: str) -> bool: | 
| 74 |  | -        """Prepare the necessary wrapper files for running the build. | 
| 75 |  | -
 | 
| 76 |  | -        This method will return False if there is any errors happened during operation. | 
| 77 |  | -
 | 
| 78 |  | -        Parameters | 
| 79 |  | -        ---------- | 
| 80 |  | -        wrapper_path : str | 
| 81 |  | -            The path where all necessary wrapper files are located. | 
| 82 |  | -        build_dir : str | 
| 83 |  | -            The path of the build dir. This is where all files are copied to. | 
| 84 |  | -
 | 
| 85 |  | -        Returns | 
| 86 |  | -        ------- | 
| 87 |  | -        bool | 
| 88 |  | -            True if succeed else False. | 
| 89 |  | -        """ | 
| 90 |  | -        # The path of the needed wrapper files | 
| 91 |  | -        wrapper_files = self.wrapper_files | 
| 92 |  | - | 
| 93 |  | -        if copy_file_bulk(wrapper_files, wrapper_path, build_dir): | 
| 94 |  | -            # Ensure that gradlew is executable. | 
| 95 |  | -            file_path = os.path.join(build_dir, "gradlew") | 
| 96 |  | -            status = os.stat(file_path) | 
| 97 |  | -            if oct(status.st_mode)[-3:] != "744": | 
| 98 |  | -                logger.debug("%s does not have 744 permission. Changing it to 744.") | 
| 99 |  | -                os.chmod(file_path, 0o744) | 
| 100 |  | -            return True | 
| 101 |  | - | 
| 102 |  | -        return False | 
| 103 |  | - | 
| 104 |  | -    def get_dep_analyzer(self) -> CycloneDxGradle: | 
| 105 |  | -        """Create a DependencyAnalyzer for the Gradle build tool. | 
| 106 |  | -
 | 
| 107 |  | -        Returns | 
| 108 |  | -        ------- | 
| 109 |  | -        CycloneDxGradle | 
| 110 |  | -            The CycloneDxGradle object. | 
| 111 |  | -
 | 
| 112 |  | -        Raises | 
| 113 |  | -        ------ | 
| 114 |  | -        DependencyAnalyzerError | 
| 115 |  | -        """ | 
| 116 |  | -        if "dependency.resolver" not in defaults or "dep_tool_gradle" not in defaults["dependency.resolver"]: | 
| 117 |  | -            raise DependencyAnalyzerError("No default dependency analyzer is found.") | 
| 118 |  | -        if not DependencyAnalyzer.tool_valid(defaults.get("dependency.resolver", "dep_tool_gradle")): | 
| 119 |  | -            raise DependencyAnalyzerError( | 
| 120 |  | -                f"Dependency analyzer {defaults.get('dependency.resolver', 'dep_tool_gradle')} is not valid.", | 
| 121 |  | -            ) | 
| 122 |  | - | 
| 123 |  | -        tool_name, tool_version = tuple( | 
| 124 |  | -            defaults.get( | 
| 125 |  | -                "dependency.resolver", | 
| 126 |  | -                "dep_tool_gradle", | 
| 127 |  | -                fallback="cyclonedx-gradle:1.7.3", | 
| 128 |  | -            ).split(":") | 
| 129 |  | -        ) | 
| 130 |  | -        if tool_name == DependencyTools.CYCLONEDX_GRADLE: | 
| 131 |  | -            return CycloneDxGradle( | 
| 132 |  | -                resources_path=global_config.resources_path, | 
| 133 |  | -                file_name="bom.json", | 
| 134 |  | -                tool_name=tool_name, | 
| 135 |  | -                tool_version=tool_version, | 
| 136 |  | -            ) | 
| 137 |  | - | 
| 138 |  | -        raise DependencyAnalyzerError(f"Unsupported SBOM generator for Gradle: {tool_name}.") | 
| 139 |  | - | 
| 140 |  | -    def get_gradle_exec(self, repo_path: str) -> str: | 
| 141 |  | -        """Get the Gradle executable for the repo. | 
| 142 |  | -
 | 
| 143 |  | -        Parameters | 
| 144 |  | -        ---------- | 
| 145 |  | -        repo_path: str | 
| 146 |  | -            The absolute path to a repository containing Gradle projects. | 
| 147 |  | -
 | 
| 148 |  | -        Returns | 
| 149 |  | -        ------- | 
| 150 |  | -        str | 
| 151 |  | -            The absolute path to the Gradle executable. | 
| 152 |  | -        """ | 
| 153 |  | -        # We try to use the gradlew that comes with the repository first. | 
| 154 |  | -        repo_gradlew = os.path.join(repo_path, "gradlew") | 
| 155 |  | -        if os.path.isfile(repo_gradlew) and os.access(repo_gradlew, os.X_OK): | 
| 156 |  | -            return repo_gradlew | 
| 157 |  | - | 
| 158 |  | -        # We use Macaron's built-in gradlew as a fallback option. | 
| 159 |  | -        return os.path.join(os.path.join(macaron.MACARON_PATH, "resources"), "gradlew") | 
| 160 |  | - | 
| 161 | 72 |     def get_group_id(self, gradle_exec: str, project_path: str) -> str | None: | 
| 162 | 73 |         """Get the group id of a Gradle project. | 
| 163 | 74 | 
 | 
|  | 
0 commit comments