Skip to content

Commit 2494c6c

Browse files
committed
Bootstrap the Flutter IJ with integrations tests
The additional STARTER test framework is added, see https://github.com/JetBrains/intellij-ide-starter Thanks to others here who trailblazed, @jonathan1983, JetBrains/intellij-platform-plugin-template#537 and @helinx, flutter#8338 The change does not try to get the new tests working in the presubmit.
1 parent d823dca commit 2494c6c

File tree

6 files changed

+578
-36
lines changed

6 files changed

+578
-36
lines changed

build.gradle.kts

Lines changed: 113 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ allprojects {
2828

2929
repositories {
3030
mavenCentral()
31+
maven("https://cache-redirector.jetbrains.com/packages.jetbrains.team/maven/p/ij/intellij-ide-starter")
32+
maven("https://mvnrepository.com/artifact/com.jetbrains.intellij.tools/ide-starter-driver")
3133
intellijPlatform {
3234
defaultRepositories()
3335
}
@@ -41,6 +43,7 @@ plugins {
4143
id("org.jetbrains.intellij.platform") version "2.7.2" // IntelliJ Platform Gradle Plugin
4244
id("org.jetbrains.kotlin.jvm") version "2.2.0" // Kotlin support
4345
id("org.jetbrains.changelog") version "2.2.0" // Gradle Changelog Plugin
46+
idea // IntelliJ IDEA support
4447
}
4548

4649
// By default (e.g. when we call `runIde` during development), the plugin version is SNAPSHOT
@@ -90,11 +93,18 @@ jvmVersion = when (javaVersion) {
9093
throw IllegalArgumentException("javaVersion must be defined in the product matrix as either \"17\" or \"21\", but is not for $ideaVersion")
9194
}
9295
}
96+
9397
kotlin {
9498
compilerOptions {
9599
apiVersion.set(KotlinVersion.KOTLIN_2_1)
96100
jvmTarget = jvmVersion
97101
}
102+
// This is how you specify the specific JVM requirements, this may be a requirement for the Starter test framework
103+
// jvmToolchain {
104+
// languageVersion = JavaLanguageVersion.of(21)
105+
// @Suppress("UnstableApiUsage")
106+
// vendor = JvmVendorSpec.JETBRAINS
107+
// }
98108
}
99109

100110
var javaCompatibilityVersion: JavaVersion
@@ -111,18 +121,79 @@ javaCompatibilityVersion = when (javaVersion) {
111121
throw IllegalArgumentException("javaVersion must be defined in the product matrix as either \"17\" or \"21\", but is not for $ideaVersion")
112122
}
113123
}
124+
114125
java {
115126
sourceCompatibility = javaCompatibilityVersion
116127
targetCompatibility = javaCompatibilityVersion
117128
}
118129

130+
sourceSets {
131+
main {
132+
java.srcDirs(
133+
listOf(
134+
"src",
135+
"third_party/vmServiceDrivers"
136+
)
137+
)
138+
// Add kotlin.srcDirs if we start using Kotlin in the main plugin.
139+
resources.srcDirs(
140+
listOf(
141+
"src",
142+
"resources"
143+
)
144+
)
145+
}
146+
test {
147+
java.srcDirs(
148+
listOf(
149+
"src",
150+
"testSrc/unit",
151+
"third_party/vmServiceDrivers"
152+
)
153+
)
154+
resources.srcDirs(
155+
listOf(
156+
"resources",
157+
"testData",
158+
"testSrc/unit"
159+
)
160+
)
161+
}
162+
163+
create("integration", Action<SourceSet> {
164+
java.srcDirs("testSrc/integration")
165+
kotlin.srcDirs("testSrc/integration")
166+
resources.srcDirs("testSrc/integration")
167+
compileClasspath += sourceSets["main"].output + sourceSets["test"].output
168+
runtimeClasspath += sourceSets["main"].output + sourceSets["test"].output
169+
})
170+
}
171+
172+
// Configure IntelliJ IDEA to recognize integration as test sources
173+
idea {
174+
module {
175+
testSources.from(sourceSets["integration"].kotlin.srcDirs)
176+
testResources.from(sourceSets["integration"].resources.srcDirs)
177+
}
178+
}
179+
180+
val integrationImplementation: Configuration by configurations.getting {
181+
extendsFrom(configurations.testImplementation.get())
182+
}
183+
184+
val integrationRuntimeOnly: Configuration by configurations.getting {
185+
extendsFrom(configurations.testRuntimeOnly.get())
186+
}
187+
119188
dependencies {
120189
intellijPlatform {
121190
// Documentation on the default target platform methods:
122191
// https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-dependencies-extension.html#default-target-platforms
123192
// Android Studio versions can be found at: https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html
124193
androidStudio(ideaVersion)
125194
testFramework(TestFrameworkType.Platform)
195+
testFramework(TestFrameworkType.Starter, configurationName = "integrationImplementation")
196+
testFramework(TestFrameworkType.JUnit5, configurationName = "integrationImplementation")
126197

127198
// Plugin dependency documentation:
128199
// https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-dependencies-extension.html#plugins
@@ -166,6 +237,14 @@ dependencies {
166237
)
167238
)
168239
)
240+
241+
// UI Test dependencies
242+
integrationImplementation("org.kodein.di:kodein-di-jvm:7.26.1")
243+
integrationImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
244+
245+
// JUnit 5 is required for UI tests
246+
integrationImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
247+
integrationRuntimeOnly("org.junit.platform:junit-platform-launcher")
169248
}
170249

171250
intellijPlatform {
@@ -213,37 +292,42 @@ intellijPlatform {
213292
}
214293
}
215294

216-
sourceSets {
217-
main {
218-
java.srcDirs(
219-
listOf(
220-
"src",
221-
"third_party/vmServiceDrivers"
222-
)
223-
)
224-
// Add kotlin.srcDirs if we start using Kotlin in the main plugin.
225-
resources.srcDirs(
226-
listOf(
227-
"src",
228-
"resources"
229-
)
230-
)
231-
}
232-
test {
233-
java.srcDirs(
234-
listOf(
235-
"src",
236-
"testSrc/unit",
237-
"third_party/vmServiceDrivers"
238-
)
295+
tasks {
296+
register<Test>("integration") {
297+
description = "Runs only the UI integration tests that start the IDE"
298+
group = "verification"
299+
testClassesDirs = sourceSets["integration"].output.classesDirs
300+
classpath = sourceSets["integration"].runtimeClasspath
301+
useJUnitPlatform {
302+
includeTags("ui")
303+
}
304+
305+
// UI tests should run sequentially (not in parallel) to avoid conflicts
306+
maxParallelForks = 1
307+
308+
// Increase memory for UI tests
309+
minHeapSize = "1g"
310+
maxHeapSize = "4g"
311+
312+
systemProperty("path.to.build.plugin", buildPlugin.get().archiveFile.get().asFile.absolutePath)
313+
systemProperty("idea.home.path", prepareTestSandbox.get().getDestinationDir().parentFile.absolutePath)
314+
systemProperty(
315+
"allure.results.directory", project.layout.buildDirectory.get().asFile.absolutePath + "/allure-results"
239316
)
240-
resources.srcDirs(
241-
listOf(
242-
"resources",
243-
"testData",
244-
"testSrc/unit"
317+
// systemProperty("uiPlatformBuildVersion", providers.gradleProperty("uiPlatformBuildVersion").get())
318+
319+
// Disable IntelliJ test listener that conflicts with standard JUnit
320+
systemProperty("idea.test.cyclic.buffer.size", "0")
321+
322+
// Add required JVM arguments
323+
jvmArgumentProviders += CommandLineArgumentProvider {
324+
mutableListOf(
325+
"--add-opens=java.base/java.lang=ALL-UNNAMED",
326+
"--add-opens=java.desktop/javax.swing=ALL-UNNAMED"
245327
)
246-
)
328+
}
329+
330+
dependsOn(buildPlugin)
247331
}
248332
}
249333

src/io/flutter/module/FlutterGeneratorPeer.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@
2424
import io.flutter.sdk.FlutterSdk;
2525
import io.flutter.sdk.FlutterSdkUtil;
2626

27-
import javax.swing.ComboBoxEditor;
28-
import javax.swing.JComponent;
29-
import javax.swing.JLabel;
30-
import javax.swing.JPanel;
31-
import javax.swing.JScrollPane;
32-
import javax.swing.JTextPane;
27+
import javax.swing.*;
3328
import javax.swing.event.DocumentEvent;
3429
import javax.swing.text.JTextComponent;
3530

@@ -65,6 +60,16 @@ public FlutterGeneratorPeer(WizardContext context) {
6560
private void init() {
6661
mySdkPathComboWithBrowse.getComboBox().setEditable(true);
6762
FlutterSdkUtil.addKnownSDKPathsToCombo(mySdkPathComboWithBrowse.getComboBox());
63+
if (mySdkPathComboWithBrowse.getComboBox().getModel().getSize() == 0) {
64+
// If no SDKs are found, try to use the one from the FLUTTER_SDK environment variable.
65+
// This ensures the SDK path is pre-filled when the combo box is empty, not requiring
66+
// a running Application which is the case for users and bots on the initial startup
67+
// experience.
68+
final String flutterSDKPath = System.getenv("FLUTTER_SDK");
69+
if (flutterSDKPath != null && !flutterSDKPath.isEmpty()) {
70+
mySdkPathComboWithBrowse.getComboBox().setSelectedItem(flutterSDKPath);
71+
}
72+
}
6873

6974
mySdkPathComboWithBrowse.addBrowseFolderListener(null, FileChooserDescriptorFactory.createSingleFolderDescriptor()
7075
.withTitle(FlutterBundle.message("flutter.sdk.browse.path.label")), TextComponentAccessor.STRING_COMBOBOX_WHOLE_TEXT);

0 commit comments

Comments
 (0)