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(pacmak): support adding suffix to .NET package versions #557

Merged
merged 5 commits into from
Jun 25, 2019
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
5 changes: 3 additions & 2 deletions packages/jsii-calc-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions packages/jsii-calc-lib/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -541,5 +542,5 @@
}
},
"version": "0.12.1",
"fingerprint": "MXSaKBVwpFalIulxHb3PUOMH4eKJJHPxI2u+zfEsbmA="
"fingerprint": "aQ66EJSs69SuXip1lDEBj6a1qwzN8+ThWgYp6Lq1Q8Y="
}
12 changes: 7 additions & 5 deletions packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -8776,5 +8778,5 @@
}
},
"version": "0.12.1",
"fingerprint": "AlSn00Q27h2jLbVq5Xtz97KdHszOYlZOq+al2FOvsWM="
"fingerprint": "eJFB3vFCc9pOmBGqLCLopXjumM3fvGhVp9zhFfty6xM="
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static IEnumerable<XElement> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -283,7 +283,7 @@ void SaveType(Type type)
case TypeKind.Class:
{
var classType = (ClassType) type;

if (classType.IsAbstract)
{
SaveTypeFile($"{symbols.GetAbstractClassProxyName(classType)}.cs",
Expand Down
Original file line number Diff line number Diff line change
@@ -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}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public AssemblyTargets(DotNetTarget dotnet, IDictionary<string, object> others =

[JsonProperty("dotnet", NullValueHandling = NullValueHandling.Ignore)]
public DotNetTarget DotNet { get; }

[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class DotNetTarget
{
Expand All @@ -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));
Expand All @@ -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; }

Expand All @@ -54,6 +61,9 @@ public DotNetTarget

[JsonProperty("iconUrl", NullValueHandling = NullValueHandling.Ignore)]
public string IconUrl { get; }
}

[JsonProperty("versionSuffix", NullValueHandling = NullValueHandling.Ignore)]
public string VersionSuffix { get; }
}
}
}
5 changes: 3 additions & 2 deletions packages/jsii-kernel/test/test.kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-pacmak/lib/targets/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -541,5 +542,5 @@
}
},
"version": "0.12.1",
"fingerprint": "MXSaKBVwpFalIulxHb3PUOMH4eKJJHPxI2u+zfEsbmA="
"fingerprint": "aQ66EJSs69SuXip1lDEBj6a1qwzN8+ThWgYp6Lq1Q8Y="
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IncludeSymbols>true</IncludeSymbols>
<IncludeSource>true</IncludeSource>
<PackageVersion>0.12.1</PackageVersion>
<PackageVersion>0.12.1-devpreview</PackageVersion>
<PackageId>Amazon.JSII.Tests.CalculatorPackageId.LibPackageId</PackageId>
<Description>A simple calcuator library built on JSII. (Stability: Deprecated)</Description>
<ProjectUrl>https://github.com/awslabs/jsii.git</ProjectUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</scm>
<groupId>software.amazon.jsii.tests</groupId>
<artifactId>calculator-lib</artifactId>
<version>0.12.1-devpreview</version>
<version>0.12.1.DEVPREVIEW</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -8776,5 +8778,5 @@
}
},
"version": "0.12.1",
"fingerprint": "AlSn00Q27h2jLbVq5Xtz97KdHszOYlZOq+al2FOvsWM="
"fingerprint": "eJFB3vFCc9pOmBGqLCLopXjumM3fvGhVp9zhFfty6xM="
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
<PackageReference Include="Amazon.JSII.Runtime" Version="0.12.1" />
<PackageReference Include="Amazon.JSII.Tests.CalculatorPackageId.BasePackageId" Version="0.12.1" />
<PackageReference Include="Amazon.JSII.Tests.CalculatorPackageId.BaseOfBasePackageId" Version="0.12.1" />
<PackageReference Include="Amazon.JSII.Tests.CalculatorPackageId.LibPackageId" Version="0.12.1" />
<PackageReference Include="Amazon.JSII.Tests.CalculatorPackageId.LibPackageId" Version="0.12.1-devpreview" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion packages/jsii-pacmak/test/expected.jsii-calc/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<dependency>
<groupId>software.amazon.jsii.tests</groupId>
<artifactId>calculator-lib</artifactId>
<version>0.12.1-devpreview</version>
<version>0.12.1.DEVPREVIEW</version>
</dependency>
<dependency>
<groupId>software.amazon.jsii</groupId>
Expand Down