You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2019/03/24 16:17:08 UTC
[pulsar] branch master updated: Encode client version into Java
source file instead of pulsar-client-version.properties (#3880)
This is an automated email from the ASF dual-hosted git repository.
mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 5653df8 Encode client version into Java source file instead of pulsar-client-version.properties (#3880)
5653df8 is described below
commit 5653df8b396d1876e09bf002bf02e55f97a62415
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Sun Mar 24 09:17:04 2019 -0700
Encode client version into Java source file instead of pulsar-client-version.properties (#3880)
---
pulsar-client/pom.xml | 13 +++++++++
.../org/apache/pulsar/PulsarVersion.java | 25 +++++++++++++++++
.../org/apache/pulsar/client/impl/ClientCnx.java | 7 ++---
.../org/apache/pulsar/client/impl/HttpClient.java | 32 ++--------------------
.../resources/pulsar-client-version.properties | 20 --------------
.../apache/pulsar/proxy/server/ProxyClientCnx.java | 10 +++----
6 files changed, 48 insertions(+), 59 deletions(-)
diff --git a/pulsar-client/pom.xml b/pulsar-client/pom.xml
index bc97c56..3ad3fb4 100644
--- a/pulsar-client/pom.xml
+++ b/pulsar-client/pom.xml
@@ -167,6 +167,19 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>templating-maven-plugin</artifactId>
+ <version>1.0.0</version>
+ <executions>
+ <execution>
+ <id>filtering-java-templates</id>
+ <goals>
+ <goal>filter-sources</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</project>
diff --git a/pulsar-client/src/main/java-templates/org/apache/pulsar/PulsarVersion.java b/pulsar-client/src/main/java-templates/org/apache/pulsar/PulsarVersion.java
new file mode 100644
index 0000000..f27a7e0
--- /dev/null
+++ b/pulsar-client/src/main/java-templates/org/apache/pulsar/PulsarVersion.java
@@ -0,0 +1,25 @@
+/**
+ * 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.pulsar;
+
+public class PulsarVersion {
+ public static String getVersion() {
+ return "${project.version}";
+ }
+}
diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientCnx.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientCnx.java
index 5f2dae0..948c027 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientCnx.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientCnx.java
@@ -20,9 +20,7 @@ package org.apache.pulsar.client.impl;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
-import static org.apache.pulsar.client.impl.HttpClient.getPulsarClientVersion;
-import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.channels.ClosedChannelException;
@@ -40,6 +38,7 @@ import javax.net.ssl.SSLSession;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.http.conn.ssl.DefaultHostnameVerifier;
+import org.apache.pulsar.PulsarVersion;
import org.apache.pulsar.client.api.Authentication;
import org.apache.pulsar.client.api.AuthenticationDataProvider;
import org.apache.pulsar.client.api.PulsarClientException;
@@ -202,7 +201,7 @@ public class ClientCnx extends PulsarHandler {
authenticationDataProvider = authentication.getAuthData(remoteHostName);
AuthData authData = authenticationDataProvider.authenticate(AuthData.of(AuthData.INIT_AUTH_DATA));
return Commands.newConnect(authentication.getAuthMethodName(), authData, this.protocolVersion,
- getPulsarClientVersion(), proxyToTargetBrokerAddress, null, null, null);
+ PulsarVersion.getVersion(), proxyToTargetBrokerAddress, null, null, null);
}
@Override
@@ -300,7 +299,7 @@ public class ClientCnx extends PulsarHandler {
ByteBuf request = Commands.newAuthResponse(authentication.getAuthMethodName(),
authData,
this.protocolVersion,
- getPulsarClientVersion());
+ PulsarVersion.getVersion());
if (log.isDebugEnabled()) {
log.debug("{} Mutual auth {}", ctx.channel(), authentication.getAuthMethodName());
diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/HttpClient.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/HttpClient.java
index 43e5bd7..91818ab 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/HttpClient.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/HttpClient.java
@@ -34,6 +34,7 @@ import java.util.Map;
import java.util.Properties;
import java.util.concurrent.CompletableFuture;
+import org.apache.pulsar.PulsarVersion;
import org.apache.pulsar.client.api.Authentication;
import org.apache.pulsar.client.api.AuthenticationDataProvider;
import org.apache.pulsar.client.api.PulsarClientException;
@@ -80,7 +81,7 @@ public class HttpClient implements Closeable {
confBuilder.setFollowRedirect(true);
confBuilder.setConnectTimeout(connectTimeoutInSeconds * 1000);
confBuilder.setReadTimeout(readTimeoutInSeconds * 1000);
- confBuilder.setUserAgent(String.format("Pulsar-Java-v%s", getPulsarClientVersion()));
+ confBuilder.setUserAgent(String.format("Pulsar-Java-v%s", PulsarVersion.getVersion()));
confBuilder.setKeepAliveStrategy(new DefaultKeepAliveStrategy() {
@Override
public boolean keepAlive(Request ahcRequest, HttpRequest request, HttpResponse response) {
@@ -193,34 +194,5 @@ public class HttpClient implements Closeable {
}
- /**
- * Looks for a file called pulsar-client-version.properties and returns the client version
- *
- * @return client version or unknown version depending on whether the file is found or not.
- */
- public static String getPulsarClientVersion() {
- String path = "/pulsar-client-version.properties";
- String unknownClientIdentifier = "UnknownClient";
-
- try {
- InputStream stream = HttpClient.class.getResourceAsStream(path);
- if (stream == null) {
- return unknownClientIdentifier;
- }
- Properties props = new Properties();
- try {
- props.load(stream);
- String version = (String) props.get("pulsar-client-version");
- return version;
- } catch (IOException e) {
- return unknownClientIdentifier;
- } finally {
- stream.close();
- }
- } catch (Throwable t) {
- return unknownClientIdentifier;
- }
- }
-
private static final Logger log = LoggerFactory.getLogger(HttpClient.class);
}
diff --git a/pulsar-client/src/main/resources/pulsar-client-version.properties b/pulsar-client/src/main/resources/pulsar-client-version.properties
deleted file mode 100644
index bdda194..0000000
--- a/pulsar-client/src/main/resources/pulsar-client-version.properties
+++ /dev/null
@@ -1,20 +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.
-#
-
-pulsar-client-version=${project.version}
\ No newline at end of file
diff --git a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyClientCnx.java b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyClientCnx.java
index a075840..91e7345 100644
--- a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyClientCnx.java
+++ b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyClientCnx.java
@@ -18,8 +18,10 @@
*/
package org.apache.pulsar.proxy.server;
-import static org.apache.pulsar.client.impl.HttpClient.getPulsarClientVersion;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.EventLoopGroup;
+import org.apache.pulsar.PulsarVersion;
import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.client.impl.ClientCnx;
import org.apache.pulsar.client.impl.conf.ClientConfigurationData;
@@ -27,9 +29,6 @@ import org.apache.pulsar.common.api.Commands;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import io.netty.buffer.ByteBuf;
-import io.netty.channel.EventLoopGroup;
-
public class ProxyClientCnx extends ClientCnx {
String clientAuthRole;
@@ -58,7 +57,8 @@ public class ProxyClientCnx extends ClientCnx {
authData = authentication.getAuthData().getCommandData();
}
return Commands.newConnect(authentication.getAuthMethodName(), authData, protocolVersion,
- getPulsarClientVersion(), proxyToTargetBrokerAddress, clientAuthRole, clientAuthData, clientAuthMethod);
+ PulsarVersion.getVersion(), proxyToTargetBrokerAddress, clientAuthRole, clientAuthData,
+ clientAuthMethod);
}
private static final Logger log = LoggerFactory.getLogger(ProxyClientCnx.class);