Skip to content

Conversation

@baptistemesta
Copy link

Relates to #34459

#34459

@baptistemesta
Copy link
Author

I was not sure about test naming conventions.
I only added some unit tests since the task is pretty straightforward.

@dnhatn dnhatn added the :Delivery/Build Build or test infrastructure label Oct 17, 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 your contribution @baptistemesta !
This looks good, just left a few comments.

Copy link
Contributor

Choose a reason for hiding this comment

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

We prefer adding the set prefix.

Suggested change
public void contents(Object contents) {
public void setContents(Object contents) {

Also in this particular case I think we should also make a semantic change and type contents with String. This does mean that groovy will resolve GStrings sooner, but looking at the uses of this task that is ok and I would prefer the stronger typing, it's one of the reasons we convert in the first place.
We can always lather add a version that takes Supplier<String> if we need it to be more dynamic.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public void file(Object file) {
public void setFile(File file) {
this.file = file;
}
public void setFile(String file) {
this.file = getProject().file(file);
}

Along the same lines as above to avoid the use of Object.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer we use something like Files.write where we can be specific about the encoding.
FileWriter will rely on the default encoding, something we generally try to avoid.

@alpar-t
Copy link
Contributor

alpar-t commented Oct 17, 2018

@elasticmachine test this please

@baptistemesta
Copy link
Author

I integrated changes.

  • When using setFile and setContents, the configuration closure needs to use = I think
  • Change the task to have strongly typed methods

I have an issue with the Files.writeString, build fails with:

> Task :build-tools:compileJava FAILED
/Users/baptiste/git/elasticsearch/buildSrc/src/main/java/org/elasticsearch/gradle/FileContentsTask.java:62: error: cannot find symbol
        Files.writeString(file.toPath(), contents, Charset.forName("UTF-8"));
             ^
  symbol:   method writeString(Path,String,Charset)
  location: class Files
1 error

@alpar-t
Copy link
Contributor

alpar-t commented Oct 18, 2018

I have an issue with the Files.writeString, build fails with:

The method is Files.write, it takes byte[] as argument.
You control the encoding when converting from string to byte[]

Copy link
Contributor

Choose a reason for hiding this comment

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

The equals is ok, other parts of the build use it as well and I think it's the direction Gradle is going into w.r.t. task properties.
We could do without the as File if we have a setFile(String file) method, see my previous suggestion.

@alpar-t
Copy link
Contributor

alpar-t commented Oct 18, 2018

@elasticmachine test this please

Copy link
Contributor

Choose a reason for hiding this comment

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

Please use getProject().file() here to be consistent with how Gradle resolves strings to files.
For relative paths, new File() is relative to the current working directory, while project.file() is relative to project.projectDir.

@alpar-t
Copy link
Contributor

alpar-t commented Oct 19, 2018

@elasticmachine test this please

@baptistemesta
Copy link
Author

Yep I was using Files.writeString which exists since java 11...
all is integrated I think

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.

Looks good, will wait for CI and merge if all goes well.
Thanks again for your contribution!
One last time, @elasticmachine test this please.

@alpar-t
Copy link
Contributor

alpar-t commented Oct 19, 2018

@elasticmachine test this please

@alpar-t
Copy link
Contributor

alpar-t commented Oct 20, 2018

@baptistemesta please look at the CI failures. Checkstyle found some unused imports.

@elasticmachine run packaging tests

@alpar-t
Copy link
Contributor

alpar-t commented Oct 20, 2018

@elasticmachine run sample packaging tests

@baptistemesta
Copy link
Author

@atorok Ok i'll fix that, thanks

@baptistemesta baptistemesta force-pushed the refactor/filecontentstask-to-java branch from 44541be to 9d73661 Compare October 23, 2018 17:48
@baptistemesta
Copy link
Author

all good, fixed codestyle + squashed all commits

@alpar-t
Copy link
Contributor

alpar-t commented Oct 24, 2018

@elasticmachine test this please

@alpar-t
Copy link
Contributor

alpar-t commented Oct 24, 2018

@baptistemesta While not immediately obvious, the packaging-sample failure is most likely related to your PR. The other one does not seem like it, try merging master in.
@elasticmachine ok to test

@alpar-t
Copy link
Contributor

alpar-t commented Mar 7, 2019

@baptistemesta I'm closing this due to lack of activity, please reopen if you plan to work on it,

@alpar-t alpar-t closed this Mar 7, 2019
@mark-vieira mark-vieira added the Team:Delivery Meta label for Delivery team label Nov 11, 2020
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 Team:Delivery Meta label for Delivery team v7.2.0 v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants