Skip to content

Commit

Permalink
add addJavaDependencies api to sources
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Aug 14, 2024
1 parent 1fa1cea commit 61a8c23
Show file tree
Hide file tree
Showing 6 changed files with 532 additions and 393 deletions.
19 changes: 18 additions & 1 deletion generators/java/generators/build-tool/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import BaseApplicationGenerator from '../../../base-application/index.js';
import { GENERATOR_GRADLE, GENERATOR_MAVEN } from '../../../generator-list.js';
import type { MavenDependency } from '../../../maven/types.js';
import { javaScopeToGradleScope } from '../../support/index.js';
import type { JavaDependency } from '../../types.js';
import type { ConditionalJavaDefinition, JavaDependency, JavaNeedleOptions } from '../../types.js';

const { GRADLE, MAVEN } = buildToolTypes;

Expand Down Expand Up @@ -132,6 +132,23 @@ export default class BuildToolGenerator extends BaseApplicationGenerator {
}
}
};

source.addJavaDefinitions = (
optionsOrDefinition: JavaNeedleOptions | ConditionalJavaDefinition,
...definitions: ConditionalJavaDefinition[]
) => {
let options: JavaNeedleOptions | undefined = undefined;
if ('gradleFile' in optionsOrDefinition || 'gradleVersionCatalogFile' in optionsOrDefinition) {
options = optionsOrDefinition;
} else {
definitions.unshift(optionsOrDefinition as ConditionalJavaDefinition);
}
for (const definition of definitions) {
if (definition.condition ?? true) {
source.addJavaDefinition!(definition, options);
}
}
};
},
});
}
Expand Down
6 changes: 6 additions & 0 deletions generators/java/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,19 @@ export type JavaApplication = BaseApplication &
addOpenapiGeneratorPlugin: boolean;
};

export type ConditionalJavaDefinition = JavaDefinition & { condition?: boolean };

export type JavaSourceType = {
/**
* Add a JavaDefinition to the application.
* A version requires a valid version otherwise it will be ignored.
* A dependency with versionRef requires a valid referenced version at `versions` otherwise it will be ignored.
*/
addJavaDefinition?(definition: JavaDefinition, options?: JavaNeedleOptions): void;
addJavaDefinitions?(
optionsOrDefinition: JavaNeedleOptions | ConditionalJavaDefinition,
...definitions: ConditionalJavaDefinition[]
): void;
addJavaDependencies?(dependency: JavaDependency[], options?: JavaNeedleOptions): void;
hasJavaProperty?(propertyName: string): boolean;
hasJavaManagedProperty?(propertyName: string): boolean;
Expand Down
Loading

0 comments on commit 61a8c23

Please sign in to comment.