Minor change to Helidon version handling allowing snapshot versions (#19320)

* Minor change to Helidon version handling

Signed-off-by: Tim Quinn <tim.quinn@oracle.com>

* Update modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaHelidonCommonCodegen.java

Co-authored-by: martin-mfg <2026226+martin-mfg@users.noreply.github.com>

* Review comments: fix typo in comment

---------

Signed-off-by: Tim Quinn <tim.quinn@oracle.com>
Co-authored-by: martin-mfg <2026226+martin-mfg@users.noreply.github.com>
This commit is contained in:
Tim Quinn 2024-08-09 02:59:57 -05:00 committed by GitHub
parent ad7acc30eb
commit 07baddfe12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View File

@ -483,7 +483,7 @@ public abstract class JavaHelidonCommonCodegen extends AbstractJavaCodegen
}
private void setHelidonVersion(String version) {
helidonVersion = VersionUtil.instance().chooseVersion(version);
helidonVersion = VersionUtil.instance().chooseVersionBestMatchOrSelf(version);
setParentVersion(helidonVersion);
helidonMajorVersion = VersionUtil.majorVersion(helidonVersion);
}
@ -769,6 +769,30 @@ public abstract class JavaHelidonCommonCodegen extends AbstractJavaCodegen
return chooseVersion(requestedVersion, versions);
}
/**
* Returns either the best match version or, if there is none, the requested version itself to allow references to
* unpublished releases such as snapshots.
*
* @param requestedVersion version to search for
* @return either the best match or, if none, the requested version itself
*/
String chooseVersionBestMatchOrSelf(String requestedVersion) {
return chooseVersionBestMatchOrSelf(requestedVersion, versions);
}
/**
* Returns either the best match version or, if there is none, the requested version itself to allow references to
* unpublished releases such as snapshots.
*
* @param requestedVersion version to search for
* @param candidateVersions releases to consider
* @return either the best match or, if none, the requested version itself
*/
String chooseVersionBestMatchOrSelf(String requestedVersion, List<String> candidateVersions) {
String bestMatch = chooseVersion(requestedVersion, candidateVersions);
return bestMatch != null ? bestMatch : requestedVersion;
}
/**
* Returns the version that is the "closest" match to the requested version expression from among the provided
* releases, where the expression expression is one of the following:

View File

@ -48,4 +48,10 @@ public class HelidonCommonCodegenTest {
}
@Test void checkUseOfUnpublishedRelease() {
assertThat(test.chooseVersionBestMatchOrSelf("4.0.11-SNAPSHOT",
List.of("4.0.10", "3.2.1", "3.2.0", "2.0.4", "1.2.3", "1.2.2", "1.1.0")))
.isEqualTo("4.0.11-SNAPSHOT");
}
}