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

[gax-java] fix: make GaxProperties.version accessible in Android #1117

Merged
merged 6 commits into from Jun 6, 2020

Conversation

miraleung
Copy link
Contributor

@miraleung miraleung commented Jun 4, 2020

No description provided.

@googlebot googlebot added the cla: yes label Jun 4, 2020
@miraleung miraleung linked an issue Jun 4, 2020 that may be closed by this pull request
@miraleung miraleung requested a review from elharo Jun 4, 2020
@miraleung
Copy link
Contributor Author

@miraleung miraleung commented Jun 4, 2020

I tested this in an Android app and standalone Java binary, and they both work.

@miraleung miraleung requested a review from vam-google Jun 4, 2020
@codecov
Copy link

@codecov codecov bot commented Jun 4, 2020

Codecov Report

Merging #1117 into master will increase coverage by 0.00%.
The diff coverage is 20.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1117   +/-   ##
=========================================
  Coverage     78.65%   78.66%           
+ Complexity     1170     1169    -1     
=========================================
  Files           204      204           
  Lines          5187     5189    +2     
  Branches        416      417    +1     
=========================================
+ Hits           4080     4082    +2     
- Misses          932      933    +1     
+ Partials        175      174    -1     
Impacted Files Coverage Δ Complexity Δ
...in/java/com/google/api/gax/core/GaxProperties.java 55.00% <20.00%> (+5.00%) 5.00 <1.00> (-1.00) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cf1bce8...374f4f5. Read the comment docs.

// Always read GaxProperties' version from the properties file.
if (!libraryClass.equals(GaxProperties.class)) {
version = getLibraryVersion(libraryClass);
if (!DEFAULT_VERSION.equals(version)) {
Copy link
Contributor

@elharo elharo Jun 4, 2020

Choose a reason for hiding this comment

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

why the if? seems we can return unconditionally here if it is the default version. Or do you want to read from gradle.properties instead if this is the default version?

Copy link
Contributor Author

@miraleung miraleung Jun 4, 2020

Choose a reason for hiding this comment

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

Since this seems applicable to any generic library class (i.e. keep reading if the version is empty, aka DEFAULT_VERSION), I was trying to keep the non-GaxProperties logic the same.

}

try (InputStream in = libraryClass.getResourceAsStream("/dependencies.properties")) {
Copy link
Contributor

@vam-google vam-google Jun 5, 2020

Choose a reason for hiding this comment

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

Why is this needed? Most probably this will break execution as a bazel artifact (i.e. when a client library is build with bazel and executed from bazel context). In any case, introducing another properties file will duplicate version information in two places. Plus, the version in dependencies.properties is automatically bumped by Yoshi's tools during releases.

Copy link
Contributor Author

@miraleung miraleung Jun 5, 2020

Choose a reason for hiding this comment

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

This is similar to this PR in google-http-java-client. Note that dependencies.properties was never being pulled into the Android JAR. This file is also suboptimal to include since it includes every dependency, which we don't necessarily want gax-external developers to parse.

On the other hand, gradle.properties is a standard artifact that is expected to be provided in many libraries and works on both Android and plain Java binaries.

Copy link
Contributor

@vam-google vam-google Jun 5, 2020

Choose a reason for hiding this comment

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

tl;dr; Please strongly consider just making dependencies.properties work in android env.

google-http-java-client is not used via bazel, that is why it does not matter for it. Also it does not have dependencies.properites.

Note, dependencies.properties is used in any scenario (with or without bazel). It is the source of truth for the version.

As for gradle.properties, it makes gax-java as java artifact depend on its build system (gradle, which is one of many) during runtime. The same artifact can be built by maven, for example, which makes gradle.properties an alien thing there. I guess it is also not even included in bazel artfiact unlike dependencies.properties (https://github.com/googleapis/gax-java/blob/master/gax/BUILD.bazel#L43). If you run bazel test //... for gax-java, does it work (most probably it will not)?

In any case, most importantly, this value is not updated automatically so after the next release it will start reporting wrong version number. There is TODO, but it is not sufficient (after all this PR fixes one relatively small issue, so introducing a future issue with it is not "cost efficient").

Copy link
Contributor Author

@miraleung miraleung Jun 5, 2020

Choose a reason for hiding this comment

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

IMO we shouldn't include all of dependencies.properties, so here's a workaround. I'm now generating a new dependencies.properties that pulls in version.gax at build time. This still works with bazel test //..., ./gradlew test, Android, and plain Java binaries.

We also did not have a GaxPropertiesTest before, so I've added one.

Copy link
Contributor

@elharo elharo left a comment

Please merge to master

@miraleung
Copy link
Contributor Author

@miraleung miraleung commented Jun 5, 2020

Merged to master.

build.gradle Outdated
@@ -40,6 +40,15 @@ googleJavaFormat {
exclude 'build/**'
exclude 'bazel*/**'
}

task generateProjectProperties {
ext.outputFile = file("gax/src/main/resources/dependencies.propertoes")
Copy link
Contributor

@vam-google vam-google Jun 5, 2020

Choose a reason for hiding this comment

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

propertoes -> properties

version = getLibraryVersion(libraryClass);
if (!DEFAULT_VERSION.equals(version)) {
return version;
}
}

try (InputStream in = libraryClass.getResourceAsStream("/dependencies.properties")) {
Copy link
Contributor

@vam-google vam-google Jun 5, 2020

Choose a reason for hiding this comment

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

This reads dependencies.properteis, but generateProjectProperties writes to the file with typo dependencies.propertoes. Looks like the file (even if it did not contain a typo) is never read (and the tests pass without the need to copy the file).

Copy link
Contributor Author

@miraleung miraleung Jun 5, 2020

Choose a reason for hiding this comment

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

Fixed.

@@ -0,0 +1 @@
version.gax=1.56.0
Copy link
Contributor

@vam-google vam-google Jun 5, 2020

Choose a reason for hiding this comment

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

Please add newline char.
Please justify the need of copying the file. What harm does including the whole file makes?
Even if we do the copy, shouldn't it be created only as build artifacts but not included in git (otherwise it is an unnecessary duplication, and confusing source artifacts created during build)?

Copy link
Contributor Author

@miraleung miraleung Jun 5, 2020

Choose a reason for hiding this comment

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

Removed from git.

// Source jar
// ----------

task sourcesJar(type: Jar, dependsOn: classes) {
dependsOn generateProjectProperties
Copy link
Contributor

@vam-google vam-google Jun 5, 2020

Choose a reason for hiding this comment

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

Where is the generated file included - in -sources jar or in .class files jar? If it is in sources jar only, then it will not be accessible as a resource during runtime.

Copy link
Contributor Author

@miraleung miraleung Jun 5, 2020

Choose a reason for hiding this comment

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

.class files, because it's accessible when running tests or an Android APK.

Copy link
Contributor

@vam-google vam-google left a comment

LGTM, please use your judgement

@miraleung
Copy link
Contributor Author

@miraleung miraleung commented Jun 6, 2020

Found a way to keep the generated files only in the build directory.

@miraleung
Copy link
Contributor Author

@miraleung miraleung commented Jun 6, 2020

The optimal solution was to generate and write a subset of dependencies.properties to a build-only directory, and that worked on Android, gradle / bazel tests, and plain Java binaries when built locally. However, this fails on CI and TravisCI, so we'll have to go back to the second-last commit. The CI failures are a likely motivator for the http-client workaround.

@miraleung miraleung merged commit ecbab4a into master Jun 6, 2020
8 of 9 checks passed
@miraleung miraleung deleted the fixit/version branch Jun 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants