@@ -59,6 +59,27 @@ if (VersionProperties.elasticsearch.toString().endsWith('-SNAPSHOT')) {
59
59
}
60
60
String elasticLicenseUrl = " https://raw.githubusercontent.com/elastic/elasticsearch/${ licenseCommit} /licenses/ELASTIC-LICENSE.txt"
61
61
62
+ List<String > getChangedFilesByProject (Project project ) {
63
+ // Get list of all changed files
64
+ ByteArrayOutputStream systemOutStream = new ByteArrayOutputStream ()
65
+
66
+ String ghprbTargetBranch = System . getenv(" ghprbTargetBranch" )
67
+ String targetBranch = ghprbTargetBranch ? " origin/${ ghprbTargetBranch} " : " master"
68
+ String projectDir = project. getRootDir(). toPath(). relativize(project. getProjectDir(). toPath())
69
+ String command = " git diff --relative=" + projectDir + " --name-only --diff-filter=ACMRT " + targetBranch
70
+
71
+ command. execute(). waitForProcessOutput(systemOutStream, System . err)
72
+ List<String > changedFiles = systemOutStream. toString(). trim(). split(' \n ' )
73
+ systemOutStream. close()
74
+ List<String > changedJavaFiles = new ArrayList<> ()
75
+ for (f in changedFiles) {
76
+ if (f. endsWith(" .java" )) {
77
+ changedJavaFiles. add(f)
78
+ }
79
+ }
80
+ return changedJavaFiles
81
+ }
82
+
62
83
subprojects {
63
84
// Default to the apache license
64
85
project. ext. licenseName = ' The Apache Software License, Version 2.0'
@@ -107,13 +128,24 @@ subprojects {
107
128
// switched to an exclude list, and eventualy removed completely.
108
129
def projectPathsToFormat = [
109
130
// ':build-tools'
131
+ ' :x-pack:plugin:transform'
110
132
]
111
133
112
134
if (projectPathsToFormat. contains(project. path)) {
113
135
project. apply plugin : " com.diffplug.gradle.spotless"
114
136
137
+ List<String > changedFiles = getChangedFilesByProject(project)
138
+
139
+ println " [" + project. path + " ] Check formating of: " + changedFiles
140
+ if (changedFiles. isEmpty()) {
141
+ return
142
+ }
143
+
115
144
spotless {
116
145
java {
146
+ target project. fileTree(' .' ) {
147
+ includes= changedFiles
148
+ }
117
149
118
150
removeUnusedImports()
119
151
eclipse(). configFile rootProject. file(' .eclipseformat.xml' )
0 commit comments