Skip to content

Commit 9cc90f0

Browse files
author
Mihail Slavchev
committed
merge
1 parent 7970b93 commit 9cc90f0

2 files changed

Lines changed: 94 additions & 4 deletions

File tree

build/project-template-gradle/build.gradle

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ apply plugin: "com.android.application"
3333
def isWinOs = System.properties['os.name'].toLowerCase().contains('windows')
3434
def metadataParams = new LinkedList <String> ()
3535
def allJarPaths = new LinkedList <String> ()
36+
def configurationsDir = "configurations"
3637
def createPluginConfigFile = false
3738
def configStage = "\n:config phase: "
3839
def nodeModulesDir = "../../node_modules/"
@@ -180,15 +181,103 @@ dependencies {
180181
///////////////////////////// CONFIGURATION PHASE //////////////////////////////////
181182
////////////////////////////////////////////////////////////////////////////////////
182183

184+
def createIncludeFile (filePath, fileName, dimensionName) {
185+
println "\t+creating include.gradle file for: " + filePath
186+
def defaultIncludeFile = new File(filePath, "include.gradle")
187+
defaultIncludeFile.write ""
188+
defaultIncludeFile << "android { \n"
189+
defaultIncludeFile << "\tproductFlavors {\n"
190+
defaultIncludeFile << '\t\t"' + fileName + '" {\n'
191+
defaultIncludeFile << '\t\t\tdimension "' + dimensionName + '"\n'
192+
defaultIncludeFile << "\t\t}\n"
193+
defaultIncludeFile << "\t}\n"
194+
defaultIncludeFile << "}"
195+
}
196+
197+
def sanatizeDimensionName(str) {
198+
return str.replaceAll(/\W/, "")
199+
}
200+
201+
//make sure the include.gradle file, produced by the user, has only allowed characters in dimension attribute and remove any invalid characters if necessary
202+
def updateIncludeGradleFile(subFile, dimensionName) {
203+
def igFile = new File(subFile.getAbsolutePath())
204+
def newContent = igFile.text.replaceAll(/dimension\s+["'](.+?)["']/) { fullMatch, fDimension ->
205+
def newFg = sanatizeDimensionName(fDimension)
206+
dimensionName = newFg
207+
return "dimension \"$newFg\""
208+
}
209+
igFile.text = newContent
210+
211+
return dimensionName
212+
}
213+
214+
task createDefaultIncludeFiles {
215+
description "creates default include.gradle files for added plugins IF NECESSARY"
216+
println "$configStage createDefaultIncludeFiles"
217+
def ft = file(configurationsDir)
218+
219+
ft.listFiles().each { fl ->
220+
221+
if(fl.isDirectory()) {
222+
def fileName = fl.name
223+
def dimensionName = sanatizeDimensionName(fileName)
224+
createPluginConfigFile = true
225+
def foundIncludeFile = false
226+
227+
println "\t+found plugins: " + fileName
228+
fl.listFiles().each { subFile ->
229+
230+
if(subFile.name == "include.gradle") {
231+
foundIncludeFile = true
232+
dimensionName = updateIncludeGradleFile(subFile, dimensionName)
233+
}
234+
}
235+
236+
pluginNames.add('"' + dimensionName + '"')
237+
238+
if(!foundIncludeFile) {
239+
createIncludeFile(fl.getAbsolutePath() ,fileName, dimensionName)
240+
}
241+
}
242+
}
243+
}
183244

245+
task createPluginsConfigFile {
246+
description "creates product flavor config file based on what plugins are added"
247+
248+
if(configDir.exists()) {
249+
println "$configStage createPluginsConfigFile"
250+
251+
def flavorsFile = new File("$configurationsDir/include.gradle")
252+
flavorsFile.write "" //clear config file
253+
254+
if(createPluginConfigFile) {
255+
println "\t+creating product flavors include.gradle file in $configurationsDir folder..."
256+
def flavors = pluginNames.join(",")
257+
258+
flavorsFile << "android { \n"
259+
flavorsFile << "\tflavorDimensions " + flavors + "\n"
260+
flavorsFile << "}\n"
261+
}
262+
}
263+
}
184264

185265
task pluginExtend {
186266
description "applies additional configuration"
187267

188-
configDir.eachFileRecurse(groovy.io.FileType.FILES) {
189-
if(it.name.equals('include.gradle')) {
190-
println "\t+applying configuration from: " + it
191-
apply from: it
268+
def pathToAppGradle = "../../app/App_Resources/Android/app.gradle"
269+
def appGradle = file(pathToAppGradle)
270+
if(appGradle.exists()) {
271+
apply from: pathToAppGradle
272+
}
273+
274+
if(configDir.exists()) {
275+
println "$configStage pluginExtend"
276+
configDir.eachFileRecurse(groovy.io.FileType.FILES) {
277+
if(it.name.equals('include.gradle')) {
278+
println "\t+applying configuration from: " + it
279+
apply from: it
280+
}
192281
}
193282
}
194283
}

build/project-template-gradle/src/main/java/com/tns/RuntimeHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.os.Handler;
88
import android.os.Looper;
99
import android.util.Log;
10+
import java.io.IOException;
1011

1112
public class RuntimeHelper
1213
{

0 commit comments

Comments
 (0)