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();
}
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;
}
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;
}
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();
}
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();
}
Aggregations