From e273ec40c209658247a71b109bb90cd126984a29 Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri Date: Mon, 27 Jun 2016 22:47:06 +0700 Subject: [PATCH] JDK detection algorithm improvements and small tweaks - Improve JDK detection algorithm (fix #55, #56, #63, #65) - Change statistics endpoint to a new one - Remove unused code --- core/usages.py | 5 ----- threads/jdk_manager.py | 43 ++++++++++++++++++++++++++++++++++++++++-- utils/constant.py | 4 ++-- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/core/usages.py b/core/usages.py index 866589c..8a001a9 100644 --- a/core/usages.py +++ b/core/usages.py @@ -68,11 +68,6 @@ def send_packages_usages(self): if Settings().get("send_stats_and_usages"): params = self.get_usages_data() params["package"] = "true" - # Downloader.request( - # Constant.get_usages_host(), - # params, - # on_complete=self.on_usages_sent - # ) def Usages(): diff --git a/threads/jdk_manager.py b/threads/jdk_manager.py index d92818d..311efa1 100644 --- a/threads/jdk_manager.py +++ b/threads/jdk_manager.py @@ -58,8 +58,44 @@ def get_jdk_version(cls, path=None, executable=None): return version return None - @classmethod - def get_java_home(cls, path=None): + def is_java_home_path(self, path): + """ + Check whether the specified path is contains all Java runtime files + + @param path: a directory path + """ + required_files = set([ + file + for files in + Settings().get("java_runtime_files").values() + for file in files + ]) + + existing_files = ( + name + for name in os.listdir(path) + if os.path.isfile(os.path.join(path, name)) + ) + return required_files.issubset(existing_files) + + def find_java_home(self, path): + """ + Find all subfolder of specified path and return the path if it contains + all Java runtime files + + @param path: a path to find + """ + for name in os.listdir(path): + path_name = os.path.join(path, name) + if os.path.isdir(path_name): + if self.is_java_home_path(path_name): + return os.path.dirname(path_name) + java_home = self.find_java_home(path_name) + if java_home: + return java_home + return None + + def get_java_home(self, path=None): """ Returns the Java home directory @@ -81,6 +117,9 @@ def get_java_home(cls, path=None): )) if output["data"] and os.path.exists(output["data"]): return output["data"] + if path: + # Move one level up, so we ends up on the JDK root directory + return self.find_java_home(os.path.dirname(path)) return None def is_jdk_path(self, path): diff --git a/utils/constant.py b/utils/constant.py index ac1cf6c..a915b53 100644 --- a/utils/constant.py +++ b/utils/constant.py @@ -25,7 +25,7 @@ class Constant: @staticmethod def get_version(): - return "2.0.0-prebeta.5" + return "2.0.0-prebeta.6" @staticmethod def get_usages_schema_version(): @@ -33,7 +33,7 @@ def get_usages_schema_version(): @staticmethod def get_usages_host(): - return "http://javatar.digitalparticle.com/" + return "http://api.digitalparticle.com/1/stats/" @staticmethod def get_packages_schema_version():