From dfde37a82c57a4325aae15be409e539be2e16a41 Mon Sep 17 00:00:00 2001 From: Romain Marcadier-Muller Date: Tue, 25 Jun 2019 16:02:23 +0200 Subject: [PATCH] feat(pacmak): support adding a suffix to Java package version (#552) Allows setting a `jsii.targets.java.maven.versionSuffix` key that defines a string to be appended at the end of the version number of the Maven package. If the suffix starts with `.` or `-`, it will be appended to the version number directly (`0.12.0` with suffix `.dp` will render `0.12.0.dp`); but otherwise, it'll be prepended with a `-` before it is concatenated with the version number (`0.12.0` with suffix `dp` will render `0.12.0-dp`). --- packages/jsii-calc-lib/package.json | 5 ++-- packages/jsii-calc-lib/test/assembly.jsii | 5 ++-- packages/jsii-calc/test/assembly.jsii | 8 +++--- packages/jsii-kernel/test/test.kernel.ts | 2 +- packages/jsii-pacmak/lib/targets/java.ts | 26 ++++++++++++++++--- .../test/expected.jsii-calc-base/java/pom.xml | 4 +-- .../.jsii | 5 ++-- .../test/expected.jsii-calc-lib/java/pom.xml | 6 ++--- .../.jsii | 8 +++--- .../test/expected.jsii-calc/java/pom.xml | 10 +++---- 10 files changed, 52 insertions(+), 27 deletions(-) diff --git a/packages/jsii-calc-lib/package.json b/packages/jsii-calc-lib/package.json index 2ec74054b7..fa1a64e915 100644 --- a/packages/jsii-calc-lib/package.json +++ b/packages/jsii-calc-lib/package.json @@ -14,7 +14,8 @@ "package": "software.amazon.jsii.tests.calculator.lib", "maven": { "groupId": "software.amazon.jsii.tests", - "artifactId": "calculator-lib" + "artifactId": "calculator-lib", + "versionSuffix": "devpreview" } }, "dotnet": { @@ -53,4 +54,4 @@ "type": "git", "url": "https://github.com/awslabs/jsii.git" } -} \ No newline at end of file +} diff --git a/packages/jsii-calc-lib/test/assembly.jsii b/packages/jsii-calc-lib/test/assembly.jsii index 387348ef42..d3f7b2564f 100644 --- a/packages/jsii-calc-lib/test/assembly.jsii +++ b/packages/jsii-calc-lib/test/assembly.jsii @@ -105,7 +105,8 @@ "java": { "maven": { "artifactId": "calculator-lib", - "groupId": "software.amazon.jsii.tests" + "groupId": "software.amazon.jsii.tests", + "versionSuffix": "devpreview" }, "package": "software.amazon.jsii.tests.calculator.lib" }, @@ -540,5 +541,5 @@ } }, "version": "0.12.1", - "fingerprint": "8rURgFQ4mU5jtzoxcgnq46MwxVxAepVcXcayr94T7Jk=" + "fingerprint": "MXSaKBVwpFalIulxHb3PUOMH4eKJJHPxI2u+zfEsbmA=" } diff --git a/packages/jsii-calc/test/assembly.jsii b/packages/jsii-calc/test/assembly.jsii index b35f83dc94..5510258156 100644 --- a/packages/jsii-calc/test/assembly.jsii +++ b/packages/jsii-calc/test/assembly.jsii @@ -91,7 +91,8 @@ "java": { "maven": { "artifactId": "calculator-lib", - "groupId": "software.amazon.jsii.tests" + "groupId": "software.amazon.jsii.tests", + "versionSuffix": "devpreview" }, "package": "software.amazon.jsii.tests.calculator.lib" }, @@ -165,7 +166,8 @@ "java": { "maven": { "artifactId": "calculator-lib", - "groupId": "software.amazon.jsii.tests" + "groupId": "software.amazon.jsii.tests", + "versionSuffix": "devpreview" }, "package": "software.amazon.jsii.tests.calculator.lib" }, @@ -8774,5 +8776,5 @@ } }, "version": "0.12.1", - "fingerprint": "zqNgOADt1geKGnlmywyqSBDc4sGLkoK3kxoWdDOf6ro=" + "fingerprint": "AlSn00Q27h2jLbVq5Xtz97KdHszOYlZOq+al2FOvsWM=" } diff --git a/packages/jsii-kernel/test/test.kernel.ts b/packages/jsii-kernel/test/test.kernel.ts index 7d86cf5129..acea505182 100644 --- a/packages/jsii-kernel/test/test.kernel.ts +++ b/packages/jsii-kernel/test/test.kernel.ts @@ -252,7 +252,7 @@ defineTest('naming allows returns the module name for different languages', asyn }, java: { package: 'software.amazon.jsii.tests.calculator.lib', - maven: { groupId: 'software.amazon.jsii.tests', artifactId: 'calculator-lib' } + 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 0d214a1763..473e0e447a 100644 --- a/packages/jsii-pacmak/lib/targets/java.ts +++ b/packages/jsii-pacmak/lib/targets/java.ts @@ -423,8 +423,9 @@ class JavaGenerator extends Generator { url: assm.repository.url }, - ...assm.targets.java.maven, - 'version': assm.version, + 'groupId': assm.targets.java.maven.groupId, + 'artifactId': assm.targets.java.maven.artifactId, + 'version': makeVersion(assm.version, assm.targets.java.maven.versionSuffix), 'packaging': 'jar', 'properties': { 'project.build.sourceEncoding': 'UTF-8' }, @@ -492,6 +493,22 @@ class JavaGenerator extends Generator { ); this.code.closeFile('pom.xml'); + /** + * Combines a version number with an optional suffix. If the suffix starts with '-' or '.', it will be + * concatenated as-is to the semantic version number. Otherwise, it'll be appended to the version number with an + * intercalar '-'. + * + * @param version the semantic version number + * @param suffix the suffix, if any. + */ + function makeVersion(version: string, suffix?: string): string { + if (!suffix) { return version; } + if (!suffix.startsWith('-') && !suffix.startsWith('.')) { + return `${version}-${suffix}`; + } + return `${version}${suffix}`; + } + function mavenDependencies() { const dependencies = new Array(); const allDeps = { ...(assm.dependencies || {}), ...self.referencedModules }; @@ -501,8 +518,9 @@ class JavaGenerator extends Generator { throw new Error(`Assembly ${assm.name} depends on ${depName}, which does not declare a java target`); } dependencies.push({ - ...dep.targets.java.maven, - version: dep.version + groupId: dep.targets.java.maven.groupId, + artifactId: dep.targets.java.maven.artifactId, + version: makeVersion(dep.version, dep.targets.java.maven.versionSuffix), }); } // The JSII java runtime base classes diff --git a/packages/jsii-pacmak/test/expected.jsii-calc-base/java/pom.xml b/packages/jsii-pacmak/test/expected.jsii-calc-base/java/pom.xml index 874d3e1e37..ff450f9126 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc-base/java/pom.xml +++ b/packages/jsii-pacmak/test/expected.jsii-calc-base/java/pom.xml @@ -25,8 +25,8 @@ scm:git:https://github.com/awslabs/jsii.git https://github.com/awslabs/jsii.git - calculator-base software.amazon.jsii.tests + calculator-base 0.12.1 jar @@ -34,8 +34,8 @@ - calculator-base-of-base software.amazon.jsii.tests + calculator-base-of-base 0.12.1 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 387348ef42..d3f7b2564f 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 @@ -105,7 +105,8 @@ "java": { "maven": { "artifactId": "calculator-lib", - "groupId": "software.amazon.jsii.tests" + "groupId": "software.amazon.jsii.tests", + "versionSuffix": "devpreview" }, "package": "software.amazon.jsii.tests.calculator.lib" }, @@ -540,5 +541,5 @@ } }, "version": "0.12.1", - "fingerprint": "8rURgFQ4mU5jtzoxcgnq46MwxVxAepVcXcayr94T7Jk=" + "fingerprint": "MXSaKBVwpFalIulxHb3PUOMH4eKJJHPxI2u+zfEsbmA=" } 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 841256f112..ecd5d7ccf7 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 @@ -25,17 +25,17 @@ scm:git:https://github.com/awslabs/jsii.git https://github.com/awslabs/jsii.git - calculator-lib software.amazon.jsii.tests - 0.12.1 + calculator-lib + 0.12.1-devpreview jar UTF-8 - calculator-base software.amazon.jsii.tests + calculator-base 0.12.1 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 b35f83dc94..5510258156 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 @@ -91,7 +91,8 @@ "java": { "maven": { "artifactId": "calculator-lib", - "groupId": "software.amazon.jsii.tests" + "groupId": "software.amazon.jsii.tests", + "versionSuffix": "devpreview" }, "package": "software.amazon.jsii.tests.calculator.lib" }, @@ -165,7 +166,8 @@ "java": { "maven": { "artifactId": "calculator-lib", - "groupId": "software.amazon.jsii.tests" + "groupId": "software.amazon.jsii.tests", + "versionSuffix": "devpreview" }, "package": "software.amazon.jsii.tests.calculator.lib" }, @@ -8774,5 +8776,5 @@ } }, "version": "0.12.1", - "fingerprint": "zqNgOADt1geKGnlmywyqSBDc4sGLkoK3kxoWdDOf6ro=" + "fingerprint": "AlSn00Q27h2jLbVq5Xtz97KdHszOYlZOq+al2FOvsWM=" } 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 f9d5af1516..957fe3a212 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/java/pom.xml +++ b/packages/jsii-pacmak/test/expected.jsii-calc/java/pom.xml @@ -46,8 +46,8 @@ scm:git:https://github.com/awslabs/jsii.git https://github.com/awslabs/jsii.git - calculator software.amazon.jsii.tests + calculator 0.12.1 jar @@ -55,19 +55,19 @@ - calculator-base software.amazon.jsii.tests + calculator-base 0.12.1 - calculator-base-of-base software.amazon.jsii.tests + calculator-base-of-base 0.12.1 - calculator-lib software.amazon.jsii.tests - 0.12.1 + calculator-lib + 0.12.1-devpreview software.amazon.jsii