PatchInstallerFactory extends AbstractInstallerFactory { @Override protected boolean canHandlePackage(@NotNull RepoPackage p, @NotNull RepoManager manager, @NotNull FileOp fop) { ProgressIndicator progress = new StudioLoggerProgressIndicator(PatchInstallerFactory.class); if (p instanceof LocalPackage) { if (fop.isWindows()) { try { if (FileUtilKt.recursiveSize(fop.toPath(((LocalPackage)p).getLocation())) >= PSEUDO_PATCH_CUTOFF) { return false; } } catch (IOException e) { } LocalPackage latestPatcher = PatchInstallerUtil.getLatestPatcher(manager); return latestPatcher != null && !latestPatcher.equals(p); } else { return false; } } LocalPackage local = manager.getPackages().getLocalPackages().get(p.getPath()); RemotePackage remote = (RemotePackage)p; if (local == null || (!fop.isWindows() && !hasPatch(local, remote))) { return false; } if (hasPatch(local, remote)) { LocalPackage patcher = PatchInstallerUtil.getDependantPatcher((RemotePackage)p, manager); if (patcher != null && myPatchRunnerFactory.getPatchRunner(patcher, progress, fop) != null) { return true; } if (PatchInstallerUtil.getInProgressDependantPatcherInstall((RemotePackage)p, manager) != null) { return true; } if (!fop.isWindows()) { return false; } } if (((RemotePackage)p).getArchive().getComplete().getSize() >= PSEUDO_PATCH_CUTOFF) { return false; } LocalPackage patcher = PatchInstallerUtil.getLatestPatcher(manager); return patcher != null && PatchInstallerUtil.comparePatcherPaths(patcher.getPath(), KNOWN_GOOD_VERSION) >= 0; } PatchInstallerFactory(); @VisibleForTesting  PatchInstallerFactory(@NotNull PatchRunner.Factory runnerFactory);   }
@Test public void cantHandleLinuxUninstallWithPatcher() { myFileOp.setIsWindows(false); LocalPackage p = new FakeLocalPackage("foo"); myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(p, PATCHER_4)); assertFalse(myInstallerFactory.canHandlePackage(p, myRepoManager, myFileOp)); }
@Test public void canHandleWindowsUninstallWithPatcher() { myFileOp.setIsWindows(true); LocalPackage p = new FakeLocalPackage("foo"); myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(p, PATCHER_4)); assertTrue(myInstallerFactory.canHandlePackage(p, myRepoManager, myFileOp)); }
@Test public void cantHandleWindowsUninstallWithLargeFile() { myFileOp.setIsWindows(true); LocalPackage p = new FakeLocalPackage("foo"); myFileOp.recordExistingFile(p.getLocation().getAbsolutePath(), new byte[100 * 1024 * 1024]); myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(p, PATCHER_4)); assertFalse(myInstallerFactory.canHandlePackage(p, myRepoManager, myFileOp)); }
@Test public void cantHandleWindowsUninstallWithoutPatcher() { myFileOp.setIsWindows(true); LocalPackage p = new FakeLocalPackage("foo"); myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(p)); assertFalse(myInstallerFactory.canHandlePackage(p, myRepoManager, myFileOp)); }
@Test public void cantHandleWindowsUninstallOfLatestPatcher() { myFileOp.setIsWindows(true); myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(PATCHER_4)); assertFalse(myInstallerFactory.canHandlePackage(PATCHER_4, myRepoManager, myFileOp)); }
@Test public void cantHandleNoPatchOnLinux() { myFileOp.setIsWindows(false); FakeRemotePackage p = new FakeRemotePackage("foo"); p.setCompleteUrl("http: p.setDependencies(ImmutableList.of(new FakeDependency(PATCHER_4.getPath()))); myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(PATCHER_4)); myRepositoryPackages.setRemotePkgInfos(ImmutableList.of(p)); assertFalse(myInstallerFactory.canHandlePackage(p, myRepoManager, myFileOp)); }
@Test public void canHandleOnLinux() { myFileOp.setIsWindows(false); FakeRemotePackage remote = new FakeRemotePackage("foo"); remote.setCompleteUrl("http: remote.setRevision(new Revision(2)); remote.setPatchInfo("foo", new Revision(1)); remote.setDependencies(ImmutableList.of(new FakeDependency(PATCHER_4.getPath()))); FakeLocalPackage local = new FakeLocalPackage("foo"); local.setRevision(new Revision(1)); myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(local, PATCHER_4)); myRepositoryPackages.setRemotePkgInfos(ImmutableList.of(remote)); assertTrue(myInstallerFactory.canHandlePackage(remote, myRepoManager, myFileOp)); }
@Test public void cantHandleWrongPatch() { myFileOp.setIsWindows(false); FakeRemotePackage remote = new FakeRemotePackage("foo"); remote.setRevision(new Revision(2)); remote.setPatchInfo("foo", new Revision(1)); remote.setDependencies(ImmutableList.of(new FakeDependency(PATCHER_4.getPath()))); remote.setCompleteUrl("http: FakeLocalPackage local = new FakeLocalPackage("foo"); local.setRevision(new Revision(1, 1)); myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(local, PATCHER_4)); myRepositoryPackages.setRemotePkgInfos(ImmutableList.of(remote)); assertFalse(myInstallerFactory.canHandlePackage(remote, myRepoManager, myFileOp)); }
@Test public void canHandleOnWindows() { myFileOp.setIsWindows(true); FakeRemotePackage remote = new FakeRemotePackage("foo"); remote.setRevision(new Revision(2)); remote.setPatchInfo("foo", new Revision(1)); remote.setDependencies(ImmutableList.of(new FakeDependency(PATCHER_4.getPath()))); remote.setCompleteUrl("http: FakeLocalPackage local = new FakeLocalPackage("foo"); local.setRevision(new Revision(1)); myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(local, PATCHER_4)); myRepositoryPackages.setRemotePkgInfos(ImmutableList.of(remote)); assertTrue(myInstallerFactory.canHandlePackage(remote, myRepoManager, myFileOp)); }
@Test public void canHandleLargeFileOnWindows() { myFileOp.setIsWindows(true); FakeRemotePackage remote = new FakeRemotePackage("foo"); remote.setRevision(new Revision(2)); remote.setPatchInfo("foo", new Revision(1)); remote.setCompleteUrl("http: remote.getArchive().getComplete().setSize(100 * 1024 * 1024); remote.setDependencies(ImmutableList.of(new FakeDependency(PATCHER_4.getPath()))); FakeLocalPackage local = new FakeLocalPackage("foo"); local.setRevision(new Revision(1)); myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(local, PATCHER_4)); myRepositoryPackages.setRemotePkgInfos(ImmutableList.of(remote)); assertTrue(myInstallerFactory.canHandlePackage(remote, myRepoManager, myFileOp)); }
@Test public void canHandleNoPatchOnWindowsWithNewPatcher() { myFileOp.setIsWindows(true); FakeRemotePackage remote = new FakeRemotePackage("foo"); remote.setRevision(new Revision(2)); remote.setCompleteUrl("http: FakeLocalPackage local = new FakeLocalPackage("foo"); local.setRevision(new Revision(1)); myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(local, PATCHER_4)); myRepositoryPackages.setRemotePkgInfos(ImmutableList.of(remote)); assertTrue(myInstallerFactory.canHandlePackage(remote, myRepoManager, myFileOp)); }
@Test public void cantHandleNoPatchOnWindowsWithLargeFile() { myFileOp.setIsWindows(true); FakeRemotePackage remote = new FakeRemotePackage("foo"); remote.setRevision(new Revision(2)); remote.setCompleteUrl("http: remote.getArchive().getComplete().setSize(100 * 1024 * 1024); remote.setDependencies(ImmutableList.of(new FakeDependency(PATCHER_4.getPath()))); FakeLocalPackage local = new FakeLocalPackage("foo"); local.setRevision(new Revision(1)); myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(local, PATCHER_4)); myRepositoryPackages.setRemotePkgInfos(ImmutableList.of(remote)); assertFalse(myInstallerFactory.canHandlePackage(remote, myRepoManager, myFileOp)); }
@Test public void cantHandleNoSrcOnWindows() { myFileOp.setIsWindows(true); FakeRemotePackage remote = new FakeRemotePackage("foo"); remote.setRevision(new Revision(2)); remote.setDependencies(ImmutableList.of(new FakeDependency(PATCHER_4.getPath()))); remote.setCompleteUrl("http: myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(PATCHER_4)); myRepositoryPackages.setRemotePkgInfos(ImmutableList.of(remote)); assertFalse(myInstallerFactory.canHandlePackage(remote, myRepoManager, myFileOp)); }
@Test public void cantHandleNoPatchOnWindowsWithOldPatcher() { myFileOp.setIsWindows(true); FakeRemotePackage remote = new FakeRemotePackage("foo"); remote.setRevision(new Revision(2)); remote.setCompleteUrl("http: FakeLocalPackage local = new FakeLocalPackage("foo"); local.setRevision(new Revision(1)); myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(local, PATCHER_2)); myRepositoryPackages.setRemotePkgInfos(ImmutableList.of(remote)); assertFalse(myInstallerFactory.canHandlePackage(remote, myRepoManager, myFileOp)); }
@Test public void cantHandleNoPatchOnWindowsWithNoPatcher() { myFileOp.setIsWindows(true); FakeRemotePackage remote = new FakeRemotePackage("foo"); remote.setRevision(new Revision(2)); remote.setCompleteUrl("http: FakeLocalPackage local = new FakeLocalPackage("foo"); local.setRevision(new Revision(1)); myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(local)); myRepositoryPackages.setRemotePkgInfos(ImmutableList.of(remote)); assertFalse(myInstallerFactory.canHandlePackage(remote, myRepoManager, myFileOp)); }