aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalph Sennhauser <sera@gentoo.org>2011-09-12 17:27:13 +0000
committerRalph Sennhauser <sera@gentoo.org>2011-09-12 17:27:13 +0000
commitfaf2262cb2de063153e04f929ffa83cff1377481 (patch)
tree0f83b9356b10050430362f2387003f40547a6fbb
parentPrefixify in tmp dir (diff)
downloadjava-config-faf2262cb2de063153e04f929ffa83cff1377481.tar.gz
java-config-faf2262cb2de063153e04f929ffa83cff1377481.tar.bz2
java-config-faf2262cb2de063153e04f929ffa83cff1377481.zip
Implement jdk listing by version and prefs.
svn path=/projects/java-config-2/branches/generation3-support/; revision=8808
-rwxr-xr-xsrc/java-config-223
-rw-r--r--src/java_config_2/EnvironmentManager.py12
-rw-r--r--src/java_config_2/VersionManager.py26
3 files changed, 57 insertions, 4 deletions
diff --git a/src/java-config-2 b/src/java-config-2
index 12e8e2f..6d44f3c 100755
--- a/src/java-config-2
+++ b/src/java-config-2
@@ -8,6 +8,7 @@
from java_config_2 import __version__
from java_config_2.OutputFormatter import OutputFormatter
from java_config_2.EnvironmentManager import EnvironmentManager
+from java_config_2.VersionManager import VersionManager
from java_config_2.Errors import *
import os
@@ -180,7 +181,18 @@ def print_jdks(option, opt, value, parser):
"""
Prints the handels of the jdks avaiable and fulfilling the requirements.
"""
- fatalError("Not yet implemented!")
+ # VM __eq_ is implemeted in terms of version provided -> conceptually broken.
+ copy = []
+ vms = manager.get_virtual_machines(include_jre=0).values()
+ if parser.values.min_target:
+ for vm in vms:
+ if verman.version_cmp(vm.version(), parser.values.min_target) >= 0:
+ copy.append(vm)
+ else:
+ copy = vms
+
+ for vm in verman.sort_vms_by_prefs(copy, parser.values.min_target):
+ print(vm)
def set_system_vm(option, opt, value, parser):
vm = manager.get_vm(value)
@@ -329,6 +341,7 @@ if __name__ == '__main__':
global printer, manager
printer = OutputFormatter(True, True)
manager = EnvironmentManager(root, eprefix)
+ verman = VersionManager(manager)
usage = "java-config [options]\n\n"
usage += "Java Configuration Utility Version " + str(__version__) + "\n"
@@ -502,6 +515,14 @@ if __name__ == '__main__':
except ValueError:
pass
+ args = sys.argv[1:]
+ try:
+ args.remove('--print-jdks')
+ args.append('--print-jdks')
+ except ValueError:
+ pass
+
+
(options, args) = parser.parse_args(args=args)
except InvalidVMError:
fatalError("The active vm could not be found")
diff --git a/src/java_config_2/EnvironmentManager.py b/src/java_config_2/EnvironmentManager.py
index 8f66978..0a1db7e 100644
--- a/src/java_config_2/EnvironmentManager.py
+++ b/src/java_config_2/EnvironmentManager.py
@@ -129,10 +129,18 @@ class EnvironmentManager(object):
self.load_active_vm()
return self.active
- def get_virtual_machines(self):
+ def get_virtual_machines(self, include_jre=1, include_build_only=1):
if self.virtual_machines is None:
self.load_vms()
- return self.virtual_machines
+ vms = {}
+ for k, v in self.virtual_machines.items():
+ if not include_jre and not v.is_jdk():
+ continue
+ if not include_build_only and v.is_build_only():
+ continue
+ vms[k] = v
+
+ return vms
def find_vm(self, name):
found = []
diff --git a/src/java_config_2/VersionManager.py b/src/java_config_2/VersionManager.py
index cd00897..1c07713 100644
--- a/src/java_config_2/VersionManager.py
+++ b/src/java_config_2/VersionManager.py
@@ -72,7 +72,7 @@ class VersionManager:
# then try system vm
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()
@@ -360,6 +360,30 @@ needed dependency, report this to http://bugs.gentoo.org.
return resolved
+ def sort_vms_by_prefs(self, vm_list, version):
+ result = []
+ vms = list(vm_list)
+
+ # VM __eq_ is implemeted in terms of version provided and so we cheat.
+ prefs = self.get_prefs()
+ for pref in prefs:
+ if pref[0] == version or pref[0] == "*":
+ for handle in pref[1]:
+ for i, vm in enumerate(vms):
+ if vm.name().startswith(handle):
+ result.append(vm)
+ vms.pop(i)
+
+ # version_cmp returns float! Cheat onces more.
+ #vms.sort(lambda x, y : self.version_cmp(x.version(), y.version()))
+ vms.sort(key=lambda vm : vm.version());
+
+ for vm in vms:
+ result.append(vm)
+
+ return result
+
+
#vator=VersionManager()
#for i in [
# ">=virtual/jdk-1.3",