diff --git a/platform/built-in-server/testSrc/BinaryRequestHandlerTest.kt b/platform/built-in-server/testSrc/BinaryRequestHandlerTest.kt index 0c8c4dc5e13f..1d3b65cc977f 100644 --- a/platform/built-in-server/testSrc/BinaryRequestHandlerTest.kt +++ b/platform/built-in-server/testSrc/BinaryRequestHandlerTest.kt @@ -17,6 +17,7 @@ import org.jetbrains.io.ChannelExceptionHandler import org.jetbrains.io.Decoder import org.jetbrains.io.MessageDecoder import org.jetbrains.io.NettyUtil +import org.jetbrains.testFramework.FixtureRule import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain diff --git a/platform/built-in-server/testSrc/RestApiTest.kt b/platform/built-in-server/testSrc/RestApiTest.kt index 2f9586857102..b4716ebfac5e 100644 --- a/platform/built-in-server/testSrc/RestApiTest.kt +++ b/platform/built-in-server/testSrc/RestApiTest.kt @@ -1,19 +1,19 @@ package org.jetbrains.ide +import com.google.gson.stream.JsonWriter +import com.intellij.openapi.vfs.CharsetToolkit import io.netty.handler.codec.http.HttpResponseStatus +import org.hamcrest.CoreMatchers.equalTo +import org.jetbrains.ide.TestManager.TestDescriptor +import org.jetbrains.testFramework.FixtureRule +import org.junit.Assert.assertThat import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain - -import org.hamcrest.CoreMatchers.equalTo -import org.jetbrains.ide.TestManager.TestDescriptor -import org.junit.Assert.assertThat -import java.net.URL -import java.net.HttpURLConnection -import com.google.gson.stream.JsonWriter -import java.io.OutputStreamWriter -import com.intellij.openapi.vfs.CharsetToolkit import java.io.BufferedOutputStream +import java.io.OutputStreamWriter +import java.net.HttpURLConnection +import java.net.URL public class RestApiTest { private val fixtureManager = FixtureRule() diff --git a/platform/built-in-server/testSrc/TestManager.kt b/platform/built-in-server/testSrc/TestManager.kt index 50fa6cd3fe84..05f13c915c89 100644 --- a/platform/built-in-server/testSrc/TestManager.kt +++ b/platform/built-in-server/testSrc/TestManager.kt @@ -1,11 +1,13 @@ package org.jetbrains.ide +import com.intellij.openapi.application.writeAction import com.intellij.openapi.roots.ModuleRootManager import com.intellij.openapi.roots.ModuleRootModificationUtil import com.intellij.openapi.util.io.FileUtilRt import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.vfs.VirtualFile import com.intellij.testFramework.fixtures.IdeaProjectTestFixture +import org.jetbrains.testFramework.invokeAndWaitIfNeed import org.junit.rules.TestWatcher import org.junit.runner.Description import java.io.File @@ -63,10 +65,10 @@ class TestManager(val projectFixture: IdeaProjectTestFixture) : TestWatcher() { } invokeAndWaitIfNeed { - val normalizedFilePath = FileUtilRt.toSystemIndependentName(filePath) + val normalizedFilePath = FileUtilRt.toSystemIndependentName(filePath!!) if (annotation!!.relativeToProject) { val root = projectFixture.getProject().getBaseDir() - runWriteAction { + writeAction { fileToDelete = root.findOrCreateChildData(this@TestManager, normalizedFilePath) } } @@ -75,7 +77,7 @@ class TestManager(val projectFixture: IdeaProjectTestFixture) : TestWatcher() { ModuleRootModificationUtil.updateModel(projectFixture.getModule()) { model -> val contentEntry = model.getContentEntries()[0] val contentRoot = contentEntry.getFile()!! - runWriteAction { + writeAction { contentRoot.findChild(EXCLUDED_DIR_NAME)?.delete(this@TestManager) fileToDelete = contentRoot.createChildDirectory(this@TestManager, EXCLUDED_DIR_NAME) fileToDelete!!.createChildData(this@TestManager, normalizedFilePath) @@ -87,7 +89,7 @@ class TestManager(val projectFixture: IdeaProjectTestFixture) : TestWatcher() { } else { val root = ModuleRootManager.getInstance(projectFixture.getModule()).getSourceRoots()[0] - runWriteAction { + writeAction { fileToDelete = root.findOrCreateChildData(this@TestManager, normalizedFilePath) } } @@ -101,11 +103,11 @@ class TestManager(val projectFixture: IdeaProjectTestFixture) : TestWatcher() { } if (fileToDelete != null) { - invokeAndWaitIfNeed { runWriteAction { fileToDelete?.delete(this@TestManager) } } + invokeAndWaitIfNeed { writeAction { fileToDelete?.delete(this@TestManager) } } fileToDelete = null } - if (ioFileToDelete != null && !FileUtilRt.delete(ioFileToDelete)) { + if (ioFileToDelete != null && !FileUtilRt.delete(ioFileToDelete!!)) { ioFileToDelete!!.deleteOnExit() } diff --git a/platform/core-impl/core-impl.iml b/platform/core-impl/core-impl.iml index 6d93fd99a32c..e57a2b6e112a 100644 --- a/platform/core-impl/core-impl.iml +++ b/platform/core-impl/core-impl.iml @@ -11,5 +11,6 @@ + \ No newline at end of file diff --git a/platform/core-impl/src/com/intellij/openapi/application/actions.kt b/platform/core-impl/src/com/intellij/openapi/application/actions.kt new file mode 100644 index 000000000000..df6f89b514bc --- /dev/null +++ b/platform/core-impl/src/com/intellij/openapi/application/actions.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.application + +public inline fun writeAction(runnable: () -> Unit) { + val token = WriteAction.start() + try { + runnable() + } + finally { + token.finish() + } +} \ No newline at end of file diff --git a/platform/testFramework/testSrc/FixtureRule.kt b/platform/testFramework/testSrc/FixtureRule.kt index 9edd6647a696..dcca0ef2d24c 100644 --- a/platform/testFramework/testSrc/FixtureRule.kt +++ b/platform/testFramework/testSrc/FixtureRule.kt @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.ide +package org.jetbrains.testFramework -import com.intellij.openapi.application.WriteAction import com.intellij.testFramework.UsefulTestCase import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory import org.junit.rules.ExternalResource @@ -25,16 +24,6 @@ public fun invokeAndWaitIfNeed(runnable: () -> Unit) { if (SwingUtilities.isEventDispatchThread()) runnable() else SwingUtilities.invokeAndWait(runnable) } -public inline fun runWriteAction(runnable: () -> Unit) { - val token = WriteAction.start() - try { - runnable() - } - finally { - token.finish() - } -} - public class FixtureRule() : ExternalResource() { val projectFixture = IdeaTestFixtureFactory.getFixtureFactory().createLightFixtureBuilder().getFixture()