mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Avoid using temp before @TempDir has initialized it
Closes gh-28748
This commit is contained in:
parent
f2b959b0a5
commit
c083e0b049
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.springframework.boot.build;
|
package org.springframework.boot.build;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -23,16 +24,21 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import io.spring.javaformat.gradle.SpringJavaFormatPlugin;
|
import io.spring.javaformat.gradle.SpringJavaFormatPlugin;
|
||||||
import io.spring.javaformat.gradle.tasks.CheckFormat;
|
import io.spring.javaformat.gradle.tasks.CheckFormat;
|
||||||
import io.spring.javaformat.gradle.tasks.Format;
|
import io.spring.javaformat.gradle.tasks.Format;
|
||||||
|
import org.gradle.api.Action;
|
||||||
|
import org.gradle.api.GradleException;
|
||||||
import org.gradle.api.JavaVersion;
|
import org.gradle.api.JavaVersion;
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
|
import org.gradle.api.Task;
|
||||||
import org.gradle.api.artifacts.Configuration;
|
import org.gradle.api.artifacts.Configuration;
|
||||||
import org.gradle.api.artifacts.ConfigurationContainer;
|
import org.gradle.api.artifacts.ConfigurationContainer;
|
||||||
import org.gradle.api.artifacts.Dependency;
|
import org.gradle.api.artifacts.Dependency;
|
||||||
import org.gradle.api.artifacts.DependencySet;
|
import org.gradle.api.artifacts.DependencySet;
|
||||||
|
import org.gradle.api.file.FileTree;
|
||||||
import org.gradle.api.plugins.JavaBasePlugin;
|
import org.gradle.api.plugins.JavaBasePlugin;
|
||||||
import org.gradle.api.plugins.JavaPlugin;
|
import org.gradle.api.plugins.JavaPlugin;
|
||||||
import org.gradle.api.plugins.JavaPluginExtension;
|
import org.gradle.api.plugins.JavaPluginExtension;
|
||||||
@ -178,7 +184,10 @@ class JavaConventions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void configureJavadocConventions(Project project) {
|
private void configureJavadocConventions(Project project) {
|
||||||
project.getTasks().withType(Javadoc.class, (javadoc) -> javadoc.getOptions().source("1.8").encoding("UTF-8"));
|
project.getTasks().withType(Javadoc.class, (javadoc) -> {
|
||||||
|
javadoc.getOptions().source("1.8").encoding("UTF-8");
|
||||||
|
javadoc.doFirst(new VerifyPackageInfo());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureJavaConventions(Project project) {
|
private void configureJavaConventions(Project project) {
|
||||||
@ -264,4 +273,22 @@ class JavaConventions {
|
|||||||
project.getTasks().getByName(JavaBasePlugin.CHECK_TASK_NAME).dependsOn(checkClasspathForProhibitedDependencies);
|
project.getTasks().getByName(JavaBasePlugin.CHECK_TASK_NAME).dependsOn(checkClasspathForProhibitedDependencies);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class VerifyPackageInfo implements Action<Task> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Task javadoc) {
|
||||||
|
FileTree source = ((Javadoc) javadoc).getSource();
|
||||||
|
Stream<File> dirs = source.getFiles().stream().map((file) -> file.getParentFile()).distinct();
|
||||||
|
Set<File> missingPackageInfo = dirs.map((file) -> new File(file, "package-info.java"))
|
||||||
|
.filter((packageInfo) -> !packageInfo.isFile()).collect(Collectors.toSet());
|
||||||
|
if (!missingPackageInfo.isEmpty()) {
|
||||||
|
StringBuilder message = new StringBuilder(
|
||||||
|
"A package-info.java file was missing from the following directories:\n");
|
||||||
|
missingPackageInfo.forEach((packageInfo) -> message.append("\t" + packageInfo.getParentFile() + "\n"));
|
||||||
|
throw new GradleException(message.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import java.util.Map;
|
|||||||
import org.gradle.api.GradleException;
|
import org.gradle.api.GradleException;
|
||||||
import org.gradle.api.JavaVersion;
|
import org.gradle.api.JavaVersion;
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.io.TempDir;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
|
||||||
@ -45,15 +46,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|||||||
*/
|
*/
|
||||||
class BootBuildImageTests {
|
class BootBuildImageTests {
|
||||||
|
|
||||||
@TempDir
|
|
||||||
File temp;
|
|
||||||
|
|
||||||
Project project;
|
Project project;
|
||||||
|
|
||||||
private final BootBuildImage buildImage;
|
private BootBuildImage buildImage;
|
||||||
|
|
||||||
BootBuildImageTests() {
|
@BeforeEach
|
||||||
File projectDir = new File(this.temp, "project");
|
void setUp(@TempDir File temp) {
|
||||||
|
File projectDir = new File(temp, "project");
|
||||||
projectDir.mkdirs();
|
projectDir.mkdirs();
|
||||||
this.project = GradleProjectBuilder.builder().withProjectDir(projectDir).withName("build-image-test").build();
|
this.project = GradleProjectBuilder.builder().withProjectDir(projectDir).withName("build-image-test").build();
|
||||||
this.project.setDescription("Test project for BootBuildImage");
|
this.project.setDescription("Test project for BootBuildImage");
|
||||||
|
Loading…
Reference in New Issue
Block a user