Search in sources :

Example 6 with WriteAction

use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.

the class MavenDependencyCompletionAndResolutionTest method testRemovingExistingProjects.

public void testRemovingExistingProjects() throws Exception {
    final VirtualFile m = createModulePom("m1", "<groupId>project-group</groupId>" + "<artifactId>m1</artifactId>" + "<version>1</version>");
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + "  <dependency>" + "    <groupId>project-group</groupId>" + "    <artifactId><caret></artifactId>" + "  </dependency>" + "</dependencies>");
    importProjects(myProjectPom, m);
    assertCompletionVariants(myProjectPom, "m1");
    myProjectsManager.listenForExternalChanges();
    new WriteAction() {

        protected void run(@NotNull Result result) throws Throwable {
            m.delete(null);
        }
    }.execute();
    waitForReadingCompletion();
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + "  <dependency>" + "    <groupId>project-group</groupId>" + "    <artifactId><caret></artifactId>" + "  </dependency>" + "</dependencies>");
    assertCompletionVariants(myProjectPom);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) Result(com.intellij.openapi.application.Result)

Example 7 with WriteAction

use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.

the class ResourceFilteringTest method testUpdatingWhenPropertiesInFiltersAreChanged.

public void testUpdatingWhenPropertiesInFiltersAreChanged() throws Exception {
    final VirtualFile filter = createProjectSubFile("filters/filter.properties", "xxx=1");
    createProjectSubFile("resources/file.properties", "value=${xxx}");
    importProject("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<build>" + "  <filters>" + "    <filter>filters/filter.properties</filter>" + "  </filters>" + "  <resources>" + "    <resource>" + "      <directory>resources</directory>" + "      <filtering>true</filtering>" + "    </resource>" + "  </resources>" + "</build>");
    compileModules("project");
    assertResult("target/classes/file.properties", "value=1");
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            VfsUtil.saveText(filter, "xxx=2");
        }
    }.execute().throwException();
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    compileModules("project");
    assertResult("target/classes/file.properties", "value=2");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Example 8 with WriteAction

use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.

the class MavenProjectsManagerWatcher method start.

public synchronized void start() {
    final MessageBusConnection myBusConnection = myProject.getMessageBus().connect(myChangedDocumentsQueue);
    myBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, new MyFileChangeListener());
    myBusConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyRootChangesListener());
    myChangedDocumentsQueue.makeUserAware(myProject);
    myChangedDocumentsQueue.activate();
    myBusConnection.subscribe(ProjectTopics.MODULES, new ModuleListener() {

        @Override
        public void moduleRemoved(@NotNull Project project, @NotNull Module module) {
            MavenProject mavenProject = myManager.findProject(module);
            if (mavenProject != null && !myManager.isIgnored(mavenProject)) {
                VirtualFile file = mavenProject.getFile();
                if (myManager.isManagedFile(file) && myManager.getModules(mavenProject).isEmpty()) {
                    myManager.removeManagedFiles(Collections.singletonList(file));
                } else {
                    myManager.setIgnoredState(Collections.singletonList(mavenProject), true);
                }
            }
        }

        @Override
        public void moduleAdded(@NotNull final Project project, @NotNull final Module module) {
            // this method is needed to return non-ignored status for modules that were deleted (and thus ignored) and then created again with a different module type
            if (myManager.isMavenizedModule(module)) {
                MavenProject mavenProject = myManager.findProject(module);
                if (mavenProject != null)
                    myManager.setIgnoredState(Collections.singletonList(mavenProject), false);
            }
        }
    });
    DocumentAdapter myDocumentListener = new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent event) {
            Document doc = event.getDocument();
            VirtualFile file = FileDocumentManager.getInstance().getFile(doc);
            if (file == null)
                return;
            String fileName = file.getName();
            boolean isMavenFile = fileName.equals(MavenConstants.POM_XML) || fileName.equals(MavenConstants.PROFILES_XML) || isSettingsFile(file) || fileName.startsWith("pom.");
            if (!isMavenFile)
                return;
            synchronized (myChangedDocuments) {
                myChangedDocuments.add(doc);
            }
            myChangedDocumentsQueue.queue(new Update(MavenProjectsManagerWatcher.this) {

                @Override
                public void run() {
                    final Document[] copy;
                    synchronized (myChangedDocuments) {
                        copy = myChangedDocuments.toArray(new Document[myChangedDocuments.size()]);
                        myChangedDocuments.clear();
                    }
                    MavenUtil.invokeLater(myProject, () -> new WriteAction() {

                        @Override
                        protected void run(@NotNull Result result) throws Throwable {
                            for (Document each : copy) {
                                PsiDocumentManager.getInstance(myProject).commitDocument(each);
                                ((FileDocumentManagerImpl) FileDocumentManager.getInstance()).saveDocument(each, false);
                            }
                        }
                    }.execute());
                }
            });
        }
    };
    EditorFactory.getInstance().getEventMulticaster().addDocumentListener(myDocumentListener, myBusConnection);
    final MavenGeneralSettings.Listener mySettingsPathsChangesListener = new MavenGeneralSettings.Listener() {

        @Override
        public void changed() {
            updateSettingsFilePointers();
            onSettingsChange();
        }
    };
    myGeneralSettings.addListener(mySettingsPathsChangesListener);
    Disposer.register(myChangedDocumentsQueue, new Disposable() {

        @Override
        public void dispose() {
            myGeneralSettings.removeListener(mySettingsPathsChangesListener);
            mySettingsFilesPointers.clear();
        }
    });
    updateSettingsFilePointers();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Disposable(com.intellij.openapi.Disposable) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModuleListener(com.intellij.openapi.project.ModuleListener) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener) VirtualFilePointerListener(com.intellij.openapi.vfs.pointers.VirtualFilePointerListener) ModuleListener(com.intellij.openapi.project.ModuleListener) WriteAction(com.intellij.openapi.application.WriteAction) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) Document(com.intellij.openapi.editor.Document) Update(com.intellij.util.ui.update.Update) Result(com.intellij.openapi.application.Result) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module)

Example 9 with WriteAction

use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.

the class EditorTextFieldControl method setValue.

@Override
protected void setValue(final String value) {
    CommandProcessor.getInstance().runUndoTransparentAction(() -> new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            final T component = getComponent();
            final Document document = getEditorTextField(component).getDocument();
            document.replaceString(0, document.getTextLength(), value == null ? "" : value);
        }
    }.execute());
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Example 10 with WriteAction

use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.

the class StructureImportingTest method testParentInLocalRepository.

public void testParentInLocalRepository() throws Exception {
    if (!hasMavenInstallation())
        return;
    final VirtualFile parent = createModulePom("parent", "<groupId>test</groupId>" + "<artifactId>parent</artifactId>" + "<version>1</version>" + "<packaging>pom</packaging>" + "<dependencies>" + "  <dependency>" + "    <groupId>junit</groupId>" + "    <artifactId>junit</artifactId>" + "    <version>4.0</version>" + "  </dependency>" + "</dependencies>");
    executeGoal("parent", "install");
    new WriteAction() {

        protected void run(@NotNull Result result) throws Throwable {
            parent.delete(null);
        }
    }.execute();
    createProjectPom("<groupId>test</groupId>" + "<artifactId>m</artifactId>" + "<version>1</version>" + "<parent>" + "  <groupId>test</groupId>" + "  <artifactId>parent</artifactId>" + "  <version>1</version>" + "</parent>");
    importProject();
    assertModules("m");
    assertModuleLibDeps("m", "Maven: junit:junit:4.0");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) Result(com.intellij.openapi.application.Result)

Aggregations

Result (com.intellij.openapi.application.Result)85 WriteAction (com.intellij.openapi.application.WriteAction)85 NotNull (org.jetbrains.annotations.NotNull)38 VirtualFile (com.intellij.openapi.vfs.VirtualFile)37 File (java.io.File)20 IOException (java.io.IOException)16 Module (com.intellij.openapi.module.Module)10 PsiFile (com.intellij.psi.PsiFile)7 Sdk (com.intellij.openapi.projectRoots.Sdk)5 RunResult (com.intellij.openapi.application.RunResult)4 Document (com.intellij.openapi.editor.Document)4 Project (com.intellij.openapi.project.Project)4 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)4 Library (com.intellij.openapi.roots.libraries.Library)4 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)4 ModifiableFacetModel (com.intellij.facet.ModifiableFacetModel)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 FacetManager (com.intellij.facet.FacetManager)2 ProjectFacetManager (com.intellij.facet.ProjectFacetManager)2