Skip to content

Commit

Permalink
Merge pull request #1607 from aws/bump/1.4.1
Browse files Browse the repository at this point in the history
chore(release): 1.4.1
  • Loading branch information
RomainMuller authored Apr 22, 2020
2 parents 6e18940 + 65ca683 commit 0b09d7b
Show file tree
Hide file tree
Showing 34 changed files with 538 additions and 268 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [1.4.1](https://github.com/aws/jsii/compare/v1.4.0...v1.4.1) (2020-04-22)


### Bug Fixes

* **java:** compilation fails with "code too large" ([#1605](https://github.com/aws/jsii/issues/1605)) ([b9ec853](https://github.com/aws/jsii/commit/b9ec85384c53567e77bed4ab1a02910a297fff02))

## [1.4.0](https://github.com/aws/jsii/compare/v1.3.2...v1.4.0) (2020-04-22)


Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"rejectCycles": true
}
},
"version": "1.4.0"
"version": "1.4.1"
}
2 changes: 1 addition & 1 deletion packages/@jsii/dotnet-runtime-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"devDependencies": {
"@jsii/dotnet-runtime": "^0.0.0",
"@types/node": "^10.17.20",
"@types/node": "^10.17.21",
"jsii-calc": "^0.0.0",
"jsii-pacmak": "^0.0.0",
"typescript": "~3.8.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
Expand Down
2 changes: 1 addition & 1 deletion packages/@jsii/dotnet-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"devDependencies": {
"@jsii/runtime": "^0.0.0",
"@types/node": "^10.17.20",
"@types/node": "^10.17.21",
"@types/semver": "^7.1.0",
"jsii-build-tools": "^0.0.0",
"semver": "^7.3.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/@jsii/dotnet-runtime/src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PackageReference Update="Microsoft.Extensions.Logging" Version="3.1.3" />
<PackageReference Update="Microsoft.Extensions.Logging.Console" Version="3.1.3" />

<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.6.0" />
<PackageReference Update="NSubstitute" Version="4.2.1" />
<PackageReference Update="xunit" Version="2.4.1" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.1" />
Expand Down
2 changes: 1 addition & 1 deletion packages/@jsii/integ-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@types/dotenv": "^8.2.0",
"@types/fs-extra": "^8.1.0",
"@types/jest": "^25.2.1",
"@types/node": "^10.17.20",
"@types/node": "^10.17.21",
"@types/tar": "^4.0.3",
"eslint": "^6.8.0",
"typescript": "~3.8.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/@jsii/java-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"devDependencies": {
"@jsii/runtime": "^0.0.0",
"@types/node": "^10.17.20",
"@types/node": "^10.17.21",
"jsii-build-tools": "^0.0.0",
"typescript": "~3.8.3"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@jsii/kernel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@types/fs-extra": "^8.1.0",
"@types/jest": "^25.2.1",
"@types/jest-expect-message": "^1.0.1",
"@types/node": "^10.17.20",
"@types/node": "^10.17.21",
"@types/tar": "^4.0.3",
"eslint": "^6.8.0",
"jest": "^25.4.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@jsii/ruby-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"devDependencies": {
"@jsii/runtime": "^0.0.0",
"@types/node": "^10.17.20",
"@types/node": "^10.17.21",
"jsii-build-tools": "^0.0.0",
"jsii-calc": "^0.0.0",
"jsii-pacmak": "^0.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/@jsii/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@scope/jsii-calc-base": "^0.0.0",
"@scope/jsii-calc-lib": "^0.0.0",
"@types/jest": "^25.2.1",
"@types/node": "^10.17.20",
"@types/node": "^10.17.21",
"eslint": "^6.8.0",
"jest": "^25.4.0",
"jsii-build-tools": "^0.0.0",
Expand All @@ -49,7 +49,7 @@
"source-map-loader": "^0.2.4",
"typescript": "~3.8.3",
"wasm-loader": "^1.3.0",
"webpack": "^4.42.1",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11"
},
"jest": {
Expand Down
2 changes: 1 addition & 1 deletion packages/@jsii/spec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"devDependencies": {
"@types/jest": "^25.2.1",
"@types/node": "^10.17.20",
"@types/node": "^10.17.21",
"eslint": "^6.8.0",
"jest": "^25.4.0",
"jsii-build-tools": "^0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@scope/jsii-calc-base-of-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"test:update": "npm run build && UPDATE_DIFF=1 npm run test"
},
"devDependencies": {
"@types/node": "^10.17.20",
"@types/node": "^10.17.21",
"jsii": "^0.0.0",
"jsii-build-tools": "^0.0.0",
"jsii-rosetta": "^0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/@scope/jsii-calc-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@scope/jsii-calc-base-of-base": "^0.0.0"
},
"devDependencies": {
"@types/node": "^10.17.20",
"@types/node": "^10.17.21",
"jsii": "^0.0.0",
"jsii-build-tools": "^0.0.0",
"jsii-rosetta": "^0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/@scope/jsii-calc-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@scope/jsii-calc-base-of-base": "^0.0.0"
},
"devDependencies": {
"@types/node": "^10.17.20",
"@types/node": "^10.17.21",
"jsii": "^0.0.0",
"jsii-build-tools": "^0.0.0",
"jsii-rosetta": "^0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/codemaker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@types/decamelize": "^1.2.0",
"@types/fs-extra": "^8.1.0",
"@types/jest": "^25.2.1",
"@types/node": "^10.17.20",
"@types/node": "^10.17.21",
"eslint": "^6.8.0",
"jest": "^25.4.0",
"typescript": "~3.8.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-calc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@scope/jsii-calc-lib": "^0.0.0"
},
"devDependencies": {
"@types/node": "^10.17.20",
"@types/node": "^10.17.21",
"jsii": "^0.0.0",
"jsii-build-tools": "^0.0.0",
"jsii-rosetta": "^0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@types/inquirer": "^6.5.0",
"@types/jest": "^25.2.1",
"@types/jest-expect-message": "^1.0.1",
"@types/node": "^10.17.20",
"@types/node": "^10.17.21",
"@types/yargs": "^15.0.4",
"eslint": "^6.8.0",
"jest": "^25.4.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-diff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@types/fs-extra": "^8.1.0",
"@types/jest": "^25.2.1",
"@types/jest-expect-message": "^1.0.1",
"@types/node": "^10.17.20",
"@types/node": "^10.17.21",
"@types/tar-fs": "^1.16.3",
"@types/yargs": "^15.0.4",
"eslint": "^6.8.0",
Expand Down
89 changes: 82 additions & 7 deletions packages/jsii-pacmak/lib/targets/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,20 @@ class JavaGenerator extends Generator {
return `${path.join('src', 'main', 'java', ...packageName.split('.'), typeName.split('.')[0])}.java`;
}

private toJavaResourcePath(assm: spec.Assembly, fqn: string, ext = '.txt') {
const { packageName, typeName } = this.toNativeName(assm, {
fqn,
kind: spec.TypeKind.Class,
assembly: assm.name,
name: fqn.replace(/.*\.([^.]+)$/, '$1')
});

const name = `${path.join(...packageName.split('.'), typeName.split('.')[0])}${ext}`;
const filePath = path.join('src', 'main', 'resources', name);

return { filePath, name };
}

// eslint-disable-next-line complexity
private addJavaDocs(doc: spec.Documentable, defaultText?: string) {
if (!defaultText && Object.keys(doc.docs ?? {}).length === 0
Expand Down Expand Up @@ -1813,24 +1827,74 @@ class JavaGenerator extends Generator {
private emitModuleFile(mod: spec.Assembly) {
const moduleName = mod.name;
const moduleClass = this.makeModuleClass(moduleName);

const { filePath: moduleResFile, name: moduleResName } = this.toJavaResourcePath(mod, `${mod.name}.${MODULE_CLASS_NAME}`);
this.code.openFile(moduleResFile);
for (const fqn of Object.keys(this.assembly.types ?? {})) {
this.code.line(`${fqn}=${this.toNativeFqn(fqn, { binaryName: true })}`);
}
this.code.closeFile(moduleResFile);

const moduleFile = this.toJavaFilePath(mod, {
assembly: mod.name,
fqn: `${mod.name}.${MODULE_CLASS_NAME}`,
kind: spec.TypeKind.Class,
name: MODULE_CLASS_NAME,
});

this.code.openFile(moduleFile);
this.code.line(`package ${this.toNativeName(mod).packageName};`);
this.code.line();
if (Object.keys(mod.dependencies ?? {}).length > 0) {
this.code.line('import static java.util.Arrays.asList;');
this.code.line();
}
this.code.line('import java.io.BufferedReader;');
this.code.line('import java.io.InputStream;');
this.code.line('import java.io.InputStreamReader;');
this.code.line('import java.io.IOException;');
this.code.line('import java.io.Reader;');
this.code.line('import java.io.UncheckedIOException;');
this.code.line();
this.code.line('import java.nio.charset.StandardCharsets;');
this.code.line();
this.code.line('import java.util.HashMap;');
if (Object.keys(mod.dependencies ?? {}).length > 0) {
this.code.line('import java.util.List;');
}
this.code.line('import java.util.Map;');
this.code.line();
this.code.line('import software.amazon.jsii.JsiiModule;');
this.code.line();

this.code.openBlock(`public final class ${MODULE_CLASS_NAME} extends JsiiModule`);
this.code.line('private static final Map<String, String> MODULE_TYPES = load();');
this.code.line();

this.code.openBlock('private static Map<String, String> load()');
this.code.line('final Map<String, String> result = new HashMap<>();');
this.code.line(`final ClassLoader cl = ${MODULE_CLASS_NAME}.class.getClassLoader();`);
this.code.line(`try (final InputStream is = cl.getResourceAsStream("${moduleResName}");`);
this.code.line(' final Reader rd = new InputStreamReader(is, StandardCharsets.UTF_8);');
this.code.openBlock(' final BufferedReader br = new BufferedReader(rd))');
this.code.line('br.lines()');
this.code.line(' .filter(line -> !line.trim().isEmpty())');
this.code.openBlock(' .forEach(line -> ');
this.code.line('final String[] parts = line.split("=", 2);');
this.code.line('final String fqn = parts[0];');
this.code.line('final String className = parts[1];');
this.code.line('result.put(fqn, className);');
this.code.unindent('});'); // Proxy for closeBlock
this.code.closeBlock();
this.code.openBlock('catch (final IOException exception)');
this.code.line('throw new UncheckedIOException(exception);');
this.code.closeBlock();
this.code.line('return result;');
this.code.closeBlock();
this.code.line();

this.code.line('private final Map<String, Class<?>> cache = new HashMap<>();');
this.code.line();

// ctor
this.code.openBlock(`public ${MODULE_CLASS_NAME}()`);
Expand All @@ -1854,11 +1918,19 @@ class JavaGenerator extends Generator {
this.code.line();
this.code.line('@Override');
this.code.openBlock('protected Class<?> resolveClass(final String fqn) throws ClassNotFoundException');
this.code.openBlock('switch (fqn)');
for (const type of Object.keys(this.assembly.types ?? {})) {
this.code.line(`case "${type}": return ${this.toNativeFqn(type)}.class;`);
}
this.code.line('default: throw new ClassNotFoundException("Unknown JSII type: " + fqn);');
this.code.openBlock('if (!MODULE_TYPES.containsKey(fqn))');
this.code.line('throw new ClassNotFoundException("Unknown JSII type: " + fqn);');
this.code.closeBlock();
this.code.line('return this.cache.computeIfAbsent(MODULE_TYPES.get(fqn), this::findClass);');
this.code.closeBlock();

this.code.line();
this.code.openBlock('private Class<?> findClass(final String binaryName)');
this.code.openBlock('try');
this.code.line('return Class.forName(binaryName);');
this.code.closeBlock();
this.code.openBlock('catch (final ClassNotFoundException exception)');
this.code.line('throw new RuntimeException(exception);');
this.code.closeBlock();
this.code.closeBlock();

Expand Down Expand Up @@ -1893,7 +1965,7 @@ class JavaGenerator extends Generator {
*
* @throws if the assembly the FQN belongs to does not have a `targets.java.package` set.
*/
private toNativeFqn(fqn: string): string {
private toNativeFqn(fqn: string, { binaryName }: { binaryName: boolean } = { binaryName: false }): string {
const [mod, ...name] = fqn.split('.');
const depMod = this.findModule(mod);
// Make sure any dependency (direct or transitive) of which any type is explicitly referenced by the generated
Expand All @@ -1905,7 +1977,10 @@ class JavaGenerator extends Generator {
}

const { packageName, typeName } = this.toNativeName(this.assembly, this.assembly.types![fqn]);
return `${packageName}${typeName ? `.${typeName}` : ''}`;
const className = typeName && binaryName
? typeName.replace('.', '$')
: typeName;
return `${packageName}${className ? `.${className}` : ''}`;
}

private getNativeName(assm: spec.Assembly, name: string | undefined): string;
Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-pacmak/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@types/fs-extra": "^8.1.0",
"@types/jest": "^25.2.1",
"@types/mock-fs": "^4.10.0",
"@types/node": "^10.17.20",
"@types/node": "^10.17.21",
"@types/semver": "^7.1.0",
"@types/yargs": "^15.0.4",
"eslint": "^6.8.0",
Expand Down
Loading

0 comments on commit 0b09d7b

Please sign in to comment.