Implement ConcatFilesTask from Groovy to Java issues#34459#37497
Implement ConcatFilesTask from Groovy to Java issues#34459#37497alpar-t merged 10 commits intoelastic:masterfrom
Conversation
695e6e7 to
800bdb3
Compare
800bdb3 to
af7f347
Compare
|
If this looks like a good enough implementation, I can start writing any tests that are required. (And sorry for the force pushes, I forgot those are not allowed even in forks in Elasticsearch) |
buildSrc/src/main/java/org/elasticsearch/gradle/ConcatFilesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/ConcatFilesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/ConcatFilesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/ConcatFilesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/ConcatFilesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/ConcatFilesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/ConcatFilesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/ConcatFilesTask.java
Outdated
Show resolved
Hide resolved
|
Pinging @elastic/es-core-infra |
|
|
||
| // To remove duplicate lines | ||
| LinkedHashSet<String> uniqueLines = new LinkedHashSet<>(); | ||
| for (File f : getFiles()) { |
There was a problem hiding this comment.
I am not sure if looping over a FileTree instance this way is correct.
|
@elasticmachine Test this please. @rjernst Thanks for the review, I have incorporated your suggestions to the best of my understanding. I ran |
|
@elasticmachine test this please |
buildSrc/src/main/java/org/elasticsearch/gradle/ConcatFilesTask.java
Outdated
Show resolved
Hide resolved
|
|
||
| @TaskAction | ||
| public void concatFiles() throws IOException { | ||
| final String encoding = "UTF-8"; |
There was a problem hiding this comment.
Just use StandardCharsets.UTF_8, no need for a variable.
There was a problem hiding this comment.
@atorok
There were multiple places where I had to mention the encoding type (UTF-8), hence I used it as a variable to keep it DRY.
Please let me know if it still makes more sense to you to remove the variable.
There was a problem hiding this comment.
I do think it's better to use the StandardCharsets.UTF_8 constant to keep it dry rather than our own variable.
There was a problem hiding this comment.
Ahh, now I see your point. Fixed it, thanks! :)
alpar-t
left a comment
There was a problem hiding this comment.
Please also write tests for the task.
|
@atorok I have added the setter for I tried running The same error is thrown when I run |
|
Fixed the above issue - seemed like a problem with the Java version and environment variables. |
| file.getParentFile().mkdirs(); | ||
| file.createNewFile(); | ||
| concatFilesTask.setTarget(file); | ||
| concatFilesTask.setFiles(new FileTree()); |
There was a problem hiding this comment.
This fails saying FileTree is abstract; cannot be instantiated.
There was a problem hiding this comment.
That's right, you'll have to use the class as intended by Gradle projcet.fileTree in this case.
See: https://docs.gradle.org/current/javadoc/org/gradle/api/file/FileTree.html
| for (File f : getFiles()) { | ||
| uniqueLines.addAll(Files.readAllLines(f.toPath(), Charset.forName(encoding))); | ||
| } | ||
| getFiles().getFiles().forEach(f -> uniqueLines.addAll(fileReadAllLines(f, encoding))); |
There was a problem hiding this comment.
This fails with NullPointerException when setFiles is not used in the tests (I guess because the first getFiles() returns null?).
| for (File f : getFiles()) { | ||
| uniqueLines.addAll(Files.readAllLines(f.toPath(), Charset.forName(encoding))); | ||
| } | ||
| getFiles().getFiles().forEach(f -> uniqueLines.addAll(fileReadAllLines(f, encoding))); |
There was a problem hiding this comment.
Also, here Files.readAllLines raises the error unreported exception IOException; must be caught or declared to be thrown, even though the definition of concatFilesTask says throws IOException. Hence the need for creating an Exception-safe function fileReadAllLines.
|
Hi @atorok I tried to write the tests for this task but facing some problems using |
|
Just wanted to check in once again on this PR to request if somebody has any suggestions for me on how I can go ahead with writing the test cases. |
|
Sorry to keep you waiting @akki I will look at this early next week. |
|
I understand, appreciate the update on your availability. :) |
|
@akki see here for file tree: https://docs.gradle.org/current/javadoc/org/gradle/api/file/FileTree.html you'll have to use the class as intended by Gradle. Specifically use |
|
Thanks for the hint; I'll get back to this by next week. |
|
Hi @atorok / all Please let me know your thoughts. |
|
@elasticmachine test this please |
|
@elasticmachine test this please |
buildSrc/src/main/java/org/elasticsearch/gradle/ConcatFilesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/test/java/org/elasticsearch/gradle/ConcatFilesTaskTests.java
Outdated
Show resolved
Hide resolved
buildSrc/src/test/java/org/elasticsearch/gradle/ConcatFilesTaskTests.java
Outdated
Show resolved
Hide resolved
* Use standardcharset everywhere * Reshuffling of imports * Cosmetic changes
|
@atorok Thank you for the review. I have updated the PR to address your comments. |
|
@akki those failures are indeed not related to the changes, they are happening because the PR was created a long time ago and master got out of sync. I merged master in so @elasticmachine test this please. |
|
@atorok Ahh, thank you. I did not realise that because GitHub told me This branch has no conflicts with the base branch. |
Issue #34459
Facing one problem (added as comment), after which the implementation would be complete for review from my side.