use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class AbstractDataGetter method preLoadCommitData.
@NotNull
public TIntObjectHashMap<T> preLoadCommitData(@NotNull TIntHashSet commits) throws VcsException {
TIntObjectHashMap<T> result = new TIntObjectHashMap<>();
final MultiMap<VirtualFile, String> rootsAndHashes = MultiMap.create();
commits.forEach(commit -> {
CommitId commitId = myStorage.getCommitId(commit);
if (commitId != null) {
rootsAndHashes.putValue(commitId.getRoot(), commitId.getHash().asString());
}
return true;
});
for (Map.Entry<VirtualFile, Collection<String>> entry : rootsAndHashes.entrySet()) {
VcsLogProvider logProvider = myLogProviders.get(entry.getKey());
if (logProvider != null) {
List<? extends T> details = readDetails(logProvider, entry.getKey(), ContainerUtil.newArrayList(entry.getValue()));
for (T data : details) {
int index = myStorage.getCommitIndex(data.getId(), data.getRoot());
result.put(index, data);
}
saveInCache(result);
} else {
LOG.error("No log provider for root " + entry.getKey().getPath() + ". All known log providers " + myLogProviders);
}
}
return result;
}
use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class SimpleRefGroup method buildGroups.
public static void buildGroups(@NotNull MultiMap<VcsRefType, VcsRef> groupedRefs, boolean compact, boolean showTagNames, @NotNull List<RefGroup> result) {
if (groupedRefs.isEmpty())
return;
if (compact) {
VcsRef firstRef = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(groupedRefs.values()));
RefGroup group = ContainerUtil.getFirstItem(result);
if (group == null) {
result.add(new SimpleRefGroup(firstRef.getType().isBranch() || showTagNames ? firstRef.getName() : "", ContainerUtil.newArrayList(groupedRefs.values())));
} else {
group.getRefs().addAll(groupedRefs.values());
}
} else {
for (Map.Entry<VcsRefType, Collection<VcsRef>> entry : groupedRefs.entrySet()) {
if (entry.getKey().isBranch()) {
for (VcsRef ref : entry.getValue()) {
result.add(new SimpleRefGroup(ref.getName(), ContainerUtil.newArrayList(ref)));
}
} else {
result.add(new SimpleRefGroup(showTagNames ? ObjectUtils.notNull(ContainerUtil.getFirstItem(entry.getValue())).getName() : "", ContainerUtil.newArrayList(entry.getValue())));
}
}
}
}
use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class VcsLogRepoSizeCollector method groupRootsByVcs.
@NotNull
private static MultiMap<VcsKey, VirtualFile> groupRootsByVcs(@NotNull Map<VirtualFile, VcsLogProvider> providers) {
MultiMap<VcsKey, VirtualFile> result = MultiMap.create();
for (Map.Entry<VirtualFile, VcsLogProvider> entry : providers.entrySet()) {
VirtualFile root = entry.getKey();
VcsKey vcs = entry.getValue().getSupportedVcs();
result.putValue(vcs, root);
}
return result;
}
use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class CloudGitChooseAccountStepImpl method updateDataModel.
@Override
public void updateDataModel() {
super.updateDataModel();
final MultiMap<CloudGitProjectRoot, DetectedSourceRoot> project2sourceRoots = new MultiMap<>();
new RootIterator() {
CloudGitProjectRoot lastProjectRoot = null;
@Override
protected void processProjectRoot(CloudGitProjectRoot root) {
lastProjectRoot = root;
project2sourceRoots.put(lastProjectRoot, new ArrayList<>());
}
@Override
protected void processJavaSourceRoot(DetectedSourceRoot root) {
project2sourceRoots.putValue(lastProjectRoot, root);
}
}.iterate();
List<ModuleDescriptor> modules = new ArrayList<>(myProjectDescriptor.getModules());
for (Map.Entry<CloudGitProjectRoot, Collection<DetectedSourceRoot>> project2sourceRootsEntry : project2sourceRoots.entrySet()) {
final CloudGitProjectRoot projectRoot = project2sourceRootsEntry.getKey();
final File directory = projectRoot.getDirectory();
ModuleDescriptor moduleDescriptor = new ModuleDescriptor(directory, StdModuleTypes.JAVA, project2sourceRootsEntry.getValue());
final String applicationName = projectRoot.getApplicationName();
moduleDescriptor.addConfigurationUpdater(new ModuleBuilder.ModuleConfigurationUpdater() {
@Override
public void update(@NotNull final Module module, @NotNull ModifiableRootModel rootModel) {
final MessageBusConnection connection = module.getProject().getMessageBus().connect();
connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {
@Override
public void moduleAdded(@NotNull Project project, @NotNull Module addedModule) {
if (addedModule == module) {
StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> onModuleAdded(module));
connection.disconnect();
}
}
});
}
private void onModuleAdded(Module module) {
createRunConfiguration(module, applicationName);
GitInit.refreshAndConfigureVcsMappings(module.getProject(), projectRoot.getRepositoryRoot(), directory.getAbsolutePath());
}
});
modules.add(moduleDescriptor);
}
myProjectDescriptor.setModules(modules);
}
use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class GitRefManager method groupForTable.
@NotNull
@Override
public List<RefGroup> groupForTable(@NotNull Collection<VcsRef> references, boolean compact, boolean showTagNames) {
List<VcsRef> sortedReferences = ContainerUtil.sorted(references, myLabelsComparator);
MultiMap<VcsRefType, VcsRef> groupedRefs = ContainerUtil.groupBy(sortedReferences, VcsRef::getType);
List<RefGroup> result = ContainerUtil.newArrayList();
if (groupedRefs.isEmpty())
return result;
VcsRef head = null;
Map.Entry<VcsRefType, Collection<VcsRef>> firstGroup = ObjectUtils.notNull(ContainerUtil.getFirstItem(groupedRefs.entrySet()));
if (firstGroup.getKey().equals(HEAD)) {
head = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(firstGroup.getValue()));
groupedRefs.remove(HEAD, head);
}
GitRepository repository = getRepository(references);
if (repository != null) {
result.addAll(getTrackedRefs(groupedRefs, repository));
}
result.forEach(refGroup -> {
groupedRefs.remove(LOCAL_BRANCH, refGroup.getRefs().get(0));
groupedRefs.remove(REMOTE_BRANCH, refGroup.getRefs().get(1));
});
SimpleRefGroup.buildGroups(groupedRefs, compact, showTagNames, result);
if (head != null) {
if (repository != null && !repository.isOnBranch()) {
result.add(0, new SimpleRefGroup("!", Collections.singletonList(head)));
} else {
if (!result.isEmpty()) {
RefGroup first = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(result));
first.getRefs().add(0, head);
} else {
result.add(0, new SimpleRefGroup("", Collections.singletonList(head)));
}
}
}
return result;
}
Aggregations