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

adjusts to liquibase generator. #25631

Merged
merged 5 commits into from
Mar 26, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/generator-database-changelog-liquibase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ jobs:
#----------------------------------------------------------------------
# Launch tests
#----------------------------------------------------------------------
- name: 'TESTS: check liquibase:diff'
run: ./mvnw liquibase:diff
- name: 'TESTS: backend'
run: npm run ci:backend:test
- name: 'TESTS: frontend'
Expand Down
12 changes: 6 additions & 6 deletions generators/app/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -518,17 +518,17 @@ exports[`generator - app with default config should match snapshot 1`] = `
"sonar-maven-plugin": "'SONAR-MAVEN-PLUGIN-VERSION'",
"spotless-gradle-plugin": "'SPOTLESS-GRADLE-PLUGIN-VERSION'",
"spotless-maven-plugin": "'SPOTLESS-MAVEN-PLUGIN-VERSION'",
"spring-boot": "'SPRING-BOOT-VERSION'",
"spring-cloud-dependencies": "'SPRING-CLOUD-DEPENDENCIES-VERSION'",
"spring-dependency-management": "'SPRING-DEPENDENCY-MANAGEMENT-VERSION'",
"springdoc": "'SPRINGDOC-VERSION'",
"testng": "'TESTNG-VERSION'",
"typesafe": "'TYPESAFE-VERSION'",
"xmemcached": "'XMEMCACHED-VERSION'",
"xmemcached-provider": "'XMEMCACHED-PROVIDER-VERSION'",
},
"javaManagedProperties": {},
"javaPackageSrcDir": "src/main/java/com/mycompany/myapp/",
"javaPackageTestDir": "src/test/java/com/mycompany/myapp/",
"javaProperties": {},
"javaVersion": "JAVA_VERSION",
"jhiPrefix": "jhi",
"jhiPrefixCapitalized": "Jhi",
Expand Down Expand Up @@ -1091,14 +1091,14 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"sonar-maven-plugin": "'SONAR-MAVEN-PLUGIN-VERSION'",
"spotless-gradle-plugin": "'SPOTLESS-GRADLE-PLUGIN-VERSION'",
"spotless-maven-plugin": "'SPOTLESS-MAVEN-PLUGIN-VERSION'",
"spring-boot": "'SPRING-BOOT-VERSION'",
"spring-cloud-dependencies": "'SPRING-CLOUD-DEPENDENCIES-VERSION'",
"spring-dependency-management": "'SPRING-DEPENDENCY-MANAGEMENT-VERSION'",
"springdoc": "'SPRINGDOC-VERSION'",
"testng": "'TESTNG-VERSION'",
},
"javaManagedProperties": {},
"javaPackageSrcDir": "src/main/java/com/mycompany/myapp/",
"javaPackageTestDir": "src/test/java/com/mycompany/myapp/",
"javaProperties": {},
"javaVersion": "JAVA_VERSION",
"jhiPrefix": "jhi",
"jhiPrefixCapitalized": "Jhi",
Expand Down Expand Up @@ -1664,17 +1664,17 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"sonar-maven-plugin": "'SONAR-MAVEN-PLUGIN-VERSION'",
"spotless-gradle-plugin": "'SPOTLESS-GRADLE-PLUGIN-VERSION'",
"spotless-maven-plugin": "'SPOTLESS-MAVEN-PLUGIN-VERSION'",
"spring-boot": "'SPRING-BOOT-VERSION'",
"spring-cloud-dependencies": "'SPRING-CLOUD-DEPENDENCIES-VERSION'",
"spring-dependency-management": "'SPRING-DEPENDENCY-MANAGEMENT-VERSION'",
"springdoc": "'SPRINGDOC-VERSION'",
"testng": "'TESTNG-VERSION'",
"typesafe": "'TYPESAFE-VERSION'",
"xmemcached": "'XMEMCACHED-VERSION'",
"xmemcached-provider": "'XMEMCACHED-PROVIDER-VERSION'",
},
"javaManagedProperties": {},
"javaPackageSrcDir": "src/main/java/com/mycompany/myapp/",
"javaPackageTestDir": "src/test/java/com/mycompany/myapp/",
"javaProperties": {},
"javaVersion": "JAVA_VERSION",
"jhiPrefix": "jhi",
"jhiPrefixCapitalized": "Jhi",
Expand Down
23 changes: 13 additions & 10 deletions generators/base-core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { GeneratorMeta } from '@yeoman/types';
import chalk from 'chalk';
import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
import * as _ from 'lodash-es';
import { kebabCase } from 'lodash-es';
import { kebabCase, snakeCase } from 'lodash-es';
import { simpleGit } from 'simple-git';
import type { CopyOptions } from 'mem-fs-editor';
import type { Data as TemplateData, Options as TemplateOptions } from 'ejs';
Expand Down Expand Up @@ -60,6 +60,7 @@ import command from '../base/command.js';
import { GENERATOR_JHIPSTER, YO_RC_FILE } from '../generator-constants.js';
import { convertConfigToOption } from '../../lib/internal/index.js';
import { getGradleLibsVersionsProperties } from '../gradle/support/dependabot-gradle.js';
import { dockerPlaceholderGenerator } from '../docker/utils.js';

const { merge, get, set } = _;
const {
Expand Down Expand Up @@ -1000,10 +1001,18 @@ templates: ${JSON.stringify(existingTemplates, null, 2)}`;
*/
prepareDependencies(
map: Record<string, string>,
valuePlaceholder: (value: string) => string = value => `${_.snakeCase(value).toUpperCase()}_VERSION`,
valuePlaceholder?: 'java' | 'docker' | ((value: string) => string),
): Record<string, string> {
let placeholder: (value: string) => string;
if (valuePlaceholder === 'java') {
placeholder = value => `'${kebabCase(value).toUpperCase()}-VERSION'`;
} else if (valuePlaceholder === 'docker') {
placeholder = dockerPlaceholderGenerator;
} else {
placeholder = valuePlaceholder ?? (value => `${snakeCase(value).toUpperCase()}_VERSION`);
}
if (this.useVersionPlaceholders) {
return Object.fromEntries(Object.keys(map).map(dep => [dep, valuePlaceholder(dep)]));
return Object.fromEntries(Object.keys(map).map(dep => [dep, placeholder(dep)]));
}
return {
...map,
Expand All @@ -1027,13 +1036,7 @@ templates: ${JSON.stringify(existingTemplates, null, 2)}`;

const gradleLibsVersions = this.readTemplate(gradleCatalog)?.toString();
if (gradleLibsVersions) {
Object.assign(
javaDependencies,
this.prepareDependencies(
getGradleLibsVersionsProperties(gradleLibsVersions!),
value => `'${kebabCase(value).toUpperCase()}-VERSION'`,
),
);
Object.assign(javaDependencies, this.prepareDependencies(getGradleLibsVersionsProperties(gradleLibsVersions!), 'java'));
}
}

Expand Down
4 changes: 2 additions & 2 deletions generators/base-workspaces/internal/docker-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
*/
import { dockerContainers as elasticDockerContainer } from '../../generator-constants.js';
import { dockerPlaceholderGenerator, getDockerfileContainers } from '../../docker/utils.js';
import { getDockerfileContainers } from '../../docker/utils.js';

export async function loadDockerDependenciesTask(this: any, { context = this } = {}) {
const dockerfile = this.readTemplate(this.jhipsterTemplatePath('../../server/resources/Dockerfile'));
Expand All @@ -26,6 +26,6 @@ export async function loadDockerDependenciesTask(this: any, { context = this } =
...elasticDockerContainer,
...getDockerfileContainers(dockerfile),
},
dockerPlaceholderGenerator,
'docker',
);
}
29 changes: 20 additions & 9 deletions generators/bootstrap-application-server/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as _ from 'lodash-es';

import BaseApplicationGenerator from '../base-application/index.js';
import { GENERATOR_BOOTSTRAP_APPLICATION_BASE, GENERATOR_BOOTSTRAP_APPLICATION_SERVER } from '../generator-list.js';
Expand All @@ -43,10 +42,10 @@ import {
import { getGradleLibsVersionsProperties } from '../gradle/support/index.js';
import { getPomVersionProperties } from '../maven/support/index.js';
import { prepareField as prepareFieldForLiquibaseTemplates } from '../liquibase/support/index.js';
import { dockerPlaceholderGenerator, getDockerfileContainers } from '../docker/utils.js';
import { getDockerfileContainers } from '../docker/utils.js';
import { GRADLE_VERSION } from '../gradle/constants.js';
import { normalizePathEnd } from '../base/support/path.js';
import { getFrontendAppName } from '../base/support/index.js';
import { getFrontendAppName, mutateData } from '../base/support/index.js';
import { getMainClassName } from '../java/support/index.js';
import { loadConfig, loadDerivedConfig } from '../../lib/internal/index.js';
import serverCommand from '../server/command.js';
Expand Down Expand Up @@ -82,24 +81,36 @@ export default class BoostrapApplicationServer extends BaseApplicationGenerator
const gradleLibsVersions = this.readTemplate(
this.jhipsterTemplatePath('../../server/resources/gradle/libs.versions.toml'),
)?.toString();
application.packageInfoJavadocs = [];
application.javaDependencies = this.prepareDependencies(
const applicationJavaDependencies = this.prepareDependencies(
{
...getPomVersionProperties(pomFile!),
...getGradleLibsVersionsProperties(gradleLibsVersions!),
},
// Gradle doesn't allows snakeCase
value => `'${_.kebabCase(value).toUpperCase()}-VERSION'`,
'java',
);

const dockerfile = this.readTemplate(this.jhipsterTemplatePath('../../server/resources/Dockerfile'));
application.dockerContainers = this.prepareDependencies(
const applicationDockerContainers = this.prepareDependencies(
{
...dockerContainers,
...getDockerfileContainers(dockerfile),
},
dockerPlaceholderGenerator,
'docker',
);

mutateData(application, {
packageInfoJavadocs: [],
javaProperties: {},
javaManagedProperties: {},
javaDependencies: ({ javaDependencies }) => ({
...applicationJavaDependencies,
...javaDependencies,
}),
dockerContainers: ({ dockerContainers: currentDockerContainers = {} }) => ({
...applicationDockerContainers,
...currentDockerContainers,
}),
});
},
});
}
Expand Down
5 changes: 4 additions & 1 deletion generators/gradle/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ export default class GradleGenerator extends BaseApplicationGenerator {
source.addGradlePlugin = plugin => this.editFile('build.gradle', addGradlePluginCallback(plugin));
source.addGradleMavenRepository = repository => this.editFile('build.gradle', addGradleMavenRepositoryCallback(repository));
source.addGradlePluginManagement = plugin => this.editFile('settings.gradle', addGradlePluginManagementCallback(plugin));
source.addGradleProperty = property => this.editFile('gradle.properties', addGradlePropertyCallback(property));
source.addGradleProperty = property => {
application.javaProperties![property.property] = property.value!;
this.editFile('gradle.properties', addGradlePropertyCallback(property));
};
source.addGradleDependencyCatalogVersions = (versions, { gradleVersionCatalogFile = 'gradle/libs.versions.toml' } = {}) =>
this.editFile(gradleVersionCatalogFile, addGradleDependenciesCatalogVersionCallback(versions));
source.addGradleDependencyCatalogVersion = (version, options) => source.addGradleDependencyCatalogVersions!([version], options);
Expand Down
14 changes: 12 additions & 2 deletions generators/java/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export default class JavaGenerator extends BaseApplicationGenerator {
get preparing() {
return this.asPreparingTaskGroup({
prepareJavaApplication({ application, source }) {
source.hasJavaProperty = (property: string) => application.javaProperties![property] !== undefined;
source.hasJavaManagedProperty = (property: string) => application.javaManagedProperties![property] !== undefined;
source.addJavaDependencies = (dependencies, options) => {
if (application.buildToolMaven) {
const annotationProcessors = dependencies.filter(dep => dep.scope === 'annotationProcessor');
Expand Down Expand Up @@ -145,12 +147,20 @@ export default class JavaGenerator extends BaseApplicationGenerator {
source.addJavaDefinition = (definition, options) => {
const { dependencies, versions } = definition;
if (dependencies) {
source.addJavaDependencies!(dependencies, options);
source.addJavaDependencies!(
dependencies.filter(dep => {
if (dep.versionRef) {
return versions?.find(({ name }) => name === dep.versionRef)?.version;
}
return true;
}),
options,
);
}
if (versions) {
if (application.buildToolMaven) {
source.addMavenDefinition!({
properties: versions.map(({ name, version }) => ({ property: `${name}.version`, value: version })),
properties: versions.filter(v => v.version).map(({ name, version }) => ({ property: `${name}.version`, value: version })),
});
}
if (application.buildToolGradle) {
Expand Down
15 changes: 14 additions & 1 deletion generators/java/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type JavaArtifact = {
classifier?: string;
} & JavaArtifactType;

export type JavaArtifactVersion = RequireOneOrNone<{ version: string; versionRef: string }, 'version' | 'versionRef'>;
export type JavaArtifactVersion = RequireOneOrNone<{ version?: string; versionRef?: string }, 'version' | 'versionRef'>;

export type JavaDependency = JavaArtifact & JavaArtifactVersion;

Expand Down Expand Up @@ -48,7 +48,13 @@ export type JavaApplication = BaseApplication &

temporaryDir: string;

/** Java dependency versions */
javaDependencies: Record<string, string>;
/** Known properties that can be used */
javaProperties: Record<string, string | null>;
/** Known managed properties that can be used */
javaManagedProperties: Record<string, string | null>;
/** Pre-defined package JavaDocs */
packageInfoJavadocs: { packageName: string; documentation: string }[];

prettierJava: boolean;
Expand All @@ -57,6 +63,13 @@ export type JavaApplication = BaseApplication &
};

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;
addJavaDependencies?(dependency: JavaDependency[], options?: JavaNeedleOptions): void;
hasJavaProperty?(propertyName: string): boolean;
hasJavaManagedProperty?(propertyName: string): boolean;
};
1 change: 1 addition & 0 deletions generators/languages/languages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const generatorPath = join(__dirname, 'index.js');
const createClientProject = options =>
basicHelpers
.runJHipster('app')
.withMockedGenerators(['jhipster:liquibase'])
.withJHipsterConfig()
.withOptions({
...options,
Expand Down
Loading
Loading