Skip to content

Commit 3696f4d

Browse files
author
Hendrik Muhs
committed
check only changed files regarding format
1 parent f155d88 commit 3696f4d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

build.gradle

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,27 @@ if (VersionProperties.elasticsearch.toString().endsWith('-SNAPSHOT')) {
5959
}
6060
String elasticLicenseUrl = "https://raw.githubusercontent.com/elastic/elasticsearch/${licenseCommit}/licenses/ELASTIC-LICENSE.txt"
6161

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+
6283
subprojects {
6384
// Default to the apache license
6485
project.ext.licenseName = 'The Apache Software License, Version 2.0'
@@ -107,13 +128,24 @@ subprojects {
107128
// switched to an exclude list, and eventualy removed completely.
108129
def projectPathsToFormat = [
109130
// ':build-tools'
131+
':x-pack:plugin:transform'
110132
]
111133

112134
if (projectPathsToFormat.contains(project.path)) {
113135
project.apply plugin: "com.diffplug.gradle.spotless"
114136

137+
List<String> changedFiles = getChangedFilesByProject(project)
138+
139+
println "[" + project.path + "] Check formating of: " + changedFiles
140+
if (changedFiles.isEmpty()) {
141+
return
142+
}
143+
115144
spotless {
116145
java {
146+
target project.fileTree('.') {
147+
includes= changedFiles
148+
}
117149

118150
removeUnusedImports()
119151
eclipse().configFile rootProject.file('.eclipseformat.xml')

0 commit comments

Comments
 (0)