diff options
author | Ralph Sennhauser <sera@gentoo.org> | 2013-02-08 15:40:13 +0000 |
---|---|---|
committer | Ralph Sennhauser <sera@gentoo.org> | 2013-02-08 15:40:13 +0000 |
commit | 6cdf52cca1f613ec1b9c265687fd333adadcf606 (patch) | |
tree | 9d208f843fe10e226a5aa492a191f26ff435dfb0 /src | |
parent | Allow running tests from everywhere (diff) | |
download | java-config-6cdf52cca1f613ec1b9c265687fd333adadcf606.tar.gz java-config-6cdf52cca1f613ec1b9c265687fd333adadcf606.tar.bz2 java-config-6cdf52cca1f613ec1b9c265687fd333adadcf606.zip |
Drop EnvironmentManager singlton hack and so really fix VersionManager to not lock on the active JVM. #402315
svn path=/projects/java-config-2/trunk/; revision=9182
Diffstat (limited to 'src')
-rwxr-xr-x | src/depend-java-query | 2 | ||||
-rwxr-xr-x | src/gjl | 8 | ||||
-rw-r--r-- | src/java_config_2/EnvironmentManager.py | 3 | ||||
-rw-r--r-- | src/java_config_2/VersionManager.py | 84 | ||||
-rw-r--r-- | src/java_config_2/Virtual.py | 2 |
5 files changed, 42 insertions, 57 deletions
diff --git a/src/depend-java-query b/src/depend-java-query index 2df5b70..64f7b5d 100755 --- a/src/depend-java-query +++ b/src/depend-java-query @@ -66,7 +66,7 @@ if __name__ == '__main__': global printer, manager, verman printer = OutputFormatter(True, True) manager = EnvironmentManager() - verman = VersionManager() + verman = VersionManager(manager) usage = "depend-java-query [options]\n\n" usage += "Java Dep Query Utility Version " + str(__version__) + "\n" @@ -25,7 +25,7 @@ atom_parser = re.compile(r"([<>=]+)virtual/(jre|jdk)-([0-9\.*]+)") def get_needed_target(pkg): highest_target = "" needs_jdk = False - for pkg in get_needed_packages(pkg): + for pkg in verman.get_needed_packages(pkg): pkg_needs_jdk = False x = pkg.query("TARGET") try: @@ -45,7 +45,7 @@ def get_needed_target(pkg): def get_needed_target2(pkg): highest_target = "" needs_jdk = set() - for pkg in get_needed_packages(pkg): + for pkg in verman.get_needed_packages(pkg): target = pkg.target() if highest_target < target: highest_target = target @@ -76,7 +76,7 @@ def abort(msg): def get_needed_vms(pkg): virtuals = set() vms = set() - for pkg in get_needed_packages(pkg): + for pkg in verman.get_needed_packages(pkg): try: x = pkg.query("VM") if atom_parser.match( x ): @@ -251,7 +251,7 @@ if __name__ == '__main__': global printer, manager, verman printer = OutputFormatter(True, True) manager = EnvironmentManager() - verman = VersionManager() + verman = VersionManager(manager) if not options.package: abort("Too dumb todo anything without -p") diff --git a/src/java_config_2/EnvironmentManager.py b/src/java_config_2/EnvironmentManager.py index c26f9ef..dd387bb 100644 --- a/src/java_config_2/EnvironmentManager.py +++ b/src/java_config_2/EnvironmentManager.py @@ -488,7 +488,4 @@ class EnvironmentManager(object): self.set_active_vm(storeVM) return result -# Singleton hack -EnvironmentManager = EnvironmentManager() - # vim:set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap: diff --git a/src/java_config_2/VersionManager.py b/src/java_config_2/VersionManager.py index 3e568e0..f6f91d4 100644 --- a/src/java_config_2/VersionManager.py +++ b/src/java_config_2/VersionManager.py @@ -58,13 +58,10 @@ class VersionManager: default_pref_file = '/usr/share/java-config-2/config/jdk-defaults.conf' _prefs = None - def __init__(self): - pass + def __init__(self, env_manager): + self.env_manager = env_manager def get_prefs(self): - from java_config_2.EnvironmentManager import EnvironmentManager - envman = EnvironmentManager() - if self._prefs: return self._prefs else: @@ -73,9 +70,9 @@ class VersionManager: if os.path.exists(self.user_pref_file): self._prefs += PrefsFileParser(self.user_pref_file).get_config() # then try system vm - sys_vm = envman.system_vm_name() + sys_vm = self.env_manager.system_vm_name() if sys_vm is not None: - self._prefs.append(['*', [sys_vm]]) + self._prefs.append(['*', [sys_vm]]) # then try the build defaults if os.path.exists(self.default_pref_file): self._prefs += PrefsFileParser(self.default_pref_file).get_config() @@ -194,8 +191,6 @@ class VersionManager: def get_target_from_pkg_deps(self, matches): """ Get the lowest virtual machine version from a packages dependencies.""" - from java_config_2.EnvironmentManager import EnvironmentManager - manager = EnvironmentManager() highest = None pkg_name = None @@ -206,12 +201,12 @@ class VersionManager: if match['slot'] and match['slot'] != '0': pkg_name += '-' + match['slot'] try: - pkg = manager.get_package(pkg_name) + pkg = self.manager.get_package(pkg_name) pkgs.append(pkg) except: pass - deep_pkgs = get_needed_packages(*pkgs) + deep_pkgs = self.get_needed_packages(*pkgs) for pkg in deep_pkgs: try: @@ -228,8 +223,6 @@ class VersionManager: return pkg_name, highest def get_vm(self, atoms, allow_build_only = False): - from java_config_2.EnvironmentManager import EnvironmentManager - pkg_name, highest_pkg_target = self.get_target_from_pkg_deps(self.parse_depend_packages(atoms)) matched_atoms = self.parse_depend(atoms) @@ -250,7 +243,7 @@ class VersionManager: for gvm in self.find_vm(vmProviderString, atom, highest_pkg_target, allow_build_only): if need_virtual: # Package we are finding a vm for needs a virtual # New, correct way of searching for virtuals - if EnvironmentManager().have_provider(need_virtual, gvm, self): # We have a package available that provides it, will use that + if self.env_manager.have_provider(need_virtual, gvm, self): # We have a package available that provides it, will use that return gvm else: return gvm # use it! @@ -260,7 +253,7 @@ class VersionManager: for atom in matched_atoms: for gvm in self.find_vm("", atom, highest_pkg_target, allow_build_only): if need_virtual: # Package we are finding a vm for needs a virtual - if EnvironmentManager().have_provider(need_virtual, gvm, self): + if self.env_manager.have_provider(need_virtual, gvm, self): return gvm else: return gvm @@ -281,8 +274,7 @@ class VersionManager: def find_vm(self, vmProviderString, atom, min_package_target, allow_build_only = True): - from java_config_2.EnvironmentManager import EnvironmentManager - vm_list = EnvironmentManager().find_vm(vmProviderString) + vm_list = self.env_manager.find_vm(vmProviderString) vm_list.sort() vm_list.reverse() for vm in vm_list: @@ -333,44 +325,40 @@ class VersionManager: return 0 -def get_needed_packages(*packages): - from java_config_2.EnvironmentManager import EnvironmentManager - - manager = EnvironmentManager() - - unresolved = set() - for package in packages: - unresolved.add(package) - - resolved = set() - - while len(unresolved) > 0: - pkg = unresolved.pop() - resolved.add(pkg) - # dep is in the form of (jar, pkg) - for dep in manager.get_pkg_deps(pkg): - dep_pkg = dep[-1] - p = manager.get_package(dep_pkg) - if p is None: - if ',' in dep_pkg: - msg = """ + def get_needed_packages(self, *packages): + unresolved = set() + for package in packages: + unresolved.add(package) + + resolved = set() + + while len(unresolved) > 0: + pkg = unresolved.pop() + resolved.add(pkg) + # dep is in the form of (jar, pkg) + for dep in self.env_manager.get_pkg_deps(pkg): + dep_pkg = dep[-1] + p = self.env_manager.get_package(dep_pkg) + if p is None: + if ',' in dep_pkg: + msg = """ Package %s has a broken DEPEND entry in package.env. Please reinstall it. If this does not fix it, please report this to http://bugs.gentoo.org """ - msg = msg % pkg - else: - msg = """ + msg = msg % pkg + else: + msg = """ Package %s not found in the system. This package is listed as a dependency of %s. Please run emerge -1Da %s and if it does not bring in the needed dependency, report this to http://bugs.gentoo.org. """ - msg = msg % (dep_pkg,pkg,pkg) - abort(msg) - - if p not in resolved: - unresolved.add(p) - - return resolved + msg = msg % (dep_pkg,pkg,pkg) + abort(msg) + + if p not in resolved: + unresolved.add(p) + + return resolved #vator=VersionManager() #for i in [ diff --git a/src/java_config_2/Virtual.py b/src/java_config_2/Virtual.py index 30f6431..ea862d4 100644 --- a/src/java_config_2/Virtual.py +++ b/src/java_config_2/Virtual.py @@ -65,7 +65,7 @@ class Virtual(Package): if not element in self._packages: self._packages.append(element) - verman = VersionManager() + verman = VersionManager(self._manager) vmachines = self._manager.get_virtual_machines() for vm in vmachines: if verman.version_satisfies(" ".join(vms), vmachines[vm]): |