Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions google-services-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {
implementation 'com.google.android.gms:strict-version-matcher-plugin:1.2.4'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.google.guava:guava:27.0.1-jre'
implementation 'org.apache.commons:commons-lang3:3.12.0'
testImplementation 'junit:junit:4.12'
testImplementation 'com.google.truth:truth:0.42'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ class GoogleServicesPlugin implements Plugin<Project> {
"com.android.model.application"
]),
MODEL_LIBRARY(["com.android.model.library"])
public PluginType(Collection plugins) {

PluginType(Collection plugins) {
this.plugins = plugins
}
private final Collection plugins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import org.apache.commons.lang3.StringUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.file.DirectoryProperty;
Expand Down Expand Up @@ -458,20 +459,20 @@ private static long countSlashes(String input) {

static List<String> getJsonLocations(String buildType, List<String> flavorNames) {
List<String> fileLocations = new ArrayList<>();
String flavorName = flavorNames.stream().reduce("", (a,b) -> a + (a.length() == 0 ? b : capitalize(b)));
String flavorName = flavorNames.stream().reduce("", (a, b) -> a + (a.length() == 0 ? b : StringUtils.capitalize(b)));
fileLocations.add("");
fileLocations.add("src/" + flavorName + "/" + buildType);
fileLocations.add("src/" + buildType + "/" + flavorName);
fileLocations.add("src/" + flavorName);
fileLocations.add("src/" + buildType);
fileLocations.add("src/" + flavorName + capitalize(buildType));
fileLocations.add("src/" + flavorName + StringUtils.capitalize(buildType));
fileLocations.add("src/" + buildType);
String fileLocation = "src";
for(String flavor : flavorNames) {
fileLocation += "/" + flavor;
fileLocations.add(fileLocation);
fileLocations.add(fileLocation + "/" + buildType);
fileLocations.add(fileLocation + capitalize(buildType));
fileLocations.add(fileLocation + StringUtils.capitalize(buildType));
}
fileLocations = fileLocations
.stream()
Expand All @@ -481,9 +482,4 @@ static List<String> getJsonLocations(String buildType, List<String> flavorNames)
.collect(toList());
return fileLocations;
}

public static String capitalize(String s) {
if (s.length() == 0) return s;
return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think rewriting this method to just use:

  return s.substring(0, 1).toUpperCase() + s.substring(1);

is more reasonable than taking on the dependency on org.apache.commons:commons-lang3 and increases the chances of this getting merged.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ public void testMultipleFlavors() {
"src/flavor/testRelease/google-services.json");
}

@Test
public void testMultipleFlavorsWithCamelCase() {
List<String> output =
toStringList(GoogleServicesTask.getJsonLocations("release", Arrays.asList("flavor", "testTest")));
assertThat(output)
.containsAllOf(
"google-services.json",
"src/release/google-services.json",
"src/flavorRelease/google-services.json",
"src/flavor/google-services.json",
"src/flavor/release/google-services.json",
"src/release/flavorTestTest/google-services.json",
"src/flavorTestTest/google-services.json",
"src/flavorTestTestRelease/google-services.json",
"src/flavor/testTest/release/google-services.json",
"src/flavor/testTestRelease/google-services.json");
}


// This is necessary because some of the strings are actually groovy string implementations
// which fail equality tests with java strings during testing
private static List<String> toStringList(List<String> input) {
Expand Down