Skip to content

Commit

Permalink
Merge branch '3.2.x' into 3.3.x
Browse files Browse the repository at this point in the history
Closes gh-42357
  • Loading branch information
wilkinsona committed Sep 18, 2024
2 parents 23f064d + 1240c59 commit 4a6793e
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,21 @@ dependencies {

testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-gradle-test-support"))
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
testImplementation("com.fasterxml.jackson.core:jackson-databind")
testImplementation("com.fasterxml.jackson.module:jackson-module-parameter-names")
testImplementation("com.tngtech.archunit:archunit-junit5:0.22.0")
testImplementation("net.java.dev.jna:jna-platform")
testImplementation("org.apache.commons:commons-compress")
testImplementation("org.apache.httpcomponents.client5:httpclient5")
testImplementation("org.assertj:assertj-core")
testImplementation("org.graalvm.buildtools:native-gradle-plugin")
testImplementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion")
testImplementation("org.jetbrains.kotlin:kotlin-compiler-runner:$kotlinVersion")
testImplementation("org.jetbrains.kotlin:kotlin-daemon-client:$kotlinVersion")
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("org.mockito:mockito-core")
testImplementation("org.tomlj:tomlj:1.0.0")
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
import org.junit.platform.commons.util.AnnotationUtils;

import org.springframework.boot.gradle.testkit.PluginClasspathGradleBuild;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuildExtension;
import org.springframework.boot.testsupport.gradle.testkit.GradleVersions;
Expand Down Expand Up @@ -96,7 +97,7 @@ public String getDisplayName(int invocationIndex) {

@Override
public List<Extension> getAdditionalExtensions() {
GradleBuild gradleBuild = new GradleBuild().gradleVersion(this.gradleVersion);
GradleBuild gradleBuild = new PluginClasspathGradleBuild().gradleVersion(this.gradleVersion);
if (this.configurationCache) {
gradleBuild.configurationCache();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;

import org.springframework.boot.gradle.testkit.PluginClasspathGradleBuild;
import org.springframework.boot.testsupport.gradle.testkit.Dsl;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuildExtension;
Expand Down Expand Up @@ -60,8 +61,8 @@ private static final class DslTestTemplateInvocationContext implements TestTempl

@Override
public List<Extension> getAdditionalExtensions() {
GradleBuild gradleBuild = new GradleBuild(this.dsl);
gradleBuild.gradleVersion(GradleVersions.minimumCompatible());
GradleBuild gradleBuild = new PluginClasspathGradleBuild(this.dsl)
.gradleVersion(GradleVersions.minimumCompatible());
return Arrays.asList(new GradleBuildFieldSetter(gradleBuild), new GradleBuildExtension());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;

import org.springframework.boot.gradle.testkit.PluginClasspathGradleBuild;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuildExtension;

Expand All @@ -42,7 +43,7 @@
@ExtendWith(GradleBuildExtension.class)
class KotlinPluginActionIntegrationTests {

GradleBuild gradleBuild = new GradleBuild();
GradleBuild gradleBuild = new PluginClasspathGradleBuild();

@Test
void noKotlinVersionPropertyWithoutKotlinPlugin() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;

import org.springframework.boot.gradle.testkit.PluginClasspathGradleBuild;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuildExtension;

Expand All @@ -35,7 +36,7 @@
@ExtendWith(GradleBuildExtension.class)
class SpringBootPluginIntegrationTests {

final GradleBuild gradleBuild = new GradleBuild();
final GradleBuild gradleBuild = new PluginClasspathGradleBuild();

@Test
@DisabledForJreRange(min = JRE.JAVA_20)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright 2012-2024 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
*
* https://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.springframework.boot.gradle.testkit;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.core.Versioned;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
import com.sun.jna.Platform;
import io.spring.gradle.dependencymanagement.DependencyManagementPlugin;
import org.antlr.v4.runtime.Lexer;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http2.HttpVersionPolicy;
import org.gradle.testkit.runner.GradleRunner;
import org.jetbrains.kotlin.gradle.model.KotlinProject;
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin;
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin;
import org.jetbrains.kotlin.project.model.LanguageSettings;
import org.jetbrains.kotlin.tooling.core.KotlinToolingVersion;
import org.tomlj.Toml;

import org.springframework.asm.ClassVisitor;
import org.springframework.boot.buildpack.platform.build.BuildRequest;
import org.springframework.boot.loader.tools.LaunchScript;
import org.springframework.boot.testsupport.gradle.testkit.Dsl;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;

/**
* Custom {@link GradleBuild} that configures the
* {@link GradleRunner#withPluginClasspath(Iterable) plugin classpath}.
*
* @author Andy Wilkinson
* @author Scott Frederick
*/
public class PluginClasspathGradleBuild extends GradleBuild {

public PluginClasspathGradleBuild() {
super();
}

public PluginClasspathGradleBuild(Dsl dsl) {
super(dsl);
}

@Override
public GradleRunner prepareRunner(String... arguments) throws IOException {
return super.prepareRunner(arguments).withPluginClasspath(pluginClasspath());
}

private List<File> pluginClasspath() {
return Arrays.asList(new File("bin/main"), new File("build/classes/java/main"),
new File("build/resources/main"), new File(pathOfJarContaining(LaunchScript.class)),
new File(pathOfJarContaining(ClassVisitor.class)),
new File(pathOfJarContaining(DependencyManagementPlugin.class)),
new File(pathOfJarContaining("org.jetbrains.kotlin.cli.common.PropertiesKt")),
new File(pathOfJarContaining(KotlinPlatformJvmPlugin.class)),
new File(pathOfJarContaining(KotlinProject.class)),
new File(pathOfJarContaining(KotlinToolingVersion.class)),
new File(pathOfJarContaining("org.jetbrains.kotlin.daemon.client.KotlinCompilerClient")),
new File(pathOfJarContaining(KotlinCompilerPluginSupportPlugin.class)),
new File(pathOfJarContaining(LanguageSettings.class)),
new File(pathOfJarContaining(ArchiveEntry.class)), new File(pathOfJarContaining(BuildRequest.class)),
new File(pathOfJarContaining(HttpClientConnectionManager.class)),
new File(pathOfJarContaining(HttpRequest.class)),
new File(pathOfJarContaining(HttpVersionPolicy.class)), new File(pathOfJarContaining(Module.class)),
new File(pathOfJarContaining(Versioned.class)),
new File(pathOfJarContaining(ParameterNamesModule.class)),
new File(pathOfJarContaining(JsonView.class)), new File(pathOfJarContaining(Platform.class)),
new File(pathOfJarContaining(Toml.class)), new File(pathOfJarContaining(Lexer.class)),
new File(pathOfJarContaining("org.graalvm.buildtools.gradle.NativeImagePlugin")),
new File(pathOfJarContaining("org.graalvm.reachability.GraalVMReachabilityMetadataRepository")),
new File(pathOfJarContaining("org.graalvm.buildtools.utils.SharedConstants")));
}

private String pathOfJarContaining(String className) {
try {
return pathOfJarContaining(Class.forName(className));
}
catch (ClassNotFoundException ex) {
throw new IllegalArgumentException(ex);
}
}

private String pathOfJarContaining(Class<?> type) {
return type.getProtectionDomain().getCodeSource().getLocation().getPath();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,7 @@ dependencies {
compileOnly("org.junit.jupiter:junit-jupiter")

implementation(gradleTestKit())
implementation(project(":spring-boot-project:spring-boot-tools:spring-boot-buildpack-platform"))
implementation(project(":spring-boot-project:spring-boot-tools:spring-boot-loader-tools"))
implementation("io.spring.gradle:dependency-management-plugin")
implementation("org.graalvm.buildtools:native-gradle-plugin")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-compiler-runner:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-daemon-client:$kotlinVersion")
implementation("org.apache.commons:commons-compress")

implementation("org.assertj:assertj-core")
implementation("org.springframework:spring-core")
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,11 @@
import java.util.Properties;
import java.util.jar.JarFile;

import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.core.Versioned;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
import com.sun.jna.Platform;
import io.spring.gradle.dependencymanagement.DependencyManagementPlugin;
import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension;
import org.antlr.v4.runtime.Lexer;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http2.HttpVersionPolicy;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.gradle.util.GradleVersion;
import org.jetbrains.kotlin.gradle.model.KotlinProject;
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin;
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin;
import org.jetbrains.kotlin.project.model.LanguageSettings;
import org.jetbrains.kotlin.tooling.core.KotlinToolingVersion;
import org.tomlj.Toml;

import org.springframework.asm.ClassVisitor;
import org.springframework.boot.buildpack.platform.build.BuildRequest;
import org.springframework.boot.loader.tools.LaunchScript;

import org.springframework.util.FileCopyUtils;
import org.springframework.util.FileSystemUtils;

Expand Down Expand Up @@ -95,7 +75,7 @@ public GradleBuild() {
this(Dsl.GROOVY);
}

public GradleBuild(Dsl dsl) {
protected GradleBuild(Dsl dsl) {
this.dsl = dsl;
}

Expand All @@ -112,44 +92,6 @@ void after() {
FileSystemUtils.deleteRecursively(this.projectDir);
}

private List<File> pluginClasspath() {
return Arrays.asList(new File("bin/main"), new File("build/classes/java/main"),
new File("build/resources/main"), new File(pathOfJarContaining(LaunchScript.class)),
new File(pathOfJarContaining(ClassVisitor.class)),
new File(pathOfJarContaining(DependencyManagementPlugin.class)),
new File(pathOfJarContaining("org.jetbrains.kotlin.cli.common.PropertiesKt")),
new File(pathOfJarContaining(KotlinPlatformJvmPlugin.class)),
new File(pathOfJarContaining(KotlinProject.class)),
new File(pathOfJarContaining(KotlinToolingVersion.class)),
new File(pathOfJarContaining("org.jetbrains.kotlin.daemon.client.KotlinCompilerClient")),
new File(pathOfJarContaining(KotlinCompilerPluginSupportPlugin.class)),
new File(pathOfJarContaining(LanguageSettings.class)),
new File(pathOfJarContaining(ArchiveEntry.class)), new File(pathOfJarContaining(BuildRequest.class)),
new File(pathOfJarContaining(HttpClientConnectionManager.class)),
new File(pathOfJarContaining(HttpRequest.class)),
new File(pathOfJarContaining(HttpVersionPolicy.class)), new File(pathOfJarContaining(Module.class)),
new File(pathOfJarContaining(Versioned.class)),
new File(pathOfJarContaining(ParameterNamesModule.class)),
new File(pathOfJarContaining(JsonView.class)), new File(pathOfJarContaining(Platform.class)),
new File(pathOfJarContaining(Toml.class)), new File(pathOfJarContaining(Lexer.class)),
new File(pathOfJarContaining("org.graalvm.buildtools.gradle.NativeImagePlugin")),
new File(pathOfJarContaining("org.graalvm.reachability.GraalVMReachabilityMetadataRepository")),
new File(pathOfJarContaining("org.graalvm.buildtools.utils.SharedConstants")));
}

private String pathOfJarContaining(String className) {
try {
return pathOfJarContaining(Class.forName(className));
}
catch (ClassNotFoundException ex) {
throw new IllegalArgumentException(ex);
}
}

private String pathOfJarContaining(Class<?> type) {
return type.getProtectionDomain().getCodeSource().getLocation().getPath();
}

public GradleBuild script(String script) {
this.script = script.endsWith(this.dsl.getExtension()) ? script : script + this.dsl.getExtension();
return this;
Expand Down Expand Up @@ -230,9 +172,7 @@ public GradleRunner prepareRunner(String... arguments) throws IOException {
if (repository.exists()) {
FileSystemUtils.copyRecursively(repository, new File(this.projectDir, "repository"));
}
GradleRunner gradleRunner = GradleRunner.create()
.withProjectDir(this.projectDir)
.withPluginClasspath(pluginClasspath());
GradleRunner gradleRunner = GradleRunner.create().withProjectDir(this.projectDir);
if (!this.configurationCache) {
// See https://github.com/gradle/gradle/issues/14125
gradleRunner.withDebug(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ dependencies {
}

systemTestImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
systemTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-gradle-plugin"))
systemTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-gradle-test-support"))
systemTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-buildpack-platform"))
systemTestImplementation(gradleTestKit())
Expand Down

0 comments on commit 4a6793e

Please sign in to comment.