diff --git a/buildSrc/src/main/java/org/springframework/boot/build/antora/GenerateAntoraPlaybook.java b/buildSrc/src/main/java/org/springframework/boot/build/antora/GenerateAntoraPlaybook.java index adbf9e55a269..2965509797ff 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/antora/GenerateAntoraPlaybook.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/antora/GenerateAntoraPlaybook.java @@ -50,6 +50,7 @@ * Task to generate a local Antora playbook. * * @author Phillip Webb + * @author Yanming Zhou */ public abstract class GenerateAntoraPlaybook extends DefaultTask { @@ -57,6 +58,8 @@ public abstract class GenerateAntoraPlaybook extends DefaultTask { private static final String GENERATED_DOCS = "build/generated/docs/"; + private final Project project; + @OutputFile public abstract RegularFileProperty getOutputFile(); @@ -76,9 +79,10 @@ public abstract class GenerateAntoraPlaybook extends DefaultTask { public abstract Property getExcludeJavadocExtension(); public GenerateAntoraPlaybook() { + this.project = getProject(); setGroup("Documentation"); setDescription("Generates an Antora playbook.yml file for local use"); - getOutputFile().convention(getProject().getLayout() + getOutputFile().convention(this.project.getLayout() .getBuildDirectory() .file("generated/docs/antora-playbook/antora-playbook.yml")); getContentSourceConfiguration().convention("antoraContent"); @@ -127,7 +131,7 @@ private void addExtensions(Map data) { extensions.xref((xref) -> xref.stub(getXrefStubs().getOrElse(Collections.emptyList()))); extensions.zipContentsCollector((zipContentsCollector) -> { zipContentsCollector.versionFile("gradle.properties"); - String locationName = getProject().getName() + "-${version}-${name}-${classifier}.zip"; + String locationName = this.project.getName() + "-${version}-${name}-${classifier}.zip"; Path antoraContent = getRelativeProjectPath() .resolve(GENERATED_DOCS + "antora-content/" + locationName); Path antoraDependencies = getRelativeProjectPath() @@ -149,12 +153,12 @@ private void addSources(Map data) { private Map createContentSource() { Map source = new LinkedHashMap<>(); Path playbookPath = getOutputFile().get().getAsFile().toPath().getParent(); - Path antoraSrc = getProjectPath(getProject()).resolve(ANTORA_SOURCE_DIR); + Path antoraSrc = getProjectPath(this.project).resolve(ANTORA_SOURCE_DIR); StringBuilder url = new StringBuilder("."); relativizeFromRootProject(playbookPath).normalize().forEach((path) -> url.append(File.separator).append("..")); source.put("url", url.toString()); source.put("branches", "HEAD"); - source.put("version", getProject().getVersion().toString()); + source.put("version", this.project.getVersion().toString()); Set startPaths = new LinkedHashSet<>(); addAntoraContentStartPaths(startPaths); startPaths.add(relativizeFromRootProject(antoraSrc).toString()); @@ -163,7 +167,7 @@ private Map createContentSource() { } private void addAntoraContentStartPaths(Set startPaths) { - Configuration configuration = getProject().getConfigurations().findByName("antoraContent"); + Configuration configuration = this.project.getConfigurations().findByName("antoraContent"); if (configuration != null) { for (ProjectDependency dependency : configuration.getAllDependencies().withType(ProjectDependency.class)) { Path path = dependency.getDependencyProject().getProjectDir().toPath(); @@ -175,7 +179,7 @@ private void addAntoraContentStartPaths(Set startPaths) { private void addDir(Map data) { Path playbookDir = toRealPath(getOutputFile().get().getAsFile().toPath()).getParent(); Path outputDir = toRealPath( - getProject().getLayout().getBuildDirectory().dir("site").get().getAsFile().toPath()); + this.project.getLayout().getBuildDirectory().dir("site").get().getAsFile().toPath()); data.put("output", Map.of("dir", "." + File.separator + playbookDir.relativize(outputDir))); } @@ -202,11 +206,11 @@ private Yaml createYaml() { } private Path getRelativeProjectPath() { - return relativizeFromRootProject(getProjectPath(getProject())); + return relativizeFromRootProject(getProjectPath(this.project)); } private Path relativizeFromRootProject(Path subPath) { - Path rootProjectPath = getProjectPath(getProject().getRootProject()); + Path rootProjectPath = getProjectPath(this.project.getRootProject()); return rootProjectPath.relativize(subPath).normalize(); } diff --git a/buildSrc/src/main/java/org/springframework/boot/build/cli/HomebrewFormula.java b/buildSrc/src/main/java/org/springframework/boot/build/cli/HomebrewFormula.java index 3edf6097d3c6..a4afb5abd0ef 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/cli/HomebrewFormula.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/cli/HomebrewFormula.java @@ -47,21 +47,24 @@ * A {@link Task} for creating a Homebrew formula manifest. * * @author Andy Wilkinson + * @author Yanming Zhou */ public abstract class HomebrewFormula extends DefaultTask { private static final Logger logger = LoggerFactory.getLogger(HomebrewFormula.class); + private final Project project; + private final FileSystemOperations fileSystemOperations; @Inject public HomebrewFormula(FileSystemOperations fileSystemOperations) { + this.project = getProject(); this.fileSystemOperations = fileSystemOperations; - Project project = getProject(); MapProperty properties = getProperties(); properties.put("hash", getArchive().map((archive) -> sha256(archive.getAsFile()))); - getProperties().put("repo", ArtifactRelease.forProject(project).getDownloadRepo()); - getProperties().put("version", project.getVersion().toString()); + getProperties().put("repo", ArtifactRelease.forProject(this.project).getDownloadRepo()); + getProperties().put("version", this.project.getVersion().toString()); } private String sha256(File file) { @@ -90,7 +93,7 @@ private String sha256(File file) { @TaskAction void createFormula() { - BuildType buildType = BuildProperties.get(getProject()).buildType(); + BuildType buildType = BuildProperties.get(this.project).buildType(); if (buildType != BuildType.OPEN_SOURCE) { logger.debug("Skipping Homebrew formula for non open source build type"); return; diff --git a/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java b/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java index 485f731cc4a4..3bf55a43d221 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java @@ -106,6 +106,7 @@ * * @author Andy Wilkinson * @author Phillip Webb + * @author Yanming Zhou */ public class MavenPluginPlugin implements Plugin { @@ -334,8 +335,14 @@ private void addExtractVersionPropertiesTask(Project project) { public abstract static class FormatHelpMojoSource extends DefaultTask { + private final Project project; + private Task generator; + public FormatHelpMojoSource() { + this.project = getProject(); + } + void setGenerator(Task generator) { this.generator = generator; getInputs().files(this.generator) @@ -350,7 +357,7 @@ void setGenerator(Task generator) { void syncAndFormat() { FileFormatter formatter = new FileFormatter(); for (File output : this.generator.getOutputs().getFiles()) { - formatter.formatFiles(getProject().fileTree(output), StandardCharsets.UTF_8) + formatter.formatFiles(this.project.fileTree(output), StandardCharsets.UTF_8) .forEach((edit) -> save(output, edit)); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-antlib/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-antlib/build.gradle index d1cdace201b8..6b4b49a73a54 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-antlib/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-antlib/build.gradle @@ -32,6 +32,7 @@ task syncIntegrationTestSources(type: Sync) { } processResources { + def project = owner.project eachFile { filter { it.replace('${spring-boot.version}', project.version) } }