Search in sources :

Example 41 with WriteAction

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

the class LibraryOptionsPanel method doConfigure.

private void doConfigure() {
    switch(myButtonEnumModel.getSelected()) {
        case DOWNLOAD:
            final LibraryDownloadSettings oldDownloadSettings = mySettings.getDownloadSettings();
            LOG.assertTrue(oldDownloadSettings != null);
            final LibraryDownloadSettings newDownloadSettings = DownloadingOptionsDialog.showDialog(myPanel, oldDownloadSettings, mySettings.getCompatibleVersions(), true);
            if (newDownloadSettings != null) {
                mySettings.setDownloadSettings(newDownloadSettings);
            }
            break;
        case USE_LIBRARY:
            final Object item = myExistingLibraryComboBox.getSelectedItem();
            if (item instanceof LibraryEditor) {
                EditLibraryDialog dialog = new EditLibraryDialog(myPanel, mySettings, (LibraryEditor) item);
                dialog.show();
                if (item instanceof ExistingLibraryEditor) {
                    new WriteAction() {

                        protected void run(@NotNull final Result result) {
                            ((ExistingLibraryEditor) item).commit();
                        }
                    }.execute();
                }
            }
            break;
        case USE_FROM_PROVIDER:
        case SETUP_LIBRARY_LATER:
            break;
    }
    updateState();
}
Also used : ExistingLibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor) ExistingLibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor) NewLibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor) LibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor) WriteAction(com.intellij.openapi.application.WriteAction) Result(com.intellij.openapi.application.Result)

Example 42 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 43 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)

Example 44 with WriteAction

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

the class GradleImportingTestCase method configureWrapper.

private void configureWrapper() throws IOException, URISyntaxException {
    URI distributionUri = new AbstractModelBuilderTest.DistributionLocator().getDistributionFor(GradleVersion.version(gradleVersion));
    myProjectSettings.setDistributionType(DistributionType.DEFAULT_WRAPPED);
    final VirtualFile wrapperJarFrom = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(wrapperJar());
    assert wrapperJarFrom != null;
    final VirtualFile wrapperJarFromTo = createProjectSubFile("gradle/wrapper/gradle-wrapper.jar");
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            wrapperJarFromTo.setBinaryContent(wrapperJarFrom.contentsToByteArray());
        }
    }.execute().throwException();
    Properties properties = new Properties();
    properties.setProperty("distributionBase", "GRADLE_USER_HOME");
    properties.setProperty("distributionPath", "wrapper/dists");
    properties.setProperty("zipStoreBase", "GRADLE_USER_HOME");
    properties.setProperty("zipStorePath", "wrapper/dists");
    properties.setProperty("distributionUrl", distributionUri.toString());
    StringWriter writer = new StringWriter();
    properties.store(writer, null);
    createProjectSubFile("gradle/wrapper/gradle-wrapper.properties", writer.toString());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StringWriter(java.io.StringWriter) WriteAction(com.intellij.openapi.application.WriteAction) Properties(java.util.Properties) URI(java.net.URI) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Example 45 with WriteAction

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

the class AddFacetTest method testAddFacetAfterCreatingManifest.

public void testAddFacetAfterCreatingManifest() {
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            VirtualFile[] roots = ModuleRootManager.getInstance(myModule).getContentRoots();
            VirtualFile metaInf = roots[0].createChildDirectory(this, "META-INF");
            VirtualFile manifest = metaInf.createChildData(this, "MANIFEST.MF");
            VfsUtil.saveText(manifest, "Manifest-Version: 1.0\n" + "Bundle-ManifestVersion: 2\n" + "Bundle-Name: Test\n" + "Bundle-SymbolicName: test\n" + "Bundle-Version: 1.0.0\n");
            PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
        }
    }.execute();
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            ModifiableFacetModel model = FacetManager.getInstance(myModule).createModifiableModel();
            OsmorcFacet facet = new OsmorcFacet(myModule);
            facet.getConfiguration().setManifestGenerationMode(ManifestGenerationMode.Manually);
            model.addFacet(facet);
            model.commit();
        }
    }.execute();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) 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