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

Fix VERSION constant #1355

Merged
merged 2 commits into from Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -15,11 +15,14 @@
package com.google.api.client.googleapis;

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.regex.Matcher;
import java.util.regex.Pattern;

/**
* Utility class for the Google API Client Library.
Expand All @@ -29,42 +32,52 @@
*/
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-SNAPSHOT".toString();
// {x-version-update-end:google-api-client:current}

// NOTE: Integer instead of int so compiler thinks it isn't a constant, so it won't inline it
/**
* Major part of the current release version.
*
* @since 1.14
*/
public static final Integer MAJOR_VERSION = 1;
public static final Integer MAJOR_VERSION;

/**
* Minor part of the current release version.
*
* @since 1.14
*/
public static final Integer MINOR_VERSION = 26;
public static final Integer MINOR_VERSION;

/**
* Bug fix part of the current release version.
*
* @since 1.14
*/
public static final Integer BUGFIX_VERSION = 0;
public static final Integer BUGFIX_VERSION;

/** Current release version. */
// NOTE: toString() so compiler thinks it isn't a constant, so it won't inline it
public static final String VERSION = (MAJOR_VERSION + "." + MINOR_VERSION + "." + BUGFIX_VERSION
+ "-SNAPSHOT").toString();
@VisibleForTesting
static final Pattern VERSION_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)(-SNAPSHOT)?");

static {
Matcher versionMatcher = VERSION_PATTERN.matcher(VERSION);
versionMatcher.find();
MAJOR_VERSION = Integer.parseInt(versionMatcher.group(1));
MINOR_VERSION = Integer.parseInt(versionMatcher.group(2));
BUGFIX_VERSION = Integer.parseInt(versionMatcher.group(3));
}

/** Cached value for {@link #getCertificateTrustStore()}. */
static KeyStore certTrustStore;

/**
* Returns the key store for trusted root certificates to use for Google APIs.
*
* <p>
* Value is cached, so subsequent access is fast.
* </p>
* <p>Value is cached, so subsequent access is fast.
*
* @since 1.14
*/
Expand All @@ -78,6 +91,5 @@ public static synchronized KeyStore getCertificateTrustStore()
return certTrustStore;
}

private GoogleUtils() {
}
private GoogleUtils() {}
}
Expand Up @@ -16,6 +16,8 @@

import java.security.KeyStore;
import java.util.Enumeration;
import java.util.regex.Matcher;

import junit.framework.TestCase;

/**
Expand All @@ -36,4 +38,22 @@ public void testGetCertificateTrustStore() throws Exception {
// has been added or removed
assertEquals(70, trustStore.size());
}

public void testVersionMatcher() {
String version = "1.30.3";
Matcher matcher = GoogleUtils.VERSION_PATTERN.matcher(version);
assertTrue(matcher.find());
assertEquals(1, Integer.parseInt(matcher.group(1)));
assertEquals(30, Integer.parseInt(matcher.group(2)));
assertEquals(3, Integer.parseInt(matcher.group(3)));
}

public void testVersionMatcherSnapshot() {
String version = "1.30.3-SNAPSHOT";
Matcher matcher = GoogleUtils.VERSION_PATTERN.matcher(version);
assertTrue(matcher.find());
assertEquals(1, Integer.parseInt(matcher.group(1)));
assertEquals(30, Integer.parseInt(matcher.group(2)));
assertEquals(3, Integer.parseInt(matcher.group(3)));
}
}