Allow creating IntelliJ plugins with Gradle Kotlin DSL build scripts

This commit is contained in:
Dmitry Jemerov
2018-10-23 12:31:15 +02:00
parent c94749cd91
commit c491e795e0
3 changed files with 35 additions and 9 deletions
@@ -1,5 +1,6 @@
<idea-plugin>
<extensions defaultExtensionNs="org.jetbrains.plugins.gradle">
<frameworkSupport implementation="org.jetbrains.idea.devkit.gradle.GradleIntellijPluginFrameworkSupportProvider"/>
<kotlinDslFrameworkSupport implementation="org.jetbrains.idea.devkit.gradle.KdslGradleIntellijPluginFrameworkSupportProvider"/>
</extensions>
</idea-plugin>
@@ -34,7 +34,7 @@ import com.intellij.util.io.HttpRequests;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.devkit.DevKitBundle;
import org.jetbrains.plugins.gradle.frameworkSupport.BuildScriptDataBuilder;
import org.jetbrains.plugins.gradle.frameworkSupport.GradleFrameworkSupportProvider;
import org.jetbrains.plugins.gradle.frameworkSupport.KotlinDslGradleFrameworkSupportProvider;
import org.jetbrains.plugins.gradle.service.execution.GradleExternalTaskConfigurationType;
import javax.swing.*;
@@ -47,7 +47,7 @@ import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class GradleIntellijPluginFrameworkSupportProvider extends GradleFrameworkSupportProvider {
public class GradleIntellijPluginFrameworkSupportProvider extends KotlinDslGradleFrameworkSupportProvider {
private static final String ID = "gradle-intellij-plugin";
private static final Logger LOG = Logger.getInstance(GradleIntellijPluginFrameworkSupportProvider.class);
@@ -98,6 +98,19 @@ public class GradleIntellijPluginFrameworkSupportProvider extends GradleFramewor
else {
ideVersion = applicationInfo.getFullVersion();
}
configureBuildScript(buildScriptData, pluginVersion, ideVersion);
VirtualFile contentRoot = ArrayUtil.getFirstElement(rootModel.getContentRoots());
if (contentRoot == null) return;
if (!createPluginXml(projectId, module, contentRoot.getPath())) return;
StartupManager.getInstance(module.getProject()).runWhenProjectIsInitialized(() -> {
FileEditorManager.getInstance(module.getProject()).openFile(buildScriptData.getBuildScriptFile(), true);
createRunConfiguration(module, contentRoot.getPath());
});
}
protected void configureBuildScript(@NotNull BuildScriptDataBuilder buildScriptData,
String pluginVersion,
String ideVersion) {
buildScriptData
.addPluginDefinitionInPluginsGroup("id 'org.jetbrains.intellij' version '" + pluginVersion + "'")
.addOther("intellij {\n version '" + ideVersion + "'\n}\n")
@@ -106,13 +119,6 @@ public class GradleIntellijPluginFrameworkSupportProvider extends GradleFramewor
" Add change notes here.<br>\n" +
" <em>most HTML tags may be used</em>\"\"\"\n" +
"}");
VirtualFile contentRoot = ArrayUtil.getFirstElement(rootModel.getContentRoots());
if (contentRoot == null) return;
if (!createPluginXml(projectId, module, contentRoot.getPath())) return;
StartupManager.getInstance(module.getProject()).runWhenProjectIsInitialized(() -> {
FileEditorManager.getInstance(module.getProject()).openFile(buildScriptData.getBuildScriptFile(), true);
createRunConfiguration(module, contentRoot.getPath());
});
}
@Override
@@ -0,0 +1,19 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.idea.devkit.gradle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.gradle.frameworkSupport.BuildScriptDataBuilder;
public class KdslGradleIntellijPluginFrameworkSupportProvider extends GradleIntellijPluginFrameworkSupportProvider {
@Override
protected void configureBuildScript(@NotNull BuildScriptDataBuilder buildScriptData, String pluginVersion, String ideVersion) {
buildScriptData
.addPluginDefinitionInPluginsGroup("id(\"org.jetbrains.intellij\") version \"" + pluginVersion + "\"")
.addOther("intellij {\n version = \"" + ideVersion + "\"\n}\n")
.addOther("tasks.getByName<org.jetbrains.intellij.tasks.PatchPluginXmlTask>(\"patchPluginXml\") {\n" +
" changeNotes(\"\"\"\n" +
" Add change notes here.<br>\n" +
" <em>most HTML tags may be used</em>\"\"\")\n" +
"}");
}
}