You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "HarshMehta112 (via GitHub)" <gi...@apache.org> on 2025/11/27 11:35:26 UTC
[PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
HarshMehta112 opened a new pull request, #1430:
URL: https://github.com/apache/maven-release/pull/1430
Following this checklist to help us incorporate your
contribution quickly and easily:
- [x] Your pull request should address just one issue, without pulling in other changes.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Each commit in the pull request should have a meaningful subject line and body.
Note that commits might be squashed by a maintainer on merge.
- [x] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
This may not always be possible but is a best-practice.
- [x] Run `mvn verify` to make sure basic checks pass.
A more thorough check will be performed on your pull request automatically.
- [x] You have run the integration tests successfully (`mvn -Prun-its verify`).
If your pull request is about ~20 lines of code you don't need to sign an
[Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure
please ask on the developers list.
**I've gone ahead and applied for the Individual Contributor License Agreement.**
To make clear that you license your contribution under
the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
you have to acknowledge this by using the following check-box.
- [x] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
- [x] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
# Replace archived `org.semver:api` with custom `SemVer` implementation
Fixed #1426
## What changed
- Removed dependency on the archived `org.semver:api` library.
- Introduced a custom internal semantic-versioning implementation: renamed class from `Version` → `SemVer`, and refactored related version-policy code under `maven-release-semver-policy`.
- Updated all references, method calls, and tests to use the new `SemVer` class.
- Existing unit and integration tests updated accordingly and pass successfully.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "HarshMehta112 (via GitHub)" <gi...@apache.org>.
HarshMehta112 commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2572078551
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/AbstarctSemVerVersionPolicy.java:
##########
@@ -31,19 +30,19 @@
*/
abstract class AbstarctSemVerVersionPolicy implements VersionPolicy {
- protected Version createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
+ protected SemVer createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
try {
- return Version.parse(request.getVersion());
+ return SemVer.parse(request.getVersion());
} catch (IllegalArgumentException e) {
throw new VersionParseException(e.getMessage());
}
}
- protected VersionPolicyResult createResult(Version version) {
+ protected VersionPolicyResult createResult(SemVer version) {
return new VersionPolicyResult().setVersion(version.toString());
}
- protected VersionPolicyResult createSnapshotResult(Version version) {
+ protected VersionPolicyResult createSnapshotResult(SemVer version) {
return new VersionPolicyResult().setVersion(version.toString() + "-SNAPSHOT");
Review Comment:
Updated to use the toSnapshotVersion method here.
##########
maven-release-policies/maven-release-semver-policy/src/test/java/org/apache/maven/shared/release/policy/semver/SemVerTest.java:
##########
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * Unit tests for the SemVer class.
+ */
+public class SemVerTest {
+
+ @Test
+ public void testParseSimpleVersion() {
Review Comment:
Implemented a parameterized test as suggested.
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVer.java:
##########
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A simple Semantic Versioning 2.0.0 implementation.
+ * <p>
+ * This class provides basic parsing and manipulation of semantic version strings
+ * following the format: MAJOR.MINOR.PATCH[-PRERELEASE][+METADATA]
+ * </p>
+ *
+ * @see <a href="https://semver.org/">Semantic Versioning 2.0.0</a>
+ */
+public class SemVer {
+
+ /**
+ * Regex pattern for parsing semantic versions from semver.org.
+ * Groups: 1=major, 2=minor, 3=patch, 4=prerelease, 5=metadata
+ *
+ * @see <a href="https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string">SemVer Regex</a>
+ */
+ private static final Pattern SEMVER_PATTERN = Pattern.compile("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)"
+ + "(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)"
+ + "(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$");
+
+ private final int major;
+ private final int minor;
+ private final int patch;
+ private final String preRelease;
+ private final String metadata;
+
+ /**
+ * Version element types that can be incremented.
+ */
+ public enum Element {
+ MAJOR,
+ MINOR,
+ PATCH
+ }
+
+ /**
+ * Constructs a new SemVer instance.
+ *
+ * @param major the major version number
+ * @param minor the minor version number
+ * @param patch the patch version number
+ * @param preRelease the pre-release identifier (can be null)
+ * @param metadata the build metadata (can be null)
+ */
+ public SemVer(int major, int minor, int patch, String preRelease, String metadata) {
+ if (major < 0 || minor < 0 || patch < 0) {
+ throw new IllegalArgumentException("Version numbers must be non-negative");
+ }
+ this.major = major;
+ this.minor = minor;
+ this.patch = patch;
+ this.preRelease = preRelease;
+ this.metadata = metadata;
+ }
+
+ /**
+ * Parses a version string into a SemVer object.
+ *
+ * @param version the version string to parse
+ * @return the parsed SemVer object
+ * @throws IllegalArgumentException if the version string is invalid
+ */
+ public static SemVer parse(String version) {
+ if (version == null || version.trim().isEmpty()) {
+ throw new IllegalArgumentException("Version string cannot be null or empty");
+ }
+
+ Matcher matcher = SEMVER_PATTERN.matcher(version.trim());
+ if (!matcher.matches()) {
+ throw new IllegalArgumentException("Invalid semantic version format: " + version);
+ }
+
+ int major = Integer.parseInt(matcher.group(1));
+ int minor = Integer.parseInt(matcher.group(2));
+ int patch = Integer.parseInt(matcher.group(3));
+ String preRelease = matcher.group(4);
+ String metadata = matcher.group(5);
+
+ return new SemVer(major, minor, patch, preRelease, metadata);
+ }
+
+ /**
+ * Returns a new SemVer with the release version (removes -SNAPSHOT and any pre-release/metadata).
+ * <p>
+ * Examples:
+ * <ul>
+ * <li>1.2.3-SNAPSHOT → 1.2.3</li>
+ * <li>1.2.3-beta+build → 1.2.3</li>
+ * <li>1.2.3 → 1.2.3</li>
+ * </ul>
+ *
+ * @return a new SemVer representing the release version
+ */
+ public SemVer toReleaseVersion() {
+ return new SemVer(major, minor, patch, null, null);
+ }
+
+ /**
+ * Returns a new SemVer with -SNAPSHOT appended as pre-release identifier.
+ * If the version already has a pre-release identifier, it will be replaced with SNAPSHOT.
+ * Metadata is removed.
+ * <p>
+ * Examples:
+ * <ul>
+ * <li>1.2.3 → 1.2.3-SNAPSHOT</li>
+ * <li>1.2.3-beta → 1.2.3-SNAPSHOT</li>
+ * <li>1.2.3+build → 1.2.3-SNAPSHOT</li>
+ * <li>1.2.3-SNAPSHOT → 1.2.3-SNAPSHOT (no change)</li>
+ * </ul>
+ *
+ * @return a new SemVer with SNAPSHOT pre-release identifier
+ */
+ public SemVer toSnapshotVersion() {
+ return new SemVer(major, minor, patch, "SNAPSHOT", null);
+ }
+
+ /**
+ * Returns a new SemVer with the specified element incremented.
+ * If the version has pre-release or metadata, returns the release version without incrementing.
+ * Otherwise, increments the specified element and all lower elements are reset to 0.
+ * Pre-release and metadata are always cleared in the result.
+ *
+ * @param element the element to increment (MAJOR, MINOR, or PATCH)
+ * @return a new SemVer with the specified element incremented (or release version if pre-release/metadata present)
+ */
+ public SemVer next(Element element) {
+ Objects.requireNonNull(element, "Element cannot be null");
+
+ // If version has pre-release or metadata, just return release version without incrementing
+ if (hasPreRelease() || hasMetadata()) {
+ return toReleaseVersion();
+ }
+
+ switch (element) {
+ case MAJOR:
+ return new SemVer(major + 1, 0, 0, null, null);
+ case MINOR:
+ return new SemVer(major, minor + 1, 0, null, null);
+ case PATCH:
+ return new SemVer(major, minor, patch + 1, null, null);
+ default:
+ throw new IllegalArgumentException("Unknown element: " + element);
+ }
+ }
+
+ /**
+ * Checks if this version has a pre-release identifier.
+ *
+ * @return true if pre-release identifier is present, false otherwise
+ */
+ public boolean hasPreRelease() {
+ return preRelease != null && !preRelease.isEmpty();
+ }
+
+ /**
+ * Checks if this version has build metadata.
+ *
+ * @return true if build metadata is present, false otherwise
+ */
+ public boolean hasMetadata() {
+ return metadata != null && !metadata.isEmpty();
+ }
+
+ /**
+ * Returns the major version number.
+ *
+ * @return the major version
+ */
+ public int getMajor() {
+ return major;
+ }
+
+ /**
+ * Returns the minor version number.
+ *
+ * @return the minor version
+ */
+ public int getMinor() {
+ return minor;
+ }
+
+ /**
+ * Returns the patch version number.
+ *
+ * @return the patch version
+ */
+ public int getPatch() {
+ return patch;
+ }
+
+ /**
+ * Returns the pre-release identifier.
+ *
+ * @return the pre-release identifier, or null if not present
+ */
+ public String getPreRelease() {
+ return preRelease;
+ }
+
+ /**
+ * Returns the build metadata.
+ *
+ * @return the build metadata, or null if not present
+ */
+ public String getMetadata() {
+ return metadata;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(major).append('.').append(minor).append('.').append(patch);
+
+ if (preRelease != null && !preRelease.isEmpty()) {
+ sb.append('-').append(preRelease);
+ }
+
+ if (metadata != null && !metadata.isEmpty()) {
+ sb.append('+').append(metadata);
+ }
+
+ return sb.toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
Review Comment:
Currently removing equals and hashCode because we don’t strictly need them right now. My thought process is that if in the future we need to compare SemVer objects by value or use them in hash-based collections.
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVer.java:
##########
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A simple Semantic Versioning 2.0.0 implementation.
+ * <p>
+ * This class provides basic parsing and manipulation of semantic version strings
+ * following the format: MAJOR.MINOR.PATCH[-PRERELEASE][+METADATA]
+ * </p>
+ *
+ * @see <a href="https://semver.org/">Semantic Versioning 2.0.0</a>
+ */
+public class SemVer {
+
+ /**
+ * Regex pattern for parsing semantic versions from semver.org.
+ * Groups: 1=major, 2=minor, 3=patch, 4=prerelease, 5=metadata
+ *
+ * @see <a href="https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string">SemVer Regex</a>
+ */
+ private static final Pattern SEMVER_PATTERN = Pattern.compile("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)"
+ + "(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)"
+ + "(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$");
+
+ private final int major;
+ private final int minor;
+ private final int patch;
+ private final String preRelease;
+ private final String metadata;
+
+ /**
+ * Version element types that can be incremented.
+ */
+ public enum Element {
+ MAJOR,
+ MINOR,
+ PATCH
+ }
+
+ /**
+ * Constructs a new SemVer instance.
+ *
+ * @param major the major version number
+ * @param minor the minor version number
+ * @param patch the patch version number
+ * @param preRelease the pre-release identifier (can be null)
+ * @param metadata the build metadata (can be null)
+ */
+ public SemVer(int major, int minor, int patch, String preRelease, String metadata) {
+ if (major < 0 || minor < 0 || patch < 0) {
+ throw new IllegalArgumentException("Version numbers must be non-negative");
+ }
+ this.major = major;
+ this.minor = minor;
+ this.patch = patch;
+ this.preRelease = preRelease;
+ this.metadata = metadata;
+ }
+
+ /**
+ * Parses a version string into a SemVer object.
+ *
+ * @param version the version string to parse
+ * @return the parsed SemVer object
+ * @throws IllegalArgumentException if the version string is invalid
+ */
+ public static SemVer parse(String version) {
+ if (version == null || version.trim().isEmpty()) {
+ throw new IllegalArgumentException("Version string cannot be null or empty");
+ }
+
+ Matcher matcher = SEMVER_PATTERN.matcher(version.trim());
+ if (!matcher.matches()) {
+ throw new IllegalArgumentException("Invalid semantic version format: " + version);
+ }
+
+ int major = Integer.parseInt(matcher.group(1));
+ int minor = Integer.parseInt(matcher.group(2));
+ int patch = Integer.parseInt(matcher.group(3));
+ String preRelease = matcher.group(4);
+ String metadata = matcher.group(5);
+
+ return new SemVer(major, minor, patch, preRelease, metadata);
+ }
+
+ /**
+ * Returns a new SemVer with the release version (removes -SNAPSHOT and any pre-release/metadata).
+ * <p>
+ * Examples:
+ * <ul>
+ * <li>1.2.3-SNAPSHOT → 1.2.3</li>
+ * <li>1.2.3-beta+build → 1.2.3</li>
+ * <li>1.2.3 → 1.2.3</li>
+ * </ul>
+ *
+ * @return a new SemVer representing the release version
+ */
+ public SemVer toReleaseVersion() {
+ return new SemVer(major, minor, patch, null, null);
+ }
+
+ /**
+ * Returns a new SemVer with -SNAPSHOT appended as pre-release identifier.
+ * If the version already has a pre-release identifier, it will be replaced with SNAPSHOT.
+ * Metadata is removed.
+ * <p>
+ * Examples:
+ * <ul>
+ * <li>1.2.3 → 1.2.3-SNAPSHOT</li>
+ * <li>1.2.3-beta → 1.2.3-SNAPSHOT</li>
+ * <li>1.2.3+build → 1.2.3-SNAPSHOT</li>
+ * <li>1.2.3-SNAPSHOT → 1.2.3-SNAPSHOT (no change)</li>
+ * </ul>
+ *
+ * @return a new SemVer with SNAPSHOT pre-release identifier
+ */
+ public SemVer toSnapshotVersion() {
+ return new SemVer(major, minor, patch, "SNAPSHOT", null);
+ }
+
+ /**
+ * Returns a new SemVer with the specified element incremented.
+ * If the version has pre-release or metadata, returns the release version without incrementing.
+ * Otherwise, increments the specified element and all lower elements are reset to 0.
+ * Pre-release and metadata are always cleared in the result.
+ *
+ * @param element the element to increment (MAJOR, MINOR, or PATCH)
+ * @return a new SemVer with the specified element incremented (or release version if pre-release/metadata present)
+ */
+ public SemVer next(Element element) {
+ Objects.requireNonNull(element, "Element cannot be null");
+
+ // If version has pre-release or metadata, just return release version without incrementing
+ if (hasPreRelease() || hasMetadata()) {
+ return toReleaseVersion();
+ }
+
+ switch (element) {
+ case MAJOR:
+ return new SemVer(major + 1, 0, 0, null, null);
+ case MINOR:
+ return new SemVer(major, minor + 1, 0, null, null);
+ case PATCH:
+ return new SemVer(major, minor, patch + 1, null, null);
+ default:
+ throw new IllegalArgumentException("Unknown element: " + element);
+ }
+ }
+
+ /**
+ * Checks if this version has a pre-release identifier.
+ *
+ * @return true if pre-release identifier is present, false otherwise
+ */
+ public boolean hasPreRelease() {
Review Comment:
I’ve updated the visibility to private
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2569572390
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVer.java:
##########
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A simple Semantic Versioning 2.0.0 implementation.
+ * <p>
+ * This class provides basic parsing and manipulation of semantic version strings
+ * following the format: MAJOR.MINOR.PATCH[-PRERELEASE][+METADATA]
+ * </p>
+ *
+ * @see <a href="https://semver.org/">Semantic Versioning 2.0.0</a>
+ */
+public class SemVer {
+
+ /**
+ * Regex pattern for parsing semantic versions from semver.org.
+ * Groups: 1=major, 2=minor, 3=patch, 4=prerelease, 5=metadata
+ *
+ * @see <a href="https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string">SemVer Regex</a>
+ */
+ private static final Pattern SEMVER_PATTERN = Pattern.compile("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)"
+ + "(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)"
+ + "(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$");
+
+ private final int major;
+ private final int minor;
+ private final int patch;
+ private final String preRelease;
+ private final String metadata;
+
+ /**
+ * Version element types that can be incremented.
+ */
+ public enum Element {
+ MAJOR,
+ MINOR,
+ PATCH
+ }
+
+ /**
+ * Constructs a new SemVer instance.
+ *
+ * @param major the major version number
+ * @param minor the minor version number
+ * @param patch the patch version number
+ * @param preRelease the pre-release identifier (can be null)
+ * @param metadata the build metadata (can be null)
+ */
+ public SemVer(int major, int minor, int patch, String preRelease, String metadata) {
+ if (major < 0 || minor < 0 || patch < 0) {
+ throw new IllegalArgumentException("Version numbers must be non-negative");
+ }
+ this.major = major;
+ this.minor = minor;
+ this.patch = patch;
+ this.preRelease = preRelease;
+ this.metadata = metadata;
+ }
+
+ /**
+ * Parses a version string into a SemVer object.
+ *
+ * @param version the version string to parse
+ * @return the parsed SemVer object
+ * @throws IllegalArgumentException if the version string is invalid
+ */
+ public static SemVer parse(String version) {
+ if (version == null || version.trim().isEmpty()) {
+ throw new IllegalArgumentException("Version string cannot be null or empty");
+ }
+
+ Matcher matcher = SEMVER_PATTERN.matcher(version.trim());
+ if (!matcher.matches()) {
+ throw new IllegalArgumentException("Invalid semantic version format: " + version);
+ }
+
+ int major = Integer.parseInt(matcher.group(1));
+ int minor = Integer.parseInt(matcher.group(2));
+ int patch = Integer.parseInt(matcher.group(3));
+ String preRelease = matcher.group(4);
+ String metadata = matcher.group(5);
+
+ return new SemVer(major, minor, patch, preRelease, metadata);
+ }
+
+ /**
+ * Returns a new SemVer with the release version (removes -SNAPSHOT and any pre-release/metadata).
+ * <p>
+ * Examples:
+ * <ul>
+ * <li>1.2.3-SNAPSHOT → 1.2.3</li>
+ * <li>1.2.3-beta+build → 1.2.3</li>
+ * <li>1.2.3 → 1.2.3</li>
+ * </ul>
+ *
+ * @return a new SemVer representing the release version
+ */
+ public SemVer toReleaseVersion() {
+ return new SemVer(major, minor, patch, null, null);
+ }
+
+ /**
+ * Returns a new SemVer with -SNAPSHOT appended as pre-release identifier.
+ * If the version already has a pre-release identifier, it will be replaced with SNAPSHOT.
+ * Metadata is removed.
+ * <p>
+ * Examples:
+ * <ul>
+ * <li>1.2.3 → 1.2.3-SNAPSHOT</li>
+ * <li>1.2.3-beta → 1.2.3-SNAPSHOT</li>
+ * <li>1.2.3+build → 1.2.3-SNAPSHOT</li>
+ * <li>1.2.3-SNAPSHOT → 1.2.3-SNAPSHOT (no change)</li>
+ * </ul>
+ *
+ * @return a new SemVer with SNAPSHOT pre-release identifier
+ */
+ public SemVer toSnapshotVersion() {
+ return new SemVer(major, minor, patch, "SNAPSHOT", null);
+ }
+
+ /**
+ * Returns a new SemVer with the specified element incremented.
+ * If the version has pre-release or metadata, returns the release version without incrementing.
+ * Otherwise, increments the specified element and all lower elements are reset to 0.
+ * Pre-release and metadata are always cleared in the result.
+ *
+ * @param element the element to increment (MAJOR, MINOR, or PATCH)
+ * @return a new SemVer with the specified element incremented (or release version if pre-release/metadata present)
+ */
+ public SemVer next(Element element) {
+ Objects.requireNonNull(element, "Element cannot be null");
+
+ // If version has pre-release or metadata, just return release version without incrementing
+ if (hasPreRelease() || hasMetadata()) {
+ return toReleaseVersion();
+ }
+
+ switch (element) {
+ case MAJOR:
+ return new SemVer(major + 1, 0, 0, null, null);
+ case MINOR:
+ return new SemVer(major, minor + 1, 0, null, null);
+ case PATCH:
+ return new SemVer(major, minor, patch + 1, null, null);
+ default:
+ throw new IllegalArgumentException("Unknown element: " + element);
+ }
+ }
+
+ /**
+ * Checks if this version has a pre-release identifier.
+ *
+ * @return true if pre-release identifier is present, false otherwise
+ */
+ public boolean hasPreRelease() {
Review Comment:
used in line 155 - maybe can be private
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2569582289
##########
maven-release-policies/maven-release-semver-policy/src/test/java/org/apache/maven/shared/release/policy/semver/SemVerTest.java:
##########
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * Unit tests for the SemVer class.
+ */
+public class SemVerTest {
+
+ @Test
+ public void testParseSimpleVersion() {
Review Comment:
maybe parameterized test can be used ... for this and next similar
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2569588481
##########
maven-release-policies/maven-release-semver-policy/src/test/java/org/apache/maven/shared/release/policy/semver/SemVerTest.java:
##########
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * Unit tests for the SemVer class.
+ */
+public class SemVerTest {
+
+ @Test
+ public void testParseSimpleVersion() {
+ SemVer version = SemVer.parse("1.2.3");
+ assertEquals(1, version.getMajor());
+ assertEquals(2, version.getMinor());
+ assertEquals(3, version.getPatch());
+ assertNull(version.getPreRelease());
+ assertNull(version.getMetadata());
+ assertEquals("1.2.3", version.toString());
+ }
+
+ @Test
+ public void testParseVersionWithPreRelease() {
+ SemVer version = SemVer.parse("1.2.3-alpha.1");
+ assertEquals(1, version.getMajor());
+ assertEquals(2, version.getMinor());
+ assertEquals(3, version.getPatch());
+ assertEquals("alpha.1", version.getPreRelease());
+ assertNull(version.getMetadata());
+ assertEquals("1.2.3-alpha.1", version.toString());
+ }
+
+ @Test
+ public void testParseVersionWithMetadata() {
+ SemVer version = SemVer.parse("1.2.3+build.123");
+ assertEquals(1, version.getMajor());
+ assertEquals(2, version.getMinor());
+ assertEquals(3, version.getPatch());
+ assertNull(version.getPreRelease());
+ assertEquals("build.123", version.getMetadata());
+ assertEquals("1.2.3+build.123", version.toString());
+ }
+
+ @Test
+ public void testParseVersionWithPreReleaseAndMetadata() {
+ SemVer version = SemVer.parse("1.2.3-beta.2+build.456");
+ assertEquals(1, version.getMajor());
+ assertEquals(2, version.getMinor());
+ assertEquals(3, version.getPatch());
+ assertEquals("beta.2", version.getPreRelease());
+ assertEquals("build.456", version.getMetadata());
+ assertEquals("1.2.3-beta.2+build.456", version.toString());
+ }
+
+ @Test
+ public void testParseSnapshot() {
+ SemVer version = SemVer.parse("1.0.0-SNAPSHOT");
+ assertEquals(1, version.getMajor());
+ assertEquals(0, version.getMinor());
+ assertEquals(0, version.getPatch());
+ assertEquals("SNAPSHOT", version.getPreRelease());
+ assertEquals("1.0.0-SNAPSHOT", version.toString());
+ }
+
+ @Test
+ public void testParseInvalidVersionThrowsException() {
+ assertThrows(IllegalArgumentException.class, () -> SemVer.parse("invalid"));
+ assertThrows(IllegalArgumentException.class, () -> SemVer.parse("1.2"));
Review Comment:
here should be also parametrized test
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "pzygielo (via GitHub)" <gi...@apache.org>.
pzygielo commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2568362992
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/AbstarctSemVerVersionPolicy.java:
##########
@@ -31,19 +30,19 @@
*/
abstract class AbstarctSemVerVersionPolicy implements VersionPolicy {
- protected Version createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
+ protected SemVer createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
Review Comment:
Seems 13hrs ago it (almost) was: https://github.com/apache/maven-release/releases/tag/maven-release-3.3.0
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "pzygielo (via GitHub)" <gi...@apache.org>.
pzygielo commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2568355649
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/AbstarctSemVerVersionPolicy.java:
##########
@@ -31,19 +30,19 @@
*/
abstract class AbstarctSemVerVersionPolicy implements VersionPolicy {
- protected Version createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
+ protected SemVer createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
Review Comment:
> This is an API breaking change.
But was it ever released?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2569521302
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/AbstarctSemVerVersionPolicy.java:
##########
@@ -31,19 +30,19 @@
*/
abstract class AbstarctSemVerVersionPolicy implements VersionPolicy {
- protected Version createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
+ protected SemVer createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
Review Comment:
Yes it is internal class - name can be changed want you want
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "pzygielo (via GitHub)" <gi...@apache.org>.
pzygielo commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2568399654
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/AbstarctSemVerVersionPolicy.java:
##########
@@ -31,19 +30,19 @@
*/
abstract class AbstarctSemVerVersionPolicy implements VersionPolicy {
- protected Version createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
+ protected SemVer createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
Review Comment:
But the class has package visibility so this is not a part of API, is it?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "HarshMehta112 (via GitHub)" <gi...@apache.org>.
HarshMehta112 commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2572072798
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVer.java:
##########
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A simple Semantic Versioning 2.0.0 implementation.
+ * <p>
+ * This class provides basic parsing and manipulation of semantic version strings
+ * following the format: MAJOR.MINOR.PATCH[-PRERELEASE][+METADATA]
+ * </p>
+ *
+ * @see <a href="https://semver.org/">Semantic Versioning 2.0.0</a>
+ */
+public class SemVer {
Review Comment:
I’ve updated the visibility to package-private.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "pzygielo (via GitHub)" <gi...@apache.org>.
pzygielo commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2568362992
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/AbstarctSemVerVersionPolicy.java:
##########
@@ -31,19 +30,19 @@
*/
abstract class AbstarctSemVerVersionPolicy implements VersionPolicy {
- protected Version createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
+ protected SemVer createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
Review Comment:
Seems 13hrs ago it was: https://github.com/apache/maven-release/releases/tag/maven-release-3.3.0
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski merged PR #1430:
URL: https://github.com/apache/maven-release/pull/1430
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "HarshMehta112 (via GitHub)" <gi...@apache.org>.
HarshMehta112 commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2572075611
##########
maven-release-policies/maven-release-semver-policy/src/test/java/org/apache/maven/shared/release/policy/semver/SemVerTest.java:
##########
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * Unit tests for the SemVer class.
+ */
+public class SemVerTest {
+
+ @Test
+ public void testParseSimpleVersion() {
+ SemVer version = SemVer.parse("1.2.3");
+ assertEquals(1, version.getMajor());
+ assertEquals(2, version.getMinor());
+ assertEquals(3, version.getPatch());
+ assertNull(version.getPreRelease());
+ assertNull(version.getMetadata());
+ assertEquals("1.2.3", version.toString());
+ }
+
+ @Test
+ public void testParseVersionWithPreRelease() {
+ SemVer version = SemVer.parse("1.2.3-alpha.1");
+ assertEquals(1, version.getMajor());
+ assertEquals(2, version.getMinor());
+ assertEquals(3, version.getPatch());
+ assertEquals("alpha.1", version.getPreRelease());
+ assertNull(version.getMetadata());
+ assertEquals("1.2.3-alpha.1", version.toString());
+ }
+
+ @Test
+ public void testParseVersionWithMetadata() {
+ SemVer version = SemVer.parse("1.2.3+build.123");
+ assertEquals(1, version.getMajor());
+ assertEquals(2, version.getMinor());
+ assertEquals(3, version.getPatch());
+ assertNull(version.getPreRelease());
+ assertEquals("build.123", version.getMetadata());
+ assertEquals("1.2.3+build.123", version.toString());
+ }
+
+ @Test
+ public void testParseVersionWithPreReleaseAndMetadata() {
+ SemVer version = SemVer.parse("1.2.3-beta.2+build.456");
+ assertEquals(1, version.getMajor());
+ assertEquals(2, version.getMinor());
+ assertEquals(3, version.getPatch());
+ assertEquals("beta.2", version.getPreRelease());
+ assertEquals("build.456", version.getMetadata());
+ assertEquals("1.2.3-beta.2+build.456", version.toString());
+ }
+
+ @Test
+ public void testParseSnapshot() {
+ SemVer version = SemVer.parse("1.0.0-SNAPSHOT");
+ assertEquals(1, version.getMajor());
+ assertEquals(0, version.getMinor());
+ assertEquals(0, version.getPatch());
+ assertEquals("SNAPSHOT", version.getPreRelease());
+ assertEquals("1.0.0-SNAPSHOT", version.toString());
+ }
+
+ @Test
+ public void testParseInvalidVersionThrowsException() {
+ assertThrows(IllegalArgumentException.class, () -> SemVer.parse("invalid"));
+ assertThrows(IllegalArgumentException.class, () -> SemVer.parse("1.2"));
Review Comment:
Implemented a parameterized test as suggested.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "HarshMehta112 (via GitHub)" <gi...@apache.org>.
HarshMehta112 commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2572074565
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVer.java:
##########
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A simple Semantic Versioning 2.0.0 implementation.
+ * <p>
+ * This class provides basic parsing and manipulation of semantic version strings
+ * following the format: MAJOR.MINOR.PATCH[-PRERELEASE][+METADATA]
+ * </p>
+ *
+ * @see <a href="https://semver.org/">Semantic Versioning 2.0.0</a>
+ */
+public class SemVer {
Review Comment:
No, this class is not forked from the archived code. I wrote it myself, using SemVer 2.0.0 as a reference.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2569554199
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVer.java:
##########
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A simple Semantic Versioning 2.0.0 implementation.
+ * <p>
+ * This class provides basic parsing and manipulation of semantic version strings
+ * following the format: MAJOR.MINOR.PATCH[-PRERELEASE][+METADATA]
+ * </p>
+ *
+ * @see <a href="https://semver.org/">Semantic Versioning 2.0.0</a>
+ */
+public class SemVer {
Review Comment:
yes can be package visible
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2568465447
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/AbstarctSemVerVersionPolicy.java:
##########
@@ -31,19 +30,19 @@
*/
abstract class AbstarctSemVerVersionPolicy implements VersionPolicy {
- protected Version createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
+ protected SemVer createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
Review Comment:
True. So we don't have to worry about the visibility. I might go ahead and fix the spelling in a separate PR then. In fact I should just remove Abstract from the name completely.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2569550991
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/AbstarctSemVerVersionPolicy.java:
##########
@@ -31,19 +30,19 @@
*/
abstract class AbstarctSemVerVersionPolicy implements VersionPolicy {
Review Comment:
fixed in:
- #1431
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2568294781
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/AbstarctSemVerVersionPolicy.java:
##########
@@ -31,19 +30,19 @@
*/
abstract class AbstarctSemVerVersionPolicy implements VersionPolicy {
- protected Version createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
+ protected SemVer createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
Review Comment:
This is an API breaking change. I;'m not sure, but maybe we should add a new correctly spelled AbstractSemVerVersionPolicy class and deprecate this existing class.
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVerVersionPolicy.java:
##########
@@ -24,13 +24,11 @@
import org.apache.maven.shared.release.policy.version.VersionPolicyRequest;
import org.apache.maven.shared.release.policy.version.VersionPolicyResult;
import org.apache.maven.shared.release.versions.VersionParseException;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* Uses SemVer implementation to increase minor element when resolving the development version.
- *
- * @deprecated use {@link SemVerMinorDevelopmentVersionPolicy} instead.
Review Comment:
This change seems possibly unrelated?
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVer.java:
##########
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A simple Semantic Versioning 2.0.0 implementation.
Review Comment:
Is 2.0.0 what we want? maven version comparison is only compatible with semver 1.0.0
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVer.java:
##########
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A simple Semantic Versioning 2.0.0 implementation.
+ * <p>
+ * This class provides basic parsing and manipulation of semantic version strings
+ * following the format: MAJOR.MINOR.PATCH[-PRERELEASE][+METADATA]
+ * </p>
+ *
+ * @see <a href="https://semver.org/">Semantic Versioning 2.0.0</a>
+ */
+public class SemVer {
Review Comment:
If we could not expose the type publicly for now, that would be good.
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVer.java:
##########
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A simple Semantic Versioning 2.0.0 implementation.
+ * <p>
+ * This class provides basic parsing and manipulation of semantic version strings
+ * following the format: MAJOR.MINOR.PATCH[-PRERELEASE][+METADATA]
+ * </p>
+ *
+ * @see <a href="https://semver.org/">Semantic Versioning 2.0.0</a>
+ */
+public class SemVer {
Review Comment:
Is this class forked from the archived code?
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVer.java:
##########
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A simple Semantic Versioning 2.0.0 implementation.
+ * <p>
+ * This class provides basic parsing and manipulation of semantic version strings
+ * following the format: MAJOR.MINOR.PATCH[-PRERELEASE][+METADATA]
+ * </p>
+ *
+ * @see <a href="https://semver.org/">Semantic Versioning 2.0.0</a>
+ */
+public class SemVer {
+
+ /**
+ * Regex pattern for parsing semantic versions from semver.org.
+ * Groups: 1=major, 2=minor, 3=patch, 4=prerelease, 5=metadata
+ *
+ * @see <a href="https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string">SemVer Regex</a>
+ */
+ private static final Pattern SEMVER_PATTERN = Pattern.compile("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)"
+ + "(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)"
+ + "(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$");
+
+ private final int major;
+ private final int minor;
+ private final int patch;
+ private final String preRelease;
+ private final String metadata;
+
+ /**
+ * Version element types that can be incremented.
+ */
+ public enum Element {
+ MAJOR,
+ MINOR,
+ PATCH
+ }
+
+ /**
+ * Constructs a new SemVer instance.
+ *
+ * @param major the major version number
+ * @param minor the minor version number
+ * @param patch the patch version number
+ * @param preRelease the pre-release identifier (can be null)
+ * @param metadata the build metadata (can be null)
+ */
+ public SemVer(int major, int minor, int patch, String preRelease, String metadata) {
+ if (major < 0 || minor < 0 || patch < 0) {
+ throw new IllegalArgumentException("Version numbers must be non-negative");
+ }
+ this.major = major;
+ this.minor = minor;
+ this.patch = patch;
+ this.preRelease = preRelease;
+ this.metadata = metadata;
+ }
+
+ /**
+ * Parses a version string into a SemVer object.
+ *
+ * @param version the version string to parse
+ * @return the parsed SemVer object
+ * @throws IllegalArgumentException if the version string is invalid
+ */
+ public static SemVer parse(String version) {
+ if (version == null || version.trim().isEmpty()) {
+ throw new IllegalArgumentException("Version string cannot be null or empty");
+ }
+
+ Matcher matcher = SEMVER_PATTERN.matcher(version.trim());
+ if (!matcher.matches()) {
+ throw new IllegalArgumentException("Invalid semantic version format: " + version);
+ }
+
+ int major = Integer.parseInt(matcher.group(1));
+ int minor = Integer.parseInt(matcher.group(2));
+ int patch = Integer.parseInt(matcher.group(3));
+ String preRelease = matcher.group(4);
+ String metadata = matcher.group(5);
+
+ return new SemVer(major, minor, patch, preRelease, metadata);
+ }
+
+ /**
+ * Returns a new SemVer with the release version (removes -SNAPSHOT and any pre-release/metadata).
+ * <p>
+ * Examples:
+ * <ul>
+ * <li>1.2.3-SNAPSHOT → 1.2.3</li>
+ * <li>1.2.3-beta+build → 1.2.3</li>
+ * <li>1.2.3 → 1.2.3</li>
+ * </ul>
+ *
+ * @return a new SemVer representing the release version
+ */
+ public SemVer toReleaseVersion() {
+ return new SemVer(major, minor, patch, null, null);
+ }
+
+ /**
+ * Returns a new SemVer with -SNAPSHOT appended as pre-release identifier.
+ * If the version already has a pre-release identifier, it will be replaced with SNAPSHOT.
+ * Metadata is removed.
+ * <p>
+ * Examples:
+ * <ul>
+ * <li>1.2.3 → 1.2.3-SNAPSHOT</li>
+ * <li>1.2.3-beta → 1.2.3-SNAPSHOT</li>
+ * <li>1.2.3+build → 1.2.3-SNAPSHOT</li>
+ * <li>1.2.3-SNAPSHOT → 1.2.3-SNAPSHOT (no change)</li>
+ * </ul>
+ *
+ * @return a new SemVer with SNAPSHOT pre-release identifier
+ */
+ public SemVer toSnapshotVersion() {
+ return new SemVer(major, minor, patch, "SNAPSHOT", null);
+ }
+
+ /**
+ * Returns a new SemVer with the specified element incremented.
+ * If the version has pre-release or metadata, returns the release version without incrementing.
+ * Otherwise, increments the specified element and all lower elements are reset to 0.
+ * Pre-release and metadata are always cleared in the result.
+ *
+ * @param element the element to increment (MAJOR, MINOR, or PATCH)
+ * @return a new SemVer with the specified element incremented (or release version if pre-release/metadata present)
+ */
+ public SemVer next(Element element) {
+ Objects.requireNonNull(element, "Element cannot be null");
+
+ // If version has pre-release or metadata, just return release version without incrementing
+ if (hasPreRelease() || hasMetadata()) {
+ return toReleaseVersion();
+ }
+
+ switch (element) {
+ case MAJOR:
+ return new SemVer(major + 1, 0, 0, null, null);
+ case MINOR:
+ return new SemVer(major, minor + 1, 0, null, null);
+ case PATCH:
+ return new SemVer(major, minor, patch + 1, null, null);
+ default:
+ throw new IllegalArgumentException("Unknown element: " + element);
+ }
+ }
+
+ /**
+ * Checks if this version has a pre-release identifier.
+ *
+ * @return true if pre-release identifier is present, false otherwise
+ */
+ public boolean hasPreRelease() {
Review Comment:
Are all these methods used? Any that are not should be removed.
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/AbstarctSemVerVersionPolicy.java:
##########
@@ -31,19 +30,19 @@
*/
abstract class AbstarctSemVerVersionPolicy implements VersionPolicy {
Review Comment:
we misspelled this class name, didn't we? Bleah.
##########
maven-release-policies/maven-release-semver-policy/src/test/java/org/apache/maven/shared/release/policy/semver/SemVerTest.java:
##########
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * Unit tests for the SemVer class.
+ */
+public class SemVerTest {
+
+ @Test
+ public void testParseSimpleVersion() {
+ SemVer version = SemVer.parse("1.2.3");
+ assertEquals(1, version.getMajor());
+ assertEquals(2, version.getMinor());
+ assertEquals(3, version.getPatch());
+ assertNull(version.getPreRelease());
+ assertNull(version.getMetadata());
+ assertEquals("1.2.3", version.toString());
+ }
+
+ @Test
+ public void testParseVersionWithPreRelease() {
+ SemVer version = SemVer.parse("1.2.3-alpha.1");
+ assertEquals(1, version.getMajor());
+ assertEquals(2, version.getMinor());
+ assertEquals(3, version.getPatch());
+ assertEquals("alpha.1", version.getPreRelease());
+ assertNull(version.getMetadata());
+ assertEquals("1.2.3-alpha.1", version.toString());
+ }
+
+ @Test
+ public void testParseVersionWithMetadata() {
+ SemVer version = SemVer.parse("1.2.3+build.123");
+ assertEquals(1, version.getMajor());
+ assertEquals(2, version.getMinor());
+ assertEquals(3, version.getPatch());
+ assertNull(version.getPreRelease());
+ assertEquals("build.123", version.getMetadata());
+ assertEquals("1.2.3+build.123", version.toString());
+ }
+
+ @Test
+ public void testParseVersionWithPreReleaseAndMetadata() {
+ SemVer version = SemVer.parse("1.2.3-beta.2+build.456");
+ assertEquals(1, version.getMajor());
+ assertEquals(2, version.getMinor());
+ assertEquals(3, version.getPatch());
+ assertEquals("beta.2", version.getPreRelease());
+ assertEquals("build.456", version.getMetadata());
+ assertEquals("1.2.3-beta.2+build.456", version.toString());
+ }
+
+ @Test
+ public void testParseSnapshot() {
+ SemVer version = SemVer.parse("1.0.0-SNAPSHOT");
+ assertEquals(1, version.getMajor());
+ assertEquals(0, version.getMinor());
+ assertEquals(0, version.getPatch());
+ assertEquals("SNAPSHOT", version.getPreRelease());
+ assertEquals("1.0.0-SNAPSHOT", version.toString());
+ }
+
+ @Test
+ public void testParseInvalidVersionThrowsException() {
+ assertThrows(IllegalArgumentException.class, () -> SemVer.parse("invalid"));
+ assertThrows(IllegalArgumentException.class, () -> SemVer.parse("1.2"));
Review Comment:
why does this throw? I thought 1.2 would be OK.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "HarshMehta112 (via GitHub)" <gi...@apache.org>.
HarshMehta112 commented on PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#issuecomment-3586137846
@elharo @slawekjaranowski
Could you please clarify how you would like this feature to be implemented? As discussed with @slawekjaranowski, the suggestion was to follow the SemVer 2.0.0 specification (https://github.com/apache/maven-release/issues/1426). I also observed that the existing SemVerVersion-related policies and test cases are already aligned with SemVer 2.0.0, and we could potentially use the recommended regular expression provided in the SemVer documentation: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string.
However, @elharo pointed out that Maven only compatible with SemVer 1.0.0.
Since I am still new to open-source contribution, I am trying to fully understand the intended direction. Could you please advise on the preferred approach so I can proceed accordingly?
Thank you!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2569564913
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVer.java:
##########
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A simple Semantic Versioning 2.0.0 implementation.
Review Comment:
It is not a default versioning policy - it is a possibility which can be used
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2569576759
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/AbstarctSemVerVersionPolicy.java:
##########
@@ -31,19 +30,19 @@
*/
abstract class AbstarctSemVerVersionPolicy implements VersionPolicy {
- protected Version createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
+ protected SemVer createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
try {
- return Version.parse(request.getVersion());
+ return SemVer.parse(request.getVersion());
} catch (IllegalArgumentException e) {
throw new VersionParseException(e.getMessage());
}
}
- protected VersionPolicyResult createResult(Version version) {
+ protected VersionPolicyResult createResult(SemVer version) {
return new VersionPolicyResult().setVersion(version.toString());
}
- protected VersionPolicyResult createSnapshotResult(Version version) {
+ protected VersionPolicyResult createSnapshotResult(SemVer version) {
return new VersionPolicyResult().setVersion(version.toString() + "-SNAPSHOT");
Review Comment:
`toSnapshotVersion` method should be used here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2569521302
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/AbstarctSemVerVersionPolicy.java:
##########
@@ -31,19 +30,19 @@
*/
abstract class AbstarctSemVerVersionPolicy implements VersionPolicy {
- protected Version createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
+ protected SemVer createVersionFromRequest(VersionPolicyRequest request) throws VersionParseException {
Review Comment:
Yes it is internal class - name and internals can be changed want you want
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#issuecomment-3590164567
@elharo @kwin look ok for me
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "HarshMehta112 (via GitHub)" <gi...@apache.org>.
HarshMehta112 commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2568904195
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVerVersionPolicy.java:
##########
@@ -24,13 +24,11 @@
import org.apache.maven.shared.release.policy.version.VersionPolicyRequest;
import org.apache.maven.shared.release.policy.version.VersionPolicyResult;
import org.apache.maven.shared.release.versions.VersionParseException;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* Uses SemVer implementation to increase minor element when resolving the development version.
- *
- * @deprecated use {@link SemVerMinorDevelopmentVersionPolicy} instead.
Review Comment:
Removed unrelated changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2569593359
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVer.java:
##########
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A simple Semantic Versioning 2.0.0 implementation.
+ * <p>
+ * This class provides basic parsing and manipulation of semantic version strings
+ * following the format: MAJOR.MINOR.PATCH[-PRERELEASE][+METADATA]
+ * </p>
+ *
+ * @see <a href="https://semver.org/">Semantic Versioning 2.0.0</a>
+ */
+public class SemVer {
+
+ /**
+ * Regex pattern for parsing semantic versions from semver.org.
+ * Groups: 1=major, 2=minor, 3=patch, 4=prerelease, 5=metadata
+ *
+ * @see <a href="https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string">SemVer Regex</a>
+ */
+ private static final Pattern SEMVER_PATTERN = Pattern.compile("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)"
+ + "(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)"
+ + "(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$");
+
+ private final int major;
+ private final int minor;
+ private final int patch;
+ private final String preRelease;
+ private final String metadata;
+
+ /**
+ * Version element types that can be incremented.
+ */
+ public enum Element {
+ MAJOR,
+ MINOR,
+ PATCH
+ }
+
+ /**
+ * Constructs a new SemVer instance.
+ *
+ * @param major the major version number
+ * @param minor the minor version number
+ * @param patch the patch version number
+ * @param preRelease the pre-release identifier (can be null)
+ * @param metadata the build metadata (can be null)
+ */
+ public SemVer(int major, int minor, int patch, String preRelease, String metadata) {
+ if (major < 0 || minor < 0 || patch < 0) {
+ throw new IllegalArgumentException("Version numbers must be non-negative");
+ }
+ this.major = major;
+ this.minor = minor;
+ this.patch = patch;
+ this.preRelease = preRelease;
+ this.metadata = metadata;
+ }
+
+ /**
+ * Parses a version string into a SemVer object.
+ *
+ * @param version the version string to parse
+ * @return the parsed SemVer object
+ * @throws IllegalArgumentException if the version string is invalid
+ */
+ public static SemVer parse(String version) {
+ if (version == null || version.trim().isEmpty()) {
+ throw new IllegalArgumentException("Version string cannot be null or empty");
+ }
+
+ Matcher matcher = SEMVER_PATTERN.matcher(version.trim());
+ if (!matcher.matches()) {
+ throw new IllegalArgumentException("Invalid semantic version format: " + version);
+ }
+
+ int major = Integer.parseInt(matcher.group(1));
+ int minor = Integer.parseInt(matcher.group(2));
+ int patch = Integer.parseInt(matcher.group(3));
+ String preRelease = matcher.group(4);
+ String metadata = matcher.group(5);
+
+ return new SemVer(major, minor, patch, preRelease, metadata);
+ }
+
+ /**
+ * Returns a new SemVer with the release version (removes -SNAPSHOT and any pre-release/metadata).
+ * <p>
+ * Examples:
+ * <ul>
+ * <li>1.2.3-SNAPSHOT → 1.2.3</li>
+ * <li>1.2.3-beta+build → 1.2.3</li>
+ * <li>1.2.3 → 1.2.3</li>
+ * </ul>
+ *
+ * @return a new SemVer representing the release version
+ */
+ public SemVer toReleaseVersion() {
+ return new SemVer(major, minor, patch, null, null);
+ }
+
+ /**
+ * Returns a new SemVer with -SNAPSHOT appended as pre-release identifier.
+ * If the version already has a pre-release identifier, it will be replaced with SNAPSHOT.
+ * Metadata is removed.
+ * <p>
+ * Examples:
+ * <ul>
+ * <li>1.2.3 → 1.2.3-SNAPSHOT</li>
+ * <li>1.2.3-beta → 1.2.3-SNAPSHOT</li>
+ * <li>1.2.3+build → 1.2.3-SNAPSHOT</li>
+ * <li>1.2.3-SNAPSHOT → 1.2.3-SNAPSHOT (no change)</li>
+ * </ul>
+ *
+ * @return a new SemVer with SNAPSHOT pre-release identifier
+ */
+ public SemVer toSnapshotVersion() {
+ return new SemVer(major, minor, patch, "SNAPSHOT", null);
+ }
+
+ /**
+ * Returns a new SemVer with the specified element incremented.
+ * If the version has pre-release or metadata, returns the release version without incrementing.
+ * Otherwise, increments the specified element and all lower elements are reset to 0.
+ * Pre-release and metadata are always cleared in the result.
+ *
+ * @param element the element to increment (MAJOR, MINOR, or PATCH)
+ * @return a new SemVer with the specified element incremented (or release version if pre-release/metadata present)
+ */
+ public SemVer next(Element element) {
+ Objects.requireNonNull(element, "Element cannot be null");
+
+ // If version has pre-release or metadata, just return release version without incrementing
+ if (hasPreRelease() || hasMetadata()) {
+ return toReleaseVersion();
+ }
+
+ switch (element) {
+ case MAJOR:
+ return new SemVer(major + 1, 0, 0, null, null);
+ case MINOR:
+ return new SemVer(major, minor + 1, 0, null, null);
+ case PATCH:
+ return new SemVer(major, minor, patch + 1, null, null);
+ default:
+ throw new IllegalArgumentException("Unknown element: " + element);
+ }
+ }
+
+ /**
+ * Checks if this version has a pre-release identifier.
+ *
+ * @return true if pre-release identifier is present, false otherwise
+ */
+ public boolean hasPreRelease() {
+ return preRelease != null && !preRelease.isEmpty();
+ }
+
+ /**
+ * Checks if this version has build metadata.
+ *
+ * @return true if build metadata is present, false otherwise
+ */
+ public boolean hasMetadata() {
+ return metadata != null && !metadata.isEmpty();
+ }
+
+ /**
+ * Returns the major version number.
+ *
+ * @return the major version
+ */
+ public int getMajor() {
+ return major;
+ }
+
+ /**
+ * Returns the minor version number.
+ *
+ * @return the minor version
+ */
+ public int getMinor() {
+ return minor;
+ }
+
+ /**
+ * Returns the patch version number.
+ *
+ * @return the patch version
+ */
+ public int getPatch() {
+ return patch;
+ }
+
+ /**
+ * Returns the pre-release identifier.
+ *
+ * @return the pre-release identifier, or null if not present
+ */
+ public String getPreRelease() {
+ return preRelease;
+ }
+
+ /**
+ * Returns the build metadata.
+ *
+ * @return the build metadata, or null if not present
+ */
+ public String getMetadata() {
+ return metadata;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(major).append('.').append(minor).append('.').append(patch);
+
+ if (preRelease != null && !preRelease.isEmpty()) {
+ sb.append('-').append(preRelease);
+ }
+
+ if (metadata != null && !metadata.isEmpty()) {
+ sb.append('+').append(metadata);
+ }
+
+ return sb.toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
Review Comment:
I dont't know if we need equals and hashCode
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2569587609
##########
maven-release-policies/maven-release-semver-policy/src/test/java/org/apache/maven/shared/release/policy/semver/SemVerTest.java:
##########
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * Unit tests for the SemVer class.
+ */
+public class SemVerTest {
+
+ @Test
+ public void testParseSimpleVersion() {
+ SemVer version = SemVer.parse("1.2.3");
+ assertEquals(1, version.getMajor());
+ assertEquals(2, version.getMinor());
+ assertEquals(3, version.getPatch());
+ assertNull(version.getPreRelease());
+ assertNull(version.getMetadata());
+ assertEquals("1.2.3", version.toString());
+ }
+
+ @Test
+ public void testParseVersionWithPreRelease() {
+ SemVer version = SemVer.parse("1.2.3-alpha.1");
+ assertEquals(1, version.getMajor());
+ assertEquals(2, version.getMinor());
+ assertEquals(3, version.getPatch());
+ assertEquals("alpha.1", version.getPreRelease());
+ assertNull(version.getMetadata());
+ assertEquals("1.2.3-alpha.1", version.toString());
+ }
+
+ @Test
+ public void testParseVersionWithMetadata() {
+ SemVer version = SemVer.parse("1.2.3+build.123");
+ assertEquals(1, version.getMajor());
+ assertEquals(2, version.getMinor());
+ assertEquals(3, version.getPatch());
+ assertNull(version.getPreRelease());
+ assertEquals("build.123", version.getMetadata());
+ assertEquals("1.2.3+build.123", version.toString());
+ }
+
+ @Test
+ public void testParseVersionWithPreReleaseAndMetadata() {
+ SemVer version = SemVer.parse("1.2.3-beta.2+build.456");
+ assertEquals(1, version.getMajor());
+ assertEquals(2, version.getMinor());
+ assertEquals(3, version.getPatch());
+ assertEquals("beta.2", version.getPreRelease());
+ assertEquals("build.456", version.getMetadata());
+ assertEquals("1.2.3-beta.2+build.456", version.toString());
+ }
+
+ @Test
+ public void testParseSnapshot() {
+ SemVer version = SemVer.parse("1.0.0-SNAPSHOT");
+ assertEquals(1, version.getMajor());
+ assertEquals(0, version.getMinor());
+ assertEquals(0, version.getPatch());
+ assertEquals("SNAPSHOT", version.getPreRelease());
+ assertEquals("1.0.0-SNAPSHOT", version.toString());
+ }
+
+ @Test
+ public void testParseInvalidVersionThrowsException() {
+ assertThrows(IllegalArgumentException.class, () -> SemVer.parse("invalid"));
+ assertThrows(IllegalArgumentException.class, () -> SemVer.parse("1.2"));
Review Comment:
1.2 is not a semantic versioning
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fixed #1426 : Fix(maven-release-semver-policy) : Replace archived `org.semver:api` with custom `SemVer` implementation [maven-release]
Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on code in PR #1430:
URL: https://github.com/apache/maven-release/pull/1430#discussion_r2569558997
##########
maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVer.java:
##########
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.maven.shared.release.policy.semver;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A simple Semantic Versioning 2.0.0 implementation.
Review Comment:
It is not a Maven versioning strict - it is a policy which can be used for managing next version for released artifacts
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org