From 68af379714f6ad37ad397cf91a84a548a3cdd562 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 5 Jan 2023 13:56:58 -0800 Subject: [PATCH] Don't use repo.spring.io in released Homebrew or Scoop recipes Update our Homebrew and Scoop recipes to use `repo1.maven.org` rather than `repo.spring.io` for releases. Fixes gh-33702 --- .../artifactory/ArtifactoryRepository.java | 16 +++++++++--- .../AbstractPackageManagerDefinitionTask.java | 26 +++++++++++++++---- .../src/main/homebrew/spring-boot.rb | 2 +- .../src/main/scoop/springboot.json | 2 +- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/artifactory/ArtifactoryRepository.java b/buildSrc/src/main/java/org/springframework/boot/build/artifactory/ArtifactoryRepository.java index 12c9b7f8bb..1e0a7d675e 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/artifactory/ArtifactoryRepository.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/artifactory/ArtifactoryRepository.java @@ -25,6 +25,12 @@ import org.gradle.api.Project; */ public final class ArtifactoryRepository { + private static final String SNAPSHOT = "snapshot"; + + private static final String MILESTONE = "milestone"; + + private static final String RELEASE = "release"; + private final String name; private ArtifactoryRepository(String name) { @@ -35,6 +41,10 @@ public final class ArtifactoryRepository { return this.name; } + public boolean isRelease() { + return RELEASE.equals(this.name); + } + @Override public String toString() { return this.name; @@ -48,13 +58,13 @@ public final class ArtifactoryRepository { String version = project.getVersion().toString(); int modifierIndex = version.lastIndexOf('-'); if (modifierIndex == -1) { - return "release"; + return RELEASE; } String type = version.substring(modifierIndex + 1); if (type.startsWith("M") || type.startsWith("RC")) { - return "milestone"; + return MILESTONE; } - return "snapshot"; + return SNAPSHOT; } } diff --git a/buildSrc/src/main/java/org/springframework/boot/build/cli/AbstractPackageManagerDefinitionTask.java b/buildSrc/src/main/java/org/springframework/boot/build/cli/AbstractPackageManagerDefinitionTask.java index b2d4ea1f90..775e3f2d66 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/cli/AbstractPackageManagerDefinitionTask.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/cli/AbstractPackageManagerDefinitionTask.java @@ -23,6 +23,7 @@ import java.util.Map; import org.apache.commons.codec.digest.DigestUtils; import org.gradle.api.DefaultTask; +import org.gradle.api.Project; import org.gradle.api.file.RegularFile; import org.gradle.api.provider.Provider; import org.gradle.api.tasks.InputFile; @@ -38,9 +39,14 @@ import org.springframework.boot.build.artifactory.ArtifactoryRepository; * a Homebrew formula. * * @author Andy Wilkinson + * @author Phillip Webb */ public abstract class AbstractPackageManagerDefinitionTask extends DefaultTask { + private static final String SPRING_REPO = "https://repo.spring.io/%s"; + + private static final String MAVEN_REPO = "https://repo1.maven.org/maven2"; + private Provider archive; private File template; @@ -84,14 +90,19 @@ public abstract class AbstractPackageManagerDefinitionTask extends DefaultTask { getProject().copy((copy) -> { copy.from(this.template); copy.into(this.outputDir); - Map properties = new HashMap<>(additionalProperties); - properties.put("hash", sha256(this.archive.get().getAsFile())); - properties.put("repo", ArtifactoryRepository.forProject(getProject())); - properties.put("project", getProject()); - copy.expand(properties); + copy.expand(getProperties(additionalProperties)); }); } + private Map getProperties(Map additionalProperties) { + Map properties = new HashMap<>(additionalProperties); + Project project = getProject(); + properties.put("hash", sha256(this.archive.get().getAsFile())); + properties.put("repo", getRepo(project)); + properties.put("project", project); + return properties; + } + private String sha256(File file) { try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); @@ -102,4 +113,9 @@ public abstract class AbstractPackageManagerDefinitionTask extends DefaultTask { } } + private String getRepo(Project project) { + ArtifactoryRepository artifactoryRepo = ArtifactoryRepository.forProject(project); + return (!artifactoryRepo.isRelease()) ? String.format(SPRING_REPO, artifactoryRepo.getName()) : MAVEN_REPO; + } + } diff --git a/spring-boot-project/spring-boot-cli/src/main/homebrew/spring-boot.rb b/spring-boot-project/spring-boot-cli/src/main/homebrew/spring-boot.rb index e802190723..b3973befc9 100644 --- a/spring-boot-project/spring-boot-cli/src/main/homebrew/spring-boot.rb +++ b/spring-boot-project/spring-boot-cli/src/main/homebrew/spring-boot.rb @@ -2,7 +2,7 @@ require 'formula' class SpringBoot < Formula homepage 'https://spring.io/projects/spring-boot' - url 'https://repo.spring.io/${repo}/org/springframework/boot/spring-boot-cli/${project.version}/spring-boot-cli-${project.version}-bin.tar.gz' + url '${repo}/org/springframework/boot/spring-boot-cli/${project.version}/spring-boot-cli-${project.version}-bin.tar.gz' version '${project.version}' sha256 '${hash}' head 'https://github.com/spring-projects/spring-boot.git' diff --git a/spring-boot-project/spring-boot-cli/src/main/scoop/springboot.json b/spring-boot-project/spring-boot-cli/src/main/scoop/springboot.json index dbfe2308cc..d49cacca6d 100644 --- a/spring-boot-project/spring-boot-cli/src/main/scoop/springboot.json +++ b/spring-boot-project/spring-boot-cli/src/main/scoop/springboot.json @@ -3,7 +3,7 @@ "version": "${scoopVersion}", "license": "Apache 2.0", "hash": "${hash}", - "url": "https://repo.spring.io/${repo}/org/springframework/boot/spring-boot-cli/${project.version}/spring-boot-cli-${project.version}-bin.zip", + "url": "${repo}/org/springframework/boot/spring-boot-cli/${project.version}/spring-boot-cli-${project.version}-bin.zip", "extract_dir": "spring-${project.version}", "bin": "bin\\\\spring.bat", "suggest": {