def main()

in AdoptOpenJDK/AdoptOpenJDKURLProvider.py [0:0]


    def main(self):
        """Find the download URL"""
        jvm_type = self.env.get("jvm_type", "hotspot")
        if jvm_type not in ["hotspot", "openj9"]:
            raise ProcessorError("jvm_type can only be 'hotspot' or 'openj9'")
        jdk_type = self.env.get("jdk_type", "jdk")
        if jdk_type not in ["jdk", "jre"]:
            raise ProcessorError("jdk_type can only be 'jdk' or 'jre'")
        binary_type = self.env.get("binary_type", "pkg")
        if binary_type not in ["pkg", "tgz"]:
            raise ProcessorError("jdk_type can only be 'pkg' or 'tgz'")
        release = self.env.get("release", "latest")
        queries = "?os=mac&openjdk_impl={}&type={}&release={}".format(
            jvm_type, jdk_type, release
        )
        # Fetch the API data
        query_suffix = urljoin("openjdk{}".format(self.env["jdk_version"]), queries)
        api_url = urljoin(URL, query_suffix)
        self.output("Query URL: {}".format(api_url))
        api_data = self.download(api_url, text=True)
        api_results = json.loads(api_data)
        # Determine what we're looking for - pkg or tgz
        if binary_type == "pkg":
            checksum_url = api_results["binaries"][0]["installer_checksum_link"]
            url = api_results["binaries"][0]["installer_link"]
        else:
            checksum_url = api_results["binaries"][0]["checksum_link"]
            url = api_results["binaries"][0]["binary_link"]
        # Use semantic versioning for the version string, although historically this
        # hasn't been anything particularly problematic
        version = api_results["binaries"][0]["version_data"]["semver"]
        self.env["version"] = version
        self.output("Version: {}".format(version))
        # Get the checksum from the internet
        checksum = self.get_checksum(checksum_url, binary_type)
        self.env["checksum"] = checksum
        self.output("checksum: {}".format(checksum))
        # Pick the URL
        self.env["url"] = url
        self.output("Found URL {}".format(self.env["url"]))