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

Detect isAndroidProject based on plugin IDs #237

Merged
merged 10 commits into from
Jun 25, 2018
Merged

Detect isAndroidProject based on plugin IDs #237

merged 10 commits into from
Jun 25, 2018

Conversation

trevjonez
Copy link
Contributor

should fix #236

trevjonez added 2 commits June 7, 2018 02:09
Gradle wrapper to latest as android gradle 3.1.2 needs at minimum 4.4
Test cases to show false positive no longer occurs when parent project has an android extension
@trevjonez
Copy link
Contributor Author

Looks like code narc is real upset with a bunch of files I didn't touch as well as with some that I did. My attempt was to hand match the style based on what was in the Utils class already. Reformatting the classes just to appease the travis script seems like a commit that should be external to this bug fix PR. What is the right way to proceed with this?

@zpencer zpencer self-requested a review June 8, 2018 16:40
@zpencer
Copy link
Contributor

zpencer commented Jun 8, 2018

I downgraded the gradle wrapper from 4.8 back to 4.3 and most of the errors went away. I guess the new version of gradle comes with more strict rules. It did find a few lints in the one of the added files though. Let's downgrade for now.

@trevjonez
Copy link
Contributor Author

Glad you thought of that, didn't even cross my mind as a variable. I'll try to get this all touched up tonight.

@trevjonez
Copy link
Contributor Author

So interesting thing. I can't even run the tests to completion locally unless I upgrade the gradle wrapper. I don't get any errors but it hangs after about 5 tests have ran. I am wondering if the current test suite shouldn't be reworked to minimize the time required? The majority of the time spent isn't even running anything related to this plugin. It should be possible to verify the critical plugin behaviors by analyzing the project and task graph after configuration phase without actually spending all the time required to run the project builds to completion?

assert isAndroidProject
}

@Requires({ Version.ANDROID_GRADLE_PLUGIN_VERSION.startsWith("3.") })
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be for only 3.x or for 3.x and up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

project.apply plugin:'com.android.base' will only work from 3.x and up. they add that marker plugin for this exact use case. My thought is that when you can safely abandon pre 3.0 support that case would be all that is required. which is why I have it as the first thing the isAndroidProject checks for.

The problem though is this test will fail with a no such plugin error when the tests are built/ran with 2.+ plugin versions.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit concerned about the string matching here for the "and up" part of "3.x and up". Should we adapt Utils.compareGradleVersion to be able to check any version string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea if you think it is worth while I would be happy to make the change. Was just trying to get a guard in there fast so that if someone needed to debug against 2.3.0 they still could.

build.gradle Outdated
@@ -82,7 +83,7 @@ dependencies {
// Add android plugin to the test classpath, so that we can jump into class definitions,
// read their sources, set break points, etc while debugging android unit tests.
// Change the version if necessary to match the specific unit test.
testRuntime 'com.android.tools.build:gradle:2.3.0'
testCompile 'com.android.tools.build:gradle:3.1.2'
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 if we follow the pattern in the existing android tests we can construct a project with an android version on a per test project basis. Then we can validate that the new code does not cause problems for android plugin 2.x.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So if I follow correctly you are saying we take and create external projects at different android gradle plugin version to validate the utils class implementation?(similar to the way the other test files work)

It will be a decent bit more code and add some runtime overhead of the external gradle processes but should be the most robust way to validate backwards compat.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, validating backwards compat is a requirement for all versions we support. Maybe we some point we would drop support for 2.x but for now I think we should validate all new code for 2.x versions.

I think the tests would probably end up looking something like BuildLogicFunctionalTest.java

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've done tests that way in some other projects I was just trying to be too lazy here. I'll go revamp these tests to use the external run api's which should get rid of the need for the version check Require on the 3.+ test as well.

@trevjonez
Copy link
Contributor Author

ok hopefully that will get through travis without hanging. I want to say I really dislike how hacky the current test project classpath solution is. it doesn't allow gradle to resolve dependencies the way it does in a production environment.

I don't know if it will work cleanly with travis but usually what I do is have the test task depend on the maven install task so that my test projects can reference the mavenLocal() in order to resolve the plugin under test as well as getting the normal pom file list of dependencies.

so fwiw I don't like what I had to do in ProtobufPluginTestHelper to substitute guava but can't change the project to use guava 22 because of the backwards compat concerns.

I would love to help refactor the testing setup classpath config to be more straight forward but I don't think it is appropriate for the scope of this PR.

here is an example of what that looks like:
https://github.com/trevjonez/Kontrast/blob/master/plugin/build.gradle

@trevjonez
Copy link
Contributor Author

any hints on how to get the tests to not hang? If I run locally with the gradle wrapper it will deadlock, if I run with local install of 4.8 they run and pass in under 8 minutes

zpencer added a commit to zpencer/protobuf-gradle-plugin that referenced this pull request Jun 13, 2018
For unknown reasons, the unit tests hang for Gradle 4.3 on this PR on Travis:
google#237

I have confirmed that the code works fine on 4.8.
zpencer added a commit to zpencer/protobuf-gradle-plugin that referenced this pull request Jun 13, 2018
For unknown reasons, the unit tests hang for Gradle 4.3 on this PR on Travis:
google#237

I have confirmed that the code works fine on 4.8.
@zpencer
Copy link
Contributor

zpencer commented Jun 13, 2018

I spent some time increasing the verbosity of the tests, but I couldn't figure out why it hangs in travis. FWIW the tests work fine for me locally even with gradle 4.3. I'll bump gradle to 4.8:
#239

zpencer added a commit to zpencer/protobuf-gradle-plugin that referenced this pull request Jun 13, 2018
For unknown reasons, the unit tests hang for Gradle 4.3 on this PR on Travis:
google#237

I have confirmed that the code works fine on 4.8.
zpencer added a commit that referenced this pull request Jun 14, 2018
For unknown reasons, the unit tests hang for Gradle 4.3 on this PR on Travis:
#237

I have confirmed that the code works fine on 4.8.
@zpencer
Copy link
Contributor

zpencer commented Jun 15, 2018

Could the build failure be caused by a mismatch in build tools versions in build_base.gradle?

@trevjonez
Copy link
Contributor Author

yea it is license. with newer versions of gradle plugin they remove the need to specify build tools version. Seeing if I can do both version in travis file. do you want me to squash all these once it is passing or is that the merge policy?

@trevjonez
Copy link
Contributor Author

@zpencer Anything else I need to do for this to get merged? Wanting to do some workflow demo's on Friday morning which requires these changes. hoping I can avoid doing a local install to facilitate a smoke and mirrors demo.

@zpencer zpencer merged commit 8f0a7a6 into google:master Jun 25, 2018
@zpencer
Copy link
Contributor

zpencer commented Jun 25, 2018

@trevjonez sorry I let this update slip past me! I've merged the PR now.

zhangkun83 pushed a commit to zhangkun83/protobuf-gradle-plugin-1 that referenced this pull request Nov 7, 2018
For unknown reasons, the unit tests hang for Gradle 4.3 on this PR on Travis:
google#237

I have confirmed that the code works fine on 4.8.
zhangkun83 pushed a commit to zhangkun83/protobuf-gradle-plugin-1 that referenced this pull request Nov 7, 2018
Check for android project by plugin ID
@trevjonez trevjonez deleted the bug/236 branch April 24, 2019 22:53
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.

Android project detection is done in an unsafe way leading to mixed projects not working correctly.
2 participants