Skip to content

Commit 86b9d08

Browse files
committed
clean up after rebase to master
make plugin config tasks into functions which are called during gradle's config step
1 parent c290946 commit 86b9d08

File tree

3 files changed

+86
-105
lines changed

3 files changed

+86
-105
lines changed

android-static-binding-generator/project/build.gradle

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -155,23 +155,16 @@ task traverseJsFilesArgs { //(jsCodeDir, bindingsFilePath, interfaceNamesFilePat
155155
list.add(interfaceNamesFilePath)
156156
list.add(jsFilesParameter)
157157

158-
def list = new ArrayList<String>();
159-
list.add("node")
160-
list.add(jsParserPath)
161-
list.add(jsCodeDir)
162-
list.add(bindingsFilePath)
163-
list.add(interfaceNamesFilePath)
164-
list.add(jsFilesParameter)
165-
166-
logger.info("Task: traverseJsFilesArgs: executed with arguments: " + list.toString().replaceAll(',', ''))
167-
def proc = list.execute()
168-
proc.in.eachLine { line -> println line }
169-
proc.out.close()
170-
proc.waitFor()
171-
172-
if (proc.exitValue()) {
173-
println "gave the following error: "
174-
println "[ERROR] ${proc.getErrorStream()}"
158+
logger.info("Task: traverseJsFilesArgs: executed with arguments: " + list.toString().replaceAll(',', ''))
159+
def proc = list.execute()
160+
proc.in.eachLine { line -> println line }
161+
proc.out.close()
162+
proc.waitFor()
163+
164+
if (proc.exitValue()) {
165+
println "gave the following error: "
166+
println "[ERROR] ${proc.getErrorStream()}"
167+
}
175168
}
176169
}
177170

@@ -279,9 +272,10 @@ task generateBindings() {
279272
inputs.dir (bindingsFile)
280273

281274
doFirst {
282-
if(!file(bindingsFileP).exists()) {
275+
if (!file(bindingsFileP).exists()) {
283276
throw new GradleException("No ${bindingsFileP} was found after runAstParser task was ran! Check to see if there are any .js files inside ${jsCodeDir}")
284277
}
278+
285279
javaexec {
286280
main "-jar"
287281

android-static-binding-generator/project/parser/js_parser.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ function readLinesFromFile(filePath, outArr, resolveParameter) {
103103
return reject(err);
104104
}
105105

106-
console.log("finished with reading lines with js files");
107-
108106
return resolve(resolveParameter)
109107
});
110108
});

build-artifacts/project-template-gradle/build.gradle

Lines changed: 74 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,20 @@ def metadataParams = new LinkedList <String> ()
3939
def allJarPaths = new LinkedList <String> ()
4040
def configStage = "\tconfig phase: "
4141
def nodeModulesDir = "../../node_modules/"
42-
def configurationsDir = new File(projectDir, "build/configurations")
4342
def dependenciesJson = file("dependencies.json")
4443

4544
// the build script will not work with previous versions of the CLI (3.1 or earlier)
4645
if (!dependenciesJson.exists()) {
4746
throw new BuildCancelledException("""
4847
'dependencies.json' file not found. Check whether the NativeScript CLI has prepared the project beforehand,
49-
and that your NativeScript version is 3.2, or a more recent one. To build an android project with the current
50-
version of the {N} CLI install a previous version of the runtime package - 'tns platform add android@3.1'.
48+
and that your NativeScript version is 3.3, or a more recent one. To build an android project with the current
49+
version of the {N} CLI install a previous version of the runtime package - 'tns platform add android@3.2'.
5150
""")
5251
}
5352

5453
def nativescriptDependencies = new JsonSlurper().parseText(dependenciesJson.text)
5554

5655
def packageJsonContents = [:]
57-
def excludedDevDependencies = ['**/.bin/**']
5856

5957
def dontRunSbg = project.hasProperty("dontRunSbg");
6058
def asbgProject = project(":asbg")
@@ -81,25 +79,74 @@ def renameResultApks = { variant ->
8179
}
8280
}
8381

84-
// gets the devDependencies declared in the package.json and excludes them from the build
85-
task getDevDependencies {
86-
doLast {
87-
println "$configStage getDevDependencies"
82+
////////////////////////////////////////////////////////////////////////////////////
83+
///////////////////////////// CONFIGURATIONS ///////////////////////////////////////
84+
////////////////////////////////////////////////////////////////////////////////////
85+
86+
def applyPluginsIncludeGradleConfigurations = { ->
87+
def taskNames = project.getGradle().startParameter.taskNames
88+
89+
// don't apply plugin configurations if clean is invoked
90+
if (taskNames && taskNames.size() > 0 && taskNames.getAt(0).equals("clean")) {
91+
return []
92+
}
93+
94+
def configurationsDir = new File(projectDir, "build/configurations")
95+
configurationsDir.deleteDir()
96+
97+
def dimensions = []
98+
def includes = new ArrayList<String>()
99+
def flavorNumber = 0
100+
101+
nativescriptDependencies.each { dep ->
102+
def androidDir = file("${dep.directory}/platforms/android")
103+
if (!androidDir.exists()) {
104+
return
105+
}
106+
107+
def packageJsonPath = file("${dep.directory}/package.json")
108+
def packageJson = new JsonSlurper().parseText(packageJsonPath.text)
109+
def pluginName = packageJson.name
110+
def dimensionName = sanitizeDimensionName(pluginName)
88111

89-
String content = new File("$projectDir/../../package.json").getText("UTF-8")
90-
def jsonSlurper = new JsonSlurper()
91-
def packageJsonMap = jsonSlurper.parseText(content)
112+
dimensions.add(dimensionName)
113+
def flavor = "F${flavorNumber++}"
114+
115+
def includeGradleFile = new File(androidDir, "include.gradle")
116+
def destinationDir = file("${configurationsDir}/${pluginName}/")
117+
def destinationIncludeGradleFile = file("${configurationsDir}/${pluginName}/include.gradle")
92118

93-
packageJsonContents = packageJsonMap.devDependencies;
119+
Files.createDirectories(Paths.get(destinationDir.getAbsolutePath()))
94120

95-
packageJsonContents.each { entry ->
96-
excludedDevDependencies.add(entry.key + '/platforms/android/**/*.jar')
121+
if (includeGradleFile.exists()) {
122+
println "\t + add include.gradle from ${includeGradleFile}"
123+
destinationIncludeGradleFile.text = modifyProductFlavorInContent(includeGradleFile.text, dimensionName, flavor)
124+
} else {
125+
println "\t + creating include.gradle for plugin ${file(dep.directory)}"
126+
destinationIncludeGradleFile.text = createProductFlavorsContent(flavor, dimensionName)
97127
}
128+
129+
includes.add(destinationIncludeGradleFile.getAbsolutePath());
130+
131+
copyAndRenamePluginDirToFlavorName(androidDir, flavor);
132+
}
133+
134+
includes.each {
135+
println "\t + applying plugin configuration from ${it}"
136+
apply from: it
137+
}
138+
139+
return dimensions
140+
}
141+
142+
def applyAppGradleConfiguration = { ->
143+
def pathToAppGradle = "$projectDir/../../app/App_Resources/Android/app.gradle"
144+
def appGradle = file(pathToAppGradle)
145+
if (appGradle.exists()) {
146+
println "\t + applying user-defined configuration from ${appGradle}"
147+
apply from: pathToAppGradle
98148
}
99149
}
100-
////////////////////////////////////////////////////////////////////////////////////
101-
///////////////////////////// CONFIGURATIONS ///////////////////////////////////////
102-
////////////////////////////////////////////////////////////////////////////////////
103150

104151
android {
105152
compileSdkVersion computeCompileSdkVersion()
@@ -177,6 +224,12 @@ android {
177224
compileTask.dependsOn("asbg:generateBindings")
178225
}
179226
}
227+
228+
def dimensions = applyPluginsIncludeGradleConfigurations()
229+
230+
flavorDimensions(*dimensions)
231+
232+
applyAppGradleConfiguration()
180233
}
181234

182235
repositories {
@@ -204,9 +257,6 @@ dependencies {
204257

205258
// take all jars within the libs dir
206259
compile fileTree(dir: "$projectDir/libs", include: ["**/*.jar"])
207-
208-
// take all jars within the node_modules dir
209-
compile fileTree(dir: nodeModulesDir, include: ["**/platforms/android/**/*.jar"], exclude: excludedDevDependencies)
210260
}
211261

212262
////////////////////////////////////////////////////////////////////////////////////
@@ -245,67 +295,6 @@ task addDependenciesFromNativeScriptPlugins {
245295
}
246296
}
247297

248-
task applyPluginsIncludeGradleConfigurations {
249-
configurationsDir.deleteDir()
250-
251-
def dimensions = []
252-
def includes = new ArrayList<String>()
253-
def flavorNumber = 0
254-
255-
nativescriptDependencies.each { dep ->
256-
def androidDir = file("${dep.directory}/platforms/android")
257-
if (!androidDir.exists()) {
258-
return
259-
}
260-
261-
def packageJsonPath = file("${dep.directory}/package.json")
262-
def packageJson = new JsonSlurper().parseText(packageJsonPath.text)
263-
def pluginName = packageJson.name
264-
def dimensionName = sanitizeDimensionName(pluginName)
265-
266-
dimensions.add(dimensionName)
267-
def flavor = "F${flavorNumber++}"
268-
269-
def includeGradleFile = new File(androidDir, "include.gradle")
270-
def destinationDir = file("${configurationsDir}/${pluginName}/")
271-
def destinationIncludeGradleFile = file("${configurationsDir}/${pluginName}/include.gradle")
272-
273-
Files.createDirectories(Paths.get(destinationDir.getAbsolutePath()))
274-
275-
if (includeGradleFile.exists()) {
276-
println "\t + add include.gradle from ${includeGradleFile}"
277-
destinationIncludeGradleFile.text = modifyProductFlavorInContent(includeGradleFile.text, dimensionName, flavor)
278-
} else {
279-
println "\t + creating include.gradle for plugin ${file(dep.directory)}"
280-
destinationIncludeGradleFile.text = createProductFlavorsContent(flavor, dimensionName)
281-
}
282-
283-
includes.add(destinationIncludeGradleFile.getAbsolutePath());
284-
285-
copyAndRenamePluginDirToFlavorName(androidDir, flavor);
286-
}
287-
288-
flavorDimensions(*dimensions)
289-
290-
includes.each {
291-
println "\t + applying plugin configuration from ${it}"
292-
apply from: it
293-
}
294-
}
295-
296-
applyPluginsIncludeGradleConfigurations.finalizedBy(applyAppGradleConfiguration)
297-
298-
task applyAppGradleConfiguration {
299-
description "applies user-defined gradle configuration"
300-
301-
def pathToAppGradle = "$projectDir/../../app/App_Resources/Android/app.gradle"
302-
def appGradle = file(pathToAppGradle)
303-
if (appGradle.exists()) {
304-
println "\t + applying user-defined configuration from ${appGradle}"
305-
apply from: pathToAppGradle
306-
}
307-
}
308-
309298
static def updateProductFlavorsContent(flavor, dimensionName, oldContent) {
310299
def endIndex = oldContent.length() - 1;
311300
def index = 0;
@@ -476,15 +465,15 @@ def copyAndRenamePluginDirToFlavorName(directory, flavor) {
476465
copyFolder(directory, targetDir)
477466
}
478467

479-
////////////////////////////////////////////////////////////////////////////////////
480-
///////////////////////////// EXECUTUION PHASE /////////////////////////////////////
481-
////////////////////////////////////////////////////////////////////////////////////
482-
483468
task ensureMetadataOutDir {
484469
def outputDir = file("$projectDir/metadata/output/assets/metadata")
485470
outputDir.mkdirs()
486471
}
487472

473+
////////////////////////////////////////////////////////////////////////////////////
474+
///////////////////////////// EXECUTUION PHASE /////////////////////////////////////
475+
////////////////////////////////////////////////////////////////////////////////////
476+
488477
task collectAllJars {
489478
description "gathers all paths to jar dependencies before building metadata with them"
490479

0 commit comments

Comments
 (0)