Dynamically populate repositories used in Ant/Maven integration tests
Update build scripts and tests so that repository settings are copied dynamically from the build. See gh-42333
This commit is contained in:
parent
7d8507d186
commit
d44e7c9af2
|
@ -50,6 +50,7 @@ public class ConventionsPlugin implements Plugin<Project> {
|
|||
new KotlinConventions().apply(project);
|
||||
new WarConventions().apply(project);
|
||||
new EclipseConventions().apply(project);
|
||||
RepoistoryTransformersExtension.apply(project);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<String, String> 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<ibiblio name=\"%s\" m2compatible=\"true\" root=\"%s\" />".formatted(indent, name,
|
||||
repository.getUrl()));
|
||||
}
|
||||
});
|
||||
return result.toString();
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
public Transformer<String, String> 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<repository>%n".formatted(indent));
|
||||
xml.append("%s\t<id>%s</id>%n".formatted(indent, repository.getName()));
|
||||
xml.append("%s\t<url>%s</url>%n".formatted(indent, repository.getUrl()));
|
||||
xml.append("%s\t<releases>%n".formatted(indent));
|
||||
xml.append("%s\t\t<enabled>%s</enabled>%n".formatted(indent, !snapshots));
|
||||
xml.append("%s\t</releases>%n".formatted(indent));
|
||||
xml.append("%s\t<snapshots>%n".formatted(indent));
|
||||
xml.append("%s\t\t<enabled>%s</enabled>%n".formatted(indent, snapshots));
|
||||
xml.append("%s\t</snapshots>%n".formatted(indent));
|
||||
xml.append("%s</repository>".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);
|
||||
}
|
||||
|
||||
}
|
|
@ -28,6 +28,7 @@ dependencies {
|
|||
task copyIntegrationTestSources(type: Copy) {
|
||||
from file("src/it")
|
||||
into "${buildDir}/it"
|
||||
filter(springRepoistoryTransformers.ant())
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
<ivy pattern="${user.home}/.m2/[organisation]/[module]/[revision]/[module]-[revision].pom" />
|
||||
</filesystem>
|
||||
<ibiblio name="ibiblio" m2compatible="true" />
|
||||
<ibiblio name="spring-milestones" m2compatible="true" root="https://repo.spring.io/milestone" />
|
||||
<ibiblio name="spring-snapshots" m2compatible="true" root="https://repo.spring.io/snapshot" />
|
||||
<!-- {spring.mavenRepositories} -->
|
||||
</chain>
|
||||
</resolvers>
|
||||
</ivysettings>
|
||||
|
|
@ -99,12 +99,18 @@ syncDocumentationSourceForAsciidoctor {
|
|||
}
|
||||
}
|
||||
|
||||
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")
|
||||
|
|
|
@ -160,7 +160,7 @@ class MavenBuild {
|
|||
}
|
||||
|
||||
});
|
||||
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);
|
||||
|
|
|
@ -18,19 +18,7 @@
|
|||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<!-- {spring.mavenRepositories} -->
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
|
@ -43,11 +31,7 @@
|
|||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
</pluginRepository>
|
||||
<!-- {spring.mavenRepositories} -->
|
||||
</pluginRepositories>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
|
|
@ -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" ]
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
</target>
|
||||
|
||||
<target name="compile" depends="init" description="compile">
|
||||
<javac srcdir="src/main/java" destdir="build/ant/classes" classpathref="compile.classpath" fork="true" includeantruntime="false" source="8" target="8" compiler="javac1.8"/>
|
||||
<javac srcdir="${projectDir}/src/main/java" destdir="build/ant/classes" classpathref="compile.classpath" fork="true" includeantruntime="false" source="8" target="8" compiler="javac1.8"/>
|
||||
</target>
|
||||
|
||||
<target name="clean" description="cleans all created files/dirs">
|
||||
|
|
|
@ -9,8 +9,7 @@
|
|||
<ivy pattern="${projectDir}/build/test-repository/[organisation]/[module]/[revision]/[module]-[revision].pom" />
|
||||
</filesystem>
|
||||
<ibiblio name="ibiblio" m2compatible="true" />
|
||||
<ibiblio name="spring-milestones" m2compatible="true" root="https://repo.spring.io/milestone" />
|
||||
<ibiblio name="spring-snapshots" m2compatible="true" root="https://repo.spring.io/snapshot" />
|
||||
<!-- {spring.mavenRepositories} -->
|
||||
</chain>
|
||||
</resolvers>
|
||||
</ivysettings>
|
||||
|
|
Loading…
Reference in New Issue