[Git][java-team/gradle-kotlin-dsl][master] New patch removing the ignored configuration blocks from the scripts

Emmanuel Bourg (@ebourg) gitlab at salsa.debian.org
Wed Sep 30 09:35:26 BST 2026



Emmanuel Bourg pushed to branch master at Debian Java Maintainers / gradle-kotlin-dsl


Commits:
0aa6e8b0 by Emmanuel Bourg at 2026-09-30T10:32:38+02:00
New patch removing the ignored configuration blocks from the scripts

- - - - -


3 changed files:

- debian/changelog
- + debian/patches/08-ignore-blocks-text.patch
- debian/patches/series


Changes:

=====================================
debian/changelog
=====================================
@@ -1,3 +1,9 @@
+gradle-kotlin-dsl (0.15.6-2) unstable; urgency=medium
+
+  * Ignore the plugin configuration blocks declared in debian/gradle.ignoreRules
+
+ -- Emmanuel Bourg <ebourg at apache.org>  Wed, 30 Sep 2026 10:32:30 +0200
+
 gradle-kotlin-dsl (0.15.6-1) unstable; urgency=medium
 
   * New upstream release


=====================================
debian/patches/08-ignore-blocks-text.patch
=====================================
@@ -0,0 +1,162 @@
+Description: Remove the ignored configuration blocks from the script source
+ A Kotlin script is compiled before it runs, so the body of a block naming a
+ plugin unavailable in Debian cannot be absorbed at execution time the way it is
+ in Groovy. The blocks listed in debian/gradle.ignoreRules are blanked out of
+ the source before it is handed to the compiler, with the same lexer upstream
+ uses to locate its own plugins and buildscript blocks. The file on disk is not
+ modified and the line numbers are preserved.
+Author: Emmanuel Bourg <ebourg at apache.org>
+Forwarded: not-needed
+--- a/provider/src/main/kotlin/org/gradle/kotlin/dsl/provider/BuildscriptBlockExtraction.kt
++++ b/provider/src/main/kotlin/org/gradle/kotlin/dsl/provider/BuildscriptBlockExtraction.kt
+@@ -57,6 +57,51 @@
+ }
+ 
+ 
++/**
++ * Extracts every section of the given [script] whose identifier is in
++ * [identifiers], in the form:
++ *
++ *     [identifier] { anything* }
++ *
++ * Unlike [extractTopLevelSectionFrom] the sections may repeat and may be nested
++ * in another block, as in `subprojects { ... }`. Only the identifiers starting a
++ * statement are considered, so that an expression such as `val x = jmh { ... }`
++ * is left alone.
++ */
++public
++fun ignoredSectionsFrom(script: String, identifiers: Set<String>): List<IntRange> {
++    require('\r' !in script) {
++        "CR characters are not supported by the Kotlin lexer. Convert the line separators before attempting this operation."
++    }
++    val sections = mutableListOf<IntRange>()
++    KotlinLexer().run {
++        start(script)
++        var statementStart = true
++        while (tokenType != null) {
++            if (statementStart && tokenType == IDENTIFIER && tokenText in identifiers) {
++                val sectionStart = tokenStart
++                advance()
++                skipWhiteSpaceAndComments()
++                if (tokenType == LBRACE) {
++                    val sectionEnd = findBlockEnd() ?: return sections
++                    sections.add(sectionStart..sectionEnd)
++                    advance()
++                    continue
++                }
++            }
++            statementStart = when (tokenType) {
++                LBRACE, RBRACE, SEMICOLON -> true
++                WHITE_SPACE -> statementStart || '\n' in tokenText
++                in COMMENTS -> statementStart
++                else -> false
++            }
++            advance()
++        }
++    }
++    return sections
++}
++
++
+ private
+ fun KotlinLexer.expectNoMore(identifier: String) {
+     nextTopLevelSection(identifier)?.let {
+--- /dev/null
++++ b/provider/src/main/kotlin/org/gradle/kotlin/dsl/provider/IgnoredBlocks.kt
+@@ -0,0 +1,85 @@
++/*
++ * Copyright 2026 the original author or authors.
++ *
++ * Licensed under the Apache License, Version 2.0 (the "License");
++ * you may not use this file except in compliance with the License.
++ * You may obtain a copy of the License at
++ *
++ *      http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing, software
++ * distributed under the License is distributed on an "AS IS" BASIS,
++ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
++ * See the License for the specific language governing permissions and
++ * limitations under the License.
++ */
++
++package org.gradle.kotlin.dsl.provider
++
++import java.io.File
++
++
++private
++val rulesFile = File("debian/gradle.ignoreRules")
++
++
++/**
++ * Blanks out the configuration blocks the package being built has chosen to
++ * ignore, before the script is compiled.
++ *
++ * A Kotlin script is compiled before it runs, so the body of a block naming a
++ * plugin unavailable in Debian cannot be absorbed at execution time the way it
++ * is in Groovy. It is removed from the source instead, the file on disk being
++ * left untouched. The characters are replaced by spaces rather than deleted so
++ * that the line numbers of the rest of the script are preserved.
++ */
++internal
++fun discardIgnoredBlocks(script: String): String {
++    val names = ignoredBlockNames()
++    if (names.isEmpty()) {
++        return script
++    }
++
++    var result = script
++    for (range in ignoredSectionsFrom(script, names)) {
++        result = result.blankRange(range)
++    }
++    return result
++}
++
++
++/**
++ * The names of the blocks listed in debian/gradle.ignoreRules, read through
++ * gradle-debian-helper. No block is ignored when the file is absent or the
++ * helper is not installed. The file is the switch, as it is for the plugins:
++ * the gradle-debian-helper.hook.enabled property belongs to the artifact
++ * resolution hook, and the Gradle package turns it off while still ignoring
++ * what it lists.
++ */
++private
++fun ignoredBlockNames(): Set<String> {
++    if (!rulesFile.exists()) {
++        return emptySet()
++    }
++
++    return try {
++        val rulesClass = Class.forName("org.debian.gradle.plugin.IgnoreRules")
++        val rules = rulesClass.getMethod("read").invoke(null)
++        @Suppress("UNCHECKED_CAST")
++        rulesClass.getMethod("getIgnoredExtensions").invoke(rules) as Set<String>
++    } catch (e: Throwable) {
++        println("\tCouldn't read the ignored blocks: $e")
++        emptySet()
++    }
++}
++
++
++private
++fun String.blankRange(range: IntRange): String =
++    StringBuilder(this).apply {
++        for (i in range) {
++            if (this[i] != '\n') {
++                setCharAt(i, ' ')
++            }
++        }
++    }.toString()
+--- a/provider/src/main/kotlin/org/gradle/kotlin/dsl/provider/KotlinBuildScriptCompiler.kt
++++ b/provider/src/main/kotlin/org/gradle/kotlin/dsl/provider/KotlinBuildScriptCompiler.kt
+@@ -60,7 +60,7 @@
+ 
+     val scriptPath = source.fileName!!
+ 
+-    val script = convertLineSeparators(scriptResource.text!!)
++    val script = discardIgnoredBlocks(convertLineSeparators(scriptResource.text!!))
+ 
+     val displayName: String
+         get() = source.displayName


=====================================
debian/patches/series
=====================================
@@ -3,3 +3,4 @@
 05-kotlin-1.3-scripting-plugin.patch
 06-kotlin-jar-names.patch
 07-fast-class-files-reading.patch
+08-ignore-blocks-text.patch



View it on GitLab: https://salsa.debian.org/java-team/gradle-kotlin-dsl/-/commit/0aa6e8b0771bc94231b9ced65e7b58273579666a

-- 
View it on GitLab: https://salsa.debian.org/java-team/gradle-kotlin-dsl/-/commit/0aa6e8b0771bc94231b9ced65e7b58273579666a
You're receiving this email because of your account on salsa.debian.org. Manage all notifications: https://salsa.debian.org/-/profile/notifications | Help: https://salsa.debian.org/help


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20260930/a87bb99a/attachment.htm>


More information about the pkg-java-commits mailing list