|
30 | 30 |
|
31 | 31 | import org.opensearch.gradle.BuildPlugin |
32 | 32 |
|
33 | | -/* |
34 | | - * This script plugin configures formatting for Java source using Spotless |
35 | | - * for Gradle. Since the act of formatting existing source can interfere |
36 | | - * with developers' workflows, we don't automatically format all code |
37 | | - * (yet). Instead, we maintain a list of projects that are excluded from |
38 | | - * formatting, until we reach a point where we can comfortably format them |
39 | | - * in one go without too much disruption. |
40 | | - * |
41 | | - * Any new sub-projects must not be added to the exclusions list! |
42 | | - * |
43 | | - * To perform a reformat, run: |
44 | | - * |
45 | | - * ./gradlew spotlessApply |
46 | | - * |
47 | | - * To check the current format, run: |
48 | | - * |
49 | | - * ./gradlew spotlessJavaCheck |
50 | | - * |
51 | | - * This is also carried out by the `precommit` task. |
52 | | - * |
53 | | - * For more about Spotless, see: |
54 | | - * |
55 | | - * https://github.com/diffplug/spotless/tree/master/plugin-gradle |
56 | | - */ |
| 33 | +import static java.lang.System.getenv |
57 | 34 |
|
58 | 35 | allprojects { |
59 | 36 | plugins.withType(BuildPlugin).whenPluginAdded { |
60 | | - project.apply plugin: "com.diffplug.spotless" |
61 | | - |
62 | | - spotless { |
63 | | - java { |
64 | | - // Normally this isn't necessary, but we have Java sources in |
65 | | - // non-standard places |
66 | | - target '**/*.java' |
67 | | - |
68 | | - importOrder( |
69 | | - 'de.thetaphi', |
70 | | - 'com.carrotsearch', |
71 | | - 'com.fasterxml', |
72 | | - 'com.avast', |
73 | | - 'com.sun', |
74 | | - 'com.maxmind|com.github|com.networknt|groovy|nebula', |
75 | | - 'org.antlr', |
76 | | - 'software.amazon', |
77 | | - 'com.azure|com.microsoft|com.ibm|com.google|joptsimple|org.apache|org.bouncycastle|org.codehaus|org.opensearch|org.objectweb|org.joda|org.hamcrest|org.openjdk|org.gradle|org.junit', |
78 | | - 'javax', |
79 | | - 'java', |
80 | | - '', |
81 | | - '\\#java|\\#org.opensearch|\\#org.hamcrest|\\#' |
82 | | - ) |
83 | | - |
84 | | - eclipse().withP2Mirrors(Map.of("https://download.eclipse.org/", "https://mirror.umd.edu/eclipse/")).configFile rootProject.file('buildSrc/formatterConfig.xml') |
85 | | - endWithNewline() |
86 | | - |
87 | | - custom 'Refuse wildcard imports', { |
88 | | - // Wildcard imports can't be resolved; fail the build |
89 | | - if (it =~ /\s+import .*\*;/) { |
90 | | - throw new AssertionError("Do not use wildcard imports. 'spotlessApply' cannot resolve this issue.") |
91 | | - } |
92 | | - } |
93 | | - |
94 | | - // See DEVELOPER_GUIDE.md for details of when to enable this. |
95 | | - if (System.getProperty('spotless.paddedcell') != null) { |
96 | | - paddedCell() |
97 | | - } |
| 37 | + project.apply plugin: "com.diffplug.spotless" |
| 38 | + spotless { |
| 39 | + java { |
| 40 | + // Normally this isn't necessary, but we have Java sources in |
| 41 | + // non-standard places |
| 42 | + target '**/*.java' |
| 43 | + importOrder( |
| 44 | + 'de.thetaphi', |
| 45 | + 'com.carrotsearch', |
| 46 | + 'com.fasterxml', |
| 47 | + 'com.avast', |
| 48 | + 'com.sun', |
| 49 | + 'com.maxmind|com.github|com.networknt|groovy|nebula', |
| 50 | + 'org.antlr', |
| 51 | + 'software.amazon', |
| 52 | + 'com.azure|com.microsoft|com.ibm|com.google|joptsimple|org.apache|org.bouncycastle|org.codehaus|org.opensearch|org.objectweb|org.joda|org.hamcrest|org.openjdk|org.gradle|org.junit', |
| 53 | + 'javax', |
| 54 | + 'java', |
| 55 | + '', |
| 56 | + '\\#java|\\#org.opensearch|\\#org.hamcrest|\\#' |
| 57 | + ) |
| 58 | + eclipse().withP2Mirrors(Map.of("https://download.eclipse.org/", "https://mirror.umd.edu/eclipse/")).configFile rootProject.file('buildSrc/formatterConfig.xml') |
| 59 | + endWithNewline() |
| 60 | + removeWildcardImports() |
| 61 | + // See DEVELOPER_GUIDE.md for details of when to enable this. |
| 62 | + if (System.getProperty('spotless.paddedcell') != null) { |
| 63 | + paddedCell() |
98 | 64 | } |
99 | | - format 'misc', { |
100 | | - target '*.md', '*.gradle', '**/*.json', '**/*.yaml', '**/*.yml', '**/*.svg' |
101 | | - |
102 | | - targetExclude '**/simple-bulk11.json', '**/simple-msearch5.json' |
103 | | - |
104 | | - endWithNewline() |
| 65 | + } |
| 66 | + format 'misc', { |
| 67 | + target '*.md', '*.gradle', '**/*.json', '**/*.yaml', '**/*.yml', '**/*.svg' |
| 68 | + targetExclude '**/simple-bulk11.json', '**/simple-msearch5.json' |
| 69 | + endWithNewline() |
| 70 | + } |
| 71 | + } |
| 72 | + tasks { |
| 73 | + if (getenv("dogFoodDev")) { |
| 74 | + assemble { |
| 75 | + dependsOn(spotlessJavaApply) |
105 | 76 | } |
106 | 77 | } |
107 | | - |
108 | | - precommit.dependsOn 'spotlessJavaCheck' |
| 78 | + if (!getenv("skipDogFood")) { |
| 79 | + check { |
| 80 | + dependsOn(spotlessJavaCheck) |
| 81 | + } |
| 82 | + } |
| 83 | + } |
109 | 84 | } |
110 | 85 | } |
0 commit comments