Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: JSII_AGENT #325

Merged
merged 3 commits into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/jsii-calc/lib/compliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1221,3 +1221,15 @@ class PrivateImplementation extends ExportedBaseClass implements IPrivatelyImple
super(true);
}
}

/**
* Host runtime version should be set via JSII_AGENT
*/
export class JsiiAgent {
/**
* Returns the value of the JSII_AGENT environment variable.
*/
public static get jsiiAgent(): string | undefined {
return process.env.JSII_AGENT;
}
};
28 changes: 27 additions & 1 deletion packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -2099,6 +2099,32 @@
}
]
},
"jsii-calc.JsiiAgent": {
"assembly": "jsii-calc",
"docs": {
"comment": "Host runtime version should be set via JSII_AGENT"
},
"fqn": "jsii-calc.JsiiAgent",
"initializer": {
"initializer": true
},
"kind": "class",
"name": "JsiiAgent",
"properties": [
{
"docs": {
"comment": "Returns the value of the JSII_AGENT environment variable."
},
"immutable": true,
"name": "jsiiAgent",
"static": true,
"type": {
"optional": true,
"primitive": "string"
}
}
]
},
"jsii-calc.LoadBalancedFargateServiceProps": {
"assembly": "jsii-calc",
"datatype": true,
Expand Down Expand Up @@ -3736,5 +3762,5 @@
}
},
"version": "0.7.11",
"fingerprint": "Nw3vyHfzec4IFe674buqsgL3x8QgvKP0lUC3csRIW7g="
"fingerprint": "l8bUuUzVdVn151P/XjDEVN9kHkLfJ+d5fmgZVODpQkg="
}
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,12 @@ public void NullShouldBeTreatedAsUndefined()
obj.ChangeMeToUndefined = null;
obj.VerifyPropertyIsUndefined();
}

[Fact(DisplayName = Prefix + nameof(JsiiAgent))]
public void JsiiAgent()
{
Assert.Equal("DotNet/" + Environment.Version.ToString(), JsiiAgent_.JsiiAgent);
}

[Fact(DisplayName = Prefix + nameof(ReceiveInstanceOfPrivateClass))]
public void ReceiveInstanceOfPrivateClass()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public NodeProcess(IJsiiRuntimeProvider jsiiRuntimeProvider, ILoggerFactory logg
}
};

_process.StartInfo.EnvironmentVariables.Add("JSII_AGENT", "DotNet/" + Environment.Version.ToString());

_logger.LogDebug("Starting jsii runtime...");
_logger.LogDebug($"{_process.StartInfo.FileName} {_process.StartInfo.Arguments}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import software.amazon.jsii.tests.calculator.SyncVirtualMethods;
import software.amazon.jsii.tests.calculator.UnionProperties;
import software.amazon.jsii.tests.calculator.UsesInterfaceWithProperties;
import software.amazon.jsii.tests.calculator.JsiiAgent;
import software.amazon.jsii.tests.calculator.composition.CompositeOperation;
import software.amazon.jsii.tests.calculator.lib.EnumFromScopedModule;
import software.amazon.jsii.tests.calculator.lib.IFriendly;
Expand Down Expand Up @@ -953,6 +954,11 @@ public void nullShouldBeTreatedAsUndefined() {
obj.setChangeMeToUndefined(null);
obj.verifyPropertyIsUndefined();
}

@Test
public void testJsiiAgent() {
assertEquals("Java/" + System.getProperty("java.version"), JsiiAgent.getJsiiAgent());
}

/**
* @see https://github.com/awslabs/jsii/issues/320
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ private void startRuntimeIfNeeded() {
if (traceEnabled) {
pb.environment().put("JSII_DEBUG", "1");
}

pb.environment().put("JSII_AGENT", "Java/" + System.getProperty("java.version"));

try {
this.childProcess = pb.start();
Expand Down
4 changes: 4 additions & 0 deletions packages/jsii-kernel/test/test.kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,10 @@ defineTest('nulls are converted to undefined - properties', async (_test, sandbo
sandbox.invoke({ objref, method: 'verifyPropertyIsUndefined' });
});

defineTest('JSII_AGENT is undefined in node.js', async (test, sandbox) => {
test.equal(sandbox.sget({ fqn: 'jsii-calc.JsiiAgent', property: 'jsiiAgent' }).value, undefined);
});

// =================================================================================================

const testNames: { [name: string]: boolean } = { };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2099,6 +2099,32 @@
}
]
},
"jsii-calc.JsiiAgent": {
"assembly": "jsii-calc",
"docs": {
"comment": "Host runtime version should be set via JSII_AGENT"
},
"fqn": "jsii-calc.JsiiAgent",
"initializer": {
"initializer": true
},
"kind": "class",
"name": "JsiiAgent",
"properties": [
{
"docs": {
"comment": "Returns the value of the JSII_AGENT environment variable."
},
"immutable": true,
"name": "jsiiAgent",
"static": true,
"type": {
"optional": true,
"primitive": "string"
}
}
]
},
"jsii-calc.LoadBalancedFargateServiceProps": {
"assembly": "jsii-calc",
"datatype": true,
Expand Down Expand Up @@ -3736,5 +3762,5 @@
}
},
"version": "0.7.11",
"fingerprint": "Nw3vyHfzec4IFe674buqsgL3x8QgvKP0lUC3csRIW7g="
"fingerprint": "l8bUuUzVdVn151P/XjDEVN9kHkLfJ+d5fmgZVODpQkg="
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Amazon.JSII.Runtime.Deputy;

namespace Amazon.JSII.Tests.CalculatorNamespace
{
/// <summary>Host runtime version should be set via JSII_AGENT</summary>
[JsiiClass(typeof(JsiiAgent_), "jsii-calc.JsiiAgent", "[]")]
public class JsiiAgent_ : DeputyBase
{
public JsiiAgent_(): base(new DeputyProps(new object[]{}))
{
}

protected JsiiAgent_(ByRefValue reference): base(reference)
{
}

protected JsiiAgent_(DeputyProps props): base(props)
{
}

/// <summary>Returns the value of the JSII_AGENT environment variable.</summary>
[JsiiProperty("jsiiAgent", "{\"primitive\":\"string\",\"optional\":true}")]
public static string JsiiAgent
{
get => GetStaticProperty<string>(typeof(JsiiAgent_));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ protected Class<?> resolveClass(final String fqn) throws ClassNotFoundException
case "jsii-calc.JSObjectLiteralToNative": return software.amazon.jsii.tests.calculator.JSObjectLiteralToNative.class;
case "jsii-calc.JSObjectLiteralToNativeClass": return software.amazon.jsii.tests.calculator.JSObjectLiteralToNativeClass.class;
case "jsii-calc.JavaReservedWords": return software.amazon.jsii.tests.calculator.JavaReservedWords.class;
case "jsii-calc.JsiiAgent": return software.amazon.jsii.tests.calculator.JsiiAgent.class;
case "jsii-calc.LoadBalancedFargateServiceProps": return software.amazon.jsii.tests.calculator.LoadBalancedFargateServiceProps.class;
case "jsii-calc.Multiply": return software.amazon.jsii.tests.calculator.Multiply.class;
case "jsii-calc.MutableObjectLiteral": return software.amazon.jsii.tests.calculator.MutableObjectLiteral.class;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package software.amazon.jsii.tests.calculator;

/**
* Host runtime version should be set via JSII_AGENT
*/
@javax.annotation.Generated(value = "jsii-pacmak")
@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.JsiiAgent")
public class JsiiAgent extends software.amazon.jsii.JsiiObject {
protected JsiiAgent(final software.amazon.jsii.JsiiObject.InitializationMode mode) {
super(mode);
}
public JsiiAgent() {
super(software.amazon.jsii.JsiiObject.InitializationMode.Jsii);
software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this);
}

/**
* Returns the value of the JSII_AGENT environment variable.
*/
@javax.annotation.Nullable
public static java.lang.String getJsiiAgent() {
return software.amazon.jsii.JsiiObject.jsiiStaticGet(software.amazon.jsii.tests.calculator.JsiiAgent.class, "jsiiAgent", java.lang.String.class);
}
}
41 changes: 41 additions & 0 deletions packages/jsii-pacmak/test/expected.jsii-calc/sphinx/jsii-calc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2665,6 +2665,47 @@ JavaReservedWords
:type: string


JsiiAgent
^^^^^^^^^

.. py:class:: JsiiAgent()

**Language-specific names:**

.. tabs::

.. code-tab:: c#

using Amazon.JSII.Tests.CalculatorNamespace;

.. code-tab:: java

import software.amazon.jsii.tests.calculator.JsiiAgent;

.. code-tab:: javascript

const { JsiiAgent } = require('jsii-calc');

.. code-tab:: typescript

import { JsiiAgent } from 'jsii-calc';



Host runtime version should be set via JSII_AGENT




.. py:attribute:: jsiiAgent

Returns the value of the JSII_AGENT environment variable.



:type: string *(optional)* *(readonly)* *(static)*


LoadBalancedFargateServiceProps (interface)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
28 changes: 21 additions & 7 deletions packages/jsii-runtime/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.