Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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>
<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,14 +19,18 @@

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
Expand Down Expand Up @@ -102,6 +106,72 @@ public static String getImplementationVersion(String manifestPath) {
.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
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;
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());
}
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=2.0
VersionInBash=1.9.5
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-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

<properties>
<!-- Note: We need also update the version in CommonVersion.java & RpcVersion.java now -->
<revision>1.5.0</revision>
<revision>1.9.5</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<top.level.dir>${project.basedir}/..</top.level.dir>
<compiler.source>1.8</compiler.source>
Expand Down
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
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 @@ -36,18 +36,23 @@
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",
Expand All @@ -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");
Expand All @@ -95,10 +93,56 @@
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);

Check warning on line 130 in hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/ApplicationConfig.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/ApplicationConfig.java#L130

Added line #L130 was not covered by tests
}
builder.buildContext(true);
} catch (OpenApiConfigurationException e) {
throw new RuntimeException(e.getMessage(), e);

Check warning on line 134 in hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/ApplicationConfig.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/ApplicationConfig.java#L133-L134

Added lines #L133 - L134 were not covered by tests
}
}
}

@Override
public RequestEventListener onRequest(RequestEvent requestEvent) {
return null;
}
});
}

private class ConfFactory extends AbstractBinder implements Factory<HugeConfig> {

private final HugeConfig conf;
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
13 changes: 12 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,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
</scm>

<properties>
<revision>1.5.0</revision>
<hugegraph-commons.version>1.5.0</hugegraph-commons.version>
<revision>1.9.5</revision>
<hugegraph-commons.version>1.9.5</hugegraph-commons.version>
<lombok.version>1.18.30</lombok.version>
<release.name>hugegraph</release.name>
<maven.compiler.source>11</maven.compiler.source>
Expand Down
Loading