|
26 | 26 | import org.gradle.process.ExecOperations; |
27 | 27 | import org.gradle.process.ExecResult; |
28 | 28 |
|
| 29 | +import javax.inject.Inject; |
29 | 30 | import java.io.ByteArrayOutputStream; |
30 | 31 | import java.io.File; |
31 | 32 | import java.io.IOException; |
|
42 | 43 | import java.util.function.Function; |
43 | 44 | import java.util.stream.Collectors; |
44 | 45 |
|
45 | | -import javax.inject.Inject; |
46 | | - |
47 | 46 | import static org.elasticsearch.gradle.internal.transport.TransportVersionReference.listFromFile; |
48 | 47 | import static org.elasticsearch.gradle.internal.transport.TransportVersionUtils.latestFilePath; |
49 | 48 | import static org.elasticsearch.gradle.internal.transport.TransportVersionUtils.writeDefinitionFile; |
@@ -240,7 +239,7 @@ private List<TransportVersionLatest> getMainLatestFiles() throws IOException { |
240 | 239 | List<TransportVersionLatest> latestFiles = new ArrayList<>(); |
241 | 240 | String latestBasePath = TransportVersionUtils.getResourcePath(getResourcesProjectDir().get(), "latest/"); |
242 | 241 | for (String latestPath : getMainResources(latestBasePath)) { |
243 | | - TransportVersionLatest latest = readExistingFile(latestPath, this::latestRelativePath, TransportVersionLatest::fromString); |
| 242 | + TransportVersionLatest latest = readExistingFile(latestPath, Function.identity(), TransportVersionLatest::fromString); |
244 | 243 | latestFiles.add(latest); |
245 | 244 | } |
246 | 245 | return latestFiles; |
@@ -268,42 +267,25 @@ private String findAddedTransportVersionName(Set<String> referencedNames, List<S |
268 | 267 |
|
269 | 268 | // TODO duplicated |
270 | 269 | private Set<String> getMainResources(String subPath) { |
271 | | - String output = gitCommand("ls-tree", "--name-only", "-r", "main", getResourcesProjectDir().get() + "/" + subPath); |
| 270 | + String output = gitCommand("ls-tree", "--name-only", "-r", "main", subPath); |
272 | 271 | return Set.of(output.split(System.lineSeparator())); |
273 | 272 | } |
274 | 273 |
|
275 | 274 | private Set<String> getChangedResources(String subPath) { |
276 | | - String output = gitCommand("diff", "--name-only", "main", getResourcesProjectDir().get() + "/" + subPath); |
| 275 | + String output = gitCommand("diff", "--name-only", "main", subPath).strip(); |
| 276 | + if (output.isEmpty()) { |
| 277 | + return Set.of(); |
| 278 | + } |
277 | 279 | return Set.of(output.split(System.lineSeparator())); |
278 | 280 | } |
279 | 281 |
|
280 | | - // TODO duplicated |
281 | | - private TransportVersionLatest readLatestFromMain(String releaseBranch) { |
282 | | - return readExistingFile(releaseBranch, this::latestRelativePath, TransportVersionLatest::fromString); |
283 | | - } |
284 | | - |
285 | 282 | // TODO duplicated |
286 | 283 | private <T> T readExistingFile(String name, Function<String, String> pathFunction, BiFunction<String, String, T> parser) { |
287 | 284 | String relativePath = pathFunction.apply(name); |
288 | 285 | String content = gitCommand("show", "main:" + relativePath).strip(); |
289 | 286 | return parser.apply(relativePath, content); |
290 | 287 | } |
291 | 288 |
|
292 | | - // TODO duplicated |
293 | | - private String latestRelativePath(String branch) { |
294 | | - return relativePath(latestFilePath(getResourcesDirectory().get(), branch)); |
295 | | - } |
296 | | - |
297 | | - // TODO duplicated |
298 | | - private Path resourcesDirPath() { |
299 | | - return getResourcesDirectory().get().getAsFile().toPath(); |
300 | | - } |
301 | | - |
302 | | - // TODO duplicated |
303 | | - private String relativePath(Path file) { |
304 | | - return rootPath.relativize(file).toString(); |
305 | | - } |
306 | | - |
307 | 289 | // TODO duplicated |
308 | 290 | public String gitCommand(String... args) { |
309 | 291 | final ByteArrayOutputStream stdout = new ByteArrayOutputStream(); |
|
0 commit comments