@Override public Dependency[] getDependencies() { return vltPkg.getDependencies(); }
/** * Sorts the packages by the dependency order * @param packages packages to sort * @param <T> Type of the collection. * @throws CyclicDependencyException if a cyclic dependency is detected */ public static <T extends VaultPackage> void sort(Collection<T> packages) throws CyclicDependencyException { Map<PackageId, Dependency[]> list = new LinkedHashMap<PackageId, Dependency[]>(); Map<PackageId, VaultPackage> byId = new LinkedHashMap<PackageId, VaultPackage>(); for (VaultPackage pack: packages) { list.put(pack.getId(), pack.getDependencies()); byId.put(pack.getId(), pack); } packages.clear(); for (PackageId id: resolve(list)) { packages.add((T) byId.remove(id)); } }
/** * {@inheritDoc} */ @Nonnull @Override public DependencyReport analyzeDependencies(@Nonnull PackageId id, boolean onlyInstalled) throws IOException, NoSuchPackageException { List<Dependency> unresolved = new LinkedList<Dependency>(); List<PackageId> resolved = new LinkedList<PackageId>(); try (RegisteredPackage pkg = open(id)) { if (pkg == null) { throw new NoSuchPackageException().setId(id); } //noinspection resource for (Dependency dep : pkg.getPackage().getDependencies()) { PackageId resolvedId = resolve(dep, onlyInstalled); if (resolvedId == null) { unresolved.add(dep); } else { resolved.add(resolvedId); } } } return new DependencyReportImpl(id, unresolved.toArray(new Dependency[unresolved.size()]), resolved.toArray(new PackageId[resolved.size()]) ); }
/** * {@inheritDoc} */ @Nonnull @Override public PackageId[] usage(PackageId id) throws IOException { TreeSet<PackageId> usages = new TreeSet<PackageId>(); for (PackageId pid : packages()) { try (RegisteredPackage pkg = open(pid)) { if (pkg == null || !pkg.isInstalled()) { continue; } // noinspection resource for (Dependency dep : pkg.getPackage().getDependencies()) { if (dep.matches(id)) { usages.add(pid); break; } } } } return usages.toArray(new PackageId[usages.size()]); }