diff --git a/generators/spring-boot-javers/__snapshots__/generator.spec.js.snap b/generators/spring-boot-javers/__snapshots__/generator.spec.js.snap index 47508b5..1198695 100644 --- a/generators/spring-boot-javers/__snapshots__/generator.spec.js.snap +++ b/generators/spring-boot-javers/__snapshots__/generator.spec.js.snap @@ -2,30 +2,282 @@ exports[`SubGenerator spring-boot-javers of entity-audit JHipster blueprint > run > should succeed 1`] = ` { + ".devcontainer/Dockerfile": { + "stateCleared": "modified", + }, + ".devcontainer/devcontainer.json": { + "stateCleared": "modified", + }, + ".editorconfig": { + "stateCleared": "modified", + }, + ".gitattributes": { + "stateCleared": "modified", + }, + ".gitignore": { + "stateCleared": "modified", + }, + ".husky/pre-commit": { + "stateCleared": "modified", + }, + ".lintstagedrc.cjs": { + "stateCleared": "modified", + }, + ".mvn/jvm.config": { + "stateCleared": "modified", + }, + ".mvn/wrapper/maven-wrapper.jar": { + "stateCleared": "modified", + }, + ".mvn/wrapper/maven-wrapper.properties": { + "stateCleared": "modified", + }, + ".prettierignore": { + "stateCleared": "modified", + }, + ".prettierrc": { + "stateCleared": "modified", + }, ".yo-rc.json": { "stateCleared": "modified", }, + "README.md": { + "stateCleared": "modified", + }, + "checkstyle.xml": { + "stateCleared": "modified", + }, + "mvnw": { + "stateCleared": "modified", + }, + "mvnw.cmd": { + "stateCleared": "modified", + }, + "npmw": { + "stateCleared": "modified", + }, + "npmw.cmd": { + "stateCleared": "modified", + }, + "package.json": { + "stateCleared": "modified", + }, + "pom.xml": { + "stateCleared": "modified", + }, + "sonar-project.properties": { + "stateCleared": "modified", + }, + "src/main/docker/app.yml": { + "stateCleared": "modified", + }, + "src/main/docker/grafana/provisioning/dashboards/JVM.json": { + "stateCleared": "modified", + }, + "src/main/docker/grafana/provisioning/dashboards/dashboard.yml": { + "stateCleared": "modified", + }, + "src/main/docker/grafana/provisioning/datasources/datasource.yml": { + "stateCleared": "modified", + }, + "src/main/docker/jhipster-control-center.yml": { + "stateCleared": "modified", + }, + "src/main/docker/jib/entrypoint.sh": { + "stateCleared": "modified", + }, + "src/main/docker/monitoring.yml": { + "stateCleared": "modified", + }, + "src/main/docker/postgresql.yml": { + "stateCleared": "modified", + }, + "src/main/docker/prometheus/prometheus.yml": { + "stateCleared": "modified", + }, + "src/main/docker/services.yml": { + "stateCleared": "modified", + }, + "src/main/docker/sonar.yml": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/ApplicationWebXml.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/myapp/GeneratedByJHipster.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/myapp/JhipsterApp.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/aop/logging/LoggingAspect.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/aop/logging/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/ApplicationProperties.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/AsyncConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/CRLFLogConverter.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/CacheConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/Constants.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/DatabaseConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/DateTimeFormatConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/JacksonConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/LiquibaseConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/LoggingAspectConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/LoggingConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/SecurityConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/SecurityJwtConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/StaticResourcesWebConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/WebConfigurer.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/myapp/config/audit/JaversAuthorProvider.java": { "stateCleared": "modified", }, "src/main/java/com/mycompany/myapp/config/audit/package-info.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/myapp/config/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/domain/AbstractAuditingEntity.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/myapp/domain/Authority.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/myapp/domain/User.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/myapp/domain/package-info.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/myapp/management/SecurityMetersService.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/management/package-info.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/myapp/package-info.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/myapp/repository/AuthorityRepository.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/repository/UserRepository.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/repository/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/security/AuthoritiesConstants.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/security/DomainUserDetailsService.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/security/SecurityUtils.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/security/SpringSecurityAuditorAware.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/security/UserNotActivatedException.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/security/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/EmailAlreadyUsedException.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/InvalidPasswordException.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/MailService.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/UserService.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/UsernameAlreadyUsedException.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/dto/AdminUserDTO.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/dto/PasswordChangeDTO.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/dto/UserDTO.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/dto/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/mapper/UserMapper.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/mapper/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/filter/SpaWebFilter.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/filter/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/AccountResource.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/AuthenticateController.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/myapp/web/rest/JaversEntityAuditResource.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/myapp/web/rest/PublicUserResource.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/UserResource.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/myapp/web/rest/dto/EntityAuditAction.java": { "stateCleared": "modified", }, @@ -35,9 +287,186 @@ exports[`SubGenerator spring-boot-javers of entity-audit JHipster blueprint > ru "src/main/java/com/mycompany/myapp/web/rest/dto/package-info.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/myapp/web/rest/errors/BadRequestAlertException.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/errors/EmailAlreadyUsedException.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/errors/ErrorConstants.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/errors/ExceptionTranslator.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/errors/FieldErrorVM.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/errors/InvalidPasswordException.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/errors/LoginAlreadyUsedException.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/errors/package-info.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/myapp/web/rest/package-info.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/myapp/web/rest/vm/KeyAndPasswordVM.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/vm/LoginVM.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/vm/ManagedUserVM.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/vm/package-info.java": { + "stateCleared": "modified", + }, + "src/main/resources/banner.txt": { + "stateCleared": "modified", + }, + "src/main/resources/config/application-dev.yml": { + "stateCleared": "modified", + }, + "src/main/resources/config/application-prod.yml": { + "stateCleared": "modified", + }, + "src/main/resources/config/application-tls.yml": { + "stateCleared": "modified", + }, + "src/main/resources/config/application.yml": { + "stateCleared": "modified", + }, + "src/main/resources/config/liquibase/changelog/00000000000000_initial_schema.xml": { + "stateCleared": "modified", + }, + "src/main/resources/config/liquibase/data/authority.csv": { + "stateCleared": "modified", + }, + "src/main/resources/config/liquibase/data/user.csv": { + "stateCleared": "modified", + }, + "src/main/resources/config/liquibase/data/user_authority.csv": { + "stateCleared": "modified", + }, + "src/main/resources/config/liquibase/master.xml": { + "stateCleared": "modified", + }, + "src/main/resources/config/tls/keystore.p12": { + "stateCleared": "modified", + }, + "src/main/resources/i18n/messages.properties": { + "stateCleared": "modified", + }, + "src/main/resources/i18n/messages_en.properties": { + "stateCleared": "modified", + }, + "src/main/resources/logback-spring.xml": { + "stateCleared": "modified", + }, + "src/main/resources/templates/error.html": { + "stateCleared": "modified", + }, + "src/main/resources/templates/mail/activationEmail.html": { + "stateCleared": "modified", + }, + "src/main/resources/templates/mail/creationEmail.html": { + "stateCleared": "modified", + }, + "src/main/resources/templates/mail/passwordResetEmail.html": { + "stateCleared": "modified", + }, + "src/main/webapp/i18n/en/activate.json": { + "stateCleared": "modified", + }, + "src/main/webapp/i18n/en/adminAuthority.json": { + "stateCleared": "modified", + }, + "src/main/webapp/i18n/en/configuration.json": { + "stateCleared": "modified", + }, + "src/main/webapp/i18n/en/error.json": { + "stateCleared": "modified", + }, + "src/main/webapp/i18n/en/global.json": { + "stateCleared": "modified", + }, + "src/main/webapp/i18n/en/health.json": { + "stateCleared": "modified", + }, + "src/main/webapp/i18n/en/home.json": { + "stateCleared": "modified", + }, + "src/main/webapp/i18n/en/login.json": { + "stateCleared": "modified", + }, + "src/main/webapp/i18n/en/logs.json": { + "stateCleared": "modified", + }, + "src/main/webapp/i18n/en/metrics.json": { + "stateCleared": "modified", + }, + "src/main/webapp/i18n/en/password.json": { + "stateCleared": "modified", + }, + "src/main/webapp/i18n/en/register.json": { + "stateCleared": "modified", + }, + "src/main/webapp/i18n/en/reset.json": { + "stateCleared": "modified", + }, + "src/main/webapp/i18n/en/sessions.json": { + "stateCleared": "modified", + }, + "src/main/webapp/i18n/en/settings.json": { + "stateCleared": "modified", + }, + "src/main/webapp/i18n/en/user-management.json": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/IntegrationTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/TechnicalStructureTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/AsyncSyncConfiguration.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/CRLFLogConverterTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/EmbeddedSQL.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/PostgreSqlTestContainer.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/SpringBootTestClassOrderer.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/SqlTestContainer.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/SqlTestContainersSpringContextCustomizerFactory.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/StaticResourcesWebConfigurerTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/WebConfigurerTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/WebConfigurerTestController.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/timezone/HibernateTimeZoneIT.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/myapp/domain/AssertUtils.java": { "stateCleared": "modified", }, @@ -50,5 +479,104 @@ exports[`SubGenerator spring-boot-javers of entity-audit JHipster blueprint > ru "src/test/java/com/mycompany/myapp/domain/AuthorityTestSamples.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/myapp/management/SecurityMetersServiceTests.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/repository/timezone/DateTimeWrapper.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/repository/timezone/DateTimeWrapperRepository.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/security/DomainUserDetailsServiceIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/security/SecurityUtilsUnitTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/security/jwt/AuthenticationIntegrationTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/security/jwt/JwtAuthenticationTestUtils.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/security/jwt/TokenAuthenticationIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/security/jwt/TokenAuthenticationSecurityMetersIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/service/MailServiceIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/service/UserServiceIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/service/mapper/UserMapperTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/filter/SpaWebFilterIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/rest/AccountResourceIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/rest/AuthenticateControllerIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/rest/PublicUserResourceIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/rest/TestUtil.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/rest/UserResourceIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/rest/WithUnauthenticatedMockUser.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/rest/errors/ExceptionTranslatorIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/rest/errors/ExceptionTranslatorTestController.java": { + "stateCleared": "modified", + }, + "src/test/resources/META-INF/spring.factories": { + "stateCleared": "modified", + }, + "src/test/resources/config/application-testdev.yml": { + "stateCleared": "modified", + }, + "src/test/resources/config/application-testprod.yml": { + "stateCleared": "modified", + }, + "src/test/resources/config/application.yml": { + "stateCleared": "modified", + }, + "src/test/resources/i18n/messages_en.properties": { + "stateCleared": "modified", + }, + "src/test/resources/junit-platform.properties": { + "stateCleared": "modified", + }, + "src/test/resources/logback.xml": { + "stateCleared": "modified", + }, + "src/test/resources/templates/mail/activationEmail.html": { + "stateCleared": "modified", + }, + "src/test/resources/templates/mail/creationEmail.html": { + "stateCleared": "modified", + }, + "src/test/resources/templates/mail/passwordResetEmail.html": { + "stateCleared": "modified", + }, + "src/test/resources/templates/mail/testEmail.html": { + "stateCleared": "modified", + }, } `; diff --git a/generators/spring-boot-javers/generator.js b/generators/spring-boot-javers/generator.js index c536901..278c6f8 100644 --- a/generators/spring-boot-javers/generator.js +++ b/generators/spring-boot-javers/generator.js @@ -1,11 +1,12 @@ import { join } from 'path'; import BaseApplicationGenerator from 'generator-jhipster/generators/base-application'; -import { javaMainPackageTemplatesBlock } from 'generator-jhipster/generators/java/support'; +import { addJavaAnnotation, addJavaImport, javaMainPackageTemplatesBlock } from 'generator-jhipster/generators/java/support'; import { getPomVersionProperties } from 'generator-jhipster/generators/server/support'; export default class extends BaseApplicationGenerator { async beforeQueue() { await this.dependsOnJHipster('jhipster-entity-audit:java-audit'); + await this.dependsOnJHipster('spring-boot'); } get [BaseApplicationGenerator.PREPARING]() { @@ -15,6 +16,18 @@ export default class extends BaseApplicationGenerator { const versions = getPomVersionProperties(pomFile); Object.assign(application.javaDependencies, this.prepareDependencies(versions)); }, + source({ source }) { + source.editJavaFile = + source.editJavaFile ?? + ((file, { staticImports = [], imports = [], annotations = [] }, ...editFileCallback) => + this.editFile( + file, + ...staticImports.map(classPath => addJavaImport(classPath, { staticImport: true })), + ...imports.map(classPath => addJavaImport(classPath)), + ...annotations.map(annotation => addJavaAnnotation(annotation)), + ...editFileCallback, + )); + }, }); } @@ -32,23 +45,19 @@ export default class extends BaseApplicationGenerator { return this.asWritingTaskGroup({ async writingTemplateTask({ application }) { await this.writeFiles({ - sections: { - javersAudit: [ - { - ...javaMainPackageTemplatesBlock(), - templates: ['config/audit/JaversAuthorProvider.java'], - }, - { - condition: application.auditPage, - ...javaMainPackageTemplatesBlock(), - templates: [ - 'web/rest/JaversEntityAuditResource.java', - 'web/rest/dto/EntityAuditEvent.java', - 'web/rest/dto/EntityAuditAction.java', - ], - }, - ], - }, + blocks: [ + javaMainPackageTemplatesBlock({ + templates: ['config/audit/JaversAuthorProvider.java'], + }), + javaMainPackageTemplatesBlock({ + condition: application.auditPage, + templates: [ + 'web/rest/JaversEntityAuditResource.java', + 'web/rest/dto/EntityAuditEvent.java', + 'web/rest/dto/EntityAuditAction.java', + ], + }), + ], context: application, }); }, @@ -56,80 +65,43 @@ export default class extends BaseApplicationGenerator { } get [BaseApplicationGenerator.POST_WRITING]() { - return { - async postWritingTemplateTask({ - source, - application: { mainJavaPackageDir, buildToolMaven, buildToolGradle, databaseTypeSql, databaseTypeMongodb, javaDependencies }, - }) { + return this.asPostWritingTaskGroup({ + async postWritingTemplateTask({ source, application }) { + const { mainJavaPackageDir, databaseTypeSql, databaseTypeMongodb, javaDependencies } = application; // add annotations for Javers to ignore fields in 'AbstractAuditingEntity' class - this.editFile(`${mainJavaPackageDir}domain/AbstractAuditingEntity.java`, { ignoreNonExisting: true }, contents => - contents - .replace( - /import org.springframework.data.annotation.CreatedBy;/, - `import org.springframework.data.annotation.CreatedBy; -import org.javers.core.metamodel.annotation.DiffIgnore;`, - ) - .replace(/(\s*)@MappedSuperclass/, '$1@MappedSuperclass$1@DiffIgnore') - .replace(/\s*import com.fasterxml.jackson.annotation.JsonIgnore;/, ''), + source.editJavaFile( + `${mainJavaPackageDir}domain/AbstractAuditingEntity.java`, + { annotations: [{ annotation: 'DiffIgnore', package: 'org.javers.core.metamodel.annotation' }] }, + contents => contents.replace(/\s*import com.fasterxml.jackson.annotation.JsonIgnore;/, ''), ); // add required third party dependencies - if (buildToolMaven) { - if (databaseTypeMongodb) { - source.addMavenDependency?.({ - groupId: 'org.javers', - artifactId: 'javers-spring-boot-starter-mongo', - version: javaDependencies['javers-core'], - }); - } else if (databaseTypeSql) { - source.addMavenDependency?.({ - groupId: 'org.javers', - artifactId: 'javers-spring-boot-starter-sql', - version: javaDependencies['javers-core'], - }); - } - } else if (buildToolGradle) { - if (databaseTypeMongodb) { - source.addGradleDependency?.({ - groupId: 'org.javers', - artifactId: 'javers-spring-boot-starter-mongo', - version: javaDependencies['javers-core'], - scope: 'implementation', - }); - } else if (databaseTypeSql) { - source.addGradleDependency?.({ - groupId: 'org.javers', - artifactId: 'javers-spring-boot-starter-sql', - version: javaDependencies['javers-core'], - scope: 'implementation', - }); - } + if (databaseTypeMongodb || databaseTypeSql) { + source.addJavaDefinition?.({ + dependencies: [ + { + groupId: 'org.javers', + artifactId: databaseTypeMongodb ? 'javers-spring-boot-starter-mongo' : 'javers-spring-boot-starter-sql', + version: javaDependencies['javers-core'], + }, + ], + }); } }, - }; + }); } get [BaseApplicationGenerator.POST_WRITING_ENTITIES]() { - return { - async postWritingEntitiesTask({ application: { mainJavaPackageDir }, entities }) { + return this.asPostWritingEntitiesTaskGroup({ + async postWritingEntitiesTask({ application: { mainJavaPackageDir }, entities, source }) { for (const entity of entities.filter(e => !e.builtIn && e.enableAudit)) { const { persistClass, entityPackage = '' } = entity; const entityAbsoluteFolder = join(mainJavaPackageDir, entityPackage); - this.editFile(`${entityAbsoluteFolder}repository/${persistClass}Repository.java`, contents => - contents - .replace( - /@Repository/, - `@Repository -@JaversSpringDataAuditable`, - ) - .replace( - /import org.springframework.stereotype.Repository;/, - `import org.javers.spring.annotation.JaversSpringDataAuditable; -import org.springframework.stereotype.Repository;`, - ), - ); + source.editJavaFile(`${entityAbsoluteFolder}repository/${persistClass}Repository.java`, { + annotations: [{ annotation: 'JaversSpringDataAuditable', package: 'org.javers.spring.annotation' }], + }); } }, - }; + }); } }