Search in sources :

Example 81 with WriteAction

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

the class Flexmojos3ImporterTest method testMainCassAndFinalName.

public void testMainCassAndFinalName() throws Exception {
    final VirtualFile file = createProjectSubFile("src/main/flex/SomeClass.mxml");
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            VfsUtil.saveText(file, "<mx:Application xmlns:mx=\"http://www.adobe.com/2006/mxml\"/>");
        }
    }.execute().throwException();
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    importProject(mavenProjectDescription("project", "swf") + "<build>" + "  <finalName>foo</finalName>" + "  <sourceDirectory>src/main/flex</sourceDirectory>" + "  <plugins>" + "    <plugin>" + flexmojosPlugin() + "      <dependencies>\n" + "        <dependency>\n" + "          <groupId>com.adobe.flex</groupId>\n" + "          <artifactId>compiler</artifactId>\n" + "          <version>3.5.0.12683</version>\n" + "          <type>pom</type>\n" + "        </dependency>\n" + "      </dependencies>\n" + "    </plugin>" + "  </plugins>" + "</build>" + flexFrameworkDependency("3.5.0.12683"));
    performPostImportTasks();
    checkBCCount("project", 1);
    checkBC("project", "project", new BuildConfigurationNature(Web, false, Application), "SomeClass", "foo.swf", "target", "3.5.0.12683", "en_US", "target/foo-config-report.xml");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) BuildConfigurationNature(com.intellij.flex.model.bc.BuildConfigurationNature) WriteAction(com.intellij.openapi.application.WriteAction) NotNull(org.jetbrains.annotations.NotNull) MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult) Result(com.intellij.openapi.application.Result)

Example 82 with WriteAction

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

the class JavaStepDefinitionCreator method getDefaultStepDefinitionFolder.

@NotNull
@Override
public PsiDirectory getDefaultStepDefinitionFolder(@NotNull final GherkinStep step) {
    PsiFile featureFile = step.getContainingFile();
    if (featureFile != null) {
        PsiDirectory psiDirectory = featureFile.getContainingDirectory();
        final Project project = step.getProject();
        if (psiDirectory != null) {
            ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
            VirtualFile directory = psiDirectory.getVirtualFile();
            if (projectFileIndex.isInContent(directory)) {
                VirtualFile sourceRoot = projectFileIndex.getSourceRootForFile(directory);
                //noinspection ConstantConditions
                final Module module = projectFileIndex.getModuleForFile(featureFile.getVirtualFile());
                if (module != null) {
                    final VirtualFile[] sourceRoots = ModuleRootManager.getInstance(module).getSourceRoots();
                    if (sourceRoot != null && sourceRoot.getName().equals("resources")) {
                        final VirtualFile resourceParent = sourceRoot.getParent();
                        for (VirtualFile vFile : sourceRoots) {
                            if (vFile.getPath().startsWith(resourceParent.getPath()) && vFile.getName().equals("java")) {
                                sourceRoot = vFile;
                                break;
                            }
                        }
                    } else {
                        if (sourceRoots.length > 0) {
                            sourceRoot = sourceRoots[sourceRoots.length - 1];
                        }
                    }
                }
                String packageName = "";
                if (sourceRoot != null) {
                    packageName = CucumberJavaUtil.getPackageOfStepDef(step);
                }
                final String packagePath = packageName.replace('.', '/');
                final String path = sourceRoot != null ? sourceRoot.getPath() : directory.getPath();
                // ToDo: I shouldn't create directories, only create VirtualFile object.
                final Ref<PsiDirectory> resultRef = new Ref<>();
                new WriteAction() {

                    protected void run(@NotNull Result result) throws Throwable {
                        final VirtualFile packageFile = VfsUtil.createDirectoryIfMissing(path + '/' + packagePath);
                        if (packageFile != null) {
                            resultRef.set(PsiDirectoryFactory.getInstance(project).createDirectory(packageFile));
                        }
                    }
                }.execute();
                return resultRef.get();
            }
        }
    }
    assert featureFile != null;
    return ObjectUtils.assertNotNull(featureFile.getParent());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) Result(com.intellij.openapi.application.Result) Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 83 with WriteAction

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

the class HeavyOsgiFixtureTestCase method loadModules.

private static void loadModules(String projectName, final Project project, String projectDirPath) throws Exception {
    final File projectDir = OsgiTestUtil.extractProject(projectName, projectDirPath);
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            VirtualFile virtualDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(projectDir);
            assertNotNull(projectDir.getPath(), virtualDir);
            for (File moduleDir : projectDir.listFiles(VISIBLE_DIR_FILTER)) {
                File moduleFile = new File(moduleDir, moduleDir.getName() + ".iml");
                if (moduleFile.exists()) {
                    LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleFile);
                    ModuleManager.getInstance(project).loadModule(moduleFile.getPath());
                }
            }
        }
    }.execute();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Result(com.intellij.openapi.application.Result)

Example 84 with WriteAction

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

the class RubyMotionFacetConfigurator method configure.

public static void configure(VirtualFile baseDir, Module module) {
    final RubyMotionFacet existingFacet = RubyMotionFacet.getInstance(module);
    if (existingFacet != null) {
        return;
    }
    FacetManager facetManager = FacetManager.getInstance(module);
    final ModifiableFacetModel model = facetManager.createModifiableModel();
    RubyMotionFacetType facetType = RubyMotionFacetType.getInstance();
    RubyMotionFacetConfiguration configuration = ProjectFacetManager.getInstance(module.getProject()).createDefaultConfiguration(facetType);
    //configuration.setProjectRootPath(baseDir.getPath());
    VirtualFile testFolder = baseDir.findChild("spec");
    final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
    if (testFolder != null) {
        //configuration.setTestPath(testFolder.getPath());
        addTestSources(testFolder, rootModel);
    }
    VirtualFile libFolder = baseDir.findChild("app");
    if (libFolder != null) {
    //configuration.setLibPath(libFolder.getPath());
    }
    RubyMotionFacet.updateMotionLibrary(rootModel);
    IdeaInternalUtil.runInsideWriteAction(new ActionRunner.InterruptibleRunnable() {

        public void run() throws Exception {
            rootModel.commit();
        }
    });
    RubyMotionFacet facet = facetManager.createFacet(facetType, facetType.getDefaultFacetName(), configuration, null);
    model.addFacet(facet);
    new WriteAction() {

        protected void run(@NotNull final Result result) throws Throwable {
            model.commit();
        }
    }.execute();
    RubyMotionUtilExt.createMotionRunConfiguration(module);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ActionRunner(com.intellij.util.ActionRunner) WriteAction(com.intellij.openapi.application.WriteAction) RubyMotionFacetType(org.jetbrains.plugins.ruby.motion.facet.RubyMotionFacetType) RubyMotionFacetConfiguration(org.jetbrains.plugins.ruby.motion.facet.RubyMotionFacetConfiguration) Result(com.intellij.openapi.application.Result) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) RubyMotionFacet(org.jetbrains.plugins.ruby.motion.facet.RubyMotionFacet) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) ProjectFacetManager(com.intellij.facet.ProjectFacetManager) FacetManager(com.intellij.facet.FacetManager)

Example 85 with WriteAction

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

the class RubyMotionFacetConfigurator method configureSdk.

private static void configureSdk(final Project project) {
    final ProjectRootManager manager = ProjectRootManager.getInstance(project);
    final Sdk sdk = manager.getProjectSdk();
    if (!RubySdkUtil.isNativeRuby19(sdk)) {
        for (final Sdk newSdk : ProjectJdkTable.getInstance().getSdksOfType(RubySdkType.getInstance())) {
            if (RubySdkUtil.isNativeRuby19(newSdk) && !RubySdkUtil.isNativeRuby20(newSdk) && !RubyRemoteInterpreterManager.getInstance().isRemoteSdk(newSdk)) {
                new WriteAction() {

                    @Override
                    protected void run(@NotNull Result result) throws Throwable {
                        ProjectRootManager.getInstance(project).setProjectSdk(newSdk);
                    }
                }.execute();
            }
        }
    }
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) Sdk(com.intellij.openapi.projectRoots.Sdk) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) 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