PatchInstallerUtil { @Nullable static LocalPackage getDependantPatcher(@NotNull RemotePackage remote, @NotNull RepoManager mgr) { for (Dependency d : remote.getAllDependencies()) { if (d.getPath().startsWith(PATCHER_PATH_PREFIX + RepoPackage.PATH_SEPARATOR)) { LocalPackage patcher = mgr.getPackages().getLocalPackages().get(d.getPath()); if (patcher != null) { return patcher; } } } return null; }  static File generatePatch(PatchOperation patchOp, File destDir, FileOp fop, ProgressIndicator progress); @Nullable static PackageOperation getInProgressDependantPatcherInstall(@NotNull RemotePackage remote, @NotNull RepoManager mgr); static final String PATCHER_PATH_PREFIX; }
@Test public void getDependantPatcher() throws Exception { LocalPackage target = new FakeLocalPackage("patcher;v2"); List<LocalPackage> local = ImmutableList.of(new FakeLocalPackage("patcher;v1"), target, new FakeLocalPackage("patcher;v3")); FakeRemotePackage update = new FakeRemotePackage("p"); List<RemotePackage> remote = ImmutableList.of(update, new FakeRemotePackage("patcher;v4")); update.setDependencies(ImmutableList.of(new FakeDependency(target.getPath()))); RepositoryPackages packages = new RepositoryPackages(local, remote); FakeRepoManager mgr = new FakeRepoManager(new File("/sdk"), packages); LocalPackage patcher = PatchInstallerUtil.getDependantPatcher(update, mgr); assertEquals(target, patcher); }
@Test public void dependantPatcherNotInstalled() throws Exception { FakeLocalPackage target = new FakeLocalPackage("patcher;v2"); List<LocalPackage> local = ImmutableList.of(new FakeLocalPackage("patcher;v1"), new FakeLocalPackage("patcher;v3")); FakeRemotePackage update = new FakeRemotePackage("p"); List<RemotePackage> remote = ImmutableList.of(update, new FakeRemotePackage("patcher;v4")); update.setDependencies(ImmutableList.of(new FakeDependency(target.getPath()))); RepositoryPackages packages = new RepositoryPackages(local, remote); FakeRepoManager mgr = new FakeRepoManager(new File("/sdk"), packages); LocalPackage patcher = PatchInstallerUtil.getDependantPatcher(update, mgr); assertNull(patcher); }