Skip to content

Conversation

@dRadest
Copy link

@dRadest dRadest commented Apr 14, 2019

Contributes to #34459

status: ongoing

Done so far:

  • refactored DependenciesInfoTask.groovy to DependenciesInfoTask.java

@dRadest dRadest changed the title Refactor: convert DependeciesInfoTask to Java Refactor: convert DependenciesInfoTask to Java Apr 14, 2019
@colings86 colings86 added the :Delivery/Build Build or test infrastructure label Apr 15, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

Copy link
Contributor

@rhamedy rhamedy left a comment

Choose a reason for hiding this comment

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

Not part of the Elastic team but, left some comments anyway based on my learning experience from my PR for 39605 👍

package org.elasticsearch.gradle;

import org.gradle.api.DefaultTask;
import org.elasticsearch.gradle.precommit.DependencyLicensesTask;
Copy link
Contributor

Choose a reason for hiding this comment

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

If I remember correctly, in this refactor effort you cannot reference groovy classes (i.e. DependencyLicensesTask) but, it's ok for groovy classes to reference this new java class. You might have to wait for #35231 to get merged first 🤔

Copy link
Author

Choose a reason for hiding this comment

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

Yep, that was my general idea, i.e. to wait

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I had some problems running the tests and stopped working on #35231. I'll try to see if I can make the tests work this weekend.


private File outputFile = new File(getProject().getBuildDir(), "reports/dependencies/dependencies.csv");

@Input
Copy link
Contributor

Choose a reason for hiding this comment

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

You do not need these annotations i.e. @Input anymore 👍 See review comments on other PRs.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks. I missed that. Is this just for the @input or all annotations?

for(File file : matchedfiles) {
String prefix = file.getName().split("-LICENSE.*")[0];
if (group.contains(prefix) || name.contains(prefix)) {
license = file.getAbsoluteFile();
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is same as existing code but, makes me curious.

I wonder how this loop works? When the if (group.contains(prefix) || name.contains(prefix)) is true more than once then previous value of license is replaced with new one 🤔If it is true only once then we should return early after assigning license value. No? 😕

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure, but I wonder if there could be more than one license file for a dependency? How would we know without looping through all of them? And if there are, looping through all of them and sticking to the last one makes as much sense as any other.

if (license != null) {
// replace * because they are sometimes used at the beginning lines as if the license was a multi-line comment
final String content = new String(Files.readAllBytes(outfile.toPath()), StandardCharsets.UTF_8);
content.replaceAll("\\s+", " ").replaceAll("\\*", " ");
Copy link
Contributor

Choose a reason for hiding this comment

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

It kinda feels weird when invoking replaceAll on a final instance. Also replaceAll does not change the value of content and it returns the updated string and you are not storing it anywhere (hence changes lost). You might have to stick with existing solution

final String content = new String(license.readBytes(), "UTF-8").replaceAll("\\s+", " ").replaceAll("\\*", " ")

It does not change the value of a final field as well as the result of replaceAll on string is not lost 👍

Copy link
Author

Choose a reason for hiding this comment

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

Ups! My bad. Thanks for pointing that out. But isn't readBytes() groovy ? I replaced it with Files.readAllBytes()

@alpar-t
Copy link
Contributor

alpar-t commented May 2, 2019

Thanks for picking this up @dRadest , and thanks for pitching in @rhamedy !
@elasticmachine test this please.

@alpar-t
Copy link
Contributor

alpar-t commented Jun 12, 2019

@elasticmachine update branch

@alpar-t
Copy link
Contributor

alpar-t commented Jun 12, 2019

@elasticmachine test this please

@alpar-t
Copy link
Contributor

alpar-t commented Jun 13, 2019

@dRadest looks like something is not wired correctly ? CI is picking up:

15:16:29 /var/lib/jenkins/workspace/elastic+elasticsearch+pull-request-1/buildSrc/src/main/java/org/elasticsearch/gradle/DependenciesInfoTask.java:30: error: cannot find symbol
15:16:29 import org.elasticsearch.gradle.precommit.DependencyLicensesTask;
15:16:29                                          ^
15:16:29   symbol:   class DependencyLicensesTask
15:16:29   location: package org.elasticsearch.gradle.precommit```

@alpar-t
Copy link
Contributor

alpar-t commented Jul 16, 2019

I'm going to close this. @dRadest feel free to open it if you plan to work on it again

@alpar-t alpar-t closed this Jul 16, 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 Team:Delivery Meta label for Delivery team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants