RequiredPackagesInstallStep extends AbstractInstallStep { protected List<Optional<Package>> resolvePackages(Collection<Package> installablePackages, List<String> minimumPackages) { return minimumPackages .stream() .map(pkgName -> installablePackages .stream() .filter(p -> pkgName.equals(p.getName())) .sorted((p1, p2) -> { return p2.getVersion().compareTo(p1.getVersion()); }) .findFirst()) .collect(Collectors.toList()); } RequiredPackagesInstallStep(InstallableDistribution installableDistribution); @Override String getName(); @Override double getProgress();  }
@Test public void testResolvePackages() throws Exception { List<org.openthinclient.pkgmgr.db.Package> installable = Arrays.asList( createPackage("base", "2.0-12"), createPackage("base", "2.0-27"), createPackage("base", "2.0-18") ); final List<Optional<Package>> result = new RequiredPackagesInstallStep(null).resolvePackages(installable, Collections.singletonList("base")); assertEquals(1, result.size()); assertTrue(result.get(0).isPresent()); assertEquals("0:2.0-27", result.get(0).get().getVersion().toString()); }
@Test public void testResolvePackagesFromDistributionsXML() throws Exception { final LocalPackageList localPackageList = new LocalPackageList(new Source(), new File("target/test-classes/Packages.txt")); List<Package> installablePackages = parsePackagesList(localPackageList).collect(Collectors.toList()); assertEquals(36, installablePackages.size()); final InstallableDistribution distribution = InstallableDistributions.getDefaultDistributions().getPreferred(); assertNotNull(distribution); assertEquals(2, distribution.getMinimumPackages().size()); RequiredPackagesInstallStep rpis = new RequiredPackagesInstallStep(distribution); final List<Optional<Package>> resolvedPackages = rpis.resolvePackages(installablePackages, distribution.getMinimumPackages()); assertEquals(2, resolvedPackages.size()); LOG.info("Resolving dependencies"); PackageManagerOperation operation = new DefaultPackageManagerOperation(new PackageManagerOperationResolverImpl(() -> Collections.EMPTY_LIST, () -> installablePackages)); resolvedPackages.stream().map(Optional::get).forEach(operation::install); operation.resolve(); InstallPlan installPlan = operation.getInstallPlan(); List<InstallPlanStep> steps = installPlan.getSteps(); assertEquals("Wrong number of expected packages to install. Please check the package resolving.", 7, steps.size()); }