@@ -68,9 +68,11 @@ public abstract class ServiceOptions<ServiceT extends Service<OptionsT>, Service
6868 private static final String MANIFEST_ARTIFACT_ID_KEY = "artifactId" ;
6969 private static final String MANIFEST_VERSION_KEY = "Implementation-Version" ;
7070 private static final String ARTIFACT_ID = "gcloud-java-core" ;
71- private static final String APPLICATION_BASE_NAME = "gcloud-java" ;
72- private static final String APPLICATION_NAME = getApplicationName ();
73- private static final long serialVersionUID = -6410263550484023006L ;
71+ private static final String LIBRARY_NAME = "gcloud-java" ;
72+ private static final String LIBRARY_VERSION = getLibraryVersion ();
73+ private static final String APPLICATION_NAME =
74+ LIBRARY_VERSION == null ? LIBRARY_NAME : LIBRARY_NAME + "/" + LIBRARY_VERSION ;
75+ private static final long serialVersionUID = 3049375916337507361L ;
7476
7577 private final String projectId ;
7678 private final String host ;
@@ -439,6 +441,20 @@ public String applicationName() {
439441 return APPLICATION_NAME ;
440442 }
441443
444+ /**
445+ * Returns the library's name, {@code gcloud-java}, as a string.
446+ */
447+ public String libraryName () {
448+ return LIBRARY_NAME ;
449+ }
450+
451+ /**
452+ * Returns the library's version as a string.
453+ */
454+ public String libraryVersion () {
455+ return LIBRARY_VERSION ;
456+ }
457+
442458 protected int baseHashCode () {
443459 return Objects .hash (projectId , host , authCredentialsState , retryParams , serviceFactoryClassName ,
444460 serviceRpcFactoryClassName , clock );
@@ -491,7 +507,7 @@ static <T> T getFromServiceLoader(Class<? extends T> clazz, T defaultInstance) {
491507 return Iterables .getFirst (ServiceLoader .load (clazz ), defaultInstance );
492508 }
493509
494- private static String getApplicationName () {
510+ private static String getLibraryVersion () {
495511 String version = null ;
496512 try {
497513 Enumeration <URL > resources =
@@ -507,6 +523,6 @@ private static String getApplicationName() {
507523 } catch (IOException e ) {
508524 // ignore
509525 }
510- return version != null ? APPLICATION_BASE_NAME + "/" + version : APPLICATION_BASE_NAME ;
526+ return version ;
511527 }
512528}
0 commit comments