Skip to content

Instantly share code, notes, and snippets.

@FrancescoJo
Created February 10, 2017 10:27
Show Gist options
  • Save FrancescoJo/6e46826a57bfe8bcf0a87842c50b6776 to your computer and use it in GitHub Desktop.
Save FrancescoJo/6e46826a57bfe8bcf0a87842c50b6776 to your computer and use it in GitHub Desktop.
import java.util.regex.Matcher
import java.util.regex.Pattern
// ext makes method callable project wide
ext.getCurrentFlavor = { ->
Gradle gradle = getGradle()
String tskReqStr = gradle.getStartParameter().getTaskRequests().toString()
Pattern pattern;
if (tskReqStr.contains("assemble"))
pattern = Pattern.compile("assemble(\\w+)(Release|Debug)")
else
pattern = Pattern.compile("generate(\\w+)(Release|Debug)")
Matcher matcher = pattern.matcher(tskReqStr)
if (matcher.find()) {
return matcher.group(1).toLowerCase()
} else {
return "";
}
}
ext.getCurrentBuildType = { ->
Gradle gradle = getGradle()
String tskReqStr = gradle.getStartParameter().getTaskRequests().toString()
if (tskReqStr.contains("Release")) {
return "release"
} else if (tskReqStr.contains("generateDebug")) {
return "debug"
}
return "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment