diff --git a/packages/jsii-calc-lib/package.json b/packages/jsii-calc-lib/package.json index fa1a64e915..d92fbd20e3 100644 --- a/packages/jsii-calc-lib/package.json +++ b/packages/jsii-calc-lib/package.json @@ -15,12 +15,13 @@ "maven": { "groupId": "software.amazon.jsii.tests", "artifactId": "calculator-lib", - "versionSuffix": "devpreview" + "versionSuffix": ".DEVPREVIEW" } }, "dotnet": { "namespace": "Amazon.JSII.Tests.CalculatorNamespace.LibNamespace", - "packageId": "Amazon.JSII.Tests.CalculatorPackageId.LibPackageId" + "packageId": "Amazon.JSII.Tests.CalculatorPackageId.LibPackageId", + "versionSuffix": "-devpreview" }, "python": { "distName": "scope.jsii-calc-lib", diff --git a/packages/jsii-calc-lib/test/assembly.jsii b/packages/jsii-calc-lib/test/assembly.jsii index d3f7b2564f..fe8a0c2ed3 100644 --- a/packages/jsii-calc-lib/test/assembly.jsii +++ b/packages/jsii-calc-lib/test/assembly.jsii @@ -100,13 +100,14 @@ "targets": { "dotnet": { "namespace": "Amazon.JSII.Tests.CalculatorNamespace.LibNamespace", - "packageId": "Amazon.JSII.Tests.CalculatorPackageId.LibPackageId" + "packageId": "Amazon.JSII.Tests.CalculatorPackageId.LibPackageId", + "versionSuffix": "-devpreview" }, "java": { "maven": { "artifactId": "calculator-lib", "groupId": "software.amazon.jsii.tests", - "versionSuffix": "devpreview" + "versionSuffix": ".DEVPREVIEW" }, "package": "software.amazon.jsii.tests.calculator.lib" }, @@ -541,5 +542,5 @@ } }, "version": "0.12.1", - "fingerprint": "MXSaKBVwpFalIulxHb3PUOMH4eKJJHPxI2u+zfEsbmA=" + "fingerprint": "aQ66EJSs69SuXip1lDEBj6a1qwzN8+ThWgYp6Lq1Q8Y=" } diff --git a/packages/jsii-calc/test/assembly.jsii b/packages/jsii-calc/test/assembly.jsii index 5510258156..cd35d429f8 100644 --- a/packages/jsii-calc/test/assembly.jsii +++ b/packages/jsii-calc/test/assembly.jsii @@ -86,13 +86,14 @@ "targets": { "dotnet": { "namespace": "Amazon.JSII.Tests.CalculatorNamespace.LibNamespace", - "packageId": "Amazon.JSII.Tests.CalculatorPackageId.LibPackageId" + "packageId": "Amazon.JSII.Tests.CalculatorPackageId.LibPackageId", + "versionSuffix": "-devpreview" }, "java": { "maven": { "artifactId": "calculator-lib", "groupId": "software.amazon.jsii.tests", - "versionSuffix": "devpreview" + "versionSuffix": ".DEVPREVIEW" }, "package": "software.amazon.jsii.tests.calculator.lib" }, @@ -161,13 +162,14 @@ "targets": { "dotnet": { "namespace": "Amazon.JSII.Tests.CalculatorNamespace.LibNamespace", - "packageId": "Amazon.JSII.Tests.CalculatorPackageId.LibPackageId" + "packageId": "Amazon.JSII.Tests.CalculatorPackageId.LibPackageId", + "versionSuffix": "-devpreview" }, "java": { "maven": { "artifactId": "calculator-lib", "groupId": "software.amazon.jsii.tests", - "versionSuffix": "devpreview" + "versionSuffix": ".DEVPREVIEW" }, "package": "software.amazon.jsii.tests.calculator.lib" }, @@ -8776,5 +8778,5 @@ } }, "version": "0.12.1", - "fingerprint": "AlSn00Q27h2jLbVq5Xtz97KdHszOYlZOq+al2FOvsWM=" + "fingerprint": "eJFB3vFCc9pOmBGqLCLopXjumM3fvGhVp9zhFfty6xM=" } diff --git a/packages/jsii-dotnet-generator/src/Amazon.JSII.Generator/AssemblyExtensions.cs b/packages/jsii-dotnet-generator/src/Amazon.JSII.Generator/AssemblyExtensions.cs index eaac8b5cc5..73226d70d9 100644 --- a/packages/jsii-dotnet-generator/src/Amazon.JSII.Generator/AssemblyExtensions.cs +++ b/packages/jsii-dotnet-generator/src/Amazon.JSII.Generator/AssemblyExtensions.cs @@ -59,7 +59,7 @@ public static IEnumerable GetMsBuildProperties(this Assembly assembly) yield return new XElement("GeneratePackageOnBuild", true); yield return new XElement("IncludeSymbols", true); yield return new XElement("IncludeSource", true); - yield return new XElement("PackageVersion", assembly.Version); + yield return new XElement("PackageVersion", assembly.GetDecoratedVersion()); yield return new XElement("PackageId", assembly.Targets.DotNet.PackageId); yield return new XElement("Description", GetDescription()); yield return new XElement("ProjectUrl", assembly.Homepage); diff --git a/packages/jsii-dotnet-generator/src/Amazon.JSII.Generator/AssemblyGenerator.cs b/packages/jsii-dotnet-generator/src/Amazon.JSII.Generator/AssemblyGenerator.cs index 1038ea7d58..78a0f6a38e 100644 --- a/packages/jsii-dotnet-generator/src/Amazon.JSII.Generator/AssemblyGenerator.cs +++ b/packages/jsii-dotnet-generator/src/Amazon.JSII.Generator/AssemblyGenerator.cs @@ -126,7 +126,7 @@ void SaveProjectFile() ), GetDependencies() .Distinct() - .Select(d => new { Package = symbols.GetAssemblyName(d.Key), d.Value.Version}) + .Select(d => new { Package = symbols.GetAssemblyName(d.Key), Version = d.Value.GetDecoratedVersion() }) .Select(d => new XElement("PackageReference", new XAttribute("Include", d.Package), @@ -283,7 +283,7 @@ void SaveType(Type type) case TypeKind.Class: { var classType = (ClassType) type; - + if (classType.IsAbstract) { SaveTypeFile($"{symbols.GetAbstractClassProxyName(classType)}.cs", diff --git a/packages/jsii-dotnet-generator/src/Amazon.JSII.Generator/VersionSuffixExtensions.cs b/packages/jsii-dotnet-generator/src/Amazon.JSII.Generator/VersionSuffixExtensions.cs new file mode 100644 index 0000000000..b647b5ca2f --- /dev/null +++ b/packages/jsii-dotnet-generator/src/Amazon.JSII.Generator/VersionSuffixExtensions.cs @@ -0,0 +1,27 @@ +using Amazon.JSII.JsonModel.Spec; + +namespace Amazon.JSII.Generator +{ + public static class VersionSuffixExtensions + { + public static string GetDecoratedVersion(this Assembly assembly) + { + return MakeDecoratedVersion(assembly.Version, assembly.Targets?.DotNet?.VersionSuffix); + } + + public static string GetDecoratedVersion(this PackageVersion package) + { + return MakeDecoratedVersion(package.Version, package.Targets?.DotNet?.VersionSuffix); + } + + private static string MakeDecoratedVersion(string version, string suffix) + { + if (suffix == null) + { + return version; + } + // suffix is guaranteed to start with a leading `-` + return $"{version}{suffix}"; + } + } +} diff --git a/packages/jsii-dotnet-jsonmodel/src/Amazon.JSII.JsonModel/Spec/AssemblyTargets.cs b/packages/jsii-dotnet-jsonmodel/src/Amazon.JSII.JsonModel/Spec/AssemblyTargets.cs index 77ff8467b0..9e9ad114f0 100644 --- a/packages/jsii-dotnet-jsonmodel/src/Amazon.JSII.JsonModel/Spec/AssemblyTargets.cs +++ b/packages/jsii-dotnet-jsonmodel/src/Amazon.JSII.JsonModel/Spec/AssemblyTargets.cs @@ -14,7 +14,7 @@ public AssemblyTargets(DotNetTarget dotnet, IDictionary others = [JsonProperty("dotnet", NullValueHandling = NullValueHandling.Ignore)] public DotNetTarget DotNet { get; } - + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] public class DotNetTarget { @@ -25,7 +25,8 @@ public DotNetTarget string title = null, bool signAssembly = false, string assemblyOriginatorKeyFile = null, - string iconUrl = null + string iconUrl = null, + string versionSuffix = null ) { Namespace = @namespace ?? throw new ArgumentNullException(nameof(@namespace)); @@ -35,8 +36,14 @@ public DotNetTarget SignAssembly = signAssembly; AssemblyOriginatorKeyFile = assemblyOriginatorKeyFile; IconUrl = iconUrl; + VersionSuffix = versionSuffix; + + if (VersionSuffix != null && !VersionSuffix.StartsWith("-")) + { + throw new ArgumentException($"{nameof(versionSuffix)} must start with a '-' (received {versionSuffix})"); + } } - + [JsonProperty("namespace")] public string Namespace { get; } @@ -54,6 +61,9 @@ public DotNetTarget [JsonProperty("iconUrl", NullValueHandling = NullValueHandling.Ignore)] public string IconUrl { get; } - } + + [JsonProperty("versionSuffix", NullValueHandling = NullValueHandling.Ignore)] + public string VersionSuffix { get; } + } } } diff --git a/packages/jsii-kernel/test/test.kernel.ts b/packages/jsii-kernel/test/test.kernel.ts index acea505182..be056157f4 100644 --- a/packages/jsii-kernel/test/test.kernel.ts +++ b/packages/jsii-kernel/test/test.kernel.ts @@ -248,11 +248,12 @@ defineTest('naming allows returns the module name for different languages', asyn test.deepEqual(sandbox.naming({ assembly: '@scope/jsii-calc-lib' }).naming, { dotnet: { namespace: 'Amazon.JSII.Tests.CalculatorNamespace.LibNamespace', - packageId: 'Amazon.JSII.Tests.CalculatorPackageId.LibPackageId' + packageId: 'Amazon.JSII.Tests.CalculatorPackageId.LibPackageId', + versionSuffix: '-devpreview' }, java: { package: 'software.amazon.jsii.tests.calculator.lib', - maven: { groupId: 'software.amazon.jsii.tests', artifactId: 'calculator-lib', versionSuffix: 'devpreview' }, + maven: { groupId: 'software.amazon.jsii.tests', artifactId: 'calculator-lib', versionSuffix: '.DEVPREVIEW' }, }, js: { npm: '@scope/jsii-calc-lib' }, python: { distName: 'scope.jsii-calc-lib', module: 'scope.jsii_calc_lib' }, diff --git a/packages/jsii-pacmak/lib/targets/java.ts b/packages/jsii-pacmak/lib/targets/java.ts index 473e0e447a..2fc4fb99fc 100644 --- a/packages/jsii-pacmak/lib/targets/java.ts +++ b/packages/jsii-pacmak/lib/targets/java.ts @@ -504,7 +504,7 @@ class JavaGenerator extends Generator { function makeVersion(version: string, suffix?: string): string { if (!suffix) { return version; } if (!suffix.startsWith('-') && !suffix.startsWith('.')) { - return `${version}-${suffix}`; + throw new Error(`versionSuffix must start with '-' or '.', but received ${suffix}`); } return `${version}${suffix}`; } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/.jsii b/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/.jsii index d3f7b2564f..fe8a0c2ed3 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/.jsii +++ b/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/.jsii @@ -100,13 +100,14 @@ "targets": { "dotnet": { "namespace": "Amazon.JSII.Tests.CalculatorNamespace.LibNamespace", - "packageId": "Amazon.JSII.Tests.CalculatorPackageId.LibPackageId" + "packageId": "Amazon.JSII.Tests.CalculatorPackageId.LibPackageId", + "versionSuffix": "-devpreview" }, "java": { "maven": { "artifactId": "calculator-lib", "groupId": "software.amazon.jsii.tests", - "versionSuffix": "devpreview" + "versionSuffix": ".DEVPREVIEW" }, "package": "software.amazon.jsii.tests.calculator.lib" }, @@ -541,5 +542,5 @@ } }, "version": "0.12.1", - "fingerprint": "MXSaKBVwpFalIulxHb3PUOMH4eKJJHPxI2u+zfEsbmA=" + "fingerprint": "aQ66EJSs69SuXip1lDEBj6a1qwzN8+ThWgYp6Lq1Q8Y=" } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId.csproj b/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId.csproj index a851b8f691..c3ebac8442 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId.csproj +++ b/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId.csproj @@ -4,7 +4,7 @@ true true true - 0.12.1 + 0.12.1-devpreview Amazon.JSII.Tests.CalculatorPackageId.LibPackageId A simple calcuator library built on JSII. (Stability: Deprecated) https://github.com/awslabs/jsii.git diff --git a/packages/jsii-pacmak/test/expected.jsii-calc-lib/java/pom.xml b/packages/jsii-pacmak/test/expected.jsii-calc-lib/java/pom.xml index ecd5d7ccf7..7d41e39b29 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc-lib/java/pom.xml +++ b/packages/jsii-pacmak/test/expected.jsii-calc-lib/java/pom.xml @@ -27,7 +27,7 @@ software.amazon.jsii.tests calculator-lib - 0.12.1-devpreview + 0.12.1.DEVPREVIEW jar UTF-8 diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii index 5510258156..cd35d429f8 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii @@ -86,13 +86,14 @@ "targets": { "dotnet": { "namespace": "Amazon.JSII.Tests.CalculatorNamespace.LibNamespace", - "packageId": "Amazon.JSII.Tests.CalculatorPackageId.LibPackageId" + "packageId": "Amazon.JSII.Tests.CalculatorPackageId.LibPackageId", + "versionSuffix": "-devpreview" }, "java": { "maven": { "artifactId": "calculator-lib", "groupId": "software.amazon.jsii.tests", - "versionSuffix": "devpreview" + "versionSuffix": ".DEVPREVIEW" }, "package": "software.amazon.jsii.tests.calculator.lib" }, @@ -161,13 +162,14 @@ "targets": { "dotnet": { "namespace": "Amazon.JSII.Tests.CalculatorNamespace.LibNamespace", - "packageId": "Amazon.JSII.Tests.CalculatorPackageId.LibPackageId" + "packageId": "Amazon.JSII.Tests.CalculatorPackageId.LibPackageId", + "versionSuffix": "-devpreview" }, "java": { "maven": { "artifactId": "calculator-lib", "groupId": "software.amazon.jsii.tests", - "versionSuffix": "devpreview" + "versionSuffix": ".DEVPREVIEW" }, "package": "software.amazon.jsii.tests.calculator.lib" }, @@ -8776,5 +8778,5 @@ } }, "version": "0.12.1", - "fingerprint": "AlSn00Q27h2jLbVq5Xtz97KdHszOYlZOq+al2FOvsWM=" + "fingerprint": "eJFB3vFCc9pOmBGqLCLopXjumM3fvGhVp9zhFfty6xM=" } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon.JSII.Tests.CalculatorPackageId.csproj b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon.JSII.Tests.CalculatorPackageId.csproj index a26de52753..31c378f147 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon.JSII.Tests.CalculatorPackageId.csproj +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon.JSII.Tests.CalculatorPackageId.csproj @@ -19,6 +19,6 @@ - + \ No newline at end of file diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/java/pom.xml b/packages/jsii-pacmak/test/expected.jsii-calc/java/pom.xml index 957fe3a212..9a4916e512 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/java/pom.xml +++ b/packages/jsii-pacmak/test/expected.jsii-calc/java/pom.xml @@ -67,7 +67,7 @@ software.amazon.jsii.tests calculator-lib - 0.12.1-devpreview + 0.12.1.DEVPREVIEW software.amazon.jsii