lucene/gradle/validation/spotless.gradle

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

142 lines
4.4 KiB
Groovy
Raw Normal View History

/*
* 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.
*/
def resources = scriptResources(buildscript)
allprojects { prj ->
plugins.withType(JavaPlugin) {
prj.apply plugin: 'com.diffplug.spotless'
spotless {
java {
// TODO: work out how to have multiple different header files (we have
// classes in the codebase that have original headers).
// licenseHeaderFile file("${resources}/asl-header.txt"), '^(\\s*package)'
lineEndings 'UNIX'
endWithNewline()
googleJavaFormat('1.9')
switch (project.path) {
// These modules are complete - all sources scanned.
case ":lucene:core":
target "src/java/**/*.java",
"src/test/**/*.java"
targetExclude "**/resources/**", "**/StandardTokenizerImpl.java"
break
case ":lucene:highlighter":
target "src/java/**/*.java",
"src/test/**/*.java"
targetExclude "**/resources/**"
break
case ":lucene:queries":
target "src/java/**/*.java",
"src/test/**/*.java"
targetExclude "**/resources/**"
break
case ":lucene:analysis:common":
target "src/**/*.java"
targetExclude "**/resources/**",
"**/HTMLStripCharFilter.java",
"**/UAX29URLEmailTokenizerImpl.java",
"**/tartarus/**"
break
case ":lucene:demo":
case ":lucene:analysis:morfologik":
case ":lucene:analysis:icu":
case ":lucene:analysis:kuromoji":
case ":lucene:memory":
case ":lucene:benchmark":
case ":lucene:analysis:nori":
case ":lucene:analysis:opennlp":
case ":lucene:analysis:phonetic":
case ":lucene:analysis:smartcn":
case ":lucene:analysis:stempel":
case ":lucene:classification":
case ":lucene:backward-codecs":
case ":lucene:codecs":
case ":lucene:join":
target "src/**/*.java"
targetExclude "**/resources/**"
break
case ":lucene:expressions":
target "src/**/*.java"
targetExclude "**/resources/**", "**/JavascriptLexer.java", "**/JavascriptParser.java",
"**/JavascriptVisitor.java"
break
// Partially complete.
case ":lucene:facet":
target "src/**/*.java"
targetExclude "**/taxonomy.8.6.3-cfs.zip"
break
// All others - disable reformatting/ checks for now.
case ":lucene:grouping":
case ":lucene:luke":
case ":lucene:misc":
case ":lucene:monitor":
case ":lucene:queryparser":
case ":lucene:replicator":
case ":lucene:sandbox":
case ":lucene:spatial3d":
case ":lucene:spatial-extras":
case ":lucene:suggest":
case ":lucene:test-framework":
default:
target 'non-existing/**'
break
}
}
}
spotlessJava {
doFirst {
project.mkdir("${buildDir}/spotless/spotlessJava")
}
}
}
}
// Add an alias to 'spotlessApply' simply called 'tidy' and add
// spotlessCheck to check.
allprojects { prj ->
task tidy() {
description "Applies formatters and cleanups to sources."
group "verification"
}
tasks.matching { task -> task.name == "spotlessApply" }.configureEach { v ->
tidy.dependsOn v
}
tasks.matching { task -> task.name == "spotlessCheck" }.configureEach { v ->
check.dependsOn v
}
}