From 7178919003b0b3e1a508d4b386237f0157ed1672 Mon Sep 17 00:00:00 2001 From: Walid Boussaffa Date: Mon, 7 Jun 2021 15:46:37 +0100 Subject: [PATCH] added recipe for openjdk --- recipes/openjdk/all/conandata.yml | 14 ++++++ recipes/openjdk/all/conanfile.py | 50 +++++++++++++++++++ recipes/openjdk/all/test_package/conanfile.py | 18 +++++++ recipes/openjdk/config.yml | 3 ++ 4 files changed, 85 insertions(+) create mode 100644 recipes/openjdk/all/conandata.yml create mode 100644 recipes/openjdk/all/conanfile.py create mode 100644 recipes/openjdk/all/test_package/conanfile.py create mode 100644 recipes/openjdk/config.yml diff --git a/recipes/openjdk/all/conandata.yml b/recipes/openjdk/all/conandata.yml new file mode 100644 index 00000000000000..5f4858ad937963 --- /dev/null +++ b/recipes/openjdk/all/conandata.yml @@ -0,0 +1,14 @@ +sources: + "16.0.1": + Windows: { + url: "https://download.java.net/java/GA/jdk16.0.1/7147401fd7354114ac51ef3e1328291f/9/GPL/openjdk-16.0.1_windows-x64_bin.zip", + sha256: "733b45b09463c97133d70c2368f1b9505da58e88f2c8a84358dd4accfd06a7a4", + } + Linux: { + url: "https://download.java.net/java/GA/jdk16.0.1/7147401fd7354114ac51ef3e1328291f/9/GPL/openjdk-16.0.1_linux-x64_bin.tar.gz", + sha256: "b1198ffffb7d26a3fdedc0fa599f60a0d12aa60da1714b56c1defbce95d8b235", + } + Macos: { + url: "https://download.java.net/java/GA/jdk16.0.1/7147401fd7354114ac51ef3e1328291f/9/GPL/openjdk-16.0.1_osx-x64_bin.tar.gz", + sha256: "6098f839954439d4916444757c542c1b8778a32461706812d41cc8bbefce7f2f", + } diff --git a/recipes/openjdk/all/conanfile.py b/recipes/openjdk/all/conanfile.py new file mode 100644 index 00000000000000..acc79fbdd0e6cf --- /dev/null +++ b/recipes/openjdk/all/conanfile.py @@ -0,0 +1,50 @@ +from conans import ConanFile, tools +from conans.errors import ConanInvalidConfiguration +import os + + +class OpenJDK(ConanFile): + name = "openjdk" + url = "https://github.com/conan-io/conan-center-index/" + description = "Java Development Kit builds, from Oracle" + homepage = "https://jdk.java.net" + license = "GPL-2.0-with-classpath-exception" + topics = ("java", "jdk", "openjdk") + settings = "os", "arch" + no_copy_source = True + + @property + def _source_subfolder(self): + return "source_subfolder" + + def configure(self): + if self.settings.arch != "x86_64": + raise ConanInvalidConfiguration("Unsupported Architecture. This package currently only supports x86_64.") + if self.settings.os not in ["Windows", "Macos", "Linux"]: + raise ConanInvalidConfiguration("Unsupported os. This package currently only support Linux/Macos/Windows") + + def source(self): + tools.get(**self.conan_data["sources"][self.version][str(self.settings.os)], + destination=self._source_subfolder, strip_root=True) + + def package(self): + if self.settings.os == "Macos": + _source_subfolder = os.path.join(self._source_subfolder, "Contents", "Home") + else: + _source_subfolder = self._source_subfolder + self.copy(pattern="*", dst="bin", src=os.path.join(_source_subfolder, "bin")) + self.copy(pattern="*", dst="include", src=os.path.join(_source_subfolder, "include")) + self.copy(pattern="*", dst="lib", src=os.path.join(_source_subfolder, "lib")) + self.copy(pattern="*", dst=os.path.join("lib", "jmods"), src=os.path.join(_source_subfolder, "jmods")) + self.copy(pattern="*", dst="licenses", src=os.path.join(_source_subfolder, "legal")) + # conf folder is required for security settings, to avoid + # java.lang.SecurityException: Can't read cryptographic policy directory: unlimited + # https://github.com/conan-io/conan-center-index/pull/4491#issuecomment-774555069 + self.copy(pattern="*", dst="conf", src=os.path.join(_source_subfolder, "conf")) + + def package_info(self): + self.output.info("Creating JAVA_HOME environment variable with : {0}".format(self.package_folder)) + self.env_info.JAVA_HOME = self.package_folder + + self.output.info("Appending PATH environment variable with : {0}".format(os.path.join(self.package_folder, "bin"))) + self.env_info.PATH.append(os.path.join(self.package_folder, "bin")) diff --git a/recipes/openjdk/all/test_package/conanfile.py b/recipes/openjdk/all/test_package/conanfile.py new file mode 100644 index 00000000000000..089b50f57fafc9 --- /dev/null +++ b/recipes/openjdk/all/test_package/conanfile.py @@ -0,0 +1,18 @@ +from conans import ConanFile +from six import StringIO + + +class TestPackage(ConanFile): + + def build(self): + pass # nothing to build, but tests should not warn + + def test(self): + test_cmd = ['java', '--version'] + output = StringIO() + self.run(test_cmd, output=output) + version_info = output.getvalue() + if "openjdk" in version_info: + pass + else: + raise Exception("java call seems not use the openjdk bin") diff --git a/recipes/openjdk/config.yml b/recipes/openjdk/config.yml new file mode 100644 index 00000000000000..7fd63e870b786b --- /dev/null +++ b/recipes/openjdk/config.yml @@ -0,0 +1,3 @@ +versions: + "16.0.1": + folder: all