Skip to content

Commit

Permalink
feat(pacmak): support adding a suffix to Java package version (#552)
Browse files Browse the repository at this point in the history
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`).
  • Loading branch information
RomainMuller authored Jun 25, 2019
1 parent 3ce4842 commit dfde37a
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 27 deletions.
5 changes: 3 additions & 2 deletions packages/jsii-calc-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -53,4 +54,4 @@
"type": "git",
"url": "https://github.com/awslabs/jsii.git"
}
}
}
5 changes: 3 additions & 2 deletions packages/jsii-calc-lib/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -540,5 +541,5 @@
}
},
"version": "0.12.1",
"fingerprint": "8rURgFQ4mU5jtzoxcgnq46MwxVxAepVcXcayr94T7Jk="
"fingerprint": "MXSaKBVwpFalIulxHb3PUOMH4eKJJHPxI2u+zfEsbmA="
}
8 changes: 5 additions & 3 deletions packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -8774,5 +8776,5 @@
}
},
"version": "0.12.1",
"fingerprint": "zqNgOADt1geKGnlmywyqSBDc4sGLkoK3kxoWdDOf6ro="
"fingerprint": "AlSn00Q27h2jLbVq5Xtz97KdHszOYlZOq+al2FOvsWM="
}
2 changes: 1 addition & 1 deletion packages/jsii-kernel/test/test.kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
26 changes: 22 additions & 4 deletions packages/jsii-pacmak/lib/targets/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down Expand Up @@ -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<MavenDependency>();
const allDeps = { ...(assm.dependencies || {}), ...self.referencedModules };
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
<connection>scm:git:https://github.com/awslabs/jsii.git</connection>
<url>https://github.com/awslabs/jsii.git</url>
</scm>
<artifactId>calculator-base</artifactId>
<groupId>software.amazon.jsii.tests</groupId>
<artifactId>calculator-base</artifactId>
<version>0.12.1</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<artifactId>calculator-base-of-base</artifactId>
<groupId>software.amazon.jsii.tests</groupId>
<artifactId>calculator-base-of-base</artifactId>
<version>0.12.1</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -540,5 +541,5 @@
}
},
"version": "0.12.1",
"fingerprint": "8rURgFQ4mU5jtzoxcgnq46MwxVxAepVcXcayr94T7Jk="
"fingerprint": "MXSaKBVwpFalIulxHb3PUOMH4eKJJHPxI2u+zfEsbmA="
}
6 changes: 3 additions & 3 deletions packages/jsii-pacmak/test/expected.jsii-calc-lib/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
<connection>scm:git:https://github.com/awslabs/jsii.git</connection>
<url>https://github.com/awslabs/jsii.git</url>
</scm>
<artifactId>calculator-lib</artifactId>
<groupId>software.amazon.jsii.tests</groupId>
<version>0.12.1</version>
<artifactId>calculator-lib</artifactId>
<version>0.12.1-devpreview</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<artifactId>calculator-base</artifactId>
<groupId>software.amazon.jsii.tests</groupId>
<artifactId>calculator-base</artifactId>
<version>0.12.1</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -8774,5 +8776,5 @@
}
},
"version": "0.12.1",
"fingerprint": "zqNgOADt1geKGnlmywyqSBDc4sGLkoK3kxoWdDOf6ro="
"fingerprint": "AlSn00Q27h2jLbVq5Xtz97KdHszOYlZOq+al2FOvsWM="
}
10 changes: 5 additions & 5 deletions packages/jsii-pacmak/test/expected.jsii-calc/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,28 @@
<connection>scm:git:https://github.com/awslabs/jsii.git</connection>
<url>https://github.com/awslabs/jsii.git</url>
</scm>
<artifactId>calculator</artifactId>
<groupId>software.amazon.jsii.tests</groupId>
<artifactId>calculator</artifactId>
<version>0.12.1</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<artifactId>calculator-base</artifactId>
<groupId>software.amazon.jsii.tests</groupId>
<artifactId>calculator-base</artifactId>
<version>0.12.1</version>
</dependency>
<dependency>
<artifactId>calculator-base-of-base</artifactId>
<groupId>software.amazon.jsii.tests</groupId>
<artifactId>calculator-base-of-base</artifactId>
<version>0.12.1</version>
</dependency>
<dependency>
<artifactId>calculator-lib</artifactId>
<groupId>software.amazon.jsii.tests</groupId>
<version>0.12.1</version>
<artifactId>calculator-lib</artifactId>
<version>0.12.1-devpreview</version>
</dependency>
<dependency>
<groupId>software.amazon.jsii</groupId>
Expand Down

0 comments on commit dfde37a

Please sign in to comment.