Skip to content

Make KotlinDslScriptModel resilient #34363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix/clean things in existing code
  • Loading branch information
jbartok committed Jul 23, 2025
commit 4f75a81c841ecba461bcc8de667c4131ca55e244
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,18 @@ import org.gradle.tooling.model.kotlin.dsl.KotlinDslScriptsModel
class CustomModelAction implements BuildAction<MyCustomModel>, Serializable {

@Override
public MyCustomModel execute(BuildController controller) {
GradleBuild build = controller.getModel(GradleBuild.class);
MyCustomModel execute(BuildController controller) {
GradleBuild build = controller.getModel(GradleBuild.class)

KotlinDslScriptsModel buildScriptModel = controller.getModel(KotlinDslScriptsModel.class);
KotlinDslScriptsModel buildScriptsModel = controller.getModel(KotlinDslScriptsModel.class)


def paths = build.projects.collect{project ->
def projectPaths = build.projects.collect{project ->
project.buildTreePath
}
build.includedBuilds.each {b -> b.projects.each {project ->
paths << project.buildTreePath
projectPaths << project.buildTreePath
}}

def identifier = build.projects.collect{project ->
project.projectIdentifier
}

// Build your custom model
return new MyCustomModel(
buildScriptModel.scriptModels,
identifier,
paths
);
return new MyCustomModel(projectPaths, buildScriptsModel.scriptModels)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,24 @@ import org.gradle.tooling.model.kotlin.dsl.KotlinDslModelsParameters

class FailedSyncIntegrationTest extends AbstractIntegrationSpec implements ToolingApiSpec {

def "broken settings file - strict mode- build action"() {
def setup() {
executer.withArguments(KotlinDslModelsParameters.CLASSPATH_MODE_SYSTEM_PROPERTY_DECLARATION)
}

def "basic build - broken main settings file"() {
given:
settingsKotlinFile << """
blow up !!!
"""

when:
MyCustomModel model = runBuildActionFails(new CustomModelAction())
MyCustomModel model = runBuildAction(new CustomModelAction())

then:
failureDescriptionContains("Script compilation error")
model.paths == [":"]
}

def "basic project - broken root build file with build action"() {
def "basic build - broken root build file"() {
given:
settingsKotlinFile << """
rootProject.name = "root"
Expand All @@ -47,14 +51,13 @@ class FailedSyncIntegrationTest extends AbstractIntegrationSpec implements Tooli
"""

when:
executer.withArguments(KotlinDslModelsParameters.CLASSPATH_MODE_SYSTEM_PROPERTY_DECLARATION)
MyCustomModel model = runBuildAction(new CustomModelAction())

then:
model.paths == [":"]
}

def "basic project w/ included build - broken included build build file - build action"() {
def "basic project w/ included build - broken build file in included build"() {
given:
settingsKotlinFile << """
rootProject.name = "root"
Expand All @@ -70,14 +73,35 @@ class FailedSyncIntegrationTest extends AbstractIntegrationSpec implements Tooli
"""

when:
executer.withArguments(KotlinDslModelsParameters.CLASSPATH_MODE_SYSTEM_PROPERTY_DECLARATION)
MyCustomModel model = runBuildAction(new CustomModelAction())

then:
model.paths == [":", ":included"]
}

def "basic project w/ included build - broken included build settings file and build script - strict mode - build action"() {
def "basic build w/ included build - broken settings file in included build"() {
given:
settingsKotlinFile << """
rootProject.name = "root"
includeBuild("included")
"""

def included = testDirectory.createDir("included")
included.file("settings.gradle.kts") << """
boom !!!
"""
included.file("build.gradle.kts") << """
// nothing interesting
"""

when:
MyCustomModel model = runBuildAction(new CustomModelAction())

then:
model.paths == [":", ":included"]
}

def "basic build w/ included build - broken settings and build file in included build"() {
given:
settingsKotlinFile << """
rootProject.name = "root"
Expand All @@ -93,10 +117,10 @@ class FailedSyncIntegrationTest extends AbstractIntegrationSpec implements Tooli
"""

when:
MyCustomModel model = runBuildActionFails(new CustomModelAction())
MyCustomModel model = runBuildAction(new CustomModelAction())

then:
failureDescriptionContains("Script compilation error")
model.paths == [":", ":included"]
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@

package org.gradle.integtests.tooling

import org.gradle.tooling.model.ProjectIdentifier
import org.gradle.tooling.model.kotlin.dsl.KotlinDslScriptModel;

class MyCustomModel implements Serializable {
List<ProjectIdentifier> projectIdentifiers;
List<String> paths;
Map<File, KotlinDslScriptModel> scriptModels;

MyCustomModel(Map<File, KotlinDslScriptModel> models, List<ProjectIdentifier> projectIdentifiers,
List<String> paths) {
this.projectIdentifiers = projectIdentifiers;
MyCustomModel(List<String> paths, Map<File, KotlinDslScriptModel> models) {
this.paths = paths;
this.scriptModels = models;
}
Expand Down