Merge branch '2.7.x' into 3.0.x

Closes gh-34161
This commit is contained in:
Scott Frederick 2023-02-09 15:47:34 -06:00
commit cbac3c81d6
10 changed files with 134 additions and 103 deletions

View File

@ -30,7 +30,7 @@ import org.gradle.api.Project;
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.tasks.Sync;
import org.springframework.boot.build.artifactory.ArtifactoryRepository;
import org.springframework.boot.build.artifacts.ArtifactRelease;
import org.springframework.util.StringUtils;
/**
@ -59,6 +59,7 @@ import org.springframework.util.StringUtils;
* </ul>
*
* @author Andy Wilkinson
* @author Scott Frederick
*/
class AsciidoctorConventions {
@ -110,10 +111,12 @@ class AsciidoctorConventions {
}
private void configureCommonAttributes(Project project, AbstractAsciidoctorTask asciidoctorTask) {
ArtifactRelease artifacts = ArtifactRelease.forProject(project);
Map<String, Object> attributes = new HashMap<>();
attributes.put("attribute-missing", "warn");
attributes.put("github-tag", determineGitHubTag(project));
attributes.put("spring-boot-artifactory-repo", ArtifactoryRepository.forProject(project));
attributes.put("artifact-release-type", artifacts.getType());
attributes.put("artifact-download-repo", artifacts.getDownloadRepo());
attributes.put("revnumber", null);
asciidoctorTask.attributes(attributes);
}

View File

@ -14,16 +14,17 @@
* limitations under the License.
*/
package org.springframework.boot.build.artifactory;
package org.springframework.boot.build.artifacts;
import org.gradle.api.Project;
/**
* An Artifactory repository to which a build of Spring Boot can be published.
* Information about artifacts produced by a build.
*
* @author Andy Wilkinson
* @author Scott Frederick
*/
public final class ArtifactoryRepository {
public final class ArtifactRelease {
private static final String SNAPSHOT = "snapshot";
@ -31,30 +32,33 @@ public final class ArtifactoryRepository {
private static final String RELEASE = "release";
private final String name;
private static final String SPRING_REPO = "https://repo.spring.io/%s";
private ArtifactoryRepository(String name) {
this.name = name;
private static final String MAVEN_REPO = "https://repo.maven.apache.org/maven2";
private final String type;
private ArtifactRelease(String type) {
this.type = type;
}
public String getName() {
return this.name;
public String getType() {
return this.type;
}
public String getDownloadRepo() {
return (this.isRelease()) ? MAVEN_REPO : String.format(SPRING_REPO, this.getType());
}
public boolean isRelease() {
return RELEASE.equals(this.name);
return RELEASE.equals(this.type);
}
@Override
public String toString() {
return this.name;
public static ArtifactRelease forProject(Project project) {
return new ArtifactRelease(determineReleaseType(project));
}
public static ArtifactoryRepository forProject(Project project) {
return new ArtifactoryRepository(determineArtifactoryRepo(project));
}
private static String determineArtifactoryRepo(Project project) {
private static String determineReleaseType(Project project) {
String version = project.getVersion().toString();
int modifierIndex = version.lastIndexOf('-');
if (modifierIndex == -1) {

View File

@ -35,7 +35,7 @@ import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.TaskExecutionException;
import org.springframework.boot.build.artifactory.ArtifactoryRepository;
import org.springframework.boot.build.artifacts.ArtifactRelease;
/**
* A {@link Task} for creating a Homebrew formula manifest.
@ -44,10 +44,6 @@ import org.springframework.boot.build.artifactory.ArtifactoryRepository;
*/
public class HomebrewFormula extends DefaultTask {
private static final String SPRING_REPO = "https://repo.spring.io/%s";
private static final String MAVEN_REPO = "https://repo.maven.apache.org/maven2";
private Provider<RegularFile> archive;
private File template;
@ -99,7 +95,7 @@ public class HomebrewFormula extends DefaultTask {
Map<String, Object> properties = new HashMap<>(additionalProperties);
Project project = getProject();
properties.put("hash", sha256(this.archive.get().getAsFile()));
properties.put("repo", getRepo(project));
properties.put("repo", ArtifactRelease.forProject(project).getDownloadRepo());
properties.put("project", project);
return properties;
}
@ -114,11 +110,6 @@ public class HomebrewFormula extends DefaultTask {
}
}
private String getRepo(Project project) {
ArtifactoryRepository artifactoryRepo = ArtifactoryRepository.forProject(project);
return (!artifactoryRepo.isRelease()) ? String.format(SPRING_REPO, artifactoryRepo.getName()) : MAVEN_REPO;
}
@TaskAction
void createFormula() {
createDescriptor(Collections.emptyMap());

View File

@ -1,60 +0,0 @@
/*
* Copyright 2012-2021 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.artifactory;
import org.gradle.api.Project;
import org.gradle.testfixtures.ProjectBuilder;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link ArtifactoryRepository}.
*
* @author Andy Wilkinson
*/
class ArtifactoryRepositoryTests {
@Test
void whenProjectVersionIsMilestoneThenRepositoryIsMilestone() {
Project project = ProjectBuilder.builder().build();
project.setVersion("1.2.3-M1");
assertThat(ArtifactoryRepository.forProject(project).getName()).isEqualTo("milestone");
}
@Test
void whenProjectVersionIsReleaseCandidateThenRepositoryIsMilestone() {
Project project = ProjectBuilder.builder().build();
project.setVersion("1.2.3-RC1");
assertThat(ArtifactoryRepository.forProject(project).getName()).isEqualTo("milestone");
}
@Test
void whenProjectVersionIsReleaseThenRepositoryIsRelease() {
Project project = ProjectBuilder.builder().build();
project.setVersion("1.2.3");
assertThat(ArtifactoryRepository.forProject(project).getName()).isEqualTo("release");
}
@Test
void whenProjectVersionIsSnapshotThenRepositoryIsSnapshot() {
Project project = ProjectBuilder.builder().build();
project.setVersion("1.2.3-SNAPSHOT");
assertThat(ArtifactoryRepository.forProject(project).getName()).isEqualTo("snapshot");
}
}

View File

@ -0,0 +1,90 @@
/*
* Copyright 2012-2021 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.artifacts;
import org.gradle.api.Project;
import org.gradle.testfixtures.ProjectBuilder;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link ArtifactRelease}.
*
* @author Andy Wilkinson
* @author Scott Frederick
*/
class ArtifactReleaseTests {
@Test
void whenProjectVersionIsSnapshotThenTypeIsSnapshot() {
Project project = ProjectBuilder.builder().build();
project.setVersion("1.2.3-SNAPSHOT");
assertThat(ArtifactRelease.forProject(project).getType()).isEqualTo("snapshot");
}
@Test
void whenProjectVersionIsMilestoneThenTypeIsMilestone() {
Project project = ProjectBuilder.builder().build();
project.setVersion("1.2.3-M1");
assertThat(ArtifactRelease.forProject(project).getType()).isEqualTo("milestone");
}
@Test
void whenProjectVersionIsReleaseCandidateThenTypeIsMilestone() {
Project project = ProjectBuilder.builder().build();
project.setVersion("1.2.3-RC1");
assertThat(ArtifactRelease.forProject(project).getType()).isEqualTo("milestone");
}
@Test
void whenProjectVersionIsReleaseThenTypeIsRelease() {
Project project = ProjectBuilder.builder().build();
project.setVersion("1.2.3");
assertThat(ArtifactRelease.forProject(project).getType()).isEqualTo("release");
}
@Test
void whenProjectVersionIsSnapshotThenRepositoryIsArtifactorySnapshot() {
Project project = ProjectBuilder.builder().build();
project.setVersion("1.2.3-SNAPSHOT");
assertThat(ArtifactRelease.forProject(project).getDownloadRepo()).contains("repo.spring.io/snapshot");
}
@Test
void whenProjectVersionIsMilestoneThenRepositoryIsArtifactoryMilestone() {
Project project = ProjectBuilder.builder().build();
project.setVersion("1.2.3-M1");
assertThat(ArtifactRelease.forProject(project).getDownloadRepo()).contains("repo.spring.io/milestone");
}
@Test
void whenProjectVersionIsReleaseCandidateThenRepositoryIsArtifactoryMilestone() {
Project project = ProjectBuilder.builder().build();
project.setVersion("1.2.3-RC1");
assertThat(ArtifactRelease.forProject(project).getDownloadRepo()).contains("repo.spring.io/milestone");
}
@Test
void whenProjectVersionIsReleaseThenRepositoryIsMavenCentral() {
Project project = ProjectBuilder.builder().build();
project.setVersion("1.2.3");
assertThat(ArtifactRelease.forProject(project).getDownloadRepo())
.contains("https://repo.maven.apache.org/maven2");
}
}

View File

@ -11,7 +11,7 @@
:docinfo: shared,private
:attribute-missing: warn
:chomp: default headers packages
:spring-boot-artifactory-repo: snapshot
:artifact-release-type: snapshot
:github-tag: main
:spring-boot-version: current
:github-repo: spring-projects/spring-boot

View File

@ -61,7 +61,7 @@ Open your favorite text editor and add the following:
<!-- Additional lines to be added here... -->
ifeval::["{spring-boot-artifactory-repo}" != "release"]
ifeval::["{artifact-release-type}" != "release"]
<!-- (you only need this if you are using a milestone or snapshot version) -->
<repositories>
<repository>

View File

@ -73,13 +73,16 @@ You do not need to use the CLI to work with Spring Boot, but it is a quick way t
[[getting-started.installing.cli.manual-installation]]
==== Manual Installation
You can download the Spring CLI distribution from the Spring software repository:
ifeval::["{artifact-release-type}" == "snapshot"]
You can download one of the `spring-boot-cli-\*-bin.zip` or `spring-boot-cli-*-bin.tar.gz` files from the {artifact-download-repo}/org/springframework/boot/spring-boot-cli/{spring-boot-version}/[Spring software repository].
endif::[]
ifeval::["{artifact-release-type}" != "snapshot"]
You can download the Spring CLI distribution from one of the following locations:
* https://repo.spring.io/{spring-boot-artifactory-repo}/org/springframework/boot/spring-boot-cli/{spring-boot-version}/spring-boot-cli-{spring-boot-version}-bin.zip[spring-boot-cli-{spring-boot-version}-bin.zip]
* https://repo.spring.io/{spring-boot-artifactory-repo}/org/springframework/boot/spring-boot-cli/{spring-boot-version}/spring-boot-cli-{spring-boot-version}-bin.tar.gz[spring-boot-cli-{spring-boot-version}-bin.tar.gz]
* {artifact-download-repo}/org/springframework/boot/spring-boot-cli/{spring-boot-version}/spring-boot-cli-{spring-boot-version}-bin.zip[spring-boot-cli-{spring-boot-version}-bin.zip]
* {artifact-download-repo}/org/springframework/boot/spring-boot-cli/{spring-boot-version}/spring-boot-cli-{spring-boot-version}-bin.tar.gz[spring-boot-cli-{spring-boot-version}-bin.tar.gz]
endif::[]
Cutting edge
https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-cli/[snapshot distributions] are also available.
Once downloaded, follow the {github-raw}/spring-boot-project/spring-boot-tools/spring-boot-cli/src/main/content/INSTALL.txt[INSTALL.txt] instructions from the unpacked archive.
In summary, there is a `spring` script (`spring.bat` for Windows) in a `bin/` directory in the `.zip` file.

View File

@ -2,7 +2,7 @@
= Getting Started
To get started with the plugin it needs to be applied to your project.
ifeval::["{spring-boot-artifactory-repo}" == "release"]
ifeval::["{artifact-release-type}" == "release"]
The plugin is https://plugins.gradle.org/plugin/org.springframework.boot[published to Gradle's plugin portal] and can be applied using the `plugins` block:
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
@ -16,7 +16,7 @@ include::../gradle/getting-started/apply-plugin-release.gradle[]
include::../gradle/getting-started/apply-plugin-release.gradle.kts[]
----
endif::[]
ifeval::["{spring-boot-artifactory-repo}" == "milestone"]
ifeval::["{artifact-release-type}" == "milestone"]
The plugin is published to the Spring milestones repository.
Gradle can be configured to use the milestones repository and the plugin can then be applied using the `plugins` block.
To configure Gradle to use the milestones repository, add the following to your `settings.gradle` (Groovy) or `settings.gradle.kts` (Kotlin):
@ -47,7 +47,7 @@ include::../gradle/getting-started/apply-plugin-release.gradle[]
include::../gradle/getting-started/apply-plugin-release.gradle.kts[]
----
endif::[]
ifeval::["{spring-boot-artifactory-repo}" == "snapshot"]
ifeval::["{artifact-release-type}" == "snapshot"]
The plugin is published to the Spring snapshots repository.
Gradle can be configured to use the snapshots repository and the plugin can then be applied using the `plugins` block.
To configure Gradle to use the snapshots repository, add the following to your `settings.gradle` (Groovy) or `settings.gradle.kts` (Kotlin):

View File

@ -58,7 +58,7 @@ The `SpringBootPlugin` class provides a `BOM_COORDINATES` constant that can be u
First, configure the project to depend on the Spring Boot plugin but do not apply it:
ifeval::["{spring-boot-artifactory-repo}" == "release"]
ifeval::["{artifact-release-type}" == "release"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
@ -71,7 +71,7 @@ include::../gradle/managing-dependencies/depend-on-plugin-release.gradle[]
include::../gradle/managing-dependencies/depend-on-plugin-release.gradle.kts[]
----
endif::[]
ifeval::["{spring-boot-artifactory-repo}" == "milestone"]
ifeval::["{artifact-release-type}" == "milestone"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
@ -83,7 +83,7 @@ include::../gradle/managing-dependencies/depend-on-plugin-milestone.gradle[]
include::../gradle/managing-dependencies/depend-on-plugin-release.gradle.kts[]
----
endif::[]
ifeval::["{spring-boot-artifactory-repo}" == "snapshot"]
ifeval::["{artifact-release-type}" == "snapshot"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----