This is an automated email from the ASF dual-hosted git repository.
Croway 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 401226e60811 CAMEL-20206: refactor complex method getVersion() (#24384)
401226e60811 is described below
commit 401226e6081111df31a428233f4c885f39e23196
Author: Filip Gaľa <[email protected]>
AuthorDate: Thu Jul 2 17:18:15 2026 +0200
CAMEL-20206: refactor complex method getVersion() (#24384)
* refactored method getVersion to reduce cognitive complexity
* apply code suggestion - rename method parameter name
---
.../org/apache/camel/catalog/VersionHelper.java | 52 +++++++---------------
1 file changed, 15 insertions(+), 37 deletions(-)
diff --git
a/catalog/camel-catalog/src/main/java/org/apache/camel/catalog/VersionHelper.java
b/catalog/camel-catalog/src/main/java/org/apache/camel/catalog/VersionHelper.java
index 3a62aa268670..d7fd7cb74cf4 100644
---
a/catalog/camel-catalog/src/main/java/org/apache/camel/catalog/VersionHelper.java
+++
b/catalog/camel-catalog/src/main/java/org/apache/camel/catalog/VersionHelper.java
@@ -31,46 +31,11 @@ public class VersionHelper {
return version;
}
// First, try to load from maven properties
- InputStream is = null;
- try {
- Properties p = new Properties();
- is =
getClass().getResourceAsStream("/META-INF/maven/org.apache.camel/camel-catalog/pom.properties");
- if (is != null) {
- p.load(is);
- version = p.getProperty("version", "");
- }
- } catch (Exception e) {
- // ignore
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (Exception e) {
- // ignore
- }
- }
- }
+ version =
getVersionFromProperties("/META-INF/maven/org.apache.camel/camel-catalog/pom.properties");
// Next, try to load from version.properties
if (version == null) {
- try {
- Properties p = new Properties();
- is =
getClass().getResourceAsStream("/META-INF/version.properties");
- if (is != null) {
- p.load(is);
- version = p.getProperty("version", "");
- }
- } catch (Exception e) {
- // ignore
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (Exception e) {
- // ignore
- }
- }
- }
+ version = getVersionFromProperties("/META-INF/version.properties");
}
// Fallback to using Java API
@@ -92,4 +57,17 @@ public class VersionHelper {
return version;
}
+ private String getVersionFromProperties(String resourcePath) {
+ try (InputStream is = getClass().getResourceAsStream(resourcePath)) {
+ Properties p = new Properties();
+ if (is != null) {
+ p.load(is);
+ return p.getProperty("version", "");
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+
+ return null;
+ }
}