Browse Source

Merge branch '3.3.x'

pull/42406/head
Phillip Webb 1 year ago
parent
commit
c7c73be859
  1. 72
      buildSrc/src/main/java/org/springframework/boot/build/bom/BomExtension.java
  2. 3
      buildSrc/src/main/java/org/springframework/boot/build/bom/BomPlugin.java
  3. 45
      buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/MavenMetadataVersionResolver.java
  4. 57
      buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/MoveToSnapshots.java
  5. 28
      buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeBom.java
  6. 34
      buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeDependencies.java
  7. 88
      buildSrc/src/main/java/org/springframework/boot/build/properties/BuildProperties.java
  8. 36
      buildSrc/src/main/java/org/springframework/boot/build/properties/BuildType.java
  9. 37
      buildSrc/src/main/java/org/springframework/boot/build/repository/RepositoryUrl.java
  10. 105
      buildSrc/src/main/java/org/springframework/boot/build/repository/SpringRepository.java

72
buildSrc/src/main/java/org/springframework/boot/build/bom/BomExtension.java

@ -66,6 +66,7 @@ import org.springframework.boot.build.bom.Library.ProhibitedVersion; @@ -66,6 +66,7 @@ import org.springframework.boot.build.bom.Library.ProhibitedVersion;
import org.springframework.boot.build.bom.Library.VersionAlignment;
import org.springframework.boot.build.bom.bomr.version.DependencyVersion;
import org.springframework.boot.build.mavenplugin.MavenExec;
import org.springframework.boot.build.properties.BuildProperties;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.PropertyPlaceholderHelper;
import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver;
@ -78,22 +79,19 @@ import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver; @@ -78,22 +79,19 @@ import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver;
*/
public class BomExtension {
private final Project project;
private final UpgradeHandler upgradeHandler;
private final Map<String, DependencyVersion> properties = new LinkedHashMap<>();
private final Map<String, String> artifactVersionProperties = new HashMap<>();
private final List<Library> libraries = new ArrayList<>();
private final UpgradeHandler upgradeHandler;
private final DependencyHandler dependencyHandler;
private final Project project;
public BomExtension(DependencyHandler dependencyHandler, Project project) {
this.dependencyHandler = dependencyHandler;
this.upgradeHandler = project.getObjects().newInstance(UpgradeHandler.class);
public BomExtension(Project project) {
this.project = project;
this.upgradeHandler = project.getObjects().newInstance(UpgradeHandler.class, project);
}
public List<Library> getLibraries() {
@ -105,8 +103,9 @@ public class BomExtension { @@ -105,8 +103,9 @@ public class BomExtension {
}
public Upgrade getUpgrade() {
return new Upgrade(this.upgradeHandler.upgradePolicy, new GitHub(this.upgradeHandler.gitHub.organization,
this.upgradeHandler.gitHub.repository, this.upgradeHandler.gitHub.issueLabels));
GitHubHandler gitHub = this.upgradeHandler.gitHub;
return new Upgrade(this.upgradeHandler.upgradePolicy,
new GitHub(gitHub.organization, gitHub.repository, gitHub.issueLabels));
}
public void library(String name, Action<LibraryHandler> action) {
@ -196,6 +195,7 @@ public class BomExtension { @@ -196,6 +195,7 @@ public class BomExtension {
}
private void addLibrary(Library library) {
DependencyHandler dependencies = this.project.getDependencies();
this.libraries.add(library);
String versionProperty = library.getVersionProperty();
if (versionProperty != null) {
@ -203,23 +203,30 @@ public class BomExtension { @@ -203,23 +203,30 @@ public class BomExtension {
}
for (Group group : library.getGroups()) {
for (Module module : group.getModules()) {
putArtifactVersionProperty(group.getId(), module.getName(), module.getClassifier(), versionProperty);
this.dependencyHandler.getConstraints()
.add(JavaPlatformPlugin.API_CONFIGURATION_NAME, createDependencyNotation(group.getId(),
module.getName(), library.getVersion().getVersion()));
addModule(library, dependencies, versionProperty, group, module);
}
for (String bomImport : group.getBoms()) {
putArtifactVersionProperty(group.getId(), bomImport, versionProperty);
String bomDependency = createDependencyNotation(group.getId(), bomImport,
library.getVersion().getVersion());
this.dependencyHandler.add(JavaPlatformPlugin.API_CONFIGURATION_NAME,
this.dependencyHandler.platform(bomDependency));
this.dependencyHandler.add(BomPlugin.API_ENFORCED_CONFIGURATION_NAME,
this.dependencyHandler.enforcedPlatform(bomDependency));
addBomImport(library, dependencies, versionProperty, group, bomImport);
}
}
}
private void addModule(Library library, DependencyHandler dependencies, String versionProperty, Group group,
Module module) {
putArtifactVersionProperty(group.getId(), module.getName(), module.getClassifier(), versionProperty);
String constraint = createDependencyNotation(group.getId(), module.getName(),
library.getVersion().getVersion());
dependencies.getConstraints().add(JavaPlatformPlugin.API_CONFIGURATION_NAME, constraint);
}
private void addBomImport(Library library, DependencyHandler dependencies, String versionProperty, Group group,
String bomImport) {
putArtifactVersionProperty(group.getId(), bomImport, versionProperty);
String bomDependency = createDependencyNotation(group.getId(), bomImport, library.getVersion().getVersion());
dependencies.add(JavaPlatformPlugin.API_CONFIGURATION_NAME, dependencies.platform(bomDependency));
dependencies.add(BomPlugin.API_ENFORCED_CONFIGURATION_NAME, dependencies.enforcedPlatform(bomDependency));
}
public static class LibraryHandler {
private final List<Group> groups = new ArrayList<>();
@ -501,7 +508,12 @@ public class BomExtension { @@ -501,7 +508,12 @@ public class BomExtension {
private UpgradePolicy upgradePolicy;
private final GitHubHandler gitHub = new GitHubHandler();
private final GitHubHandler gitHub;
@Inject
public UpgradeHandler(Project project) {
this.gitHub = new GitHubHandler(project);
}
public void setPolicy(UpgradePolicy upgradePolicy) {
this.upgradePolicy = upgradePolicy;
@ -536,12 +548,18 @@ public class BomExtension { @@ -536,12 +548,18 @@ public class BomExtension {
public static class GitHubHandler {
private String organization = "spring-projects";
private String organization;
private String repository = "spring-boot";
private String repository;
private List<String> issueLabels;
public GitHubHandler(Project project) {
BuildProperties buildProperties = BuildProperties.get(project);
this.organization = buildProperties.gitHub().organization();
this.repository = buildProperties.gitHub().repository();
}
public void setOrganization(String organization) {
this.organization = organization;
}
@ -558,9 +576,9 @@ public class BomExtension { @@ -558,9 +576,9 @@ public class BomExtension {
public static final class GitHub {
private String organization = "spring-projects";
private String organization;
private String repository = "spring-boot";
private String repository;
private final List<String> issueLabels;

3
buildSrc/src/main/java/org/springframework/boot/build/bom/BomPlugin.java

@ -60,8 +60,7 @@ public class BomPlugin implements Plugin<Project> { @@ -60,8 +60,7 @@ public class BomPlugin implements Plugin<Project> {
JavaPlatformExtension javaPlatform = project.getExtensions().getByType(JavaPlatformExtension.class);
javaPlatform.allowDependencies();
createApiEnforcedConfiguration(project);
BomExtension bom = project.getExtensions()
.create("bom", BomExtension.class, project.getDependencies(), project);
BomExtension bom = project.getExtensions().create("bom", BomExtension.class, project);
CheckBom checkBom = project.getTasks().create("bomrCheck", CheckBom.class, bom);
project.getTasks().named("check").configure((check) -> check.dependsOn(checkBom));
project.getTasks().create("bomrUpgrade", UpgradeBom.class, bom);

45
buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/MavenMetadataVersionResolver.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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.
@ -30,11 +30,15 @@ import javax.xml.parsers.DocumentBuilderFactory; @@ -30,11 +30,15 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.springframework.boot.build.bom.bomr.version.DependencyVersion;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.HttpClientErrorException;
@ -50,42 +54,37 @@ final class MavenMetadataVersionResolver implements VersionResolver { @@ -50,42 +54,37 @@ final class MavenMetadataVersionResolver implements VersionResolver {
private final RestTemplate rest;
private final Collection<URI> repositoryUrls;
private final Collection<MavenArtifactRepository> repositories;
MavenMetadataVersionResolver(Collection<URI> repositoryUrls) {
this(new RestTemplate(Collections.singletonList(new StringHttpMessageConverter())), repositoryUrls);
MavenMetadataVersionResolver(Collection<MavenArtifactRepository> repositories) {
this(new RestTemplate(Collections.singletonList(new StringHttpMessageConverter())), repositories);
}
MavenMetadataVersionResolver(RestTemplate restTemplate, Collection<URI> repositoryUrls) {
MavenMetadataVersionResolver(RestTemplate restTemplate, Collection<MavenArtifactRepository> repositories) {
this.rest = restTemplate;
this.repositoryUrls = normalize(repositoryUrls);
}
private Collection<URI> normalize(Collection<URI> uris) {
return uris.stream().map(this::normalize).toList();
}
private URI normalize(URI uri) {
if ("/".equals(uri.getPath())) {
return uri;
}
return URI.create(uri + "/");
this.repositories = repositories;
}
@Override
public SortedSet<DependencyVersion> resolveVersions(String groupId, String artifactId) {
Set<String> versions = new HashSet<>();
for (URI repositoryUrl : this.repositoryUrls) {
versions.addAll(resolveVersions(groupId, artifactId, repositoryUrl));
for (MavenArtifactRepository repository : this.repositories) {
versions.addAll(resolveVersions(groupId, artifactId, repository));
}
return versions.stream().map(DependencyVersion::parse).collect(Collectors.toCollection(TreeSet::new));
}
private Set<String> resolveVersions(String groupId, String artifactId, URI repositoryUrl) {
private Set<String> resolveVersions(String groupId, String artifactId, MavenArtifactRepository repository) {
Set<String> versions = new HashSet<>();
URI url = repositoryUrl.resolve(groupId.replace('.', '/') + "/" + artifactId + "/maven-metadata.xml");
URI url = repository.getUrl().resolve(groupId.replace('.', '/') + "/" + artifactId + "/maven-metadata.xml");
try {
String metadata = this.rest.getForObject(url, String.class);
HttpHeaders headers = new HttpHeaders();
String username = repository.getCredentials().getUsername();
if (username != null) {
headers.setBasicAuth(username, repository.getCredentials().getPassword());
}
HttpEntity<Void> request = new HttpEntity<>(headers);
String metadata = this.rest.exchange(url, HttpMethod.GET, request, String.class).getBody();
Document metadataDocument = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(new InputSource(new StringReader(metadata)));
@ -104,7 +103,7 @@ final class MavenMetadataVersionResolver implements VersionResolver { @@ -104,7 +103,7 @@ final class MavenMetadataVersionResolver implements VersionResolver {
}
catch (Exception ex) {
System.err.println("Failed to resolve versions for module " + groupId + ":" + artifactId + " in repository "
+ repositoryUrl + ": " + ex.getMessage());
+ repository + ": " + ex.getMessage());
}
return versions;
}

57
buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/MoveToSnapshots.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 the original author or authors.
* Copyright 2021-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.
@ -16,8 +16,8 @@ @@ -16,8 +16,8 @@
package org.springframework.boot.build.bom.bomr;
import java.net.URI;
import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.BiPredicate;
@ -34,6 +34,10 @@ import org.springframework.boot.build.bom.Library; @@ -34,6 +34,10 @@ import org.springframework.boot.build.bom.Library;
import org.springframework.boot.build.bom.bomr.ReleaseSchedule.Release;
import org.springframework.boot.build.bom.bomr.github.Milestone;
import org.springframework.boot.build.bom.bomr.version.DependencyVersion;
import org.springframework.boot.build.properties.BuildProperties;
import org.springframework.boot.build.properties.BuildType;
import org.springframework.boot.build.repository.SpringRepository;
import org.springframework.boot.build.repository.SpringRepository.RepositoryType;
/**
* A {@link Task} to move to snapshot dependencies.
@ -44,12 +48,20 @@ public abstract class MoveToSnapshots extends UpgradeDependencies { @@ -44,12 +48,20 @@ public abstract class MoveToSnapshots extends UpgradeDependencies {
private static final Logger log = LoggerFactory.getLogger(MoveToSnapshots.class);
private final URI REPOSITORY_URI = URI.create("https://repo.spring.io/snapshot/");
@Inject
public MoveToSnapshots(BomExtension bom) {
super(bom, true);
getRepositoryUris().add(this.REPOSITORY_URI);
BuildType buildType = BuildProperties.get(this).buildType();
getRepositoryNames().addAll(getSnapshotRepositoryNames(buildType));
}
public static List<String> getSnapshotRepositoryNames(BuildType buildType) {
return Arrays.stream(SpringRepository.values())
.filter((repository) -> repository.getRepositoryType() == RepositoryType.SNAPSHOT)
.filter((repository) -> repository.getBuildType() == BuildType.OPEN_SOURCE
|| repository.getBuildType() == buildType)
.map(SpringRepository::getName)
.toList();
}
@Override
@ -83,26 +95,31 @@ public abstract class MoveToSnapshots extends UpgradeDependencies { @@ -83,26 +95,31 @@ public abstract class MoveToSnapshots extends UpgradeDependencies {
@Override
protected List<BiPredicate<Library, DependencyVersion>> determineUpdatePredicates(Milestone milestone) {
ReleaseSchedule releaseSchedule = new ReleaseSchedule();
Map<String, List<Release>> releases = releaseSchedule.releasesBetween(OffsetDateTime.now(),
milestone.getDueOn());
return switch (BuildProperties.get(this).buildType()) {
case OPEN_SOURCE -> determineOpenSourceUpdatePredicates(milestone);
case COMMERCIAL -> super.determineUpdatePredicates(milestone);
};
}
private List<BiPredicate<Library, DependencyVersion>> determineOpenSourceUpdatePredicates(Milestone milestone) {
Map<String, List<Release>> scheduledReleases = getScheduledOpenSourceReleases(milestone);
List<BiPredicate<Library, DependencyVersion>> predicates = super.determineUpdatePredicates(milestone);
predicates.add((library, candidate) -> {
List<Release> releasesForLibrary = releases.get(library.getCalendarName());
if (releasesForLibrary != null) {
for (Release release : releasesForLibrary) {
if (candidate.isSnapshotFor(release.getVersion())) {
return true;
}
}
}
if (log.isInfoEnabled()) {
log.info("Ignoring " + candidate + ". No release of " + library.getName() + " scheduled before "
+ milestone.getDueOn());
List<Release> releases = scheduledReleases.get(library.getCalendarName());
boolean match = (releases != null)
&& releases.stream().anyMatch((release) -> candidate.isSnapshotFor(release.getVersion()));
if (log.isInfoEnabled() && !match) {
log.info("Ignoring {}. No release of {} scheduled before {}", candidate, library.getName(),
milestone.getDueOn());
}
return false;
return match;
});
return predicates;
}
private Map<String, List<Release>> getScheduledOpenSourceReleases(Milestone milestone) {
ReleaseSchedule releaseSchedule = new ReleaseSchedule();
return releaseSchedule.releasesBetween(OffsetDateTime.now(), milestone.getDueOn());
}
}

28
buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeBom.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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.
@ -16,14 +16,15 @@ @@ -16,14 +16,15 @@
package org.springframework.boot.build.bom.bomr;
import java.net.URI;
import javax.inject.Inject;
import org.gradle.api.Task;
import org.gradle.api.artifacts.ArtifactRepositoryContainer;
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
import org.springframework.boot.build.bom.BomExtension;
import org.springframework.boot.build.properties.BuildProperties;
import org.springframework.boot.build.repository.SpringRepository;
/**
* {@link Task} to upgrade the libraries managed by a bom.
@ -36,14 +37,29 @@ public abstract class UpgradeBom extends UpgradeDependencies { @@ -36,14 +37,29 @@ public abstract class UpgradeBom extends UpgradeDependencies {
@Inject
public UpgradeBom(BomExtension bom) {
super(bom);
switch (BuildProperties.get(this).buildType()) {
case OPEN_SOURCE -> addOpenSourceRepositories();
case COMMERCIAL -> addCommercialRepositories();
}
}
private void addOpenSourceRepositories() {
getProject().getRepositories().withType(MavenArtifactRepository.class, (repository) -> {
URI repositoryUrl = repository.getUrl();
if (!repositoryUrl.toString().endsWith("snapshot")) {
getRepositoryUris().add(repositoryUrl);
if (!isSnaphotRepository(repository)) {
getRepositoryNames().add(repository.getName());
}
});
}
private void addCommercialRepositories() {
getRepositoryNames().addAll(ArtifactRepositoryContainer.DEFAULT_MAVEN_CENTRAL_REPO_NAME,
SpringRepository.COMMERCIAL_RELEASE.getName());
}
private boolean isSnaphotRepository(MavenArtifactRepository repository) {
return repository.getUrl().toString().endsWith("snapshot");
}
@Override
protected String issueTitle(Upgrade upgrade) {
return "Upgrade to " + upgrade.getLibrary().getName() + " " + upgrade.getVersion();

34
buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeDependencies.java

@ -20,10 +20,10 @@ import java.io.File; @@ -20,10 +20,10 @@ import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.net.URI;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Properties;
import java.util.Set;
@ -35,6 +35,7 @@ import javax.inject.Inject; @@ -35,6 +35,7 @@ import javax.inject.Inject;
import org.gradle.api.DefaultTask;
import org.gradle.api.InvalidUserDataException;
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
import org.gradle.api.internal.tasks.userinput.UserInputHandler;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.Property;
@ -54,7 +55,7 @@ import org.springframework.boot.build.bom.bomr.version.DependencyVersion; @@ -54,7 +55,7 @@ import org.springframework.boot.build.bom.bomr.version.DependencyVersion;
import org.springframework.util.StringUtils;
/**
* Base class for tasks that upgrade dependencies in a bom.
* Base class for tasks that upgrade dependencies in a BOM.
*
* @author Andy Wilkinson
* @author Moritz Halbritter
@ -91,7 +92,7 @@ public abstract class UpgradeDependencies extends DefaultTask { @@ -91,7 +92,7 @@ public abstract class UpgradeDependencies extends DefaultTask {
public abstract Property<String> getLibraries();
@Input
abstract ListProperty<URI> getRepositoryUris();
abstract ListProperty<String> getRepositoryNames();
@TaskAction
void upgradeDependencies() {
@ -217,12 +218,27 @@ public abstract class UpgradeDependencies extends DefaultTask { @@ -217,12 +218,27 @@ public abstract class UpgradeDependencies extends DefaultTask {
@SuppressWarnings("deprecation")
private List<Upgrade> resolveUpgrades(Milestone milestone) {
List<Upgrade> upgrades = new InteractiveUpgradeResolver(getServices().get(UserInputHandler.class),
new MultithreadedLibraryUpdateResolver(getThreads().get(),
new StandardLibraryUpdateResolver(new MavenMetadataVersionResolver(getRepositoryUris().get()),
determineUpdatePredicates(milestone))))
.resolveUpgrades(matchingLibraries(), this.bom.getLibraries());
return upgrades;
InteractiveUpgradeResolver upgradeResolver = new InteractiveUpgradeResolver(
getServices().get(UserInputHandler.class), getLibraryUpdateResolver(milestone));
return upgradeResolver.resolveUpgrades(matchingLibraries(), this.bom.getLibraries());
}
private LibraryUpdateResolver getLibraryUpdateResolver(Milestone milestone) {
VersionResolver versionResolver = new MavenMetadataVersionResolver(getRepositories());
LibraryUpdateResolver libraryResolver = new StandardLibraryUpdateResolver(versionResolver,
determineUpdatePredicates(milestone));
return new MultithreadedLibraryUpdateResolver(getThreads().get(), libraryResolver);
}
private Collection<MavenArtifactRepository> getRepositories() {
return getRepositoryNames().map(this::asRepositories).get();
}
private List<MavenArtifactRepository> asRepositories(List<String> repositoryNames) {
return repositoryNames.stream()
.map(getProject().getRepositories()::getByName)
.map(MavenArtifactRepository.class::cast)
.toList();
}
protected List<BiPredicate<Library, DependencyVersion>> determineUpdatePredicates(Milestone milestone) {

88
buildSrc/src/main/java/org/springframework/boot/build/properties/BuildProperties.java

@ -0,0 +1,88 @@ @@ -0,0 +1,88 @@
/*
* 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.properties;
import org.gradle.api.Project;
import org.gradle.api.Task;
/**
* Properties that can influence the build.
*
* @param buildType the build type
* @param gitHub GitHub details
* @author Phillip Webb
*/
public record BuildProperties(BuildType buildType, GitHub gitHub) {
private static final String PROPERTY_NAME = BuildProperties.class.getName();
/**
* Get the {@link BuildProperties} for the given {@link Task}.
* @param task the source task
* @return the build properties
*/
public static BuildProperties get(Task task) {
return get(task.getProject());
}
/**
* Get the {@link BuildProperties} for the given {@link Project}.
* @param project the source project
* @return the build properties
*/
public static BuildProperties get(Project project) {
BuildProperties buildProperties = (BuildProperties) project.findProperty(PROPERTY_NAME);
if (buildProperties == null) {
buildProperties = load(project);
project.getExtensions().getExtraProperties().set(PROPERTY_NAME, buildProperties);
}
return buildProperties;
}
private static BuildProperties load(Project project) {
BuildType buildType = buildType(project.findProperty("spring.build-type"));
return switch (buildType) {
case OPEN_SOURCE -> new BuildProperties(buildType, GitHub.OPEN_SOURCE);
case COMMERCIAL -> new BuildProperties(buildType, GitHub.COMMERCIAL);
};
}
private static BuildType buildType(Object value) {
if (value == null || "oss".equals(value.toString())) {
return BuildType.OPEN_SOURCE;
}
if ("commercial".equals(value.toString())) {
return BuildType.COMMERCIAL;
}
throw new IllegalStateException("Unknown build type property '" + value + "'");
}
/**
* GitHub properties.
*
* @param organization the GitHub organization
* @param repository the GitHub repository
*/
public record GitHub(String organization, String repository) {
static final GitHub OPEN_SOURCE = new GitHub("spring-projects", "spring-boot");
static final GitHub COMMERCIAL = new GitHub("spring-projects", "spring-boot-commercial");
}
}

36
buildSrc/src/main/java/org/springframework/boot/build/properties/BuildType.java

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
/*
* 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.properties;
/**
* The type of build being performed.
*
* @author Phillip Webb
*/
public enum BuildType {
/**
* An open source build.
*/
OPEN_SOURCE,
/**
* A commercial build.
*/
COMMERCIAL
}

37
buildSrc/src/main/java/org/springframework/boot/build/repository/RepositoryUrl.java

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
/*
* 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.repository;
/**
* Utility to build repository URLs.
*
* @author Phillip Webb
*/
final class RepositoryUrl {
private RepositoryUrl() {
}
static String openSource(String path) {
return "https://repo.spring.io" + path;
}
static String commercial(String path) {
return "https://usw1.packages.broadcom.com" + path;
}
}

105
buildSrc/src/main/java/org/springframework/boot/build/repository/SpringRepository.java

@ -0,0 +1,105 @@ @@ -0,0 +1,105 @@
/*
* 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.repository;
import org.springframework.boot.build.properties.BuildType;
/**
* Enumeration of repositories defined in the order that they should be used.
*
* @author Phillip Webb
*/
public enum SpringRepository {
/**
* Repository for commercial releases.
*/
COMMERCIAL_RELEASE("spring-commerical-release", BuildType.COMMERCIAL, RepositoryType.RELEASE,
RepositoryUrl.commercial("/spring-enterprise-maven-prod-local")),
/**
* Repository for open source milestones.
*/
OSS_MILESTONE("spring-oss-milestone", BuildType.OPEN_SOURCE, RepositoryType.MILESTONE,
RepositoryUrl.openSource("/milestone")),
/**
* Repository for commercial snapshots.
*/
COMMERCIAL_SNAPSHOT("spring-commerical-snapshot", BuildType.COMMERCIAL, RepositoryType.SNAPSHOT,
RepositoryUrl.commercial("/spring-enterprise-maven-dev-local")),
/**
* Repository for open source snapshots.
*/
OSS_SNAPSHOT("spring-oss-snapshot", BuildType.OPEN_SOURCE, RepositoryType.SNAPSHOT,
RepositoryUrl.openSource("/snapshot"));
private final String name;
private final BuildType buildType;
private final RepositoryType repositoryType;
private final String url;
SpringRepository(String name, BuildType buildType, RepositoryType repositoryType, String url) {
this.name = name;
this.buildType = buildType;
this.repositoryType = repositoryType;
this.url = url;
}
public String getName() {
return this.name;
}
public BuildType getBuildType() {
return this.buildType;
}
public RepositoryType getRepositoryType() {
return this.repositoryType;
}
public String getUrl() {
return this.url;
}
/**
* Repository types.
*/
public enum RepositoryType {
/**
* Repository containing release artifacts.
*/
RELEASE,
/**
* Repository containing milestone artifacts.
*/
MILESTONE,
/**
* Repository containing snapshot artifacts.
*/
SNAPSHOT
}
}
Loading…
Cancel
Save