[gax-java] fix: make GaxProperties.version accessible in Android #1117
Changes from all commits
c12779a
1305707
15565c6
ca91181
7fd9779
374f4f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,6 @@ bazel-* | |
# IntelliJ | ||
.idea | ||
out | ||
|
||
# Auto-generated files. | ||
gax/src/main/resources/dependencies.properties |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,9 +57,13 @@ public static String getLibraryVersion(Class<?> libraryClass) { | |
* method are expected to be cached. | ||
*/ | ||
public static String getLibraryVersion(Class<?> libraryClass, String propertyName) { | ||
String version = getLibraryVersion(libraryClass); | ||
if (!DEFAULT_VERSION.equals(version)) { | ||
return version; | ||
String version = null; | ||
// Always read GaxProperties' version from the properties file. | ||
if (!libraryClass.equals(GaxProperties.class)) { | ||
version = getLibraryVersion(libraryClass); | ||
if (!DEFAULT_VERSION.equals(version)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
return version; | ||
} | ||
} | ||
|
||
try (InputStream in = libraryClass.getResourceAsStream("/dependencies.properties")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 On the other hand, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tl;dr; Please strongly consider just making
Note, As for 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"). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO we shouldn't include all of We also did not have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This reads There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following disclaimer | ||
* in the documentation and/or other materials provided with the | ||
* distribution. | ||
* * Neither the name of Google LLC nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.google.api.gax.core; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.util.regex.Pattern; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
@RunWith(JUnit4.class) | ||
public class GaxPropertiesTest { | ||
|
||
@Test | ||
public void testGaxVersion() { | ||
String gaxVersion = GaxProperties.getGaxVersion(); | ||
assertTrue(Pattern.compile("^\\d+\\.\\d+\\.\\d+").matcher(gaxVersion).find()); | ||
String[] versionComponents = gaxVersion.split("\\."); | ||
// This test was added in version 1.56.0, so check that the major and minor numbers are greater | ||
// than that. | ||
int major = Integer.parseInt(versionComponents[0]); | ||
int minor = Integer.parseInt(versionComponents[1]); | ||
|
||
assertTrue(major >= 1); | ||
if (major == 1) { | ||
assertTrue(minor >= 56); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.