From 0dbef8c17887133e6157f66645611a1c8fdfc196 Mon Sep 17 00:00:00 2001 From: fscarponi Date: Tue, 11 Jun 2024 17:10:58 +0200 Subject: [PATCH 1/2] 242 candidate with ide patch policy The commit updates the version to 242 in `.github/workflows/publish-snapshot.yml.disabled` and `build.gradle.kts` files. Additionally, new IDE patch policy has been implemented in `.github/workflows/test.yml`, allowing continual tests even on failures. For this, multiple environment variables have been defined and an if clause is introduced to check failure conditions before patching and re-running tests. Modifications are also made to `SourceSetModel.kt` to handle dependencies slightly differently. The file `kmp-modifier/src/test/kotlin/com/jetbrains/packageSearch/mppDependencyUpdater/intellijStuff/SdkTestCase.kt` has been largely commented out. --- .../workflows/TrustKotlinGradlePluginPatch.kt | 99 ++++ .../TrustKotlinGradlePluginPatch.main.kts | 85 +++ .../{build.yml.disabled => build.yml} | 15 + ...lease.yml.disabled => publish-release.yml} | 2 +- .../workflows/publish-snapshot.yml.disabled | 2 +- .github/workflows/test.yml | 93 +++- build.gradle.kts | 2 +- .../gradle/ConfigureGradleIntellijPlugin.kt | 2 +- .../gradle/ConfigurePublishPlugin.kt | 2 +- .../dsl/models/SourceSetModel.kt | 11 +- .../intellijStuff/SdkTestCase.kt | 513 +++++++++--------- .../intellijStuff/TestUnknownSdkResolver.kt | 206 +++---- packagesearch.versions.toml | 8 +- .../PackageSearchProjectServiceTest.kt | 6 +- .../projects/gradle/pkgs-test-java.zip | Bin 91014 -> 91068 bytes 15 files changed, 664 insertions(+), 382 deletions(-) create mode 100644 .github/workflows/TrustKotlinGradlePluginPatch.kt create mode 100644 .github/workflows/TrustKotlinGradlePluginPatch.main.kts rename .github/workflows/{build.yml.disabled => build.yml} (51%) rename .github/workflows/{publish-release.yml.disabled => publish-release.yml} (97%) diff --git a/.github/workflows/TrustKotlinGradlePluginPatch.kt b/.github/workflows/TrustKotlinGradlePluginPatch.kt new file mode 100644 index 00000000..f1bc6952 --- /dev/null +++ b/.github/workflows/TrustKotlinGradlePluginPatch.kt @@ -0,0 +1,99 @@ +package com.jetbrains.packagesearch.plugin.tests.scripts + +import java.nio.file.Path +import java.nio.file.Paths +import javax.xml.parsers.DocumentBuilderFactory +import javax.xml.transform.OutputKeys +import javax.xml.transform.TransformerFactory +import javax.xml.transform.dom.DOMSource +import javax.xml.transform.stream.StreamResult +import kotlin.io.path.exists +import kotlin.io.path.listDirectoryEntries +import org.w3c.dom.Document +import org.w3c.dom.Element + +private val domFileName="builtinRegistry" + +fun main(){ + scoutRegistryFiles().forEach { + println("Patching file: $it") + patchKotlinGradlePlugin(it) + } +} + +// WARNING: USE THIS FUNCTION WITH CAUTION AND ONLY FOR TESTS PURPOSES +internal fun scoutRegistryFiles(): List { + println("Scouting registry files") + val userDir = Path.of(System.getProperty("user.home")) + println("current directory: $userDir") + println("contains: ${userDir.listDirectoryEntries()}") + println ("Scouting for gradle ide caches") + val gradleDir= Path.of(userDir.toString(), ".gradle") + println("gradle directory exists: ${gradleDir.exists()}") + val cacheDir= Paths.get(gradleDir.toString(), "caches", "modules-2", "files-2.1", "com.jetbrains.intellij.idea", "ideaIC") + println("idea cache directory exists: ${cacheDir.exists()}") + + //scout for the registry file + val configsFiles= buildList { + cacheDir.toFile().walk().forEach { + if (it.name.contains(domFileName) && it.extension.lowercase().endsWith("xml")) { + add(it.toPath()) + } + } + } + + println("Found ${configsFiles.size} registry files") + configsFiles.forEach { println(it) } + + return configsFiles +} + +internal fun patchKotlinGradlePlugin(xmlPath: Path) { + if (!xmlPath.exists()) { + error("can not find XML file to patch: $xmlPath") + } + + val xmlFile = xmlPath.toFile() + val documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder() + val document: Document = documentBuilder.parse(xmlFile) + + // Create the new plugin element with its attributes + val pluginElement: Element = document.createElement("plugin") + pluginElement.setAttribute("directoryName", "Kotlin") + pluginElement.setAttribute("id", "org.jetbrains.kotlin") + + // Create the dependencies element + val dependenciesElement: Element = document.createElement("dependencies") + + // List of dependency values + val dependencyValues = listOf( + "com.intellij.modules.platform", + "com.intellij.modules.java", + "com.intellij.modules.java-capable", + "com.intellij.java" + ) + + // Add each dependency to the dependencies element + for (dependencyValue in dependencyValues) { + val dependencyElement: Element = document.createElement("dependency") + dependencyElement.appendChild(document.createTextNode(dependencyValue)) + dependenciesElement.appendChild(dependencyElement) + } + + // Append the dependencies element to the plugin element + pluginElement.appendChild(dependenciesElement) + + // Append the plugin element to the root element + document.documentElement.appendChild(pluginElement) + + // Save the updated document back to the file + val transformerFactory = TransformerFactory.newInstance() + val transformer = transformerFactory.newTransformer() + transformer.setOutputProperty(OutputKeys.INDENT, "yes") + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2") + val source = DOMSource(document) + val result = StreamResult(xmlFile) + transformer.transform(source, result) + + println("XML file updated successfully.") +} \ No newline at end of file diff --git a/.github/workflows/TrustKotlinGradlePluginPatch.main.kts b/.github/workflows/TrustKotlinGradlePluginPatch.main.kts new file mode 100644 index 00000000..9c703fec --- /dev/null +++ b/.github/workflows/TrustKotlinGradlePluginPatch.main.kts @@ -0,0 +1,85 @@ +import java.nio.file.Path +import java.nio.file.Paths +import javax.xml.parsers.DocumentBuilderFactory +import javax.xml.transform.OutputKeys +import javax.xml.transform.TransformerFactory +import javax.xml.transform.dom.DOMSource +import javax.xml.transform.stream.StreamResult +import kotlin.io.path.exists +import kotlin.io.path.listDirectoryEntries +import org.w3c.dom.Document +import org.w3c.dom.Element + +val domFileName = "builtinRegistry" + +println("Scouting registry files") +val userDir = Path.of(System.getProperty("user.home")) +println("current directory: $userDir") +println("contains: ${userDir.listDirectoryEntries()}") +println ("Scouting for gradle ide caches") +val gradleDir = Path.of(userDir.toString(), ".gradle") +println("gradle directory exists: ${gradleDir.exists()}") +val cacheDir = + Paths.get(gradleDir.toString(), "caches", "modules-2", "files-2.1", "com.jetbrains.intellij.idea", "ideaIC") +println("idea cache directory exists: ${cacheDir.exists()}") + +//scout for the registry file +val configsFiles = buildList { + cacheDir.toFile().walk().forEach { + if (it.name.contains(domFileName) && it.extension.lowercase().endsWith("xml")) { + add(it.toPath()) + } + } +} + +println("Found ${configsFiles.size} registry files") +configsFiles.forEach { + xmlPath -> + if (!xmlPath.exists()) { + error("can not find XML file to patch: $xmlPath") + } + + val xmlFile = xmlPath.toFile() + val documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder() + val document: Document = documentBuilder.parse(xmlFile) + + // Create the new plugin element with its attributes + val pluginElement: Element = document.createElement("plugin") + pluginElement.setAttribute("directoryName", "Kotlin") + pluginElement.setAttribute("id", "org.jetbrains.kotlin") + + // Create the dependencies element + val dependenciesElement: Element = document.createElement("dependencies") + + // List of dependency values + val dependencyValues = listOf( + "com.intellij.modules.platform", + "com.intellij.modules.java", + "com.intellij.modules.java-capable", + "com.intellij.java" + ) + + // Add each dependency to the dependencies element + for (dependencyValue in dependencyValues) { + val dependencyElement: Element = document.createElement("dependency") + dependencyElement.appendChild(document.createTextNode(dependencyValue)) + dependenciesElement.appendChild(dependencyElement) + } + + // Append the dependencies element to the plugin element + pluginElement.appendChild(dependenciesElement) + + // Append the plugin element to the root element + document.documentElement.appendChild(pluginElement) + + // Save the updated document back to the file + val transformerFactory = TransformerFactory.newInstance() + val transformer = transformerFactory.newTransformer() + transformer.setOutputProperty(OutputKeys.INDENT, "yes") + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2") + val source = DOMSource(document) + val result = StreamResult(xmlFile) + transformer.transform(source, result) + + println("XML file updated successfully.") +} diff --git a/.github/workflows/build.yml.disabled b/.github/workflows/build.yml similarity index 51% rename from .github/workflows/build.yml.disabled rename to .github/workflows/build.yml index 63371d35..c79eff3c 100644 --- a/.github/workflows/build.yml.disabled +++ b/.github/workflows/build.yml @@ -17,6 +17,21 @@ jobs: cache: gradle - uses: gradle/gradle-build-action@v3 - name: Run :buildShadowPlugin task + id: simple-build + continue-on-error: true + run: ./gradlew :plugin:buildShadowPlugin + env: + GRADLE_ENTERPRISE_KEY: ${{ secrets.GRADLE_ENTERPRISE_KEY }} + SPACE_INTELLIJ_NIGHTLIES_TOKEN: ${{ secrets.SPACE_INTELLIJ_NIGHTLIES_TOKEN }} + SPACE_INTELLIJ_NIGHTLIES_USERNAME: ${{ secrets.SPACE_INTELLIJ_NIGHTLIES_USERNAME }} + SPACE_PACKAGE_SEARCH_TOKEN: ${{ secrets.SPACE_PACKAGE_SEARCH_TOKEN }} + SPACE_PACKAGE_SEARCH_USERNAME: ${{ secrets.SPACE_PACKAGE_SEARCH_USERNAME }} + - name: Patch IDE config files + if: steps.simple-build.outcome == 'failure' + run: kotlinc -script ./.github/workflows/TrustKotlinGradlePluginPatch.main.kts + - name: Run :buildShadowPlugin task AFTER PATCH + id: patched-build + if: steps.simple-build.outcome == 'failure' run: ./gradlew :plugin:buildShadowPlugin env: GRADLE_ENTERPRISE_KEY: ${{ secrets.GRADLE_ENTERPRISE_KEY }} diff --git a/.github/workflows/publish-release.yml.disabled b/.github/workflows/publish-release.yml similarity index 97% rename from .github/workflows/publish-release.yml.disabled rename to .github/workflows/publish-release.yml index 651d9df9..cb893aaa 100644 --- a/.github/workflows/publish-release.yml.disabled +++ b/.github/workflows/publish-release.yml @@ -3,7 +3,7 @@ name: Publish to Marketplace on: release: types: [ published ] - branches: [ master ] + branches: [ release/242 ] jobs: publish: diff --git a/.github/workflows/publish-snapshot.yml.disabled b/.github/workflows/publish-snapshot.yml.disabled index 79d2394e..b89d9e5b 100644 --- a/.github/workflows/publish-snapshot.yml.disabled +++ b/.github/workflows/publish-snapshot.yml.disabled @@ -2,7 +2,7 @@ name: Publish snapshot to TBE on: push: - branches: [ master ] + branches: [ releases/242 ] jobs: publish: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5e3eccb3..61eef016 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,7 +2,7 @@ name: Run tests on: pull_request: - branches: [ master ] + branches: [ master, releases/242 , fabrizio.scarponi/242 ] jobs: gradle: @@ -25,7 +25,24 @@ jobs: with: java-version: 11 distribution: 'temurin' - - name: Run tests + - name: Run GRADLE tests + continue-on-error: true + id: simple-build + env: + KMP: true + GRADLE_VERSION: ${{ matrix.gradle-version }} + GRADLE_ENTERPRISE_KEY: ${{ secrets.GRADLE_ENTERPRISE_KEY }} + JAVA_VERSION: ${{matrix.jdk-version}} + SPACE_INTELLIJ_NIGHTLIES_TOKEN: ${{ secrets.SPACE_INTELLIJ_NIGHTLIES_TOKEN }} + SPACE_INTELLIJ_NIGHTLIES_USERNAME: ${{ secrets.SPACE_INTELLIJ_NIGHTLIES_USERNAME }} + SPACE_PACKAGE_SEARCH_TOKEN: ${{ secrets.SPACE_PACKAGE_SEARCH_TOKEN }} + SPACE_PACKAGE_SEARCH_USERNAME: ${{ secrets.SPACE_PACKAGE_SEARCH_USERNAME }} + run: ./gradlew :plugin:test --continue --tests "com.jetbrains.packagesearch.plugin.tests.end2end.projectservice.GradleProjectTest" + - name: Patch IDE config files + if: steps.simple-build.outcome == 'failure' + run: kotlinc -script ./.github/workflows/TrustKotlinGradlePluginPatch.main.kts + - name: Run GRADLE tests PATCHED + if: steps.simple-build.outcome == 'failure' env: KMP: true GRADLE_VERSION: ${{ matrix.gradle-version }} @@ -59,7 +76,23 @@ jobs: with: java-version: 11 distribution: 'temurin' - - name: Run Gradle tests + - name: Run MAVEN tests + id: simple-build + continue-on-error: true + env: + KMP: true + GRADLE_ENTERPRISE_KEY: ${{ secrets.GRADLE_ENTERPRISE_KEY }} + JAVA_VERSION: ${{matrix.jdk-version}} + SPACE_INTELLIJ_NIGHTLIES_TOKEN: ${{ secrets.SPACE_INTELLIJ_NIGHTLIES_TOKEN }} + SPACE_INTELLIJ_NIGHTLIES_USERNAME: ${{ secrets.SPACE_INTELLIJ_NIGHTLIES_USERNAME }} + SPACE_PACKAGE_SEARCH_TOKEN: ${{ secrets.SPACE_PACKAGE_SEARCH_TOKEN }} + SPACE_PACKAGE_SEARCH_USERNAME: ${{ secrets.SPACE_PACKAGE_SEARCH_USERNAME }} + run: ./gradlew :plugin:test --continue --tests "com.jetbrains.packagesearch.plugin.tests.end2end.projectservice.MavenProjectTest" + - name: Patch IDE config files + if: steps.simple-build.outcome == 'failure' + run: kotlinc -script ./.github/workflows/TrustKotlinGradlePluginPatch.main.kts + - name: Run MAVEN tests Patched + if: steps.simple-build.outcome == 'failure' env: KMP: true GRADLE_ENTERPRISE_KEY: ${{ secrets.GRADLE_ENTERPRISE_KEY }} @@ -95,7 +128,24 @@ jobs: with: java-version: 11 distribution: 'temurin' - - name: Run tests + - name: Run KMP tests + id: simple-build + continue-on-error: true + env: + KMP: true + GRADLE_VERSION: ${{ matrix.gradle-version }} + GRADLE_ENTERPRISE_KEY: ${{ secrets.GRADLE_ENTERPRISE_KEY }} + JAVA_VERSION: ${{matrix.jdk-version}} + SPACE_INTELLIJ_NIGHTLIES_TOKEN: ${{ secrets.SPACE_INTELLIJ_NIGHTLIES_TOKEN }} + SPACE_INTELLIJ_NIGHTLIES_USERNAME: ${{ secrets.SPACE_INTELLIJ_NIGHTLIES_USERNAME }} + SPACE_PACKAGE_SEARCH_TOKEN: ${{ secrets.SPACE_PACKAGE_SEARCH_TOKEN }} + SPACE_PACKAGE_SEARCH_USERNAME: ${{ secrets.SPACE_PACKAGE_SEARCH_USERNAME }} + run: ./gradlew :plugin:test --continue --tests "com.jetbrains.packagesearch.plugin.tests.end2end.projectservice.KMPGradleProjectTest" + - name: Patch IDE config files + if: steps.simple-build.outcome == 'failure' + run: kotlinc -script ./.github/workflows/TrustKotlinGradlePluginPatch.main.kts + - name: Run KMP tests + if: steps.simple-build.outcome == 'failure' env: KMP: true GRADLE_VERSION: ${{ matrix.gradle-version }} @@ -134,7 +184,24 @@ jobs: with: java-version: 11 distribution: 'temurin' - - name: Run tests + - name: Run VERSION CATALOG tests + continue-on-error: true + id: simple-build + env: + KMP: true + GRADLE_VERSION: ${{ matrix.gradle-version }} + GRADLE_ENTERPRISE_KEY: ${{ secrets.GRADLE_ENTERPRISE_KEY }} + JAVA_VERSION: ${{matrix.jdk-version}} + SPACE_INTELLIJ_NIGHTLIES_TOKEN: ${{ secrets.SPACE_INTELLIJ_NIGHTLIES_TOKEN }} + SPACE_INTELLIJ_NIGHTLIES_USERNAME: ${{ secrets.SPACE_INTELLIJ_NIGHTLIES_USERNAME }} + SPACE_PACKAGE_SEARCH_TOKEN: ${{ secrets.SPACE_PACKAGE_SEARCH_TOKEN }} + SPACE_PACKAGE_SEARCH_USERNAME: ${{ secrets.SPACE_PACKAGE_SEARCH_USERNAME }} + run: ./gradlew :plugin:test --continue --tests "com.jetbrains.packagesearch.plugin.tests.end2end.projectservice.CatalogProjectTest" + - name: Patch IDE config files + if: steps.simple-build.outcome == 'failure' + run: kotlinc -script ./.github/workflows/TrustKotlinGradlePluginPatch.main.kts + - name: Run VERSION CATALOG tests PATCHED + if: steps.simple-build.outcome == 'failure' env: KMP: true GRADLE_VERSION: ${{ matrix.gradle-version }} @@ -164,7 +231,21 @@ jobs: with: java-version: 11 distribution: 'temurin' - - name: Run tests + - name: Run UNIT tests + id: simple-build + continue-on-error: true + env: + GRADLE_ENTERPRISE_KEY: ${{ secrets.GRADLE_ENTERPRISE_KEY }} + SPACE_INTELLIJ_NIGHTLIES_TOKEN: ${{ secrets.SPACE_INTELLIJ_NIGHTLIES_TOKEN }} + SPACE_INTELLIJ_NIGHTLIES_USERNAME: ${{ secrets.SPACE_INTELLIJ_NIGHTLIES_USERNAME }} + SPACE_PACKAGE_SEARCH_TOKEN: ${{ secrets.SPACE_PACKAGE_SEARCH_TOKEN }} + SPACE_PACKAGE_SEARCH_USERNAME: ${{ secrets.SPACE_PACKAGE_SEARCH_USERNAME }} + run: ./gradlew :plugin:utils:test + - name: Patch IDE config files + if: steps.simple-build.outcome == 'failure' + run: kotlinc -script ./.github/workflows/TrustKotlinGradlePluginPatch.main.kts + - name: Run UNIT tests + if: steps.simple-build.outcome == 'failure' env: GRADLE_ENTERPRISE_KEY: ${{ secrets.GRADLE_ENTERPRISE_KEY }} SPACE_INTELLIJ_NIGHTLIES_TOKEN: ${{ secrets.SPACE_INTELLIJ_NIGHTLIES_TOKEN }} diff --git a/build.gradle.kts b/build.gradle.kts index 3d6ff596..f47cff79 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,7 @@ plugins { allprojects { group = "org.jetbrains.packagesearch" - val baseVersion = "241.99999-SNAPSHOT" + val baseVersion = "242.99999-SNAPSHOT" version = when (val ref = getenv("GITHUB_REF")) { null -> baseVersion else -> when { diff --git a/buildSrc/src/main/kotlin/org/jetbrains/packagesearch/gradle/ConfigureGradleIntellijPlugin.kt b/buildSrc/src/main/kotlin/org/jetbrains/packagesearch/gradle/ConfigureGradleIntellijPlugin.kt index 748264e7..8cd2a37e 100644 --- a/buildSrc/src/main/kotlin/org/jetbrains/packagesearch/gradle/ConfigureGradleIntellijPlugin.kt +++ b/buildSrc/src/main/kotlin/org/jetbrains/packagesearch/gradle/ConfigureGradleIntellijPlugin.kt @@ -15,7 +15,7 @@ fun Project.configureGradleIntellijPlugin(packageSearchExtension: PackageSearchE plugins.withId("org.jetbrains.intellij") { extensions.withType { - version = "LATEST-EAP-SNAPSHOT" + version = "242.16677-EAP-CANDIDATE-SNAPSHOT" instrumentCode = false downloadSources = !isCI } diff --git a/buildSrc/src/main/kotlin/org/jetbrains/packagesearch/gradle/ConfigurePublishPlugin.kt b/buildSrc/src/main/kotlin/org/jetbrains/packagesearch/gradle/ConfigurePublishPlugin.kt index f839cda5..68b28692 100644 --- a/buildSrc/src/main/kotlin/org/jetbrains/packagesearch/gradle/ConfigurePublishPlugin.kt +++ b/buildSrc/src/main/kotlin/org/jetbrains/packagesearch/gradle/ConfigurePublishPlugin.kt @@ -15,7 +15,7 @@ import org.gradle.api.component.SoftwareComponentFactory import org.gradle.api.file.DuplicatesStrategy import org.gradle.api.internal.component.SoftwareComponentInternal import org.gradle.api.plugins.ExtraPropertiesExtension -import org.gradle.api.plugins.internal.DefaultAdhocSoftwareComponent +import org.gradle.api.plugins.internal. DefaultAdhocSoftwareComponent import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.publish.maven.tasks.PublishToMavenRepository diff --git a/kmp-modifier/src/main/kotlin/com/intellij/packageSearch/mppDependencyUpdater/dsl/models/SourceSetModel.kt b/kmp-modifier/src/main/kotlin/com/intellij/packageSearch/mppDependencyUpdater/dsl/models/SourceSetModel.kt index 252306b7..56c9066a 100644 --- a/kmp-modifier/src/main/kotlin/com/intellij/packageSearch/mppDependencyUpdater/dsl/models/SourceSetModel.kt +++ b/kmp-modifier/src/main/kotlin/com/intellij/packageSearch/mppDependencyUpdater/dsl/models/SourceSetModel.kt @@ -3,7 +3,7 @@ package com.intellij.packageSearch.mppDependencyUpdater.dsl.models import com.android.tools.idea.gradle.dsl.api.dependencies.DependenciesModel import com.android.tools.idea.gradle.dsl.api.util.PsiElementHolder -import com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModelImpl +import com.android.tools.idea.gradle.dsl.model.dependencies.DeclarativeDependenciesModelImpl import com.android.tools.idea.gradle.dsl.parser.elements.GradleNameElement import com.intellij.psi.PsiElement import com.intellij.packageSearch.mppDependencyUpdater.dsl.elements.SourceSetDependenciesElement @@ -18,11 +18,16 @@ class SourceSetModel( override fun getPsiElement(): PsiElement? = dslElement.psiElement - fun dependencies(): DependenciesModel? = dslElement.dependencies()?.let { DependenciesModelImpl(it) } + fun dependencies(): DependenciesModel? = dslElement.dependencies()?.let { + when (it) { + is SourceSetDependenciesElement -> DeclarativeDependenciesModelImpl(it) + else -> error("unexpected dependencies element: $it, unable to cast as DependenciesModel") + } + } fun addDependenciesBlock(): DependenciesModel { val depsElement = SourceSetDependenciesElement(dslElement, GradleNameElement.create("dependencies")) dslElement.setNewElement(depsElement) - return DependenciesModelImpl(depsElement) + return DeclarativeDependenciesModelImpl(depsElement) } } \ No newline at end of file diff --git a/kmp-modifier/src/test/kotlin/com/jetbrains/packageSearch/mppDependencyUpdater/intellijStuff/SdkTestCase.kt b/kmp-modifier/src/test/kotlin/com/jetbrains/packageSearch/mppDependencyUpdater/intellijStuff/SdkTestCase.kt index 32d80f2b..7c9c1c35 100644 --- a/kmp-modifier/src/test/kotlin/com/jetbrains/packageSearch/mppDependencyUpdater/intellijStuff/SdkTestCase.kt +++ b/kmp-modifier/src/test/kotlin/com/jetbrains/packageSearch/mppDependencyUpdater/intellijStuff/SdkTestCase.kt @@ -6,7 +6,6 @@ import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.projectRoots.* import com.intellij.openapi.projectRoots.impl.DependentSdkType -import com.intellij.openapi.projectRoots.impl.MockSdk import com.intellij.openapi.roots.ProjectRootManager import com.intellij.openapi.roots.ui.configuration.projectRoot.SdkDownload import com.intellij.openapi.roots.ui.configuration.projectRoot.SdkDownloadTask @@ -18,259 +17,259 @@ import java.io.File import java.util.* import java.util.function.Consumer import javax.swing.JComponent - -abstract class SdkTestCase : LightPlatformTestCase() { - - val projectSdk get() = ProjectRootManager.getInstance(project).projectSdk - - override fun setUp() { - super.setUp() - - TestSdkGenerator.reset() - SdkType.EP_NAME.point.registerExtension(TestSdkType, testRootDisposable) - SdkType.EP_NAME.point.registerExtension(DependentTestSdkType, testRootDisposable) - SdkDownload.EP_NAME.point.registerExtension(TestSdkDownloader, testRootDisposable) - } - - fun createAndRegisterSdk(isProjectSdk: Boolean = false): TestSdk { - val sdk = TestSdkGenerator.createNextSdk() - registerSdk(sdk, isProjectSdk) - return sdk - } - - fun createAndRegisterDependentSdk(isProjectSdk: Boolean = false): DependentTestSdk { - val sdk = TestSdkGenerator.createNextDependentSdk() - registerSdk(sdk.parent) - registerSdk(sdk, isProjectSdk) - return sdk - } - - private fun registerSdk(sdk: TestSdk, isProjectSdk: Boolean = false) { - registerSdk(sdk, testRootDisposable) - if (isProjectSdk) { - setProjectSdk(sdk) - } - } - - fun registerSdks(vararg sdks: TestSdk) { - registerSdks(*sdks, parentDisposable = testRootDisposable) - } - - private fun setProjectSdk(sdk: Sdk?) { - invokeAndWaitIfNeeded { - runWriteAction { - val rootManager = ProjectRootManager.getInstance(project) - rootManager.projectSdk = sdk - } - } - } - - fun withProjectSdk(sdk: TestSdk, action: () -> Unit) { - val projectSdk = projectSdk - setProjectSdk(sdk) - try { - action() - } - finally { - setProjectSdk(projectSdk) - } - } - - fun withRegisteredSdk(sdk: TestSdk, isProjectSdk: Boolean = false, action: () -> Unit) { - withRegisteredSdks(sdk) { - when (isProjectSdk) { - true -> withProjectSdk(sdk, action) - else -> action() - } - } - } - - fun withRegisteredSdks(vararg sdks: TestSdk, action: () -> Unit) { - registerSdks(*sdks) - try { - action() - } - finally { - removeSdks(*sdks) - } - } - - interface TestSdkType : JavaSdkType, SdkTypeId { - companion object : SdkType("test-type"), TestSdkType { - override fun getPresentableName(): String = name - override fun isValidSdkHome(path: String): Boolean = true - override fun suggestSdkName(currentSdkName: String?, sdkHome: String): String = TestSdkGenerator.findTestSdk( - sdkHome - )!!.name - override fun suggestHomePath(): String? = null - override fun suggestHomePaths(): Collection = TestSdkGenerator.getAllTestSdks().map { it.homePath } - override fun createAdditionalDataConfigurable(sdkModel: SdkModel, sdkModificator: SdkModificator): AdditionalDataConfigurable? = null - override fun saveAdditionalData(additionalData: SdkAdditionalData, additional: Element) {} - override fun getBinPath(sdk: Sdk): String = File(sdk.homePath, "bin").path - override fun getToolsPath(sdk: Sdk): String = File(sdk.homePath, "lib/tools.jar").path - override fun getVMExecutablePath(sdk: Sdk): String = File(sdk.homePath, "bin/java").path - override fun getVersionString(sdkHome: String): String? = TestSdkGenerator.findTestSdk(sdkHome)?.versionString - } - } - - object DependentTestSdkType : DependentSdkType("dependent-test-type"), TestSdkType { - private fun getParentPath(sdk: Sdk, relativePath: String) = - (sdk as? DependentTestSdk) - ?.parent?.homePath - ?.let { File(it, relativePath).path } - - override fun getPresentableName(): String = name - override fun isValidSdkHome(path: String): Boolean = true - override fun suggestSdkName(currentSdkName: String?, sdkHome: String): String = "dependent-sdk-name" - override fun suggestHomePath(): String? = null - override fun createAdditionalDataConfigurable(sdkModel: SdkModel, sdkModificator: SdkModificator): AdditionalDataConfigurable? = null - override fun saveAdditionalData(additionalData: SdkAdditionalData, additional: Element) {} - override fun getBinPath(sdk: Sdk) = getParentPath(sdk, "bin") - override fun getToolsPath(sdk: Sdk) = getParentPath(sdk, "lib/tools.jar") - override fun getVMExecutablePath(sdk: Sdk) = getParentPath(sdk, "bin/java") - - override fun getUnsatisfiedDependencyMessage() = "Unsatisfied dependency message" - override fun isValidDependency(sdk: Sdk) = sdk is TestSdkType - override fun getDependencyType() = TestSdkType - } - - open class TestSdk(name: String, homePath: String, versionString: String, sdkType: TestSdkType) - : MockSdk(name, homePath, versionString, MultiMap(), sdkType) { - - constructor(name: String, homePath: String, versionString: String) - : this(name, homePath, versionString, TestSdkType) - - override fun getHomePath(): String = super.getHomePath()!! - } - - open class DependentTestSdk(name: String, homePath: String, versionString: String, val parent: TestSdk) - : TestSdk(name, homePath, versionString, DependentTestSdkType) - - object TestSdkDownloader : SdkDownload { - override fun supportsDownload(sdkTypeId: SdkTypeId) = sdkTypeId == TestSdkType - - override fun showDownloadUI( - sdkTypeId: SdkTypeId, - sdkModel: SdkModel, - parentComponent: JComponent, - selectedSdk: Sdk?, - sdkCreatedCallback: Consumer - ) { - val sdk = TestSdkGenerator.createNextSdk() - sdkCreatedCallback.accept(object : SdkDownloadTask { - override fun doDownload(indicator: ProgressIndicator) {} - override fun getPlannedVersion() = sdk.versionString - override fun getSuggestedSdkName() = sdk.name - override fun getPlannedHomeDir() = sdk.homePath - }) - } - } - - object TestSdkGenerator { - private var createdSdkCounter = 0 - private lateinit var createdSdks: MutableMap - - fun getAllTestSdks() = createdSdks.values - - fun findTestSdk(sdk: Sdk): TestSdk? = findTestSdk(sdk.homePath!!) - - fun findTestSdk(homePath: String): TestSdk? = createdSdks[FileUtil.toSystemDependentName(homePath)] - - fun getCurrentSdk() = createdSdks.values.last() - - fun reserveNextSdk(versionString: String = "11"): SdkInfo { - val name = "test $versionString (${createdSdkCounter++})" - val homePath = FileUtil.toCanonicalPath(FileUtil.join(FileUtil.getTempDirectory(), "jdk-$name")) - return SdkInfo(name, versionString, homePath) - } - - fun createTestSdk(sdkInfo: SdkInfo): TestSdk { - val sdk = TestSdk(sdkInfo.name, sdkInfo.homePath, sdkInfo.versionString) - createdSdks[FileUtil.toSystemDependentName(sdkInfo.homePath)] = sdk - return sdk - } - - fun createNextSdk(versionString: String = "11"): TestSdk { - val sdkInfo = reserveNextSdk(versionString) - generateJdkStructure(sdkInfo) - return createTestSdk(sdkInfo) - } - - fun createNextDependentSdk(): DependentTestSdk { - val name = "dependent-test-name (${createdSdkCounter++})" - val versionString = "11" - val homePath = FileUtil.getTempDirectory() + "/jdk-$name" - val parentSdk = createNextSdk() - val sdk = DependentTestSdk(name, homePath, versionString, parentSdk) - createdSdks[homePath] = sdk - return sdk - } - - fun generateJdkStructure(sdkInfo: SdkInfo) { - val homePath = sdkInfo.homePath - createFile("$homePath/release") - createFile("$homePath/jre/lib/rt.jar") - createFile("$homePath/bin/javac") - createFile("$homePath/bin/java") - val properties = Properties() - properties.setProperty("JAVA_FULL_VERSION", sdkInfo.versionString) - File("$homePath/release").outputStream().use { - properties.store(it, null) - } - } - - private fun createFile(path: String) { - val file = File(path) - file.parentFile.mkdirs() - file.createNewFile() - } - - fun reset() { - createdSdkCounter = 0 - createdSdks = LinkedHashMap() - } - - data class SdkInfo(val name: String, val versionString: String, val homePath: String) - } - - companion object { - fun assertSdk(expected: TestSdk?, actual: Sdk?, isAssertSdkName: Boolean = true) { - if (expected != null && actual != null) { - if (isAssertSdkName) { - assertEquals(expected.name, actual.name) - } - assertEquals(expected.sdkType, actual.sdkType) - assertEquals(expected, TestSdkGenerator.findTestSdk(actual)) - } - else { - assertEquals(expected, actual) - } - } - - fun registerSdk(sdk: TestSdk, parentDisposable: Disposable) { - invokeAndWaitIfNeeded { - runWriteAction { - val jdkTable = ProjectJdkTable.getInstance() - jdkTable.addJdk(sdk, parentDisposable) - } - } - } - - fun registerSdks(vararg sdks: TestSdk, parentDisposable: Disposable) { - sdks.forEach { registerSdk(it, parentDisposable) } - } - - fun removeSdk(sdk: Sdk) { - invokeAndWaitIfNeeded { - runWriteAction { - val jdkTable = ProjectJdkTable.getInstance() - jdkTable.removeJdk(sdk) - } - } - } - - fun removeSdks(vararg sdks: Sdk) { - sdks.forEach(Companion::removeSdk) - } - } -} \ No newline at end of file +// +//abstract class SdkTestCase : LightPlatformTestCase() { +// +// val projectSdk get() = ProjectRootManager.getInstance(project).projectSdk +// +// override fun setUp() { +// super.setUp() +// +// TestSdkGenerator.reset() +// SdkType.EP_NAME.point.registerExtension(TestSdkType, testRootDisposable) +// SdkType.EP_NAME.point.registerExtension(DependentTestSdkType, testRootDisposable) +// SdkDownload.EP_NAME.point.registerExtension(TestSdkDownloader, testRootDisposable) +// } +// +// fun createAndRegisterSdk(isProjectSdk: Boolean = false): TestSdk { +// val sdk = TestSdkGenerator.createNextSdk() +// registerSdk(sdk, isProjectSdk) +// return sdk +// } +// +// fun createAndRegisterDependentSdk(isProjectSdk: Boolean = false): DependentTestSdk { +// val sdk = TestSdkGenerator.createNextDependentSdk() +// registerSdk(sdk.parent) +// registerSdk(sdk, isProjectSdk) +// return sdk +// } +// +// private fun registerSdk(sdk: TestSdk, isProjectSdk: Boolean = false) { +// registerSdk(sdk, testRootDisposable) +// if (isProjectSdk) { +// setProjectSdk(sdk) +// } +// } +// +// fun registerSdks(vararg sdks: TestSdk) { +// registerSdks(*sdks, parentDisposable = testRootDisposable) +// } +// +// private fun setProjectSdk(sdk: Sdk?) { +// invokeAndWaitIfNeeded { +// runWriteAction { +// val rootManager = ProjectRootManager.getInstance(project) +// rootManager.projectSdk = sdk +// } +// } +// } +// +// fun withProjectSdk(sdk: TestSdk, action: () -> Unit) { +// val projectSdk = projectSdk +// setProjectSdk(sdk) +// try { +// action() +// } +// finally { +// setProjectSdk(projectSdk) +// } +// } +// +// fun withRegisteredSdk(sdk: TestSdk, isProjectSdk: Boolean = false, action: () -> Unit) { +// withRegisteredSdks(sdk) { +// when (isProjectSdk) { +// true -> withProjectSdk(sdk, action) +// else -> action() +// } +// } +// } +// +// fun withRegisteredSdks(vararg sdks: TestSdk, action: () -> Unit) { +// registerSdks(*sdks) +// try { +// action() +// } +// finally { +// removeSdks(*sdks) +// } +// } +// +// interface TestSdkType : JavaSdkType, SdkTypeId { +// companion object : SdkType("test-type"), TestSdkType { +// override fun getPresentableName(): String = name +// override fun isValidSdkHome(path: String): Boolean = true +// override fun suggestSdkName(currentSdkName: String?, sdkHome: String): String = TestSdkGenerator.findTestSdk( +// sdkHome +// )!!.name +// override fun suggestHomePath(): String? = null +// override fun suggestHomePaths(): Collection = TestSdkGenerator.getAllTestSdks().map { it.homePath } +// override fun createAdditionalDataConfigurable(sdkModel: SdkModel, sdkModificator: SdkModificator): AdditionalDataConfigurable? = null +// override fun saveAdditionalData(additionalData: SdkAdditionalData, additional: Element) {} +// override fun getBinPath(sdk: Sdk): String = File(sdk.homePath, "bin").path +// override fun getToolsPath(sdk: Sdk): String = File(sdk.homePath, "lib/tools.jar").path +// override fun getVMExecutablePath(sdk: Sdk): String = File(sdk.homePath, "bin/java").path +// override fun getVersionString(sdkHome: String): String? = TestSdkGenerator.findTestSdk(sdkHome)?.versionString +// } +// } +// +// object DependentTestSdkType : DependentSdkType("dependent-test-type"), TestSdkType { +// private fun getParentPath(sdk: Sdk, relativePath: String) = +// (sdk as? DependentTestSdk) +// ?.parent?.homePath +// ?.let { File(it, relativePath).path } +// +// override fun getPresentableName(): String = name +// override fun isValidSdkHome(path: String): Boolean = true +// override fun suggestSdkName(currentSdkName: String?, sdkHome: String): String = "dependent-sdk-name" +// override fun suggestHomePath(): String? = null +// override fun createAdditionalDataConfigurable(sdkModel: SdkModel, sdkModificator: SdkModificator): AdditionalDataConfigurable? = null +// override fun saveAdditionalData(additionalData: SdkAdditionalData, additional: Element) {} +// override fun getBinPath(sdk: Sdk) = getParentPath(sdk, "bin") +// override fun getToolsPath(sdk: Sdk) = getParentPath(sdk, "lib/tools.jar") +// override fun getVMExecutablePath(sdk: Sdk) = getParentPath(sdk, "bin/java") +// +// override fun getUnsatisfiedDependencyMessage() = "Unsatisfied dependency message" +// override fun isValidDependency(sdk: Sdk) = sdk is TestSdkType +// override fun getDependencyType() = TestSdkType +// } +// +// open class TestSdk(name: String, homePath: String, versionString: String, sdkType: TestSdkType) +// : MockSdk(name, homePath, versionString, MultiMap(), sdkType) { +// +// constructor(name: String, homePath: String, versionString: String) +// : this(name, homePath, versionString, TestSdkType) +// +// override fun getHomePath(): String = super.getHomePath()!! +// } +// +// open class DependentTestSdk(name: String, homePath: String, versionString: String, val parent: TestSdk) +// : TestSdk(name, homePath, versionString, DependentTestSdkType) +// +// object TestSdkDownloader : SdkDownload { +// override fun supportsDownload(sdkTypeId: SdkTypeId) = sdkTypeId == TestSdkType +// +// override fun showDownloadUI( +// sdkTypeId: SdkTypeId, +// sdkModel: SdkModel, +// parentComponent: JComponent, +// selectedSdk: Sdk?, +// sdkCreatedCallback: Consumer +// ) { +// val sdk = TestSdkGenerator.createNextSdk() +// sdkCreatedCallback.accept(object : SdkDownloadTask { +// override fun doDownload(indicator: ProgressIndicator) {} +// override fun getPlannedVersion() = sdk.versionString +// override fun getSuggestedSdkName() = sdk.name +// override fun getPlannedHomeDir() = sdk.homePath +// }) +// } +// } +// +// object TestSdkGenerator { +// private var createdSdkCounter = 0 +// private lateinit var createdSdks: MutableMap +// +// fun getAllTestSdks() = createdSdks.values +// +// fun findTestSdk(sdk: Sdk): TestSdk? = findTestSdk(sdk.homePath!!) +// +// fun findTestSdk(homePath: String): TestSdk? = createdSdks[FileUtil.toSystemDependentName(homePath)] +// +// fun getCurrentSdk() = createdSdks.values.last() +// +// fun reserveNextSdk(versionString: String = "11"): SdkInfo { +// val name = "test $versionString (${createdSdkCounter++})" +// val homePath = FileUtil.toCanonicalPath(FileUtil.join(FileUtil.getTempDirectory(), "jdk-$name")) +// return SdkInfo(name, versionString, homePath) +// } +// +// fun createTestSdk(sdkInfo: SdkInfo): TestSdk { +// val sdk = TestSdk(sdkInfo.name, sdkInfo.homePath, sdkInfo.versionString) +// createdSdks[FileUtil.toSystemDependentName(sdkInfo.homePath)] = sdk +// return sdk +// } +// +// fun createNextSdk(versionString: String = "11"): TestSdk { +// val sdkInfo = reserveNextSdk(versionString) +// generateJdkStructure(sdkInfo) +// return createTestSdk(sdkInfo) +// } +// +// fun createNextDependentSdk(): DependentTestSdk { +// val name = "dependent-test-name (${createdSdkCounter++})" +// val versionString = "11" +// val homePath = FileUtil.getTempDirectory() + "/jdk-$name" +// val parentSdk = createNextSdk() +// val sdk = DependentTestSdk(name, homePath, versionString, parentSdk) +// createdSdks[homePath] = sdk +// return sdk +// } +// +// fun generateJdkStructure(sdkInfo: SdkInfo) { +// val homePath = sdkInfo.homePath +// createFile("$homePath/release") +// createFile("$homePath/jre/lib/rt.jar") +// createFile("$homePath/bin/javac") +// createFile("$homePath/bin/java") +// val properties = Properties() +// properties.setProperty("JAVA_FULL_VERSION", sdkInfo.versionString) +// File("$homePath/release").outputStream().use { +// properties.store(it, null) +// } +// } +// +// private fun createFile(path: String) { +// val file = File(path) +// file.parentFile.mkdirs() +// file.createNewFile() +// } +// +// fun reset() { +// createdSdkCounter = 0 +// createdSdks = LinkedHashMap() +// } +// +// data class SdkInfo(val name: String, val versionString: String, val homePath: String) +// } +// +// companion object { +// fun assertSdk(expected: TestSdk?, actual: Sdk?, isAssertSdkName: Boolean = true) { +// if (expected != null && actual != null) { +// if (isAssertSdkName) { +// assertEquals(expected.name, actual.name) +// } +// assertEquals(expected.sdkType, actual.sdkType) +// assertEquals(expected, TestSdkGenerator.findTestSdk(actual)) +// } +// else { +// assertEquals(expected, actual) +// } +// } +// +// fun registerSdk(sdk: TestSdk, parentDisposable: Disposable) { +// invokeAndWaitIfNeeded { +// runWriteAction { +// val jdkTable = ProjectJdkTable.getInstance() +// jdkTable.addJdk(sdk, parentDisposable) +// } +// } +// } +// +// fun registerSdks(vararg sdks: TestSdk, parentDisposable: Disposable) { +// sdks.forEach { registerSdk(it, parentDisposable) } +// } +// +// fun removeSdk(sdk: Sdk) { +// invokeAndWaitIfNeeded { +// runWriteAction { +// val jdkTable = ProjectJdkTable.getInstance() +// jdkTable.removeJdk(sdk) +// } +// } +// } +// +// fun removeSdks(vararg sdks: Sdk) { +// sdks.forEach(Companion::removeSdk) +// } +// } +//} \ No newline at end of file diff --git a/kmp-modifier/src/test/kotlin/com/jetbrains/packageSearch/mppDependencyUpdater/intellijStuff/TestUnknownSdkResolver.kt b/kmp-modifier/src/test/kotlin/com/jetbrains/packageSearch/mppDependencyUpdater/intellijStuff/TestUnknownSdkResolver.kt index 686eac0b..8698fd03 100644 --- a/kmp-modifier/src/test/kotlin/com/jetbrains/packageSearch/mppDependencyUpdater/intellijStuff/TestUnknownSdkResolver.kt +++ b/kmp-modifier/src/test/kotlin/com/jetbrains/packageSearch/mppDependencyUpdater/intellijStuff/TestUnknownSdkResolver.kt @@ -14,106 +14,106 @@ import com.intellij.openapi.roots.ui.configuration.UnknownSdkResolver import com.intellij.openapi.roots.ui.configuration.UnknownSdkResolver.UnknownSdkLookup import com.intellij.openapi.roots.ui.configuration.projectRoot.SdkDownloadTask import com.intellij.util.lang.JavaVersion - -object TestUnknownSdkResolver : UnknownSdkResolver { - lateinit var unknownSdkFixMode: TestUnknownSdkFixMode - - private val javaSdkType get() = ExternalSystemJdkProvider.getInstance().javaSdkType - - override fun supportsResolution(sdkTypeId: SdkTypeId): Boolean { - return when (unknownSdkFixMode) { - TestUnknownSdkFixMode.TEST_LOCAL_FIX -> sdkTypeId is SdkTestCase.TestSdkType - TestUnknownSdkFixMode.REAL_LOCAL_FIX -> sdkTypeId == javaSdkType - TestUnknownSdkFixMode.TEST_DOWNLOADABLE_FIX -> sdkTypeId is SdkTestCase.TestSdkType - } - } - - override fun createResolver(project: Project?, indicator: ProgressIndicator): UnknownSdkLookup { - return TestUnknownSdkLookup() - } - - private fun suggestsTestUnknownSdkLocalFixes(): Sequence { - return SdkTestCase.TestSdkGenerator.getAllTestSdks().asSequence() - .mapNotNull { createTestUnknownSdkLocalFix(it) } - } - - private fun suggestsRealUnknownSdkLocalFixes(): Sequence { - val appFixes = ProjectJdkTable.getInstance().allJdks.asSequence() - .mapNotNull { createTestUnknownSdkLocalFix(it) } - val localFixes = javaSdkType.suggestHomePaths().asSequence() - .mapNotNull { createTestUnknownSdkLocalFix(it) } - return appFixes + localFixes - } - - private fun createTestUnknownSdkLocalFix(sdk: Sdk): TestUnknownSdkLocalFix? { - val homePath = sdk.homePath ?: return null - val versionString = sdk.versionString ?: return null - val version = JavaVersion.tryParse(versionString) ?: return null - return TestUnknownSdkLocalFix(homePath, versionString, version, sdk.name, sdk) - } - - private fun createTestUnknownSdkLocalFix(homePath: String): TestUnknownSdkLocalFix? { - val versionString = javaSdkType.getVersionString(homePath) ?: return null - val version = JavaVersion.tryParse(versionString) ?: return null - val suggestedName = javaSdkType.suggestSdkName(null, homePath) - return TestUnknownSdkLocalFix(homePath, versionString, version, suggestedName, null) - } - - private class TestUnknownSdkLookup : UnknownSdkLookup { - override fun proposeLocalFix(sdk: UnknownSdk, indicator: ProgressIndicator): UnknownSdkLocalSdkFix? { - val suggestedUnknownSdkLocalFixes = when (unknownSdkFixMode) { - TestUnknownSdkFixMode.TEST_LOCAL_FIX -> suggestsTestUnknownSdkLocalFixes() - TestUnknownSdkFixMode.REAL_LOCAL_FIX -> suggestsRealUnknownSdkLocalFixes() - TestUnknownSdkFixMode.TEST_DOWNLOADABLE_FIX -> return null - } - val nameFilter = sdk.sdkName?.let { JdkRequirements.parseRequirement(it) } - return suggestedUnknownSdkLocalFixes - .filter { sdk.sdkVersionStringPredicate?.test(it.versionString) != false } - .filter { sdk.sdkHomePredicate?.test(it.existingSdkHome) != false } - .filter { nameFilter?.matches(it) != false } - .maxByOrNull { it.version } - } - - override fun proposeDownload(sdk: UnknownSdk, indicator: ProgressIndicator): UnknownSdkDownloadableSdkFix? { - if (unknownSdkFixMode != TestUnknownSdkFixMode.TEST_DOWNLOADABLE_FIX) return null - return TestUnknownSdkDownloadableSdkFix() - } - } - - private class TestUnknownSdkLocalFix( - private val homeDir: String, - private val versionString: String, - val version: JavaVersion, - private val suggestedName: String, - private val prototype: Sdk? - ) : UnknownSdkLocalSdkFix { - override fun getExistingSdkHome() = homeDir - override fun getVersionString() = versionString - override fun getSuggestedSdkName(): String = suggestedName - override fun configureSdk(sdk: Sdk) = Unit - override fun getRegisteredSdkPrototype() = prototype - } - - private class TestUnknownSdkDownloadableSdkFix : UnknownSdkDownloadableSdkFix { - private val sdkInfo = SdkTestCase.TestSdkGenerator.reserveNextSdk() - override fun getVersionString() = sdkInfo.versionString - override fun getDownloadDescription() = sdkInfo.name - override fun configureSdk(sdk: Sdk) {} - override fun createTask(indicator: ProgressIndicator) = - object : SdkDownloadTask { - override fun getPlannedVersion() = sdkInfo.versionString - override fun getSuggestedSdkName() = sdkInfo.name - override fun getPlannedHomeDir() = sdkInfo.homePath - override fun doDownload(indicator: ProgressIndicator) { - SdkTestCase.TestSdkGenerator.generateJdkStructure(sdkInfo) - SdkTestCase.TestSdkGenerator.createTestSdk(sdkInfo) - } - } - } - - enum class TestUnknownSdkFixMode { - TEST_LOCAL_FIX, - REAL_LOCAL_FIX, - TEST_DOWNLOADABLE_FIX - } -} \ No newline at end of file +// +//object TestUnknownSdkResolver : UnknownSdkResolver { +// lateinit var unknownSdkFixMode: TestUnknownSdkFixMode +// +// private val javaSdkType get() = ExternalSystemJdkProvider.getInstance().javaSdkType +// +// override fun supportsResolution(sdkTypeId: SdkTypeId): Boolean { +// return when (unknownSdkFixMode) { +// TestUnknownSdkFixMode.TEST_LOCAL_FIX -> sdkTypeId is SdkTestCase.TestSdkType +// TestUnknownSdkFixMode.REAL_LOCAL_FIX -> sdkTypeId == javaSdkType +// TestUnknownSdkFixMode.TEST_DOWNLOADABLE_FIX -> sdkTypeId is SdkTestCase.TestSdkType +// } +// } +// +// override fun createResolver(project: Project?, indicator: ProgressIndicator): UnknownSdkLookup { +// return TestUnknownSdkLookup() +// } +// +// private fun suggestsTestUnknownSdkLocalFixes(): Sequence { +// return SdkTestCase.TestSdkGenerator.getAllTestSdks().asSequence() +// .mapNotNull { createTestUnknownSdkLocalFix(it) } +// } +// +// private fun suggestsRealUnknownSdkLocalFixes(): Sequence { +// val appFixes = ProjectJdkTable.getInstance().allJdks.asSequence() +// .mapNotNull { createTestUnknownSdkLocalFix(it) } +// val localFixes = javaSdkType.suggestHomePaths().asSequence() +// .mapNotNull { createTestUnknownSdkLocalFix(it) } +// return appFixes + localFixes +// } +// +// private fun createTestUnknownSdkLocalFix(sdk: Sdk): TestUnknownSdkLocalFix? { +// val homePath = sdk.homePath ?: return null +// val versionString = sdk.versionString ?: return null +// val version = JavaVersion.tryParse(versionString) ?: return null +// return TestUnknownSdkLocalFix(homePath, versionString, version, sdk.name, sdk) +// } +// +// private fun createTestUnknownSdkLocalFix(homePath: String): TestUnknownSdkLocalFix? { +// val versionString = javaSdkType.getVersionString(homePath) ?: return null +// val version = JavaVersion.tryParse(versionString) ?: return null +// val suggestedName = javaSdkType.suggestSdkName(null, homePath) +// return TestUnknownSdkLocalFix(homePath, versionString, version, suggestedName, null) +// } +// +// private class TestUnknownSdkLookup : UnknownSdkLookup { +// override fun proposeLocalFix(sdk: UnknownSdk, indicator: ProgressIndicator): UnknownSdkLocalSdkFix? { +// val suggestedUnknownSdkLocalFixes = when (unknownSdkFixMode) { +// TestUnknownSdkFixMode.TEST_LOCAL_FIX -> suggestsTestUnknownSdkLocalFixes() +// TestUnknownSdkFixMode.REAL_LOCAL_FIX -> suggestsRealUnknownSdkLocalFixes() +// TestUnknownSdkFixMode.TEST_DOWNLOADABLE_FIX -> return null +// } +// val nameFilter = sdk.sdkName?.let { JdkRequirements.parseRequirement(it) } +// return suggestedUnknownSdkLocalFixes +// .filter { sdk.sdkVersionStringPredicate?.test(it.versionString) != false } +// .filter { sdk.sdkHomePredicate?.test(it.existingSdkHome) != false } +// .filter { nameFilter?.matches(it) != false } +// .maxByOrNull { it.version } +// } +// +// override fun proposeDownload(sdk: UnknownSdk, indicator: ProgressIndicator): UnknownSdkDownloadableSdkFix? { +// if (unknownSdkFixMode != TestUnknownSdkFixMode.TEST_DOWNLOADABLE_FIX) return null +// return TestUnknownSdkDownloadableSdkFix() +// } +// } +// +// private class TestUnknownSdkLocalFix( +// private val homeDir: String, +// private val versionString: String, +// val version: JavaVersion, +// private val suggestedName: String, +// private val prototype: Sdk? +// ) : UnknownSdkLocalSdkFix { +// override fun getExistingSdkHome() = homeDir +// override fun getVersionString() = versionString +// override fun getSuggestedSdkName(): String = suggestedName +// override fun configureSdk(sdk: Sdk) = Unit +// override fun getRegisteredSdkPrototype() = prototype +// } +// +// private class TestUnknownSdkDownloadableSdkFix : UnknownSdkDownloadableSdkFix { +// private val sdkInfo = SdkTestCase.TestSdkGenerator.reserveNextSdk() +// override fun getVersionString() = sdkInfo.versionString +// override fun getDownloadDescription() = sdkInfo.name +// override fun configureSdk(sdk: Sdk) {} +// override fun createTask(indicator: ProgressIndicator) = +// object : SdkDownloadTask { +// override fun getPlannedVersion() = sdkInfo.versionString +// override fun getSuggestedSdkName() = sdkInfo.name +// override fun getPlannedHomeDir() = sdkInfo.homePath +// override fun doDownload(indicator: ProgressIndicator) { +// SdkTestCase.TestSdkGenerator.generateJdkStructure(sdkInfo) +// SdkTestCase.TestSdkGenerator.createTestSdk(sdkInfo) +// } +// } +// } +// +// enum class TestUnknownSdkFixMode { +// TEST_LOCAL_FIX, +// REAL_LOCAL_FIX, +// TEST_DOWNLOADABLE_FIX +// } +//} \ No newline at end of file diff --git a/packagesearch.versions.toml b/packagesearch.versions.toml index ab782a21..adaafe77 100644 --- a/packagesearch.versions.toml +++ b/packagesearch.versions.toml @@ -2,7 +2,7 @@ assertk = "0.28.1" caffeine = "3.1.6" commonsCodec = "1.16.0" -composeDesktop = "1.6.0-dev1440" +composeDesktop = "1.6.11" coroutines = "1.8.0" detekt = "1.23.6" dokka = "1.9.20" @@ -10,12 +10,12 @@ flexmark = "0.64.8" foojay = "0.5.0" gradlePublishPlugin = "1.1.0" ideStarter = "LATEST-EAP-SNAPSHOT" -idea = "2023.1.2" -ideaGradlePlugin = "1.16.1" +idea = "2024.2" +ideaGradlePlugin = "1.17.3" jewel = "0.19.0" junit = "5.10.2" junit4 = "4.13.2" -kotlin = "1.9.20" +kotlin = "1.9.24" kotlinPoet = "1.15.2" kotlinterGradlePlugin = "3.12.0" kotlinxDatetime = "0.5.0" diff --git a/plugin/src/test/kotlin/com/jetbrains/packagesearch/plugin/tests/end2end/projectservice/PackageSearchProjectServiceTest.kt b/plugin/src/test/kotlin/com/jetbrains/packagesearch/plugin/tests/end2end/projectservice/PackageSearchProjectServiceTest.kt index 0a4d1dd5..1278d967 100644 --- a/plugin/src/test/kotlin/com/jetbrains/packagesearch/plugin/tests/end2end/projectservice/PackageSearchProjectServiceTest.kt +++ b/plugin/src/test/kotlin/com/jetbrains/packagesearch/plugin/tests/end2end/projectservice/PackageSearchProjectServiceTest.kt @@ -1,6 +1,5 @@ package com.jetbrains.packagesearch.plugin.tests.end2end.projectservice -import com.intellij.ide.starter.junit5.JUnit5StarterAssistant import com.intellij.tools.ide.performanceTesting.commands.CommandChain import com.intellij.tools.ide.performanceTesting.commands.exitApp import com.intellij.tools.ide.performanceTesting.commands.waitForSmartMode @@ -26,7 +25,6 @@ import org.junit.jupiter.api.extension.ExtendWith import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.MethodSource -@ExtendWith(JUnit5StarterAssistant::class) abstract class PackageSearchProjectServiceTest { abstract val resourcePath: String @@ -75,10 +73,10 @@ abstract class PackageSearchProjectServiceTest { .dumpPKGSTestData() .exitApp() - testContext.runIdeInBackground( + testContext.runIDE( commands = dumpPkgsDataChain, launchName = DumpPackageSearchModules.DUMP_NAME - ).await() + ) //result validation validateResult(projectName, "$resourcePath/$projectName.json") diff --git a/plugin/src/test/resources/projects/gradle/pkgs-test-java.zip b/plugin/src/test/resources/projects/gradle/pkgs-test-java.zip index 7132f357dfe8f3c601750dc6b27f2ed2267f9d1f..b30adab50af45662d01f2740d1c26df8061c41b5 100644 GIT binary patch delta 761 zcmZ8fTWHf@6wYZ#t+BPmc3w8ui0A}Ufh!Ic#h>QJT9^h9+E4p_6y^{6k6@%$Q1%Ay!A_dq7~L zS}~UbH-BxhXhmB;wQ1H!oLwvmXbabkaxP7ywBpqxa0mw27Q`E2Sb}bq#@>=4F>A0b z3b=4k11}E;^@Pp%Sfg+qRb)y-JAYW#H6Lne(#8xFFyc<9Dbag_+QdQzd3Qv&2T+Mr uQw=cJ3F1M40Q;~Z{$3S*iWtd6^km3YG59u@U}pcglimznwmk~FIe!7fCgcJD delta 650 zcmY*XO=uHg5Z#yU+BQ^OZEBHV+NwyhO%oLaseu&TNV3ajTWL`9x7qa6i=qc_74@J8 z4;}>PQh)F+Mi6`HMW|F`)0jd%t7t(gw0h{-`Hbn$F5k|)H#599A3Hm*+?`i$y~cpP z`{(_um!>w(Zk(4SDNRq4=%s{?{fWV9J=z(p)(tDt_-HOznM!6G8Z{$q zj(_`6T`(6zR%&@vi&#swnjNa8mQRf@jg74MLz925nX@?#& zhxv#HWMnZ&Nf%x8;v&?&-A$gqDxb$Rm&J&@sDrK~aFF_Q(B!tnKNO(2!&BiLRJxbL z9y#9RkJ4-oLENNR9%0&-hlY0|cQ{PvVMC#*0{qlo;L4e1ZWR#44UyaOnogdP}Zr&SkTDi(NX-9j6E$-s*{n{|bT9hR(aBl=9< z=2^KlRVngHy(Xw(;ux(t>?PYmFHIIOCt9tl%>s@Cul&5(agv@eqDlz?&zeb}N=PC^ z^%DB%w2NV!qqi>meB|;C+!px-%!v@BSQ$}IS6Yk&NKK=YX7V^dR+;w@jy#wD*N)p< g`(1|SncmLm6FmQYi|O$xyTnb!_>J?gaKZ+ozfcFikpKVy From 00ea8b0de7b4f684567e27ce1d6715fc54ae61dc Mon Sep 17 00:00:00 2001 From: fscarponi Date: Fri, 14 Jun 2024 16:38:24 +0200 Subject: [PATCH 2/2] Update test workflow and disable publishing workflows for master The test workflow has been updated to trigger only on pull requests to the master branch, removing the previously specified branches. Also, the 'publish-release' and 'build' workflows have been disabled for now. --- .github/workflows/{build.yml => build.yml.disabled} | 0 .../{publish-release.yml => publish-release.yml.disabled} | 0 .github/workflows/test.yml | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{build.yml => build.yml.disabled} (100%) rename .github/workflows/{publish-release.yml => publish-release.yml.disabled} (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml.disabled similarity index 100% rename from .github/workflows/build.yml rename to .github/workflows/build.yml.disabled diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml.disabled similarity index 100% rename from .github/workflows/publish-release.yml rename to .github/workflows/publish-release.yml.disabled diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 61eef016..42cc12c4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,7 +2,7 @@ name: Run tests on: pull_request: - branches: [ master, releases/242 , fabrizio.scarponi/242 ] + branches: [ master ] jobs: gradle: