Skip to content

Commit

Permalink
TINKERPOP-2954 Use maven replacer plugin to inject version into clients
Browse files Browse the repository at this point in the history
Removes the jcabi manifest based version injection system. Manifest system
was subject to errors in systems which removed manifests from jars and was
also not compatible with GLV's.
  • Loading branch information
Cole-Greer committed Jun 28, 2023
1 parent 98d24d0 commit 842494b
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,13 @@
*/
package org.apache.tinkerpop.gremlin.util;

import com.jcabi.manifests.Manifests;

import java.io.IOException;

/**
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
public final class Gremlin {
private static String version;

static {
try {
version = Manifests.read("version");
}
catch (Throwable t) {
version = "VersionNotFound";
}
}
private final static String gremlinVersion = "3.5.7-SNAPSHOT"; // Configured automatically by Maven Replace Plugin

private Gremlin() {
}
Expand All @@ -45,7 +34,7 @@ private Gremlin() {
* the version. This typically would be the result of the version being missing from the manifest file.
*/
public static String version() {
return version;
return gremlinVersion;
}

public static void main(final String[] arguments) throws IOException {
Expand Down
5 changes: 5 additions & 0 deletions gremlin-dotnet/src/Gremlin.Net/Driver/Tokens.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ namespace Gremlin.Net.Driver
/// </summary>
public class Tokens
{
/// <summary>
/// Current TinkerPop version.
/// </summary>
public static string GremlinVersion = "3.5.7-SNAPSHOT"; // Configured automatically by Maven Replace Plugin

/// <summary>
/// The key for the unique identifier of the request.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions gremlin-dotnet/src/Gremlin.Net/Process/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;
using Gremlin.Net.Driver;
using static System.Runtime.InteropServices.RuntimeInformation;

namespace Gremlin.Net.Process
Expand Down Expand Up @@ -79,8 +80,7 @@ private static string GenerateUserAgent()
{
var applicationName = Assembly.GetEntryAssembly()?.GetName().Name?
.Replace(' ', '_') ?? "NotAvailable";
var driverVersion = Assembly.GetExecutingAssembly().GetName().Version?.ToString()
.Replace(' ', '_') ?? "NotAvailable";
var driverVersion = Tokens.GremlinVersion;
var languageVersion = Environment.Version.ToString().Replace(' ', '_');
var osName = Environment.OSVersion.Platform.ToString().Replace(' ', '_');
var osVersion = Environment.OSVersion.Version.ToString().Replace(' ', '_');
Expand Down
16 changes: 3 additions & 13 deletions gremlin-go/driver/user_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"os"
"path/filepath"
"runtime"
"runtime/debug"
"strings"
)

Expand All @@ -38,28 +37,19 @@ var userAgent string

const userAgentHeader = "User-Agent"

const gremlinVersion = "3.5.7-SNAPSHOT" // Configured automatically by Maven Replace Plugin

func init() {
applicationName := "NotAvailable"
driverVersion := "NotAvailable"

path, err := os.Executable()
if err == nil {
applicationName = filepath.Base(path)
}

bi, ok := debug.ReadBuildInfo()
if ok {
for _, dep := range bi.Deps {
if strings.Contains(dep.Path, "gremlin-go") {
driverVersion = dep.Version
break
}
}
}
applicationName = strings.ReplaceAll(applicationName, " ", "_")
driverVersion = strings.ReplaceAll(driverVersion, " ", "_")
runtimeVersion := strings.ReplaceAll(runtime.Version(), " ", "_")
osName := strings.ReplaceAll(runtime.GOOS, " ", "_")
architecture := strings.ReplaceAll(runtime.GOARCH, " ", "_")
userAgent = fmt.Sprintf("%v Gremlin-Go.%v %v %v.NotAvailable %v", applicationName, driverVersion, runtimeVersion, osName, architecture)
userAgent = fmt.Sprintf("%v Gremlin-Go.%v %v %v.NotAvailable %v", applicationName, gremlinVersion, runtimeVersion, osName, architecture)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const crypto = require('crypto');
const os = require('os');
const { readFileSync } = require('fs');

const gremlinVersion = "3.5.7-SNAPSHOT"; // Configured automatically by Maven Replace Plugin

exports.toLong = function toLong(value) {
return new Long(value);
};
Expand Down Expand Up @@ -84,12 +86,6 @@ exports.ImmutableMap = ImmutableMap;

function generateUserAgent() {
const applicationName = (process.env.npm_package_name || 'NotAvailable').replace('_', ' ');
let driverVersion;
try {
driverVersion = JSON.parse(readFileSync(__dirname + '/../package.json')).version.replace('_', ' ');
} catch (e) {
driverVersion = 'NotAvailable';
}
let runtimeVersion;
let osName;
let osVersion;
Expand All @@ -108,7 +104,7 @@ function generateUserAgent() {
osVersion = os.release().replace(' ', '_');
}

const userAgent = `${applicationName} Gremlin-Javascript.${driverVersion} ${runtimeVersion} ${osName}.${osVersion} ${cpuArch}`;
const userAgent = `${applicationName} Gremlin-Javascript.${gremlinVersion} ${runtimeVersion} ${osName}.${osVersion} ${cpuArch}`;

return userAgent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,16 @@
#
import platform

gremlin_version = "3.5.7-SNAPSHOT" # Configured automatically by Maven Replace Plugin

def _generate_user_agent():
application_name = "NotAvailable"
try:
from gremlin_python import __version__
driver_version = __version__.version.replace(" ", "_")
except ImportError:
driver_version = "NotAvailable"
runtime_version = platform.python_version().replace(" ", "_")
os_name = platform.system().replace(" ", "_")
os_version = platform.release().replace(" ", "_")
architecture = platform.machine().replace(" ", "_")
user_agent = "{appName} Gremlin-Python.{driverVersion} {runtimeVersion} {osName}.{osVersion} {cpuArch}".format(
appName=application_name, driverVersion=driver_version, runtimeVersion=runtime_version,
appName=application_name, driverVersion=gremlin_version, runtimeVersion=runtime_version,
osName=os_name, osVersion=os_version, cpuArch=architecture)

return user_agent
Expand Down
37 changes: 37 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,43 @@ limitations under the License.
<build>
<directory>${basedir}/target</directory>
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<basedir>${basedir}</basedir>
<includes>
<include>gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/Gremlin.java</include>
<include>gremlin-dotnet/src/Gremlin.Net/Driver/Tokens.cs</include>
<include>gremlin-python/src/main/python/gremlin_python/driver/useragent.py</include>
<include>gremlin-javascript/src/main/javascript/gremlin-javascript/lib/utils.js</include>
<include>gremlin-go/driver/user_agent.go</include>
</includes>
<replacements>
<replacement>
<token>gremlinVersion = ".*"</token>
<value>gremlinVersion = "${project.version}"</value>
</replacement>
<replacement>
<token>GremlinVersion = ".*"</token>
<value>GremlinVersion = "${project.version}"</value>
</replacement>
<replacement>
<token>gremlin_version = ".*"</token>
<value>gremlin_version = "${project.version}"</value>
</replacement>
</replacements>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
Expand Down

0 comments on commit 842494b

Please sign in to comment.