Skip to content

Commit 45ce096

Browse files
committed
Replace our TestCompiler with Spring Framework's version
Replace the last use of our `TestCompiler` with Spring Framework's version. See gh-31266
1 parent 7bae02b commit 45ce096

File tree

3 files changed

+21
-165
lines changed

3 files changed

+21
-165
lines changed

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/JarLauncherTests.java

+21-15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.loader;
1818

1919
import java.io.File;
20+
import java.io.FileOutputStream;
2021
import java.net.URL;
2122
import java.net.URLClassLoader;
2223
import java.util.ArrayList;
@@ -33,8 +34,11 @@
3334
import org.springframework.boot.loader.archive.Archive;
3435
import org.springframework.boot.loader.archive.ExplodedArchive;
3536
import org.springframework.boot.loader.archive.JarFileArchive;
36-
import org.springframework.boot.testsupport.compiler.TestCompiler;
37+
import org.springframework.core.io.ClassPathResource;
38+
import org.springframework.core.test.tools.SourceFile;
39+
import org.springframework.core.test.tools.TestCompiler;
3740
import org.springframework.util.FileCopyUtils;
41+
import org.springframework.util.function.ThrowingConsumer;
3842

3943
import static org.assertj.core.api.Assertions.assertThat;
4044

@@ -101,24 +105,26 @@ void jarFilesPresentInBootInfLibsAndNotInClasspathIndexShouldBeAddedAfterBootInf
101105
}
102106

103107
@Test
104-
@SuppressWarnings("removal")
105-
void explodedJarDefinedPackagesIncludeManifestAttributes() throws Exception {
108+
void explodedJarDefinedPackagesIncludeManifestAttributes() {
106109
Manifest manifest = new Manifest();
107110
Attributes attributes = manifest.getMainAttributes();
108111
attributes.put(Name.MANIFEST_VERSION, "1.0");
109112
attributes.put(Name.IMPLEMENTATION_TITLE, "test");
110-
File explodedRoot = explode(
111-
createJarArchive("archive.jar", manifest, "BOOT-INF", true, Collections.emptyList()));
112-
TestCompiler compiler = new TestCompiler(new File(explodedRoot, "BOOT-INF/classes"));
113-
File source = new File(this.tempDir, "explodedsample/ExampleClass.java");
114-
source.getParentFile().mkdirs();
115-
FileCopyUtils.copy(new File("src/test/resources/explodedsample/ExampleClass.txt"), source);
116-
compiler.getTask(Collections.singleton(source)).call();
117-
JarLauncher launcher = new JarLauncher(new ExplodedArchive(explodedRoot, true));
118-
Iterator<Archive> archives = launcher.getClassPathArchivesIterator();
119-
URLClassLoader classLoader = (URLClassLoader) launcher.createClassLoader(archives);
120-
Class<?> loaded = classLoader.loadClass("explodedsample.ExampleClass");
121-
assertThat(loaded.getPackage().getImplementationTitle()).isEqualTo("test");
113+
SourceFile sourceFile = SourceFile.of("explodedsample/ExampleClass.java",
114+
new ClassPathResource("explodedsample/ExampleClass.txt"));
115+
TestCompiler.forSystem().compile(sourceFile, ThrowingConsumer.of((compiled) -> {
116+
File explodedRoot = explode(
117+
createJarArchive("archive.jar", manifest, "BOOT-INF", true, Collections.emptyList()));
118+
File target = new File(explodedRoot, "BOOT-INF/classes/explodedsample/ExampleClass.class");
119+
target.getParentFile().mkdirs();
120+
FileCopyUtils.copy(compiled.getClassLoader().getResourceAsStream("explodedsample/ExampleClass.class"),
121+
new FileOutputStream(target));
122+
JarLauncher launcher = new JarLauncher(new ExplodedArchive(explodedRoot, true));
123+
Iterator<Archive> archives = launcher.getClassPathArchivesIterator();
124+
URLClassLoader classLoader = (URLClassLoader) launcher.createClassLoader(archives);
125+
Class<?> loaded = classLoader.loadClass("explodedsample.ExampleClass");
126+
assertThat(loaded.getPackage().getImplementationTitle()).isEqualTo("test");
127+
}));
122128
}
123129

124130
protected final URL[] getExpectedFileUrls(File explodedRoot) {

spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/compiler/TestCompiler.java

-130
This file was deleted.

spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/compiler/package-info.java

-20
This file was deleted.

0 commit comments

Comments
 (0)