Skip to content

Commit 5124855

Browse files
authored
DefaultDevelocityBuildLifecycleService shouldn't force IP compatibility for build (#30382)
2 parents ff97670 + 1942d61 commit 5124855

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

platforms/enterprise/enterprise/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ dependencies {
5353
}
5454

5555
testImplementation(projects.resources)
56+
testImplementation(testFixtures(projects.core))
5657

5758
integTestImplementation(projects.internalTesting)
5859
integTestImplementation(projects.internalIntegTesting)

platforms/enterprise/enterprise/src/main/java/org/gradle/internal/enterprise/impl/DefaultDevelocityBuildLifecycleService.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.gradle.api.Action;
2121
import org.gradle.api.Project;
22+
import org.gradle.api.configuration.BuildFeatures;
2223
import org.gradle.api.invocation.Gradle;
2324
import org.gradle.internal.enterprise.DevelocityBuildLifecycleService;
2425

@@ -27,14 +28,27 @@
2728
public class DefaultDevelocityBuildLifecycleService implements DevelocityBuildLifecycleService {
2829

2930
private final Gradle gradle;
31+
private final BuildFeatures buildFeatures;
3032

3133
@Inject
32-
public DefaultDevelocityBuildLifecycleService(Gradle gradle) {
34+
public DefaultDevelocityBuildLifecycleService(Gradle gradle, BuildFeatures buildFeatures) {
3335
this.gradle = gradle;
36+
this.buildFeatures = buildFeatures;
3437
}
3538

3639
@Override
3740
public void beforeProject(Action<? super Project> action) {
38-
gradle.getLifecycle().beforeProject(action::execute);
41+
// GradleLifecycle#beforeProject isolates the action to be safe with Isolated Projects.
42+
// This brings additional serializability requirements for any state referenced by the action.
43+
// Therefore, the new callback cannot be used without Isolated Projects, because it implies a breaking change in behavior
44+
if (isIsolatedProjects()) {
45+
gradle.getLifecycle().beforeProject(action::execute);
46+
} else {
47+
gradle.allprojects(action);
48+
}
49+
}
50+
51+
private boolean isIsolatedProjects() {
52+
return buildFeatures.getIsolatedProjects().getActive().getOrElse(false);
3953
}
4054
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.gradle.internal.enterprise
18+
19+
import org.gradle.api.configuration.BuildFeatures
20+
import org.gradle.api.internal.configuration.DefaultBuildFeature
21+
import org.gradle.api.invocation.Gradle
22+
import org.gradle.api.invocation.GradleLifecycle
23+
import org.gradle.internal.enterprise.impl.DefaultDevelocityBuildLifecycleService
24+
import org.gradle.util.TestUtil
25+
import spock.lang.Specification
26+
27+
class DevelocityBuildLifecycleServiceTest extends Specification {
28+
29+
def 'uses #correctApi API for `beforeProject` logic execution if IsolatedProjects enabled=#ipEnabled'() {
30+
given:
31+
def gradle = Mock(Gradle) {
32+
_ * getLifecycle() >> Mock(GradleLifecycle)
33+
}
34+
def buildFeatures = Mock(BuildFeatures) {
35+
_ * getIsolatedProjects() >> new DefaultBuildFeature(
36+
TestUtil.providerFactory().provider { ipEnabled },
37+
TestUtil.providerFactory().provider { ipEnabled }
38+
)
39+
}
40+
def service = new DefaultDevelocityBuildLifecycleService(gradle, buildFeatures)
41+
42+
when:
43+
service.beforeProject {/*do something*/ }
44+
45+
then:
46+
if (ipEnabled) {
47+
0 * gradle.allprojects(_)
48+
1 * gradle.lifecycle.beforeProject(_)
49+
} else {
50+
1 * gradle.allprojects(_)
51+
0 * gradle.lifecycle.beforeProject(_)
52+
}
53+
54+
where:
55+
ipEnabled | correctApi
56+
true | "GradleLifecycle#beforeProject"
57+
false | "Gradle#allprojects"
58+
}
59+
}

0 commit comments

Comments
 (0)