(self, get=None)
| 1795 | # return ret |
| 1796 | |
| 1797 | def get_local_jdk_version(self, get=None): |
| 1798 | import os |
| 1799 | import json |
| 1800 | # 获取本地文件中的JDK版本 |
| 1801 | ret = [] |
| 1802 | if os.path.exists(self._panel_path + '/data/get_local_jdk.json'): |
| 1803 | ret2 = public.ReadFile(self._panel_path + '/data/get_local_jdk.json') |
| 1804 | if isinstance(ret2, str): |
| 1805 | ret2 = json.loads(ret2) |
| 1806 | for i in range(len(ret2)): |
| 1807 | ret.append({'name': '自定义JDK', 'path': ret2[i], 'operation': 1, 'is_current': False}) |
| 1808 | |
| 1809 | # 读取/etc/profile文件来获取当前JAVA_HOME环境变量 |
| 1810 | bashrc_path = os.path.expanduser('/etc/profile') |
| 1811 | |
| 1812 | current_java_home = '' |
| 1813 | # 检查文件是否存在 |
| 1814 | if os.path.exists(bashrc_path): |
| 1815 | profile_data = public.readFile(bashrc_path) |
| 1816 | if profile_data: |
| 1817 | for line in profile_data.strip("\n"): |
| 1818 | if 'export JAVA_HOME=' in line: |
| 1819 | current_java_home = line.split('=')[1].strip().replace('"', '').replace("'", "") |
| 1820 | |
| 1821 | # 获取已安装的JDK版本 |
| 1822 | jdks = self._get_jdk_status()['versions'] |
| 1823 | jdks = sorted(jdks, key = lambda x: x['status'], reverse = True) |
| 1824 | for jdk in jdks: |
| 1825 | jdk_path = '/www/server/java/' + jdk['version'] + '/bin/java' |
| 1826 | is_current = os.path.dirname(os.path.dirname(jdk_path)) == current_java_home |
| 1827 | if jdk['status']: |
| 1828 | ret.append({'name': jdk['version'], 'path': jdk_path, 'operation': 1, 'is_current': is_current}) |
| 1829 | else: |
| 1830 | ret.append({'name': jdk['version'], 'path': '', 'operation': 0, 'is_current': False}) |
| 1831 | |
| 1832 | # 检查其他JDK路径 |
| 1833 | jdk_paths = [ |
| 1834 | ('JDK', '/usr/bin/java'), |
| 1835 | ('jdk8', '/usr/java/jdk1.8.0_121/bin/java'), |
| 1836 | ('openjdk8', '/usr/local/btjdk/jdk8/bin/java'), |
| 1837 | ('jdk7', '/usr/java/jdk1.7.0_80/bin/java') |
| 1838 | ] |
| 1839 | for name, path in jdk_paths: |
| 1840 | if os.path.exists(path): |
| 1841 | is_current = os.path.dirname(os.path.dirname(path)) == current_java_home |
| 1842 | ret.append({'name': name, 'path': path, 'operation': 2, 'is_current': is_current}) |
| 1843 | |
| 1844 | # 检查是否有正在安装的JDK |
| 1845 | for i in ret: |
| 1846 | import psutil |
| 1847 | try: |
| 1848 | if os.path.exists('/www/server/java/' + i['name'] + '.pl'): |
| 1849 | pid = int(public.readFile('/www/server/java/' + i['name'] + '.pl')) |
| 1850 | psutil.Process(pid) |
| 1851 | i['operation'] = 3 |
| 1852 | except UnicodeEncodeError: |
| 1853 | continue |
| 1854 | except: |
no test coverage detected