From d5483f7cbbeb128f3fb44651206fffb9bda4dcb3 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Wed, 5 Jan 2022 09:59:18 -0600 Subject: [PATCH] Antora prerelease: true for milestone and rc --- .../antora/CheckAntoraVersionPlugin.java | 24 +++++++++++++------ .../antora/CheckAntoraVersionPluginTests.java | 12 +++++----- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/gradle/antora/CheckAntoraVersionPlugin.java b/buildSrc/src/main/java/org/springframework/gradle/antora/CheckAntoraVersionPlugin.java index 50bc8ea59d..a0dcb966cc 100644 --- a/buildSrc/src/main/java/org/springframework/gradle/antora/CheckAntoraVersionPlugin.java +++ b/buildSrc/src/main/java/org/springframework/gradle/antora/CheckAntoraVersionPlugin.java @@ -38,14 +38,20 @@ public class CheckAntoraVersionPlugin implements Plugin { private static String getDefaultAntoraVersion(Project project) { String projectVersion = getProjectVersion(project); - int preReleaseIndex = getPreReleaseIndex(projectVersion); - return isPreRelease(projectVersion) ? projectVersion.substring(0, preReleaseIndex) : projectVersion; + int preReleaseIndex = getSnapshotIndex(projectVersion); + return isSnapshot(projectVersion) ? projectVersion.substring(0, preReleaseIndex) : projectVersion; } private static String getDefaultAntoraPrerelease(Project project) { String projectVersion = getProjectVersion(project); - int preReleaseIndex = getPreReleaseIndex(projectVersion); - return isPreRelease(projectVersion) ? projectVersion.substring(preReleaseIndex) : null; + if (isSnapshot(projectVersion)) { + int preReleaseIndex = getSnapshotIndex(projectVersion); + return projectVersion.substring(preReleaseIndex); + } + if (isPreRelease(projectVersion)) { + return Boolean.TRUE.toString(); + } + return null; } private static String getProjectVersion(Project project) { @@ -56,11 +62,15 @@ public class CheckAntoraVersionPlugin implements Plugin { return String.valueOf(projectVersion); } - private static int getPreReleaseIndex(String projectVersion) { - return projectVersion.lastIndexOf("-"); + private static boolean isSnapshot(String projectVersion) { + return getSnapshotIndex(projectVersion) >= 0; + } + + private static int getSnapshotIndex(String projectVersion) { + return projectVersion.lastIndexOf("-SNAPSHOT"); } private static boolean isPreRelease(String projectVersion) { - return getPreReleaseIndex(projectVersion) >= 0; + return projectVersion.lastIndexOf("-") >= 0; } } diff --git a/buildSrc/src/test/java/org/springframework/gradle/antora/CheckAntoraVersionPluginTests.java b/buildSrc/src/test/java/org/springframework/gradle/antora/CheckAntoraVersionPluginTests.java index 719ab68ac2..81f5502572 100644 --- a/buildSrc/src/test/java/org/springframework/gradle/antora/CheckAntoraVersionPluginTests.java +++ b/buildSrc/src/test/java/org/springframework/gradle/antora/CheckAntoraVersionPluginTests.java @@ -46,8 +46,8 @@ class CheckAntoraVersionPluginTests { assertThat(task).isInstanceOf(CheckAntoraVersionTask.class); CheckAntoraVersionTask checkAntoraVersionTask = (CheckAntoraVersionTask) task; - assertThat(checkAntoraVersionTask.getAntoraVersion().get()).isEqualTo("1.0.0"); - assertThat(checkAntoraVersionTask.getAntoraPrerelease().get()).isEqualTo("-M1"); + assertThat(checkAntoraVersionTask.getAntoraVersion().get()).isEqualTo("1.0.0-M1"); + assertThat(checkAntoraVersionTask.getAntoraPrerelease().get()).isEqualTo("true"); assertThat(checkAntoraVersionTask.getAntoraYmlFile().getAsFile().get()).isEqualTo(project.file("antora.yml")); } @@ -63,8 +63,8 @@ class CheckAntoraVersionPluginTests { assertThat(task).isInstanceOf(CheckAntoraVersionTask.class); CheckAntoraVersionTask checkAntoraVersionTask = (CheckAntoraVersionTask) task; - assertThat(checkAntoraVersionTask.getAntoraVersion().get()).isEqualTo("1.0.0"); - assertThat(checkAntoraVersionTask.getAntoraPrerelease().get()).isEqualTo("-RC1"); + assertThat(checkAntoraVersionTask.getAntoraVersion().get()).isEqualTo("1.0.0-RC1"); + assertThat(checkAntoraVersionTask.getAntoraPrerelease().get()).isEqualTo("true"); assertThat(checkAntoraVersionTask.getAntoraYmlFile().getAsFile().get()).isEqualTo(project.file("antora.yml")); } @@ -170,7 +170,7 @@ class CheckAntoraVersionPluginTests { String expectedVersion = "1.0.0-M1"; Project project = ProjectBuilder.builder().build(); File rootDir = project.getRootDir(); - IOUtils.write("version: '1.0.0'\nprerelease: '-M1'", new FileOutputStream(new File(rootDir, "antora.yml")), StandardCharsets.UTF_8); + IOUtils.write("version: '1.0.0-M1'\nprerelease: 'true'", new FileOutputStream(new File(rootDir, "antora.yml")), StandardCharsets.UTF_8); project.setVersion(expectedVersion); project.getPluginManager().apply(CheckAntoraVersionPlugin.class); @@ -187,7 +187,7 @@ class CheckAntoraVersionPluginTests { String expectedVersion = "1.0.0-RC1"; Project project = ProjectBuilder.builder().build(); File rootDir = project.getRootDir(); - IOUtils.write("version: '1.0.0'\nprerelease: '-RC1'", new FileOutputStream(new File(rootDir, "antora.yml")), StandardCharsets.UTF_8); + IOUtils.write("version: '1.0.0-RC1'\nprerelease: 'true'", new FileOutputStream(new File(rootDir, "antora.yml")), StandardCharsets.UTF_8); project.setVersion(expectedVersion); project.getPluginManager().apply(CheckAntoraVersionPlugin.class);