-
Notifications
You must be signed in to change notification settings - Fork 580
refactor: centralize version management in project #2797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4689874
ce80946
ccac86d
1bdc2ee
744ee1c
33266dc
5a7ce1e
736ff63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
|
||
| 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 |
|---|---|---|
|
|
@@ -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 | ||
|
Comment on lines
35
to
36
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By referencing the @imbajin What do you think?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It seems so. We can make adjustments if we encounter any problems? |
||
| 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 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.