|
| 1 | +from conans import ConanFile, tools |
| 2 | +from conans.errors import ConanInvalidConfiguration |
| 3 | +import os |
| 4 | + |
| 5 | +required_conan_version = ">=1.33.0" |
| 6 | + |
| 7 | + |
| 8 | +class OpenJDK(ConanFile): |
| 9 | + name = "openjdk" |
| 10 | + url = "https://github.com/conan-io/conan-center-index/" |
| 11 | + description = "Java Development Kit builds, from Oracle" |
| 12 | + homepage = "https://jdk.java.net" |
| 13 | + license = "GPL-2.0-with-classpath-exception" |
| 14 | + topics = ("java", "jdk", "openjdk") |
| 15 | + settings = "os", "arch" |
| 16 | + no_copy_source = True |
| 17 | + |
| 18 | + @property |
| 19 | + def _source_subfolder(self): |
| 20 | + return "source_subfolder" |
| 21 | + |
| 22 | + def configure(self): |
| 23 | + if self.settings.arch != "x86_64": |
| 24 | + raise ConanInvalidConfiguration("Unsupported Architecture. This package currently only supports x86_64.") |
| 25 | + if self.settings.os not in ["Windows", "Macos", "Linux"]: |
| 26 | + raise ConanInvalidConfiguration("Unsupported os. This package currently only support Linux/Macos/Windows") |
| 27 | + |
| 28 | + def build(self): |
| 29 | + tools.get(**self.conan_data["sources"][self.version][str(self.settings.os)], |
| 30 | + destination=self._source_subfolder, strip_root=True) |
| 31 | + |
| 32 | + def package(self): |
| 33 | + if self.settings.os == "Macos": |
| 34 | + _source_subfolder = os.path.join(self._source_subfolder, "jdk-{}.jdk".format(self.version), "Contents", "Home") |
| 35 | + else: |
| 36 | + _source_subfolder = self._source_subfolder |
| 37 | + self.copy(pattern="*", dst="bin", src=os.path.join(_source_subfolder, "bin"), |
| 38 | + excludes=("msvcp140.dll", "vcruntime140.dll", "vcruntime140_1.dll")) |
| 39 | + self.copy(pattern="*", dst="include", src=os.path.join(_source_subfolder, "include")) |
| 40 | + self.copy(pattern="*", dst="lib", src=os.path.join(_source_subfolder, "lib")) |
| 41 | + self.copy(pattern="*", dst=os.path.join("lib", "jmods"), src=os.path.join(_source_subfolder, "jmods")) |
| 42 | + self.copy(pattern="*", dst="licenses", src=os.path.join(_source_subfolder, "legal")) |
| 43 | + # conf folder is required for security settings, to avoid |
| 44 | + # java.lang.SecurityException: Can't read cryptographic policy directory: unlimited |
| 45 | + # https://github.com/conan-io/conan-center-index/pull/4491#issuecomment-774555069 |
| 46 | + self.copy(pattern="*", dst="conf", src=os.path.join(_source_subfolder, "conf")) |
| 47 | + |
| 48 | + def package_info(self): |
| 49 | + self.output.info("Creating JAVA_HOME environment variable with : {0}".format(self.package_folder)) |
| 50 | + self.env_info.JAVA_HOME = self.package_folder |
| 51 | + |
| 52 | + self.output.info("Appending PATH environment variable with : {0}".format(os.path.join(self.package_folder, "bin"))) |
| 53 | + self.env_info.PATH.append(os.path.join(self.package_folder, "bin")) |
0 commit comments