Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npx projen@0.1.17
- run: yarn install --frozen-lockfile
- run: npx projen@0.1.19
- run: yarn install
- run: yarn build
2 changes: 2 additions & 0 deletions .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ const project = new TypeScriptLibraryProject({
'jsii-srcmak': 'bin/jsii-srcmak'
},
devDependencies: {
'@types/ncp': Semver.caret('2.0.4'),
'@types/node': Semver.caret('13.9.8'),
'@types/fs-extra': Semver.caret('9.0.1'),
},
dependencies: {
'jsii': Semver.caret('1.5.0'),
'jsii-pacmak': Semver.caret('1.5.0'),
'fs-extra': Semver.caret('9.0.0'),
'ncp': Semver.caret('2.0.0'),
'yargs': Semver.caret('11.1.1'),
},
releaseToNpm: true
Expand Down
2 changes: 1 addition & 1 deletion lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface Options {
python?: PythonOutputOptions;

/**
* Produces java code under src/main/yourpackage/main/java/yourpackage/
* Produces java code under src/main/
*
* @default - java is not generated
*/
Expand Down
10 changes: 7 additions & 3 deletions lib/srcmak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as path from 'path';
import { exec, mkdtemp } from './util';
import { compile } from './compile';
import { Options } from './options';
import { ncp } from 'ncp';

const pacmakModule = require.resolve('jsii-pacmak/bin/jsii-pacmak');

Expand Down Expand Up @@ -35,10 +36,13 @@ export async function srcmak(srcdir: string, options: Options = { }) {
}

if (options.java) {
const reldir = options.java.package.replace(/\./g, '/');
const source = path.resolve(path.join(workdir, 'dist/java/src/'));
const target = path.join(options.java.outdir, 'src/main', reldir);
await fs.move(source, target, { overwrite: true });
const target = path.join(options.java.outdir, 'src/');
ncp(source, target, { clobber: false }, (err) => {
if (err) {
return console.error(err);
}
});
}
});
}
21 changes: 13 additions & 8 deletions test/__snapshots__/cli.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`java output 1`] = `
Object {
"src/main/mypackage/main/java/mypackage/$Module.java": "package mypackage;
"src/main/java/mypackage/$Module.java": "package mypackage;

import java.io.BufferedReader;
import java.io.InputStream;
Expand Down Expand Up @@ -53,7 +53,11 @@ public final class $Module extends JsiiModule {
if (!MODULE_TYPES.containsKey(fqn)) {
throw new ClassNotFoundException(\\"Unknown JSII type: \\" + fqn);
}
return this.cache.computeIfAbsent(MODULE_TYPES.get(fqn), this::findClass);
String className = MODULE_TYPES.get(fqn);
if (!this.cache.containsKey(className)) {
this.cache.put(className, this.findClass(className));
}
return this.cache.get(className);
}

private Class<?> findClass(final String binaryName) {
Expand All @@ -66,7 +70,7 @@ public final class $Module extends JsiiModule {
}
}
",
"src/main/mypackage/main/java/mypackage/Calculator.java": "package mypackage;
"src/main/java/mypackage/Calculator.java": "package mypackage;

/**
* A sophisticaed multi-language calculator.
Expand Down Expand Up @@ -116,7 +120,7 @@ public class Calculator extends software.amazon.jsii.JsiiObject {
}
}
",
"src/main/mypackage/main/java/mypackage/Operands.java": "package mypackage;
"src/main/java/mypackage/Operands.java": "package mypackage;

/**
* Math operands.
Expand Down Expand Up @@ -145,7 +149,7 @@ public interface Operands extends software.amazon.jsii.JsiiSerializable {
/**
* A builder for {@link Operands}
*/
public static final class Builder {
public static final class Builder implements software.amazon.jsii.Builder<Operands> {
private java.lang.Number lhs;
private java.lang.Number rhs;

Expand Down Expand Up @@ -174,6 +178,7 @@ public interface Operands extends software.amazon.jsii.JsiiSerializable {
* @return a new instance of {@link Operands}
* @throws NullPointerException if any required attribute was not provided
*/
@Override
public Operands build() {
return new Jsii$Proxy(lhs, rhs);
}
Expand Down Expand Up @@ -253,7 +258,7 @@ public interface Operands extends software.amazon.jsii.JsiiSerializable {
}
}
",
"src/main/mypackage/main/resources/mypackage/$Module.txt": "generated.Calculator=mypackage.Calculator
"src/main/resources/mypackage/$Module.txt": "generated.Calculator=mypackage.Calculator
generated.Operands=mypackage.Operands
",
}
Expand All @@ -268,9 +273,9 @@ Object {
],
},
"description": "generated",
"fingerprint": "YzbxW50rbVtKyO3xyXOGChedDt8pdGdCRYTETM1PW7k=",
"fingerprint": "+fSgo9PQwFAKmX2JcaRILwTXE/p1H1bq+QKuOREAfuE=",
"homepage": "http://generated",
"jsiiVersion": "1.5.0 (build 46538f8)",
"jsiiVersion": "1.6.0 (build 248e75b)",
"license": "Apache-2.0",
"name": "generated",
"repository": Object {
Expand Down
21 changes: 13 additions & 8 deletions test/__snapshots__/srcmak.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`java + different entrypoint 1`] = `
Object {
"src/main/hello/world/main/java/hello/world/$Module.java": "package hello.world;
"src/main/java/hello/world/$Module.java": "package hello.world;

import java.io.BufferedReader;
import java.io.InputStream;
Expand Down Expand Up @@ -53,7 +53,11 @@ public final class $Module extends JsiiModule {
if (!MODULE_TYPES.containsKey(fqn)) {
throw new ClassNotFoundException(\\"Unknown JSII type: \\" + fqn);
}
return this.cache.computeIfAbsent(MODULE_TYPES.get(fqn), this::findClass);
String className = MODULE_TYPES.get(fqn);
if (!this.cache.containsKey(className)) {
this.cache.put(className, this.findClass(className));
}
return this.cache.get(className);
}

private Class<?> findClass(final String binaryName) {
Expand All @@ -66,7 +70,7 @@ public final class $Module extends JsiiModule {
}
}
",
"src/main/hello/world/main/java/hello/world/Hello.java": "package hello.world;
"src/main/java/hello/world/Hello.java": "package hello.world;


@software.amazon.jsii.Jsii(module = hello.world.$Module.class, fqn = \\"generated.Hello\\")
Expand All @@ -90,7 +94,7 @@ public class Hello extends software.amazon.jsii.JsiiObject {
}
}
",
"src/main/hello/world/main/java/hello/world/Operands.java": "package hello.world;
"src/main/java/hello/world/Operands.java": "package hello.world;


@software.amazon.jsii.Jsii(module = hello.world.$Module.class, fqn = \\"generated.Operands\\")
Expand All @@ -110,7 +114,7 @@ public interface Operands extends software.amazon.jsii.JsiiSerializable {
/**
* A builder for {@link Operands}
*/
public static final class Builder {
public static final class Builder implements software.amazon.jsii.Builder<Operands> {
private java.lang.Number lhs;
private java.lang.Number rhs;

Expand Down Expand Up @@ -139,6 +143,7 @@ public interface Operands extends software.amazon.jsii.JsiiSerializable {
* @return a new instance of {@link Operands}
* @throws NullPointerException if any required attribute was not provided
*/
@Override
public Operands build() {
return new Jsii$Proxy(lhs, rhs);
}
Expand Down Expand Up @@ -218,7 +223,7 @@ public interface Operands extends software.amazon.jsii.JsiiSerializable {
}
}
",
"src/main/hello/world/main/resources/hello/world/$Module.txt": "generated.Hello=hello.world.Hello
"src/main/resources/hello/world/$Module.txt": "generated.Hello=hello.world.Hello
generated.Operands=hello.world.Operands
",
}
Expand All @@ -233,9 +238,9 @@ Object {
],
},
"description": "generated",
"fingerprint": "mDN1As+e+zwuytAHqC8o+7gwTrnrzC2d65pSGEUAe1I=",
"fingerprint": "cNtb65kyZQOiBulmzr+bs6dCGdv4uhea1tFTkbRGJTw=",
"homepage": "http://generated",
"jsiiVersion": "1.5.0 (build 46538f8)",
"jsiiVersion": "1.6.0 (build 248e75b)",
"license": "Apache-2.0",
"name": "generated",
"repository": Object {
Expand Down
Loading