diff --git a/google-api-client/pom.xml b/google-api-client/pom.xml index 254e33959..daf918cfe 100644 --- a/google-api-client/pom.xml +++ b/google-api-client/pom.xml @@ -18,6 +18,17 @@ + + org.apache.maven.plugins + maven-resources-plugin + + + + resources + + + + maven-javadoc-plugin @@ -94,6 +105,16 @@ + + + + src/main/resources + + + src/main/properties + true + + diff --git a/google-api-client/src/main/java/com/google/api/client/googleapis/GoogleUtils.java b/google-api-client/src/main/java/com/google/api/client/googleapis/GoogleUtils.java index a89617a89..9bb2fc74c 100644 --- a/google-api-client/src/main/java/com/google/api/client/googleapis/GoogleUtils.java +++ b/google-api-client/src/main/java/com/google/api/client/googleapis/GoogleUtils.java @@ -16,11 +16,11 @@ import com.google.api.client.util.SecurityUtils; import com.google.common.annotations.VisibleForTesting; - import java.io.IOException; import java.io.InputStream; import java.security.GeneralSecurityException; import java.security.KeyStore; +import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -32,11 +32,8 @@ */ public final class GoogleUtils { - // NOTE: toString() so compiler thinks it isn't a constant, so it won't inline it - // {x-version-update-start:google-api-client:current} /** Current release version. */ - public static final String VERSION = "1.30.3".toString(); - // {x-version-update-end:google-api-client:current} + public static final String VERSION = getVersion(); // NOTE: Integer instead of int so compiler thinks it isn't a constant, so it won't inline it /** @@ -91,5 +88,24 @@ public static synchronized KeyStore getCertificateTrustStore() return certTrustStore; } + private static String getVersion() { + String version = GoogleUtils.class.getPackage().getImplementationVersion(); + // in a non-packaged environment (local), there's no implementation version to read + if (version == null) { + // fall back to reading from a properties file - note this value is expected to be cached + try (InputStream inputStream = + GoogleUtils.class.getResourceAsStream("google-api-client.properties")) { + if (inputStream != null) { + Properties properties = new Properties(); + properties.load(inputStream); + version = properties.getProperty("google-api-client.version"); + } + } catch (IOException e) { + // ignore + } + } + return version; + } + private GoogleUtils() {} } diff --git a/google-api-client/src/main/properties/com/google/api/client/googleapis/google-api-client.properties b/google-api-client/src/main/properties/com/google/api/client/googleapis/google-api-client.properties new file mode 100644 index 000000000..f6a515d62 --- /dev/null +++ b/google-api-client/src/main/properties/com/google/api/client/googleapis/google-api-client.properties @@ -0,0 +1 @@ +google-api-client.version=${project.version} diff --git a/google-api-client/src/test/java/com/google/api/client/googleapis/GoogleUtilsTest.java b/google-api-client/src/test/java/com/google/api/client/googleapis/GoogleUtilsTest.java index a25e20209..aa961382c 100644 --- a/google-api-client/src/test/java/com/google/api/client/googleapis/GoogleUtilsTest.java +++ b/google-api-client/src/test/java/com/google/api/client/googleapis/GoogleUtilsTest.java @@ -56,4 +56,12 @@ public void testVersionMatcherSnapshot() { assertEquals(30, Integer.parseInt(matcher.group(2))); assertEquals(3, Integer.parseInt(matcher.group(3))); } + + public void testVersion() { + Matcher matcher = GoogleUtils.VERSION_PATTERN.matcher(GoogleUtils.VERSION); + assertTrue(matcher.find()); + assertNotNull(GoogleUtils.MAJOR_VERSION); + assertNotNull(GoogleUtils.MINOR_VERSION); + assertNotNull(GoogleUtils.BUGFIX_VERSION); + } } diff --git a/pom.xml b/pom.xml index bdeb9ca27..53f6246e1 100644 --- a/pom.xml +++ b/pom.xml @@ -297,8 +297,9 @@ + org.apache.maven.plugins maven-checkstyle-plugin - 2.6 + 3.1.0 org.codehaus.mojo @@ -325,6 +326,11 @@ maven-site-plugin 3.8.2 + + org.apache.maven.plugins + maven-resources-plugin + 3.1.0 + @@ -412,22 +418,6 @@ - - org.apache.maven.plugins - maven-checkstyle-plugin - - checkstyle.xml - true - ${basedir}/../checkstyle-suppressions.xml - - - - - check - - - - org.codehaus.mojo findbugs-maven-plugin @@ -546,5 +536,53 @@ + + + + root-directory + + + checkstyle-suppressions.xml + + + + . + + + + + + checkstyle-tests + + [1.8,) + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + com.puppycrawl.tools + checkstyle + 8.23 + + + + checkstyle.xml + true + checkstyle-suppressions.xml + + + + + check + + + + + + +