Skip to content

convert ConcatFilesTask.groovy to .java #34476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

convert ConcatFilesTask.groovy to .java #34476

wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Oct 15, 2018

No description provided.

@rjernst
Copy link
Member

rjernst commented Oct 15, 2018

Thanks for the PR @mara2701. It looks like this is incomplete? The .groovy file still exists, and the java implementation doesn't have a TaskAction annotated method, nor input/outputs.

@rjernst rjernst added :Delivery/Build Build or test infrastructure >refactoring labels Oct 15, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

Copy link
Contributor

@alpar-t alpar-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @mara2701 ! We appreciate your effort.
I think this is a good starting point, I added some comments.
I also added more details to #34459 as to what we expect with this transition,
sorry I should have added these to begin with.

public void concatFiles() {
final StringBuilder output = new StringBuilder();

if (headerLine != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is not necessary, Gradle doesn't allow for it unless the task is marked @Optional


final StringBuilder sb = new StringBuilder();
for (File f: files) {
Scanner scanner = new Scanner(f, "UTF-8" );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use a try-with-resources syntax with this.

final StringBuilder sb = new StringBuilder();
for (File f: files) {
Scanner scanner = new Scanner(f, "UTF-8" );
String text = scanner.useDelimiter("\\A").next();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using nextLine might be easier to read, and since we need all the lines in memory to perform the de-duplication anyhow, I would consider doing it in one step.
Using java streams and a set as the Groovy implementation did to take care of the de-duplication would make this concise and easy to understand:

  files.getFiles().stream()
            .flatMap(Files.readLines(null, StandardCharsets.UTF_8).stream())
            .collect(Collectors.toSet())
            .forEach( line -> {
                    // write each line to target        
            })

You will probably have to collect to a different set implementation to preserve order but this is the general idea. Writing a test will make that obvious.

@akki
Copy link
Contributor

akki commented Jan 4, 2019

@mara2701 Are you planning to work further on this?
Since there is no activity on this thread for more than 2 months, is it fine if I take this task ahead?

@akki
Copy link
Contributor

akki commented Jan 15, 2019

Picking this task due to long inactivity.

@danielmitterdorfer
Copy link
Member

This PR might be obsolete due to #37497.

@alpar-t
Copy link
Contributor

alpar-t commented Mar 7, 2019

Closing since #37497 was merged.

@alpar-t alpar-t closed this Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Delivery/Build Build or test infrastructure >refactoring stalled
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants