Skip to content

Commit cf1d0c3

Browse files
author
Elad Ben-Israel
authored
feat: JSII_AGENT (#325)
Language runtimes now set JSII_AGENT to include the runtime version such as "DotNet/1.2.3.4" or "Java/1.8.44". Fixes #324
1 parent 9c59acc commit cf1d0c3

File tree

13 files changed

+201
-9
lines changed

13 files changed

+201
-9
lines changed

packages/jsii-calc/lib/compliance.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,3 +1221,15 @@ class PrivateImplementation extends ExportedBaseClass implements IPrivatelyImple
12211221
super(true);
12221222
}
12231223
}
1224+
1225+
/**
1226+
* Host runtime version should be set via JSII_AGENT
1227+
*/
1228+
export class JsiiAgent {
1229+
/**
1230+
* Returns the value of the JSII_AGENT environment variable.
1231+
*/
1232+
public static get jsiiAgent(): string | undefined {
1233+
return process.env.JSII_AGENT;
1234+
}
1235+
};

packages/jsii-calc/test/assembly.jsii

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,32 @@
20992099
}
21002100
]
21012101
},
2102+
"jsii-calc.JsiiAgent": {
2103+
"assembly": "jsii-calc",
2104+
"docs": {
2105+
"comment": "Host runtime version should be set via JSII_AGENT"
2106+
},
2107+
"fqn": "jsii-calc.JsiiAgent",
2108+
"initializer": {
2109+
"initializer": true
2110+
},
2111+
"kind": "class",
2112+
"name": "JsiiAgent",
2113+
"properties": [
2114+
{
2115+
"docs": {
2116+
"comment": "Returns the value of the JSII_AGENT environment variable."
2117+
},
2118+
"immutable": true,
2119+
"name": "jsiiAgent",
2120+
"static": true,
2121+
"type": {
2122+
"optional": true,
2123+
"primitive": "string"
2124+
}
2125+
}
2126+
]
2127+
},
21022128
"jsii-calc.LoadBalancedFargateServiceProps": {
21032129
"assembly": "jsii-calc",
21042130
"datatype": true,
@@ -3736,5 +3762,5 @@
37363762
}
37373763
},
37383764
"version": "0.7.11",
3739-
"fingerprint": "Nw3vyHfzec4IFe674buqsgL3x8QgvKP0lUC3csRIW7g="
3765+
"fingerprint": "l8bUuUzVdVn151P/XjDEVN9kHkLfJ+d5fmgZVODpQkg="
37403766
}

packages/jsii-dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,12 @@ public void NullShouldBeTreatedAsUndefined()
861861
obj.ChangeMeToUndefined = null;
862862
obj.VerifyPropertyIsUndefined();
863863
}
864+
865+
[Fact(DisplayName = Prefix + nameof(JsiiAgent))]
866+
public void JsiiAgent()
867+
{
868+
Assert.Equal("DotNet/" + Environment.Version.ToString(), JsiiAgent_.JsiiAgent);
869+
}
864870

865871
[Fact(DisplayName = Prefix + nameof(ReceiveInstanceOfPrivateClass))]
866872
public void ReceiveInstanceOfPrivateClass()

packages/jsii-dotnet-runtime/src/Amazon.JSII.Runtime/Services/NodeProcess.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public NodeProcess(IJsiiRuntimeProvider jsiiRuntimeProvider, ILoggerFactory logg
2626
}
2727
};
2828

29+
_process.StartInfo.EnvironmentVariables.Add("JSII_AGENT", "DotNet/" + Environment.Version.ToString());
30+
2931
_logger.LogDebug("Starting jsii runtime...");
3032
_logger.LogDebug($"{_process.StartInfo.FileName} {_process.StartInfo.Arguments}");
3133

packages/jsii-java-runtime-test/project/src/test/java/software/amazon/jsii/testing/ComplianceTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import software.amazon.jsii.tests.calculator.SyncVirtualMethods;
3939
import software.amazon.jsii.tests.calculator.UnionProperties;
4040
import software.amazon.jsii.tests.calculator.UsesInterfaceWithProperties;
41+
import software.amazon.jsii.tests.calculator.JsiiAgent;
4142
import software.amazon.jsii.tests.calculator.composition.CompositeOperation;
4243
import software.amazon.jsii.tests.calculator.lib.EnumFromScopedModule;
4344
import software.amazon.jsii.tests.calculator.lib.IFriendly;
@@ -953,6 +954,11 @@ public void nullShouldBeTreatedAsUndefined() {
953954
obj.setChangeMeToUndefined(null);
954955
obj.verifyPropertyIsUndefined();
955956
}
957+
958+
@Test
959+
public void testJsiiAgent() {
960+
assertEquals("Java/" + System.getProperty("java.version"), JsiiAgent.getJsiiAgent());
961+
}
956962

957963
/**
958964
* @see https://github.com/awslabs/jsii/issues/320

packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiRuntime.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ private void startRuntimeIfNeeded() {
222222
if (traceEnabled) {
223223
pb.environment().put("JSII_DEBUG", "1");
224224
}
225+
226+
pb.environment().put("JSII_AGENT", "Java/" + System.getProperty("java.version"));
225227

226228
try {
227229
this.childProcess = pb.start();

packages/jsii-kernel/test/test.kernel.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,10 @@ defineTest('nulls are converted to undefined - properties', async (_test, sandbo
959959
sandbox.invoke({ objref, method: 'verifyPropertyIsUndefined' });
960960
});
961961

962+
defineTest('JSII_AGENT is undefined in node.js', async (test, sandbox) => {
963+
test.equal(sandbox.sget({ fqn: 'jsii-calc.JsiiAgent', property: 'jsiiAgent' }).value, undefined);
964+
});
965+
962966
// =================================================================================================
963967

964968
const testNames: { [name: string]: boolean } = { };

packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,32 @@
20992099
}
21002100
]
21012101
},
2102+
"jsii-calc.JsiiAgent": {
2103+
"assembly": "jsii-calc",
2104+
"docs": {
2105+
"comment": "Host runtime version should be set via JSII_AGENT"
2106+
},
2107+
"fqn": "jsii-calc.JsiiAgent",
2108+
"initializer": {
2109+
"initializer": true
2110+
},
2111+
"kind": "class",
2112+
"name": "JsiiAgent",
2113+
"properties": [
2114+
{
2115+
"docs": {
2116+
"comment": "Returns the value of the JSII_AGENT environment variable."
2117+
},
2118+
"immutable": true,
2119+
"name": "jsiiAgent",
2120+
"static": true,
2121+
"type": {
2122+
"optional": true,
2123+
"primitive": "string"
2124+
}
2125+
}
2126+
]
2127+
},
21022128
"jsii-calc.LoadBalancedFargateServiceProps": {
21032129
"assembly": "jsii-calc",
21042130
"datatype": true,
@@ -3736,5 +3762,5 @@
37363762
}
37373763
},
37383764
"version": "0.7.11",
3739-
"fingerprint": "Nw3vyHfzec4IFe674buqsgL3x8QgvKP0lUC3csRIW7g="
3765+
"fingerprint": "l8bUuUzVdVn151P/XjDEVN9kHkLfJ+d5fmgZVODpQkg="
37403766
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Amazon.JSII.Runtime.Deputy;
2+
3+
namespace Amazon.JSII.Tests.CalculatorNamespace
4+
{
5+
/// <summary>Host runtime version should be set via JSII_AGENT</summary>
6+
[JsiiClass(typeof(JsiiAgent_), "jsii-calc.JsiiAgent", "[]")]
7+
public class JsiiAgent_ : DeputyBase
8+
{
9+
public JsiiAgent_(): base(new DeputyProps(new object[]{}))
10+
{
11+
}
12+
13+
protected JsiiAgent_(ByRefValue reference): base(reference)
14+
{
15+
}
16+
17+
protected JsiiAgent_(DeputyProps props): base(props)
18+
{
19+
}
20+
21+
/// <summary>Returns the value of the JSII_AGENT environment variable.</summary>
22+
[JsiiProperty("jsiiAgent", "{\"primitive\":\"string\",\"optional\":true}")]
23+
public static string JsiiAgent
24+
{
25+
get => GetStaticProperty<string>(typeof(JsiiAgent_));
26+
}
27+
}
28+
}

packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/$Module.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ protected Class<?> resolveClass(final String fqn) throws ClassNotFoundException
6161
case "jsii-calc.JSObjectLiteralToNative": return software.amazon.jsii.tests.calculator.JSObjectLiteralToNative.class;
6262
case "jsii-calc.JSObjectLiteralToNativeClass": return software.amazon.jsii.tests.calculator.JSObjectLiteralToNativeClass.class;
6363
case "jsii-calc.JavaReservedWords": return software.amazon.jsii.tests.calculator.JavaReservedWords.class;
64+
case "jsii-calc.JsiiAgent": return software.amazon.jsii.tests.calculator.JsiiAgent.class;
6465
case "jsii-calc.LoadBalancedFargateServiceProps": return software.amazon.jsii.tests.calculator.LoadBalancedFargateServiceProps.class;
6566
case "jsii-calc.Multiply": return software.amazon.jsii.tests.calculator.Multiply.class;
6667
case "jsii-calc.MutableObjectLiteral": return software.amazon.jsii.tests.calculator.MutableObjectLiteral.class;

0 commit comments

Comments
 (0)