Skip to content
This repository has been archived by the owner on Oct 23, 2018. It is now read-only.

Commit

Permalink
JDK detection algorithm improvements and small tweaks
Browse files Browse the repository at this point in the history
- Improve JDK detection algorithm (fix #55, #56, #63, #65)
- Change statistics endpoint to a new one
- Remove unused code
  • Loading branch information
Sirisak Lueangsaksri committed Jun 27, 2016
1 parent f62ce64 commit e273ec4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
5 changes: 0 additions & 5 deletions core/usages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
43 changes: 41 additions & 2 deletions threads/jdk_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions utils/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ class Constant:

@staticmethod
def get_version():
return "2.0.0-prebeta.5"
return "2.0.0-prebeta.6"

@staticmethod
def get_usages_schema_version():
return "2.0"

@staticmethod
def get_usages_host():
return "http://javatar.digitalparticle.com/"
return "http://api.digitalparticle.com/1/stats/"

@staticmethod
def get_packages_schema_version():
Expand Down

0 comments on commit e273ec4

Please sign in to comment.