Search in sources :

Example 46 with Consumer

use of com.intellij.util.Consumer in project intellij-community by JetBrains.

the class ExternalSystemFacadeManager method onProjectRename.

private static <V> void onProjectRename(@NotNull Map<IntegrationKey, V> data, @NotNull String oldName, @NotNull String newName) {
    Set<IntegrationKey> keys = ContainerUtilRt.newHashSet(data.keySet());
    for (IntegrationKey key : keys) {
        if (!key.getIdeProjectName().equals(oldName)) {
            continue;
        }
        IntegrationKey newKey = new IntegrationKey(newName, key.getIdeProjectLocationHash(), key.getExternalSystemId(), key.getExternalProjectConfigPath());
        V value = data.get(key);
        data.put(newKey, value);
        data.remove(key);
        if (value instanceof Consumer) {
            //noinspection unchecked
            ((Consumer) value).consume(newKey);
        }
    }
}
Also used : IntegrationKey(com.intellij.openapi.externalSystem.util.IntegrationKey) Consumer(com.intellij.util.Consumer)

Example 47 with Consumer

use of com.intellij.util.Consumer in project intellij-community by JetBrains.

the class GroovyConsole method getOrCreateConsole.

public static void getOrCreateConsole(@NotNull final Project project, @NotNull final VirtualFile contentFile, @NotNull final Consumer<GroovyConsole> callback) {
    final GroovyConsole existingConsole = contentFile.getUserData(GROOVY_CONSOLE);
    if (existingConsole != null)
        return;
    final Consumer<Module> initializer = module -> {
        final GroovyConsole console = createConsole(project, contentFile, module);
        if (console != null) {
            callback.consume(console);
        }
    };
    final Module module = GroovyConsoleStateService.getInstance(project).getSelectedModule(contentFile);
    if (module == null || module.isDisposed()) {
        // if not, then select module, then run initializer
        GroovyConsoleUtil.selectModuleAndRun(project, initializer);
    } else {
        // if module for console is already selected, then use it for creation
        initializer.consume(module);
    }
}
Also used : ExecutionManager(com.intellij.execution.ExecutionManager) PathsList(com.intellij.util.PathsList) ExecutionException(com.intellij.execution.ExecutionException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) com.intellij.execution.process(com.intellij.execution.process) GroovyScriptRunConfiguration(org.jetbrains.plugins.groovy.runner.GroovyScriptRunConfiguration) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType) Charset(java.nio.charset.Charset) CloseAction(com.intellij.execution.ui.actions.CloseAction) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) OutputStream(java.io.OutputStream) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) ConsoleViewImpl(com.intellij.execution.impl.ConsoleViewImpl) StringUtil(com.intellij.openapi.util.text.StringUtil) DefaultGroovyScriptRunner(org.jetbrains.plugins.groovy.runner.DefaultGroovyScriptRunner) Key(com.intellij.openapi.util.Key) GroovyScriptRunner(org.jetbrains.plugins.groovy.runner.GroovyScriptRunner) IOException(java.io.IOException) Executor(com.intellij.execution.Executor) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) ConsoleView(com.intellij.execution.ui.ConsoleView) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) JavaParameters(com.intellij.execution.configurations.JavaParameters) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) javax.swing(javax.swing) Module(com.intellij.openapi.module.Module)

Example 48 with Consumer

use of com.intellij.util.Consumer in project intellij-community by JetBrains.

the class GitCherryPicker method createChangeListAfterUpdate.

@Nullable
private LocalChangeList createChangeListAfterUpdate(@NotNull final VcsFullCommitDetails commit, @NotNull final Collection<FilePath> paths, @NotNull final String commitMessage) {
    final CountDownLatch waiter = new CountDownLatch(1);
    final AtomicReference<LocalChangeList> changeList = new AtomicReference<>();
    ApplicationManager.getApplication().invokeAndWait(new Runnable() {

        @Override
        public void run() {
            myChangeListManager.invokeAfterUpdate(new Runnable() {

                public void run() {
                    changeList.set(createChangeListIfThereAreChanges(commit, commitMessage));
                    waiter.countDown();
                }
            }, InvokeAfterUpdateMode.SILENT_CALLBACK_POOLED, "Cherry-pick", new Consumer<VcsDirtyScopeManager>() {

                public void consume(VcsDirtyScopeManager vcsDirtyScopeManager) {
                    vcsDirtyScopeManager.filePathsDirty(paths, null);
                }
            }, ModalityState.NON_MODAL);
        }
    }, ModalityState.NON_MODAL);
    try {
        boolean success = waiter.await(100, TimeUnit.SECONDS);
        if (!success) {
            LOG.error("Couldn't await for changelist manager refresh");
        }
    } catch (InterruptedException e) {
        LOG.error(e);
        return null;
    }
    return changeList.get();
}
Also used : Consumer(com.intellij.util.Consumer) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(org.jetbrains.annotations.Nullable)

Example 49 with Consumer

use of com.intellij.util.Consumer in project intellij-community by JetBrains.

the class MvcModuleStructureUtil method getUpdateProjectStructureActions.

private static Pair<Collection<Consumer<ModifiableRootModel>>, Collection<Consumer<ModifiableFacetModel>>> getUpdateProjectStructureActions(Collection<VirtualFile> appRoots, MvcProjectStructure structure) {
    for (final VirtualFile appRoot : ModuleRootManager.getInstance(structure.myModule).getContentRoots()) {
        appRoot.refresh(false, false);
    }
    Collection<Consumer<ModifiableRootModel>> actions = ContainerUtil.newArrayList();
    removeInvalidSourceRoots(actions, structure);
    cleanupDefaultLibrary(structure.myModule, actions, appRoots, structure.getUserLibraryName());
    moveupLibrariesFromMavenPlugin(structure.myModule, actions);
    List<VirtualFile> rootsToFacetSetup = new ArrayList<>(appRoots.size());
    for (VirtualFile appRoot : appRoots) {
        if (checkValidity(appRoot)) {
            ContainerUtil.addIfNotNull(actions, addSourceRootsAndLibDirectory(appRoot, structure));
            rootsToFacetSetup.add(appRoot);
        }
    }
    Collection<Consumer<ModifiableFacetModel>> facetActions = ContainerUtil.newArrayList();
    structure.setupFacets(facetActions, rootsToFacetSetup);
    return Pair.create(actions, facetActions);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Consumer(com.intellij.util.Consumer)

Example 50 with Consumer

use of com.intellij.util.Consumer in project intellij-community by JetBrains.

the class MvcModuleStructureUtil method addSourceRootsAndLibDirectory.

@Nullable
private static Consumer<ModifiableRootModel> addSourceRootsAndLibDirectory(@NotNull final VirtualFile root, final MvcProjectStructure structure) {
    ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(structure.myModule);
    Map<VirtualFile, JpsModuleSourceRootType<?>> sourceRoots = new HashMap<>();
    for (ContentEntry entry : moduleRootManager.getContentEntries()) {
        for (SourceFolder folder : entry.getSourceFolders()) {
            sourceRoots.put(folder.getFile(), folder.getRootType());
        }
    }
    root.refresh(false, true);
    final List<Consumer<ContentEntry>> actions = ContainerUtil.newArrayList();
    for (Map.Entry<JpsModuleSourceRootType<?>, Collection<String>> entry : structure.getSourceFolders().entrySet()) {
        JpsModuleSourceRootType<?> rootType = entry.getKey();
        for (String src : entry.getValue()) {
            addSourceFolder(root, src, rootType, actions, sourceRoots);
        }
    }
    for (final String src : structure.getInvalidSourceFolders()) {
        removeSrcFolderFromRoots(root.findFileByRelativePath(src), actions, sourceRoots);
    }
    for (final VirtualFile excluded : structure.getExcludedFolders(root)) {
        if (moduleRootManager.getFileIndex().isInContent(excluded)) {
            actions.add(contentEntry -> contentEntry.addExcludeFolder(excluded));
        }
    }
    final Consumer<ModifiableRootModel> modifyLib = addJarDirectory(root, structure.myModule, structure.getUserLibraryName());
    if (actions.isEmpty() && modifyLib == null && findContentEntry(moduleRootManager, root) != null) {
        return null;
    }
    return model -> {
        ContentEntry contentEntry = findContentEntry(model, root);
        if (contentEntry == null) {
            contentEntry = model.addContentEntry(root);
        }
        for (final Consumer<ContentEntry> action : actions) {
            action.consume(contentEntry);
        }
        if (modifyLib != null) {
            modifyLib.consume(model);
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) java.util(java.util) Application(com.intellij.openapi.application.Application) ArrayUtil(com.intellij.util.ArrayUtil) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ModuleManager(com.intellij.openapi.module.ModuleManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonNls(org.jetbrains.annotations.NonNls) Computable(com.intellij.openapi.util.Computable) ContainerUtil(com.intellij.util.containers.ContainerUtil) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) PsiManager(com.intellij.psi.PsiManager) com.intellij.openapi.roots(com.intellij.openapi.roots) Library(com.intellij.openapi.roots.libraries.Library) Comparing(com.intellij.openapi.util.Comparing) SmartList(com.intellij.util.SmartList) JpsModuleSourceRootType(org.jetbrains.jps.model.module.JpsModuleSourceRootType) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) MultiMap(com.intellij.util.containers.MultiMap) CommonProcessors(com.intellij.util.CommonProcessors) StdModuleTypes(com.intellij.openapi.module.StdModuleTypes) LibraryUtil(com.intellij.openapi.roots.libraries.LibraryUtil) ModifiableModelCommitter(com.intellij.openapi.roots.impl.ModifiableModelCommitter) JavaSourceRootType(org.jetbrains.jps.model.java.JavaSourceRootType) Key(com.intellij.openapi.util.Key) IOException(java.io.IOException) FacetManager(com.intellij.facet.FacetManager) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) ModuleDeleteProvider(com.intellij.openapi.roots.ui.configuration.actions.ModuleDeleteProvider) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) VfsUtil(com.intellij.openapi.vfs.VfsUtil) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) JpsModuleSourceRootType(org.jetbrains.jps.model.module.JpsModuleSourceRootType) Consumer(com.intellij.util.Consumer) MultiMap(com.intellij.util.containers.MultiMap) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Consumer (com.intellij.util.Consumer)59 NotNull (org.jetbrains.annotations.NotNull)41 Project (com.intellij.openapi.project.Project)37 Nullable (org.jetbrains.annotations.Nullable)33 VirtualFile (com.intellij.openapi.vfs.VirtualFile)26 List (java.util.List)22 ApplicationManager (com.intellij.openapi.application.ApplicationManager)17 StringUtil (com.intellij.openapi.util.text.StringUtil)17 javax.swing (javax.swing)16 ContainerUtil (com.intellij.util.containers.ContainerUtil)15 Logger (com.intellij.openapi.diagnostic.Logger)14 Module (com.intellij.openapi.module.Module)12 java.awt (java.awt)12 Pair (com.intellij.openapi.util.Pair)11 java.util (java.util)11 File (java.io.File)10 Collection (java.util.Collection)10 PsiElement (com.intellij.psi.PsiElement)9 PsiFile (com.intellij.psi.PsiFile)9 DataContext (com.intellij.openapi.actionSystem.DataContext)8