Skip to content

Commit

Permalink
Merge branch '3.0.x'
Browse files Browse the repository at this point in the history
Closes gh-34162
  • Loading branch information
scottfrederick committed Feb 9, 2023
2 parents 6932a5c + cbac3c8 commit 12537c7
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
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;

/**
Expand Down Expand Up @@ -59,6 +59,7 @@
* </ul>
*
* @author Andy Wilkinson
* @author Scott Frederick
*/
class AsciidoctorConventions {

Expand Down Expand Up @@ -110,10 +111,12 @@ private void configureAsciidoctorTask(Project project, AbstractAsciidoctorTask a
}

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,51 @@
* 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";

private static final String MILESTONE = "milestone";

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 boolean isRelease() {
return RELEASE.equals(this.name);
public String getDownloadRepo() {
return (this.isRelease()) ? MAVEN_REPO : String.format(SPRING_REPO, this.getType());
}

@Override
public String toString() {
return this.name;
public boolean isRelease() {
return RELEASE.equals(this.type);
}

public static ArtifactoryRepository forProject(Project project) {
return new ArtifactoryRepository(determineArtifactoryRepo(project));
public static ArtifactRelease forProject(Project project) {
return new ArtifactRelease(determineReleaseType(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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
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.
Expand All @@ -44,10 +44,6 @@
*/
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;
Expand Down Expand Up @@ -99,7 +95,7 @@ private Map<String, Object> getProperties(Map<String, Object> additionalProperti
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;
}
Expand All @@ -114,11 +110,6 @@ private String sha256(File file) {
}
}

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());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
----
Expand All @@ -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
----
Expand All @@ -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
----
Expand Down

0 comments on commit 12537c7

Please sign in to comment.