2020-12-17 07:11:54 -05:00
|
|
|
/*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership.
|
|
|
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
* (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LUCENE-9564: This adds automatic (and enforced) code formatting using
|
|
|
|
* spotless and Google Java Format.
|
|
|
|
*/
|
|
|
|
|
2024-06-17 03:49:21 -04:00
|
|
|
// def resources = scriptResources(buildscript)
|
2020-12-17 07:11:54 -05:00
|
|
|
|
2024-06-17 03:49:21 -04:00
|
|
|
configure(allprojects) { prj ->
|
2020-12-17 07:11:54 -05:00
|
|
|
plugins.withType(JavaPlugin) {
|
|
|
|
prj.apply plugin: 'com.diffplug.spotless'
|
|
|
|
|
|
|
|
spotless {
|
|
|
|
java {
|
|
|
|
// TODO: Work out how to support multiple different header files (we have
|
|
|
|
// classes in the codebase that have original headers). We currently use
|
|
|
|
// Apache RAT to enforce headers so this is of lesser priority.
|
2021-01-05 07:44:05 -05:00
|
|
|
//
|
2020-12-17 07:11:54 -05:00
|
|
|
// licenseHeaderFile file("${resources}/asl-header.txt"), '^(\\s*package)'
|
2020-12-28 06:26:13 -05:00
|
|
|
|
2020-12-17 07:11:54 -05:00
|
|
|
lineEndings 'UNIX'
|
|
|
|
endWithNewline()
|
2024-06-17 03:49:21 -04:00
|
|
|
googleJavaFormat(deps.versions.googleJavaFormat.get())
|
2020-12-17 07:11:54 -05:00
|
|
|
|
|
|
|
// Apply to all Java sources
|
|
|
|
target "src/**/*.java"
|
2021-01-05 07:44:05 -05:00
|
|
|
|
2020-12-17 07:11:54 -05:00
|
|
|
// Exclude certain files (generated ones, mostly).
|
|
|
|
switch (project.path) {
|
|
|
|
case ":lucene:core":
|
|
|
|
targetExclude "**/StandardTokenizerImpl.java"
|
2020-12-18 07:02:08 -05:00
|
|
|
break
|
|
|
|
|
2020-12-17 07:11:54 -05:00
|
|
|
case ":lucene:analysis:common":
|
|
|
|
targetExclude "**/HTMLStripCharFilter.java",
|
2021-04-13 02:59:31 -04:00
|
|
|
"**/UAX29URLEmailTokenizerImpl.java"
|
2020-12-18 07:02:08 -05:00
|
|
|
break
|
|
|
|
|
2020-12-17 07:11:54 -05:00
|
|
|
case ":lucene:test-framework":
|
|
|
|
targetExclude "**/EmojiTokenizationTestUnicode_11_0.java",
|
|
|
|
"**/WordBreakTestUnicode_9_0_0.java"
|
2021-01-03 15:46:01 -05:00
|
|
|
break
|
|
|
|
|
2020-12-17 07:11:54 -05:00
|
|
|
case ":lucene:expressions":
|
2021-01-03 15:46:01 -05:00
|
|
|
break
|
|
|
|
|
2020-12-17 07:11:54 -05:00
|
|
|
case ":lucene:queryparser":
|
|
|
|
targetExclude "**/classic/ParseException.java",
|
|
|
|
"**/classic/QueryParser.java",
|
|
|
|
"**/classic/QueryParserConstants.java",
|
|
|
|
"**/classic/QueryParserTokenManager.java",
|
|
|
|
"**/classic/Token.java",
|
|
|
|
"**/classic/TokenMgrError.java",
|
|
|
|
"**/standard/parser/ParseException.java",
|
|
|
|
"**/standard/parser/StandardSyntaxParser.java",
|
|
|
|
"**/standard/parser/StandardSyntaxParserConstants.java",
|
|
|
|
"**/standard/parser/StandardSyntaxParserTokenManager.java",
|
|
|
|
"**/standard/parser/Token.java",
|
|
|
|
"**/standard/parser/TokenMgrError.java",
|
|
|
|
"**/surround/parser/ParseException.java",
|
|
|
|
"**/surround/parser/QueryParser.java",
|
|
|
|
"**/surround/parser/QueryParserConstants.java",
|
|
|
|
"**/surround/parser/QueryParserTokenManager.java",
|
|
|
|
"**/surround/parser/Token.java",
|
|
|
|
"**/surround/parser/TokenMgrError.java"
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-03 15:46:01 -05:00
|
|
|
|
2020-12-17 07:11:54 -05:00
|
|
|
// Workaround for an odd problem in spotless where it fails because
|
|
|
|
// of a missing folder.
|
|
|
|
spotlessJava {
|
2021-01-03 15:46:01 -05:00
|
|
|
doFirst {
|
2020-12-17 07:11:54 -05:00
|
|
|
project.mkdir("${buildDir}/spotless/spotlessJava")
|
2021-01-03 15:46:01 -05:00
|
|
|
}
|
|
|
|
}
|
2022-12-13 02:42:04 -05:00
|
|
|
|
|
|
|
// Schedule the core formatting task to run after Java compilation (GH-12012)
|
|
|
|
spotlessJava {
|
|
|
|
mustRunAfter tasks.withType(JavaCompile)
|
|
|
|
}
|
2020-12-17 07:11:54 -05:00
|
|
|
}
|
|
|
|
|
2022-04-25 08:51:14 -04:00
|
|
|
// Emit a custom message about how to fix formatting errors.
|
|
|
|
tasks.matching { task -> task.name == "spotlessJavaCheck" }.configureEach {
|
2024-06-17 03:49:21 -04:00
|
|
|
it.runToFixMessage.set("\nIMPORTANT: run the top-level './gradlew tidy' to format code automatically (see help/formatting.txt for more info).")
|
2022-04-25 08:51:14 -04:00
|
|
|
}
|
|
|
|
|
2024-06-17 03:49:21 -04:00
|
|
|
// Hook up spotless to tidy and check tasks.
|
|
|
|
tasks.matching { it.name == "tidy" }.configureEach { v ->
|
|
|
|
v.dependsOn tasks.matching { it.name == "spotlessApply" }
|
2020-12-17 07:11:54 -05:00
|
|
|
}
|
|
|
|
|
2024-06-17 03:49:21 -04:00
|
|
|
tasks.matching { it.name == "check" }.configureEach { v ->
|
|
|
|
v.dependsOn tasks.matching { it.name == "spotlessCheck" }
|
2020-12-17 07:11:54 -05:00
|
|
|
}
|
|
|
|
|
2024-06-17 03:49:21 -04:00
|
|
|
tasks.matching { task -> task.name in ["spotlessApply", "spotlessCheck"] }.configureEach { v ->
|
2022-04-10 14:35:45 -04:00
|
|
|
v.dependsOn ":checkJdkInternalsExportedToGradle"
|
2020-12-17 07:11:54 -05:00
|
|
|
}
|
|
|
|
}
|