diff options
-rw-r--r-- | config/symlink-tools | 13 | ||||
-rw-r--r-- | setup.py | 3 | ||||
-rwxr-xr-x | src/java-config | 26 | ||||
-rw-r--r-- | src/java_config/EnvironmentManager.py | 92 | ||||
-rwxr-xr-x | src/run-java-tool | 11 |
5 files changed, 53 insertions, 92 deletions
diff --git a/config/symlink-tools b/config/symlink-tools new file mode 100644 index 0000000..47eabae --- /dev/null +++ b/config/symlink-tools @@ -0,0 +1,13 @@ +appletviewer +jar +jarsigner +java +javac +javadoc +javah +javap +javaws +jdb +rmic +rmid +rmiregistry @@ -22,7 +22,8 @@ setup ( data_files = [ ('man/man1', ["man/java-config.1"]), ('share/java-config/config', ["config/jdk-defaults.conf"]), - ('/etc/java-config/', ["config/jdk.conf"]) + ('/etc/java-config/', ["config/jdk.conf"]), + ('share/java-config/', ["config/symlink-tools"]) ] ) diff --git a/src/java-config b/src/java-config index 936a080..c2cca4b 100755 --- a/src/java-config +++ b/src/java-config @@ -141,16 +141,13 @@ def print_environment(option, opt, value, parser): def set_system_vm(option, opt, value, parser): vm = manager.get_vm(value) - # TODO: MAKE THIS MODULAR!! - config = os.path.join('/', 'etc', 'env.d', '20java') if os.getuid() is 0: if vm.is_jre(): printer._printWarning("The specified VM is a JRE! It is suggested you use a JDK!") try: - manager.set_vm(vm, config, None) - update_env() + manager.set_system_vm(vm) except PermissionError: printer._printError("You do not have enough permissions to set the system VM!") except EnvironmentUndefinedError: @@ -160,24 +157,14 @@ def set_system_vm(option, opt, value, parser): def set_user_vm(option, opt, value, parser): vm = manager.get_vm(value) - # TODO: MAKE THIS MODULAR!! - config_sh = os.path.join(os.environ.get("HOME"), '.gentoo', 'java.sh') - config_csh = os.path.join(os.environ.get("HOME"), '.gentoo', 'java.csh') if os.getuid() is 0: printer._printError("The user 'root' should always use the System VM") else: - # TODO: MAKE THIS MODULAR!! - env_dir = os.path.join(os.environ.get("HOME"), '.gentoo') - - if os.path.exists(env_dir) and not os.path.isdir(env_dir): - printer._printError(os.path.join(os.environ.get("HOME"), '.gentoo') + " exists, but is not a directory!") - else: - try: - manager.set_vm(vm, config_sh, config_csh) - update_env() - except PermissionError: - printer._printError("You do not have enough permissions to set the VM!") + try: + manager.set_user_vm(vm) + except PermissionError: + printer._printError("You do not have enough permissions to set the VM!") def set_system_classpath(option, opt, value, parser): # TODO: MAKE THIS MODULAR!! @@ -219,7 +206,6 @@ def clean_system_classpath(option, opt, value, parser): if os.getuid() is 0: manager.clean_classpath(env_file) - update_env() else: printer._printError("You do not have enough permissions to clean the system classpath!") @@ -245,7 +231,7 @@ def select_vm(option, opt, value, parser): def update_env(): printer._print(getoutput("/usr/sbin/env-update")) - printer._printAlert("If you want to use java in your current session, you should update\nyour environment by running:\nsource /etc/profile") + printer._printAlert("If you want the changes too take effect in your current session, you should update\nyour environment by running:\nsource /etc/profile") diff --git a/src/java_config/EnvironmentManager.py b/src/java_config/EnvironmentManager.py index 6a8a0ab..47f6e31 100644 --- a/src/java_config/EnvironmentManager.py +++ b/src/java_config/EnvironmentManager.py @@ -30,9 +30,8 @@ class EnvironmentManager: if os.path.isdir(self.vms_path): count = 1 for file in os.listdir(self.vms_path): - conf = os.path.join(self.vms_path, file) - if file.startswith("20"): + conf = os.path.join(self.vms_path,file) vm = None try: @@ -47,36 +46,15 @@ class EnvironmentManager: def load_packages(self): self.packages = [] - for package in iter(glob(pkg_path)): + for package in iter(glob(self.pkg_path)): self.packages.append(Package(package, basename(dirname(package)))) def load_active_vm(self): - environ_path = [ - os.path.join(os.environ.get('HOME'), '.gentoo', 'java'), - os.path.join('/', 'etc', 'env.d', '20java') - ] - - java_home = None - - for file in environ_path: - try: - stream = open(file, 'r') - except IOError: - continue - - read = stream.readline() - while read: - if read.strip().startswith('JAVA_HOME'): - stream.close() - java_home = read.split('=', 1)[-1].strip() - break - else: - read = stream.readline() - stream.close() - - for vm in self.get_virtual_machines().itervalues(): - if vm.query('JAVA_HOME') == java_home: - self.active = vm + for link in self.vm_links(): + if os.path.islink(link): + vm_name = os.readlink(link) + vm = self.get_vm(vm_name) + self.active = vm return vm raise InvalidVMError @@ -150,54 +128,26 @@ class EnvironmentManager: else: return None - def create_env_entry(self, vm, stream, render="%s=%s\n"): - stream.write("# Autogenerated by java-config\n") - stream.write("# Java Virtual Machine: %s\n\n" % vm.query('VERSION')) + def set_user_vm(self, vm): + self.set_vm(vm, self.user_vm_link()) - try: - ENV_VARS = vm.query('ENV_VARS') - for (item, value) in vm.get_config().iteritems(): - if item in ENV_VARS: - stream.write(render % (item, value)) - except IOError: - raise PermissionError - except EnvironmentUndefinedError: - raise EnvironmentUndefinedError + def set_system_vm(self, vm): + self.set_vm(vm, self.system_vm_link()) - def set_vm(self, vm, sh_env_file, csh_env_file=None): + def set_vm(self, vm, target): + if os.path.islink(target): + os.remove(target) + os.symlink(vm.name(),target) - # Create the SH environment file - if sh_env_file is not None: - try: - stream = open(sh_env_file, 'w') - except IOError: - raise PermissionError + def vm_links(self): + return [ self.user_vm_link(), self.system_vm_link() ] - try: - self.create_env_entry(vm, stream, "%s=%s\n") - except IOError: - stream.close() - raise PermissionError - except EnvironmentUndefinedError: - stream.close(); - raise EnvironmentUndefinedError + def user_vm_link(self): + return os.path.join(os.environ.get('HOME'), '.gentoo/user-vm') - stream.close() + def system_vm_link(self): + return '/usr/share/java-config/vms/system-vm' - # Create the CSH environment file - if csh_env_file is not None: - try: - stream = open(csh_env_file, 'w') - except IOError: - raise PermissionError - - try: - self.create_env_entry(vm, stream, "setenv %s %s\n") - except IOError: - stream.close() - raise PermissionError - - stream.close() def clean_classpath(self, env_file): if os.path.isfile(env_file): diff --git a/src/run-java-tool b/src/run-java-tool new file mode 100755 index 0000000..3204410 --- /dev/null +++ b/src/run-java-tool @@ -0,0 +1,11 @@ +#!/bin/bash + +if [[ -n ${GENTOO_VM} ]]; then + execme=/usr/share/java-config/vms/${GENTOO_VM}/ +elif [[ -d ${HOME}/.gentoo/user-vm ]]; then + execme=${HOME}/.gentoo/user-vm/ +else + execme=/usr/share/java-config/vms/system-vm/ +fi + +exec ${execme}/bin/$(basename $0) "${@}" |