From 0bc499919b253a12463964a5b97a6deebef8ee62 Mon Sep 17 00:00:00 2001 From: Carlos Cerrillo Date: Thu, 28 Sep 2023 11:33:58 +0200 Subject: [PATCH] Replace special characters with hyphen in featureName In preparation for future Maven updates that may not support certain characters, this commit updates the featureVersion method to replace especial characters, including '/', ':', '"', '<', '>', '|', '?', '*', and '\', with a hyphen ('-') in the featureName parameter. Additionally, it ensures that multiple hyphens are not consecutively present in the result. --- .../plugin/gitflow/GitFlowVersionInfo.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowVersionInfo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowVersionInfo.java index 07cd34e6..a5234721 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowVersionInfo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowVersionInfo.java @@ -28,10 +28,10 @@ /** * Git flow {@link org.apache.maven.shared.release.versions.VersionInfo} * implementation. Adds few convenient methods. - * + * */ public class GitFlowVersionInfo extends DefaultVersionInfo { - + private final VersionPolicy versionPolicy; public GitFlowVersionInfo(final String version, final VersionPolicy versionPolicy) @@ -42,7 +42,7 @@ public GitFlowVersionInfo(final String version, final VersionPolicy versionPolic /** * Returns a new GitFlowVersionInfo that holds only digits in the version. - * + * * @return Digits only GitFlowVersionInfo instance. * @throws VersionParseException * If version parsing fails. @@ -53,7 +53,7 @@ public GitFlowVersionInfo digitsVersionInfo() throws VersionParseException { /** * Validates version. - * + * * @param version * Version to validate. * @return true when version is valid, false @@ -80,7 +80,7 @@ public String getReleaseVersionString() { /** * Gets next SNAPSHOT version. - * + * * @return Next SNAPSHOT version. */ public String nextSnapshotVersion() { @@ -89,7 +89,7 @@ public String nextSnapshotVersion() { /** * Gets next SNAPSHOT version. - * + * * @param index * Which part of version to increment. * @return Next SNAPSHOT version. @@ -101,7 +101,7 @@ public String nextSnapshotVersion(final Integer index) { /** * Gets next version. If index is null or not valid then it * delegates to {@link #getNextVersion()} method. - * + * * @param index * Which part of version to increment. * @param snapshot @@ -147,7 +147,7 @@ private String nextVersion(final Integer index, boolean snapshot) { /** * Gets version with appended feature name. - * + * * @param featureName * Feature name to append. * @return Version with appended feature name. @@ -155,15 +155,20 @@ private String nextVersion(final Integer index, boolean snapshot) { public String featureVersion(final String featureName) { String version = toString(); if (featureName != null) { - version = getReleaseVersionString() + "-" + featureName + version = getReleaseVersionString() + "-" + getCleanedFeatureName(featureName) + (isSnapshot() ? "-" + Artifact.SNAPSHOT_VERSION : ""); } return version; } + public static String getCleanedFeatureName(String featureName) { + String cleanedFeatureName = featureName.replaceAll("[\\\\/:\"<>|?*]", "-"); + return cleanedFeatureName.replaceAll("-+", "-"); + } + /** * Gets next hotfix version. - * + * * @param preserveSnapshot * Whether to preserve SNAPSHOT in the version. * @param index