You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by cp...@apache.org on 2021/06/04 09:12:27 UTC
[solr] branch main updated: SOLR-14920: add spotless and gjf
(automatic code formatter) plumbing (#126)
This is an automated email from the ASF dual-hosted git repository.
cpoerschke pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new a9a8d20 SOLR-14920: add spotless and gjf (automatic code formatter) plumbing (#126)
a9a8d20 is described below
commit a9a8d2023de00474277c6edbaff75d8bd12f33e8
Author: Christine Poerschke <cp...@apache.org>
AuthorDate: Fri Jun 4 10:12:21 2021 +0100
SOLR-14920: add spotless and gjf (automatic code formatter) plumbing (#126)
---
build.gradle | 2 +
gradle/validation/spotless.gradle | 90 +++++++++++++++++++++++++++++++
gradle/validation/spotless/asl-header.txt | 16 ++++++
3 files changed, 108 insertions(+)
diff --git a/build.gradle b/build.gradle
index e1e18b3..dc99edf 100644
--- a/build.gradle
+++ b/build.gradle
@@ -149,6 +149,8 @@ apply from: file('gradle/validation/check-broken-links.gradle')
apply from: file('gradle/validation/solr.config-file-sanity.gradle')
+apply from: file('gradle/validation/spotless.gradle')
+
// Source or data regeneration tasks
apply from: file('gradle/generation/javacc.gradle')
diff --git a/gradle/validation/spotless.gradle b/gradle/validation/spotless.gradle
new file mode 100644
index 0000000..cda4ba6
--- /dev/null
+++ b/gradle/validation/spotless.gradle
@@ -0,0 +1,90 @@
+/*
+ * 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.
+ */
+
+/*
+ * SOLR-14920 modelled on LUCENE-9564: This adds automatic (and enforced) code formatting using
+ * spotless and Google Java Format.
+ */
+
+def resources = scriptResources(buildscript)
+
+configure(project(":solr").subprojects) { prj ->
+ plugins.withType(JavaPlugin) {
+ prj.apply plugin: 'com.diffplug.spotless'
+
+ spotless {
+ java {
+ toggleOffOn() // obviously, only to be used sparingly.
+ // 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.
+ //
+ // licenseHeaderFile file("${resources}/asl-header.txt"), '^(\\s*package)'
+
+ lineEndings 'UNIX'
+ endWithNewline()
+ googleJavaFormat('1.9')
+
+ // Apply to all Java sources
+ target "src/**/*.java"
+
+ // Exclude certain files (generated ones, mostly).
+ switch (project.path) {
+ case ":solr:contrib:analytics":
+ case ":solr:contrib:analysis-extras":
+ case ":solr:contrib:clustering":
+ case ":solr:contrib:extraction":
+ case ":solr:contrib:gcs-repository":
+ case ":solr:contrib:jaegertracer-configurator":
+ case ":solr:contrib:langid":
+ case ":solr:contrib:ltr":
+ case ":solr:contrib:prometheus-exporter":
+ case ":solr:contrib:scripting":
+ case ":solr:core":
+ case ":solr:solrj":
+ case ":solr:solr-ref-guide":
+ case ":solr:test-framework":
+ targetExclude "src/**/*.java"
+ break
+ }
+ }
+ }
+
+ // Workaround for an odd problem in spotless where it fails because
+ // of a missing folder.
+ spotlessJava {
+ doFirst {
+ project.mkdir("${buildDir}/spotless/spotlessJava")
+ }
+ }
+ }
+
+ // Add an alias to 'spotlessApply' simply called 'tidy' and wire up
+ // spotlessCheck to convention's check.
+ 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
+ }
+}
diff --git a/gradle/validation/spotless/asl-header.txt b/gradle/validation/spotless/asl-header.txt
new file mode 100644
index 0000000..2944f98
--- /dev/null
+++ b/gradle/validation/spotless/asl-header.txt
@@ -0,0 +1,16 @@
+/*
+ * 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.
+ */