This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 37c952d645b build tooling - Should not change support level for
versions when changing x.y.z (z digit).
37c952d645b is described below
commit 37c952d645bb4737b2afe1cdebf53c7bf628ad09
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Jan 1 14:05:35 2023 +0100
build tooling - Should not change support level for versions when changing
x.y.z (z digit).
---
.../camel/tooling/util/CamelVersionHelper.java | 56 +------------
.../org/apache/camel/tooling/util/Version.java | 92 ++++++++++++++++++++++
.../camel/maven/packaging/SupportLevelHelper.java | 11 ++-
.../maven/packaging/SupportLevelHelperTest.java | 43 ++++++++++
4 files changed, 148 insertions(+), 54 deletions(-)
diff --git
a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/CamelVersionHelper.java
b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/CamelVersionHelper.java
index a572e45ebb4..80fd328971e 100644
---
a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/CamelVersionHelper.java
+++
b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/CamelVersionHelper.java
@@ -35,6 +35,10 @@ public final class CamelVersionHelper {
* @return <tt>true</tt> if GE, <tt>false</tt> otherwise
*/
public static boolean isGE(String base, String other) {
+ return isGE(base, other, false);
+ }
+
+ public static boolean isGE(String base, String other, boolean
majorMinorOnly) {
if (base == null || base.isEmpty()) {
throw new IllegalArgumentException("Empty base version");
}
@@ -79,56 +83,4 @@ public final class CamelVersionHelper {
return ver.prevMinor();
}
- private static final class Version implements Comparable<Version> {
-
- private final String version;
-
- private Version(String version) {
- this.version = version;
- }
-
- private String getVersion() {
- return version;
- }
-
- @Override
- public int compareTo(Version that) {
- if (that == null) {
- return 1;
- }
- String[] thisParts = this.getVersion().split("\\.");
- String[] thatParts = that.getVersion().split("\\.");
- int length = Math.max(thisParts.length, thatParts.length);
- for (int i = 0; i < length; i++) {
- long thisPart = i < thisParts.length ?
Long.parseLong(thisParts[i]) : 0;
- long thatPart = i < thatParts.length ?
Long.parseLong(thatParts[i]) : 0;
- if (thisPart < thatPart) {
- return -1;
- } else if (thisPart > thatPart) {
- return 1;
- }
- }
- return 0;
- }
-
- public String prevMinor() {
- String[] parts = this.getVersion().split("\\.");
- int major = Integer.parseInt(parts[0]);
- int minor = Integer.parseInt(parts[1]);
- int patch = parts.length == 3 ? Integer.parseInt(parts[2]) : 0;
-
- if (minor > 0) {
- minor -= 1;
- }
-
- String prev = major + "." + minor + "." + patch;
- return prev;
- }
-
- @Override
- public String toString() {
- return version;
- }
- }
-
}
diff --git
a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/Version.java
b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/Version.java
new file mode 100644
index 00000000000..6d02b032b6d
--- /dev/null
+++
b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/Version.java
@@ -0,0 +1,92 @@
+/*
+ * 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.camel.tooling.util;
+
+public final class Version implements Comparable<Version> {
+
+ private final String version;
+
+ public Version(String version) {
+ this.version = version;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public String getMajor() {
+ String[] thisParts = this.getVersion().split("\\.");
+ return thisParts[0];
+ }
+
+ public String getMinor() {
+ String[] thisParts = this.getVersion().split("\\.");
+ if (thisParts.length > 1) {
+ return thisParts[1];
+ } else {
+ return null;
+ }
+ }
+
+ public String getPatch() {
+ String[] thisParts = this.getVersion().split("\\.");
+ if (thisParts.length > 2) {
+ return thisParts[2];
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public int compareTo(Version that) {
+ if (that == null) {
+ return 1;
+ }
+ String[] thisParts = this.getVersion().split("\\.");
+ String[] thatParts = that.getVersion().split("\\.");
+ int length = Math.max(thisParts.length, thatParts.length);
+ for (int i = 0; i < length; i++) {
+ long thisPart = i < thisParts.length ?
Long.parseLong(thisParts[i]) : 0;
+ long thatPart = i < thatParts.length ?
Long.parseLong(thatParts[i]) : 0;
+ if (thisPart < thatPart) {
+ return -1;
+ } else if (thisPart > thatPart) {
+ return 1;
+ }
+ }
+ return 0;
+ }
+
+ public String prevMinor() {
+ String[] parts = this.getVersion().split("\\.");
+ int major = Integer.parseInt(parts[0]);
+ int minor = Integer.parseInt(parts[1]);
+ int patch = parts.length == 3 ? Integer.parseInt(parts[2]) : 0;
+
+ if (minor > 0) {
+ minor -= 1;
+ }
+
+ String prev = major + "." + minor + "." + patch;
+ return prev;
+ }
+
+ @Override
+ public String toString() {
+ return version;
+ }
+}
diff --git
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SupportLevelHelper.java
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SupportLevelHelper.java
index 14cb8c690f7..c2736b2a880 100644
---
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SupportLevelHelper.java
+++
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SupportLevelHelper.java
@@ -18,6 +18,7 @@ package org.apache.camel.maven.packaging;
import org.apache.camel.tooling.model.SupportLevel;
import org.apache.camel.tooling.util.CamelVersionHelper;
+import org.apache.camel.tooling.util.Version;
public final class SupportLevelHelper {
@@ -30,8 +31,14 @@ public final class SupportLevelHelper {
"FirstVersion is not specified. This can be done in
@UriEndpoint or in pom.xml file.");
}
- boolean justNew = CamelVersionHelper.isGE(currentVersion,
firstVersion);
- boolean prevNew =
CamelVersionHelper.isGE(CamelVersionHelper.prevMinor(currentVersion),
firstVersion);
+ // we only want major/minor (strip patch)
+ Version v1 = new Version(firstVersion);
+ v1 = new Version(v1.getMajor() + "." + v1.getMinor());
+ Version v2 = new Version(currentVersion);
+ v2 = new Version(v2.getMajor() + "." + v2.getMinor());
+
+ boolean justNew = CamelVersionHelper.isGE(v2.toString(),
v1.toString());
+ boolean prevNew =
CamelVersionHelper.isGE(CamelVersionHelper.prevMinor(v2.toString()),
v1.toString());
if (justNew || prevNew) {
// its a new component (2 releases back) that is added to this
version so lets mark it as preview by default
return SupportLevel.Preview;
diff --git
a/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/SupportLevelHelperTest.java
b/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/SupportLevelHelperTest.java
new file mode 100644
index 00000000000..cb7b5d7d45c
--- /dev/null
+++
b/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/SupportLevelHelperTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.camel.maven.packaging;
+
+import org.apache.camel.tooling.model.SupportLevel;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class SupportLevelHelperTest {
+
+ @Test
+ public void testPreview() {
+ Assertions.assertEquals(SupportLevel.Preview,
SupportLevelHelper.defaultSupportLevel("3.19.0", "3.20.0"));
+ Assertions.assertEquals(SupportLevel.Preview,
SupportLevelHelper.defaultSupportLevel("3.19.0", "3.20.1"));
+ Assertions.assertEquals(SupportLevel.Preview,
SupportLevelHelper.defaultSupportLevel("3.19.1", "3.20.1"));
+ Assertions.assertEquals(SupportLevel.Preview,
SupportLevelHelper.defaultSupportLevel("3.19.1", "3.20.2"));
+ Assertions.assertNotEquals(SupportLevel.Preview,
SupportLevelHelper.defaultSupportLevel("3.19.0", "3.21.0"));
+ }
+
+ @Test
+ public void testStable() {
+ Assertions.assertNotEquals(SupportLevel.Stable,
SupportLevelHelper.defaultSupportLevel("3.19.0", "3.20.0"));
+ Assertions.assertEquals(SupportLevel.Stable,
SupportLevelHelper.defaultSupportLevel("3.19.0", "3.21.0"));
+ Assertions.assertEquals(SupportLevel.Stable,
SupportLevelHelper.defaultSupportLevel("3.19.0", "3.21.1"));
+ Assertions.assertEquals(SupportLevel.Stable,
SupportLevelHelper.defaultSupportLevel("3.19.0", "3.22.0"));
+ Assertions.assertEquals(SupportLevel.Stable,
SupportLevelHelper.defaultSupportLevel("3.19.0", "3.22.3"));
+ }
+
+}