Search in sources :

Example 31 with WriteAction

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

the class TempDirTestFixtureImpl method getFile.

@Override
public VirtualFile getFile(@NotNull final String path) {
    return new WriteAction<VirtualFile>() {

        @Override
        protected void run(@NotNull Result<VirtualFile> result) throws IOException {
            final String fullPath = myTempDir.getCanonicalPath() + '/' + path;
            final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(fullPath);
            result.setResult(file);
        }
    }.execute().getResultObject();
}
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 32 with WriteAction

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

the class CodeInsightTestFixtureImpl method copyFileToProject.

@NotNull
@Override
public VirtualFile copyFileToProject(@NotNull String sourcePath, @NotNull String targetPath) {
    String testDataPath = getTestDataPath();
    File sourceFile = FileUtil.findFirstThatExist(testDataPath + '/' + sourcePath, sourcePath);
    VirtualFile targetFile = myTempDirFixture.getFile(targetPath);
    if (sourceFile == null && targetFile != null && targetPath.equals(sourcePath)) {
        return targetFile;
    }
    assertNotNull("Cannot find source file: " + sourcePath + "; test data path: " + testDataPath, sourceFile);
    assertTrue("Not a file: " + sourceFile, sourceFile.isFile());
    if (targetFile == null) {
        targetFile = myTempDirFixture.createFile(targetPath);
        VfsTestUtil.assertFilePathEndsWithCaseSensitivePath(targetFile, sourcePath);
        targetFile.putUserData(VfsTestUtil.TEST_DATA_FILE_PATH, sourceFile.getAbsolutePath());
    }
    final File _source = sourceFile;
    final VirtualFile _target = targetFile;
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws IOException {
            _target.setBinaryContent(FileUtil.loadFileBytes(_source));
        }
    }.execute();
    return targetFile;
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) File(java.io.File) Result(com.intellij.openapi.application.Result) NotNull(org.jetbrains.annotations.NotNull)

Example 33 with WriteAction

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

the class NonProjectFileAccessTest method createFileExternally.

@NotNull
private VirtualFile createFileExternally(File dir) {
    VirtualFile result = new WriteAction<VirtualFile>() {

        @Override
        protected void run(@NotNull Result<VirtualFile> result) throws Throwable {
            // create externally, since files created via VFS are marked for editing automatically
            File file = new File(dir, FileUtil.createSequentFileName(dir, "extfile", "txt"));
            assertTrue(file.createNewFile());
            result.setResult(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file));
        }
    }.execute().getResultObject();
    myCreatedFiles.add(result);
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) NotNull(org.jetbrains.annotations.NotNull) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Result(com.intellij.openapi.application.Result) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with WriteAction

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

the class AndroidGradleTestCase method createModule.

@NotNull
protected Module createModule(@NotNull String name, @NotNull ModuleType type) {
    VirtualFile projectRootFolder = getProject().getBaseDir();
    assertNotNull(projectRootFolder);
    final File moduleFile = new File(virtualToIoFile(projectRootFolder), name + ModuleFileType.DOT_DEFAULT_EXTENSION);
    createIfDoesntExist(moduleFile);
    return new WriteAction<Module>() {

        @Override
        protected void run(@NotNull Result<Module> result) throws Throwable {
            VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleFile);
            assertNotNull(virtualFile);
            Module module = ModuleManager.getInstance(getProject()).newModule(virtualFile.getPath(), type.getId());
            module.getModuleFile();
            result.setResult(module);
        }
    }.execute().getResultObject();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File) TestUtils.getWorkspaceFile(com.android.testutils.TestUtils.getWorkspaceFile) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) GradleInvocationResult(com.android.tools.idea.gradle.project.build.invoker.GradleInvocationResult) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with WriteAction

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

the class AppEngineSupportProvider method addProjectLibrary.

private static Library addProjectLibrary(final Module module, final String name, final List<String> jarDirectories, final VirtualFile[] sources) {
    return new WriteAction<Library>() {

        protected void run(@NotNull final Result<Library> result) {
            final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(module.getProject());
            Library library = libraryTable.getLibraryByName(name);
            if (library == null) {
                library = libraryTable.createLibrary(name);
                final Library.ModifiableModel model = library.getModifiableModel();
                for (String path : jarDirectories) {
                    String url = VfsUtilCore.pathToUrl(path);
                    VirtualFileManager.getInstance().refreshAndFindFileByUrl(url);
                    model.addJarDirectory(url, false);
                }
                for (VirtualFile sourceRoot : sources) {
                    model.addRoot(sourceRoot, OrderRootType.SOURCES);
                }
                model.commit();
            }
            result.setResult(library);
        }
    }.execute().getResultObject();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) WriteAction(com.intellij.openapi.application.WriteAction) Library(com.intellij.openapi.roots.libraries.Library) NotNull(org.jetbrains.annotations.NotNull) ValidationResult(com.intellij.facet.ui.ValidationResult) 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