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

support include in dubbo.json to specify provider interfaces #103

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion dubbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"entry": "com.alibaba.dubbo.demo",
"entryJarPath": "./java/dubbo-demo/dubbo-demo-api/target/dubbo-demo-api-2.5.7.jar",
"libDirPath": "./java/dubbo-demo/dubbo-demo-api/target/dependency/",
"providerSuffix":"Service"
"providerSuffix":"Service",
"include": ".*DemoProviderInterface|.*myDubboService"
}
Binary file added packages/interpret-cli/ext/jexpose-1.4.jar
Binary file not shown.
27 changes: 19 additions & 8 deletions packages/interpret-cli/src/ext/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,26 @@ const startFlag = 'Output at:';
*/
export async function extra(extraParam: IDubboExtInfo): Promise<IExtraResult> {
await checkConfigPath([extraParam.entryJarPath, extraParam.libDirPath]);
await checkConfigPath([extraParam.entryJarPath, extraParam.libDirPath]);
let params = ['-jar',
join(__dirname, '../../ext/jexpose-1.4.jar'),
'-t',
extraParam.entry,
'-j',
extraParam.entryJarPath,
'-l',
extraParam.libDirPath];
if (extraParam.providerSuffix) {
params.push("-s");
params.push(extraParam.providerSuffix)
}
if (extraParam.include) {
params.push("-i");
params.push(extraParam.include)
}

return new Promise<IExtraResult>(async (resolve, reject) => {
let execCmd = spawn(`java`, [
'-jar',
join(__dirname, '../../ext/jexpose-1.3.jar'),
extraParam.entry,
extraParam.entryJarPath,
extraParam.libDirPath,
extraParam.providerSuffix || 'Provider',
]);
let execCmd = spawn(`java`, params);

let err: string = '';
let jarDir: string = '';
Expand Down
4 changes: 4 additions & 0 deletions packages/interpret-cli/src/handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export class IntepretHandle implements ITypeSearch {
return this.request.providerSuffix;
}

get include(): string {
return this.request.include;
}

public async work() {
await this.prepare();
await this.doItRecursively();
Expand Down
5 changes: 5 additions & 0 deletions packages/interpret-cli/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export class Request {
return this.config.providerSuffix || 'Provider';
}


get include(): string {
return this.config.include || '';
}

registerTypeInfo(typeInfoItem: TypeInfoI) {
let key = '';
if (typeInfoItem.classPath) {
Expand Down
12 changes: 11 additions & 1 deletion packages/interpret-cli/src/transfer/to-typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ export async function toTypescript(
let {sourceFile, astJava} = intepretHandle;

let lastPointIndex = astJava.name.lastIndexOf('.') + 1;
let isProvider = false;
if (intepretHandle.providerSuffix && astJava.name.endsWith(String(intepretHandle.providerSuffix))) {
isProvider = true;
}
if (intepretHandle.include ) {
var reg = new RegExp(intepretHandle.include);
if (reg.test(astJava.name)) {
isProvider = true;
}
}
let typeInfo = {
classPath: astJava.name,
packagePath: astJava.name.substring(0, lastPointIndex),
Expand All @@ -46,7 +56,7 @@ export async function toTypescript(
isAbstract: astJava.isAbstract,
isInterface: astJava.isInterface,
isClass: !astJava.isEnum && !astJava.isInterface,
isProvider: astJava.name.endsWith(String(intepretHandle.providerSuffix) || 'Provider'),
isProvider: isProvider,
};
intepretHandle.request.registerTypeInfo(typeInfo);

Expand Down
2 changes: 2 additions & 0 deletions packages/interpret-cli/src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export interface IDubboExtInfo {
libDirPath: string;
//provider后缀名可配置,默认值 Provider
providerSuffix?: string;
//provider正则
include?: string;
}

export interface IConfig extends IDubboExtInfo {
Expand Down