Skip to content

Commit

Permalink
Adds support for BuildConfig file (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Mace authored Dec 6, 2017
1 parent 3d081f4 commit 9f2fb5f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 51 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath pluginDependencies.errorprone
classpath pluginDependencies.sonarqube
classpath pluginDependencies.buildConfig
}
}

Expand Down
25 changes: 13 additions & 12 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand All @@ -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}"
]
}
26 changes: 13 additions & 13 deletions services-core/build.gradle
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package com.mapbox.core.constants;

import com.mapbox.core.BuildConfig;

import java.util.Locale;

/**
* Includes common variables used throughout the Mapbox Service modules.
*
* @since 3.0.0
*/
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.
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mapbox.core.utils;

import android.support.annotation.Nullable;
import com.mapbox.core.constants.Constants;

import java.util.Locale;
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@ public static TypeAdapter<DirectionsError> 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:
* <ul>
* <li><strong>Ok</strong>:200 Normal success case</li>
* <li><strong>NoRoute</strong>: 200 There was no route found for the given coordinates. Check
* for impossible routes (e.g. routes over oceans without ferry connections).</li>
* <li><strong>NoSegment</strong>: 200 No road segment could be matched for coordinates. Check for
* coordinates too far away from a road.</li>
* <li><strong>NoSegment</strong>: 200 No road segment could be matched for coordinates. Check
* for coordinates too far away from a road.</li>
* <li><strong>ProfileNotFound</strong>: 404 Use a valid profile as described above</li>
* <li><strong>InvalidInput</strong>: 422</li>
* </ul>
Expand Down

0 comments on commit 9f2fb5f

Please sign in to comment.