Skip to content

Commit 530d17c

Browse files
committed
Merge pull request #27328 from dreis2211
* gh-27328: Disable Gradle plugin tests that fail on JDK 17 Closes gh-27328
2 parents 1e09ef1 + be38ce3 commit 530d17c

File tree

8 files changed

+146
-10
lines changed

8 files changed

+146
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2012-2021 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+
* https://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.springframework.boot.gradle.junit;
18+
19+
import java.util.Collections;
20+
import java.util.List;
21+
22+
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
23+
import org.junit.jupiter.api.extension.ExecutionCondition;
24+
import org.junit.jupiter.api.extension.Extension;
25+
import org.junit.jupiter.api.extension.ExtensionContext;
26+
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
27+
28+
/**
29+
* {@link TestTemplateInvocationContext} that disables tests.
30+
*
31+
* @author Christoph Dreis
32+
*/
33+
final class DisabledTemplateInvocationContext implements TestTemplateInvocationContext {
34+
35+
@Override
36+
public List<Extension> getAdditionalExtensions() {
37+
return Collections.singletonList(new DisabledCondition());
38+
}
39+
40+
private static class DisabledCondition implements ExecutionCondition {
41+
42+
@Override
43+
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
44+
return ConditionEvaluationResult.disabled("");
45+
}
46+
47+
}
48+
49+
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleCompatibilityExtension.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ final class GradleCompatibilityExtension implements TestTemplateInvocationContex
5757

5858
@Override
5959
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
60+
if (JavaVersion.current() == JavaVersion.VERSION_17) {
61+
return Stream.of(new DisabledTemplateInvocationContext());
62+
}
6063
Stream<String> gradleVersions = GRADLE_VERSIONS.stream().map((version) -> {
6164
if (version.equals("current")) {
6265
return GradleVersion.current().getVersion();

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleMultiDslExtension.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public class GradleMultiDslExtension implements TestTemplateInvocationContextPro
4242

4343
@Override
4444
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
45+
if (JavaVersion.current() == JavaVersion.VERSION_17) {
46+
return Stream.of(new DisabledTemplateInvocationContext());
47+
}
4548
return Stream.of(Dsl.values()).map(DslTestTemplateInvocationContext::new);
4649
}
4750

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2012-2021 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+
* https://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.springframework.boot.gradle.junit;
18+
19+
import java.io.File;
20+
21+
import org.gradle.api.JavaVersion;
22+
import org.gradle.api.Project;
23+
import org.gradle.internal.nativeintegration.services.NativeServices;
24+
import org.gradle.testfixtures.ProjectBuilder;
25+
import org.gradle.testfixtures.internal.ProjectBuilderImpl;
26+
27+
import org.springframework.util.Assert;
28+
import org.springframework.util.StringUtils;
29+
30+
/**
31+
* Helper class to build Gradle {@link Project Projects} for test fixtures. Wraps
32+
* functionality of Gradle's own {@link ProjectBuilder} in order to workaround an issue on
33+
* JDK 17.
34+
*
35+
* @author Christoph Dreis
36+
* @see <a href="https://github.com/gradle/gradle/issues/16857">Gradle Support JDK 17</a>
37+
*/
38+
public final class GradleProjectBuilder {
39+
40+
private File projectDir;
41+
42+
private String name;
43+
44+
private GradleProjectBuilder() {
45+
}
46+
47+
public static GradleProjectBuilder builder() {
48+
return new GradleProjectBuilder();
49+
}
50+
51+
public GradleProjectBuilder withProjectDir(File dir) {
52+
this.projectDir = dir;
53+
return this;
54+
}
55+
56+
public GradleProjectBuilder withName(String name) {
57+
this.name = name;
58+
return this;
59+
}
60+
61+
public Project build() {
62+
Assert.notNull(this.projectDir, "ProjectDir must not be null");
63+
ProjectBuilder builder = ProjectBuilder.builder();
64+
builder.withProjectDir(this.projectDir);
65+
File userHome = new File(this.projectDir, "userHome");
66+
builder.withGradleUserHomeDir(userHome);
67+
if (StringUtils.hasText(this.name)) {
68+
builder.withName(this.name);
69+
}
70+
if (JavaVersion.current() == JavaVersion.VERSION_17) {
71+
NativeServices.initialize(userHome);
72+
try {
73+
ProjectBuilderImpl.getGlobalServices();
74+
}
75+
catch (Throwable ignore) {
76+
}
77+
}
78+
return builder.build();
79+
}
80+
81+
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/SpringBootPluginTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,10 +20,10 @@
2020

2121
import org.gradle.api.Project;
2222
import org.gradle.api.artifacts.Configuration;
23-
import org.gradle.testfixtures.ProjectBuilder;
2423
import org.junit.jupiter.api.Test;
2524
import org.junit.jupiter.api.io.TempDir;
2625

26+
import org.springframework.boot.gradle.junit.GradleProjectBuilder;
2727
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
2828

2929
import static org.assertj.core.api.Assertions.assertThat;
@@ -42,7 +42,7 @@ class SpringBootPluginTests {
4242

4343
@Test
4444
void bootArchivesConfigurationsCannotBeResolved() {
45-
Project project = ProjectBuilder.builder().withProjectDir(this.temp).build();
45+
Project project = GradleProjectBuilder.builder().withProjectDir(this.temp).build();
4646
project.getPlugins().apply(SpringBootPlugin.class);
4747
Configuration bootArchives = project.getConfigurations()
4848
.getByName(SpringBootPlugin.BOOT_ARCHIVES_CONFIGURATION_NAME);

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,10 +26,10 @@
2626
import org.gradle.api.Project;
2727
import org.gradle.api.internal.project.ProjectInternal;
2828
import org.gradle.initialization.GradlePropertiesController;
29-
import org.gradle.testfixtures.ProjectBuilder;
3029
import org.junit.jupiter.api.Test;
3130
import org.junit.jupiter.api.io.TempDir;
3231

32+
import org.springframework.boot.gradle.junit.GradleProjectBuilder;
3333
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
3434

3535
import static org.assertj.core.api.Assertions.assertThat;
@@ -131,7 +131,7 @@ void additionalPropertiesAreReflectedInProperties() {
131131

132132
private Project createProject(String projectName) {
133133
File projectDir = new File(this.temp, projectName);
134-
Project project = ProjectBuilder.builder().withProjectDir(projectDir).withName(projectName).build();
134+
Project project = GradleProjectBuilder.builder().withProjectDir(projectDir).withName(projectName).build();
135135
((ProjectInternal) project).getServices().get(GradlePropertiesController.class)
136136
.loadGradlePropertiesFrom(projectDir);
137137
return project;

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@
6161
import org.gradle.api.internal.file.archive.ZipCopyAction;
6262
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
6363
import org.gradle.api.tasks.bundling.Jar;
64-
import org.gradle.testfixtures.ProjectBuilder;
6564
import org.junit.jupiter.api.BeforeEach;
6665
import org.junit.jupiter.api.Test;
6766
import org.junit.jupiter.api.io.TempDir;
6867

68+
import org.springframework.boot.gradle.junit.GradleProjectBuilder;
6969
import org.springframework.boot.loader.tools.DefaultLaunchScript;
7070
import org.springframework.boot.loader.tools.JarModeLibrary;
7171

@@ -115,7 +115,7 @@ void createTask() {
115115
try {
116116
File projectDir = new File(this.temp, "project");
117117
projectDir.mkdirs();
118-
this.project = ProjectBuilder.builder().withProjectDir(projectDir).build();
118+
this.project = GradleProjectBuilder.builder().withProjectDir(projectDir).build();
119119
this.project.setDescription("Test project for " + this.taskClass.getSimpleName());
120120
this.task = configure(this.project.getTasks().create("testArchive", this.taskClass));
121121
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
import org.gradle.api.GradleException;
2525
import org.gradle.api.JavaVersion;
2626
import org.gradle.api.Project;
27-
import org.gradle.testfixtures.ProjectBuilder;
2827
import org.junit.jupiter.api.Test;
2928
import org.junit.jupiter.api.io.TempDir;
3029

3130
import org.springframework.boot.buildpack.platform.build.BuildRequest;
3231
import org.springframework.boot.buildpack.platform.build.BuildpackReference;
3332
import org.springframework.boot.buildpack.platform.build.PullPolicy;
3433
import org.springframework.boot.buildpack.platform.docker.type.Binding;
34+
import org.springframework.boot.gradle.junit.GradleProjectBuilder;
3535

3636
import static org.assertj.core.api.Assertions.assertThat;
3737
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -55,7 +55,7 @@ class BootBuildImageTests {
5555
BootBuildImageTests() {
5656
File projectDir = new File(this.temp, "project");
5757
projectDir.mkdirs();
58-
this.project = ProjectBuilder.builder().withProjectDir(projectDir).withName("build-image-test").build();
58+
this.project = GradleProjectBuilder.builder().withProjectDir(projectDir).withName("build-image-test").build();
5959
this.project.setDescription("Test project for BootBuildImage");
6060
this.buildImage = this.project.getTasks().create("buildImage", BootBuildImage.class);
6161
}

0 commit comments

Comments
 (0)