From 468987497273fb410f1ef818b6947f0df66c8cf5 Mon Sep 17 00:00:00 2001 From: koi2000 Date: Wed, 11 Jun 2025 23:06:01 +0800 Subject: [PATCH 1/8] centralize version management --- hugegraph-commons/hugegraph-common/pom.xml | 6 ++ .../apache/hugegraph/util/VersionUtil.java | 58 +++++++++++++++++++ .../hugegraph/version/CommonVersion.java | 5 +- .../src/main/resources/version.properties | 19 ++++++ .../apache/hugegraph/version/RpcVersion.java | 3 +- hugegraph-pd/hg-pd-service/pom.xml | 2 +- .../org/apache/hugegraph/pd/rest/API.java | 3 +- .../hugegraph/server/ApplicationConfig.java | 51 +++++++++++----- .../apache/hugegraph/version/ApiVersion.java | 4 +- .../apache/hugegraph/version/CoreVersion.java | 2 +- .../src/assembly/travis/start-pd.sh | 3 +- .../src/assembly/travis/start-store.sh | 3 +- 12 files changed, 135 insertions(+), 24 deletions(-) create mode 100644 hugegraph-commons/hugegraph-common/src/main/resources/version.properties diff --git a/hugegraph-commons/hugegraph-common/pom.xml b/hugegraph-commons/hugegraph-common/pom.xml index 4c84b30c99..a57bcf59cd 100644 --- a/hugegraph-commons/hugegraph-common/pom.xml +++ b/hugegraph-commons/hugegraph-common/pom.xml @@ -238,6 +238,12 @@ + + + src/main/resources + true + + org.apache.maven.plugins 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 b49adda87a..4805b0c8a6 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,9 +19,11 @@ 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; @@ -102,6 +104,62 @@ public static String getImplementationVersion(String manifestPath) { .getValue(Attributes.Name.IMPLEMENTATION_VERSION); } + /** + * Get version from properties + * @return The common version + */ + public static String getVersionFromProperties() { + final Properties PROPS = new Properties(); + + try (InputStream is = + VersionUtil.class.getResourceAsStream("/version.properties")) { + PROPS.load(is); + } catch (IOException e) { + throw new RuntimeException("Could not load version.properties", e); + } + return PROPS.getProperty("Version"); + } + + /** + * Get api version from properties + * @return The api version + */ + public static String getApiVersionFromProperties() { + final Properties PROPS = new Properties(); + + try (InputStream is = + VersionUtil.class.getResourceAsStream("/version.properties")) { + PROPS.load(is); + } catch (IOException e) { + throw new RuntimeException("Could not load version.properties", e); + } + return PROPS.getProperty("ApiVersion"); + } + + public static String getApiCheckBeginVersionFromProperties() { + final Properties PROPS = new Properties(); + + try (InputStream is = + VersionUtil.class.getResourceAsStream("/version.properties")) { + PROPS.load(is); + } catch (IOException e) { + throw new RuntimeException("Could not load version.properties", e); + } + return PROPS.getProperty("ApiCheckBeginVersion"); + } + + public static String getApiCheckEndVersionFromProperties() { + final Properties PROPS = new Properties(); + + try (InputStream is = + VersionUtil.class.getResourceAsStream("/version.properties")) { + PROPS.load(is); + } catch (IOException e) { + throw new RuntimeException("Could not load version.properties", e); + } + return PROPS.getProperty("ApiCheckEndVersion"); + } + /** * 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 73342fdaaa..3a5f83c16e 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,12 +17,13 @@ package org.apache.hugegraph.version; -import org.apache.hugegraph.util.VersionUtil.Version; +import org.apache.hugegraph.util.VersionUtil; +import org.apache.hugegraph.util.VersionUtil.Version;; 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-commons/hugegraph-common/src/main/resources/version.properties b/hugegraph-commons/hugegraph-common/src/main/resources/version.properties new file mode 100644 index 0000000000..7ff3098ea2 --- /dev/null +++ b/hugegraph-commons/hugegraph-common/src/main/resources/version.properties @@ -0,0 +1,19 @@ +# 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. + +Version=${revision} +ApiVersion=0.71 +ApiCheckBeginVersion=1.0 +ApiCheckEndVersion=1.7 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 a2dd3d72c1..e2c41d8e29 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 37c90fe869..81b4568701 100644 --- a/hugegraph-pd/hg-pd-service/pom.xml +++ b/hugegraph-pd/hg-pd-service/pom.xml @@ -124,7 +124,7 @@ org.apache.hugegraph hugegraph-common - 1.2.0 + ${hugegraph-commons.version} org.apache.logging.log4j 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 a2287cb83e..70fea99f2b 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.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 7784613f53..98422457ae 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 @@ -28,6 +28,7 @@ import org.apache.tinkerpop.gremlin.server.util.MetricManager; import org.glassfish.hk2.api.Factory; import org.glassfish.hk2.api.MultiException; +import org.glassfish.hk2.api.ServiceLocator; import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.process.internal.RequestScoped; import org.glassfish.jersey.server.ResourceConfig; @@ -40,14 +41,18 @@ 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 @@ 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,7 +93,32 @@ public ApplicationConfig(HugeConfig conf, EventHub hub) { MetricRegistry registry = MetricManager.INSTANCE.getRegistry(); register(new InstrumentedResourceMethodApplicationListener(registry)); - // Register OpenApi file to support display on swagger-ui + 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); + + try { + new JaxrsOpenApiContextBuilder() + .servletConfig(servletConfig) + .application(this) + .openApiConfiguration(oasConfig) + .buildContext(true); + } catch (OpenApiConfigurationException e) { + throw new RuntimeException(e.getMessage(), e); + } register(OpenApiResource.class); } 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 bbc06ad309..7e314f9ed6 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 468663c924..2eff71487a 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 @@ 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 9f694d5c3c..4c02280eeb 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,8 @@ set -ev HOME_DIR=$(pwd) -PD_DIR=$HOME_DIR/hugegraph-pd/apache-hugegraph-pd-incubating-1.5.0 +source $HOME_DIR/hugegraph-commons/hugegraph-common/src/main/resources/version.properties +PD_DIR=$HOME_DIR/hugegraph-pd/apache-hugegraph-pd-incubating-${version} 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 23e8f2297c..0b1cbd626f 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,8 @@ set -ev HOME_DIR=$(pwd) -STORE_DIR=$HOME_DIR/hugegraph-store/apache-hugegraph-store-incubating-1.5.0 +source $HOME_DIR/hugegraph-commons/hugegraph-common/src/main/resources/version.properties +STORE_DIR=$HOME_DIR/hugegraph-store/apache-hugegraph-store-incubating-${version} pushd $STORE_DIR . bin/start-hugegraph-store.sh From ce80946596f0bb9b20e0ff45544832ff7be26f62 Mon Sep 17 00:00:00 2001 From: koi2000 Date: Thu, 12 Jun 2025 15:00:44 +0800 Subject: [PATCH 2/8] extract the loadProperties function --- .../apache/hugegraph/util/VersionUtil.java | 54 +++++++------------ .../hugegraph/server/ApplicationConfig.java | 1 - .../src/assembly/travis/start-pd.sh | 2 +- .../src/assembly/travis/start-store.sh | 2 +- 4 files changed, 21 insertions(+), 38 deletions(-) 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 4805b0c8a6..e555b441db 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 @@ -104,20 +104,25 @@ public static String getImplementationVersion(String manifestPath) { .getValue(Attributes.Name.IMPLEMENTATION_VERSION); } - /** - * Get version from properties - * @return The common version - */ - public static String getVersionFromProperties() { - final Properties PROPS = new Properties(); + public static Properties loadProperties() { + final Properties props = new Properties(); try (InputStream is = VersionUtil.class.getResourceAsStream("/version.properties")) { - PROPS.load(is); + props.load(is); } catch (IOException e) { throw new RuntimeException("Could not load version.properties", e); } - return PROPS.getProperty("Version"); + return props; + } + + /** + * Get version from properties + * @return The common version + */ + public static String getVersionFromProperties() { + Properties props = loadProperties(); + return props.getProperty("Version"); } /** @@ -125,39 +130,18 @@ public static String getVersionFromProperties() { * @return The api version */ public static String getApiVersionFromProperties() { - final Properties PROPS = new Properties(); - - try (InputStream is = - VersionUtil.class.getResourceAsStream("/version.properties")) { - PROPS.load(is); - } catch (IOException e) { - throw new RuntimeException("Could not load version.properties", e); - } - return PROPS.getProperty("ApiVersion"); + Properties props = loadProperties(); + return props.getProperty("ApiVersion"); } public static String getApiCheckBeginVersionFromProperties() { - final Properties PROPS = new Properties(); - - try (InputStream is = - VersionUtil.class.getResourceAsStream("/version.properties")) { - PROPS.load(is); - } catch (IOException e) { - throw new RuntimeException("Could not load version.properties", e); - } - return PROPS.getProperty("ApiCheckBeginVersion"); + Properties props = loadProperties(); + return props.getProperty("ApiCheckBeginVersion"); } public static String getApiCheckEndVersionFromProperties() { - final Properties PROPS = new Properties(); - - try (InputStream is = - VersionUtil.class.getResourceAsStream("/version.properties")) { - PROPS.load(is); - } catch (IOException e) { - throw new RuntimeException("Could not load version.properties", e); - } - return PROPS.getProperty("ApiCheckEndVersion"); + Properties props = loadProperties(); + return props.getProperty("ApiCheckEndVersion"); } /** 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 98422457ae..9fe641ceb0 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 @@ -28,7 +28,6 @@ import org.apache.tinkerpop.gremlin.server.util.MetricManager; import org.glassfish.hk2.api.Factory; import org.glassfish.hk2.api.MultiException; -import org.glassfish.hk2.api.ServiceLocator; import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.process.internal.RequestScoped; import org.glassfish.jersey.server.ResourceConfig; 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 4c02280eeb..67b3ba185b 100755 --- a/hugegraph-server/hugegraph-dist/src/assembly/travis/start-pd.sh +++ b/hugegraph-server/hugegraph-dist/src/assembly/travis/start-pd.sh @@ -19,7 +19,7 @@ set -ev HOME_DIR=$(pwd) source $HOME_DIR/hugegraph-commons/hugegraph-common/src/main/resources/version.properties -PD_DIR=$HOME_DIR/hugegraph-pd/apache-hugegraph-pd-incubating-${version} +PD_DIR=$HOME_DIR/hugegraph-pd/apache-hugegraph-pd-incubating-${Version} 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 0b1cbd626f..cadb632dce 100755 --- a/hugegraph-server/hugegraph-dist/src/assembly/travis/start-store.sh +++ b/hugegraph-server/hugegraph-dist/src/assembly/travis/start-store.sh @@ -19,7 +19,7 @@ set -ev HOME_DIR=$(pwd) source $HOME_DIR/hugegraph-commons/hugegraph-common/src/main/resources/version.properties -STORE_DIR=$HOME_DIR/hugegraph-store/apache-hugegraph-store-incubating-${version} +STORE_DIR=$HOME_DIR/hugegraph-store/apache-hugegraph-store-incubating-${Version} pushd $STORE_DIR . bin/start-hugegraph-store.sh From ccac86dd78d3f01f2fcbf3122e88f10870a3f06d Mon Sep 17 00:00:00 2001 From: koi2000 Date: Thu, 12 Jun 2025 16:31:13 +0800 Subject: [PATCH 3/8] fix errors in bash that unable to read versions --- .../src/main/resources/version.properties | 4 ++++ .../hugegraph-dist/src/assembly/travis/start-pd.sh | 12 ++++++++++-- .../src/assembly/travis/start-store.sh | 12 ++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/hugegraph-commons/hugegraph-common/src/main/resources/version.properties b/hugegraph-commons/hugegraph-common/src/main/resources/version.properties index 7ff3098ea2..e734e2f936 100644 --- a/hugegraph-commons/hugegraph-common/src/main/resources/version.properties +++ b/hugegraph-commons/hugegraph-common/src/main/resources/version.properties @@ -13,7 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +# 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 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 67b3ba185b..52b39e09e1 100755 --- a/hugegraph-server/hugegraph-dist/src/assembly/travis/start-pd.sh +++ b/hugegraph-server/hugegraph-dist/src/assembly/travis/start-pd.sh @@ -18,8 +18,16 @@ set -ev HOME_DIR=$(pwd) -source $HOME_DIR/hugegraph-commons/hugegraph-common/src/main/resources/version.properties -PD_DIR=$HOME_DIR/hugegraph-pd/apache-hugegraph-pd-incubating-${Version} + +PROPERTIES_FILE="$HOME_DIR/hugegraph-commons/hugegraph-common/src/main/resources/version.properties" +if [ -f "$PROPERTIES_FILE" ]; then + export $(grep -v '^#' "$PROPERTIES_FILE" | xargs) +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 cadb632dce..08d5b6158b 100755 --- a/hugegraph-server/hugegraph-dist/src/assembly/travis/start-store.sh +++ b/hugegraph-server/hugegraph-dist/src/assembly/travis/start-store.sh @@ -18,8 +18,16 @@ set -ev HOME_DIR=$(pwd) -source $HOME_DIR/hugegraph-commons/hugegraph-common/src/main/resources/version.properties -STORE_DIR=$HOME_DIR/hugegraph-store/apache-hugegraph-store-incubating-${Version} + +PROPERTIES_FILE="$HOME_DIR/hugegraph-commons/hugegraph-common/src/main/resources/version.properties" +if [ -f "$PROPERTIES_FILE" ]; then + export $(grep -v '^#' "$PROPERTIES_FILE" | xargs) +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 From 1bdc2ee4dc38609a8127651cb7ca7bc2b8950ec3 Mon Sep 17 00:00:00 2001 From: koi2000 Date: Thu, 12 Jun 2025 17:05:48 +0800 Subject: [PATCH 4/8] fix bug in version format error --- .../hugegraph-common/src/main/resources/version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hugegraph-commons/hugegraph-common/src/main/resources/version.properties b/hugegraph-commons/hugegraph-common/src/main/resources/version.properties index e734e2f936..b413bf04e3 100644 --- a/hugegraph-commons/hugegraph-common/src/main/resources/version.properties +++ b/hugegraph-commons/hugegraph-common/src/main/resources/version.properties @@ -20,4 +20,4 @@ Version=${revision} ApiVersion=0.71 ApiCheckBeginVersion=1.0 ApiCheckEndVersion=1.7 -VersionInBash=1.5 +VersionInBash=1.5.0 From 744ee1c84a6f78294317891426b1a7c4eec94702 Mon Sep 17 00:00:00 2001 From: koi2000 Date: Mon, 16 Jun 2025 22:19:24 +0800 Subject: [PATCH 5/8] format code --- .../src/main/java/org/apache/hugegraph/util/VersionUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e555b441db..8ee1a54e13 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 @@ -109,7 +109,7 @@ public static Properties loadProperties() { try (InputStream is = VersionUtil.class.getResourceAsStream("/version.properties")) { - props.load(is); + props.load(is); } catch (IOException e) { throw new RuntimeException("Could not load version.properties", e); } From 33266dc5547228288e941a0efecac3c06d8ee83f Mon Sep 17 00:00:00 2001 From: koi2000 Date: Tue, 24 Jun 2025 17:43:47 +0800 Subject: [PATCH 6/8] modified according to AI suggestions --- .../apache/hugegraph/util/VersionUtil.java | 52 ++++++++++++++----- .../hugegraph/version/CommonVersion.java | 2 +- .../hugegraph/server/ApplicationConfig.java | 35 +++++++++---- .../src/assembly/travis/start-pd.sh | 6 ++- .../src/assembly/travis/start-store.sh | 6 ++- 5 files changed, 76 insertions(+), 25 deletions(-) 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 8ee1a54e13..87667347ec 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 @@ -29,6 +29,8 @@ 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 @@ -105,15 +107,25 @@ public static String getImplementationVersion(String manifestPath) { } public static Properties loadProperties() { - final Properties props = new Properties(); - - try (InputStream is = - VersionUtil.class.getResourceAsStream("/version.properties")) { - props.load(is); - } catch (IOException e) { - throw new RuntimeException("Could not load version.properties", e); + 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 props; + return CACHED_PROPERTIES; } /** @@ -122,7 +134,11 @@ public static Properties loadProperties() { */ public static String getVersionFromProperties() { Properties props = loadProperties(); - return props.getProperty("Version"); + String version = props.getProperty("Version"); + if (version == null) { + throw new RuntimeException("Version property not found in version.properties"); + } + return version; } /** @@ -131,17 +147,29 @@ public static String getVersionFromProperties() { */ public static String getApiVersionFromProperties() { Properties props = loadProperties(); - return props.getProperty("ApiVersion"); + 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(); - return props.getProperty("ApiCheckBeginVersion"); + 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(); - return props.getProperty("ApiCheckEndVersion"); + String apiVersion = props.getProperty("ApiCheckEndVersion"); + if (apiVersion == null) { + throw new RuntimeException("ApiCheckEndVersion property not found in version.properties"); + } + return apiVersion; } /** 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 3a5f83c16e..1bf90ab782 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 @@ -18,7 +18,7 @@ package org.apache.hugegraph.version; import org.apache.hugegraph.util.VersionUtil; -import org.apache.hugegraph.util.VersionUtil.Version;; +import org.apache.hugegraph.util.VersionUtil.Version; public class CommonVersion { 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 9fe641ceb0..d2a86b5432 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,6 +36,7 @@ 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; @@ -108,16 +109,30 @@ public ApplicationConfig(HugeConfig conf, EventHub hub) { SwaggerConfiguration oasConfig = new SwaggerConfiguration() .openAPI(openAPI) .prettyPrint(true); - - try { - new JaxrsOpenApiContextBuilder() - .servletConfig(servletConfig) - .application(this) - .openApiConfiguration(oasConfig) - .buildContext(true); - } catch (OpenApiConfigurationException e) { - throw new RuntimeException(e.getMessage(), e); - } + 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; + } + }); register(OpenApiResource.class); } 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 52b39e09e1..ac4e70af69 100755 --- a/hugegraph-server/hugegraph-dist/src/assembly/travis/start-pd.sh +++ b/hugegraph-server/hugegraph-dist/src/assembly/travis/start-pd.sh @@ -21,7 +21,11 @@ HOME_DIR=$(pwd) PROPERTIES_FILE="$HOME_DIR/hugegraph-commons/hugegraph-common/src/main/resources/version.properties" if [ -f "$PROPERTIES_FILE" ]; then - export $(grep -v '^#' "$PROPERTIES_FILE" | xargs) + VERSION_IN_BASH=$(grep '^VersionInBash=' "$PROPERTIES_FILE" | cut -d'=' -f2) + if [ -z "$VERSION_IN_BASH" ]; then + echo "Error: VersionInBash not found in properties file" + exit 1 + fi else echo "Error: properties file not found at $PROPERTIES_FILE" exit 1 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 08d5b6158b..a8782278a2 100755 --- a/hugegraph-server/hugegraph-dist/src/assembly/travis/start-store.sh +++ b/hugegraph-server/hugegraph-dist/src/assembly/travis/start-store.sh @@ -21,7 +21,11 @@ HOME_DIR=$(pwd) PROPERTIES_FILE="$HOME_DIR/hugegraph-commons/hugegraph-common/src/main/resources/version.properties" if [ -f "$PROPERTIES_FILE" ]; then - export $(grep -v '^#' "$PROPERTIES_FILE" | xargs) + VERSION_IN_BASH=$(grep '^VersionInBash=' "$PROPERTIES_FILE" | cut -d'=' -f2) + if [ -z "$VERSION_IN_BASH" ]; then + echo "Error: VersionInBash not found in properties file" + exit 1 + fi else echo "Error: properties file not found at $PROPERTIES_FILE" exit 1 From 5a7ce1e20bf86ac11deddfd897f493bebd7f5bae Mon Sep 17 00:00:00 2001 From: koi2000 Date: Tue, 24 Jun 2025 17:54:12 +0800 Subject: [PATCH 7/8] fix bug in bash --- .../hugegraph-dist/src/assembly/travis/start-pd.sh | 8 +++----- .../hugegraph-dist/src/assembly/travis/start-store.sh | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) 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 ac4e70af69..bab4adcc8d 100755 --- a/hugegraph-server/hugegraph-dist/src/assembly/travis/start-pd.sh +++ b/hugegraph-server/hugegraph-dist/src/assembly/travis/start-pd.sh @@ -21,11 +21,9 @@ HOME_DIR=$(pwd) PROPERTIES_FILE="$HOME_DIR/hugegraph-commons/hugegraph-common/src/main/resources/version.properties" if [ -f "$PROPERTIES_FILE" ]; then - VERSION_IN_BASH=$(grep '^VersionInBash=' "$PROPERTIES_FILE" | cut -d'=' -f2) - if [ -z "$VERSION_IN_BASH" ]; then - echo "Error: VersionInBash not found in properties file" - exit 1 - fi + set -a + source "$PROPERTIES_FILE" + set +a else echo "Error: properties file not found at $PROPERTIES_FILE" exit 1 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 a8782278a2..8882df3a8e 100755 --- a/hugegraph-server/hugegraph-dist/src/assembly/travis/start-store.sh +++ b/hugegraph-server/hugegraph-dist/src/assembly/travis/start-store.sh @@ -21,11 +21,9 @@ HOME_DIR=$(pwd) PROPERTIES_FILE="$HOME_DIR/hugegraph-commons/hugegraph-common/src/main/resources/version.properties" if [ -f "$PROPERTIES_FILE" ]; then - VERSION_IN_BASH=$(grep '^VersionInBash=' "$PROPERTIES_FILE" | cut -d'=' -f2) - if [ -z "$VERSION_IN_BASH" ]; then - echo "Error: VersionInBash not found in properties file" - exit 1 - fi + set -a + source "$PROPERTIES_FILE" + set +a else echo "Error: properties file not found at $PROPERTIES_FILE" exit 1 From 736ff63684b255740afb96a94cedf61807fab654 Mon Sep 17 00:00:00 2001 From: koi2000 Date: Tue, 24 Jun 2025 19:39:54 +0800 Subject: [PATCH 8/8] extract the registered openapi as a function --- .../org/apache/hugegraph/server/ApplicationConfig.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 d2a86b5432..9f9134ffa3 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 @@ -93,6 +93,14 @@ public ApplicationConfig(HugeConfig conf, EventHub hub) { MetricRegistry registry = MetricManager.INSTANCE.getRegistry(); register(new InstrumentedResourceMethodApplicationListener(registry)); + // Set OpenApi in runtime + registerOpenApi(); + + register(OpenApiResource.class); + } + + + void registerOpenApi() { OpenAPI openAPI = new OpenAPI(); Info info = new Info() .title("HugeGraph RESTful API") @@ -133,7 +141,6 @@ public RequestEventListener onRequest(RequestEvent requestEvent) { return null; } }); - register(OpenApiResource.class); } private class ConfFactory extends AbstractBinder implements Factory {