diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 85bf280..08264a2 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -17,17 +17,18 @@ jobs: steps: - name: Git checkout - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: JDK setup - uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0 + uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: - distribution: 'zulu' - java-version: 11.0.7 + distribution: zulu + java-version: 21.0.3 - - name: Build and test - uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 # v2.4.2 - with: - arguments: build + - name: Gradle setup + uses: gradle/actions/setup-gradle@dbbdc275be76ac10734476cc723d82dfe7ec6eda # v3.4.2 + + - name: Gradle build + run: ./gradlew build env: CI: true diff --git a/.gitignore b/.gitignore index 34ed9fd..bbeda76 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ build/ /.idea/uiDesigner.xml /.idea/*.iml /.idea/modules.xml +/.intellijPlatform diff --git a/agent/build.gradle.kts b/agent/build.gradle.kts index 3fda0a6..1358c49 100644 --- a/agent/build.gradle.kts +++ b/agent/build.gradle.kts @@ -24,7 +24,7 @@ repositories { mavenCentral() } -java.toolchain.languageVersion.set(JavaLanguageVersion.of(17)) +java.toolchain.languageVersion.set(JavaLanguageVersion.of(21)) tasks.jar { archiveFileName.set("agent.jar") diff --git a/build.gradle.kts b/build.gradle.kts index be70f4c..af396a1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,114 +15,92 @@ */ import org.gradle.api.tasks.testing.logging.TestExceptionFormat -import org.jetbrains.intellij.tasks.PrepareSandboxTask -import org.jetbrains.intellij.tasks.RunPluginVerifierTask +import org.jetbrains.intellij.platform.gradle.TestFrameworkType +import org.jetbrains.intellij.platform.gradle.tasks.PrepareSandboxTask +import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import java.util.* plugins { id("java") - id("org.jetbrains.intellij").version("1.15.0") - id("org.jetbrains.kotlin.jvm").version("1.9.0") + id("org.jetbrains.intellij.platform").version("2.0.0-beta7") + id("org.jetbrains.kotlin.jvm").version("1.9.24") } val isCI = System.getenv("CI") != null val isRelease = project.findProperty("release") != null val versionSuffix = if (isRelease) "" else "-SNAPSHOT" +val tokenProperty = "plugins.repository.token" group = "com.google.idea.perf" version = "1.3.1$versionSuffix" -repositories { - mavenCentral() -} - -java.toolchain.languageVersion.set(JavaLanguageVersion.of(17)) +java.toolchain.languageVersion.set(JavaLanguageVersion.of(21)) tasks.withType { kotlinOptions { - languageVersion = "1.7" - apiVersion = "1.7" // Should match the Kotlin stdlib version in IntelliJ. - jvmTarget = "17" // Should match the JetBrains Runtime. - // allWarningsAsErrors = true + languageVersion = "1.9" + apiVersion = "1.9" // Should match the Kotlin stdlib version in IntelliJ. + jvmTarget = "21" // Should match the JetBrains Runtime. + allWarningsAsErrors = true } } -// See https://github.com/JetBrains/gradle-intellij-plugin/ -intellij { - pluginName.set("ide-perf") - version.set("232.8660.185") - downloadSources.set(!isCI) - updateSinceUntilBuild.set(false) // So that we can leave the until-build blank. -} +// See https://github.com/JetBrains/intellij-platform-gradle-plugin. +intellijPlatform { + buildSearchableOptions = false // This task is too slow. + autoReload = false // Auto-reload does not work well for this plugin currently. + + pluginConfiguration { + version = project.version.toString() + ideaVersion { + sinceBuild = "242" // Should be tested occasionally (see runPluginVerifier). + untilBuild = provider { null } // So that we can leave the until-build blank. + } + changeNotes = """ + + """.trimIndent() + } -tasks.buildSearchableOptions { - // Disable the (slow) 'buildSearchableOptions' task; we don't need it yet anyway. - enabled = false -} + publishing { + token = project.findProperty(tokenProperty) as? String + } -tasks.patchPluginXml { - // Should be tested occasionally (see runPluginVerifier). - sinceBuild.set("223") - // Should describe changes in the latest release only. - changeNotes.set( - """ - - """.trimIndent() - ) -} + // Note: the plugin verifier does not run by default in a normal build. + // Instead, you have to run it explicitly with: ./gradlew verifyPlugin + verifyPlugin { + ides.recommended() + downloadDirectory = layout.buildDirectory.dir("pluginVerifier/ides") -// Note: the plugin verifier does not run by default in a normal build. -// Instead you have to run it explicitly with: ./gradlew runPluginVerifier -tasks.runPluginVerifier { - downloadDir.set("$buildDir/pluginVerifier/ides") - - // See https://www.jetbrains.com/idea/download/other.html or - // https://jb.gg/intellij-platform-builds-list for the list of platform versions. - ideVersions.set( - listOf( - "223.8836.41", // Should match the since-build from plugin.xml. - "231.9392.1", - intellij.version.get(), // We check the current version too for deprecations, etc. + val suppressedFailures = listOf( + VerifyPluginTask.FailureLevel.EXPERIMENTAL_API_USAGES, // TODO: VfsStatTreeTable uses JBTreeTable. + VerifyPluginTask.FailureLevel.INTERNAL_API_USAGES, // See CachedValueEventConsumer. + VerifyPluginTask.FailureLevel.DEPRECATED_API_USAGES, // Using PropertiesComponent.getValues. ) - ) - - val suppressedFailures = listOf( - RunPluginVerifierTask.FailureLevel.EXPERIMENTAL_API_USAGES, // TODO: VfsStatTreeTable uses JBTreeTable. - RunPluginVerifierTask.FailureLevel.INTERNAL_API_USAGES, // See CachedValueEventConsumer. - RunPluginVerifierTask.FailureLevel.DEPRECATED_API_USAGES, // Using PropertiesComponent.getValues. - ) - failureLevel.set(EnumSet.copyOf(RunPluginVerifierTask.FailureLevel.ALL - suppressedFailures)) - - // Suppress false-positive NoSuchClassErrors; they are caused by the agent being - // loaded in the boot classloader rather than the plugin classloader. - externalPrefixes.set(listOf("com.google.idea.perf.agent")) + failureLevel = VerifyPluginTask.FailureLevel.ALL - suppressedFailures + + // Suppress false-positive NoSuchClassErrors; they are caused by the agent being + // loaded in the boot classloader rather than the plugin classloader. + externalPrefixes = listOf("com.google.idea.perf.agent") + } } val javaAgent: Configuration by configurations.creating tasks.withType { // Copy agent artifacts into the plugin home directory. - val agentDir = "${pluginName.get()}/agent" - from(javaAgent) { into(agentDir) } + from(javaAgent) { into("ide-perf/agent") } } tasks.publishPlugin { - val tokenProp = "plugins.repository.token" - val theToken = project.findProperty(tokenProp) as? String - token.set(theToken) doFirst { check(isRelease) { "Must do a release build when publishing the plugin" } - checkNotNull(theToken) { "Must specify an upload token via -P$tokenProp" } + checkNotNull(token.get()) { "Must specify an upload token via -P$tokenProperty" } } } tasks.runIde { - // Disable auto-reload until we make sure it works correctly for this plugin. - autoReloadPlugins.set(false) - // Always enable assertions. jvmArgs("-ea") @@ -142,9 +120,6 @@ tasks.test { testLogging.exceptionFormat = TestExceptionFormat.FULL testLogging.showStandardStreams = isCI enableAgent() - - // Workaround for IDEA-325466 and https://github.com/JetBrains/gradle-intellij-plugin/issues/1433. - jvmArgs("-Djava.awt.headless=true") } fun JavaForkOptions.enableAgent() { @@ -160,19 +135,36 @@ fun JavaForkOptions.enableAgent() { } } +repositories { + mavenCentral() + intellijPlatform { + defaultRepositories() + } +} + dependencies { + intellijPlatform { + // See task 'printProductsReleases' for available IntelliJ versions. + intellijIdeaCommunity("242.18071.24") // IntelliJ 2024.2 EAP 6. + pluginVerifier() + instrumentationTools() + testFramework(TestFrameworkType.Platform) + } + javaAgent(project(":agent", "runtimeElements")) compileOnly(project(":agent")) // 'compileOnly' because it is put on the bootclasspath later. - implementation("org.ow2.asm:asm:9.4") - implementation("org.ow2.asm:asm-util:9.4") - implementation("org.ow2.asm:asm-commons:9.4") + implementation("org.ow2.asm:asm:9.7") + implementation("org.ow2.asm:asm-util:9.7") + implementation("org.ow2.asm:asm-commons:9.7") testImplementation("org.jetbrains.kotlin:kotlin-test:1.7.21") - testImplementation("junit:junit:4.13.2") testImplementation("com.google.truth:truth:1.1.3") testImplementation("com.google.truth.extensions:truth-java8-extension:1.1.3") + // Workaround for https://youtrack.jetbrains.com/issue/IJPL-157292. + testRuntimeOnly("org.opentest4j:opentest4j:1.3.0") + // For simplicity, we assume all 'compileOnly' dependencies should be 'testCompileOnly' as well. configurations.testCompileOnly.get().extendsFrom(configurations.compileOnly.get()) } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 070cb70..0d18421 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/google/idea/perf/AgentLoader.kt b/src/main/java/com/google/idea/perf/AgentLoader.kt index bd9a4b8..c47d060 100644 --- a/src/main/java/com/google/idea/perf/AgentLoader.kt +++ b/src/main/java/com/google/idea/perf/AgentLoader.kt @@ -22,15 +22,14 @@ import com.google.idea.perf.agent.AgentMain import com.google.idea.perf.tracer.TracerClassFileTransformer import com.google.idea.perf.tracer.TracerHookImpl import com.google.idea.perf.agent.TracerTrampoline -import com.intellij.execution.process.OSProcessUtil import com.intellij.ide.plugins.PluginManagerCore import com.intellij.notification.Notification import com.intellij.notification.NotificationType import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.extensions.PluginId -import com.intellij.util.io.isFile import com.sun.tools.attach.VirtualMachine import java.lang.instrument.Instrumentation +import kotlin.io.path.isRegularFile import kotlin.system.measureTimeMillis // Things to improve: @@ -107,9 +106,10 @@ object AgentLoader { val agentDir = plugin.pluginPath.resolve("agent") val javaAgent = agentDir.resolve("agent.jar") - check(javaAgent.isFile()) { "Could not find agent.jar at $javaAgent" } + check(javaAgent.isRegularFile()) { "Could not find agent.jar at $javaAgent" } - val vm = VirtualMachine.attach(OSProcessUtil.getApplicationPid()) + val pid = ProcessHandle.current().pid() + val vm = VirtualMachine.attach(pid.toString()) try { vm.loadAgent(javaAgent.toAbsolutePath().toString()) }