/** * Checks package descriptor and if packages involved in dependencies are already installed. * * @param pkg package * @throws QueryException query exception */ public void check(final Package pkg) throws QueryException { // check if package is already installed final byte[] name = pkg.uniqueName(); if (repo.pkgDict().get(name) != null) PKGINST.thrw(input, name); // check package dependencies checkDepends(pkg); // check package components checkComps(pkg); }
/** * Checks if secondary package, i.e. package involved in a dependency is already installed. * * @param dep dependency * @return result */ public byte[] depPkg(final Dependency dep) { // get installed versions of secondary package final TokenSet instVers = new TokenSet(); for (final byte[] nextPkg : repo.pkgDict().keys()) if (nextPkg != null && startsWith(nextPkg, dep.pkg)) instVers.add(version(nextPkg)); // check if an appropriate version is already installed final byte[] version = availVersion(dep, instVers); return version == null ? null : dep.name(version); }
/** * Checks if an XQuery component is already installed as part of another package. * * @param comp component * @param name component's package * @return result * @throws QueryException query exception */ private boolean isInstalled(final Component comp, final byte[] name) throws QueryException { // get packages in which the module's namespace is found final TokenSet pkgs = repo.nsDict().get(comp.uri); if (pkgs == null) return false; for (final byte[] nextPkg : pkgs) { if (nextPkg != null && !eq(Package.name(nextPkg), name)) { // installed package is a different one, not just a different version // of the current one final String pkgDir = string(repo.pkgDict().get(nextPkg)); final IO pkgDesc = new IOFile(repo.path(pkgDir), DESCRIPTOR); final Package pkg = new PkgParser(repo, input).parse(pkgDesc); for (final Component nextComp : pkg.comps) { if (nextComp.name().equals(comp.name())) return true; } } } return false; }