From 90321a2cbec81999efd02acab5a0db8a124203e2 Mon Sep 17 00:00:00 2001 From: George Herbert Date: Sun, 5 Jun 2022 21:55:08 +0100 Subject: [PATCH] 2.1.1 - Migrate to Kotlin and upgrade dependencies (#16) --- build.gradle | 56 -------- build.gradle.kts | 69 +++++++++ settings.gradle | 2 - settings.gradle.kts | 2 + src/main/java/FlutterContext.java | 14 -- src/main/kotlin/FlutterContext.kt | 8 ++ src/main/resources/META-INF/plugin.xml | 4 +- verifier.gradle | 188 ------------------------- 8 files changed, 81 insertions(+), 262 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts delete mode 100644 settings.gradle create mode 100644 settings.gradle.kts delete mode 100644 src/main/java/FlutterContext.java create mode 100644 src/main/kotlin/FlutterContext.kt delete mode 100644 verifier.gradle diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 3b994e9..0000000 --- a/build.gradle +++ /dev/null @@ -1,56 +0,0 @@ -plugins { - id 'java' - id 'org.jetbrains.intellij' version '0.6.5' -} -apply plugin: 'org.jetbrains.intellij' -apply plugin: 'java' -apply plugin: 'idea' -apply from: "$rootDir/verifier.gradle" - -group 'com.herbert.george.flutter-snippets' -version "$version-$releaseChannel-$iteration" -sourceCompatibility = javaVersion -repositories { - mavenCentral() -} - -dependencies { - testCompile group: 'junit', name: 'junit', version: '4.12' -} - -sourceSets { - main { - java.srcDirs 'src', 'gen' - resources.srcDir 'resources' - } -} - -intellij { - plugins 'java', "Dart:$dartVersion", "io.flutter:$flutterVersion" - version ideaVersion - type ideaType - pluginName pluginName - downloadSources Boolean.valueOf(sources) - updateSinceUntilBuild false - sameSinceUntilBuild true - patchPluginXml { - version project.version - changeNotes "Update to showDialg to support for Flutter 2.0 Thanks ming-chu" - sinceBuild pluginSinceBuild - } -} - -publishPlugin { - channels releaseChannel - token intellijToken -} - -pluginVerifier { - pluginFileName = "$rootProject.name-$version" - ides = [ - "IC-202.6397.94", - "IC-203.5981.155"] - verifierVersion = "1.253" -} - -check.dependsOn pluginVerifier \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..d945bc0 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,69 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +fun properties(key: String) = project.findProperty(key).toString() + +plugins { + id("java") + id("org.jetbrains.kotlin.jvm") version "1.6.21" + id("org.jetbrains.intellij") version "1.5.3" +} +apply(plugin = "org.jetbrains.intellij") +apply(plugin = "java") +apply(plugin = "idea") + +group = "com.herbert.george.flutter-snippets" + +var versionString: String = "${properties("version")}-${properties("releaseChannel")}-${properties("iteration")}" + +version = versionString + +repositories { + mavenCentral() +} + +dependencies { + testImplementation("junit:junit:4.12") +} + +tasks { + // Set the JVM compatibility versions + properties("javaVersion").let { + withType { + sourceCompatibility = it + targetCompatibility = it + } + withType { + kotlinOptions.jvmTarget = it + } + } + patchPluginXml { + version.set(versionString) + changeNotes.set("Upgrade project to run use Kotlin and the latest IntelliJ plugins and IDEs") + sinceBuild.set(properties("pluginSinceBuild")) + } + publishPlugin { + channels.set(listOf(properties("releaseChannel"))) + token.set(properties("intellijToken")) + } + runPluginVerifier { + ideVersions.set( + listOf( + "IC-221.5591.52", + "IC-222.2270.31" + ) + ) + verifierVersion.set("latest") + } +} + +intellij { + plugins.set( + listOf("java", "Dart:${properties("dartVersion")}", "io.flutter:${properties("flutterVersion")}") + ) + version.set(properties("ideaVersion")) + type.set(properties("ideaType")) + pluginName.set(properties("pluginName")) +} + + + diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 53b5375..0000000 --- a/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = 'flutter-snippets' - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..89bbfc8 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,2 @@ +rootProject.name = "flutter-snippets" + diff --git a/src/main/java/FlutterContext.java b/src/main/java/FlutterContext.java deleted file mode 100644 index a8e0252..0000000 --- a/src/main/java/FlutterContext.java +++ /dev/null @@ -1,14 +0,0 @@ -import com.intellij.codeInsight.template.TemplateActionContext; -import com.intellij.codeInsight.template.TemplateContextType; -import org.jetbrains.annotations.NotNull; - -public class FlutterContext extends TemplateContextType { - protected FlutterContext() { - super("FLUTTER", "Flutter"); - } - - @Override - public boolean isInContext(@NotNull TemplateActionContext templateActionContext) { - return templateActionContext.getFile().getName().endsWith(".dart"); - } -} diff --git a/src/main/kotlin/FlutterContext.kt b/src/main/kotlin/FlutterContext.kt new file mode 100644 index 0000000..fb9e1a4 --- /dev/null +++ b/src/main/kotlin/FlutterContext.kt @@ -0,0 +1,8 @@ +import com.intellij.codeInsight.template.TemplateActionContext +import com.intellij.codeInsight.template.TemplateContextType + +class FlutterContext protected constructor() : TemplateContextType("FLUTTER", "Flutter") { + override fun isInContext(templateActionContext: TemplateActionContext): Boolean { + return templateActionContext.file.name.endsWith(".dart") + } +} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 1d0cec8..c051319 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -1,10 +1,10 @@ - + com.herbert.george.flutter-snippets Flutter Snippets George Herbert visit here +For full details of the available snippets, please visit here ]]> com.intellij.modules.java diff --git a/verifier.gradle b/verifier.gradle deleted file mode 100644 index 01037b0..0000000 --- a/verifier.gradle +++ /dev/null @@ -1,188 +0,0 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath "de.undercouch:gradle-download-task:4.0.2" - } -} - -import de.undercouch.gradle.tasks.download.DownloadAction -import org.gradle.api.internal.ConventionTask - - -/** - * Runs the IntelliJ plugin verifier. - */ -class PluginVerifierRunner extends ConventionTask { - /** - * The directory name to be used by the plugin verifier. - */ - private static final PLUGIN_VERIFIER_DIR = "pluginVerifier" - /** - * The file name to store the verifier JAR as. - */ - private static final PLUGIN_VERIFIER_NAME = "verifier-all.jar" - - /** - * The logger to use for logging. - */ - private final logger = Logging.getLogger(PluginVerifierRunner) - - /** - * The name of the plugin's distribution file, excluding the extension. - */ - private String pluginFileName - /** - * The identifiers of the IDEs to verify against. - */ - private List ides = new ArrayList() - /** - * The version of the plugin verifier to use. - */ - private String verifierVersion = "1.232" - - - @Input - String getPluginFileName() { - return pluginFileName - } - - void setPluginFileName(String pluginFileName) { - this.pluginFileName = pluginFileName - } - - @Input - List getIdes() { - return ides - } - - void setIdes(List ides) { - this.ides = ides - } - - @Input - String getVerifierVersion() { - return verifierVersion - } - - void setVerifierVersion(String verifierVersion) { - this.verifierVersion = verifierVersion - } - - - /** - * Runs the plugin verifier. - */ - @TaskAction - void runTaskAction() { - if (!project.file("${project.buildDir}/distributions/${pluginFileName}.zip").exists()) - throw new IllegalStateException("Plugin file $pluginFileName does not exist.") - - downloadVerifier() - runVerifier(ides.collect { ide -> resolveIde(ide) }) - } - - - /** - * Downloads the verifier JAR. - */ - void downloadVerifier() { - def url = "" + - "https://dl.bintray.com/jetbrains/intellij-plugin-service/org/jetbrains/intellij/" + - "plugins/verifier-cli/$verifierVersion/verifier-cli-$verifierVersion-all.jar" - - new DownloadAction(project) - .with { - src(url) - dest("$project.buildDir/$PLUGIN_VERIFIER_DIR/$PLUGIN_VERIFIER_NAME") - overwrite(false) - execute() - } - } - - /** - * Resolves the IDE with the given identifier, ensuring that it is present in the Gradle cache, and extracts the - * archive in the same directory if it does not already exist. - * - * @param identifier the IDE to download, described by its identifier and version, separated by a dash - * @return the link to the resolved archive - */ - File resolveIde(String identifier) { - logger.lifecycle("Resolving $identifier") - def dependency = project.dependencies.create(identifierToDependency(identifier)) - def configuration = project.configurations.detachedConfiguration(dependency) - def archive = configuration.singleFile.absolutePath - - def extractionTarget = new File(archive.substring(0, archive.length() - ".zip".length())) - if (!extractionTarget.exists()) { - logger.lifecycle("Extracting $identifier") - project.copy { - from project.zipTree(archive) - into extractionTarget - } - } - return extractionTarget - } - - /** - * Runs the verifier JAR against the configured IDEs and plugin. - * - * @param ides the locations of the IDEs to give to the verifier - */ - void runVerifier(List ides) { - project.javaexec { - classpath = project.files("$project.buildDir/$PLUGIN_VERIFIER_DIR/$PLUGIN_VERIFIER_NAME") - main = "com.jetbrains.pluginverifier.PluginVerifierMain" - args = [ - "-verification-reports-dir", "build/$PLUGIN_VERIFIER_DIR/reports", - "check-plugin", - "${project.buildDir}/distributions/${pluginFileName}.zip", - *(ides*.absolutePath) - ] - } - } - - - /** - * Translates a user-friendly identifier to a Maven-style dependency. - * - * @param identifier the user-friendly identifier - * @return a Maven-style dependency - * @throws IllegalArgumentException if the identifier was not recognized - */ - static String identifierToDependency(String identifier) { - def (type, version) = identifier.split("-") - - def dependencyGroup - def dependencyName - switch (type) { - case "IC": - case "IU": - dependencyGroup = "com.jetbrains.intellij.idea" - dependencyName = "idea$type" - break - case "CL": - dependencyGroup = "com.jetbrains.intellij.clion" - dependencyName = "clion" - break - case "PC": - case "PY": - dependencyGroup = "com.jetbrains.intellij.pycharm" - dependencyName = "pycharm$type" - break - case "RD": - dependencyGroup = "com.jetbrains.intellij.rider" - dependencyName = "riderRD" - break - default: - throw new IllegalArgumentException("Unknown IDE type `$type`.") - } - - return "$dependencyGroup:$dependencyName:$version" - } -} - - -project.tasks.create("pluginVerifier", PluginVerifierRunner) - .with { it.dependsOn(project.tasks.findByName("buildPlugin")) } \ No newline at end of file