Avoid using temp before @TempDir has initialized it

Closes gh-28748
pull/28778/head
Andy Wilkinson 3 years ago
parent f2b959b0a5
commit c083e0b049

@ -16,6 +16,7 @@
package org.springframework.boot.build;
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -23,16 +24,21 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import io.spring.javaformat.gradle.SpringJavaFormatPlugin;
import io.spring.javaformat.gradle.tasks.CheckFormat;
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.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.DependencySet;
import org.gradle.api.file.FileTree;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginExtension;
@ -178,7 +184,10 @@ class JavaConventions {
}
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) {
@ -264,4 +273,22 @@ class JavaConventions {
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.JavaVersion;
import org.gradle.api.Project;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@ -45,15 +46,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
*/
class BootBuildImageTests {
@TempDir
File temp;
Project project;
private final BootBuildImage buildImage;
private BootBuildImage buildImage;
BootBuildImageTests() {
File projectDir = new File(this.temp, "project");
@BeforeEach
void setUp(@TempDir File temp) {
File projectDir = new File(temp, "project");
projectDir.mkdirs();
this.project = GradleProjectBuilder.builder().withProjectDir(projectDir).withName("build-image-test").build();
this.project.setDescription("Test project for BootBuildImage");

Loading…
Cancel
Save