This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new dba6873 Supports show details of ShardingSphere's version (#14348)
dba6873 is described below
commit dba687351c3800fa175d9bff88fdc66d64c0bbff
Author: 吴伟杰 <[email protected]>
AuthorDate: Fri Dec 31 15:35:17 2021 +0800
Supports show details of ShardingSphere's version (#14348)
* Add git-commit-id-plugin
* Add ShardingSphereVersion
* Update rules of checkstyle
* Update ShardingSphereVersion
* Update Proxy startup scripts
* Include useful properties only
* Add abbrev commit id
* Update version of Proxy
* Minor refactor
* Remove template from proxy backend
* Disable failed on no git or repo info
* Use offline mode
* Update config
* Refactor ShardingSphereVersion
* Add dirty flag to Proxy's version
* Revert "Update rules of checkstyle"
This reverts commit 20c32ae3826fc36cf703561b4d218865462e6a56.
* Ignore commit info if it's not SNAPSHOT
---
pom.xml | 30 ++++++++
.../src/main/resources/bin/start.bat | 14 +++-
.../src/main/resources/bin/start.sh | 9 +++
.../shardingsphere-infra-common/pom.xml | 24 ++++++
.../autogen/version/ShardingSphereVersion.java | 85 ++++++++++++++++++++++
.../shardingsphere-proxy-backend/pom.xml | 19 -----
.../proxy/backend/version/ProxyVersion.java | 26 -------
.../proxy/initializer/BootstrapInitializer.java | 15 +++-
8 files changed, 174 insertions(+), 48 deletions(-)
diff --git a/pom.xml b/pom.xml
index 0a837d5..869d743 100644
--- a/pom.xml
+++ b/pom.xml
@@ -143,6 +143,7 @@
<docker-compose-maven-plugin.version>4.0.0</docker-compose-maven-plugin.version>
<checksum-maven-plugin.version>1.10</checksum-maven-plugin.version>
<templating-maven-plugin.version>1.0.0</templating-maven-plugin.version>
+ <git-commit-id-plugin.version>4.9.10</git-commit-id-plugin.version>
<bcprov-jdk15on.version>1.64</bcprov-jdk15on.version>
<maven.deploy.skip>false</maven.deploy.skip>
</properties>
@@ -781,6 +782,35 @@
<artifactId>templating-maven-plugin</artifactId>
<version>${templating-maven-plugin.version}</version>
</plugin>
+ <plugin>
+ <groupId>pl.project13.maven</groupId>
+ <artifactId>git-commit-id-plugin</artifactId>
+ <version>${git-commit-id-plugin.version}</version>
+ <executions>
+ <execution>
+ <id>get-the-git-infos</id>
+ <goals>
+ <goal>revision</goal>
+ </goals>
+ <phase>initialize</phase>
+ </execution>
+ </executions>
+ <configuration>
+
<generateGitPropertiesFile>true</generateGitPropertiesFile>
+
<generateGitPropertiesFilename>${project.build.outputDirectory}/current-git-commit.properties</generateGitPropertiesFilename>
+ <failOnNoGitDirectory>false</failOnNoGitDirectory>
+
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
+ <offline>true</offline>
+
<injectIntoSysProperties>false</injectIntoSysProperties>
+ <includeOnlyProperties>
+
<includeOnlyProperty>^git\.branch$</includeOnlyProperty>
+
<includeOnlyProperty>^git\.build\.(time|version)$</includeOnlyProperty>
+
<includeOnlyProperty>^git\.commit\.id(\.abbrev)?$</includeOnlyProperty>
+
<includeOnlyProperty>^git\.commit\.message\.short$</includeOnlyProperty>
+
<includeOnlyProperty>^git\.(dirty|tags)$</includeOnlyProperty>
+ </includeOnlyProperties>
+ </configuration>
+ </plugin>
</plugins>
</pluginManagement>
<plugins>
diff --git
a/shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/bin/start.bat
b/shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/bin/start.bat
index 3ee5888..48ad08b 100644
---
a/shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/bin/start.bat
+++
b/shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/bin/start.bat
@@ -34,6 +34,14 @@ if "%PORT%"=="--help" (
goto print_usage
)
+if "%PORT%"=="-v" (
+ goto print_version
+)
+
+if "%PORT%"=="--version" (
+ goto print_version
+)
+
if "%PORT%"=="" (
set MAIN_CLASS=org.apache.shardingsphere.proxy.Bootstrap
set CLASS_PATH=../conf;%CLASS_PATH%
@@ -60,7 +68,11 @@ goto exit
echo "usage: start.bat [port] [config_dir]"
echo " port: proxy listen port, default is 3307"
echo " config_dir: proxy config directory, default is conf"
- pause
+ goto exit
+
+:print_version
+ java -classpath %CLASS_PATH%
org.apache.shardingsphere.infra.autogen.version.ShardingSphereVersion
+ goto exit
:exit
pause
diff --git
a/shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/bin/start.sh
b/shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/bin/start.sh
index d1936eb..8e99003 100644
---
a/shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/bin/start.sh
+++
b/shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/bin/start.sh
@@ -49,6 +49,15 @@ if [ "$1" == "-h" ] || [ "$1" == "--help" ] ; then
print_usage
fi
+print_version() {
+ java ${JAVA_OPTS} ${JAVA_MEM_OPTS} -classpath ${CLASS_PATH}
org.apache.shardingsphere.infra.autogen.version.ShardingSphereVersion
+ exit 0
+}
+
+if [ "$1" == "-v" ] || [ "$1" == "--version" ] ; then
+ print_version
+fi
+
echo "Starting the $SERVER_NAME ..."
if [ $# == 0 ]; then
diff --git a/shardingsphere-infra/shardingsphere-infra-common/pom.xml
b/shardingsphere-infra/shardingsphere-infra-common/pom.xml
index 5493357..3ea6ddd 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/pom.xml
+++ b/shardingsphere-infra/shardingsphere-infra-common/pom.xml
@@ -76,4 +76,28 @@
<artifactId>commons-dbcp2</artifactId>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>templating-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>filtering-proxy-version</id>
+ <goals>
+ <goal>filter-sources</goal>
+ </goals>
+ <configuration>
+
<sourceDirectory>src/main/templates</sourceDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>pl.project13.maven</groupId>
+ <artifactId>git-commit-id-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/templates/org/apache/shardingsphere/infra/autogen/version/ShardingSphereVersion.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/templates/org/apache/shardingsphere/infra/autogen/version/ShardingSphereVersion.java
new file mode 100644
index 0000000..8ea772e
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/templates/org/apache/shardingsphere/infra/autogen/version/ShardingSphereVersion.java
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+
+package org.apache.shardingsphere.infra.autogen.version;
+
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * Build info of ShardingSphere. Values prefixed with `BUILD` will be empty if
building from source codes without .git directory.
+ */
+public final class ShardingSphereVersion {
+
+ public static final String VERSION = "${project.version}";
+
+ static {
+ Properties info = new Properties();
+ try {
+
info.load(ShardingSphereVersion.class.getResourceAsStream("/current-git-commit.properties"));
+ } catch (final Exception ignored) {
+ }
+ IS_SNAPSHOT = VERSION.endsWith("SNAPSHOT");
+ BUILD_BRANCH = info.getProperty("git.branch", "");
+ BUILD_TIME = info.getProperty("git.build.time", "");
+ BUILD_GIT_COMMIT_ID = info.getProperty("git.commit.id", "");
+ BUILD_GIT_COMMIT_ID_ABBREV = info.getProperty("git.commit.id.abbrev",
"");
+ BUILD_GIT_COMMIT_MESSAGE_SHORT =
info.getProperty("git.commit.message.short", "");
+ BUILD_GIT_TAG = info.getProperty("git.tags", "");
+ BUILD_GIT_DIRTY = Boolean.parseBoolean(info.getProperty("git.dirty"));
+ }
+
+ public static final boolean IS_SNAPSHOT;
+
+ public static final String BUILD_BRANCH;
+
+ public static final String BUILD_TIME;
+
+ public static final String BUILD_GIT_COMMIT_ID;
+
+ public static final String BUILD_GIT_COMMIT_ID_ABBREV;
+
+ public static final String BUILD_GIT_COMMIT_MESSAGE_SHORT;
+
+ public static final String BUILD_GIT_TAG;
+
+ public static final boolean BUILD_GIT_DIRTY;
+
+ private ShardingSphereVersion() {
+ }
+
+ /**
+ * Print version info of ShardingSphere to stdout.
+ *
+ * @param args args
+ */
+ public static void main(final String[] args) {
+ System.out.print(getVerboseVersion());
+ }
+
+ private static String getVerboseVersion() {
+ String result = "";
+ result += String.format("ShardingSphere-%s%n", VERSION);
+ if (IS_SNAPSHOT && !BUILD_GIT_COMMIT_ID.isEmpty()) {
+ result += String.format("Commit ID: %s%s%n", BUILD_GIT_DIRTY ?
"dirty-" : "", BUILD_GIT_COMMIT_ID);
+ result += String.format("Commit Message: %s%n",
BUILD_GIT_COMMIT_MESSAGE_SHORT);
+ result += BUILD_GIT_TAG.isEmpty() ? String.format("Branch: %s%n",
BUILD_BRANCH) : String.format("Tag: %s%n", BUILD_GIT_TAG);
+ result += String.format("Build time: %s%n", BUILD_TIME);
+ }
+ return result;
+ }
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
b/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
index 064f3e6..6f1cc45 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
@@ -182,23 +182,4 @@
<scope>runtime</scope>
</dependency>
</dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>templating-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>filtering-proxy-version</id>
- <goals>
- <goal>filter-sources</goal>
- </goals>
- <configuration>
-
<sourceDirectory>src/main/templates</sourceDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
</project>
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/templates/org/apache/shardingsphere/proxy/backend/version/ProxyVersion.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/templates/org/apache/shardingsphere/proxy/backend/version/ProxyVersion.java
deleted file mode 100644
index 33f6bba..0000000
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/templates/org/apache/shardingsphere/proxy/backend/version/ProxyVersion.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.shardingsphere.proxy.backend.version;
-
-/**
- * Proxy version.
- */
-public final class ProxyVersion {
-
- public static final String VERSION = "${project.version}";
-}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
index a2c2571..b5f017e 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.proxy.initializer;
+import com.google.common.base.Strings;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import
org.apache.shardingsphere.data.pipeline.scenario.rulealtered.RuleAlteredContext;
@@ -28,12 +29,12 @@ import
org.apache.shardingsphere.infra.config.datasource.DataSourceConverter;
import org.apache.shardingsphere.infra.config.datasource.DataSourceParameter;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.autogen.version.ShardingSphereVersion;
import
org.apache.shardingsphere.infra.yaml.config.swapper.mode.ModeConfigurationYamlSwapper;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.ContextManagerBuilderFactory;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.version.ProxyVersion;
import org.apache.shardingsphere.proxy.config.ProxyConfiguration;
import org.apache.shardingsphere.proxy.config.YamlProxyConfiguration;
import
org.apache.shardingsphere.proxy.config.util.DataSourceParameterConverter;
@@ -102,7 +103,7 @@ public final class BootstrapInitializer {
}
private void setDatabaseServerInfo() {
- CommonConstants.PROXY_VERSION.set(ProxyVersion.VERSION);
+ CommonConstants.PROXY_VERSION.set(getShardingSphereVersion());
findBackendDataSource().ifPresent(dataSourceSample -> {
DatabaseServerInfo databaseServerInfo = new
DatabaseServerInfo(dataSourceSample);
log.info(databaseServerInfo.toString());
@@ -118,6 +119,16 @@ public final class BootstrapInitializer {
});
}
+ private String getShardingSphereVersion() {
+ String result = ShardingSphereVersion.VERSION;
+ if (!ShardingSphereVersion.IS_SNAPSHOT ||
Strings.isNullOrEmpty(ShardingSphereVersion.BUILD_GIT_COMMIT_ID_ABBREV)) {
+ return result;
+ }
+ result += ShardingSphereVersion.BUILD_GIT_DIRTY ? "-dirty" : "";
+ result += "-" + ShardingSphereVersion.BUILD_GIT_COMMIT_ID_ABBREV;
+ return result;
+ }
+
private Optional<DataSource> findBackendDataSource() {
MetaDataContexts metaDataContexts =
ProxyContext.getInstance().getContextManager().getMetaDataContexts();
Optional<ShardingSphereMetaData> metaData =
metaDataContexts.getMetaDataMap().values().stream().filter(ShardingSphereMetaData::isComplete).findFirst();