Skip to content

Commit

Permalink
242 candidate with ide patch policy
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fscarponi committed Jun 14, 2024
1 parent 5580885 commit 0dbef8c
Show file tree
Hide file tree
Showing 15 changed files with 664 additions and 382 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/TrustKotlinGradlePluginPatch.kt
Original file line number Diff line number Diff line change
@@ -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<Path> {
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.")
}
85 changes: 85 additions & 0 deletions .github/workflows/TrustKotlinGradlePluginPatch.main.kts
Original file line number Diff line number Diff line change
@@ -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.")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Publish to Marketplace
on:
release:
types: [ published ]
branches: [ master ]
branches: [ release/242 ]

jobs:
publish:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-snapshot.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish snapshot to TBE

on:
push:
branches: [ master ]
branches: [ releases/242 ]

jobs:
publish:
Expand Down
93 changes: 87 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Run tests

on:
pull_request:
branches: [ master ]
branches: [ master, releases/242 , fabrizio.scarponi/242 ]

jobs:
gradle:
Expand All @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fun Project.configureGradleIntellijPlugin(packageSearchExtension: PackageSearchE

plugins.withId("org.jetbrains.intellij") {
extensions.withType<IntelliJPluginExtension> {
version = "LATEST-EAP-SNAPSHOT"
version = "242.16677-EAP-CANDIDATE-SNAPSHOT"
instrumentCode = false
downloadSources = !isCI
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 0dbef8c

Please sign in to comment.