-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Realize jvm toolchain repositories when marked immutable
Fixes #24669
- Loading branch information
Showing
6 changed files
with
280 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...rc/crossVersionTest/groovy/org/gradle/integtests/tooling/r81/ActionRunsNestedActions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2020 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.integtests.tooling.r81; | ||
|
||
import org.gradle.tooling.BuildAction; | ||
import org.gradle.tooling.BuildController; | ||
import org.gradle.tooling.model.gradle.BasicGradleProject; | ||
import org.gradle.tooling.model.gradle.GradleBuild; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ActionRunsNestedActions implements BuildAction<Models> { | ||
@Override | ||
public Models execute(BuildController controller) { | ||
GradleBuild buildModel = controller.getBuildModel(); | ||
List<GetProjectModel> projectActions = new ArrayList<GetProjectModel>(); | ||
for (BasicGradleProject project : buildModel.getProjects()) { | ||
projectActions.add(new GetProjectModel(project)); | ||
} | ||
List<ToolchainModel> results = controller.run(projectActions); | ||
return new Models(controller.getCanQueryProjectModelInParallel(ToolchainModel.class), results); | ||
} | ||
|
||
static class GetProjectModel implements BuildAction<ToolchainModel> { | ||
private final BasicGradleProject project; | ||
|
||
public GetProjectModel(BasicGradleProject project) { | ||
this.project = project; | ||
} | ||
|
||
@Override | ||
public ToolchainModel execute(BuildController controller) { | ||
return controller.getModel(project, ToolchainModel.class); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...cts/tooling-api/src/crossVersionTest/groovy/org/gradle/integtests/tooling/r81/Models.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2020 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.integtests.tooling.r81; | ||
|
||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public class Models implements Serializable { | ||
private final boolean runsInParallel; | ||
private final List<ToolchainModel> projects; | ||
|
||
public Models(boolean runsInParallel, Collection<ToolchainModel> projects) { | ||
this.runsInParallel = runsInParallel; | ||
this.projects = new ArrayList<ToolchainModel>(projects); | ||
} | ||
|
||
public boolean isMayRunInParallel() { | ||
return runsInParallel; | ||
} | ||
|
||
public List<ToolchainModel> getProjects() { | ||
return projects; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...ing-api/src/crossVersionTest/groovy/org/gradle/integtests/tooling/r81/ToolchainModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2023 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.integtests.tooling.r81; | ||
|
||
public interface ToolchainModel { | ||
|
||
String getPath(); | ||
|
||
int getJavaVersion(); | ||
} |
145 changes: 145 additions & 0 deletions
145
...rg/gradle/integtests/tooling/r81/ToolchainsParallelActionExecutionCrossVersionSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
* Copyright 2023 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.integtests.tooling.r81 | ||
|
||
import org.gradle.integtests.tooling.fixture.TargetGradleVersion | ||
import org.gradle.integtests.tooling.fixture.ToolingApiSpecification | ||
import org.gradle.integtests.tooling.fixture.ToolingApiVersion | ||
import org.gradle.tooling.BuildActionFailureException | ||
|
||
@ToolingApiVersion(">=8.1") | ||
class ToolchainsParallelActionExecutionCrossVersionSpec extends ToolingApiSpecification { | ||
|
||
def setup() { | ||
buildFile << """ | ||
import javax.inject.Inject | ||
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry | ||
import org.gradle.tooling.provider.model.ToolingModelBuilder | ||
class ToolchainPlugin implements Plugin<Project> { | ||
ToolingModelBuilderRegistry registry | ||
@Inject | ||
ToolchainPlugin(ToolingModelBuilderRegistry registry) { | ||
this.registry = registry | ||
} | ||
void apply(Project project) { | ||
registry.register(new ToolchainBuilder()) | ||
} | ||
} | ||
class ToolchainModel implements Serializable { | ||
String path | ||
Integer javaVersion | ||
} | ||
class ToolchainBuilder implements ToolingModelBuilder { | ||
boolean canBuild(String modelName) { | ||
return modelName == "org.gradle.integtests.tooling.r81.ToolchainModel" | ||
} | ||
Object buildAll(String modelName, Project project) { | ||
// Access toolchain related information | ||
def compileJavaVersion = project.tasks.compileJava.javaCompiler.get().metadata.languageVersion.asInt() | ||
return new ToolchainModel(path: project.path, javaVersion: compileJavaVersion); | ||
} | ||
} | ||
""" | ||
} | ||
|
||
@TargetGradleVersion(">=8.1") | ||
def "nested actions that query a project model which leverages toolchain information do not cause Property evaluation to be in unexpected state"() { | ||
given: | ||
setupBuildWithToolchainsResolution() | ||
|
||
when: | ||
withConnection { | ||
def action = action(new ActionRunsNestedActions()) | ||
action.standardOutput = System.out | ||
action.standardError = System.err | ||
action.addArguments("--parallel") | ||
action.run() | ||
} | ||
|
||
then: | ||
def e = thrown(BuildActionFailureException) | ||
def root = rootCause(e) | ||
root.message.startsWith('No locally installed toolchains match') | ||
} | ||
|
||
def rootCause(Exception e) { | ||
def ex = e | ||
while (ex.cause != null) { | ||
ex = ex.cause | ||
} | ||
ex | ||
} | ||
|
||
def setupBuildWithToolchainsResolution() { | ||
settingsFile << """ | ||
import java.util.Optional; | ||
import org.gradle.platform.BuildPlatform; | ||
public abstract class FakeResolver implements JavaToolchainResolver { | ||
@Override | ||
public Optional<JavaToolchainDownload> resolve(JavaToolchainRequest request) { | ||
return Optional.empty(); | ||
} | ||
} | ||
public abstract class FakeProvider implements Plugin<Settings> { | ||
@Inject | ||
protected abstract JavaToolchainResolverRegistry getToolchainResolverRegistry(); | ||
void apply(Settings settings) { | ||
settings.getPlugins().apply("jvm-toolchain-management"); | ||
JavaToolchainResolverRegistry registry = getToolchainResolverRegistry(); | ||
registry.register(FakeResolver.class); | ||
} | ||
} | ||
apply plugin: FakeProvider | ||
toolchainManagement { | ||
jvm { | ||
javaRepositories { | ||
repository('useless') { | ||
resolverClass = FakeResolver | ||
} | ||
} | ||
} | ||
} | ||
rootProject.name = 'root' | ||
include 'a', 'b' | ||
""" | ||
buildFile << """ | ||
allprojects { | ||
apply plugin: ToolchainPlugin | ||
apply plugin: 'java' | ||
java { | ||
toolchain { | ||
// Using a toolchain that triggers auto-provisioning is needed | ||
languageVersion = JavaLanguageVersion.of('99') | ||
} | ||
} | ||
} | ||
""" | ||
} | ||
} |