Search in sources :

Example 36 with WriteAction

use of com.intellij.openapi.application.WriteAction in project intellij-community 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));
            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) ZipFile(java.util.zip.ZipFile) File(java.io.File) Result(com.intellij.openapi.application.Result)

Example 37 with WriteAction

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

the class GradleImportingTestCase method tearDown.

@Override
public void tearDown() throws Exception {
    if (myJdkHome == null) {
        //super.setUp() wasn't called
        return;
    }
    try {
        new WriteAction() {

            @Override
            protected void run(@NotNull Result result) throws Throwable {
                Sdk old = ProjectJdkTable.getInstance().findJdk(GRADLE_JDK_NAME);
                if (old != null) {
                    SdkConfigurationUtil.removeSdk(old);
                }
            }
        }.execute();
        Messages.setTestDialog(TestDialog.DEFAULT);
        FileUtil.delete(BuildManager.getInstance().getBuildSystemDirectory());
    } finally {
        super.tearDown();
    }
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) Result(com.intellij.openapi.application.Result)

Example 38 with WriteAction

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

the class GradleImportingTestCase method configureWrapper.

private void configureWrapper() throws IOException, URISyntaxException {
    final URI distributionUri = new 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());
    WrapperConfiguration wrapperConfiguration = GradleUtil.getWrapperConfiguration(getProjectPath());
    PathAssembler.LocalDistribution localDistribution = new PathAssembler(StartParameter.DEFAULT_GRADLE_USER_HOME).getDistribution(wrapperConfiguration);
    File zip = localDistribution.getZipFile();
    try {
        if (zip.exists()) {
            ZipFile zipFile = new ZipFile(zip);
            zipFile.close();
        }
    } catch (ZipException e) {
        e.printStackTrace();
        System.out.println("Corrupted file will be removed: " + zip.getPath());
        FileUtil.delete(zip);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DistributionLocator(org.jetbrains.plugins.gradle.tooling.builder.AbstractModelBuilderTest.DistributionLocator) WriteAction(com.intellij.openapi.application.WriteAction) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) Properties(java.util.Properties) WrapperConfiguration(org.gradle.wrapper.WrapperConfiguration) URI(java.net.URI) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) PathAssembler(org.gradle.wrapper.PathAssembler) StringWriter(java.io.StringWriter) ZipFile(java.util.zip.ZipFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 39 with WriteAction

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

the class AddCustomLibraryDialog method doOKAction.

@Override
protected void doOKAction() {
    final LibraryCompositionSettings settings = myPanel.apply();
    if (settings != null && settings.downloadFiles(myPanel.getMainPanel())) {
        if (myModifiableRootModel == null) {
            final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
            new WriteAction() {

                @Override
                protected void run(@NotNull final Result result) {
                    addLibraries(model, settings);
                    model.commit();
                }
            }.execute();
        } else {
            addLibraries(myModifiableRootModel, settings);
        }
    }
    super.doOKAction();
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) LibraryCompositionSettings(com.intellij.facet.impl.ui.libraries.LibraryCompositionSettings) WriteAction(com.intellij.openapi.application.WriteAction) Result(com.intellij.openapi.application.Result)

Example 40 with WriteAction

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

the class CreateNewLibraryDialog method createLibrary.

@NotNull
public Library createLibrary() {
    final LibraryTable.ModifiableModel modifiableModel = getTableModifiableModel();
    final LibraryType<?> type = myLibraryEditor.getType();
    final Library library = modifiableModel.createLibrary(myLibraryEditor.getName(), type != null ? type.getKind() : null);
    final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx) library.getModifiableModel();
    myLibraryEditor.applyTo(model);
    new WriteAction() {

        @Override
        protected void run(@NotNull final Result result) {
            model.commit();
        }
    }.execute();
    return library;
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) WriteAction(com.intellij.openapi.application.WriteAction) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) Library(com.intellij.openapi.roots.libraries.Library) Result(com.intellij.openapi.application.Result) NotNull(org.jetbrains.annotations.NotNull)

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