From e4efc6c98d73b1fbe5081375ffb7641b62c33ad2 Mon Sep 17 00:00:00 2001 From: Sauli Anto Date: Sat, 5 Sep 2020 12:49:28 +0300 Subject: [PATCH 1/6] Fix some lint warnings --- .../config/DatabaseConfiguration.kt.ejs | 8 ++++- .../package/security/SecurityUtils.kt.ejs | 30 +++++++++---------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/generators/server/templates/src/main/kotlin/package/config/DatabaseConfiguration.kt.ejs b/generators/server/templates/src/main/kotlin/package/config/DatabaseConfiguration.kt.ejs index 9e5d22c12..09293d5d1 100644 --- a/generators/server/templates/src/main/kotlin/package/config/DatabaseConfiguration.kt.ejs +++ b/generators/server/templates/src/main/kotlin/package/config/DatabaseConfiguration.kt.ejs @@ -57,7 +57,13 @@ import org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfigurati import org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration import org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties <%_ } _%> -import org.springframework.context.annotation.* +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.ComponentScan.Filter +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.FilterType +import org.springframework.context.annotation.Import +import org.springframework.context.annotation.Profile <%_ if (databaseType === 'mongodb' || databaseType === 'couchbase' || (databaseType === 'sql' && reactive)) { _%> import org.springframework.core.convert.converter.Converter <%_ } _%> diff --git a/generators/server/templates/src/main/kotlin/package/security/SecurityUtils.kt.ejs b/generators/server/templates/src/main/kotlin/package/security/SecurityUtils.kt.ejs index 648298167..e657e129b 100644 --- a/generators/server/templates/src/main/kotlin/package/security/SecurityUtils.kt.ejs +++ b/generators/server/templates/src/main/kotlin/package/security/SecurityUtils.kt.ejs @@ -144,25 +144,25 @@ fun isAuthenticated(): <% if (!reactive) { %>Boolean<% } else { %>Mono< */ fun isCurrentUserInRole(authority: String): <% if (!reactive) { %>Boolean<% } else { %>Mono<% } %> { <%_ if (!reactive) { _%> - val authentication = SecurityContextHolder.getContext().authentication + val authentication = SecurityContextHolder.getContext().authentication - if (authentication != null) { - val isUserPresent = getAuthorities(authentication)?.any { it == authority } - if(isUserPresent != null) { - return isUserPresent + if (authentication != null) { + val isUserPresent = getAuthorities(authentication)?.any { it == authority } + if(isUserPresent != null) { + return isUserPresent + } } - } - return false + return false <%_ } else { _%> - return ReactiveSecurityContextHolder.getContext() - .map(SecurityContext::getAuthentication) - .map(Authentication::getAuthorities) - .map { - it - .map(GrantedAuthority::getAuthority) - .any { it == authority } - } + return ReactiveSecurityContextHolder.getContext() + .map(SecurityContext::getAuthentication) + .map(Authentication::getAuthorities) + .map { + it + .map(GrantedAuthority::getAuthority) + .any { it == authority } + } <%_ } _%> } From 2bfe8ee30e05a5292cf153f5e82c701bca223569 Mon Sep 17 00:00:00 2001 From: Sauli Anto Date: Mon, 7 Sep 2020 22:06:48 +0300 Subject: [PATCH 2/6] Fix tab --- .../src/main/kotlin/package/security/SecurityUtils.kt.ejs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generators/server/templates/src/main/kotlin/package/security/SecurityUtils.kt.ejs b/generators/server/templates/src/main/kotlin/package/security/SecurityUtils.kt.ejs index e657e129b..6d7103804 100644 --- a/generators/server/templates/src/main/kotlin/package/security/SecurityUtils.kt.ejs +++ b/generators/server/templates/src/main/kotlin/package/security/SecurityUtils.kt.ejs @@ -150,7 +150,7 @@ fun isCurrentUserInRole(authority: String): <% if (!reactive) { %>Boolean<% } el val isUserPresent = getAuthorities(authentication)?.any { it == authority } if(isUserPresent != null) { return isUserPresent - } + } } return false From 00361cfc233cec0064d99cdfe7080a3ff13186ea Mon Sep 17 00:00:00 2001 From: Sauli Anto Date: Tue, 8 Sep 2020 09:43:56 +0300 Subject: [PATCH 3/6] Update Ktlint Gradle and enforce fix lint errors --- generators/generator-kotlin-constants.js | 2 +- generators/server/templates/gradle/kotlin.gradle.ejs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/generators/generator-kotlin-constants.js b/generators/generator-kotlin-constants.js index e34146176..57c4efaad 100644 --- a/generators/generator-kotlin-constants.js +++ b/generators/generator-kotlin-constants.js @@ -20,7 +20,7 @@ const KOTLIN_VERSION = '1.3.70'; const MOCKITO_KOTLIN_VERSION = '2.2.0'; const KTLINT_MAVEN_VERSION = '1.2.2'; -const KTLINT_GRADLE_VERSION = '9.0.0'; +const KTLINT_GRADLE_VERSION = '9.4.0'; const DETEKT_VERSION = '1.1.0'; const MAVEN_ANTRUN_VERSION = '1.8'; diff --git a/generators/server/templates/gradle/kotlin.gradle.ejs b/generators/server/templates/gradle/kotlin.gradle.ejs index b31face4b..ba7f7530b 100644 --- a/generators/server/templates/gradle/kotlin.gradle.ejs +++ b/generators/server/templates/gradle/kotlin.gradle.ejs @@ -61,7 +61,7 @@ allOpen { ktlint { //See more options: https://github.com/JLLeitschuh/ktlint-gradle#configuration - ignoreFailures = true + ignoreFailures = false } detekt { From 4865f91139fccea044c3186b06753898de3ec295 Mon Sep 17 00:00:00 2001 From: Sauli Anto Date: Tue, 8 Sep 2020 12:20:40 +0300 Subject: [PATCH 4/6] Disable Ktlint wildcard rule --- generators/server/templates/gradle/kotlin.gradle.ejs | 1 + 1 file changed, 1 insertion(+) diff --git a/generators/server/templates/gradle/kotlin.gradle.ejs b/generators/server/templates/gradle/kotlin.gradle.ejs index ba7f7530b..985394c41 100644 --- a/generators/server/templates/gradle/kotlin.gradle.ejs +++ b/generators/server/templates/gradle/kotlin.gradle.ejs @@ -62,6 +62,7 @@ allOpen { ktlint { //See more options: https://github.com/JLLeitschuh/ktlint-gradle#configuration ignoreFailures = false + disabledRules = ["no-wildcard-imports"] } detekt { From 2c391a941f499c512fab93a2b983e1e0ebbe835c Mon Sep 17 00:00:00 2001 From: Sauli Anto Date: Tue, 8 Sep 2020 13:59:37 +0300 Subject: [PATCH 5/6] Fix lint errors --- README.md | 12 +++++------ .../package/common/field_validators.ejs | 2 +- .../domain/relationship_validators.ejs | 2 +- .../package/web/rest/EntityResourceIT.kt.ejs | 20 +++++++++---------- .../server/templates/gradle/kotlin.gradle.ejs | 6 +++--- .../config/SecurityConfiguration.kt.ejs | 6 +++--- .../PersistentTokenRememberMeServices.kt.ejs | 6 +++--- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 5fc2a20e0..e0ab59935 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ --- @@ -9,9 +9,9 @@ # About > JHipster is a development platform to quickly generate, develop, and deploy modern web applications and microservice architectures. We support many frontend technologies, including Angular, React, and Vue. We even have mobile app support for Ionic and React Native! On the backend, we support Spring Boot (with Java or Kotlin), Micronaut, Quarkus, Node.js, and .NET. For deployment, we embrace cloud native principles with Docker and Kubernetes. Deployment support exists for AWS, Azure, Cloud Foundry, Google Cloud Platform, Heroku, and OpenShift. diff --git a/generators/entity-server/templates/src/main/kotlin/package/common/field_validators.ejs b/generators/entity-server/templates/src/main/kotlin/package/common/field_validators.ejs index 85a2926fd..f6d486fa6 100644 --- a/generators/entity-server/templates/src/main/kotlin/package/common/field_validators.ejs +++ b/generators/entity-server/templates/src/main/kotlin/package/common/field_validators.ejs @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. -%> -<%# Returns a string of all validator annotations for the entity field. -%> +<%# Returns a string of all validator annotations for the entity field. -%> <% const field = fields[idx]; let result = ''; diff --git a/generators/entity-server/templates/src/main/kotlin/package/domain/relationship_validators.ejs b/generators/entity-server/templates/src/main/kotlin/package/domain/relationship_validators.ejs index 19a7bfe45..e1fd6cd27 100644 --- a/generators/entity-server/templates/src/main/kotlin/package/domain/relationship_validators.ejs +++ b/generators/entity-server/templates/src/main/kotlin/package/domain/relationship_validators.ejs @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. -%> -<%# Returns a string of all validator annotations for the entity relationships. -%> +<%# Returns a string of all validator annotations for the entity relationships. -%> <% const relationship = relationships[idx]; let result = ''; diff --git a/generators/entity-server/templates/src/test/kotlin/package/web/rest/EntityResourceIT.kt.ejs b/generators/entity-server/templates/src/test/kotlin/package/web/rest/EntityResourceIT.kt.ejs index e0ac77e22..90b0dccf4 100644 --- a/generators/entity-server/templates/src/test/kotlin/package/web/rest/EntityResourceIT.kt.ejs +++ b/generators/entity-server/templates/src/test/kotlin/package/web/rest/EntityResourceIT.kt.ejs @@ -327,16 +327,16 @@ class <%= entityClass %>ResourceIT <% if (databaseType === 'cassandra') { %>: Ab @BeforeEach fun setup() { MockitoAnnotations.initMocks(this) - <%_ if (service !== 'no') { _%> - val <%= entityInstance %>Resource = <%= entityClass %>Resource(<%= entityInstance %>Service<% if (jpaMetamodelFiltering) { %>, <%= entityInstance %>QueryService<% } %><% if (saveUserSnapshot) { %>, userRepository<% } %>) - <%_ } else { _%> - val <%= entityInstance %>Resource = <%= entityClass %>Resource(<%= entityInstance %>Repository<% if (dto === 'mapstruct') { %>, <%= entityInstance %>Mapper<% } %><% if (searchEngine === 'elasticsearch') { %>, mock<%= entityClass %>SearchRepository<% } %><% if (saveUserSnapshot) { %>, userRepository<% } %><% if (isUsingMapsId === true && dto !== 'mapstruct') { %>, <%= mapsIdRepoInstance _%> <% } %>) - <%_ } _%> - this.rest<%= entityClass %>MockMvc = MockMvcBuilders.standaloneSetup(<%= entityInstance %>Resource) - .setCustomArgumentResolvers(pageableArgumentResolver) - .setControllerAdvice(exceptionTranslator) - .setConversionService(createFormattingConversionService()) - .setMessageConverters(jacksonMessageConverter) + <%_ if (service !== 'no') { _%> + val <%= entityInstance %>Resource = <%= entityClass %>Resource(<%= entityInstance %>Service<% if (jpaMetamodelFiltering) { %>, <%= entityInstance %>QueryService<% } %><% if (saveUserSnapshot) { %>, userRepository<% } %>) + <%_ } else { _%> + val <%= entityInstance %>Resource = <%= entityClass %>Resource(<%= entityInstance %>Repository<% if (dto === 'mapstruct') { %>, <%= entityInstance %>Mapper<% } %><% if (searchEngine === 'elasticsearch') { %>, mock<%= entityClass %>SearchRepository<% } %><% if (saveUserSnapshot) { %>, userRepository<% } %><% if (isUsingMapsId === true && dto !== 'mapstruct') { %>, <%= mapsIdRepoInstance _%> <% } %>) + <%_ } _%> + this.rest<%= entityClass %>MockMvc = MockMvcBuilders.standaloneSetup(<%= entityInstance %>Resource) + .setCustomArgumentResolvers(pageableArgumentResolver) + .setControllerAdvice(exceptionTranslator) + .setConversionService(createFormattingConversionService()) + .setMessageConverters(jacksonMessageConverter) .setValidator(validator).build() } <%_ } _%> diff --git a/generators/server/templates/gradle/kotlin.gradle.ejs b/generators/server/templates/gradle/kotlin.gradle.ejs index 985394c41..9d20e477b 100644 --- a/generators/server/templates/gradle/kotlin.gradle.ejs +++ b/generators/server/templates/gradle/kotlin.gradle.ejs @@ -53,16 +53,16 @@ allOpen { [compileKotlin, compileTestKotlin]*.with { kotlinOptions { - jvmTarget = "<%= JAVA_VERSION %>" + jvmTarget = "<%= JAVA_VERSION %>" javaParameters = true - freeCompilerArgs = ["-Xjvm-default=enable"] + freeCompilerArgs = ["-Xjvm-default=enable"] } } ktlint { //See more options: https://github.com/JLLeitschuh/ktlint-gradle#configuration ignoreFailures = false - disabledRules = ["no-wildcard-imports"] + disabledRules = ["no-wildcard-imports", "filename"] } detekt { diff --git a/generators/server/templates/src/main/kotlin/package/config/SecurityConfiguration.kt.ejs b/generators/server/templates/src/main/kotlin/package/config/SecurityConfiguration.kt.ejs index ee40d5eb1..11de2b4e0 100644 --- a/generators/server/templates/src/main/kotlin/package/config/SecurityConfiguration.kt.ejs +++ b/generators/server/templates/src/main/kotlin/package/config/SecurityConfiguration.kt.ejs @@ -365,14 +365,14 @@ class SecurityConfiguration(private val oAuth2Properties: OAuth2Properties<% if override fun configure(http: HttpSecurity) { http .csrf() - <%_ if (applicationType === 'gateway') { _%> + <%_ if (applicationType === 'gateway') { _%> .ignoringAntMatchers("/h2-console/**") .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) .and() .addFilterBefore(corsFilter, CsrfFilter::class.java) - <%_ } else { _%> + <%_ } else { _%> .disable() - <%_ } _%> + <%_ } _%> .headers() .frameOptions() .disable() diff --git a/generators/server/templates/src/main/kotlin/package/security/PersistentTokenRememberMeServices.kt.ejs b/generators/server/templates/src/main/kotlin/package/security/PersistentTokenRememberMeServices.kt.ejs index 7dea428b2..d8f36c0dc 100644 --- a/generators/server/templates/src/main/kotlin/package/security/PersistentTokenRememberMeServices.kt.ejs +++ b/generators/server/templates/src/main/kotlin/package/security/PersistentTokenRememberMeServices.kt.ejs @@ -264,9 +264,9 @@ class PersistentTokenRememberMeServices( if (token.tokenDate!!.plusDays(TOKEN_VALIDITY_DAYS.toLong()).isBefore(LocalDate.now())) { <%_ } _%> <%_ if (databaseType === 'cassandra') { _%> - if (token.tokenDate!!.toInstant().plus( - TOKEN_VALIDITY_DAYS.toLong(), ChronoUnit.DAYS - ).isBefore(Date().toInstant()) + if (token.tokenDate!!.toInstant() + .plus(TOKEN_VALIDITY_DAYS.toLong(), ChronoUnit.DAYS) + .isBefore(Date().toInstant()) ) { <%_ } _%> <%_ if (databaseType === 'sql') { _%> From a06262952965d4481c892774c669ad0624cb0604 Mon Sep 17 00:00:00 2001 From: Sauli Anto Date: Tue, 8 Sep 2020 14:57:06 +0300 Subject: [PATCH 6/6] Fix tab indentation --- .../main/kotlin/package/service/mapper/EntityMapper.kt.ejs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generators/entity-server/templates/src/main/kotlin/package/service/mapper/EntityMapper.kt.ejs b/generators/entity-server/templates/src/main/kotlin/package/service/mapper/EntityMapper.kt.ejs index 297a9e205..73146af53 100644 --- a/generators/entity-server/templates/src/main/kotlin/package/service/mapper/EntityMapper.kt.ejs +++ b/generators/entity-server/templates/src/main/kotlin/package/service/mapper/EntityMapper.kt.ejs @@ -84,7 +84,7 @@ relationships.forEach((relationship, index) => { }); _%> <%_ if (relationships.length !== 0 && renMapAnotEnt === true) { _%> @Mappings( - <%- entityToDTOMapping.join(',\n\t\t') %> + <%- entityToDTOMapping.join(',\n ') %> ) <%_ } _%> <%_ if (renMapAnotEnt === true) { _%> @@ -120,7 +120,7 @@ relationships.forEach((relationship, index) => { }); _ %> <%_ if (relationships.length !== 0 && renMapAnotEnt === true) { _%> @Mappings( - <%- dtoToEntityMapping.join(',\n\t\t') %> + <%- dtoToEntityMapping.join(',\n ') %> ) <%_ } _%> override fun toEntity(<%= asDto(entityInstance) %>: <%= asDto(entityClass) %>): <%= asEntity(entityClass) %>