Skip to content

Commit

Permalink
Merge branch '3.3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
philwebb committed Sep 30, 2024
2 parents 021e84b + ec615f6 commit 99142db
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.springframework.boot.build.artifacts.ArtifactRelease;
import org.springframework.boot.build.bom.BomExtension;
import org.springframework.boot.build.bom.Library;
import org.springframework.boot.build.properties.BuildProperties;
import org.springframework.boot.build.properties.BuildType;
import org.springframework.util.Assert;

/**
Expand All @@ -47,6 +49,8 @@ public class AntoraAsciidocAttributes {

private final boolean latestVersion;

private final BuildType buildType;

private final ArtifactRelease artifactRelease;

private final List<Library> libraries;
Expand All @@ -59,16 +63,18 @@ public AntoraAsciidocAttributes(Project project, BomExtension dependencyBom,
Map<String, String> dependencyVersions) {
this.version = String.valueOf(project.getVersion());
this.latestVersion = Boolean.parseBoolean(String.valueOf(project.findProperty("latestVersion")));
this.buildType = BuildProperties.get(project).buildType();
this.artifactRelease = ArtifactRelease.forProject(project);
this.libraries = dependencyBom.getLibraries();
this.dependencyVersions = dependencyVersions;
this.projectProperties = project.getProperties();
}

AntoraAsciidocAttributes(String version, boolean latestVersion, List<Library> libraries,
AntoraAsciidocAttributes(String version, boolean latestVersion, BuildType buildType, List<Library> libraries,
Map<String, String> dependencyVersions, Map<String, ?> projectProperties) {
this.version = version;
this.latestVersion = latestVersion;
this.buildType = buildType;
this.artifactRelease = ArtifactRelease.forVersion(version);
this.libraries = (libraries != null) ? libraries : Collections.emptyList();
this.dependencyVersions = (dependencyVersions != null) ? dependencyVersions : Collections.emptyMap();
Expand All @@ -77,6 +83,7 @@ public AntoraAsciidocAttributes(Project project, BomExtension dependencyBom,

public Map<String, String> get() {
Map<String, String> attributes = new LinkedHashMap<>();
addBuildTypeAttribute(attributes);
addGitHubAttributes(attributes);
addVersionAttributes(attributes);
addArtifactAttributes(attributes);
Expand All @@ -86,6 +93,10 @@ public Map<String, String> get() {
return attributes;
}

private void addBuildTypeAttribute(Map<String, String> attributes) {
attributes.put("build-type", this.buildType.toIdentifier());
}

private void addGitHubAttributes(Map<String, String> attributes) {
attributes.put("github-repo", "spring-projects/spring-boot");
attributes.put("github-ref", determineGitHubRef());
Expand Down Expand Up @@ -152,6 +163,8 @@ private String getVersion(String groupAndArtifactId) {
private void addArtifactAttributes(Map<String, String> attributes) {
attributes.put("url-artifact-repository", this.artifactRelease.getDownloadRepo());
attributes.put("artifact-release-type", this.artifactRelease.getType());
attributes.put("build-and-artifact-release-type",
this.buildType.toIdentifier() + "-" + this.artifactRelease.getType());
}

private void addUrlJava(Map<String, String> attributes) {
Expand All @@ -177,8 +190,7 @@ public synchronized Object put(Object key, Object value) {
};
try (InputStream in = getClass().getResourceAsStream("antora-asciidoc-attributes.properties")) {
properties.load(in);
}
catch (IOException ex) {
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public enum BuildType {
/**
* A commercial build.
*/
COMMERCIAL
COMMERCIAL;

public String toIdentifier() {
return toString().replace("_", "").toLowerCase();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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.properties.BuildType;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -42,105 +43,146 @@
*/
class AntoraAsciidocAttributesTests {

@Test
void buildTypeWhenOpenSource() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, BuildType.OPEN_SOURCE, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("build-type", "opensource");
}

@Test
void buildTypeWhenCommercial() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, BuildType.COMMERCIAL, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("build-type", "commercial");
}

@Test
void githubRefWhenReleasedVersionIsTag() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, null,
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, BuildType.OPEN_SOURCE, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("github-ref", "v1.2.3");
}

@Test
void githubRefWhenLatestSnapshotVersionIsMainBranch() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true, null,
mockDependencyVersions(), null);
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true,
BuildType.OPEN_SOURCE, null, mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("github-ref", "main");
}

@Test
void githubRefWhenOlderSnapshotVersionIsBranch() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", false, null,
mockDependencyVersions(), null);
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", false,
BuildType.OPEN_SOURCE, null, mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("github-ref", "1.2.x");
}

@Test
void githubRefWhenOlderSnapshotHotFixVersionIsBranch() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3.1-SNAPSHOT", false, null,
mockDependencyVersions(), null);
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3.1-SNAPSHOT", false,
BuildType.OPEN_SOURCE, null, mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("github-ref", "1.2.3.x");
}

@Test
void versionReferenceFromLibrary() {
Library library = mockLibrary(Collections.emptyMap());
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3.1-SNAPSHOT", false, List.of(library),
mockDependencyVersions(), null);
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3.1-SNAPSHOT", false,
BuildType.OPEN_SOURCE, List.of(library), mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("version-spring-framework", "1.2.3");
}

@Test
void versionReferenceFromSpringDataDependencyReleaseVersion() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, null,
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, BuildType.OPEN_SOURCE, null,
mockDependencyVersions("3.2.5"), null);
assertThat(attributes.get()).containsEntry("version-spring-data-mongodb-docs", "3.2");
assertThat(attributes.get()).containsEntry("version-spring-data-mongodb-javadoc", "3.2.x");
}

@Test
void versionReferenceFromSpringDataDependencySnapshotVersion() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, null,
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, BuildType.OPEN_SOURCE, null,
mockDependencyVersions("3.2.0-SNAPSHOT"), null);
assertThat(attributes.get()).containsEntry("version-spring-data-mongodb-docs", "3.2-SNAPSHOT");
assertThat(attributes.get()).containsEntry("version-spring-data-mongodb-javadoc", "3.2.x");
}

@Test
void versionNativeBuildTools() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, null,
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, BuildType.OPEN_SOURCE, null,
mockDependencyVersions(), Map.of("nativeBuildToolsVersion", "3.4.5"));
assertThat(attributes.get()).containsEntry("version-native-build-tools", "3.4.5");
}

@Test
void urlArtifactRepositoryWhenRelease() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, null,
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, BuildType.OPEN_SOURCE, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("url-artifact-repository", "https://repo.maven.apache.org/maven2");
}

@Test
void urlArtifactRepositoryWhenMilestone() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-M1", true, null,
mockDependencyVersions(), null);
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-M1", true, BuildType.OPEN_SOURCE,
null, mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("url-artifact-repository", "https://repo.spring.io/milestone");
}

@Test
void urlArtifactRepositoryWhenSnapshot() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true, null,
mockDependencyVersions(), null);
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true,
BuildType.OPEN_SOURCE, null, mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("url-artifact-repository", "https://repo.spring.io/snapshot");
}

@Test
void artifactReleaseTypeWhenRelease() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, null,
void artifactReleaseTypeWhenOpenSourceRelease() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, BuildType.OPEN_SOURCE, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("artifact-release-type", "release");
assertThat(attributes.get()).containsEntry("build-and-artifact-release-type", "opensource-release");
}

@Test
void artifactReleaseTypeWhenMilestone() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-M1", true, null,
mockDependencyVersions(), null);
void artifactReleaseTypeWhenOpenSourceMilestone() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-M1", true, BuildType.OPEN_SOURCE,
null, mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("artifact-release-type", "milestone");
assertThat(attributes.get()).containsEntry("build-and-artifact-release-type", "opensource-milestone");
}

@Test
void artifactReleaseTypeWhenSnapshot() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true, null,
void artifactReleaseTypeWhenOpenSourceSnapshot() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true,
BuildType.OPEN_SOURCE, null, mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("artifact-release-type", "snapshot");
assertThat(attributes.get()).containsEntry("build-and-artifact-release-type", "opensource-snapshot");
}

@Test
void artifactReleaseTypeWhenCommercialRelease() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, BuildType.COMMERCIAL, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("artifact-release-type", "release");
assertThat(attributes.get()).containsEntry("build-and-artifact-release-type", "commercial-release");
}

@Test
void artifactReleaseTypeWhenCommercialMilestone() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-M1", true, BuildType.COMMERCIAL, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("artifact-release-type", "milestone");
assertThat(attributes.get()).containsEntry("build-and-artifact-release-type", "commercial-milestone");
}

@Test
void artifactReleaseTypeWhenCommercialSnapshot() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true, BuildType.COMMERCIAL,
null, mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("artifact-release-type", "snapshot");
assertThat(attributes.get()).containsEntry("build-and-artifact-release-type", "commercial-snapshot");
}

@Test
Expand All @@ -149,16 +191,16 @@ void urlLinksFromLibrary() {
links.put("site", (version) -> "https://example.com/site/" + version);
links.put("docs", (version) -> "https://example.com/docs/" + version);
Library library = mockLibrary(links);
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3.1-SNAPSHOT", false, List.of(library),
mockDependencyVersions(), null);
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3.1-SNAPSHOT", false,
BuildType.OPEN_SOURCE, List.of(library), mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("url-spring-framework-site", "https://example.com/site/1.2.3")
.containsEntry("url-spring-framework-docs", "https://example.com/docs/1.2.3");
}

@Test
void linksFromProperties() {
Map<String, String> attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true, null,
mockDependencyVersions(), null)
Map<String, String> attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true, BuildType.OPEN_SOURCE,
null, mockDependencyVersions(), null)
.get();
assertThat(attributes).containsEntry("include-java", "ROOT:example$java/org/springframework/boot/docs");
assertThat(attributes).containsEntry("url-spring-data-cassandra-site",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,34 +100,61 @@ Open your favorite text editor and add the following:
<!-- Additional lines to be added here... -->
ifeval::["{artifact-release-type}" != "release"]
<!-- (you only need this if you are using a milestone or snapshot version) -->
<repositories>
<repository>
<id>spring-snapshots</id>
<url>https://repo.spring.io/snapshot</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>https://repo.spring.io/snapshot</url>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
ifeval::["{build-and-artifact-release-type}" == "opensource-milestone"]
<!-- (you don't need this if you are using a release version) -->
<repositories>
<repository>
<id>spring-milestones</id>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
endif::[]
ifeval::["{build-and-artifact-release-type}" == "opensource-snapshot"]
<!-- (you don't need this if you are using a release version) -->
<repositories>
<repository>
<id>spring-snapshots</id>
<url>https://repo.spring.io/snapshot</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>https://repo.spring.io/snapshot</url>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
endif::[]
</project>
----

ifeval::["{build-type}" == "opensource"]
The preceding listing should give you a working build.
endif::[]

ifeval::["{build-type}" == "commercial"]
You will also have to configure your build to access the Spring Commercial repository.
This is usual done through a local artifact repository that mirrors the content of the Spring Commercial repository.
Alternatively, while it is not recommended, the Spring Commercial repository can also be accessed directly.
In either case, see https://docs.vmware.com/en/Tanzu-Spring-Runtime/Commercial/Tanzu-Spring-Runtime/spring-enterprise-subscription.html[the Tanzu Spring Runtime documentation] for further details.

With the addition of the necessary repository configuration, the preceding listing should give you a working build.
endif::[]

You can test it by running `mvn package` (for now, you can ignore the "`jar will be empty - no content was marked for inclusion!`" warning).

NOTE: At this point, you could import the project into an IDE (most modern Java IDEs include built-in support for Maven).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id 'org.springframework.boot' version '{gradle-project-version}'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id("org.springframework.boot") version "{gradle-project-version}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id 'org.springframework.boot' version '{gradle-project-version}' apply false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id("org.springframework.boot") version "{gradle-project-version}" apply false
}
Loading

0 comments on commit 99142db

Please sign in to comment.