@Override public final void projectClosed() { disposeComponent(); }
private ClientConfigRoot getClientFor(VirtualFile file) { ProjectConfigRegistry reg = ProjectConfigRegistry.getInstance(project); return reg == null ? null : reg.getClientFor(file); } }
@Override public final void disposeComponent() { dispose(); }
@Override public boolean validateOptions(Collection<FilePath> collection) { ProjectConfigRegistry registry = ProjectConfigRegistry.getInstance(project); if (registry == null || registry.isDisposed()) { return false; } for (FilePath filePath : collection) { ClientConfigRoot root = registry.getClientFor(filePath); if (root != null) { return true; } } return false; }
private Collection<ClientConfigRoot> getClientConfigRoots() { ProjectConfigRegistry reg = ProjectConfigRegistry.getInstance(project); return reg == null ? Collections.emptyList() : reg.getClientConfigRoots(); }
@Test void disposeComponent() { ProjectConfigRegistry registry = new ProjectConfigRegistryImpl(idea.getMockProject()); final List<ClientConfig> added = new ArrayList<>(); final List<ClientConfig> removed = new ArrayList<>(); MessageBusClient.ProjectClient client = MessageBusClient.forProject(idea.getMockProject(), idea.getMockProject()); ClientConfigAddedMessage.addListener(client, this, e -> added.add(e.getClientConfig())); ClientConfigRemovedMessage.addListener(client, this, (e) -> removed.add(e.getClientConfig())); ClientConfig config = createClientConfig(); VirtualFile root = MockVirtualFileSystem.createRoot(); registry.addClientConfig(config, root); assertEquals(1, added.size()); added.clear(); registry.disposeComponent(); assertEquals(0, added.size()); assertEquals(1, removed.size()); assertSame(config, removed.get(0)); ClientConfig fetchedState = registry.getRegisteredClientConfigState(config.getClientServerRef()); assertNull(fetchedState); // closing the project should turn off further registration removed.clear(); assertThrows(Throwable.class, () -> registry.addClientConfig(config, root)); assertEquals(0, added.size()); assertThrows(Throwable.class, () -> registry.removeClientConfigAt(root)); assertEquals(0, removed.size()); }
@Test void projectClosed() { ProjectConfigRegistry registry = new ProjectConfigRegistryImpl(idea.getMockProject()); final List<ClientConfig> added = new ArrayList<>(); final List<ClientConfig> removed = new ArrayList<>(); MessageBusClient.ProjectClient client = MessageBusClient.forProject(idea.getMockProject(), idea.getMockProject()); ClientConfigAddedMessage.addListener(client, this, e -> added.add(e.getClientConfig())); ClientConfigRemovedMessage.addListener(client, this, (e) -> removed.add(e.getClientConfig())); ClientConfig config = createClientConfig(); VirtualFile root = MockVirtualFileSystem.createRoot(); registry.addClientConfig(config, root); assertEquals(1, added.size()); added.clear(); registry.projectClosed(); assertEquals(0, added.size()); assertEquals(1, removed.size()); assertSame(config, removed.get(0)); ClientConfig fetchedState = registry.getRegisteredClientConfigState(config.getClientServerRef()); assertNull(fetchedState); // closing the project should turn off further registration removed.clear(); assertThrows(Throwable.class, () -> registry.addClientConfig(config, root)); assertEquals(0, added.size()); assertThrows(Throwable.class, () -> registry.removeClientConfigAt(root)); assertEquals(0, removed.size()); }
@NotNull private P4CommandRunner.QueryAnswer<List<P4CommittedChangelist>> asyncLoadCommittedChanges( P4ChangeBrowserSettings settings, RepositoryLocation location, int maxCount) { if (LOG.isDebugEnabled()) { LOG.debug("Loading committed changes for " + location); } ProjectConfigRegistry registry = ProjectConfigRegistry.getInstance(project); if (location == null || registry == null) { return new DoneQueryAnswer<>(Collections.emptyList()); } if (location instanceof P4RepositoryLocation) { P4RepositoryLocation repo = (P4RepositoryLocation) location; ClientConfig clientConfig = registry.getRegisteredClientConfigState(repo.getClientServerRef()); if (clientConfig == null) { LOG.warn("Could not find configuration for " + repo.getClientServerRef()); return new DoneQueryAnswer<>(Collections.emptyList()); } P4Vcs vcs = P4Vcs.getInstance(project); return P4ServerComponent .query(project, clientConfig, new ListSubmittedChangelistsQuery(repo, settings.getQueryFilter(), maxCount)) .mapQuery((c) -> c.getChangesForVcs(vcs)); } LOG.warn("Cannot load changes for non-perforce repository location " + location); return new DoneQueryAnswer<>(Collections.emptyList()); }
/** * Force a sync from server operation to overwrite local changes. * @param files files to sync * @param exceptions exceptions encountered * @param listener listener on progress */ private void forceSync(List<FilePath> files, List<VcsException> exceptions, RollbackProgressListener listener) { if (files.isEmpty() || project.isDisposed()) { return; } ProjectConfigRegistry registry = ProjectConfigRegistry.getInstance(project); if (registry == null || registry.isDisposed()) { return; } groupFilesByClient(registry, files) .stream() .map(e -> P4ServerComponent .perform(project, e.getKey().getClientConfig(), new FetchFilesAction(e.getValue(), "", true)) .whenCompleted((c) -> listener.accept(e.getValue())) .whenServerError((ex) -> listener.accept(e.getValue())) .whenOffline(() -> listener.accept(e.getValue()))) .collect(ErrorCollectors.collectActionErrors(exceptions)) .whenCompleted((c) -> LOG.info("Completed sync of files")) .whenFailed((c) -> LOG.info("Failed to sync files")); }
public ClientConfigRoot addClientConfigRoot(TemporaryFolder tmp, String clientRootDir) { File base = tmp.newFile(clientRootDir); if (!base.mkdirs()) { throw new RuntimeException("Could not create directory " + base); } MockConfigPart cp1 = new MockConfigPart() .withClientname("cn") .withUsername("u") .withServerName("s:123"); ClientConfig cc = ClientConfig.createFrom(ServerConfig.createFrom(cp1), cp1); FilePath fp = VcsUtil.getFilePath(base); VirtualFile rootDir = Objects.requireNonNull(fp.getVirtualFile()); registry.addClientConfig(cc, rootDir); roots.add(rootDir); return Objects.requireNonNull(registry.getClientFor(rootDir)); }
ProjectConfigRegistry registry = ProjectConfigRegistry.getInstance(project); Pair<IdeChangelistMap, IdeFileMap> openedCache = cache.getServerOpenedCache(); if (registry != null && registry.isOnline(p4Change.getClientServerRef())) { info.addOnline(p4Change); } else {
@Test void removeClientConfig_registered() { ProjectConfigRegistry registry = new ProjectConfigRegistryImpl(idea.getMockProject()); final List<ClientConfig> added = new ArrayList<>(); final List<ClientConfig> removed = new ArrayList<>(); MessageBusClient.ProjectClient client = MessageBusClient.forProject(idea.getMockProject(), idea.getMockProject()); ClientConfigAddedMessage.addListener(client, this, e -> added.add(e.getClientConfig())); ClientConfigRemovedMessage.addListener(client, this, (e) -> removed.add(e.getClientConfig())); ClientConfig config = createClientConfig(); VirtualFile root = MockVirtualFileSystem.createRoot(); registry.addClientConfig(config, root); assertEquals(1, added.size()); added.clear(); registry.removeClientConfigAt(root); assertEquals(0, added.size()); assertEquals(1, removed.size()); assertSame(config, removed.get(0)); ClientConfig fetchedState = registry.getRegisteredClientConfigState(config.getClientServerRef()); assertNull(fetchedState); }
MockVirtualFile root = MockVirtualFileSystem.createRoot(); registry.addClientConfig(config, root); assertEquals(0, removed.size()); ClientConfig fetchedState = registry.getRegisteredClientConfigState(config.getClientServerRef()); assertNotNull(fetchedState); assertSame(config, fetchedState); registry.addClientConfig(config, root); registry.addClientConfig(createClientConfig(), root2); registry.addClientConfig(second, root); assertEquals(1, removed.size()); assertSame(config, removed.get(0)); fetchedState = registry.getRegisteredClientConfigState(second.getClientServerRef()); assertNotNull(fetchedState); assertSame(second, fetchedState); fetchedState = registry.getRegisteredClientConfigState(config.getClientServerRef()); assertNotNull(fetchedState); assertSame(config, fetchedState);
@Override public void actionPerformed(@NotNull VcsContext event) { final Project project = event.getProject(); if (project == null) { return; } final ProjectConfigRegistry registry = ProjectConfigRegistry.getInstance(project); if (registry == null) { return; } final List<ChangeList> changeLists = getSelectedChangeLists(event); if (changeLists.isEmpty()) { return; } if (ApplicationManager.getApplication().isDispatchThread()) { ApplicationManager.getApplication().saveAll(); } ApplicationManager.getApplication().executeOnPooledThread(() -> createSwarmReviews(project, registry, changeLists)); }
private Set<Map.Entry<ClientConfigRoot, List<FilePath>>> groupFilesByClient(@NotNull final ProjectConfigRegistry registry, @NotNull final List<FilePath> files) { // Note: can't use files.stream().collect(Collectors.groupingBy(registry::getClientFor)) // because the root might be null for a file, and the groupingBy doesn't allow for null keys. // See #195. // This fix also moves the null root check into this method, out of the stream processing. Map<ClientConfigRoot, List<FilePath>> ret = new HashMap<>(); files.forEach((f) -> { ClientConfigRoot root = registry.getClientFor(f); if (root != null) { ret.computeIfAbsent(root, (x) -> new ArrayList<>()).add(f); } else { LOG.info("Skipping revert for " + f + ": not in a Perforce root"); } }); return ret.entrySet(); } }
assertNotNull(root.getClientRootDir()); vcs.goOffline(root); assertFalse(vcs.registry.isOnline(root.getClientConfig().getClientServerRef()));
@Test void removeClientConfig_notRegistered() { ProjectConfigRegistry registry = new ProjectConfigRegistryImpl(idea.getMockProject()); final List<ClientConfig> removed = new ArrayList<>(); MessageBusClient.ProjectClient client = MessageBusClient.forProject(idea.getMockProject(), idea.getMockProject()); ClientConfigAddedMessage.addListener(client, this, e -> fail("should not have added anything")); ClientConfigRemovedMessage.addListener(client, this, (e) -> removed.add(e.getClientConfig())); ClientConfig config = createClientConfig(); registry.removeClientConfigAt(MockVirtualFileSystem.createRoot()); assertEquals(0, removed.size()); ClientConfig fetchedState = registry.getRegisteredClientConfigState(config.getClientServerRef()); assertNull(fetchedState); }
private ServerConfig getServerConfigForChangelistId(ProjectConfigRegistry registry, P4ChangelistId p4cl) { ClientConfig clientConfig = registry.getRegisteredClientConfigState(p4cl.getClientServerRef()); if (clientConfig != null) { return clientConfig.getServerConfig(); } return null; }
@Test void getComponentName() { ProjectConfigRegistry registry = new ProjectConfigRegistryImpl(idea.getMockProject()); assertSame(ProjectConfigRegistry.COMPONENT_NAME, registry.getComponentName()); }
@Nullable private ClientConfigRoot getRootFor(FilePath fp) { if (fp == null || project.isDisposed()) { return null; } ProjectConfigRegistry registry = ProjectConfigRegistry.getInstance(project); if (registry == null || registry.isDisposed()) { return null; } return registry.getClientFor(fp); }