Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions hugegraph-commons/hugegraph-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@
</dependencyManagement>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
Comment thread
imbajin marked this conversation as resolved.
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -102,6 +104,46 @@ public static String getImplementationVersion(String manifestPath) {
.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
}

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);
}
return props;
}

/**
* Get version from properties
* @return The common version
*/
public static String getVersionFromProperties() {
Copy link

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Each call reloads the properties file from disk. Consider caching the loaded Properties in a static field to avoid repeated I/O.

Copilot uses AI. Check for mistakes.
Properties props = loadProperties();
return props.getProperty("Version");
}

/**
* Get api version from properties
* @return The api version
*/
public static String getApiVersionFromProperties() {
Properties props = loadProperties();
return props.getProperty("ApiVersion");
}

public static String getApiCheckBeginVersionFromProperties() {
Properties props = loadProperties();
return props.getProperty("ApiCheckBeginVersion");
}

public static String getApiCheckEndVersionFromProperties() {
Properties props = loadProperties();
return props.getProperty("ApiCheckEndVersion");
}

/**
* Get version from pom.xml
* @return The pom version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;;
Comment thread
VGalaxies marked this conversation as resolved.
Outdated

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());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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.

# 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@

package org.apache.hugegraph.version;

import org.apache.hugegraph.util.VersionUtil;
import org.apache.hugegraph.util.VersionUtil.Version;

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());
}
2 changes: 1 addition & 1 deletion hugegraph-pd/hg-pd-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Comment on lines 35 to 36
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove it?

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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,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",
Expand All @@ -60,16 +64,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");
Expand All @@ -95,7 +92,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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
11 changes: 10 additions & 1 deletion hugegraph-server/hugegraph-dist/src/assembly/travis/start-pd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@
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"
Copy link
Copy Markdown
Contributor

@VGalaxies VGalaxies Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By referencing the version.properties file in hugegraph-commons using a relative path, considering that start-pd.sh and start-store.sh are currently only used in the CI environment, maybe acceptable for now...

@imbajin What do you think?

Copy link
Copy Markdown
Member

@imbajin imbajin Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By referencing the version.properties file in hugegraph-commons using a relative path, considering that start-pd.sh and start-store.sh are currently only used in the CI environment, maybe acceptable for now...

@imbajin What do you think?

It seems so. We can make adjustments if we encounter any problems?

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@
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
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
Comment thread
koi2000 marked this conversation as resolved.

pushd $STORE_DIR
. bin/start-hugegraph-store.sh
Expand Down
Loading