From b0dd42e9b9fc8304a26c11db6e66d5856c9049fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Tue, 15 Oct 2024 10:39:59 +0200 Subject: [PATCH] Transform Maven settings with proper plugin repository tag This commit adapts d44e7c9 to transforms plugin repositories using the correct root tag. Previously, they were transformed with the regular tag, which is invalid. Closes gh-42687 --- .../boot/build/ConventionsPlugin.java | 2 +- ...a => RepositoryTransformersExtension.java} | 44 ++++++++++++------- .../spring-boot-antlib/build.gradle | 2 +- .../spring-boot-maven-plugin/build.gradle | 2 +- .../src/intTest/projects/settings.xml | 2 +- .../spring-boot-smoke-test-ant/build.gradle | 2 +- 6 files changed, 32 insertions(+), 22 deletions(-) rename buildSrc/src/main/java/org/springframework/boot/build/{RepoistoryTransformersExtension.java => RepositoryTransformersExtension.java} (69%) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/ConventionsPlugin.java b/buildSrc/src/main/java/org/springframework/boot/build/ConventionsPlugin.java index 474a93e5c4..5d3850a012 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/ConventionsPlugin.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/ConventionsPlugin.java @@ -50,7 +50,7 @@ public class ConventionsPlugin implements Plugin { new KotlinConventions().apply(project); new WarConventions().apply(project); new EclipseConventions().apply(project); - RepoistoryTransformersExtension.apply(project); + RepositoryTransformersExtension.apply(project); } } diff --git a/buildSrc/src/main/java/org/springframework/boot/build/RepoistoryTransformersExtension.java b/buildSrc/src/main/java/org/springframework/boot/build/RepositoryTransformersExtension.java similarity index 69% rename from buildSrc/src/main/java/org/springframework/boot/build/RepoistoryTransformersExtension.java rename to buildSrc/src/main/java/org/springframework/boot/build/RepositoryTransformersExtension.java index 72b698f83f..982594f426 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/RepoistoryTransformersExtension.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/RepositoryTransformersExtension.java @@ -23,18 +23,20 @@ import org.gradle.api.Transformer; import org.gradle.api.artifacts.repositories.MavenArtifactRepository; /** - * Extension to add {@code springRepoistoryTransformers} utility methods. + * Extension to add {@code springRepositoryTransformers} utility methods. * * @author Phillip Webb */ -public class RepoistoryTransformersExtension { +public class RepositoryTransformersExtension { private static final String MARKER = "{spring.mavenRepositories}"; + private static final String MARKER_PLUGIN = "{spring.mavenPluginRepositories}"; + private final Project project; @Inject - public RepoistoryTransformersExtension(Project project) { + public RepositoryTransformersExtension(Project project) { this.project = project; } @@ -65,24 +67,32 @@ public class RepoistoryTransformersExtension { private String transformMavenSettings(String line) { if (line.contains(MARKER)) { - StringBuilder result = new StringBuilder(); - String indent = getIndent(line); - this.project.getRepositories().withType(MavenArtifactRepository.class, (repository) -> { - String name = repository.getName(); - if (name.startsWith("spring-")) { - result.append(!result.isEmpty() ? "\n" : ""); - result.append(mavenRepositoryXml(indent, repository)); - } - }); - return result.toString(); + return transformMarker(line, false); + } + if (line.contains(MARKER_PLUGIN)) { + return transformMarker(line, true); } return line; } - private String mavenRepositoryXml(String indent, MavenArtifactRepository repository) { + private String transformMarker(String line, boolean pluginRepository) { + StringBuilder result = new StringBuilder(); + String indent = getIndent(line); + this.project.getRepositories().withType(MavenArtifactRepository.class, (repository) -> { + String name = repository.getName(); + if (name.startsWith("spring-")) { + result.append(!result.isEmpty() ? "\n" : ""); + result.append(mavenRepositoryXml(indent, repository, pluginRepository)); + } + }); + return result.toString(); + } + + private String mavenRepositoryXml(String indent, MavenArtifactRepository repository, boolean pluginRepository) { + String rootTag = pluginRepository ? "pluginRepository" : "repository"; boolean snapshots = repository.getName().endsWith("-snapshot"); StringBuilder xml = new StringBuilder(); - xml.append("%s%n".formatted(indent)); + xml.append("%s<%s>%n".formatted(indent, rootTag)); xml.append("%s\t%s%n".formatted(indent, repository.getName())); xml.append("%s\t%s%n".formatted(indent, repository.getUrl())); xml.append("%s\t%n".formatted(indent)); @@ -91,7 +101,7 @@ public class RepoistoryTransformersExtension { xml.append("%s\t%n".formatted(indent)); xml.append("%s\t\t%s%n".formatted(indent, snapshots)); xml.append("%s\t%n".formatted(indent)); - xml.append("%s".formatted(indent)); + xml.append("%s".formatted(indent, rootTag)); return xml.toString(); } @@ -100,7 +110,7 @@ public class RepoistoryTransformersExtension { } static void apply(Project project) { - project.getExtensions().create("springRepoistoryTransformers", RepoistoryTransformersExtension.class, project); + project.getExtensions().create("springRepositoryTransformers", RepositoryTransformersExtension.class, project); } } 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 6de24ffc04..f59b35f355 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 @@ -28,7 +28,7 @@ dependencies { task syncIntegrationTestSources(type: Sync) { destinationDir file("${buildDir}/it") from file("src/it") - filter(springRepoistoryTransformers.ant()) + filter(springRepositoryTransformers.ant()) } processResources { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle index 576e487316..0aabdb7f1f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle @@ -102,7 +102,7 @@ syncDocumentationSourceForAsciidoctor { task copySettingsXml(type: Copy) { from file("src/intTest/projects/settings.xml") into "${buildDir}/generated-resources/settings" - filter(springRepoistoryTransformers.mavenSettings()) + filter(springRepositoryTransformers.mavenSettings()) } sourceSets { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/settings.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/settings.xml index 500915763c..527bb28dd2 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/settings.xml +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/settings.xml @@ -31,7 +31,7 @@ true - + diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.gradle index dc11df6ccd..5e1fd73fd4 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.gradle @@ -50,7 +50,7 @@ task syncAntSources(type: Sync) { destinationDir file("${buildDir}/ant") from project.layout.projectDirectory include "*.xml" - filter(springRepoistoryTransformers.ant()) + filter(springRepositoryTransformers.ant()) } task antRun(type: JavaExec) {