This is an automated email from the ASF dual-hosted git repository.

vgalaxies pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git


The following commit(s) were added to refs/heads/master by this push:
     new e13946533 refactor: centralize version management in project (#2797)
e13946533 is described below

commit e1394653358dde8110c2d5fa04cbea6fce47217e
Author: koi <[email protected]>
AuthorDate: Wed Jun 25 19:51:50 2025 +0800

    refactor: centralize version management in project (#2797)
---
 hugegraph-commons/hugegraph-common/pom.xml         |  6 ++
 .../org/apache/hugegraph/util/VersionUtil.java     | 70 +++++++++++++++++++++
 .../apache/hugegraph/version/CommonVersion.java    |  3 +-
 .../src/main/resources/version.properties          | 19 +++---
 .../org/apache/hugegraph/version/RpcVersion.java   |  3 +-
 hugegraph-pd/hg-pd-service/pom.xml                 |  2 +-
 .../java/org/apache/hugegraph/pd/rest/API.java     |  3 +-
 .../apache/hugegraph/server/ApplicationConfig.java | 72 +++++++++++++++++-----
 .../org/apache/hugegraph/version/ApiVersion.java   |  4 +-
 .../org/apache/hugegraph/version/CoreVersion.java  |  2 +-
 .../hugegraph-dist/src/assembly/travis/start-pd.sh | 13 +++-
 .../src/assembly/travis/start-store.sh             | 13 +++-
 12 files changed, 176 insertions(+), 34 deletions(-)

diff --git a/hugegraph-commons/hugegraph-common/pom.xml 
b/hugegraph-commons/hugegraph-common/pom.xml
index 4c84b30c9..a57bcf59c 100644
--- a/hugegraph-commons/hugegraph-common/pom.xml
+++ b/hugegraph-commons/hugegraph-common/pom.xml
@@ -238,6 +238,12 @@
     </dependencyManagement>
 
     <build>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+                <filtering>true</filtering>
+            </resource>
+        </resources>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
diff --git 
a/hugegraph-commons/hugegraph-common/src/main/java/org/apache/hugegraph/util/VersionUtil.java
 
b/hugegraph-commons/hugegraph-common/src/main/java/org/apache/hugegraph/util/VersionUtil.java
index b49adda87..87667347e 100644
--- 
a/hugegraph-commons/hugegraph-common/src/main/java/org/apache/hugegraph/util/VersionUtil.java
+++ 
b/hugegraph-commons/hugegraph-common/src/main/java/org/apache/hugegraph/util/VersionUtil.java
@@ -19,14 +19,18 @@ package org.apache.hugegraph.util;
 
 import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URL;
 import java.util.Objects;
+import java.util.Properties;
 import java.util.jar.Attributes;
 import java.util.jar.Manifest;
 
 public final class VersionUtil {
 
+    private static volatile Properties CACHED_PROPERTIES = null;
+    private static final Object VERSION_FILE_LOCK = new Object();
     /**
      * Compare if a version is inside a range [begin, end)
      * @param version   The version to be compared
@@ -102,6 +106,72 @@ public final class VersionUtil {
                        .getValue(Attributes.Name.IMPLEMENTATION_VERSION);
     }
 
+    public static Properties loadProperties() {
+        if (CACHED_PROPERTIES == null) {
+            synchronized (VERSION_FILE_LOCK) {
+                if (CACHED_PROPERTIES == null) {
+                    final Properties props = new Properties();
+                    try (InputStream is = 
VersionUtil.class.getResourceAsStream(
+                            "/version.properties")) {
+                        if (is == null) {
+                            throw new RuntimeException(
+                                    "version.properties file not found in 
classpath");
+                        }
+                        props.load(is);
+                        CACHED_PROPERTIES = props;
+                    } catch (IOException e) {
+                        throw new RuntimeException("Could not load 
version.properties", e);
+                    }
+                }
+            }
+        }
+        return CACHED_PROPERTIES;
+    }
+
+    /**
+     * Get version from properties
+     * @return      The common version
+     */
+    public static String getVersionFromProperties() {
+        Properties props = loadProperties();
+        String version = props.getProperty("Version");
+        if (version == null) {
+            throw new RuntimeException("Version property not found in 
version.properties");
+        }
+        return version;
+    }
+
+    /**
+     * Get api version from properties
+     * @return      The api version
+     */
+    public static String getApiVersionFromProperties() {
+        Properties props = loadProperties();
+        String apiVersion = props.getProperty("ApiVersion");
+        if (apiVersion == null) {
+            throw new RuntimeException("ApiVersion property not found in 
version.properties");
+        }
+        return apiVersion;
+    }
+
+    public static String getApiCheckBeginVersionFromProperties() {
+        Properties props = loadProperties();
+        String apiVersion = props.getProperty("ApiCheckBeginVersion");
+        if (apiVersion == null) {
+            throw new RuntimeException("ApiCheckBeginVersion property not 
found in version.properties");
+        }
+        return apiVersion;
+    }
+
+    public static String getApiCheckEndVersionFromProperties() {
+        Properties props = loadProperties();
+        String apiVersion = props.getProperty("ApiCheckEndVersion");
+        if (apiVersion == null) {
+            throw new RuntimeException("ApiCheckEndVersion property not found 
in version.properties");
+        }
+        return apiVersion;
+    }
+
     /**
      * Get version from pom.xml
      * @return      The pom version
diff --git 
a/hugegraph-commons/hugegraph-common/src/main/java/org/apache/hugegraph/version/CommonVersion.java
 
b/hugegraph-commons/hugegraph-common/src/main/java/org/apache/hugegraph/version/CommonVersion.java
index 73342fdaa..1bf90ab78 100644
--- 
a/hugegraph-commons/hugegraph-common/src/main/java/org/apache/hugegraph/version/CommonVersion.java
+++ 
b/hugegraph-commons/hugegraph-common/src/main/java/org/apache/hugegraph/version/CommonVersion.java
@@ -17,6 +17,7 @@
 
 package org.apache.hugegraph.version;
 
+import org.apache.hugegraph.util.VersionUtil;
 import org.apache.hugegraph.util.VersionUtil.Version;
 
 public class CommonVersion {
@@ -24,5 +25,5 @@ public class CommonVersion {
     public static final String NAME = "hugegraph-common";
 
     // The second parameter of Version.of() is for all-in-one JAR
-    public static final Version VERSION = Version.of(CommonVersion.class, 
"1.5.0");
+    public static final Version VERSION = Version.of(CommonVersion.class, 
VersionUtil.getVersionFromProperties());
 }
diff --git a/hugegraph-server/hugegraph-dist/src/assembly/travis/start-store.sh 
b/hugegraph-commons/hugegraph-common/src/main/resources/version.properties
old mode 100755
new mode 100644
similarity index 70%
copy from hugegraph-server/hugegraph-dist/src/assembly/travis/start-store.sh
copy to hugegraph-commons/hugegraph-common/src/main/resources/version.properties
index 23e8f2297..b413bf04e
--- a/hugegraph-server/hugegraph-dist/src/assembly/travis/start-store.sh
+++ b/hugegraph-commons/hugegraph-common/src/main/resources/version.properties
@@ -1,5 +1,3 @@
-#!/bin/bash
-#
 # 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.
@@ -14,13 +12,12 @@
 # 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.
-#
-set -ev
-
-HOME_DIR=$(pwd)
-STORE_DIR=$HOME_DIR/hugegraph-store/apache-hugegraph-store-incubating-1.5.0
 
-pushd $STORE_DIR
-. bin/start-hugegraph-store.sh
-sleep 10
-popd
+# When updating the version, Version can be read from the pom file. 
+# When hugegraph-common is updated, hugegraph-commons.version in the pom file 
needs to be updated, 
+# and VersionInBash needs to be updated in this file.
+Version=${revision}
+ApiVersion=0.71
+ApiCheckBeginVersion=1.0
+ApiCheckEndVersion=1.7
+VersionInBash=1.5.0
diff --git 
a/hugegraph-commons/hugegraph-rpc/src/main/java/org/apache/hugegraph/version/RpcVersion.java
 
b/hugegraph-commons/hugegraph-rpc/src/main/java/org/apache/hugegraph/version/RpcVersion.java
index a2dd3d72c..e2c41d8e2 100644
--- 
a/hugegraph-commons/hugegraph-rpc/src/main/java/org/apache/hugegraph/version/RpcVersion.java
+++ 
b/hugegraph-commons/hugegraph-rpc/src/main/java/org/apache/hugegraph/version/RpcVersion.java
@@ -17,6 +17,7 @@
 
 package org.apache.hugegraph.version;
 
+import org.apache.hugegraph.util.VersionUtil;
 import org.apache.hugegraph.util.VersionUtil.Version;
 
 public class RpcVersion {
@@ -24,5 +25,5 @@ public class RpcVersion {
     public static final String NAME = "hugegraph-rpc";
 
     // The second parameter of Version.of() is for all-in-one JAR
-    public static final Version VERSION = Version.of(RpcVersion.class, 
"1.5.0");
+    public static final Version VERSION = Version.of(RpcVersion.class, 
VersionUtil.getVersionFromProperties());
 }
diff --git a/hugegraph-pd/hg-pd-service/pom.xml 
b/hugegraph-pd/hg-pd-service/pom.xml
index 37c90fe86..81b456870 100644
--- a/hugegraph-pd/hg-pd-service/pom.xml
+++ b/hugegraph-pd/hg-pd-service/pom.xml
@@ -124,7 +124,7 @@
         <dependency>
             <groupId>org.apache.hugegraph</groupId>
             <artifactId>hugegraph-common</artifactId>
-            <version>1.2.0</version>
+            <version>${hugegraph-commons.version}</version>
             <exclusions>
                 <exclusion>
                     <groupId>org.apache.logging.log4j</groupId>
diff --git 
a/hugegraph-pd/hg-pd-service/src/main/java/org/apache/hugegraph/pd/rest/API.java
 
b/hugegraph-pd/hg-pd-service/src/main/java/org/apache/hugegraph/pd/rest/API.java
index a2287cb83..70fea99f2 100644
--- 
a/hugegraph-pd/hg-pd-service/src/main/java/org/apache/hugegraph/pd/rest/API.java
+++ 
b/hugegraph-pd/hg-pd-service/src/main/java/org/apache/hugegraph/pd/rest/API.java
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.hugegraph.pd.common.PDException;
+import org.apache.hugegraph.util.VersionUtil;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -33,7 +34,7 @@ public class API {
 
     // TODO: use a flexible way to define the version
     // refer: 
https://github.com/apache/hugegraph/pull/2528#discussion_r1573823996
-    public static final String VERSION = "1.5.0";
+    public static final String VERSION = 
VersionUtil.getVersionFromProperties();
     public static final String PD = "PD";
     public static final String STORE = "STORE";
     public static String STATUS_KEY = "status";
diff --git 
a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/ApplicationConfig.java
 
b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/ApplicationConfig.java
index 7784613f5..9f9134ffa 100644
--- 
a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/ApplicationConfig.java
+++ 
b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/ApplicationConfig.java
@@ -36,18 +36,23 @@ import 
org.glassfish.jersey.server.monitoring.ApplicationEvent;
 import org.glassfish.jersey.server.monitoring.ApplicationEventListener;
 import org.glassfish.jersey.server.monitoring.RequestEvent;
 import org.glassfish.jersey.server.monitoring.RequestEventListener;
+import org.glassfish.jersey.servlet.ServletProperties;
 
 import com.codahale.metrics.MetricRegistry;
 import 
com.codahale.metrics.jersey3.InstrumentedResourceMethodApplicationListener;
 
+import io.swagger.v3.oas.integration.OpenApiConfigurationException;
+import io.swagger.v3.jaxrs2.integration.JaxrsOpenApiContextBuilder;
 import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
 import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
-import io.swagger.v3.oas.annotations.info.Contact;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.security.SecurityRequirement;
 import io.swagger.v3.oas.annotations.security.SecurityScheme;
+import io.swagger.v3.oas.integration.SwaggerConfiguration;
+import io.swagger.v3.oas.models.OpenAPI;
+import jakarta.servlet.ServletConfig;
+import io.swagger.v3.oas.models.info.Info;
+import io.swagger.v3.oas.models.security.SecurityRequirement;
 import jakarta.ws.rs.ApplicationPath;
+import jakarta.ws.rs.core.Context;
 
 @SecurityScheme(
         name = "basic",
@@ -60,16 +65,9 @@ import jakarta.ws.rs.ApplicationPath;
         scheme = "bearer"
 )
 @ApplicationPath("/")
-@OpenAPIDefinition(
-        info = @Info(
-                title = "HugeGraph RESTful API",
-                version = CoreVersion.DEFAULT_VERSION,
-                description = "All management API for HugeGraph",
-                contact = @Contact(url = 
"https://github.com/apache/hugegraph";, name = "HugeGraph")
-        ),
-        security = {@SecurityRequirement(name = "basic"), 
@SecurityRequirement(name = "bearer")}
-)
 public class ApplicationConfig extends ResourceConfig {
+    @Context
+    private ServletConfig servletConfig;
 
     public ApplicationConfig(HugeConfig conf, EventHub hub) {
         packages("org.apache.hugegraph.api");
@@ -95,10 +93,56 @@ public class ApplicationConfig extends ResourceConfig {
         MetricRegistry registry = MetricManager.INSTANCE.getRegistry();
         register(new InstrumentedResourceMethodApplicationListener(registry));
 
-        // Register OpenApi file to support display on swagger-ui
+        // Set OpenApi in runtime
+        registerOpenApi();
+
         register(OpenApiResource.class);
     }
 
+
+    void registerOpenApi() {
+        OpenAPI openAPI = new OpenAPI();
+        Info info = new Info()
+            .title("HugeGraph RESTful API")
+            .version(CoreVersion.DEFAULT_VERSION)
+            .description("All management API for HugeGraph")
+            .contact(new io.swagger.v3.oas.models.info.Contact()
+                .name("HugeGraph")
+                .url("https://github.com/apache/hugegraph";)); 
+
+        openAPI.setInfo(info);
+        openAPI.addSecurityItem(new SecurityRequirement().addList("basic"));
+        openAPI.addSecurityItem(new SecurityRequirement().addList("bearer"));
+        
+        SwaggerConfiguration oasConfig = new SwaggerConfiguration()
+                .openAPI(openAPI)
+                .prettyPrint(true);
+        register(new ApplicationEventListener() {
+            @Override
+            public void onEvent(ApplicationEvent event) {
+                if (event.getType() == 
ApplicationEvent.Type.INITIALIZATION_FINISHED) {
+                    try {
+                        JaxrsOpenApiContextBuilder builder =
+                                (JaxrsOpenApiContextBuilder) new 
JaxrsOpenApiContextBuilder()
+                                        .application(ApplicationConfig.this)
+                                        .openApiConfiguration(oasConfig);
+                        if (servletConfig != null) {
+                            builder.servletConfig(servletConfig);
+                        }   
+                        builder.buildContext(true);
+                   } catch (OpenApiConfigurationException e) {
+                        throw new RuntimeException(e.getMessage(), e);
+                   }
+                }
+            }
+
+            @Override
+            public RequestEventListener onRequest(RequestEvent requestEvent) {
+                return null;
+            }
+        });
+    }
+
     private class ConfFactory extends AbstractBinder implements 
Factory<HugeConfig> {
 
         private final HugeConfig conf;
diff --git 
a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/version/ApiVersion.java
 
b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/version/ApiVersion.java
index bbc06ad30..7e314f9ed 100644
--- 
a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/version/ApiVersion.java
+++ 
b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/version/ApiVersion.java
@@ -127,10 +127,10 @@ public final class ApiVersion {
      * The second parameter of Version.of() is for IDE running without JAR
      * Note: Also update the version number in 
hugegraph-server/hugegraph-api/pom.xml
      */
-    public static final Version VERSION = Version.of(ApiVersion.class, "0.71");
+    public static final Version VERSION = Version.of(ApiVersion.class, 
VersionUtil.getApiVersionFromProperties());
 
     public static void check() {
         // Check the version of hugegraph-core. Do first check from version 0.3
-        VersionUtil.check(CoreVersion.VERSION, "1.0", "1.6", CoreVersion.NAME);
+        VersionUtil.check(CoreVersion.VERSION, 
VersionUtil.getApiCheckBeginVersionFromProperties(), 
VersionUtil.getApiCheckEndVersionFromProperties(), CoreVersion.NAME);
     }
 }
diff --git 
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/version/CoreVersion.java
 
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/version/CoreVersion.java
index 468663c92..2eff71487 100644
--- 
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/version/CoreVersion.java
+++ 
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/version/CoreVersion.java
@@ -23,7 +23,7 @@ import org.apache.hugegraph.util.VersionUtil.Version;
 public class CoreVersion {
 
     public static final String NAME = "hugegraph-core";
-    public static final String DEFAULT_VERSION = "1.5.0";
+    public static final String DEFAULT_VERSION = 
VersionUtil.getVersionFromProperties();
     /**
      * The second parameter of Version.of() is for IDE running without JAR
      */
diff --git a/hugegraph-server/hugegraph-dist/src/assembly/travis/start-pd.sh 
b/hugegraph-server/hugegraph-dist/src/assembly/travis/start-pd.sh
index 9f694d5c3..bab4adcc8 100755
--- a/hugegraph-server/hugegraph-dist/src/assembly/travis/start-pd.sh
+++ b/hugegraph-server/hugegraph-dist/src/assembly/travis/start-pd.sh
@@ -18,7 +18,18 @@
 set -ev
 
 HOME_DIR=$(pwd)
-PD_DIR=$HOME_DIR/hugegraph-pd/apache-hugegraph-pd-incubating-1.5.0
+
+PROPERTIES_FILE="$HOME_DIR/hugegraph-commons/hugegraph-common/src/main/resources/version.properties"
+if [ -f "$PROPERTIES_FILE" ]; then
+    set -a
+    source "$PROPERTIES_FILE"
+    set +a
+else
+    echo "Error: properties file not found at $PROPERTIES_FILE"
+    exit 1
+fi
+
+PD_DIR=$HOME_DIR/hugegraph-pd/apache-hugegraph-pd-incubating-$VersionInBash
 
 pushd $PD_DIR
 . bin/start-hugegraph-pd.sh
diff --git a/hugegraph-server/hugegraph-dist/src/assembly/travis/start-store.sh 
b/hugegraph-server/hugegraph-dist/src/assembly/travis/start-store.sh
index 23e8f2297..8882df3a8 100755
--- a/hugegraph-server/hugegraph-dist/src/assembly/travis/start-store.sh
+++ b/hugegraph-server/hugegraph-dist/src/assembly/travis/start-store.sh
@@ -18,7 +18,18 @@
 set -ev
 
 HOME_DIR=$(pwd)
-STORE_DIR=$HOME_DIR/hugegraph-store/apache-hugegraph-store-incubating-1.5.0
+
+PROPERTIES_FILE="$HOME_DIR/hugegraph-commons/hugegraph-common/src/main/resources/version.properties"
+if [ -f "$PROPERTIES_FILE" ]; then
+    set -a
+    source "$PROPERTIES_FILE"
+    set +a
+else
+    echo "Error: properties file not found at $PROPERTIES_FILE"
+    exit 1
+fi
+
+STORE_DIR=$HOME_DIR/hugegraph-store/apache-hugegraph-store-incubating-$VersionInBash
 
 pushd $STORE_DIR
 . bin/start-hugegraph-store.sh

Reply via email to