Skip to content

Commit bc5a718

Browse files
committed
Merge branch '3.3.x'
2 parents 21901d6 + 3b8ae47 commit bc5a718

File tree

12 files changed

+163
-101
lines changed

12 files changed

+163
-101
lines changed

buildSrc/src/main/java/org/springframework/boot/build/ConventionsPlugin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public void apply(Project project) {
5050
new KotlinConventions().apply(project);
5151
new WarConventions().apply(project);
5252
new EclipseConventions().apply(project);
53+
RepoistoryTransformersExtension.apply(project);
5354
}
5455

5556
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright 2024-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.build;
18+
19+
import javax.inject.Inject;
20+
21+
import org.gradle.api.Project;
22+
import org.gradle.api.Transformer;
23+
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
24+
25+
/**
26+
* Extension to add {@code springRepoistoryTransformers} utility methods.
27+
*
28+
* @author Phillip Webb
29+
*/
30+
public class RepoistoryTransformersExtension {
31+
32+
private static final String MARKER = "{spring.mavenRepositories}";
33+
34+
private final Project project;
35+
36+
@Inject
37+
public RepoistoryTransformersExtension(Project project) {
38+
this.project = project;
39+
}
40+
41+
public Transformer<String, String> ant() {
42+
return this::transformAnt;
43+
}
44+
45+
private String transformAnt(String line) {
46+
if (line.contains(MARKER)) {
47+
StringBuilder result = new StringBuilder();
48+
String indent = getIndent(line);
49+
this.project.getRepositories().withType(MavenArtifactRepository.class, (repository) -> {
50+
String name = repository.getName();
51+
if (name.startsWith("spring-")) {
52+
result.append(!result.isEmpty() ? "\n" : "");
53+
result.append("%s<ibiblio name=\"%s\" m2compatible=\"true\" root=\"%s\" />".formatted(indent, name,
54+
repository.getUrl()));
55+
}
56+
});
57+
return result.toString();
58+
}
59+
return line;
60+
}
61+
62+
public Transformer<String, String> mavenSettings() {
63+
return this::transformMavenSettings;
64+
}
65+
66+
private String transformMavenSettings(String line) {
67+
if (line.contains(MARKER)) {
68+
StringBuilder result = new StringBuilder();
69+
String indent = getIndent(line);
70+
this.project.getRepositories().withType(MavenArtifactRepository.class, (repository) -> {
71+
String name = repository.getName();
72+
if (name.startsWith("spring-")) {
73+
result.append(!result.isEmpty() ? "\n" : "");
74+
result.append(mavenRepositoryXml(indent, repository));
75+
}
76+
});
77+
return result.toString();
78+
}
79+
return line;
80+
}
81+
82+
private String mavenRepositoryXml(String indent, MavenArtifactRepository repository) {
83+
boolean snapshots = repository.getName().endsWith("-snapshot");
84+
StringBuilder xml = new StringBuilder();
85+
xml.append("%s<repository>%n".formatted(indent));
86+
xml.append("%s\t<id>%s</id>%n".formatted(indent, repository.getName()));
87+
xml.append("%s\t<url>%s</url>%n".formatted(indent, repository.getUrl()));
88+
xml.append("%s\t<releases>%n".formatted(indent));
89+
xml.append("%s\t\t<enabled>%s</enabled>%n".formatted(indent, !snapshots));
90+
xml.append("%s\t</releases>%n".formatted(indent));
91+
xml.append("%s\t<snapshots>%n".formatted(indent));
92+
xml.append("%s\t\t<enabled>%s</enabled>%n".formatted(indent, snapshots));
93+
xml.append("%s\t</snapshots>%n".formatted(indent));
94+
xml.append("%s</repository>".formatted(indent));
95+
return xml.toString();
96+
}
97+
98+
private String getIndent(String line) {
99+
return line.substring(0, line.length() - line.stripLeading().length());
100+
}
101+
102+
static void apply(Project project) {
103+
project.getExtensions().create("springRepoistoryTransformers", RepoistoryTransformersExtension.class, project);
104+
}
105+
106+
}

spring-boot-project/spring-boot-tools/spring-boot-antlib/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dependencies {
2828
task copyIntegrationTestSources(type: Copy) {
2929
from file("src/it")
3030
into "${buildDir}/it"
31+
filter(springRepoistoryTransformers.ant())
3132
}
3233

3334
processResources {

spring-boot-project/spring-boot-tools/spring-boot-antlib/src/it/sample/ivysettings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<ivy pattern="${user.home}/.m2/[organisation]/[module]/[revision]/[module]-[revision].pom" />
99
</filesystem>
1010
<ibiblio name="ibiblio" m2compatible="true" />
11-
<ibiblio name="spring-milestones" m2compatible="true" root="https://repo.spring.io/milestone" />
12-
<ibiblio name="spring-snapshots" m2compatible="true" root="https://repo.spring.io/snapshot" />
11+
<!-- {spring.mavenRepositories} -->
1312
</chain>
1413
</resolvers>
1514
</ivysettings>
15+
Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
<settings>
2-
<localRepository>../../../../build/local-m2-repository</localRepository>
3-
<profiles>
4-
<profile>
5-
<id>cli-test-repo</id>
6-
<activation>
7-
<activeByDefault>true</activeByDefault>
8-
</activation>
9-
<repositories>
10-
<repository>
11-
<id>local.central</id>
12-
<url>file:../../../../build/test-repository</url>
13-
<releases>
14-
<enabled>true</enabled>
15-
</releases>
16-
<snapshots>
17-
<enabled>true</enabled>
18-
</snapshots>
19-
</repository>
20-
<repository>
21-
<id>thymeleaf-snapshot</id>
22-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
23-
<releases>
24-
<enabled>true</enabled>
25-
</releases>
26-
<snapshots>
27-
<enabled>true</enabled>
28-
</snapshots>
29-
</repository>
30-
</repositories>
31-
</profile>
32-
</profiles>
2+
<localRepository>../../../../build/local-m2-repository
3+
</localRepository>
4+
<profiles>
5+
<profile>
6+
<id>cli-test-repo</id>
7+
<activation>
8+
<activeByDefault>true</activeByDefault>
9+
</activation>
10+
<repositories>
11+
<repository>
12+
<id>local.central</id>
13+
<url>file:../../../../build/test-repository</url>
14+
<releases>
15+
<enabled>true</enabled>
16+
</releases>
17+
<snapshots>
18+
<enabled>true</enabled>
19+
</snapshots>
20+
</repository>
21+
<repository>
22+
<id>thymeleaf-snapshot</id>
23+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
24+
<releases>
25+
<enabled>true</enabled>
26+
</releases>
27+
<snapshots>
28+
<enabled>true</enabled>
29+
</snapshots>
30+
</repository>
31+
</repositories>
32+
</profile>
33+
</profiles>
3334
</settings>

spring-boot-project/spring-boot-tools/spring-boot-cli/src/test/resources/cli-tester/.m2/settings.xml

Lines changed: 0 additions & 44 deletions
This file was deleted.

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,18 @@ ext {
9191
xsdVersion = versionElements[0] + "." + versionElements[1]
9292
}
9393

94+
task copySettingsXml(type: Copy) {
95+
from file("src/intTest/projects/settings.xml")
96+
into "${buildDir}/generated-resources/settings"
97+
filter(springRepoistoryTransformers.mavenSettings())
98+
}
99+
94100
sourceSets {
95101
main {
96102
output.dir("${buildDir}/generated/resources/xsd", builtBy: "xsdResources")
97103
}
98104
intTest {
99-
output.dir("${buildDir}/generated-resources", builtBy: "extractVersionProperties")
105+
output.dir("${buildDir}/generated-resources", builtBy: ["extractVersionProperties", "copySettingsXml"])
100106
}
101107
dockerTest {
102108
output.dir("${buildDir}/generated-resources", builtBy: "extractVersionProperties")

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/MavenBuild.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
160160
}
161161

162162
});
163-
String settingsXml = Files.readString(Paths.get("src", "intTest", "projects", "settings.xml"))
163+
String settingsXml = Files.readString(Paths.get("build", "generated-resources", "settings", "settings.xml"))
164164
.replace("@localCentralUrl@", new File("build/test-maven-repository").toURI().toURL().toString())
165165
.replace("@localRepositoryPath@", new File("build/local-maven-repository").getAbsolutePath());
166166
Files.writeString(destination.resolve("settings.xml"), settingsXml, StandardOpenOption.CREATE_NEW);

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/settings.xml

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,7 @@
1818
<enabled>true</enabled>
1919
</snapshots>
2020
</repository>
21-
<repository>
22-
<id>spring-milestones</id>
23-
<name>Spring Milestones</name>
24-
<url>https://repo.spring.io/milestone</url>
25-
</repository>
26-
<repository>
27-
<id>spring-snapshots</id>
28-
<name>Spring Snapshots</name>
29-
<url>https://repo.spring.io/snapshot</url>
30-
<snapshots>
31-
<enabled>true</enabled>
32-
</snapshots>
33-
</repository>
21+
<!-- {spring.mavenRepositories} -->
3422
</repositories>
3523
<pluginRepositories>
3624
<pluginRepository>
@@ -43,11 +31,7 @@
4331
<enabled>true</enabled>
4432
</snapshots>
4533
</pluginRepository>
46-
<pluginRepository>
47-
<id>spring-milestones</id>
48-
<name>Spring Milestones</name>
49-
<url>https://repo.spring.io/milestone</url>
50-
</pluginRepository>
34+
<!-- {spring.mavenRepositories} -->
5135
</pluginRepositories>
5236
</profile>
5337
</profiles>

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ task syncTestRepository(type: Sync) {
4646
}
4747
}
4848

49+
task copyAntSources(type: Copy) {
50+
from project.layout.projectDirectory
51+
include "*.xml"
52+
into "${buildDir}/antbuild"
53+
filter(springRepoistoryTransformers.ant())
54+
}
55+
4956
task antRun(type: JavaExec) {
50-
dependsOn syncTestRepository, configurations.antDependencies
57+
workingDir "${buildDir}/antbuild"
58+
dependsOn syncTestRepository, copyAntSources, configurations.antDependencies
5159
classpath = configurations.antDependencies;
5260
mainClass = "org.apache.tools.ant.launch.Launcher"
5361
args = [ "clean", "build" ]

0 commit comments

Comments
 (0)