From 123a50a3c3b1719c06689bb32c28a4618058563c Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Tue, 5 Dec 2017 17:13:34 -0500 Subject: [PATCH] Adds support for BuildConfig file --- build.gradle | 1 + gradle/dependencies.gradle | 25 +++++++++--------- services-core/build.gradle | 26 +++++++++---------- .../com/mapbox/core/constants/Constants.java | 18 ++++++++----- .../com/mapbox/core/utils/ApiCallHelper.java | 26 ++++++++----------- .../directions/v5/models/DirectionsError.java | 9 ++++--- 6 files changed, 54 insertions(+), 51 deletions(-) diff --git a/build.gradle b/build.gradle index 908b41a1a..d409a198e 100644 --- a/build.gradle +++ b/build.gradle @@ -16,6 +16,7 @@ buildscript { classpath 'com.android.tools.build:gradle:2.3.3' classpath pluginDependencies.errorprone classpath pluginDependencies.sonarqube + classpath pluginDependencies.buildConfig } } diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 4a9a18ea6..0add5d165 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -14,14 +14,14 @@ ext { ] pluginVersion = [ - checkstyle : '7.8.2', - pmd : '5.8.1', - jacoco : '0.7.9', - errorprone : '0.0.10', - coveralls : '2.8.1', - spotbugs : '1.3', - sonarqube : '2.5', - buildConfigPlugin: '1.1.8' + checkstyle : '7.8.2', + pmd : '5.8.1', + jacoco : '0.7.9', + errorprone : '0.0.10', + coveralls : '2.8.1', + spotbugs : '1.3', + sonarqube : '2.5', + buildConfig: '1.1.8' ] dependenciesList = [ autoValue : "com.google.auto.value:auto-value:${version.autoValue}", @@ -41,9 +41,10 @@ ext { pluginDependencies = [ - checkstyle: "com.puppycrawl.tools:checkstyle:${pluginVersion.checkstyle}", - spotbugs : "gradle.plugin.com.github.spotbugs:gradlePlugin:${pluginVersion.spotbugs}", - sonarqube : "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:${pluginVersion.sonarqube}", - errorprone: "net.ltgt.gradle:gradle-errorprone-plugin:${pluginVersion.errorprone}" + checkstyle : "com.puppycrawl.tools:checkstyle:${pluginVersion.checkstyle}", + spotbugs : "gradle.plugin.com.github.spotbugs:gradlePlugin:${pluginVersion.spotbugs}", + sonarqube : "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:${pluginVersion.sonarqube}", + errorprone : "net.ltgt.gradle:gradle-errorprone-plugin:${pluginVersion.errorprone}", + buildConfig: "gradle.plugin.de.fuerstenau:BuildConfigPlugin:${pluginVersion.buildConfig}" ] } \ No newline at end of file diff --git a/services-core/build.gradle b/services-core/build.gradle index e5c4bb0a6..90e639b91 100644 --- a/services-core/build.gradle +++ b/services-core/build.gradle @@ -1,22 +1,22 @@ apply plugin: 'java-library' -//apply plugin: 'de.fuerstenau.buildconfig' +apply plugin: 'de.fuerstenau.buildconfig' configurations { testOutput } -//buildConfig { -// packageName = 'com.mapbox.services' -// version = project.VERSION_NAME -// buildConfigField 'String', 'GIT_REVISION', getGitRevision() -//} -// -//static def getGitRevision() { -// def cmd = "git rev-parse --short HEAD" -// def proc = cmd.execute() -// def ref = proc.text.trim() -// return ref -//} +buildConfig { + packageName = 'com.mapbox.core' + version = project.VERSION_NAME + buildConfigField 'String', 'GIT_REVISION', getGitRevision() +} + +static def getGitRevision() { + def cmd = "git rev-parse --short HEAD" + def proc = cmd.execute() + def ref = proc.text.trim() + return ref +} dependencies { diff --git a/services-core/src/main/java/com/mapbox/core/constants/Constants.java b/services-core/src/main/java/com/mapbox/core/constants/Constants.java index 4aacb12be..9883e639e 100644 --- a/services-core/src/main/java/com/mapbox/core/constants/Constants.java +++ b/services-core/src/main/java/com/mapbox/core/constants/Constants.java @@ -1,5 +1,9 @@ package com.mapbox.core.constants; +import com.mapbox.core.BuildConfig; + +import java.util.Locale; + /** * Includes common variables used throughout the Mapbox Service modules. * @@ -7,18 +11,14 @@ */ public final class Constants { - private Constants() { - // Empty constructor prevents users from initializing this class - } - /** * User agent for HTTP requests. * * @since 1.0.0 */ - public static final String HEADER_USER_AGENT = "TODO"; -// = String.format(Locale.US, "MapboxJava/%s (%s)", -// BuildConfig.VERSION, BuildConfig.GIT_REVISION); + public static final String HEADER_USER_AGENT + = String.format(Locale.US, "MapboxJava/%s (%s)", + BuildConfig.VERSION, BuildConfig.GIT_REVISION); /** * Base URL for all API calls, not hardcoded to enable testing. @@ -47,4 +47,8 @@ private Constants() { * @since 1.0.0 */ public static final int PRECISION_5 = 5; + + private Constants() { + // Empty constructor prevents users from initializing this class + } } diff --git a/services-core/src/main/java/com/mapbox/core/utils/ApiCallHelper.java b/services-core/src/main/java/com/mapbox/core/utils/ApiCallHelper.java index ebb8a8cb8..fe788af10 100644 --- a/services-core/src/main/java/com/mapbox/core/utils/ApiCallHelper.java +++ b/services-core/src/main/java/com/mapbox/core/utils/ApiCallHelper.java @@ -1,5 +1,6 @@ package com.mapbox.core.utils; +import android.support.annotation.Nullable; import com.mapbox.core.constants.Constants; import java.util.Locale; @@ -23,23 +24,18 @@ private ApiCallHelper() { * @return {@link String} representing the header user agent * @since 1.0.0 */ - public static String getHeaderUserAgent(String clientAppName) { - try { - String osName = System.getProperty("os.name"); - String osVersion = System.getProperty("os.version"); - String osArch = System.getProperty("os.arch"); + public static String getHeaderUserAgent(@Nullable String clientAppName) { + String osName = System.getProperty("os.name"); + String osVersion = System.getProperty("os.version"); + String osArch = System.getProperty("os.arch"); - if (TextUtils.isEmpty(osName) || TextUtils.isEmpty(osVersion) || TextUtils.isEmpty(osArch)) { - return Constants.HEADER_USER_AGENT; - } else { - String baseUa = String.format( - Locale.US, "%s %s/%s (%s)", Constants.HEADER_USER_AGENT, osName, osVersion, osArch); - return TextUtils.isEmpty(clientAppName) ? baseUa : String.format(Locale.US, "%s %s", - clientAppName, baseUa); - } - - } catch (Exception exception) { + if (TextUtils.isEmpty(osName) || TextUtils.isEmpty(osVersion) || TextUtils.isEmpty(osArch)) { return Constants.HEADER_USER_AGENT; + } else { + String baseUa = String.format( + Locale.US, "%s %s/%s (%s)", Constants.HEADER_USER_AGENT, osName, osVersion, osArch); + return TextUtils.isEmpty(clientAppName) ? baseUa : String.format(Locale.US, "%s %s", + clientAppName, baseUa); } } } diff --git a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/DirectionsError.java b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/DirectionsError.java index 2aa13f598..76873dba0 100644 --- a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/DirectionsError.java +++ b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/DirectionsError.java @@ -74,14 +74,15 @@ public static TypeAdapter typeAdapter(Gson gson) { public abstract static class Builder { /** - * String indicating the state of the response. This is a separate code than the HTTP status code. - * On normal valid responses, the value will be Ok. The possible responses are listed below: + * String indicating the state of the response. This is a separate code than the HTTP status + * code. On normal valid responses, the value will be Ok. The possible responses are listed + * below: *