diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/MoveToSnapshots.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/MoveToSnapshots.java index e1b170accab..9e0f319d4f0 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/MoveToSnapshots.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/MoveToSnapshots.java @@ -17,7 +17,6 @@ package org.springframework.boot.build.bom.bomr; import java.time.OffsetDateTime; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.function.BiPredicate; @@ -25,6 +24,7 @@ import java.util.function.BiPredicate; import javax.inject.Inject; import org.gradle.api.Task; +import org.gradle.api.artifacts.repositories.MavenArtifactRepository; import org.gradle.api.tasks.TaskAction; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,9 +35,6 @@ 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. @@ -51,17 +48,12 @@ public abstract class MoveToSnapshots extends UpgradeDependencies { @Inject public MoveToSnapshots(BomExtension bom) { super(bom, true); - BuildType buildType = BuildProperties.get(this).buildType(); - getRepositoryNames().addAll(getSnapshotRepositoryNames(buildType)); - } - - public static List 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(); + getProject().getRepositories().withType(MavenArtifactRepository.class, (repository) -> { + String name = repository.getName(); + if (name.startsWith("spring-") && name.endsWith("-snapshot")) { + getRepositoryNames().add(name); + } + }); } @Override @@ -95,7 +87,7 @@ public abstract class MoveToSnapshots extends UpgradeDependencies { @Override protected List> determineUpdatePredicates(Milestone milestone) { - return switch (BuildProperties.get(this).buildType()) { + return switch (BuildProperties.get(getProject()).buildType()) { case OPEN_SOURCE -> determineOpenSourceUpdatePredicates(milestone); case COMMERCIAL -> super.determineUpdatePredicates(milestone); }; diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeBom.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeBom.java index b71fe2614f8..9b734cff78a 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeBom.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeBom.java @@ -24,7 +24,6 @@ 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. @@ -37,7 +36,7 @@ public abstract class UpgradeBom extends UpgradeDependencies { @Inject public UpgradeBom(BomExtension bom) { super(bom); - switch (BuildProperties.get(this).buildType()) { + switch (BuildProperties.get(getProject()).buildType()) { case OPEN_SOURCE -> addOpenSourceRepositories(); case COMMERCIAL -> addCommercialRepositories(); } @@ -45,19 +44,16 @@ public abstract class UpgradeBom extends UpgradeDependencies { private void addOpenSourceRepositories() { getProject().getRepositories().withType(MavenArtifactRepository.class, (repository) -> { - if (!isSnaphotRepository(repository)) { - getRepositoryNames().add(repository.getName()); + String name = repository.getName(); + if (name.startsWith("spring-") && !name.endsWith("-snapshot")) { + getRepositoryNames().add(name); } }); } 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"); + "spring-commerical-release"); } @Override diff --git a/buildSrc/src/main/java/org/springframework/boot/build/properties/BuildProperties.java b/buildSrc/src/main/java/org/springframework/boot/build/properties/BuildProperties.java index ed347095e5d..81cac24c189 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/properties/BuildProperties.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/properties/BuildProperties.java @@ -17,7 +17,6 @@ package org.springframework.boot.build.properties; import org.gradle.api.Project; -import org.gradle.api.Task; /** * Properties that can influence the build. @@ -30,15 +29,6 @@ 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 diff --git a/buildSrc/src/main/java/org/springframework/boot/build/repository/RepositoryUrl.java b/buildSrc/src/main/java/org/springframework/boot/build/repository/RepositoryUrl.java deleted file mode 100644 index 690bd23ec8f..00000000000 --- a/buildSrc/src/main/java/org/springframework/boot/build/repository/RepositoryUrl.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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; - } - -} diff --git a/buildSrc/src/main/java/org/springframework/boot/build/repository/SpringRepository.java b/buildSrc/src/main/java/org/springframework/boot/build/repository/SpringRepository.java deleted file mode 100644 index 50e1471258c..00000000000 --- a/buildSrc/src/main/java/org/springframework/boot/build/repository/SpringRepository.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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 - - } - -}