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 8b4769be00e0..1d0b5546d05c 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/ConventionsPlugin.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/ConventionsPlugin.java @@ -50,6 +50,7 @@ public void apply(Project project) { new KotlinConventions().apply(project); new WarConventions().apply(project); new EclipseConventions().apply(project); + RepoistoryTransformersExtension.apply(project); } } diff --git a/buildSrc/src/main/java/org/springframework/boot/build/RepoistoryTransformersExtension.java b/buildSrc/src/main/java/org/springframework/boot/build/RepoistoryTransformersExtension.java new file mode 100644 index 000000000000..72b698f83fb7 --- /dev/null +++ b/buildSrc/src/main/java/org/springframework/boot/build/RepoistoryTransformersExtension.java @@ -0,0 +1,106 @@ +/* + * Copyright 2024-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.build; + +import javax.inject.Inject; + +import org.gradle.api.Project; +import org.gradle.api.Transformer; +import org.gradle.api.artifacts.repositories.MavenArtifactRepository; + +/** + * Extension to add {@code springRepoistoryTransformers} utility methods. + * + * @author Phillip Webb + */ +public class RepoistoryTransformersExtension { + + private static final String MARKER = "{spring.mavenRepositories}"; + + private final Project project; + + @Inject + public RepoistoryTransformersExtension(Project project) { + this.project = project; + } + + public Transformer ant() { + return this::transformAnt; + } + + private String transformAnt(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("%s".formatted(indent, name, + repository.getUrl())); + } + }); + return result.toString(); + } + return line; + } + + public Transformer mavenSettings() { + return this::transformMavenSettings; + } + + 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 line; + } + + private String mavenRepositoryXml(String indent, MavenArtifactRepository repository) { + boolean snapshots = repository.getName().endsWith("-snapshot"); + StringBuilder xml = new StringBuilder(); + xml.append("%s%n".formatted(indent)); + 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)); + xml.append("%s\t\t%s%n".formatted(indent, !snapshots)); + xml.append("%s\t%n".formatted(indent)); + 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)); + return xml.toString(); + } + + private String getIndent(String line) { + return line.substring(0, line.length() - line.stripLeading().length()); + } + + static void apply(Project project) { + project.getExtensions().create("springRepoistoryTransformers", RepoistoryTransformersExtension.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 3fa066c2c688..83dd9f4d49fa 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,6 +28,7 @@ dependencies { task copyIntegrationTestSources(type: Copy) { from file("src/it") into "${buildDir}/it" + filter(springRepoistoryTransformers.ant()) } processResources { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-antlib/src/it/sample/ivysettings.xml b/spring-boot-project/spring-boot-tools/spring-boot-antlib/src/it/sample/ivysettings.xml index 67038fba9074..2d04a1ad21bd 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-antlib/src/it/sample/ivysettings.xml +++ b/spring-boot-project/spring-boot-tools/spring-boot-antlib/src/it/sample/ivysettings.xml @@ -8,8 +8,8 @@ - - + + \ No newline at end of file diff --git a/spring-boot-project/spring-boot-tools/spring-boot-cli/src/intTest/resources/settings.xml b/spring-boot-project/spring-boot-tools/spring-boot-cli/src/intTest/resources/settings.xml index b85b5c25ffd5..4e7332c0f77d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-cli/src/intTest/resources/settings.xml +++ b/spring-boot-project/spring-boot-tools/spring-boot-cli/src/intTest/resources/settings.xml @@ -1,33 +1,34 @@ - ../../../../build/local-m2-repository - - - cli-test-repo - - true - - - - local.central - file:../../../../build/test-repository - - true - - - true - - - - thymeleaf-snapshot - https://oss.sonatype.org/content/repositories/snapshots - - true - - - true - - - - - + ../../../../build/local-m2-repository + + + + cli-test-repo + + true + + + + local.central + file:../../../../build/test-repository + + true + + + true + + + + thymeleaf-snapshot + https://oss.sonatype.org/content/repositories/snapshots + + true + + + true + + + + + diff --git a/spring-boot-project/spring-boot-tools/spring-boot-cli/src/test/resources/cli-tester/.m2/settings.xml b/spring-boot-project/spring-boot-tools/spring-boot-cli/src/test/resources/cli-tester/.m2/settings.xml deleted file mode 100644 index 504eb80a0555..000000000000 --- a/spring-boot-project/spring-boot-tools/spring-boot-cli/src/test/resources/cli-tester/.m2/settings.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - build/local-m2-repository - - - cli-test-repo - - true - - - - local.central - file:build/test-repository - - true - - - true - - - - spring-snapshot - https://repo.spring.io/snapshot - - false - - - true - - - - spring-milestone - https://repo.spring.io/milestone - - true - - - false - - - - - - 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 a3e6fa6ade7a..7ef5f1fc0c83 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 @@ -91,12 +91,18 @@ ext { xsdVersion = versionElements[0] + "." + versionElements[1] } +task copySettingsXml(type: Copy) { + from file("src/intTest/projects/settings.xml") + into "${buildDir}/generated-resources/settings" + filter(springRepoistoryTransformers.mavenSettings()) +} + sourceSets { main { output.dir("${buildDir}/generated/resources/xsd", builtBy: "xsdResources") } intTest { - output.dir("${buildDir}/generated-resources", builtBy: "extractVersionProperties") + output.dir("${buildDir}/generated-resources", builtBy: ["extractVersionProperties", "copySettingsXml"]) } dockerTest { output.dir("${buildDir}/generated-resources", builtBy: "extractVersionProperties") diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/MavenBuild.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/MavenBuild.java index 0c64502f236c..7393ef9233d4 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/MavenBuild.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/MavenBuild.java @@ -160,7 +160,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO } }); - String settingsXml = Files.readString(Paths.get("src", "intTest", "projects", "settings.xml")) + String settingsXml = Files.readString(Paths.get("build", "generated-resources", "settings", "settings.xml")) .replace("@localCentralUrl@", new File("build/test-maven-repository").toURI().toURL().toString()) .replace("@localRepositoryPath@", new File("build/local-maven-repository").getAbsolutePath()); Files.writeString(destination.resolve("settings.xml"), settingsXml, StandardOpenOption.CREATE_NEW); 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 e4aacb2648a7..500915763c48 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 @@ -18,19 +18,7 @@ true - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/snapshot - - true - - + @@ -43,11 +31,7 @@ true - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - + 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 a6cff1142b39..b98082d048da 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 @@ -46,8 +46,16 @@ task syncTestRepository(type: Sync) { } } +task copyAntSources(type: Copy) { + from project.layout.projectDirectory + include "*.xml" + into "${buildDir}/antbuild" + filter(springRepoistoryTransformers.ant()) +} + task antRun(type: JavaExec) { - dependsOn syncTestRepository, configurations.antDependencies + workingDir "${buildDir}/antbuild" + dependsOn syncTestRepository, copyAntSources, configurations.antDependencies classpath = configurations.antDependencies; mainClass = "org.apache.tools.ant.launch.Launcher" args = [ "clean", "build" ] diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.xml b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.xml index a03067231cef..644c07ef6134 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.xml +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.xml @@ -33,7 +33,7 @@ - + diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/ivysettings.xml b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/ivysettings.xml index 50eb4fcb7d1a..51cf26e3633e 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/ivysettings.xml +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/ivysettings.xml @@ -9,8 +9,7 @@ - - +