|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import org.elasticsearch.gradle.BuildPlugin |
| 21 | + |
| 22 | +/* |
| 23 | + * This script plugin configures formatting for Java source using Spotless |
| 24 | + * for Gradle. Since the act of formatting existing source can interfere |
| 25 | + * with developers' workflows, we don't automatically format all code |
| 26 | + * (yet). Instead, we maintain a list of projects that are excluded from |
| 27 | + * formatting, until we reach a point where we can comfortably format them |
| 28 | + * in one go without too much disruption. |
| 29 | + * |
| 30 | + * Any new sub-projects must not be added to the exclusions list! |
| 31 | + * |
| 32 | + * To perform a reformat, run: |
| 33 | + * |
| 34 | + * ./gradlew spotlessApply |
| 35 | + * |
| 36 | + * To check the current format, run: |
| 37 | + * |
| 38 | + * ./gradlew spotlessJavaCheck |
| 39 | + * |
| 40 | + * This is also carried out by the `precommit` task. |
| 41 | + * |
| 42 | + * For more about Spotless, see: |
| 43 | + * |
| 44 | + * https://github.com/diffplug/spotless/tree/master/plugin-gradle |
| 45 | + */ |
| 46 | + |
| 47 | +// Do not add new sub-projects here! |
| 48 | +def projectPathsToExclude = [ |
| 49 | + ':client:benchmark', |
| 50 | + ':client:client-benchmark-noop-api-plugin', |
| 51 | + ':client:rest', |
| 52 | + ':client:rest-high-level', |
| 53 | + ':client:sniffer', |
| 54 | + ':client:test', |
| 55 | + ':client:transport', |
| 56 | + ':example-plugins:custom-settings', |
| 57 | + ':example-plugins:custom-significance-heuristic', |
| 58 | + ':example-plugins:custom-suggester', |
| 59 | + ':example-plugins:painless-whitelist', |
| 60 | + ':example-plugins:rescore', |
| 61 | + ':example-plugins:rest-handler', |
| 62 | + ':example-plugins:script-expert-scoring', |
| 63 | + ':example-plugins:security-authorization-engine', |
| 64 | + ':libs:elasticsearch-cli', |
| 65 | + ':libs:elasticsearch-core', |
| 66 | + ':libs:elasticsearch-dissect', |
| 67 | + ':libs:elasticsearch-geo', |
| 68 | + ':libs:elasticsearch-grok', |
| 69 | + ':libs:elasticsearch-nio', |
| 70 | + ':libs:elasticsearch-plugin-classloader', |
| 71 | + ':libs:elasticsearch-secure-sm', |
| 72 | + ':libs:elasticsearch-ssl-config', |
| 73 | + ':libs:elasticsearch-x-content', |
| 74 | + ':modules:aggs-matrix-stats', |
| 75 | + ':modules:analysis-common', |
| 76 | + ':modules:ingest-common', |
| 77 | + ':modules:ingest-geoip', |
| 78 | + ':modules:ingest-user-agent', |
| 79 | + ':modules:lang-expression', |
| 80 | + ':modules:lang-mustache', |
| 81 | + ':modules:lang-painless', |
| 82 | + ':modules:lang-painless:spi', |
| 83 | + ':modules:mapper-extras', |
| 84 | + ':modules:parent-join', |
| 85 | + ':modules:percolator', |
| 86 | + ':modules:rank-eval', |
| 87 | + ':modules:reindex', |
| 88 | + ':modules:repository-url', |
| 89 | + ':modules:systemd', |
| 90 | + ':modules:tasks', |
| 91 | + ':modules:transport-netty4', |
| 92 | + ':plugins:analysis-icu', |
| 93 | + ':plugins:analysis-kuromoji', |
| 94 | + ':plugins:analysis-nori', |
| 95 | + ':plugins:analysis-phonetic', |
| 96 | + ':plugins:analysis-smartcn', |
| 97 | + ':plugins:analysis-stempel', |
| 98 | + ':plugins:analysis-ukrainian', |
| 99 | + ':plugins:discovery-azure-classic', |
| 100 | + ':plugins:discovery-ec2', |
| 101 | + ':plugins:discovery-gce', |
| 102 | + ':plugins:ingest-attachment', |
| 103 | + ':plugins:mapper-annotated-text', |
| 104 | + ':plugins:mapper-murmur3', |
| 105 | + ':plugins:mapper-size', |
| 106 | + ':plugins:repository-azure', |
| 107 | + ':plugins:repository-gcs', |
| 108 | + ':plugins:repository-hdfs', |
| 109 | + ':plugins:repository-s3', |
| 110 | + ':plugins:store-smb', |
| 111 | + ':plugins:transport-nio', |
| 112 | + ':qa:die-with-dignity', |
| 113 | + ':rest-api-spec', |
| 114 | + ':server', |
| 115 | + ':test:fixtures:azure-fixture', |
| 116 | + ':test:fixtures:gcs-fixture', |
| 117 | + ':test:fixtures:hdfs-fixture', |
| 118 | + ':test:fixtures:krb5kdc-fixture', |
| 119 | + ':test:fixtures:minio-fixture', |
| 120 | + ':test:fixtures:old-elasticsearch', |
| 121 | + ':test:fixtures:s3-fixture', |
| 122 | + ':test:framework', |
| 123 | + ':test:logger-usage', |
| 124 | + ':x-pack:license-tools', |
| 125 | + ':x-pack:plugin:analytics', |
| 126 | + ':x-pack:plugin:async-search', |
| 127 | + ':x-pack:plugin:async-search:qa', |
| 128 | + ':x-pack:plugin:ccr', |
| 129 | + ':x-pack:plugin:ccr:qa', |
| 130 | + ':x-pack:plugin:core', |
| 131 | + ':x-pack:plugin:deprecation', |
| 132 | + ':x-pack:plugin:eql', |
| 133 | + ':x-pack:plugin:eql:qa', |
| 134 | + ':x-pack:plugin:eql:qa:common', |
| 135 | + ':x-pack:plugin:frozen-indices', |
| 136 | + ':x-pack:plugin:graph', |
| 137 | + ':x-pack:plugin:identity-provider', |
| 138 | + ':x-pack:plugin:ilm', |
| 139 | + ':x-pack:plugin:mapper-constant-keyword', |
| 140 | + ':x-pack:plugin:mapper-flattened', |
| 141 | + ':x-pack:plugin:ml', |
| 142 | + ':x-pack:plugin:monitoring', |
| 143 | + ':x-pack:plugin:ql', |
| 144 | + ':x-pack:plugin:rollup', |
| 145 | + ':x-pack:plugin:search-business-rules', |
| 146 | + ':x-pack:plugin:security', |
| 147 | + ':x-pack:plugin:security:cli', |
| 148 | + ':x-pack:plugin:spatial', |
| 149 | + ':x-pack:plugin:sql', |
| 150 | + ':x-pack:plugin:sql:jdbc', |
| 151 | + ':x-pack:plugin:sql:qa', |
| 152 | + ':x-pack:plugin:sql:qa:security', |
| 153 | + ':x-pack:plugin:sql:sql-action', |
| 154 | + ':x-pack:plugin:sql:sql-cli', |
| 155 | + ':x-pack:plugin:sql:sql-client', |
| 156 | + ':x-pack:plugin:sql:sql-proto', |
| 157 | + ':x-pack:plugin:transform', |
| 158 | + ':x-pack:plugin:vectors', |
| 159 | + ':x-pack:plugin:voting-only-node', |
| 160 | + ':x-pack:plugin:watcher', |
| 161 | + ':x-pack:plugin:wildcard', |
| 162 | + ':x-pack:qa', |
| 163 | + ':x-pack:qa:security-example-spi-extension', |
| 164 | + ':x-pack:snapshot-tool', |
| 165 | + ':x-pack:snapshot-tool:qa:google-cloud-storage', |
| 166 | + ':x-pack:snapshot-tool:qa:s3', |
| 167 | + ':x-pack:test:feature-aware', |
| 168 | + ':x-pack:test:idp-fixture', |
| 169 | + ':x-pack:test:smb-fixture', |
| 170 | + ':x-pack:transport-client' |
| 171 | +] |
| 172 | + |
| 173 | +subprojects { |
| 174 | + plugins.withType(BuildPlugin).whenPluginAdded { |
| 175 | + if (projectPathsToExclude.contains(project.path) == false) { |
| 176 | + project.apply plugin: "com.diffplug.gradle.spotless" |
| 177 | + |
| 178 | + spotless { |
| 179 | + java { |
| 180 | + // Normally this isn't necessary, but we have Java sources in |
| 181 | + // non-standard places |
| 182 | + target '**/*.java' |
| 183 | + |
| 184 | + removeUnusedImports() |
| 185 | + eclipse().configFile rootProject.file('buildSrc/formatterConfig.xml') |
| 186 | + trimTrailingWhitespace() |
| 187 | + |
| 188 | + // See CONTRIBUTING.md for details of when to enabled this. |
| 189 | + if (System.getProperty('spotless.paddedcell') != null) { |
| 190 | + paddedCell() |
| 191 | + } |
| 192 | + } |
| 193 | + } |
| 194 | + |
| 195 | + precommit.dependsOn 'spotlessJavaCheck' |
| 196 | + } |
| 197 | + } |
| 198 | +} |
0 commit comments