Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only add google to build.grade if it is missing. #894

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions scripts/android/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ function addRepos(buildGradle) {
// modify the actual line
buildGradle = buildGradle.replace(/^(\s*)jcenter\(\)/m, modifiedLine);

var googlesMavenRepo = whitespace + 'google() // Google\'s Maven repository from cordova-plugin-firebase';
// Only add Google's Maven repo if it's not already there
var googleRepoAlreadyExists = buildGradle.test(/(google\(\))|(https:\/\/maven\.google\.com)/m);
if (googleRepoAlreadyExists) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of setting the variable twice, along with running regex and string replacement, why don't we wrap the change to only run the code if !googleRepoAlreadyExists? This will reduce code complexity and improve performance.

googlesMavenRepo = "";
}

// update the all projects grouping
var allProjectsIndex = buildGradle.indexOf('allprojects');
if (allProjectsIndex > 0) {
Expand All @@ -56,7 +63,6 @@ function addRepos(buildGradle) {

// Add google() to the allprojects section of the string
match = secondHalfOfFile.match(/^(\s*)jcenter\(\)/m);
var googlesMavenRepo = whitespace + 'google() // Google\'s Maven repository from cordova-plugin-firebase';
modifiedLine = match[0] + '\n' + googlesMavenRepo;
// modify the part of the string that is after 'allprojects'
secondHalfOfFile = secondHalfOfFile.replace(/^(\s*)jcenter\(\)/m, modifiedLine);
Expand All @@ -66,7 +72,6 @@ function addRepos(buildGradle) {
} else {
// this should not happen, but if it does, we should try to add the dependency to the buildscript
match = buildGradle.match(/^(\s*)jcenter\(\)/m);
var googlesMavenRepo = whitespace + 'google() // Google\'s Maven repository from cordova-plugin-firebase';
modifiedLine = match[0] + '\n' + googlesMavenRepo;
// modify the part of the string that is after 'allprojects'
buildGradle = buildGradle.replace(/^(\s*)jcenter\(\)/m, modifiedLine);
Expand Down