FINERACT-1072: Implementing Spotless for Gradle files

This commit is contained in:
Petri Tuomola
2020-07-04 11:25:23 +01:00
committed by Awasum Yannick
parent 1102d5b58a
commit 3f444e2710
2 changed files with 144 additions and 103 deletions
+135 -94
View File
@@ -37,9 +37,9 @@ buildscript {
dependencies { dependencies {
classpath 'io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE' classpath 'io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE'
classpath 'com.bmuschko:gradle-cargo-plugin:2.7.1', classpath 'com.bmuschko:gradle-cargo-plugin:2.7.1',
'nl.javadude.gradle.plugins:license-gradle-plugin:0.11.0', 'nl.javadude.gradle.plugins:license-gradle-plugin:0.11.0',
'org.zeroturnaround:gradle-jrebel-plugin:1.1.10', 'org.zeroturnaround:gradle-jrebel-plugin:1.1.10',
'org.springframework.boot:spring-boot-gradle-plugin:2.2.7.RELEASE' 'org.springframework.boot:spring-boot-gradle-plugin:2.2.7.RELEASE'
// below // below
classpath 'org.apache.openjpa:openjpa:3.1.1' // when upgrading, also change OpenJPA version repeated below in dependencyManagement! classpath 'org.apache.openjpa:openjpa:3.1.1' // when upgrading, also change OpenJPA version repeated below in dependencyManagement!
classpath 'com.radcortez.gradle:openjpa-gradle-plugin:3.1.0' classpath 'com.radcortez.gradle:openjpa-gradle-plugin:3.1.0'
@@ -184,7 +184,10 @@ eclipse
System.setProperty("openjpa.Log", "commons") System.setProperty("openjpa.Log", "commons")
openjpa { openjpa {
includes = ['**/AbstractPersistableCustom.class', '**/domain/*.class'] includes = [
'**/AbstractPersistableCustom.class',
'**/domain/*.class'
]
enhance { enhance {
enforcePropertyRestrictions true enforcePropertyRestrictions true
} }
@@ -218,24 +221,32 @@ jacocoTestReport{
} }
spotless { spotless {
format 'misc', { format 'misc', {
target '**/*.md', '**/*.properties', '**/*.gradle', '**/.gitignore', '**/*.yml', '**/*.xml', '**/**.json', '**/*.sql' target '**/*.md', '**/*.properties', '**/.gitignore', '**/*.yml', '**/*.xml', '**/**.json', '**/*.sql'
targetExclude '**/build/**', '**/bin/**', '**/.settings/**','**/.idea/**' targetExclude '**/build/**', '**/bin/**', '**/.settings/**','**/.idea/**'
indentWithSpaces(4) indentWithSpaces(4)
endWithNewline() endWithNewline()
trimTrailingWhitespace() trimTrailingWhitespace()
} }
java { groovyGradle {
importOrder() //sort imports alphabetically target '*.gradle', '**/*.gradle'
removeUnusedImports() greclipse()
eclipse().configFile '../config/fineractdev-formatter.xml' indentWithSpaces(4)
endWithNewline() endWithNewline()
trimTrailingWhitespace() trimTrailingWhitespace()
}
// Enforce style modifier order java {
custom 'Modifier ordering', { importOrder() //sort imports alphabetically
def modifierRanking = [ removeUnusedImports()
eclipse().configFile '../config/fineractdev-formatter.xml'
endWithNewline()
trimTrailingWhitespace()
// Enforce style modifier order
custom 'Modifier ordering', {
def modifierRanking = [
public : 1, public : 1,
protected : 2, protected : 2,
private : 3, private : 3,
@@ -248,20 +259,20 @@ spotless {
synchronized: 10, synchronized: 10,
native : 11, native : 11,
strictfp : 12] strictfp : 12]
// Find any instance of multiple modifiers. Lead with a non-word character to avoid // Find any instance of multiple modifiers. Lead with a non-word character to avoid
// accidental matching against for instance, "an alternative default value" // accidental matching against for instance, "an alternative default value"
it.replaceAll(/\W(?:public |protected |private |abstract |default |static |final |transient |volatile |synchronized |native |strictfp ){2,}/, { it.replaceAll(/\W(?:public |protected |private |abstract |default |static |final |transient |volatile |synchronized |native |strictfp ){2,}/, {
// Do not replace the leading non-word character. Identify the modifiers // Do not replace the leading non-word character. Identify the modifiers
it.replaceAll(/(?:public |protected |private |abstract |default |static |final |transient |volatile |synchronized |native |strictfp ){2,}/, { it.replaceAll(/(?:public |protected |private |abstract |default |static |final |transient |volatile |synchronized |native |strictfp ){2,}/, {
// Sort the modifiers according to the ranking above // Sort the modifiers according to the ranking above
it.split().sort({ modifierRanking[it] }).join(' ') + ' ' it.split().sort({ modifierRanking[it] }).join(' ') + ' '
} }
) )
}
)
} }
)
}
} }
lineEndings 'UNIX' lineEndings 'UNIX'
} }
@@ -309,7 +320,6 @@ rat {
'**/native/**', '**/native/**',
'**/wrapper/**', '**/wrapper/**',
'**/build/**', '**/build/**',
//Api Docs //Api Docs
'**/api-docs/*.*', '**/api-docs/*.*',
'**/docs/system-architecture/.htaccess', '**/docs/system-architecture/.htaccess',
@@ -318,14 +328,11 @@ rat {
'**/docs/system-architecture/**/*.xml', '**/docs/system-architecture/**/*.xml',
'**/bootstrap-3.0.0/assets/application.js', '**/bootstrap-3.0.0/assets/application.js',
'**/system-architecture/js/plugins.js', '**/system-architecture/js/plugins.js',
//Apache License //Apache License
'**/bootstrap-3.0.0/assets/less.js', '**/bootstrap-3.0.0/assets/less.js',
'**/css/bootstrap-3.0.0/**/*.*', '**/css/bootstrap-3.0.0/**/*.*',
//Public Domain See http://www.JSON.org/js.html //Public Domain See http://www.JSON.org/js.html
'**/bootstrap-3.0.0/assets/json2.js.htm', '**/bootstrap-3.0.0/assets/json2.js.htm',
// MIT License // MIT License
'**/modernizr-2.6.2.min.js', '**/modernizr-2.6.2.min.js',
'**/css/normalize.css', '**/css/normalize.css',
@@ -340,12 +347,10 @@ rat {
'**/system-architecture/js/vendor/toc-0.1.2/jquery.toc.min.js', '**/system-architecture/js/vendor/toc-0.1.2/jquery.toc.min.js',
'**/assets/respond.min.js', '**/assets/respond.min.js',
'**/assets/html5shiv.js', '**/assets/html5shiv.js',
//BSD License //BSD License
'**/assets/uglify.js', '**/assets/uglify.js',
//Ignore out folder //Ignore out folder
'**/out/**', '**/out/**',
// Git build info // Git build info
"**/git.properties", "**/git.properties",
] ]
@@ -374,13 +379,34 @@ configurations {
} }
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {
options.compilerArgs += ["-Xlint:unchecked","-Xlint:cast","-Xlint:auxiliaryclass","-Xlint:deprecation", options.compilerArgs += [
"-Xlint:dep-ann","-Xlint:divzero","-Xlint:empty","-Xlint:exports","-Xlint:fallthrough", "-Xlint:unchecked",
"-Xlint:finally","-Xlint:module","-Xlint:opens","-Xlint:options","-Xlint:overloads", "-Xlint:cast",
"-Xlint:overrides","-Xlint:path","-Xlint:processing","-Xlint:removal", "-Xlint:auxiliaryclass",
"-Xlint:requires-automatic","-Xlint:requires-transitive-automatic","-Xlint:try", "-Xlint:deprecation",
"-Xlint:varargs","-Xlint:preview","-Xlint:static","-Werror"] "-Xlint:dep-ann",
// TODO FINERACT-959 (gradually) enable -Xlint:all (see "javac -help -X") "-Xlint:divzero",
"-Xlint:empty",
"-Xlint:exports",
"-Xlint:fallthrough",
"-Xlint:finally",
"-Xlint:module",
"-Xlint:opens",
"-Xlint:options",
"-Xlint:overloads",
"-Xlint:overrides",
"-Xlint:path",
"-Xlint:processing",
"-Xlint:removal",
"-Xlint:requires-automatic",
"-Xlint:requires-transitive-automatic",
"-Xlint:try",
"-Xlint:varargs",
"-Xlint:preview",
"-Xlint:static",
"-Werror"
]
// TODO FINERACT-959 (gradually) enable -Xlint:all (see "javac -help -X")
options.deprecation = true options.deprecation = true
options.errorprone { options.errorprone {
@@ -396,7 +422,7 @@ tasks.withType(JavaCompile) {
"ReturnFromVoid", "ReturnFromVoid",
"AlmostJavadoc", "AlmostJavadoc",
"InvalidBlockTag", "InvalidBlockTag",
) )
//TODO gradually enable these checks //TODO gradually enable these checks
error( error(
"DefaultCharset", "DefaultCharset",
@@ -468,28 +494,33 @@ tasks.withType(JavaCompile) {
"ModifiedButNotUsed", "ModifiedButNotUsed",
"InconsistentCapitalization", "InconsistentCapitalization",
"MissingOverride", "MissingOverride",
// "InvalidBlockTag", // "InvalidBlockTag",
// "InconsistentOverloads", // "InconsistentOverloads",
// "MethodCanBeStatic", // "MethodCanBeStatic",
// "Var", // "Var",
// "ConstantField", // "ConstantField",
// "UnnecessaryDefaultInEnumSwitch", // "UnnecessaryDefaultInEnumSwitch",
// "FieldCanBeFinal" // "FieldCanBeFinal"
) )
} }
options.compilerArgs +=["-Xmaxwarns",1500,"-Xmaxerrs",1500] options.compilerArgs +=[
"-Xmaxwarns",
1500,
"-Xmaxerrs",
1500
]
} }
apply from: 'dependencies.gradle' apply from: 'dependencies.gradle'
/* TODO https://issues.apache.org/jira/browse/FINERACT-939 (dev-dependencies.gradle has been removed, as totally broken) /* TODO https://issues.apache.org/jira/browse/FINERACT-939 (dev-dependencies.gradle has been removed, as totally broken)
// Pick up dependencies based on the environment, defaults to production // Pick up dependencies based on the environment, defaults to production
if (project.hasProperty('env') && project.getProperty('env') == 'dev') { if (project.hasProperty('env') && project.getProperty('env') == 'dev') {
apply from: 'dev-dependencies.gradle' apply from: 'dev-dependencies.gradle'
} else { } else {
apply from: 'dependencies.gradle' apply from: 'dependencies.gradle'
} }
*/ */
/* Enable Oauth2 authentication based on environment, default to HTTP basic auth */ /* Enable Oauth2 authentication based on environment, default to HTTP basic auth */
if (project.hasProperty('security') && project.getProperty('security') == 'oauth') { if (project.hasProperty('security') && project.getProperty('security') == 'oauth') {
@@ -539,7 +570,7 @@ modernizer {
exclusions = [] exclusions = []
exclusionPatterns = [ exclusionPatterns = [
// To be removed when https://issues.apache.org/jira/browse/FINERACT-826 is fixed // To be removed when https://issues.apache.org/jira/browse/FINERACT-826 is fixed
'org/joda/time/.*' 'org/joda/time/.*'
] ]
} }
@@ -550,25 +581,29 @@ compileJava{
finalizedBy resolve finalizedBy resolve
} }
/* /*
pmd { pmd {
sourceSets = [sourceSets.main] sourceSets = [sourceSets.main]
} }
*/ */
war { war {
from('../licenses/binary/') { // notice the parens from('../licenses/binary/') {
// notice the parens
into "WEB-INF/licenses/binary/" // no leading slash into "WEB-INF/licenses/binary/" // no leading slash
} }
from('../LICENSE_RELEASE') { // notice the parens from('../LICENSE_RELEASE') {
// notice the parens
into "WEB-INF/" // no leading slash into "WEB-INF/" // no leading slash
} }
from('../NOTICE_RELEASE') { // notice the parens from('../NOTICE_RELEASE') {
// notice the parens
into "WEB-INF/" // no leading slash into "WEB-INF/" // no leading slash
} }
rename ('LICENSE_RELEASE', 'LICENSE') rename ('LICENSE_RELEASE', 'LICENSE')
rename ('NOTICE_RELEASE', 'NOTICE') rename ('NOTICE_RELEASE', 'NOTICE')
from('../DISCLAIMER') { // notice the parens from('../DISCLAIMER') {
// notice the parens
into "WEB-INF/" // no leading slash into "WEB-INF/" // no leading slash
} }
war.finalizedBy(bootWar) war.finalizedBy(bootWar)
@@ -589,42 +624,46 @@ license {
} }
task licenseFormatBuildScripts (type:nl.javadude.gradle.plugins.license.License) { task licenseFormatBuildScripts (type:nl.javadude.gradle.plugins.license.License) {
source = fileTree(dir: '../', includes: ['**/*.bat', '**/*.sh', '**/*.sql']) source = fileTree(dir: '../', includes: [
'**/*.bat',
'**/*.sh',
'**/*.sql'
])
} }
licenseFormat.dependsOn licenseFormatBuildScripts licenseFormat.dependsOn licenseFormatBuildScripts
configurations configurations
{ {
tomcat tomcat
} }
dependencies { dependencies {
tomcat "org.apache.tomcat:tomcat:9.0.36@zip" tomcat "org.apache.tomcat:tomcat:9.0.36@zip"
} }
dependencies { dependencies {
errorprone "com.google.errorprone:error_prone_core:2.4.0" errorprone "com.google.errorprone:error_prone_core:2.4.0"
} }
cargo { cargo {
containerId "tomcat9x" containerId "tomcat9x"
local { local {
installer { installer {
installConfiguration = configurations.tomcat installConfiguration = configurations.tomcat
downloadDir = file("$buildDir/download") downloadDir = file("$buildDir/download")
extractDir = file("$buildDir/tomcat") extractDir = file("$buildDir/tomcat")
}
startStopTimeout = 240000
containerProperties {
property 'cargo.tomcat.connector.keystoreFile', file('src/main/resources/keystore.jks')
property 'cargo.tomcat.connector.keystorePass', 'openmf'
property 'cargo.tomcat.httpSecure', true
property 'cargo.tomcat.connector.sslProtocol', 'TLS'
property 'cargo.tomcat.connector.clientAuth', false
property 'cargo.protocol', 'https'
property 'cargo.servlet.port', 8443
}
} }
startStopTimeout = 240000
containerProperties {
property 'cargo.tomcat.connector.keystoreFile', file('src/main/resources/keystore.jks')
property 'cargo.tomcat.connector.keystorePass', 'openmf'
property 'cargo.tomcat.httpSecure', true
property 'cargo.tomcat.connector.sslProtocol', 'TLS'
property 'cargo.tomcat.connector.clientAuth', false
property 'cargo.protocol', 'https'
property 'cargo.servlet.port', 8443
}
}
} }
cargoRunLocal.dependsOn bootWar cargoRunLocal.dependsOn bootWar
@@ -655,7 +694,7 @@ if (!(project.hasProperty('env') && project.getProperty('env') == 'dev')) {
} }
sourceSets { sourceSets {
integrationTest { integrationTest {
compileClasspath += main.output + test.output compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output runtimeClasspath += main.output + test.output
} }
@@ -677,7 +716,8 @@ task integrationTest(type:Test) {
integrationTest { integrationTest {
useJUnitPlatform() useJUnitPlatform()
testLogging { // FINERACT-927 testLogging {
// FINERACT-927
events "skipped", "failed" events "skipped", "failed"
showStandardStreams = false showStandardStreams = false
exceptionFormat "full" exceptionFormat "full"
@@ -685,7 +725,8 @@ integrationTest {
} }
test { test {
useJUnitPlatform() useJUnitPlatform()
testLogging { // FINERACT-927 testLogging {
// FINERACT-927
events "skipped", "failed" events "skipped", "failed"
showStandardStreams = false showStandardStreams = false
exceptionFormat "full" exceptionFormat "full"
+9 -9
View File
@@ -71,16 +71,16 @@ dependencies {
'com.github.spullara.mustache.java:compiler', 'com.github.spullara.mustache.java:compiler',
'com.jayway.jsonpath:json-path', 'com.jayway.jsonpath:json-path',
// JAX-B dependencies for JDK 9+ // JAX-B dependencies for JDK 9+
'jakarta.xml.bind:jakarta.xml.bind-api', 'jakarta.xml.bind:jakarta.xml.bind-api',
'org.dom4j:dom4j', 'org.dom4j:dom4j',
'javax.cache:cache-api', 'javax.cache:cache-api',
'com.github.spotbugs:spotbugs-annotations', 'com.github.spotbugs:spotbugs-annotations',
'io.swagger.core.v3:swagger-annotations' 'io.swagger.core.v3:swagger-annotations'
) )
implementation ('org.apache.activemq:activemq-broker') { implementation ('org.apache.activemq:activemq-broker') {
exclude group: 'org.apache.geronimo.specs' exclude group: 'org.apache.geronimo.specs'
} }
@@ -114,7 +114,7 @@ dependencies {
// Although fineract (at the time of writing) doesn't have any compile time dep. on httpclient, // Although fineract (at the time of writing) doesn't have any compile time dep. on httpclient,
// it's useful to have this for the Spring Boot TestRestTemplate http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-rest-templates-test-utility // it's useful to have this for the Spring Boot TestRestTemplate http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-rest-templates-test-utility
'org.apache.httpcomponents:httpclient', 'org.apache.httpcomponents:httpclient',
) )
// testCompile dependencies are ONLY used in src/test and/or src/integrationTest, not src/main. // testCompile dependencies are ONLY used in src/test and/or src/integrationTest, not src/main.
// Do NOT repeat dependencies which are ALREADY in implementation or runtimeOnly! // Do NOT repeat dependencies which are ALREADY in implementation or runtimeOnly!
@@ -124,7 +124,7 @@ dependencies {
'org.junit.platform:junit-platform-runner', // required to be able to run tests directly under Eclipse, see FINERACT-943 & FINERACT-1021 'org.junit.platform:junit-platform-runner', // required to be able to run tests directly under Eclipse, see FINERACT-943 & FINERACT-1021
'io.github.classgraph:classgraph', 'io.github.classgraph:classgraph',
'org.awaitility:awaitility' 'org.awaitility:awaitility'
) )
testImplementation('org.mock-server:mockserver-junit-jupiter') { testImplementation('org.mock-server:mockserver-junit-jupiter') {
exclude group: 'com.sun.mail', module: 'mailapi' exclude group: 'com.sun.mail', module: 'mailapi'
exclude group: 'javax.servlet', module: 'javax.servlet-api' exclude group: 'javax.servlet', module: 'javax.servlet-api'