/** * Handle a client object for maps (@string/google_maps_key). * @param clientObject the client Json object. * @throws IOException */ private void handleMapsService(JsonObject clientObject, Map<String, String> resValues) throws IOException { JsonObject mapsService = getServiceByName(clientObject, "maps_service"); if (mapsService == null) return; String apiKey = getAndroidApiKey(clientObject); if (apiKey != null) { resValues.put("google_maps_key", apiKey); return; } throw new GradleException("Missing api_key/current_key object"); }
private void handleGoogleApiKey(JsonObject clientObject, Map<String, String> resValues) { String apiKey = getAndroidApiKey(clientObject); if (apiKey != null) { resValues.put("google_api_key", apiKey); // TODO: remove this once SDK starts to use google_api_key. resValues.put("google_crash_reporting_api_key", apiKey); return; } // if google_crash_reporting_api_key is missing. // throw new GradleException("Missing api_key/current_key object"); throw new GradleException("Missing api_key/current_key object"); }
private static void deleteFolder(final File folder) { if (!folder.exists()) { return; } File[] files = folder.listFiles(); if (files != null) { for (final File file : files) { if (file.isDirectory()) { deleteFolder(file); } else { if (!file.delete()) { throw new GradleException("Failed to delete: " + file); } } } } if (!folder.delete()) { throw new GradleException("Failed to delete: " + folder); } }
@Test public void testNoFlavor() { List<String> output = toStringList(GoogleServicesPlugin.getJsonLocations("release", null)); assertThat(output).contains("src/release"); }
/** * Finds a service by name in the client object. Returns null if the service is not found * or if the service is disabled. * * @param clientObject the json object that represents the client. * @param serviceName the service name * @return the service if found. */ private JsonObject getServiceByName(JsonObject clientObject, String serviceName) { JsonObject services = clientObject.getAsJsonObject("services"); if (services == null) return null; JsonObject service = services.getAsJsonObject(serviceName); if (service == null) return null; JsonPrimitive status = service.getAsJsonPrimitive("status"); if (status == null) return null; String statusStr = status.getAsString(); if (STATUS_DISABLED.equals(statusStr)) return null; if (!STATUS_ENABLED.equals(statusStr)) { getLogger().warn(String.format("Status with value '%1$s' for service '%2$s' is unknown", statusStr, serviceName)); return null; } return service; }
/** * find an item in the "client" array that match the package name of the app * * @param jsonObject the root json object. * @return a JsonObject representing the client entry or null if no match is found. */ private JsonObject getClientForPackageName(JsonObject jsonObject) { JsonArray array = jsonObject.getAsJsonArray("client"); if (array != null) { final int count = array.size(); for (int i = 0; i < count; i++) { JsonElement clientElement = array.get(i); if (clientElement == null || !clientElement.isJsonObject()) { continue; } JsonObject clientObject = clientElement.getAsJsonObject(); JsonObject clientInfo = clientObject.getAsJsonObject("client_info"); if (clientInfo == null) continue; JsonObject androidClientInfo = clientInfo.getAsJsonObject("android_client_info"); if (androidClientInfo == null) continue; JsonPrimitive clientPackageName = androidClientInfo.getAsJsonPrimitive("package_name"); if (clientPackageName == null) continue; if (getPackageName().equals(clientPackageName.getAsString())) { return clientObject; } } } return null; }
/** * Handle a client object for maps (@string/google_maps_key). * * @param clientObject the client Json object. * @throws IOException */ private void handleMapsService(JsonObject clientObject, Map<String, String> resValues) throws IOException { JsonObject mapsService = getServiceByName(clientObject, "maps_service"); if (mapsService == null) return; String apiKey = getAndroidApiKey(clientObject); if (apiKey != null) { resValues.put("google_maps_key", apiKey); return; } throw new GradleException("Missing api_key/current_key object"); }
@Test public void testNoFlavor() { List<String> output = toStringList(GoogleServicesPlugin.getJsonLocations("release", null)); assertThat(output).contains("src/release"); }
private void handleGoogleApiKey(JsonObject clientObject, Map<String, String> resValues) { String apiKey = getAndroidApiKey(clientObject); if (apiKey != null) { resValues.put("google_api_key", apiKey); // TODO: remove this once SDK starts to use google_api_key. resValues.put("google_crash_reporting_api_key", apiKey); return; } // if google_crash_reporting_api_key is missing. // throw new GradleException("Missing api_key/current_key object"); throw new GradleException("Missing api_key/current_key object"); }
private static void deleteFolder(final File folder) { if (!folder.exists()) { return; } File[] files = folder.listFiles(); if (files != null) { for (final File file : files) { if (file.isDirectory()) { deleteFolder(file); } else { if (!file.delete()) { throw new GradleException("Failed to delete: " + file); } } } } if (!folder.delete()) { throw new GradleException("Failed to delete: " + folder); } }
/** * Finds a service by name in the client object. Returns null if the service is not found or if * the service is disabled. * * @param clientObject the json object that represents the client. * @param serviceName the service name * @return the service if found. */ private JsonObject getServiceByName(JsonObject clientObject, String serviceName) { JsonObject services = clientObject.getAsJsonObject("services"); if (services == null) return null; JsonObject service = services.getAsJsonObject(serviceName); if (service == null) return null; JsonPrimitive status = service.getAsJsonPrimitive("status"); if (status == null) return null; String statusStr = status.getAsString(); if (STATUS_DISABLED.equals(statusStr)) return null; if (!STATUS_ENABLED.equals(statusStr)) { getLogger() .warn( String.format( "Status with value '%1$s' for service '%2$s' is unknown", statusStr, serviceName)); return null; } return service; }
/** * find an item in the "client" array that match the package name of the app * * @param jsonObject the root json object. * @return a JsonObject representing the client entry or null if no match is found. */ private JsonObject getClientForPackageName(JsonObject jsonObject) { JsonArray array = jsonObject.getAsJsonArray("client"); if (array != null) { final int count = array.size(); for (int i = 0; i < count; i++) { JsonElement clientElement = array.get(i); if (clientElement == null || !clientElement.isJsonObject()) { continue; } JsonObject clientObject = clientElement.getAsJsonObject(); JsonObject clientInfo = clientObject.getAsJsonObject("client_info"); if (clientInfo == null) continue; JsonObject androidClientInfo = clientInfo.getAsJsonObject("android_client_info"); if (androidClientInfo == null) continue; JsonPrimitive clientPackageName = androidClientInfo.getAsJsonPrimitive("package_name"); if (clientPackageName == null) continue; if (getPackageName().equals(clientPackageName.getAsString())) { return clientObject; } } } return null; }
/** * Handle a client object for maps (@string/google_maps_key). * * @param clientObject the client Json object. * @throws IOException */ private void handleMapsService(JsonObject clientObject, Map<String, String> resValues) throws IOException { JsonObject mapsService = getServiceByName(clientObject, "maps_service"); if (mapsService == null) return; String apiKey = getAndroidApiKey(clientObject); if (apiKey != null) { resValues.put("google_maps_key", apiKey); return; } throw new GradleException("Missing api_key/current_key object"); }
@Test public void testOneFlavor() { List<String> output = toStringList(GoogleServicesPlugin.getJsonLocations("flavor/release", null)); assertThat(output) .containsAllOf( "src/release", "src/flavorRelease", "src/flavor", "src/flavor/release", "src/release/flavor"); }
private void handleGoogleApiKey(JsonObject clientObject, Map<String, String> resValues) { String apiKey = getAndroidApiKey(clientObject); if (apiKey != null) { resValues.put("google_api_key", apiKey); // TODO: remove this once SDK starts to use google_api_key. resValues.put("google_crash_reporting_api_key", apiKey); return; } // if google_crash_reporting_api_key is missing. // throw new GradleException("Missing api_key/current_key object"); throw new GradleException("Missing api_key/current_key object"); }
private static void deleteFolder(final File folder) { if (!folder.exists()) { return; } File[] files = folder.listFiles(); if (files != null) { for (final File file : files) { if (file.isDirectory()) { deleteFolder(file); } else { if (!file.delete()) { throw new GradleException("Failed to delete: " + file); } } } } if (!folder.delete()) { throw new GradleException("Failed to delete: " + folder); } } }
/** * Finds a service by name in the client object. Returns null if the service is not found or if * the service is disabled. * * @param clientObject the json object that represents the client. * @param serviceName the service name * @return the service if found. */ private JsonObject getServiceByName(JsonObject clientObject, String serviceName) { JsonObject services = clientObject.getAsJsonObject("services"); if (services == null) return null; JsonObject service = services.getAsJsonObject(serviceName); if (service == null) return null; JsonPrimitive status = service.getAsJsonPrimitive("status"); if (status == null) return null; String statusStr = status.getAsString(); if (STATUS_DISABLED.equals(statusStr)) return null; if (!STATUS_ENABLED.equals(statusStr)) { getLogger() .warn( String.format( "Status with value '%1$s' for service '%2$s' is unknown", statusStr, serviceName)); return null; } return service; }
@Test public void testOneFlavor() { List<String> output = toStringList(GoogleServicesPlugin.getJsonLocations("flavor/release", null)); assertThat(output) .containsAllOf( "src/release", "src/flavorRelease", "src/flavor", "src/flavor/release", "src/release/flavor"); }
@Test public void testMultipleFlavors() { List<String> output = toStringList(GoogleServicesPlugin.getJsonLocations("flavorTest/release", null)); assertThat(output) .containsAllOf( "src/release", "src/flavorRelease", "src/flavor", "src/flavor/release", "src/release/flavorTest", "src/flavorTest", "src/flavorTestRelease", "src/flavor/test/release", "src/flavor/testRelease"); }
@Test public void testMultipleFlavors() { List<String> output = toStringList(GoogleServicesPlugin.getJsonLocations("flavorTest/release", null)); assertThat(output) .containsAllOf( "src/release", "src/flavorRelease", "src/flavor", "src/flavor/release", "src/release/flavorTest", "src/flavorTest", "src/flavorTestRelease", "src/flavor/test/release", "src/flavor/testRelease"); }