summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2020-09-01 11:22:19 +0200
committerJon Bratseth <bratseth@gmail.com>2020-09-01 11:22:19 +0200
commit56ed305df446f9546a9db267a773d65d7c040d8e (patch)
tree936971d82100910a0d83412646b2ce26f193cd82
parentd2711310822f39f4e5aa4eb4cc107e9f84719450 (diff)
Generate a Vtag class in vespa-http-client
-rwxr-xr-xcomponent/pom.xml2
-rw-r--r--vespa-http-client/pom.xml22
-rwxr-xr-xvespa-http-client/src/main/bin/versiontagger.sh24
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java6
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/Vtag.java7
-rw-r--r--vespajlib/src/main/java/com/yahoo/vespa/VersionTagger.java10
6 files changed, 55 insertions, 16 deletions
diff --git a/component/pom.xml b/component/pom.xml
index 9d8ebb8f037..75b07643c7e 100755
--- a/component/pom.xml
+++ b/component/pom.xml
@@ -76,7 +76,7 @@
<configuration>
<mainClass>com.yahoo.vespa.VersionTagger</mainClass>
<arguments>
- <argument>${project.basedir}/../dist/vtag.map</argument>
+ <argument>${project.basedir}/../dist/vtag.map</argument>
<argument>com.yahoo.component</argument>
<argument>${project.build.directory}/generated-sources/vtag</argument>
<argument>vtag</argument>
diff --git a/vespa-http-client/pom.xml b/vespa-http-client/pom.xml
index 7b055228786..e091af1f4f1 100644
--- a/vespa-http-client/pom.xml
+++ b/vespa-http-client/pom.xml
@@ -97,9 +97,31 @@
</dependency>
</dependencies>
+
<build>
<plugins>
<plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-simplified-vtag</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <configuration>
+ <executable>src/main/bin/versiontagger.sh</executable>
+ <arguments>
+ <argument>${project.basedir}/../dist/vtag.map</argument>
+ <argument>${project.build.directory}/generated-sources/vtag/com/yahoo/vespa/http/client/core/Vtag.java</argument>
+ </arguments>
+ <sourceRoot>${project.build.directory}/generated-sources/vtag</sourceRoot>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
diff --git a/vespa-http-client/src/main/bin/versiontagger.sh b/vespa-http-client/src/main/bin/versiontagger.sh
new file mode 100755
index 00000000000..05682c3f940
--- /dev/null
+++ b/vespa-http-client/src/main/bin/versiontagger.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+# Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+# Extracts the current version number (V_TAG_COMPONENT) from vtag.map and outputs this into a Java class.
+# This replaces vespajlib/../VersionTagger.java as this module cannot depend on that, nor the dependencies
+# of the resulting class.
+#
+# Author: bratseth
+
+source=$1
+destination=$2
+destinationDir=$(dirname $destination)
+
+mkdir -p $destinationDir
+
+versionNumber=$(cat $source | grep V_TAG_COMPONENT | awk '{print $2}' )
+
+cat > $destination <<- END
+package com.yahoo.vespa.http.client.core;
+
+public class Vtag {
+ public static final String V_TAG_COMPONENT = "$versionNumber";
+}
+END
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java
index a46b2e67fe1..bd5cf761024 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java
@@ -8,6 +8,7 @@ import com.yahoo.security.SslContextBuilder;
import com.yahoo.vespa.http.client.config.ConnectionParams;
import com.yahoo.vespa.http.client.config.Endpoint;
import com.yahoo.vespa.http.client.config.FeedParams;
+import com.yahoo.vespa.http.client.core.Vtag;
import com.yahoo.vespa.http.client.core.Document;
import com.yahoo.vespa.http.client.core.Encoder;
import com.yahoo.vespa.http.client.core.Headers;
@@ -16,7 +17,6 @@ import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
-import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.InputStreamEntity;
@@ -427,8 +427,8 @@ class ApacheGatewayConnection implements GatewayConnection {
}
clientBuilder.setMaxConnPerRoute(1);
clientBuilder.setMaxConnTotal(1);
- clientBuilder.setUserAgent(String.format("vespa-http-client (%s)", Vtag.currentVersion));
- clientBuilder.setDefaultHeaders(Collections.singletonList(new BasicHeader(Headers.CLIENT_VERSION, Vtag.currentVersion)));
+ clientBuilder.setUserAgent(String.format("vespa-http-client (%s)", Vtag.V_TAG_COMPONENT));
+ clientBuilder.setDefaultHeaders(Collections.singletonList(new BasicHeader(Headers.CLIENT_VERSION, Vtag.V_TAG_COMPONENT)));
clientBuilder.disableContentCompression();
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
requestConfigBuilder.setSocketTimeout(0);
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/Vtag.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/Vtag.java
deleted file mode 100644
index f44a30208e7..00000000000
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/Vtag.java
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-package com.yahoo.vespa.http.client.core.communication;
-
-class Vtag {
- static final String currentVersion = "7.1.0";
-}
diff --git a/vespajlib/src/main/java/com/yahoo/vespa/VersionTagger.java b/vespajlib/src/main/java/com/yahoo/vespa/VersionTagger.java
index b2d2258798e..004e584a4a9 100644
--- a/vespajlib/src/main/java/com/yahoo/vespa/VersionTagger.java
+++ b/vespajlib/src/main/java/com/yahoo/vespa/VersionTagger.java
@@ -16,10 +16,10 @@ import java.util.Map;
* This class generates a java class based on the vtag.map file generated by dist/getversion.pl
*/
public class VersionTagger {
+
public static final String V_TAG_PKG = "V_TAG_PKG";
- VersionTagger() throws IOException {
- }
+ VersionTagger() {}
private static void printUsage(PrintStream out) {
out.println("Usage: java VersionTagger vtagmap pkgname outputdir");
@@ -47,7 +47,7 @@ public class VersionTagger {
String line;
while ((line = in.readLine()) != null) {
if (line.isBlank()) continue;
- String elements[] = line.split("\\s+", 2);
+ String[] elements = line.split("\\s+", 2);
map.put(elements[0], elements[1]);
}
} catch (FileNotFoundException e) {
@@ -72,8 +72,7 @@ public class VersionTagger {
VTAG
}
- void runProgram(String[] args) throws IOException, InterruptedException {
-
+ void runProgram(String[] args) throws IOException {
String vtagmapPath = args[0];
String packageName = args[1];
String dirName = args[2] + "/" + packageName.replaceAll("\\.", "/");
@@ -131,4 +130,5 @@ public class VersionTagger {
writer.write("}\n");
writer.close();
}
+
}