diff options
author | Vlastimil Babka <caster@gentoo.org> | 2006-09-07 23:21:16 +0000 |
---|---|---|
committer | Vlastimil Babka <caster@gentoo.org> | 2006-09-07 23:21:16 +0000 |
commit | 0eb22580c1fb7232a0d36953e7f2c6f67c7205f8 (patch) | |
tree | eb0d9bd50ff8a5da84007bd400809aa28621a577 | |
parent | Added apt (annotation processing tool) into run-java-tool's symlinks. (diff) | |
download | java-config-0eb22580c1fb7232a0d36953e7f2c6f67c7205f8.tar.gz java-config-0eb22580c1fb7232a0d36953e7f2c6f67c7205f8.tar.bz2 java-config-0eb22580c1fb7232a0d36953e7f2c6f67c7205f8.zip |
Added -d (--with-dependencies) trigger for --library and --classpath calls.
svn path=/projects/java-config-2/trunk/; revision=2709
-rwxr-xr-x | src/java-config-2 | 53 | ||||
-rw-r--r-- | src/java_config/EnvironmentManager.py | 76 |
2 files changed, 94 insertions, 35 deletions
diff --git a/src/java-config-2 b/src/java-config-2 index 319fc1d..175e3d4 100755 --- a/src/java-config-2 +++ b/src/java-config-2 @@ -19,6 +19,7 @@ from commands import getoutput from optparse import OptionParser, make_option +from sets import Set def version(option, opt, value, parser): printer._print("%H%BJava Configuration Utility %GVersion " + str(__version__)) @@ -69,17 +70,31 @@ def java_version(option, opt, value, parser): except PermissionError: fatalError("The java executable was not found in the Java path") -def classpath(option, opt, value, parser): +def query_pkg_path(option, opt, value, parser, query): packages = value.split(',') - classpath = manager.build_classpath(packages) + path = Set() + missing_deps = Set() + if not parser.values.with_deps: + path = manager.build_path(packages, query) + else: + path = manager.build_dep_path(packages, query, missing_deps) + + printer._print(':'.join(path)) - printer._print(':'.join(classpath)) + error = False if len(packages) > 0: for package in packages: printer._printError("Package %s was not found!" % package) - sys.exit(1) + error = True + if len(missing_deps) > 0: + for dep in missing_deps: + printer._printError("Dependency package %s was not found!" % dep) + error = True + + if error: + sys.exit(1) def get_env(option, opt, value, parser): try: @@ -227,15 +242,6 @@ def clean_user_classpath(option, opt, value, parser): deprecation_notice() manager.clean_classpath(user_classpath_target()) -def library(option, opt, value, parser): - packages = value.split(',') - library = manager.query_packages(packages, "LIBRARY_PATH") - - for package in packages: - printer._printError("Package %s was not found!" % package) - - printer._print(':'.join(library)) - def select_vm(option, opt, value, parser): vm = manager.get_vm(value) if vm: @@ -273,6 +279,7 @@ if __name__ == '__main__': options_list = [ make_option ("-V", "--version", action="callback", callback=version, help="Print version information"), make_option ("-n", "--nocolor", action="callback", callback=nocolor, help="Disable color output"), + make_option ("" , "--select-vm", action="callback", callback=select_vm, help="Use this vm instead of the active vm when returning information", type="string", dest="vm"), make_option ("-J", "--java", action="callback", callback=java, help="Print the location of the java executable"), make_option ("-c", "--javac", action="callback", callback=javac, help="Print the location of the javac executable"), make_option ("-j", "--jar", action="callback", callback=jar, help="Print the location of the jar executable"), @@ -281,22 +288,22 @@ if __name__ == '__main__': make_option ("-r", "--runtime", action="callback", callback=runtime, help="Print the runtime classpathh"), make_option ("-f", "--show-active-vm", action="callback", callback=show_active_vm, help="Print the active Virtual Machine"), make_option ("-v", "--java-version", action="callback", callback=java_version, help="Print version information for the active VM"), - make_option ("-p", "--classpath", action="callback", callback=classpath, help="Print entries in the environment classpath", type="string", dest="package(s)"), make_option ("-g", "--get-env", action="callback", callback=get_env, help="Print an environment variable from the active VM", type="string", dest="var"), + make_option ("-P", "--print", action="callback", callback=print_environment, help="Print the environment for the specified VM", type="string", dest="vm"), make_option ("-e", "--exec_cmd", action="callback", callback=exec_cmd, help="Execute something which is in JAVA_HOME", type="string", dest="command"), - make_option ("-l", "--list-available-packages", action="callback", callback=list_available_packages, help="List all available packages on the system."), make_option ("-L", "--list-available-vms", action="callback", callback=list_available_vms, help="List available Java Virtual Machines"), - make_option ("-P", "--print", action="callback", callback=print_environment, help="Print the environment for the specified VM", type="string", dest="vm"), make_option ("-S", "--set-system-vm", action="callback", callback=set_system_vm, help="Set the default Java VM for the system", type="string", dest="vm"), make_option ("-s", "--set-user-vm", action="callback", callback=set_user_vm, help="Set the default Java VM for the user", type="string", dest="vm"), - make_option ("-A", "--set-system-classpath", action="callback", callback=set_system_classpath, help="(Deprecated) Set the system classpath to include the libraries", type="string", dest="package(s)" ), - make_option ("-B", "--append-system-classpath", action="callback", callback=append_system_classpath, help="(Deprecated) Append the libraries to the system classpath", type="string", dest="package(s)"), + make_option ("-l", "--list-available-packages", action="callback", callback=list_available_packages, help="List all available packages on the system."), + make_option ("-d", "--with-dependencies", action="store_true", help="Include package dependencies in --classpath and --library calls", default=False, dest="with_deps"), + make_option ("-p", "--classpath", action="callback", callback=query_pkg_path, help="Print entries in the environment classpath for these packages", type="string", dest="package(s)", callback_args = ("CLASSPATH",)), + make_option ("-i", "--library", action="callback", callback=query_pkg_path, help="Print java library paths for these packages", type="string", dest="package(s)", callback_args = ("LIBRARY_PATH",)), + make_option ("-A", "--set-system-classpath", action="callback", callback=set_system_classpath, help="(Deprecated) Set the system classpath to include the libraries", type="string", dest="package(s)" ), + make_option ("-B", "--append-system-classpath", action="callback", callback=append_system_classpath, help="(Deprecated) Append the libraries to the system classpath", type="string", dest="package(s)"), make_option ("-X", "--clean-system-classpath", action="callback", callback=clean_system_classpath, help="(Deprecated) Clean the current system classpath"), - make_option ("-a", "--set-user-classpath", action="callback", callback=set_user_classpath, help="(Deprecated) Set the user classpath to include the libraries", type="string", dest="package(s)"), - make_option ("-b", "--append-user-classpath", action="callback", callback=append_user_classpath, help="(Deprecated) Append the libraries to the user classpath", type="string", dest="package(s)"), - make_option ("-x", "--clean-user-classpath", action="callback", callback=clean_user_classpath, help="(Deprecated) Clean the current user classpath"), - make_option ("" , "--select-vm", action="callback", callback=select_vm, help="Use this vm when returning information not the active vm", type="string", dest="vm"), - make_option ("-i", "--library", action="callback", callback=library, help="Print java library paths for these packages", type="string", dest="package(s)") + make_option ("-a", "--set-user-classpath", action="callback", callback=set_user_classpath, help="(Deprecated) Set the user classpath to include the libraries", type="string", dest="package(s)"), + make_option ("-b", "--append-user-classpath", action="callback", callback=append_user_classpath, help="(Deprecated) Append the libraries to the user classpath", type="string", dest="package(s)"), + make_option ("-x", "--clean-user-classpath", action="callback", callback=clean_user_classpath, help="(Deprecated) Clean the current user classpath") ] parser = OptionParser(usage, options_list) diff --git a/src/java_config/EnvironmentManager.py b/src/java_config/EnvironmentManager.py index 0da079a..5d8107a 100644 --- a/src/java_config/EnvironmentManager.py +++ b/src/java_config/EnvironmentManager.py @@ -35,7 +35,7 @@ class EnvironmentManager: def load_vms(self): """Load all the vm files, and check for correctness""" self.virtual_machines = {} - + if os.path.isdir(self.vms_path): count = 1 filelist = os.listdir(self.vms_path) @@ -57,7 +57,7 @@ class EnvironmentManager: self.virtual_machines[count] = vm count += 1 - + def load_packages(self): self.packages = {} self.virtuals = {} @@ -134,7 +134,7 @@ class EnvironmentManager: return all_pkg[pkgname] else: return None - + def get_packages(self): if self.packages is None: self.load_packages() @@ -240,14 +240,66 @@ class EnvironmentManager: except IOError: raise PermissionError + def add_path_elements(self, elements, path): + if elements: + for p in elements.split(':'): + if p != '': + path.add(p) + + def build_path(self, pkgs, query): + path = Set() + for lpath in self.query_packages(pkgs, query): + self.add_path_elements(lpath, path) + + return path + def build_classpath(self, pkgs): - classpath = Set() - for lcp in self.query_packages(pkgs, "CLASSPATH"): - for cp in lcp.split(':'): - if cp != '': - classpath.add(cp) + return self.build_path(pkgs, "CLASSPATH") - return classpath + def add_dep_classpath(self, pkg, dep, classpath): + pkg_cp = pkg.classpath() + if pkg_cp: + if not dep or len(dep) == 1: + self.add_path_elements(pkg_cp, classpath) + else: + for cp in pkg_cp.split(':'): + if basename(cp) == dep[0]: + classpath.add(cp) + + def build_dep_path(self, pkgs, query, missing_deps): + path = Set() + + unresolved = Set() + resolved = Set() + + for p in pkgs[:]: + pkg = self.get_package(p) + if pkg: + pkgs.remove(p) + lpath = pkg.query(query) + self.add_path_elements(lpath, path) + unresolved.add(pkg) + + while len(unresolved) > 0: + pkg = unresolved.pop() + resolved.add(pkg) + + if query != "CLASSPATH": + lpath = pkg.query(query) + self.add_path_elements(lpath, path) + + for dep in pkg.deps(): + p = self.get_package(dep[-1]) + + if p: + if p not in resolved: + unresolved.add(p) + if query == "CLASSPATH": + self.add_dep_classpath(p, dep, path) + else: + missing_deps.add(dep[-1]) + + return path def set_classpath(self, targets, pkgs): classpath = self.build_classpath(pkgs) @@ -285,7 +337,7 @@ class EnvironmentManager: for target in targets: for cp in self.get_old_classpath(target).split(':'): classpath.add(cp) - + self.clean_classpath(targets) self.write_classpath(targets, classpath) @@ -300,7 +352,7 @@ class EnvironmentManager: stream = open(target['file'], 'w') except IOError: raise PermissionError - + stream.write(target['format'] % ("CLASSPATH", ':'.join(classpath))) stream.close() @@ -308,7 +360,7 @@ class EnvironmentManager: for virtual in virtuals.split(): if not self.get_virtuals().has_key(virtual): return False - + return True # Singleton hack |