Skip to content
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

Handle plugins block and empty url in gradle source #159

Merged
merged 4 commits into from
Apr 12, 2019
Merged

Handle plugins block and empty url in gradle source #159

merged 4 commits into from
Apr 12, 2019

Conversation

janderssonse
Copy link
Contributor

Most more advanced build.gradle files out in the wild has a plugins block,
buildscript block or both. At the moment there is a restriction
where plugins blocks can be added, so the current implementation
cant handle the "apply build.gradle" clause when generating the
tempfile.

This fix will check if the "Gradle license report" plugin is installed,
and if not, either add it to the plugins block, or add an
plugins block with it if there was none in the build.gradle file.
This should make the gradle source compatible with all the cases first mentioned.

Also, there was a problem where if one dependency was missing an url,
the license cache check would fail with exception.
This takes an easy way out to fix this - it sets it to an empty
mutable string.

Most more advanced build.gradle files out in the wild has a plugins block,
buildscript block or both. At the moment there is a restriction
where plugins blocks can be added, so the current implementation
cant handle the "apply build.gradle" clause when generating the
tempfile.

This fix will check if the "Gradle license report" plugin is installed,
and if not, either add it to the plugins block, or add an
plugins block with it if there was none in the build.gradle file.
This should be compatible with all the cases first mentioned.

Also, there was a problem where if one dependency was missing an url,
the check would fail with exception.
This takes an easy way out to fix this - it sets it to an empty
mutable string.
@janderssonse
Copy link
Contributor Author

janderssonse commented Apr 9, 2019

I tested the fix on a few real life projects with the above mentioned blocks

Copy link
Contributor

@jonabc jonabc left a comment

Choose a reason for hiding this comment

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

This is great! Thank you for the bug fix 🙇 I've got a couple minor requested changes/reverts

I'm also interested in whether you can add or update the gradle source tests or fixtures to verify that the fixes work and that regressions aren't introduced in the future. I have minimal exposure to gradle so I'd rely on your knowledge on how to craft those tests, if possible

lib/licensed/sources/gradle.rb Outdated Show resolved Hide resolved
lib/licensed/sources/gradle.rb Outdated Show resolved Hide resolved
lib/licensed/sources/gradle.rb Outdated Show resolved Hide resolved
lib/licensed/sources/gradle.rb Outdated Show resolved Hide resolved
lib/licensed/sources/gradle.rb Outdated Show resolved Hide resolved
lib/licensed/sources/gradle.rb Outdated Show resolved Hide resolved
lib/licensed/sources/gradle.rb Outdated Show resolved Hide resolved
lib/licensed/sources/gradle.rb Outdated Show resolved Hide resolved
lib/licensed/sources/gradle.rb Outdated Show resolved Hide resolved
lib/licensed/sources/gradle.rb Outdated Show resolved Hide resolved
@janderssonse
Copy link
Contributor Author

janderssonse commented Apr 10, 2019

I agree with your comments. Sorry for the formatting, and for forgetting the tests, I did this patch on a train ride and stressed to get it done before I reached home. I'll try to get the fixes done on friday, when we have our hack-on-whatever-you-want day. And of course, if anyone else should feel like doing the fixes before that, they are all welcome.

@janderssonse
Copy link
Contributor Author

janderssonse commented Apr 10, 2019

A question about test fixture(s) - how detailed do you want them - should I go for having all the variants we want to test in different fixture files. 1) no buildscripts or plugins block (like now) 2) only plugins block, no license dep added 3) only plugins block, license dep added and so on. with every permutation/possible combination it would be quite a few tests. I interpret the fixtures to be more of a high perspective integration tests though, and as a first step add the ones I think is most important. A few tests is better than no tests.

@jonabc
Copy link
Contributor

jonabc commented Apr 10, 2019

@jandersson-svt

Sorry for the formatting, and for forgetting the tests, I did this patch on a train ride and stressed to get it done before I reached home.

Not a problem at all! Thank you for trying out the new source and putting together a PR to fix the issues you found 🙇

A question about test fixture(s) - how detailed do you want them ... I interpret the fixtures to be more of a high perspective integration tests though, and as a first step add the ones I think is most important. A few tests is better than no tests.

✨ this sounds great. I'm not terribly concerned about covering all edge cases right now. Getting coverage for common gradle files patterns would be perfect.

@janderssonse
Copy link
Contributor Author

Let's try this. Fixed all your suggestions as wished, I only did at simple addition to the build.gradle file for testing the pattern with a plugins block and a buildscript block. I'll add more later, but hope this basic is enough for this PR.

Btw, me and my colleague have some ideas and some suggestions, should I make an issue for each so that it can be discussed there?

(I also found one bug, but I think that is in one of the helper libraries, I'll have a look before making an issue or PR)

Copy link
Contributor

@jonabc jonabc 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, thanks!

Btw, me and my colleague have some ideas and some suggestions, should I make an issue for each so that it can be discussed there?

@jandersson-svt Yes please 🙇

@jonabc jonabc merged commit f1c0e8d into github:master Apr 12, 2019
@jonabc jonabc mentioned this pull request Apr 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants