|
10 | 10 | */ |
11 | 11 |
|
12 | 12 |
|
| 13 | +import com.diffplug.gradle.spotless.JavaExtension |
13 | 14 | import org.opensearch.gradle.test.RestIntegTestTask |
14 | 15 |
|
15 | 16 | buildscript { |
@@ -69,7 +70,56 @@ apply plugin: 'opensearch.opensearchplugin' |
69 | 70 | apply plugin: 'opensearch.pluginzip' |
70 | 71 | apply plugin: 'opensearch.rest-test' |
71 | 72 | apply plugin: 'opensearch.testclusters' |
72 | | -apply from: 'gradle/formatting.gradle' |
| 73 | +//apply from: 'gradle/formatting.gradle' |
| 74 | + |
| 75 | +spotless { |
| 76 | + java { |
| 77 | + // Normally this isn't necessary, but we have Java sources in |
| 78 | + // non-standard places |
| 79 | + target '**/com/amazon/dlic/**/*.java' |
| 80 | + |
| 81 | + removeUnusedImports() |
| 82 | + eclipse().configFile rootProject.file('formatter/formatterConfig.xml') |
| 83 | + trimTrailingWhitespace() |
| 84 | + endWithNewline(); |
| 85 | + |
| 86 | + // note: you can use an empty string for all the imports you didn't specify explicitly, and '\\#` prefix for static imports |
| 87 | + importOrder('java', 'javax', '', 'com.amazon', 'org.opensearch', '\\#') |
| 88 | + |
| 89 | + custom 'Refuse wildcard imports', { |
| 90 | + // Wildcard imports can't be resolved; fail the build |
| 91 | + if (it =~ /\s+import .*\*;/) { |
| 92 | + throw new AssertionError("Do not use wildcard imports. 'spotlessApply' cannot resolve this issue.") |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + // See DEVELOPER_GUIDE.md for details of when to enable this. |
| 97 | + if (System.getProperty('spotless.paddedcell') != null) { |
| 98 | + paddedCell() |
| 99 | + } |
| 100 | + } |
| 101 | + format 'misc', { |
| 102 | + target '*.md', '*.gradle', '**/*.json', '**/*.yaml', '**/*.yml', '**/*.svg' |
| 103 | + |
| 104 | + trimTrailingWhitespace() |
| 105 | + endWithNewline() |
| 106 | + } |
| 107 | + format('javaFoo', JavaExtension) { |
| 108 | + |
| 109 | + importOrder('java', 'javax', '', 'com.amazon', 'org.opensearch', '\\#') |
| 110 | + target '**/*.java' |
| 111 | + targetExclude '**/com/amazon/dlic/**/*.java' |
| 112 | + targetExclude('src/integrationTest/**') |
| 113 | + |
| 114 | + trimTrailingWhitespace() |
| 115 | + endWithNewline(); |
| 116 | + } |
| 117 | + format("integrationTest", JavaExtension) { |
| 118 | + target('src/integrationTest/java/**/*.java') |
| 119 | + importOrder('java', 'javax', '', 'com.amazon', 'org.opensearch', '\\#') |
| 120 | + indentWithTabs(4) |
| 121 | + } |
| 122 | +} |
73 | 123 |
|
74 | 124 | licenseFile = rootProject.file('LICENSE.txt') |
75 | 125 | noticeFile = rootProject.file('NOTICE.txt') |
|
0 commit comments