Implement Kotlin configurator for GSK
#KT-14965 Fixed
This commit is contained in:
@@ -63,7 +63,7 @@ public class KtScript extends KtNamedDeclarationStub<KotlinScriptStub> implement
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private KtBlockExpression getBlockExpression() {
|
||||
public KtBlockExpression getBlockExpression() {
|
||||
return findNotNullChildByClass(KtBlockExpression.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@ import org.jetbrains.kotlin.idea.completion.test.handlers.AbstractKeywordComplet
|
||||
import org.jetbrains.kotlin.idea.completion.test.handlers.AbstractSmartCompletionHandlerTest
|
||||
import org.jetbrains.kotlin.idea.completion.test.weighers.AbstractBasicCompletionWeigherTest
|
||||
import org.jetbrains.kotlin.idea.completion.test.weighers.AbstractSmartCompletionWeigherTest
|
||||
import org.jetbrains.kotlin.idea.configuration.AbstractGradleConfigureProjectByChangingFileTest
|
||||
import org.jetbrains.kotlin.idea.conversion.copy.AbstractJavaToKotlinCopyPasteConversionTest
|
||||
import org.jetbrains.kotlin.idea.conversion.copy.AbstractLiteralKotlinToKotlinCopyPasteTest
|
||||
import org.jetbrains.kotlin.idea.conversion.copy.AbstractLiteralTextToKotlinCopyPasteTest
|
||||
@@ -791,8 +792,9 @@ fun main(args: Array<String>) {
|
||||
model("multiFileInspections", extension = "test", singleClass = true)
|
||||
}
|
||||
|
||||
testClass<org.jetbrains.kotlin.idea.configuration.AbstractGradleConfigureProjectByChangingFileTest> {
|
||||
testClass<AbstractGradleConfigureProjectByChangingFileTest> {
|
||||
model("configuration/gradle", pattern = """(\w+)_before\.gradle$""", testMethod = "doTestGradle")
|
||||
model("configuration/gsk", pattern = """(\w+)_before\.gradle.kts$""", testMethod = "doTestGradle")
|
||||
}
|
||||
|
||||
testClass<AbstractFormatterTest> {
|
||||
@@ -1334,6 +1336,7 @@ fun main(args: Array<String>) {
|
||||
testGroup("idea/idea-android/tests", "idea/testData") {
|
||||
testClass<AbstractConfigureProjectTest> {
|
||||
model("configuration/android-gradle", pattern = """(\w+)_before\.gradle$""", testMethod = "doTestAndroidGradle")
|
||||
model("configuration/android-gsk", pattern = """(\w+)_before\.gradle.kts$""", testMethod = "doTestAndroidGradle")
|
||||
}
|
||||
|
||||
testClass<AbstractAndroidIntentionTest> {
|
||||
|
||||
+52
-61
@@ -14,79 +14,70 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.android.configure;
|
||||
package org.jetbrains.kotlin.android.configure
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.idea.KotlinPluginUtil;
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinWithGradleConfigurator;
|
||||
import org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform;
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.projectRoots.JavaSdk
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.kotlin.idea.KotlinPluginUtil
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinWithGradleConfigurator
|
||||
import org.jetbrains.kotlin.idea.versions.*
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile
|
||||
|
||||
public class KotlinAndroidGradleModuleConfigurator extends KotlinWithGradleConfigurator {
|
||||
public static final String NAME = "android-gradle";
|
||||
class KotlinAndroidGradleModuleConfigurator internal constructor() : KotlinWithGradleConfigurator() {
|
||||
|
||||
private static final String APPLY_KOTLIN_ANDROID = "apply plugin: 'kotlin-android'";
|
||||
override val name: String = NAME
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
override val targetPlatform: TargetPlatform = JvmPlatform
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TargetPlatform getTargetPlatform() {
|
||||
return JvmPlatform.INSTANCE;
|
||||
}
|
||||
override val presentableText: String = "Android with Gradle"
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
return "Android with Gradle";
|
||||
}
|
||||
public override fun isApplicable(module: Module): Boolean = KotlinPluginUtil.isAndroidGradleModule(module)
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(@NotNull Module module) {
|
||||
return KotlinPluginUtil.isAndroidGradleModule(module);
|
||||
}
|
||||
override val kotlinPluginName: String = KOTLIN_ANDROID
|
||||
|
||||
@Override
|
||||
protected String getApplyPluginDirective() {
|
||||
return APPLY_KOTLIN_ANDROID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean addElementsToFile(@NotNull GroovyFile groovyFile, boolean isTopLevelProjectFile, @NotNull String version) {
|
||||
if (isTopLevelProjectFile) {
|
||||
return Companion.addElementsToProjectFile(groovyFile, version);
|
||||
}
|
||||
else {
|
||||
return addElementsToModuleFile(groovyFile, version);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getRuntimeLibrary(@Nullable Sdk sdk, @NotNull String version) {
|
||||
if (sdk != null && KotlinRuntimeLibraryUtilKt.hasJreSpecificRuntime(version)) {
|
||||
JavaSdkVersion sdkVersion = JavaSdk.getInstance().getVersion(sdk);
|
||||
if (sdkVersion != null && sdkVersion.isAtLeast(JavaSdkVersion.JDK_1_8)) {
|
||||
// Android dex can't convert our kotlin-stdlib-jre8 artifact, so use jre7 instead (KT-16530)
|
||||
return KotlinWithGradleConfigurator.Companion.getDependencySnippet(
|
||||
KotlinRuntimeLibraryUtilKt.getMAVEN_STDLIB_ID_JRE7());
|
||||
override fun addElementsToFile(file: PsiFile, isTopLevelProjectFile: Boolean, version: String): Boolean {
|
||||
if (file is GroovyFile) {
|
||||
if (isTopLevelProjectFile) {
|
||||
return addElementsToProjectGroovyFile(file, version)
|
||||
}
|
||||
else {
|
||||
return addElementsToModuleGroovyFile(file, version)
|
||||
}
|
||||
}
|
||||
|
||||
return super.getRuntimeLibrary(sdk, version);
|
||||
if (file is KtFile) {
|
||||
if (isTopLevelProjectFile) {
|
||||
return addElementsToProjectGSKFile(file, version)
|
||||
}
|
||||
else {
|
||||
return addElementsToModuleGSKFile(file, version)
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
KotlinAndroidGradleModuleConfigurator() {
|
||||
override fun getStdlibArtifactName(sdk: Sdk?, version: String): String {
|
||||
if (sdk != null && hasJreSpecificRuntime(version)) {
|
||||
val sdkVersion = JavaSdk.getInstance().getVersion(sdk)
|
||||
if (sdkVersion != null && sdkVersion.isAtLeast(JavaSdkVersion.JDK_1_8)) {
|
||||
// Android dex can't convert our kotlin-stdlib-jre8 artifact, so use jre7 instead (KT-16530)
|
||||
return MAVEN_STDLIB_ID_JRE7
|
||||
}
|
||||
}
|
||||
|
||||
return super.getStdlibArtifactName(sdk, version)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val NAME = "android-gradle"
|
||||
|
||||
private val KOTLIN_ANDROID = "kotlin-android"
|
||||
}
|
||||
}
|
||||
|
||||
+127
-103
@@ -28,139 +28,163 @@ import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/configuration/android-gradle")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class ConfigureProjectTestGenerated extends AbstractConfigureProjectTest {
|
||||
public void testAllFilesPresentInAndroid_gradle() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/configuration/android-gradle"), Pattern.compile("(\\w+)_before\\.gradle$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("androidStudioDefault_before.gradle")
|
||||
public void testAndroidStudioDefault() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/androidStudioDefault_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("androidStudioDefaultShapshot_before.gradle")
|
||||
public void testAndroidStudioDefaultShapshot() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/androidStudioDefaultShapshot_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("buildConfigs_before.gradle")
|
||||
public void testBuildConfigs() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/buildConfigs_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("emptyDependencyList_before.gradle")
|
||||
public void testEmptyDependencyList() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/emptyDependencyList_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("emptyFile_before.gradle")
|
||||
public void testEmptyFile() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/emptyFile_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("helloWorld_before.gradle")
|
||||
public void testHelloWorld() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/helloWorld_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("libraryFile_before.gradle")
|
||||
public void testLibraryFile() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/libraryFile_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("missedApplyAndroidStatement_before.gradle")
|
||||
public void testMissedApplyAndroidStatement() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/missedApplyAndroidStatement_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("missedBuildscriptBlock_before.gradle")
|
||||
public void testMissedBuildscriptBlock() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/missedBuildscriptBlock_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("missedRepositoriesInBuildscriptBlock_before.gradle")
|
||||
public void testMissedRepositoriesInBuildscriptBlock() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/missedRepositoriesInBuildscriptBlock_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("productFlavor_before.gradle")
|
||||
public void testProductFlavor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/productFlavor_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/configuration/android-gradle/gradleExamples")
|
||||
@TestMetadata("idea/testData/configuration/android-gradle")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class GradleExamples extends AbstractConfigureProjectTest {
|
||||
public void testAllFilesPresentInGradleExamples() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/configuration/android-gradle/gradleExamples"), Pattern.compile("(\\w+)_before\\.gradle$"), TargetBackend.ANY, true);
|
||||
public static class Android_gradle extends AbstractConfigureProjectTest {
|
||||
public void testAllFilesPresentInAndroid_gradle() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/configuration/android-gradle"), Pattern.compile("(\\w+)_before\\.gradle$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("gradleExample0_before.gradle")
|
||||
public void testGradleExample0() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/gradleExamples/gradleExample0_before.gradle");
|
||||
@TestMetadata("androidStudioDefault_before.gradle")
|
||||
public void testAndroidStudioDefault() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/androidStudioDefault_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("gradleExample18_before.gradle")
|
||||
public void testGradleExample18() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/gradleExamples/gradleExample18_before.gradle");
|
||||
@TestMetadata("androidStudioDefaultShapshot_before.gradle")
|
||||
public void testAndroidStudioDefaultShapshot() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/androidStudioDefaultShapshot_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("gradleExample22_before.gradle")
|
||||
public void testGradleExample22() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/gradleExamples/gradleExample22_before.gradle");
|
||||
@TestMetadata("buildConfigs_before.gradle")
|
||||
public void testBuildConfigs() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/buildConfigs_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("gradleExample44_before.gradle")
|
||||
public void testGradleExample44() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/gradleExamples/gradleExample44_before.gradle");
|
||||
@TestMetadata("emptyDependencyList_before.gradle")
|
||||
public void testEmptyDependencyList() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/emptyDependencyList_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("gradleExample5_before.gradle")
|
||||
public void testGradleExample5() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/gradleExamples/gradleExample5_before.gradle");
|
||||
@TestMetadata("emptyFile_before.gradle")
|
||||
public void testEmptyFile() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/emptyFile_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("gradleExample50_before.gradle")
|
||||
public void testGradleExample50() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/gradleExamples/gradleExample50_before.gradle");
|
||||
@TestMetadata("helloWorld_before.gradle")
|
||||
public void testHelloWorld() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/helloWorld_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("gradleExample58_before.gradle")
|
||||
public void testGradleExample58() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/gradleExamples/gradleExample58_before.gradle");
|
||||
@TestMetadata("libraryFile_before.gradle")
|
||||
public void testLibraryFile() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/libraryFile_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("gradleExample65_before.gradle")
|
||||
public void testGradleExample65() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/gradleExamples/gradleExample65_before.gradle");
|
||||
@TestMetadata("missedApplyAndroidStatement_before.gradle")
|
||||
public void testMissedApplyAndroidStatement() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/missedApplyAndroidStatement_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("gradleExample8_before.gradle")
|
||||
public void testGradleExample8() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/gradleExamples/gradleExample8_before.gradle");
|
||||
@TestMetadata("missedBuildscriptBlock_before.gradle")
|
||||
public void testMissedBuildscriptBlock() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/missedBuildscriptBlock_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("missedRepositoriesInBuildscriptBlock_before.gradle")
|
||||
public void testMissedRepositoriesInBuildscriptBlock() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/missedRepositoriesInBuildscriptBlock_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("productFlavor_before.gradle")
|
||||
public void testProductFlavor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/productFlavor_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/configuration/android-gradle/gradleExamples")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class GradleExamples extends AbstractConfigureProjectTest {
|
||||
public void testAllFilesPresentInGradleExamples() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/configuration/android-gradle/gradleExamples"), Pattern.compile("(\\w+)_before\\.gradle$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("gradleExample0_before.gradle")
|
||||
public void testGradleExample0() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/gradleExamples/gradleExample0_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("gradleExample18_before.gradle")
|
||||
public void testGradleExample18() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/gradleExamples/gradleExample18_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("gradleExample22_before.gradle")
|
||||
public void testGradleExample22() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/gradleExamples/gradleExample22_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("gradleExample44_before.gradle")
|
||||
public void testGradleExample44() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/gradleExamples/gradleExample44_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("gradleExample5_before.gradle")
|
||||
public void testGradleExample5() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/gradleExamples/gradleExample5_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("gradleExample50_before.gradle")
|
||||
public void testGradleExample50() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/gradleExamples/gradleExample50_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("gradleExample58_before.gradle")
|
||||
public void testGradleExample58() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/gradleExamples/gradleExample58_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("gradleExample65_before.gradle")
|
||||
public void testGradleExample65() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/gradleExamples/gradleExample65_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("gradleExample8_before.gradle")
|
||||
public void testGradleExample8() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gradle/gradleExamples/gradleExample8_before.gradle");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/configuration/android-gsk")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Android_gsk extends AbstractConfigureProjectTest {
|
||||
public void testAllFilesPresentInAndroid_gsk() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/configuration/android-gsk"), Pattern.compile("(\\w+)_before\\.gradle.kts$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("emptyFile_before.gradle.kts")
|
||||
public void testEmptyFile() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gsk/emptyFile_before.gradle.kts");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("helloWorld_before.gradle.kts")
|
||||
public void testHelloWorld() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/android-gsk/helloWorld_before.gradle.kts");
|
||||
doTestAndroidGradle(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,9 @@ val EAP_12_REPOSITORY = RepositoryDescription(
|
||||
"https://bintray.com/kotlin/kotlin-eap-1.2/kotlin/",
|
||||
isSnapshot = false)
|
||||
|
||||
fun RepositoryDescription.toRepositorySnippet() = "maven {\nurl '$url'\n}"
|
||||
fun RepositoryDescription.toGroovyRepositorySnippet() = "maven {\nurl '$url'\n}"
|
||||
|
||||
fun RepositoryDescription.toKotlinRepositorySnippet() = "maven {\nsetUrl(\"$url\")\n}"
|
||||
|
||||
fun getRepositoryForVersion(version: String): RepositoryDescription? = when {
|
||||
isSnapshot(version) -> SNAPSHOT_REPOSITORY
|
||||
@@ -145,7 +147,7 @@ fun getConfiguratorByName(name: String): KotlinProjectConfigurator? {
|
||||
|
||||
fun allConfigurators() = Extensions.getExtensions(KotlinProjectConfigurator.EP_NAME)
|
||||
|
||||
fun getNonConfiguredModules(project: Project, configurator: KotlinProjectConfigurator): List<Module> {
|
||||
fun getCanBeConfiguredModules(project: Project, configurator: KotlinProjectConfigurator): List<Module> {
|
||||
return project.allModules()
|
||||
.filter { module -> configurator.canConfigure(module) }
|
||||
.excludeSourceRootModules()
|
||||
@@ -185,12 +187,12 @@ val Module.externalProjectId: String?
|
||||
val Module.externalProjectPath: String?
|
||||
get() = ExternalSystemApiUtil.getExternalProjectPath(this)
|
||||
|
||||
fun getNonConfiguredModulesWithKotlinFiles(project: Project, configurator: KotlinProjectConfigurator): List<Module> {
|
||||
fun getCanBeConfiguredModulesWithKotlinFiles(project: Project, configurator: KotlinProjectConfigurator): List<Module> {
|
||||
val modules = getConfigurableModulesWithKotlinFiles(project)
|
||||
return modules.filter { module -> configurator.getStatus(module) == ConfigureKotlinStatus.CAN_BE_CONFIGURED }
|
||||
}
|
||||
|
||||
fun getNonConfiguredModulesWithKotlinFiles(project: Project, excludeModules: Collection<Module> = emptyList()): Collection<Module> {
|
||||
fun getCanBeConfiguredModulesWithKotlinFiles(project: Project, excludeModules: Collection<Module> = emptyList()): Collection<Module> {
|
||||
val modulesWithKotlinFiles = getConfigurableModulesWithKotlinFiles(project) - excludeModules
|
||||
val configurators = allConfigurators()
|
||||
return modulesWithKotlinFiles.filter { module ->
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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 org.jetbrains.kotlin.idea.configuration
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getChildrenOfType
|
||||
import org.jetbrains.kotlin.resolve.ImportPath
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
|
||||
|
||||
fun getKotlinScriptDependencySnippet(artifactName: String): String =
|
||||
"compile(${getKotlinModuleDependencySnippet(artifactName)})"
|
||||
|
||||
fun getKotlinModuleDependencySnippet(artifactName: String): String =
|
||||
"kotlinModule(\"${artifactName.removePrefix("kotlin-")}\", $GSK_KOTLIN_VERSION_PROPERTY_NAME)"
|
||||
|
||||
fun KtFile.containsCompileStdLib(): Boolean =
|
||||
findScriptInitializer("dependencies")?.getBlock()?.findCompileStdLib() != null
|
||||
|
||||
fun KtFile.containsApplyKotlinPlugin(pluginName: String): Boolean =
|
||||
findScriptInitializer("apply")?.getBlock()?.findPlugin(pluginName) != null
|
||||
|
||||
fun KtBlockExpression.findCompileStdLib(): KtCallExpression? {
|
||||
return PsiTreeUtil.getChildrenOfType(this, KtCallExpression::class.java)?.find {
|
||||
it.calleeExpression?.text == "compile" && (it.valueArguments.firstOrNull()?.getArgumentExpression()?.isKotlinStdLib() ?: false)
|
||||
}
|
||||
}
|
||||
|
||||
fun KtFile.getRepositoriesBlock(): KtBlockExpression? =
|
||||
findScriptInitializer("repositories")?.getBlock() ?: addTopLevelBlock("repositories")
|
||||
|
||||
fun KtFile.getDependenciesBlock(): KtBlockExpression? =
|
||||
findScriptInitializer("dependencies")?.getBlock() ?: addTopLevelBlock("dependencies")
|
||||
|
||||
fun KtFile.createApplyBlock(): KtBlockExpression? {
|
||||
val apply = psiFactory.createScriptInitializer("apply {\n}")
|
||||
val plugins = findScriptInitializer("plugins")
|
||||
val addedElement = plugins?.addSibling(apply) ?: addToScriptBlock(apply)
|
||||
addedElement?.addNewLinesIfNeeded()
|
||||
return (addedElement as? KtScriptInitializer)?.getBlock()
|
||||
}
|
||||
|
||||
fun KtFile.getApplyBlock(): KtBlockExpression? = findScriptInitializer("apply")?.getBlock() ?: createApplyBlock()
|
||||
|
||||
private fun KtExpression.isKotlinStdLib(): Boolean = when (this) {
|
||||
is KtCallExpression -> calleeExpression?.text == "kotlinModule" &&
|
||||
valueArguments.firstOrNull()?.getArgumentExpression()?.text == "\"stdlib\""
|
||||
is KtStringTemplateExpression -> text.startsWith("\"org.jetbrains.kotlin:kotlin-stdlib:")
|
||||
else -> false
|
||||
}
|
||||
|
||||
private fun KtBlockExpression.findPlugin(pluginName: String): KtCallExpression? {
|
||||
return PsiTreeUtil.getChildrenOfType(this, KtCallExpression::class.java)?.find {
|
||||
it.calleeExpression?.text == "plugin" && it.valueArguments.firstOrNull()?.text == "\"$pluginName\""
|
||||
}
|
||||
}
|
||||
|
||||
fun KtBlockExpression.createPluginIfMissing(pluginName: String): KtCallExpression? =
|
||||
findPlugin(pluginName) ?: addExpressionIfMissing("plugin(\"$pluginName\")") as? KtCallExpression
|
||||
|
||||
fun changeCoroutineConfiguration(buildScriptFile: KtFile, coroutineOption: String): PsiElement? {
|
||||
val snippet = "experimental.coroutines = Coroutines.${coroutineOption.toUpperCase()}"
|
||||
val kotlinBlock = buildScriptFile.findScriptInitializer("kotlin")?.getBlock() ?:
|
||||
buildScriptFile.addTopLevelBlock("kotlin") ?: return null
|
||||
buildScriptFile.addImportIfMissing("org.jetbrains.kotlin.gradle.dsl.Coroutines")
|
||||
val statement = kotlinBlock.statements.find { it.text.startsWith("experimental.coroutines") }
|
||||
return if (statement != null) {
|
||||
statement.replace(buildScriptFile.psiFactory.createExpression(snippet))
|
||||
}
|
||||
else {
|
||||
kotlinBlock.add(buildScriptFile.psiFactory.createExpression(snippet)).apply { addNewLinesIfNeeded() }
|
||||
}
|
||||
}
|
||||
|
||||
fun KtFile.changeKotlinTaskParameter(parameterName: String, parameterValue: String, forTests: Boolean): PsiElement? {
|
||||
val snippet = "$parameterName = \"$parameterValue\""
|
||||
val taskName = if (forTests) "compileTestKotlin" else "compileKotlin"
|
||||
val optionsBlock = findScriptInitializer("$taskName.kotlinOptions")?.getBlock()
|
||||
return if (optionsBlock != null) {
|
||||
val assignment = optionsBlock.statements.find {
|
||||
(it as? KtBinaryExpression)?.left?.text == parameterName
|
||||
}
|
||||
if (assignment != null) {
|
||||
assignment.replace(psiFactory.createExpression(snippet))
|
||||
}
|
||||
else {
|
||||
optionsBlock.addExpressionIfMissing(snippet)
|
||||
}
|
||||
}
|
||||
else {
|
||||
addImportIfMissing("org.jetbrains.kotlin.gradle.tasks.KotlinCompile")
|
||||
script?.blockExpression?.addDeclarationIfMissing("val $taskName: KotlinCompile by tasks")
|
||||
addTopLevelBlock("$taskName.kotlinOptions")?.addExpressionIfMissing(snippet)
|
||||
}
|
||||
}
|
||||
|
||||
fun KtFile.getBuildScriptBlock(): KtBlockExpression? =
|
||||
findScriptInitializer("buildscript")?.getBlock() ?: addTopLevelBlock("buildscript", true)
|
||||
|
||||
fun KtBlockExpression.getRepositoriesBlock(): KtBlockExpression? =
|
||||
findBlock("repositories") ?: addBlock("repositories")
|
||||
|
||||
fun KtBlockExpression.getDependenciesBlock(): KtBlockExpression? =
|
||||
findBlock("dependencies") ?: addBlock("dependencies")
|
||||
|
||||
fun KtBlockExpression.addRepositoryIfMissing(version: String): KtCallExpression? {
|
||||
val repository = getRepositoryForVersion(version)
|
||||
val snippet = when {
|
||||
repository != null -> repository.toKotlinRepositorySnippet()
|
||||
!isRepositoryConfigured() -> MAVEN_CENTRAL
|
||||
else -> return null
|
||||
}
|
||||
|
||||
return addExpressionIfMissing(snippet) as? KtCallExpression
|
||||
}
|
||||
|
||||
private fun KtBlockExpression.isRepositoryConfigured(): Boolean {
|
||||
return text.contains(MAVEN_CENTRAL) || text.contains(JCENTER)
|
||||
}
|
||||
|
||||
fun KtBlockExpression.addPluginToClassPathIfMissing(): KtCallExpression? =
|
||||
addExpressionIfMissing("classpath(${getKotlinModuleDependencySnippet("gradle-plugin")})") as? KtCallExpression
|
||||
|
||||
private fun KtFile.findScriptInitializer(startsWith: String): KtScriptInitializer? =
|
||||
PsiTreeUtil.findChildrenOfType(this, KtScriptInitializer::class.java).find { it.text.startsWith(startsWith) }
|
||||
|
||||
private fun KtBlockExpression.findBlock(name: String): KtBlockExpression? {
|
||||
return getChildrenOfType<KtCallExpression>().find {
|
||||
it.calleeExpression?.text == name &&
|
||||
it.valueArguments.singleOrNull()?.getArgumentExpression() is KtLambdaExpression
|
||||
}?.getBlock()
|
||||
}
|
||||
|
||||
private fun KtScriptInitializer.getBlock(): KtBlockExpression? =
|
||||
PsiTreeUtil.findChildOfType<KtCallExpression>(this, KtCallExpression::class.java)?.getBlock()
|
||||
|
||||
private fun KtCallExpression.getBlock(): KtBlockExpression? =
|
||||
(valueArguments.singleOrNull()?.getArgumentExpression() as? KtLambdaExpression)?.bodyExpression
|
||||
|
||||
private fun KtBlockExpression.addBlock(name: String): KtBlockExpression? {
|
||||
return add(psiFactory.createExpression("$name {\n}"))
|
||||
?.apply { addNewLinesIfNeeded() }
|
||||
?.cast<KtCallExpression>()
|
||||
?.getBlock()
|
||||
}
|
||||
|
||||
private fun KtFile.addTopLevelBlock(name: String, first: Boolean = false): KtBlockExpression? {
|
||||
val scriptInitializer = psiFactory.createScriptInitializer("$name {\n}")
|
||||
val addedElement = addToScriptBlock(scriptInitializer, first) as? KtScriptInitializer
|
||||
addedElement?.addNewLinesIfNeeded()
|
||||
return addedElement?.getBlock()
|
||||
}
|
||||
|
||||
private fun PsiElement.addSibling(element: PsiElement): PsiElement = parent.addAfter(element, this)
|
||||
|
||||
private fun PsiElement.addNewLineBefore(lineBreaks: Int = 1) {
|
||||
parent.addBefore(psiFactory.createNewLine(lineBreaks), this)
|
||||
}
|
||||
|
||||
private fun PsiElement.addNewLineAfter(lineBreaks: Int = 1) {
|
||||
parent.addAfter(psiFactory.createNewLine(lineBreaks), this)
|
||||
}
|
||||
|
||||
private fun PsiElement.addNewLinesIfNeeded(lineBreaks: Int = 1) {
|
||||
if (prevSibling != null && prevSibling.text.isNotBlank()) {
|
||||
addNewLineBefore(lineBreaks)
|
||||
}
|
||||
|
||||
if (nextSibling != null && nextSibling.text.isNotBlank()) {
|
||||
addNewLineAfter(lineBreaks)
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtFile.addToScriptBlock(element: PsiElement, first: Boolean = false): PsiElement? =
|
||||
if (first) script?.blockExpression?.addAfter(element, null) else script?.blockExpression?.add(element)
|
||||
|
||||
private fun KtFile.addImportIfMissing(path: String): KtImportDirective =
|
||||
importDirectives.find { it.importPath?.pathStr == path } ?:
|
||||
importList?.add(psiFactory.createImportDirective(ImportPath.fromString(path))) as KtImportDirective
|
||||
|
||||
fun KtBlockExpression.addExpressionAfterIfMissing(text: String, after: PsiElement): KtExpression = addStatementIfMissing(text) {
|
||||
psiFactory.createExpression(it).let { created ->
|
||||
addAfter(created, after)
|
||||
}
|
||||
}
|
||||
|
||||
fun KtBlockExpression.addExpressionIfMissing(text: String, first: Boolean = false): KtExpression = addStatementIfMissing(text) {
|
||||
psiFactory.createExpression(it).let { created ->
|
||||
if(first) addAfter(created, null) else add(created)
|
||||
}
|
||||
}
|
||||
|
||||
fun KtBlockExpression.addDeclarationIfMissing(text: String, first: Boolean = false): KtDeclaration = addStatementIfMissing(text) {
|
||||
psiFactory.createDeclaration<KtDeclaration>(it).let { created ->
|
||||
if(first) addAfter(created, null) else add(created)
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun <reified T: PsiElement> KtBlockExpression.addStatementIfMissing(
|
||||
text: String,
|
||||
crossinline factory: (String) -> PsiElement): T {
|
||||
|
||||
statements.find { it.text == text }?.let {
|
||||
return it as T
|
||||
}
|
||||
|
||||
return factory(text).apply { addNewLinesIfNeeded() } as T
|
||||
}
|
||||
|
||||
private fun KtPsiFactory.createScriptInitializer(text: String): KtScriptInitializer =
|
||||
createFile("dummy.kts", text).script?.blockExpression?.firstChild as KtScriptInitializer
|
||||
|
||||
private val PsiElement.psiFactory: KtPsiFactory
|
||||
get() = KtPsiFactory(this)
|
||||
|
||||
|
||||
private val MAVEN_CENTRAL = "mavenCentral()"
|
||||
private val JCENTER = "jcenter()"
|
||||
|
||||
val GSK_KOTLIN_VERSION_PROPERTY_NAME = "kotlin_version"
|
||||
+8
-7
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.idea.KotlinIcons
|
||||
import org.jetbrains.kotlin.idea.versions.MAVEN_JS_STDLIB_ID
|
||||
import org.jetbrains.kotlin.idea.versions.bundledRuntimeVersion
|
||||
import org.jetbrains.kotlin.idea.versions.getDefaultJvmTarget
|
||||
import org.jetbrains.kotlin.idea.versions.getStdlibArtifactId
|
||||
import org.jetbrains.plugins.gradle.frameworkSupport.BuildScriptDataBuilder
|
||||
import org.jetbrains.plugins.gradle.frameworkSupport.GradleFrameworkSupportProvider
|
||||
import javax.swing.Icon
|
||||
@@ -50,7 +51,7 @@ abstract class GradleKotlinFrameworkSupportProvider(val frameworkTypeId: String,
|
||||
}
|
||||
|
||||
if (additionalRepository != null) {
|
||||
val oneLineRepository = additionalRepository.toRepositorySnippet().replace('\n', ' ')
|
||||
val oneLineRepository = additionalRepository.toGroovyRepositorySnippet().replace('\n', ' ')
|
||||
buildScriptData.addBuildscriptRepositoriesDefinition(oneLineRepository)
|
||||
|
||||
buildScriptData.addRepositoriesDefinition("mavenCentral()")
|
||||
@@ -74,10 +75,11 @@ abstract class GradleKotlinFrameworkSupportProvider(val frameworkTypeId: String,
|
||||
}
|
||||
|
||||
class GradleKotlinJavaFrameworkSupportProvider : GradleKotlinFrameworkSupportProvider("KOTLIN", "Kotlin (Java)") {
|
||||
override fun getPluginDefinition() = KotlinGradleModuleConfigurator.APPLY_KOTLIN
|
||||
override fun getPluginDefinition() =
|
||||
KotlinWithGradleConfigurator.getGroovyApplyPluginDirective(KotlinGradleModuleConfigurator.KOTLIN)
|
||||
|
||||
override fun getRuntimeLibrary(rootModel: ModifiableRootModel) =
|
||||
KotlinWithGradleConfigurator.getRuntimeLibraryForSdk(rootModel.sdk, bundledRuntimeVersion())
|
||||
KotlinWithGradleConfigurator.getGroovyDependencySnippet(getStdlibArtifactId(rootModel.sdk, bundledRuntimeVersion()))
|
||||
|
||||
override fun addSupport(module: Module, rootModel: ModifiableRootModel, modifiableModelsProvider: ModifiableModelsProvider, buildScriptData: BuildScriptDataBuilder) {
|
||||
super.addSupport(module, rootModel, modifiableModelsProvider, buildScriptData)
|
||||
@@ -90,10 +92,9 @@ class GradleKotlinJavaFrameworkSupportProvider : GradleKotlinFrameworkSupportPro
|
||||
}
|
||||
|
||||
class GradleKotlinJSFrameworkSupportProvider : GradleKotlinFrameworkSupportProvider("KOTLIN_JS", "Kotlin (JavaScript)") {
|
||||
override fun getPluginDefinition(): String {
|
||||
return KotlinJsGradleModuleConfigurator.APPLY_KOTLIN_JS
|
||||
}
|
||||
override fun getPluginDefinition(): String =
|
||||
KotlinWithGradleConfigurator.getGroovyApplyPluginDirective(KotlinJsGradleModuleConfigurator.KOTLIN_JS)
|
||||
|
||||
override fun getRuntimeLibrary(rootModel: ModifiableRootModel) =
|
||||
KotlinWithGradleConfigurator.getDependencySnippet(MAVEN_JS_STDLIB_ID)
|
||||
KotlinWithGradleConfigurator.getGroovyDependencySnippet(MAVEN_JS_STDLIB_ID)
|
||||
}
|
||||
|
||||
@@ -32,14 +32,13 @@ class KotlinGradleModuleConfigurator internal constructor() : KotlinWithGradleCo
|
||||
override val presentableText: String
|
||||
get() = "Gradle"
|
||||
|
||||
override val applyPluginDirective: String
|
||||
get() = APPLY_KOTLIN
|
||||
override val kotlinPluginName: String
|
||||
get() = KOTLIN
|
||||
|
||||
override fun getJvmTarget(sdk: Sdk?, version: String) = getDefaultJvmTarget(sdk, version)?.description
|
||||
|
||||
companion object {
|
||||
val NAME = "gradle"
|
||||
|
||||
val APPLY_KOTLIN = "apply plugin: 'kotlin'"
|
||||
val KOTLIN = "kotlin"
|
||||
}
|
||||
}
|
||||
|
||||
+3
-7
@@ -25,15 +25,11 @@ class KotlinJsGradleModuleConfigurator : KotlinWithGradleConfigurator() {
|
||||
override val name: String = "gradle-js"
|
||||
override val presentableText: String = "Gradle (JavaScript)"
|
||||
override val targetPlatform: TargetPlatform = JsPlatform
|
||||
|
||||
override val applyPluginDirective: String = APPLY_KOTLIN_JS
|
||||
override val kotlinPluginName: String = KOTLIN_JS
|
||||
override fun getMinimumSupportedVersion() = "1.1.0"
|
||||
|
||||
override fun getDependencyDirective(sdk: Sdk?, version: String): String {
|
||||
return KotlinWithGradleConfigurator.getDependencySnippet(MAVEN_JS_STDLIB_ID)
|
||||
}
|
||||
override fun getStdlibArtifactName(sdk: Sdk?, version: String): String = MAVEN_JS_STDLIB_ID
|
||||
|
||||
companion object {
|
||||
val APPLY_KOTLIN_JS = "apply plugin: 'kotlin2js'"
|
||||
val KOTLIN_JS = "kotlin2js"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.openapi.vfs.VfsUtil
|
||||
import com.intellij.openapi.vfs.WritingAccessProvider
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager
|
||||
import org.jetbrains.kotlin.idea.KotlinPluginUtil
|
||||
@@ -38,6 +39,9 @@ import org.jetbrains.kotlin.idea.framework.ui.ConfigureDialogWithModulesAndVersi
|
||||
import org.jetbrains.kotlin.idea.util.application.executeCommand
|
||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||
import org.jetbrains.kotlin.idea.versions.getStdlibArtifactId
|
||||
import org.jetbrains.kotlin.psi.KtBlockExpression
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getChildrenOfType
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile
|
||||
@@ -63,17 +67,23 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
return ConfigureKotlinStatus.CONFIGURED
|
||||
}
|
||||
|
||||
val buildFiles = listOf(getBuildGradleFile(module.project, getModuleFilePath(module)),
|
||||
getBuildGradleFile(module.project, getTopLevelProjectFilePath(module.project)))
|
||||
.filterNotNull()
|
||||
if (buildFiles.none { buildFile -> allGradleConfigurators.any { it.isFileConfigured(buildFile) } })
|
||||
val buildFiles = listOf(module.getBuildScriptPsiFile(), module.project.getTopLevelBuildScriptPsiFile()).filterNotNull()
|
||||
|
||||
if (buildFiles.isEmpty()) {
|
||||
return ConfigureKotlinStatus.NON_APPLICABLE
|
||||
}
|
||||
|
||||
if (buildFiles.none { it.isConfiguredByAnyGradleConfigurator() }) {
|
||||
return ConfigureKotlinStatus.CAN_BE_CONFIGURED
|
||||
}
|
||||
|
||||
return ConfigureKotlinStatus.BROKEN
|
||||
}
|
||||
|
||||
private val allGradleConfigurators: Collection<KotlinWithGradleConfigurator>
|
||||
get() = Extensions.getExtensions(KotlinProjectConfigurator.EP_NAME).filterIsInstance<KotlinWithGradleConfigurator>()
|
||||
private fun PsiFile.isConfiguredByAnyGradleConfigurator() =
|
||||
Extensions.getExtensions(KotlinProjectConfigurator.EP_NAME)
|
||||
.filterIsInstance<KotlinWithGradleConfigurator>()
|
||||
.any { it.isFileConfigured(this) }
|
||||
|
||||
protected open fun isApplicable(module: Module): Boolean {
|
||||
return KotlinPluginUtil.isGradleModule(module) && !KotlinPluginUtil.isAndroidGradleModule(module)
|
||||
@@ -81,9 +91,18 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
|
||||
protected open fun getMinimumSupportedVersion() = "1.0.0"
|
||||
|
||||
private fun isFileConfigured(projectGradleFile: GroovyFile): Boolean {
|
||||
val fileText = projectGradleFile.text
|
||||
return containsDirective(fileText, applyPluginDirective) &&
|
||||
private fun isFileConfigured(projectGradleFile: PsiFile): Boolean = when(projectGradleFile) {
|
||||
is GroovyFile -> isGradleFileConfigured(projectGradleFile)
|
||||
is KtFile -> isKotlinFileConfigured(projectGradleFile)
|
||||
else -> error("Unknown build script file type")
|
||||
}
|
||||
|
||||
fun isKotlinFileConfigured(file: KtFile): Boolean =
|
||||
file.containsApplyKotlinPlugin(kotlinPluginName) && file.containsCompileStdLib()
|
||||
|
||||
private fun isGradleFileConfigured(file: GroovyFile): Boolean {
|
||||
val fileText = file.text
|
||||
return containsDirective(fileText, getGroovyApplyPluginDirective(kotlinPluginName)) &&
|
||||
fileText.contains("org.jetbrains.kotlin") &&
|
||||
fileText.contains("kotlin-stdlib")
|
||||
}
|
||||
@@ -109,20 +128,20 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
fun configureWithVersion(project: Project,
|
||||
modulesToConfigure: List<Module>,
|
||||
kotlinVersion: String,
|
||||
collector: NotificationMessageCollector): HashSet<GroovyFile> {
|
||||
val changedFiles = HashSet<GroovyFile>()
|
||||
val projectGradleFile = getBuildGradleFile(project, getTopLevelProjectFilePath(project))
|
||||
if (projectGradleFile != null && canConfigureFile(projectGradleFile)) {
|
||||
val isModified = changeGradleFile(projectGradleFile, true, kotlinVersion, collector)
|
||||
collector: NotificationMessageCollector): HashSet<PsiFile> {
|
||||
val changedFiles = HashSet<PsiFile>()
|
||||
val buildScript = project.getTopLevelBuildScriptPsiFile()
|
||||
if (buildScript != null && canConfigureFile(buildScript)) {
|
||||
val isModified = changeBuildScript(buildScript, true, kotlinVersion, collector)
|
||||
if (isModified) {
|
||||
changedFiles.add(projectGradleFile)
|
||||
changedFiles.add(buildScript)
|
||||
}
|
||||
}
|
||||
|
||||
for (module in modulesToConfigure) {
|
||||
val file = getBuildGradleFile(project, getModuleFilePath(module))
|
||||
val file = module.getBuildScriptPsiFile()
|
||||
if (file != null && canConfigureFile(file)) {
|
||||
val isModified = changeGradleFile(file, false, kotlinVersion, collector)
|
||||
val isModified = changeBuildScript(file, false, kotlinVersion, collector)
|
||||
if (isModified) {
|
||||
changedFiles.add(file)
|
||||
}
|
||||
@@ -134,9 +153,34 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
return changedFiles
|
||||
}
|
||||
|
||||
protected fun addElementsToModuleFile(file: GroovyFile, version: String): Boolean {
|
||||
protected fun addElementsToModuleFile(file: PsiFile, version: String): Boolean = when (file) {
|
||||
is GroovyFile -> addElementsToModuleGroovyFile(file, version)
|
||||
is KtFile -> addElementsToModuleGSKFile(file, version)
|
||||
else -> error("Unknown build script file type")
|
||||
}
|
||||
|
||||
protected fun addElementsToModuleGSKFile(file: KtFile, version: String): Boolean {
|
||||
val originalText = file.text
|
||||
val sdk = ModuleUtil.findModuleForPsiElement(file)?.let { ModuleRootManager.getInstance(it).sdk }
|
||||
file.script?.blockExpression?.addDeclarationIfMissing("val $GSK_KOTLIN_VERSION_PROPERTY_NAME: String by extra", true)
|
||||
file.getApplyBlock()?.createPluginIfMissing(kotlinPluginName)
|
||||
file.getDependenciesBlock()?.addCompileStdlibIfMissing(sdk, version)
|
||||
file.getRepositoriesBlock()?.addRepositoryIfMissing(version)
|
||||
getJvmTarget(sdk, version)?.let {
|
||||
file.changeKotlinTaskParameter("jvmTarget", it, forTests = false)
|
||||
file.changeKotlinTaskParameter("jvmTarget", it, forTests = true)
|
||||
}
|
||||
return originalText != file.text
|
||||
}
|
||||
|
||||
private fun KtBlockExpression.addCompileStdlibIfMissing(sdk: Sdk?, version: String): KtCallExpression? =
|
||||
findCompileStdLib() ?:
|
||||
addExpressionIfMissing(getKotlinScriptDependencySnippet(getStdlibArtifactName(sdk, version))) as? KtCallExpression
|
||||
|
||||
protected fun addElementsToModuleGroovyFile(file: GroovyFile, version: String): Boolean {
|
||||
val oldText = file.text
|
||||
|
||||
val applyPluginDirective = getGroovyApplyPluginDirective(kotlinPluginName)
|
||||
if (!containsDirective(file.text, applyPluginDirective)) {
|
||||
val apply = GroovyPsiElementFactory.getInstance(file.project).createExpressionFromText(applyPluginDirective)
|
||||
val applyStatement = getApplyStatement(file)
|
||||
@@ -159,7 +203,7 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
|
||||
val dependenciesBlock = getDependenciesBlock(file)
|
||||
val sdk = ModuleUtil.findModuleForPsiElement(file)?.let { ModuleRootManager.getInstance(it).sdk }
|
||||
addExpressionInBlockIfNeeded(getDependencyDirective(sdk, version), dependenciesBlock, false)
|
||||
addExpressionInBlockIfNeeded(getStdlibDependencyDirectiveForGroovy(sdk, version), dependenciesBlock, false)
|
||||
val jvmTarget = getJvmTarget(sdk, version)
|
||||
if (jvmTarget != null) {
|
||||
changeKotlinTaskParameter(file, "jvmTarget", jvmTarget, forTests = false)
|
||||
@@ -169,51 +213,48 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
return file.text != oldText
|
||||
}
|
||||
|
||||
protected open fun getDependencyDirective(sdk: Sdk?, version: String) = getRuntimeLibrary(sdk, version)
|
||||
protected open fun getStdlibArtifactName(sdk: Sdk?, version: String) = getStdlibArtifactId(sdk, version)
|
||||
|
||||
private fun getStdlibDependencyDirectiveForGroovy(sdk: Sdk?, version: String) =
|
||||
getGroovyDependencySnippet(getStdlibArtifactName(sdk, version))
|
||||
|
||||
protected open fun getJvmTarget(sdk: Sdk?, version: String): String? = null
|
||||
|
||||
protected abstract val applyPluginDirective: String
|
||||
protected abstract val kotlinPluginName: String
|
||||
|
||||
protected open fun addElementsToFile(
|
||||
groovyFile: GroovyFile,
|
||||
file: PsiFile,
|
||||
isTopLevelProjectFile: Boolean,
|
||||
version: String
|
||||
): Boolean {
|
||||
if (!isTopLevelProjectFile) {
|
||||
var wasModified = addElementsToProjectFile(groovyFile, version)
|
||||
wasModified = wasModified or addElementsToModuleFile(groovyFile, version)
|
||||
var wasModified = addElementsToProjectFile(file, version)
|
||||
wasModified = wasModified or addElementsToModuleFile(file, version)
|
||||
return wasModified
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun changeGradleFile(
|
||||
groovyFile: GroovyFile,
|
||||
fun changeBuildScript(
|
||||
file: PsiFile,
|
||||
isTopLevelProjectFile: Boolean,
|
||||
version: String,
|
||||
collector: NotificationMessageCollector
|
||||
): Boolean {
|
||||
val isModified = groovyFile.project.executeWriteCommand("Configure build.gradle", null) {
|
||||
val isModified = addElementsToFile(groovyFile, isTopLevelProjectFile, version)
|
||||
val isModified = file.project.executeWriteCommand("Configure ${file.name}", null) {
|
||||
val isModified = addElementsToFile(file, isTopLevelProjectFile, version)
|
||||
|
||||
CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(groovyFile)
|
||||
CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(file)
|
||||
isModified
|
||||
}
|
||||
|
||||
val virtualFile = groovyFile.virtualFile
|
||||
val virtualFile = file.virtualFile
|
||||
if (virtualFile != null && isModified) {
|
||||
collector.addMessage(virtualFile.path + " was modified")
|
||||
}
|
||||
return isModified
|
||||
}
|
||||
|
||||
open fun getRuntimeLibrary(sdk: Sdk?, version: String): String {
|
||||
return getRuntimeLibraryForSdk(sdk, version)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val VERSION_TEMPLATE = "\$VERSION$"
|
||||
|
||||
@@ -222,21 +263,25 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
|
||||
val CLASSPATH = "classpath \"$GROUP_ID:$GRADLE_PLUGIN_ID:\$kotlin_version\""
|
||||
|
||||
private val MAVEN_CENTRAL = "mavenCentral()\n"
|
||||
private val JCENTER = "jcenter()\n"
|
||||
private val MAVEN_CENTRAL = "mavenCentral()"
|
||||
private val JCENTER = "jcenter()"
|
||||
|
||||
private val VERSION = String.format("ext.kotlin_version = '%s'", VERSION_TEMPLATE)
|
||||
|
||||
private val KOTLIN_BUILD_SCRIPT_NAME = "build.gradle.kts"
|
||||
|
||||
private fun containsDirective(fileText: String, directive: String): Boolean {
|
||||
return fileText.contains(directive)
|
||||
|| fileText.contains(directive.replace("\"", "'"))
|
||||
|| fileText.contains(directive.replace("'", "\""))
|
||||
}
|
||||
|
||||
fun addKotlinLibraryToModule(module: Module, scope: DependencyScope, libraryDescriptor: ExternalLibraryDescriptor) {
|
||||
val gradleFilePath = getModuleFilePath(module)
|
||||
val gradleFile = getBuildGradleFile(module.project, gradleFilePath)
|
||||
fun getGroovyDependencySnippet(artifactName: String) = "compile \"org.jetbrains.kotlin:$artifactName:\$kotlin_version\""
|
||||
|
||||
fun getGroovyApplyPluginDirective(pluginName: String) = "apply plugin: '$pluginName'"
|
||||
|
||||
fun addKotlinLibraryToModule(module: Module, scope: DependencyScope, libraryDescriptor: ExternalLibraryDescriptor) {
|
||||
val gradleFile = module.getBuildScriptPsiFile() as? GroovyFile
|
||||
if (gradleFile != null && canConfigureFile(gradleFile)) {
|
||||
gradleFile.project.executeWriteCommand("Add Kotlin library") {
|
||||
val groovyScope = when (scope) {
|
||||
@@ -274,8 +319,12 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
}
|
||||
|
||||
fun changeCoroutineConfiguration(module: Module, coroutineOption: String): PsiElement? {
|
||||
return changeBuildGradle(module) { gradleFile ->
|
||||
changeCoroutineConfiguration(gradleFile, coroutineOption)
|
||||
return changeBuildGradle(module) { buildScriptFile ->
|
||||
when (buildScriptFile) {
|
||||
is GroovyFile -> changeCoroutineConfiguration(buildScriptFile, coroutineOption)
|
||||
is KtFile -> changeCoroutineConfiguration(buildScriptFile, coroutineOption)
|
||||
else -> error("Unknown build script file type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,18 +339,36 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
}
|
||||
|
||||
fun changeLanguageVersion(module: Module, languageVersion: String?, apiVersion: String? = null, forTests: Boolean): PsiElement? {
|
||||
return changeBuildGradle(module) { gradleFile ->
|
||||
return changeBuildGradle(module) { buildScriptFile ->
|
||||
var result: PsiElement? = null
|
||||
if (languageVersion != null) {
|
||||
result = changeLanguageVersion(gradleFile, languageVersion, forTests)
|
||||
result = when (buildScriptFile) {
|
||||
is GroovyFile -> changeLanguageVersion(buildScriptFile, languageVersion, forTests)
|
||||
is KtFile -> changeLanguageVersion(buildScriptFile, languageVersion, forTests)
|
||||
else -> error("Unknown build script file type")
|
||||
}
|
||||
}
|
||||
|
||||
if (apiVersion != null) {
|
||||
result = changeApiVersion(gradleFile, apiVersion, forTests)
|
||||
result = when (buildScriptFile) {
|
||||
is GroovyFile -> changeApiVersion(buildScriptFile, apiVersion, forTests)
|
||||
is KtFile -> changeApiVersion(buildScriptFile, apiVersion, forTests)
|
||||
else -> error("Unknown build script file type")
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
fun changeLanguageVersion(gradleFile: KtFile, languageVersion: String, forTests: Boolean): PsiElement? {
|
||||
return gradleFile.changeKotlinTaskParameter("languageVersion", languageVersion, forTests)
|
||||
}
|
||||
|
||||
fun changeApiVersion(gradleFile: KtFile, apiVersion: String, forTests: Boolean): PsiElement? {
|
||||
return gradleFile.changeKotlinTaskParameter("apiVersion", apiVersion, forTests)
|
||||
}
|
||||
|
||||
fun changeLanguageVersion(gradleFile: GroovyFile, languageVersion: String, forTests: Boolean): PsiElement? {
|
||||
return changeKotlinTaskParameter(gradleFile, "languageVersion", languageVersion, forTests)
|
||||
}
|
||||
@@ -327,12 +394,11 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
return kotlinBlock.parent
|
||||
}
|
||||
|
||||
private fun changeBuildGradle(module: Module, body: (GroovyFile) -> PsiElement?): PsiElement? {
|
||||
val gradleFilePath = getModuleFilePath(module)
|
||||
val gradleFile = getBuildGradleFile(module.project, gradleFilePath)
|
||||
if (gradleFile != null && canConfigureFile(gradleFile)) {
|
||||
return gradleFile.project.executeWriteCommand("Change build.gradle configuration", null) {
|
||||
body(gradleFile)
|
||||
private fun changeBuildGradle(module: Module, body: (PsiFile) -> PsiElement?): PsiElement? {
|
||||
val buildScriptFile = module.getBuildScriptPsiFile()
|
||||
if (buildScriptFile != null && canConfigureFile(buildScriptFile)) {
|
||||
return buildScriptFile.project.executeWriteCommand("Change build.gradle configuration", null) {
|
||||
body(buildScriptFile)
|
||||
}
|
||||
}
|
||||
return null
|
||||
@@ -353,9 +419,7 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
}
|
||||
|
||||
fun getKotlinStdlibVersion(module: Module): String? {
|
||||
val gradleFilePath = getModuleFilePath(module)
|
||||
val gradleFile = getBuildGradleFile(module.project, gradleFilePath) ?: return null
|
||||
|
||||
val gradleFile = module.getBuildScriptPsiFile() as? GroovyFile ?: return null
|
||||
val versionProperty = "\$kotlin_version"
|
||||
val block = getBuildScriptBlock(gradleFile)
|
||||
if (block.text.contains("ext.kotlin_version = ")) {
|
||||
@@ -376,7 +440,28 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
return null
|
||||
}
|
||||
|
||||
fun addElementsToProjectFile(file: GroovyFile, version: String): Boolean {
|
||||
fun addElementsToProjectFile(file: PsiFile, version: String): Boolean = when (file) {
|
||||
is GroovyFile -> addElementsToProjectGroovyFile(file, version)
|
||||
is KtFile -> addElementsToProjectGSKFile(file, version)
|
||||
else -> error("Unknown build script file type")
|
||||
}
|
||||
|
||||
fun addElementsToProjectGSKFile(file: KtFile, version: String): Boolean {
|
||||
val originalText = file.text
|
||||
|
||||
file.getBuildScriptBlock()?.apply {
|
||||
addDeclarationIfMissing("var $GSK_KOTLIN_VERSION_PROPERTY_NAME: String by extra", true).also {
|
||||
addExpressionAfterIfMissing("$GSK_KOTLIN_VERSION_PROPERTY_NAME = \"$version\"", it)
|
||||
}
|
||||
|
||||
getRepositoriesBlock()?.addRepositoryIfMissing(version)
|
||||
getDependenciesBlock()?.addPluginToClassPathIfMissing()
|
||||
}
|
||||
|
||||
return originalText != file.text
|
||||
}
|
||||
|
||||
fun addElementsToProjectGroovyFile(file: GroovyFile, version: String): Boolean {
|
||||
var wasModified: Boolean
|
||||
|
||||
val buildScriptBlock = getBuildScriptBlock(file)
|
||||
@@ -391,53 +476,47 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
return wasModified
|
||||
}
|
||||
|
||||
private fun isRepositoryConfigured(repositoriesBlock: GrClosableBlock): Boolean {
|
||||
return repositoriesBlock.text.contains(MAVEN_CENTRAL) || repositoriesBlock.text.contains(JCENTER)
|
||||
private fun isRepositoryConfigured(repositoriesBlockText: String): Boolean {
|
||||
return repositoriesBlockText.contains(MAVEN_CENTRAL) || repositoriesBlockText.contains(JCENTER)
|
||||
}
|
||||
|
||||
private fun canConfigureFile(file: GroovyFile): Boolean {
|
||||
private fun canConfigureFile(file: PsiFile): Boolean {
|
||||
return WritingAccessProvider.isPotentiallyWritable(file.virtualFile, null)
|
||||
}
|
||||
|
||||
private fun getBuildGradleFile(project: Project, path: String?): GroovyFile? {
|
||||
if (path == null) {
|
||||
return null
|
||||
}
|
||||
val file = VfsUtil.findFileByIoFile(File(path), true) ?: return null
|
||||
val psiFile = PsiManager.getInstance(project).findFile(file) as? GroovyFile ?: return null
|
||||
return psiFile
|
||||
}
|
||||
private fun Module.getBuildScriptPsiFile() = getBuildScriptFile()?.getPsiFile(project)
|
||||
|
||||
private fun getTopLevelProjectFilePath(project: Project): String {
|
||||
return project.basePath + "/" + GradleConstants.DEFAULT_SCRIPT_NAME
|
||||
}
|
||||
private fun Project.getTopLevelBuildScriptPsiFile() = basePath?.let { findBuildGradleFile(it)?.getPsiFile(this) }
|
||||
|
||||
private fun getModuleFilePath(module: Module): String? {
|
||||
val moduleDir = File(module.moduleFilePath).parent
|
||||
var buildGradleFile = File(moduleDir + "/" + GradleConstants.DEFAULT_SCRIPT_NAME)
|
||||
if (buildGradleFile.exists()) {
|
||||
return buildGradleFile.path
|
||||
private fun Module.getBuildScriptFile(): File? {
|
||||
val moduleDir = File(moduleFilePath).parent
|
||||
findBuildGradleFile(moduleDir)?.let {
|
||||
return it
|
||||
}
|
||||
|
||||
// since IDEA 145 module file is located in .idea directory
|
||||
for (file in ModuleRootManager.getInstance(module).contentRoots) {
|
||||
buildGradleFile = File(file.path + "/" + GradleConstants.DEFAULT_SCRIPT_NAME)
|
||||
if (buildGradleFile.exists()) {
|
||||
return buildGradleFile.path
|
||||
ModuleRootManager.getInstance(this).contentRoots.forEach { root ->
|
||||
findBuildGradleFile(root.path)?.let {
|
||||
return it
|
||||
}
|
||||
}
|
||||
|
||||
val externalProjectPath = ExternalSystemApiUtil.getExternalProjectPath(module)
|
||||
if (externalProjectPath != null) {
|
||||
buildGradleFile = File(externalProjectPath + "/" + GradleConstants.DEFAULT_SCRIPT_NAME)
|
||||
if (buildGradleFile.exists()) {
|
||||
return buildGradleFile.path
|
||||
ExternalSystemApiUtil.getExternalProjectPath(this)?.let { externalProjectPath ->
|
||||
findBuildGradleFile(externalProjectPath)?.let {
|
||||
return it
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
private fun findBuildGradleFile(path: String): File? =
|
||||
File(path + "/" + GradleConstants.DEFAULT_SCRIPT_NAME).takeIf { it.exists() } ?:
|
||||
File(path + "/" + KOTLIN_BUILD_SCRIPT_NAME).takeIf { it.exists() }
|
||||
|
||||
private fun File.getPsiFile(project: Project) = VfsUtil.findFileByIoFile(this, true)?.let {
|
||||
PsiManager.getInstance(project).findFile(it)
|
||||
}
|
||||
|
||||
private fun getDependenciesBlock(file: GrStatementOwner): GrClosableBlock {
|
||||
return getBlockOrCreate(file, "dependencies")
|
||||
}
|
||||
@@ -456,7 +535,7 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
|
||||
private fun getRepositoriesBlock(file: GrStatementOwner) = getBlockOrCreate(file, "repositories")
|
||||
|
||||
fun getBlockOrCreate(parent: GrStatementOwner, name: String): GrClosableBlock {
|
||||
private fun getBlockOrCreate(parent: GrStatementOwner, name: String): GrClosableBlock {
|
||||
var block = getBlockByName(parent, name)
|
||||
if (block == null) {
|
||||
val factory = GroovyPsiElementFactory.getInstance(parent.project)
|
||||
@@ -467,7 +546,7 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
return block
|
||||
}
|
||||
|
||||
fun addLastExpressionInBlockIfNeeded(text: String, block: GrClosableBlock): Boolean {
|
||||
private fun addLastExpressionInBlockIfNeeded(text: String, block: GrClosableBlock): Boolean {
|
||||
return addExpressionInBlockIfNeeded(text, block, false)
|
||||
}
|
||||
|
||||
@@ -517,17 +596,11 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
private fun addRepository(repositoriesBlock: GrClosableBlock, version: String): Boolean {
|
||||
val repository = getRepositoryForVersion(version)
|
||||
val snippet = when {
|
||||
repository != null -> repository.toRepositorySnippet()
|
||||
!isRepositoryConfigured(repositoriesBlock) -> MAVEN_CENTRAL
|
||||
repository != null -> repository.toGroovyRepositorySnippet()
|
||||
!isRepositoryConfigured(repositoriesBlock.text) -> "$MAVEN_CENTRAL\n"
|
||||
else -> return false
|
||||
}
|
||||
return addLastExpressionInBlockIfNeeded(snippet, repositoriesBlock)
|
||||
}
|
||||
|
||||
fun getRuntimeLibraryForSdk(sdk: Sdk?, version: String): String {
|
||||
return getDependencySnippet(getStdlibArtifactId(sdk, version))
|
||||
}
|
||||
|
||||
fun getDependencySnippet(artifactId: String) = "compile \"org.jetbrains.kotlin:$artifactId:\$kotlin_version\""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ abstract class KotlinWithLibraryConfigurator internal constructor() : KotlinProj
|
||||
val showPathToJarPanel = needToChooseJarPath(project)
|
||||
|
||||
var nonConfiguredModules = if (!ApplicationManager.getApplication().isUnitTestMode)
|
||||
getNonConfiguredModules(project, this)
|
||||
getCanBeConfiguredModules(project, this)
|
||||
else
|
||||
Arrays.asList(*ModuleManager.getInstance(project).modules)
|
||||
nonConfiguredModules -= excludeModules
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinProjectConfigurator
|
||||
import org.jetbrains.kotlin.idea.configuration.getAbleToRunConfigurators
|
||||
import org.jetbrains.kotlin.idea.configuration.getConfiguratorByName
|
||||
import org.jetbrains.kotlin.idea.configuration.getNonConfiguredModulesWithKotlinFiles
|
||||
import org.jetbrains.kotlin.idea.configuration.getCanBeConfiguredModulesWithKotlinFiles
|
||||
import org.jetbrains.kotlin.idea.configuration.ui.KotlinConfigurationCheckerComponent
|
||||
import javax.swing.event.HyperlinkEvent
|
||||
|
||||
@@ -57,7 +57,7 @@ class ConfigureKotlinNotification(
|
||||
|
||||
companion object {
|
||||
fun getNotificationString(project: Project, excludeModules: Collection<Module>): String? {
|
||||
val modules = getNonConfiguredModulesWithKotlinFiles(project, excludeModules)
|
||||
val modules = getCanBeConfiguredModulesWithKotlinFiles(project, excludeModules)
|
||||
|
||||
val isOnlyOneModule = modules.size == 1
|
||||
|
||||
|
||||
@@ -52,8 +52,8 @@ public class ChooseModulePanel {
|
||||
|
||||
public ChooseModulePanel(@NotNull Project project, @NotNull KotlinProjectConfigurator configurator, Collection<Module> excludeModules) {
|
||||
this.project = project;
|
||||
this.modules = ConfigureKotlinInProjectUtilsKt.getNonConfiguredModules(project, configurator);
|
||||
this.modulesWithKtFiles = ConfigureKotlinInProjectUtilsKt.getNonConfiguredModulesWithKotlinFiles(project, configurator);
|
||||
this.modules = ConfigureKotlinInProjectUtilsKt.getCanBeConfiguredModules(project, configurator);
|
||||
this.modulesWithKtFiles = ConfigureKotlinInProjectUtilsKt.getCanBeConfiguredModulesWithKotlinFiles(project, configurator);
|
||||
|
||||
DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
val kotlin_version: String by extra
|
||||
buildscript {
|
||||
var kotlin_version: String by extra
|
||||
kotlin_version = "$VERSION$"
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath(kotlinModule("gradle-plugin", kotlin_version))
|
||||
}
|
||||
}
|
||||
apply {
|
||||
plugin("kotlin-android")
|
||||
}
|
||||
dependencies {
|
||||
compile(kotlinModule("stdlib-jre7", kotlin_version))
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
|
||||
val kotlin_version: String by extra
|
||||
buildscript {
|
||||
var kotlin_version: String by extra
|
||||
kotlin_version = "$VERSION$"
|
||||
dependencies {
|
||||
classpath("com.android.tools.build:gradle:2.3.1")
|
||||
classpath(kotlinModule("gradle-plugin", kotlin_version))
|
||||
}
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
apply {
|
||||
plugin("com.android.application")
|
||||
plugin("kotlin-android")
|
||||
}
|
||||
|
||||
android {
|
||||
buildToolsVersion("25.0.0")
|
||||
compileSdkVersion(23)
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion(15)
|
||||
targetSdkVersion(23)
|
||||
|
||||
applicationId = "com.example.kotlingradle"
|
||||
versionCode = 1
|
||||
versionName = "1.0"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
getByName("release") {
|
||||
isMinifyEnabled = false
|
||||
proguardFiles("proguard-rules.pro")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile("com.android.support:appcompat-v7:23.4.0")
|
||||
compile("com.android.support.constraint:constraint-layout:1.0.0-alpha8")
|
||||
compile(kotlinModule("stdlib-jre7", kotlin_version))
|
||||
}
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath("com.android.tools.build:gradle:2.3.1")
|
||||
}
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
apply {
|
||||
plugin("com.android.application")
|
||||
}
|
||||
|
||||
android {
|
||||
buildToolsVersion("25.0.0")
|
||||
compileSdkVersion(23)
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion(15)
|
||||
targetSdkVersion(23)
|
||||
|
||||
applicationId = "com.example.kotlingradle"
|
||||
versionCode = 1
|
||||
versionName = "1.0"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
getByName("release") {
|
||||
isMinifyEnabled = false
|
||||
proguardFiles("proguard-rules.pro")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile("com.android.support:appcompat-v7:23.4.0")
|
||||
compile("com.android.support.constraint:constraint-layout:1.0.0-alpha8")
|
||||
}
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import org.gradle.api.JavaVersion.VERSION_1_7
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
val kotlin_version: String by extra
|
||||
buildscript {
|
||||
var kotlin_version: String by extra
|
||||
kotlin_version = "$VERSION$"
|
||||
repositories {
|
||||
maven {
|
||||
setUrl("http://dl.bintray.com/kotlin/kotlin-eap-1.1")
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath(kotlinModule("gradle-plugin", kotlin_version))
|
||||
}
|
||||
}
|
||||
plugins {
|
||||
application
|
||||
}
|
||||
apply {
|
||||
plugin("kotlin")
|
||||
}
|
||||
|
||||
application {
|
||||
mainClassName = "samples.HelloWorld"
|
||||
}
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
setUrl("http://dl.bintray.com/kotlin/kotlin-eap-1.1")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit:4.12")
|
||||
compile(kotlinModule("stdlib-jre8", kotlin_version))
|
||||
}
|
||||
val compileKotlin: KotlinCompile by tasks
|
||||
compileKotlin.kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
val compileTestKotlin: KotlinCompile by tasks
|
||||
compileTestKotlin.kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
|
||||
// VERSION: $VERSION$
|
||||
@@ -0,0 +1,19 @@
|
||||
import org.gradle.api.JavaVersion.VERSION_1_7
|
||||
|
||||
plugins {
|
||||
application
|
||||
}
|
||||
|
||||
application {
|
||||
mainClassName = "samples.HelloWorld"
|
||||
}
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit:4.12")
|
||||
}
|
||||
|
||||
// VERSION: 1.1.2-eap-14-IJ143-14
|
||||
@@ -0,0 +1,39 @@
|
||||
import org.gradle.api.JavaVersion.VERSION_1_7
|
||||
|
||||
val kotlin_version: String by extra
|
||||
buildscript {
|
||||
var kotlin_version: String by extra
|
||||
kotlin_version = "$VERSION$"
|
||||
repositories {
|
||||
maven {
|
||||
setUrl("http://dl.bintray.com/kotlin/kotlin-eap")
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath(kotlinModule("gradle-plugin", kotlin_version))
|
||||
}
|
||||
}
|
||||
plugins {
|
||||
application
|
||||
}
|
||||
apply {
|
||||
plugin("kotlin")
|
||||
}
|
||||
|
||||
application {
|
||||
mainClassName = "samples.HelloWorld"
|
||||
}
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
setUrl("http://dl.bintray.com/kotlin/kotlin-eap")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit:4.12")
|
||||
compile(kotlinModule("stdlib", kotlin_version))
|
||||
}
|
||||
|
||||
// VERSION: $VERSION$
|
||||
@@ -0,0 +1,19 @@
|
||||
import org.gradle.api.JavaVersion.VERSION_1_7
|
||||
|
||||
plugins {
|
||||
application
|
||||
}
|
||||
|
||||
application {
|
||||
mainClassName = "samples.HelloWorld"
|
||||
}
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit:4.12")
|
||||
}
|
||||
|
||||
// VERSION: 1.0.2-eap-14-IJ143-14
|
||||
@@ -0,0 +1,41 @@
|
||||
import org.gradle.api.JavaVersion.VERSION_1_7
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
val kotlin_version: String by extra
|
||||
buildscript {
|
||||
var kotlin_version: String by extra
|
||||
kotlin_version = "$VERSION$"
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath(kotlinModule("gradle-plugin", kotlin_version))
|
||||
}
|
||||
}
|
||||
plugins {
|
||||
application
|
||||
}
|
||||
apply {
|
||||
plugin("kotlin")
|
||||
}
|
||||
|
||||
application {
|
||||
mainClassName = "samples.HelloWorld"
|
||||
}
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit:4.12")
|
||||
compile(kotlinModule("stdlib-jre8", kotlin_version))
|
||||
}
|
||||
val compileKotlin: KotlinCompile by tasks
|
||||
compileKotlin.kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
val compileTestKotlin: KotlinCompile by tasks
|
||||
compileTestKotlin.kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import org.gradle.api.JavaVersion.VERSION_1_7
|
||||
|
||||
plugins {
|
||||
application
|
||||
}
|
||||
|
||||
application {
|
||||
mainClassName = "samples.HelloWorld"
|
||||
}
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit:4.12")
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import org.gradle.api.JavaVersion.VERSION_1_7
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
val kotlin_version: String by extra
|
||||
buildscript {
|
||||
var kotlin_version: String by extra
|
||||
kotlin_version = "$VERSION$"
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath(kotlinModule("gradle-plugin", kotlin_version))
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
application
|
||||
}
|
||||
|
||||
apply {
|
||||
plugin("kotlin")
|
||||
}
|
||||
|
||||
application {
|
||||
mainClassName = "samples.HelloWorld"
|
||||
}
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit:4.12")
|
||||
compile(kotlinModule("stdlib-jre8", kotlin_version))
|
||||
}
|
||||
val compileKotlin: KotlinCompile by tasks
|
||||
compileKotlin.kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
val compileTestKotlin: KotlinCompile by tasks
|
||||
compileTestKotlin.kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import org.gradle.api.JavaVersion.VERSION_1_7
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath(kotlinModule("gradle-plugin", kotlin_version))
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
application
|
||||
}
|
||||
|
||||
apply {
|
||||
plugin("kotlin")
|
||||
}
|
||||
|
||||
application {
|
||||
mainClassName = "samples.HelloWorld"
|
||||
}
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit:4.12")
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import org.gradle.api.JavaVersion.VERSION_1_7
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
val kotlin_version: String by extra
|
||||
buildscript {
|
||||
var kotlin_version: String by extra
|
||||
kotlin_version = "$VERSION$"
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath(kotlinModule("gradle-plugin", kotlin_version))
|
||||
}
|
||||
}
|
||||
plugins {
|
||||
application
|
||||
}
|
||||
|
||||
apply {
|
||||
plugin("kotlin")
|
||||
}
|
||||
|
||||
application {
|
||||
mainClassName = "samples.HelloWorld"
|
||||
}
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit:4.12")
|
||||
compile(kotlinModule("stdlib-jre8", kotlin_version))
|
||||
}
|
||||
val compileKotlin: KotlinCompile by tasks
|
||||
compileKotlin.kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
val compileTestKotlin: KotlinCompile by tasks
|
||||
compileTestKotlin.kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import org.gradle.api.JavaVersion.VERSION_1_7
|
||||
|
||||
plugins {
|
||||
application
|
||||
}
|
||||
|
||||
apply {
|
||||
plugin("kotlin")
|
||||
}
|
||||
|
||||
application {
|
||||
mainClassName = "samples.HelloWorld"
|
||||
}
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit:4.12")
|
||||
}
|
||||
@@ -18,7 +18,9 @@ package org.jetbrains.kotlin.gradle
|
||||
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinWithGradleConfigurator
|
||||
import org.jetbrains.kotlin.idea.configuration.changeCoroutineConfiguration
|
||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile
|
||||
|
||||
class KotlinWithGradleConfiguratorTest : LightCodeInsightFixtureTestCase() {
|
||||
@@ -37,6 +39,19 @@ class KotlinWithGradleConfiguratorTest : LightCodeInsightFixtureTestCase() {
|
||||
|""".trimMargin("|"))
|
||||
}
|
||||
|
||||
fun testAddCoroutinesSupportGSK() {
|
||||
val buildGradle = myFixture.configureByText("build.gradle.kts", "") as KtFile
|
||||
myFixture.project.executeWriteCommand("") {
|
||||
changeCoroutineConfiguration(buildGradle, "enable")
|
||||
}
|
||||
myFixture.checkResult(
|
||||
"""import org.jetbrains.kotlin.gradle.dsl.Coroutines
|
||||
|
|
||||
|kotlin {
|
||||
| experimental.coroutines = Coroutines.ENABLE
|
||||
|}""".trimMargin("|"))
|
||||
}
|
||||
|
||||
fun testChangeCoroutinesSupport() {
|
||||
val buildGradle = myFixture.configureByText("build.gradle",
|
||||
"""apply plugin: 'kotlin'
|
||||
@@ -59,6 +74,26 @@ class KotlinWithGradleConfiguratorTest : LightCodeInsightFixtureTestCase() {
|
||||
|""".trimMargin("|"))
|
||||
}
|
||||
|
||||
fun testChangeCoroutinesSupportGSK() {
|
||||
val buildGradle = myFixture.configureByText("build.gradle.kts",
|
||||
"""import org.jetbrains.kotlin.gradle.dsl.Coroutines
|
||||
|
|
||||
|kotlin {
|
||||
| experimental.coroutines = Coroutines.DISABLE
|
||||
|}
|
||||
|""".trimMargin("|")) as KtFile
|
||||
myFixture.project.executeWriteCommand("") {
|
||||
changeCoroutineConfiguration(buildGradle, "enable")
|
||||
}
|
||||
myFixture.checkResult(
|
||||
"""import org.jetbrains.kotlin.gradle.dsl.Coroutines
|
||||
|
|
||||
|kotlin {
|
||||
| experimental.coroutines = Coroutines.ENABLE
|
||||
|}
|
||||
|""".trimMargin("|"))
|
||||
}
|
||||
|
||||
fun testAddLanguageVersion() {
|
||||
val buildGradle = myFixture.configureByText("build.gradle", "apply plugin: 'kotlin'\n") as GroovyFile
|
||||
myFixture.project.executeWriteCommand("") {
|
||||
@@ -74,6 +109,20 @@ class KotlinWithGradleConfiguratorTest : LightCodeInsightFixtureTestCase() {
|
||||
|""".trimMargin("|"))
|
||||
}
|
||||
|
||||
fun testAddLanguageVersionGSK() {
|
||||
val buildGradle = myFixture.configureByText("build.gradle.kts", "") as KtFile
|
||||
myFixture.project.executeWriteCommand("") {
|
||||
KotlinWithGradleConfigurator.changeLanguageVersion(buildGradle, "1.1", false)
|
||||
}
|
||||
myFixture.checkResult(
|
||||
"""import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
|
||||
|val compileKotlin: KotlinCompile by tasks
|
||||
|compileKotlin.kotlinOptions {
|
||||
| languageVersion = "1.1"
|
||||
|}""".trimMargin("|"))
|
||||
}
|
||||
|
||||
fun testChangeLanguageVersion() {
|
||||
val buildGradle = myFixture.configureByText("build.gradle",
|
||||
"""apply plugin: 'kotlin'
|
||||
@@ -95,4 +144,22 @@ class KotlinWithGradleConfiguratorTest : LightCodeInsightFixtureTestCase() {
|
||||
|}
|
||||
|""".trimMargin("|"))
|
||||
}
|
||||
|
||||
fun testChangeLanguageVersionGSK() {
|
||||
val buildGradle = myFixture.configureByText("build.gradle.kts",
|
||||
"""val compileKotlin: KotlinCompile by tasks
|
||||
|compileKotlin.kotlinOptions {
|
||||
| languageVersion = "1.0"
|
||||
|}
|
||||
|""".trimMargin("|")) as KtFile
|
||||
myFixture.project.executeWriteCommand("") {
|
||||
KotlinWithGradleConfigurator.changeLanguageVersion(buildGradle, "1.1", false)
|
||||
}
|
||||
myFixture.checkResult(
|
||||
"""val compileKotlin: KotlinCompile by tasks
|
||||
|compileKotlin.kotlinOptions {
|
||||
| languageVersion = "1.1"
|
||||
|}
|
||||
|""".trimMargin("|"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,6 +117,67 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
|
||||
|
||||
private fun findJsGradleModuleConfigurator() = Extensions.findExtension(KotlinProjectConfigurator.EP_NAME,
|
||||
KotlinJsGradleModuleConfigurator::class.java)
|
||||
|
||||
@Test
|
||||
fun testConfigureGSK() {
|
||||
createProjectSubFile("settings.gradle", "include ':app'")
|
||||
val file = createProjectSubFile("app/build.gradle.kts", """
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
|
||||
importProject()
|
||||
|
||||
runInEdtAndWait {
|
||||
runWriteAction {
|
||||
val module = ModuleManager.getInstance(myProject).findModuleByName("app")!!
|
||||
val configurator = findGradleModuleConfigurator()
|
||||
val collector = createConfigureKotlinNotificationCollector(myProject)
|
||||
configurator.configureWithVersion(myProject, listOf(module), "1.1.2", collector)
|
||||
|
||||
FileDocumentManager.getInstance().saveAllDocuments()
|
||||
val content = LoadTextUtil.loadText(file).toString()
|
||||
assertEquals("""
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
val kotlin_version: String by extra
|
||||
buildscript {
|
||||
var kotlin_version: String by extra
|
||||
kotlin_version = "1.1.2"
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath(kotlinModule("gradle-plugin", kotlin_version))
|
||||
}
|
||||
}
|
||||
apply {
|
||||
plugin("kotlin")
|
||||
}
|
||||
dependencies {
|
||||
compile(kotlinModule("stdlib-jre8", kotlin_version))
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
val compileKotlin: KotlinCompile by tasks
|
||||
compileKotlin.kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
val compileTestKotlin: KotlinCompile by tasks
|
||||
compileTestKotlin.kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
""".trimIndent(), content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListNonConfiguredModules() {
|
||||
createProjectSubFile("settings.gradle", "include ':app'")
|
||||
@@ -137,13 +198,13 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
|
||||
runReadAction {
|
||||
val configurator = findGradleModuleConfigurator()
|
||||
|
||||
val moduleNames = getNonConfiguredModulesWithKotlinFiles(myProject).map { it.name }
|
||||
val moduleNames = getCanBeConfiguredModulesWithKotlinFiles(myProject).map { it.name }
|
||||
assertSameElements(moduleNames, "app")
|
||||
|
||||
val moduleNamesFromConfigurator = getNonConfiguredModules(myProject, configurator).map { it.name }
|
||||
assertSameElements(moduleNamesFromConfigurator, "app", "project")
|
||||
val moduleNamesFromConfigurator = getCanBeConfiguredModules(myProject, configurator).map { it.name }
|
||||
assertSameElements(moduleNamesFromConfigurator, "app")
|
||||
|
||||
val moduleNamesWithKotlinFiles = getNonConfiguredModulesWithKotlinFiles(myProject, configurator).map { it.name }
|
||||
val moduleNamesWithKotlinFiles = getCanBeConfiguredModulesWithKotlinFiles(myProject, configurator).map { it.name }
|
||||
assertSameElements(moduleNamesWithKotlinFiles, "app")
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.configuration
|
||||
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile
|
||||
|
||||
abstract class AbstractGradleConfigureProjectByChangingFileTest : AbstractConfigureProjectByChangingFileTest<KotlinWithGradleConfigurator>() {
|
||||
@@ -28,12 +29,12 @@ abstract class AbstractGradleConfigureProjectByChangingFileTest : AbstractConfig
|
||||
}
|
||||
|
||||
override fun runConfigurator(module: Module, file: PsiFile, configurator: KotlinWithGradleConfigurator, version: String, collector: NotificationMessageCollector) {
|
||||
if (file !is GroovyFile) {
|
||||
fail("file $file is not a GroovyFile")
|
||||
if (file !is GroovyFile && file !is KtFile) {
|
||||
fail("file $file is not a GroovyFile or KtFile")
|
||||
return
|
||||
}
|
||||
|
||||
configurator.changeGradleFile(file, true, version, collector)
|
||||
configurator.changeGradleFile(file, false, version, collector)
|
||||
configurator.changeBuildScript(file, true, version, collector)
|
||||
configurator.changeBuildScript(file, false, version, collector)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,12 +91,12 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
|
||||
|
||||
public void testTwoModulesWithNonDefaultPath_doNotCopyInDefault() throws IOException {
|
||||
doTestConfigureModulesWithNonDefaultSetup(JAVA_CONFIGURATOR);
|
||||
assertEmpty(ConfigureKotlinInProjectUtilsKt.getNonConfiguredModules(myProject, JS_CONFIGURATOR));
|
||||
assertEmpty(ConfigureKotlinInProjectUtilsKt.getCanBeConfiguredModules(myProject, JS_CONFIGURATOR));
|
||||
}
|
||||
|
||||
public void testTwoModulesWithJSNonDefaultPath_doNotCopyInDefault() throws IOException {
|
||||
doTestConfigureModulesWithNonDefaultSetup(JS_CONFIGURATOR);
|
||||
assertEmpty(ConfigureKotlinInProjectUtilsKt.getNonConfiguredModules(myProject, JAVA_CONFIGURATOR));
|
||||
assertEmpty(ConfigureKotlinInProjectUtilsKt.getCanBeConfiguredModules(myProject, JAVA_CONFIGURATOR));
|
||||
}
|
||||
|
||||
public void testNewLibrary_jarExists_js() {
|
||||
|
||||
+81
-39
@@ -28,53 +28,95 @@ import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/configuration/gradle")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class GradleConfigureProjectByChangingFileTestGenerated extends AbstractGradleConfigureProjectByChangingFileTest {
|
||||
public void testAllFilesPresentInGradle() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/configuration/gradle"), Pattern.compile("(\\w+)_before\\.gradle$"), TargetBackend.ANY, true);
|
||||
@TestMetadata("idea/testData/configuration/gradle")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Gradle extends AbstractGradleConfigureProjectByChangingFileTest {
|
||||
public void testAllFilesPresentInGradle() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/configuration/gradle"), Pattern.compile("(\\w+)_before\\.gradle$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("default_before.gradle")
|
||||
public void testDefault() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/default_before.gradle");
|
||||
doTestGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("eapVersion_before.gradle")
|
||||
public void testEapVersion() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/eapVersion_before.gradle");
|
||||
doTestGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("js_before.gradle")
|
||||
public void testJs() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/js_before.gradle");
|
||||
doTestGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("m04Version_before.gradle")
|
||||
public void testM04Version() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/m04Version_before.gradle");
|
||||
doTestGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("missedLibrary_before.gradle")
|
||||
public void testMissedLibrary() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/missedLibrary_before.gradle");
|
||||
doTestGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("plugin_present_before.gradle")
|
||||
public void testPlugin_present() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/plugin_present_before.gradle");
|
||||
doTestGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("rcVersion_before.gradle")
|
||||
public void testRcVersion() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/rcVersion_before.gradle");
|
||||
doTestGradle(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("default_before.gradle")
|
||||
public void testDefault() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/default_before.gradle");
|
||||
doTestGradle(fileName);
|
||||
}
|
||||
@TestMetadata("idea/testData/configuration/gsk")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Gsk extends AbstractGradleConfigureProjectByChangingFileTest {
|
||||
public void testAllFilesPresentInGsk() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/configuration/gsk"), Pattern.compile("(\\w+)_before\\.gradle.kts$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("eapVersion_before.gradle")
|
||||
public void testEapVersion() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/eapVersion_before.gradle");
|
||||
doTestGradle(fileName);
|
||||
}
|
||||
@TestMetadata("eap11Version_before.gradle.kts")
|
||||
public void testEap11Version() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gsk/eap11Version_before.gradle.kts");
|
||||
doTestGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("js_before.gradle")
|
||||
public void testJs() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/js_before.gradle");
|
||||
doTestGradle(fileName);
|
||||
}
|
||||
@TestMetadata("eapVersion_before.gradle.kts")
|
||||
public void testEapVersion() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gsk/eapVersion_before.gradle.kts");
|
||||
doTestGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("m04Version_before.gradle")
|
||||
public void testM04Version() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/m04Version_before.gradle");
|
||||
doTestGradle(fileName);
|
||||
}
|
||||
@TestMetadata("helloWorld_before.gradle.kts")
|
||||
public void testHelloWorld() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gsk/helloWorld_before.gradle.kts");
|
||||
doTestGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("missedLibrary_before.gradle")
|
||||
public void testMissedLibrary() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/missedLibrary_before.gradle");
|
||||
doTestGradle(fileName);
|
||||
}
|
||||
@TestMetadata("missedLibrary_before.gradle.kts")
|
||||
public void testMissedLibrary() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gsk/missedLibrary_before.gradle.kts");
|
||||
doTestGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("plugin_present_before.gradle")
|
||||
public void testPlugin_present() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/plugin_present_before.gradle");
|
||||
doTestGradle(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("rcVersion_before.gradle")
|
||||
public void testRcVersion() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/rcVersion_before.gradle");
|
||||
doTestGradle(fileName);
|
||||
@TestMetadata("pluginPresent_before.gradle.kts")
|
||||
public void testPluginPresent() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gsk/pluginPresent_before.gradle.kts");
|
||||
doTestGradle(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user