This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 82f9efc Use project.version instead of proxy version (#13439)
82f9efc is described below
commit 82f9efc477f45195d4c27bd0b193a241bc6eef63
Author: Haoran Meng <[email protected]>
AuthorDate: Wed Nov 3 18:43:22 2021 +0800
Use project.version instead of proxy version (#13439)
* Use project.version instead of proxy version
---
.../shardingsphere/db/protocol/CommonConstants.java | 3 +++
.../db/protocol/mysql/constant/MySQLServerInfo.java | 8 +++-----
.../protocol/mysql/constant/MySQLServerInfoTest.java | 3 +++
.../postgresql/constant/PostgreSQLServerInfo.java | 8 +++-----
.../postgresql/constant/PostgreSQLServerInfoTest.java | 3 +++
.../shardingsphere-proxy-backend/pom.xml | 19 +++++++++++++++++++
.../proxy/backend/version/ProxyVersion.java | 15 ++++-----------
.../proxy/initializer/BootstrapInitializer.java | 3 +++
8 files changed, 41 insertions(+), 21 deletions(-)
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/CommonConstants.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/CommonConstants.java
index 44c322e..e23d8d7 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/CommonConstants.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/CommonConstants.java
@@ -22,6 +22,7 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import java.nio.charset.Charset;
+import java.util.concurrent.atomic.AtomicReference;
/**
* Common constants for protocol.
@@ -30,4 +31,6 @@ import java.nio.charset.Charset;
public final class CommonConstants {
public static final AttributeKey<Charset> CHARSET_ATTRIBUTE_KEY =
AttributeKey.valueOf(Charset.class.getName());
+
+ public static final AtomicReference<String> PROXY_VERSION = new
AtomicReference<>();
}
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
index c399b7c..f34a6d5 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.db.protocol.mysql.constant;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.db.protocol.CommonConstants;
/**
* ShardingSphere-Proxy's information for MySQL.
@@ -35,9 +36,6 @@ public final class MySQLServerInfo {
private static final String DEFAULT_MYSQL_VERSION = "5.7.22";
- // TODO Write version here is easy to forget. Consider refactoring it.
- private static final String PROXY_VERSION = "5.0.0";
-
private static final String SERVER_VERSION_PATTERN =
"%s-ShardingSphere-Proxy %s";
private static volatile String serverVersion;
@@ -48,7 +46,7 @@ public final class MySQLServerInfo {
* @param serverVersion server version
*/
public static synchronized void setServerVersion(final String
serverVersion) {
- MySQLServerInfo.serverVersion = null == serverVersion ? null :
String.format(SERVER_VERSION_PATTERN, serverVersion, PROXY_VERSION);
+ MySQLServerInfo.serverVersion = null == serverVersion ? null :
String.format(SERVER_VERSION_PATTERN, serverVersion,
CommonConstants.PROXY_VERSION.get());
}
/**
@@ -57,6 +55,6 @@ public final class MySQLServerInfo {
* @return server version
*/
public static String getServerVersion() {
- return null == serverVersion ? String.format(SERVER_VERSION_PATTERN,
DEFAULT_MYSQL_VERSION, PROXY_VERSION) : serverVersion;
+ return null == serverVersion ? String.format(SERVER_VERSION_PATTERN,
DEFAULT_MYSQL_VERSION, CommonConstants.PROXY_VERSION.get()) : serverVersion;
}
}
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfoTest.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfoTest.java
index 2f37cd5..42dd586 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfoTest.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfoTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.db.protocol.mysql.constant;
+import org.apache.shardingsphere.db.protocol.CommonConstants;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
@@ -26,12 +27,14 @@ public final class MySQLServerInfoTest {
@Test
public void assertSetServerVersion() {
+ CommonConstants.PROXY_VERSION.set("5.0.0");
MySQLServerInfo.setServerVersion("5.1.47");
assertThat(MySQLServerInfo.getServerVersion(),
is("5.1.47-ShardingSphere-Proxy 5.0.0"));
}
@Test
public void assertSetServerVersionForNull() {
+ CommonConstants.PROXY_VERSION.set("5.0.0");
MySQLServerInfo.setServerVersion(null);
assertThat(MySQLServerInfo.getServerVersion(),
is("5.7.22-ShardingSphere-Proxy 5.0.0"));
}
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfo.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfo.java
index b066b0e..e33e9e1 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfo.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfo.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.db.protocol.postgresql.constant;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.db.protocol.CommonConstants;
/**
* ShardingSphere-Proxy's information for PostgreSQL.
@@ -28,9 +29,6 @@ public final class PostgreSQLServerInfo {
private static final String DEFAULT_POSTGRESQL_VERSION = "12.3";
- // TODO Write version here is easy to forget. Consider refactoring it.
- private static final String PROXY_VERSION = "5.0.0";
-
private static final String SERVER_VERSION_PATTERN =
"%s-ShardingSphere-Proxy %s";
private static volatile String serverVersion;
@@ -41,7 +39,7 @@ public final class PostgreSQLServerInfo {
* @param serverVersion server version
*/
public static synchronized void setServerVersion(final String
serverVersion) {
- PostgreSQLServerInfo.serverVersion = null == serverVersion ? null :
String.format(SERVER_VERSION_PATTERN, serverVersion, PROXY_VERSION);
+ PostgreSQLServerInfo.serverVersion = null == serverVersion ? null :
String.format(SERVER_VERSION_PATTERN, serverVersion,
CommonConstants.PROXY_VERSION.get());
}
/**
@@ -50,6 +48,6 @@ public final class PostgreSQLServerInfo {
* @return server version
*/
public static String getServerVersion() {
- return null == serverVersion ? String.format(SERVER_VERSION_PATTERN,
DEFAULT_POSTGRESQL_VERSION, PROXY_VERSION) : serverVersion;
+ return null == serverVersion ? String.format(SERVER_VERSION_PATTERN,
DEFAULT_POSTGRESQL_VERSION, CommonConstants.PROXY_VERSION.get()) :
serverVersion;
}
}
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfoTest.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfoTest.java
index bc64fb4..7ffc5b3 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfoTest.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfoTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.db.protocol.postgresql.constant;
+import org.apache.shardingsphere.db.protocol.CommonConstants;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
@@ -26,12 +27,14 @@ public final class PostgreSQLServerInfoTest {
@Test
public void assertSetServerVersion() {
+ CommonConstants.PROXY_VERSION.set("5.0.0");
PostgreSQLServerInfo.setServerVersion("13.2");
assertThat(PostgreSQLServerInfo.getServerVersion(),
is("13.2-ShardingSphere-Proxy 5.0.0"));
}
@Test
public void assertSetServerVersionForNull() {
+ CommonConstants.PROXY_VERSION.set("5.0.0");
PostgreSQLServerInfo.setServerVersion(null);
assertThat(PostgreSQLServerInfo.getServerVersion(),
is("12.3-ShardingSphere-Proxy 5.0.0"));
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
b/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
index 330217b..1e7667d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
@@ -166,4 +166,23 @@
<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-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/CommonConstants.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/templates/org/apache/shardingsphere/proxy/backend/version/ProxyVersion.java
similarity index 66%
copy from
shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/CommonConstants.java
copy to
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/templates/org/apache/shardingsphere/proxy/backend/version/ProxyVersion.java
index 44c322e..33f6bba 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/CommonConstants.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/templates/org/apache/shardingsphere/proxy/backend/version/ProxyVersion.java
@@ -15,19 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol;
-
-import io.netty.util.AttributeKey;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-import java.nio.charset.Charset;
+package org.apache.shardingsphere.proxy.backend.version;
/**
- * Common constants for protocol.
+ * Proxy version.
*/
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class CommonConstants {
+public final class ProxyVersion {
- public static final AttributeKey<Charset> CHARSET_ATTRIBUTE_KEY =
AttributeKey.valueOf(Charset.class.getName());
+ 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 e0f6b97..4783d55 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
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.proxy.initializer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.db.protocol.CommonConstants;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
import
org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLServerInfo;
import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
@@ -32,6 +33,7 @@ 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;
@@ -89,6 +91,7 @@ public final class BootstrapInitializer {
}
private void setDatabaseServerInfo() {
+ CommonConstants.PROXY_VERSION.set(ProxyVersion.VERSION);
findBackendDataSource().ifPresent(dataSourceSample -> {
DatabaseServerInfo databaseServerInfo = new
DatabaseServerInfo(dataSourceSample);
log.info(databaseServerInfo.toString());