Search in sources :

Example 16 with WriteAction

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

the class PackagingElementsTestCase method addProjectLibrary.

static Library addProjectLibrary(final Project project, @Nullable final Module module, final String name, final DependencyScope scope, final VirtualFile[] jars) {
    return new WriteAction<Library>() {

        @Override
        protected void run(@NotNull final Result<Library> result) {
            final Library library = LibraryTablesRegistrar.getInstance().getLibraryTable(project).createLibrary(name);
            final Library.ModifiableModel libraryModel = library.getModifiableModel();
            for (VirtualFile jar : jars) {
                libraryModel.addRoot(jar, OrderRootType.CLASSES);
            }
            libraryModel.commit();
            if (module != null) {
                ModuleRootModificationUtil.addDependency(module, library, scope, false);
            }
            result.setResult(library);
        }
    }.execute().getResultObject();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) Library(com.intellij.openapi.roots.libraries.Library) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Example 17 with WriteAction

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

the class ArtifactLoadingErrorDescription method ignoreInvalidElement.

@Override
public void ignoreInvalidElement() {
    final ModifiableArtifactModel model = ArtifactManager.getInstance(myProject).createModifiableModel();
    model.removeArtifact(myArtifact);
    new WriteAction() {

        protected void run(@NotNull final Result result) {
            model.commit();
        }
    }.execute();
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) ModifiableArtifactModel(com.intellij.packaging.artifacts.ModifiableArtifactModel) Result(com.intellij.openapi.application.Result)

Example 18 with WriteAction

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

the class BaseCompilerTestCase method copyToProject.

protected void copyToProject(String relativePath) {
    File dir = PathManagerEx.findFileUnderProjectHome(relativePath, getClass());
    final File target = new File(FileUtil.toSystemDependentName(getProjectBasePath()));
    try {
        FileUtil.copyDir(dir, target);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    new WriteAction() {

        @Override
        protected void run(@NotNull final Result result) {
            VirtualFile virtualDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(target);
            assertNotNull(target.getAbsolutePath() + " not found", virtualDir);
            virtualDir.refresh(false, true);
        }
    }.execute();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) File(java.io.File) Result(com.intellij.openapi.application.Result)

Example 19 with WriteAction

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

the class AbstractQuickFixMultiFileTest method createVirtualFileFromTestFile.

/**
     * @param sourceRootDir Base path of test file(Test source directory)
     * @param testFile      source of VFile content
     * @return created VirtualFile
     */
protected static VirtualFile createVirtualFileFromTestFile(File sourceRootDir, final TestFile testFile) {
    try {
        assertFalse("Please don't use absolute path for multifile test 'FILE' directive: " + testFile.path, FileUtil.isAbsolutePlatformIndependent(testFile.path));
        FileType fileType = guessFileType(testFile);
        String extension = fileType.getDefaultExtension();
        final File fileInSourceRoot = new File(testFile.path);
        File container = FileUtil.getParentFile(fileInSourceRoot);
        if (container == null) {
            container = sourceRootDir;
        } else {
            container = new File(sourceRootDir, container.getPath());
        }
        if (!container.exists()) {
            assertTrue(container.mkdirs());
        }
        final File tempFile = FileUtil.createTempFile(container, FileUtil.getNameWithoutExtension(testFile.path), "." + extension, true);
        final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempFile);
        assert vFile != null;
        new WriteAction() {

            @Override
            protected void run(@NotNull Result result) throws Throwable {
                vFile.setCharset(CharsetToolkit.UTF8_CHARSET);
                VfsUtil.saveText(vFile, testFile.content);
            }
        }.execute();
        return vFile;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) KotlinFileType(org.jetbrains.kotlin.idea.KotlinFileType) PlainTextFileType(com.intellij.openapi.fileTypes.PlainTextFileType) JavaFileType(com.intellij.ide.highlighter.JavaFileType) FileType(com.intellij.openapi.fileTypes.FileType) WriteAction(com.intellij.openapi.application.WriteAction) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File) Result(com.intellij.openapi.application.Result)

Example 20 with WriteAction

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

the class GradleImportingTestCase method setUp.

@Override
public void setUp() throws Exception {
    myJdkHome = IdeaTestUtil.requireRealJdkHome();
    super.setUp();
    assumeThat(gradleVersion, versionMatcherRule.getMatcher());
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            Sdk oldJdk = ProjectJdkTable.getInstance().findJdk(GRADLE_JDK_NAME);
            if (oldJdk != null) {
                ProjectJdkTable.getInstance().removeJdk(oldJdk);
            }
            VirtualFile jdkHomeDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(myJdkHome));
            assert jdkHomeDir != null;
            Sdk jdk = SdkConfigurationUtil.setupSdk(new Sdk[0], jdkHomeDir, JavaSdk.getInstance(), true, null, GRADLE_JDK_NAME);
            assertNotNull("Cannot create JDK for " + myJdkHome, jdk);
            ProjectJdkTable.getInstance().addJdk(jdk);
        }
    }.execute();
    myProjectSettings = new GradleProjectSettings();
    GradleSettings.getInstance(myProject).setGradleVmOptions("-Xmx128m -XX:MaxPermSize=64m");
    System.setProperty(ExternalSystemExecutionSettings.REMOTE_PROCESS_IDLE_TTL_IN_MS_KEY, String.valueOf(GRADLE_DAEMON_TTL_MS));
    configureWrapper();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) 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