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