Skip to content

Commit 2941625

Browse files
authored
Merge pull request #798 from NativeScript/refactor-include-gradle
Refactor include gradle
2 parents 8d72fb3 + 86b9d08 commit 2941625

File tree

5 files changed

+247
-387
lines changed

5 files changed

+247
-387
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ bin/
2121
.DS_Store
2222
.settings
2323

24-
build-artifacts/
24+
*.iml

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

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
import groovy.json.JsonSlurper
66
import groovy.io.FileType
7+
import java.nio.charset.StandardCharsets
8+
import java.nio.file.Files
9+
import java.nio.file.Paths
710

8-
def isWinOs = System.properties['os.name'].toLowerCase().contains('windows')
9-
10-
def astParserDir = "$projectDir/parser"
1111
def interfaceNamesFileP = "$projectDir/interfaces-names.txt"
1212
def bindingsFileP = "$projectDir/bindings.txt"
1313
def cachedJarsFilePath = "$projectDir/cached.txt"
@@ -30,13 +30,12 @@ if (workersExcludeFile.exists()) {
3030
def absoluteOutDir;
3131
if (project.hasProperty("outDir")) {
3232
absoluteOutDir = project.outDir;
33-
33+
3434
if (!absoluteOutDir.exists()) {
3535
absoluteOutDir.mkdirs()
3636
}
3737
}
3838

39-
4039
// def absoluteJsCodeDir = new File("./jsCodeDir").getAbsolutePath()//project.jsCodeDir
4140
def absoluteJsCodeDir;
4241
def jsCodeAbsolutePath;
@@ -45,31 +44,30 @@ if (!project.hasProperty("test")) {
4544
jsCodeAbsolutePath = absoluteJsCodeDir.getAbsolutePath()
4645
}
4746

48-
def utf8 = java.nio.charset.StandardCharsets.UTF_8
49-
def current = ""
47+
def utf8 = StandardCharsets.UTF_8
48+
def jarsList = ""
5049

5150
def shouldRun = true
5251
def rootTraversed = false;
5352
def inputJsFiles = new LinkedList <String> ();
5453

5554
// depends on passed jars and generated interface-names
56-
task generateInterfaceNamesList() {
57-
55+
task generateInterfaceNamesList {
5856
doFirst {
5957
if(!project.hasProperty("test")) {
60-
current = project.jarFiles
58+
jarsList = project.jarFiles
6159
def cache = new File(cachedJarsFilePath)
62-
60+
6361
if (cache.exists()) {
6462
def contents = new String(java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(cachedJarsFilePath)), utf8).trim()
65-
shouldRun = !contents.equals(current.toString())
63+
shouldRun = !contents.equals(jarsList.toString())
6664
}
6765

6866
if (shouldRun) {
6967
javaexec {
7068
main "-jar"
7169

72-
def jarsAsStr = current.toString();
70+
def jarsAsStr = jarsList.toString();
7371
def jarsArr = jarsAsStr.replaceAll(/[\[\]]/, "").split(", ")
7472

7573
def str = new LinkedList <String> ();
@@ -80,7 +78,7 @@ task generateInterfaceNamesList() {
8078

8179
args str.toArray()
8280
}
83-
java.nio.file.Files.write(java.nio.file.Paths.get(cachedJarsFilePath), [current.toString()], utf8)
81+
Files.write(Paths.get(cachedJarsFilePath), [jarsList.toString()], utf8)
8482
}
8583
}
8684
}
@@ -95,9 +93,7 @@ def isWorkerScript = { fileName ->
9593
}
9694

9795
def traverseDirectory
98-
9996
traverseDirectory = { dir, traverseExplicitly ->
100-
10197
def currentDir = new File(dir)
10298
def pJsonFile = false;
10399

@@ -141,32 +137,34 @@ traverseDirectory = { dir, traverseExplicitly ->
141137
}
142138
}
143139

144-
task traverseJsFilesArgs << { //(jsCodeDir, bindingsFilePath, interfaceNamesFilePath, jsParserPath, jsFilesParameter) {
145-
jsCodeAbsolutePath = jsCodeDir;
146-
inputJsFiles = new LinkedList<String>();
147-
traverseDirectory(jsCodeDir, false);
140+
task traverseJsFilesArgs { //(jsCodeDir, bindingsFilePath, interfaceNamesFilePath, jsParserPath, jsFilesParameter) {
141+
doLast {
142+
jsCodeAbsolutePath = jsCodeDir;
143+
inputJsFiles = new LinkedList<String>();
144+
traverseDirectory(jsCodeDir, false);
148145

149-
new File(jsFilesParameter).withWriter { out ->
150-
inputJsFiles.each {out.println it}
151-
}
146+
new File(jsFilesParameter).withWriter { out ->
147+
inputJsFiles.each {out.println it}
148+
}
152149

153-
def list = new ArrayList<String>();
154-
list.add("node")
155-
list.add(jsParserPath)
156-
list.add(jsCodeDir)
157-
list.add(bindingsFilePath)
158-
list.add(interfaceNamesFilePath)
159-
list.add(jsFilesParameter)
160-
161-
logger.info("Task: traverseJsFilesArgs: executed with arguments: " + list.toString().replaceAll(',', ''))
162-
def proc = list.execute()
163-
proc.in.eachLine { line -> println line }
164-
proc.out.close()
165-
proc.waitFor()
166-
167-
if (proc.exitValue()) {
168-
println "gave the following error: "
169-
println "[ERROR] ${proc.getErrorStream()}"
150+
def list = new ArrayList<String>();
151+
list.add("node")
152+
list.add(jsParserPath)
153+
list.add(jsCodeDir)
154+
list.add(bindingsFilePath)
155+
list.add(interfaceNamesFilePath)
156+
list.add(jsFilesParameter)
157+
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+
}
170168
}
171169
}
172170

@@ -187,7 +185,7 @@ task runAstParser(type: RunAstParserTask) {
187185
// traverses the javascript code input directory
188186
// 1. traverses all root directory files
189187
// 2. all subdirectories that do not have a package.json containing a "nativescript" key are skipped
190-
task traverseJsFiles () {
188+
task traverseJsFiles {
191189
doFirst {
192190
// invalidate previously generated bindings.txt file
193191
// todo: remove when removing previously generated bindings is implemented
@@ -274,9 +272,10 @@ task generateBindings() {
274272
inputs.dir (bindingsFile)
275273

276274
doFirst {
277-
if(!file(bindingsFileP).exists()) {
275+
if (!file(bindingsFileP).exists()) {
278276
throw new GradleException("No ${bindingsFileP} was found after runAstParser task was ran! Check to see if there are any .js files inside ${jsCodeDir}")
279277
}
278+
280279
javaexec {
281280
main "-jar"
282281

@@ -285,7 +284,7 @@ task generateBindings() {
285284
str.add(bindingsFileP)
286285
str.add(absoluteOutDir)
287286

288-
def jarsAsStr = current.toString();
287+
def jarsAsStr = jarsList.toString();
289288
def jarsArr = jarsAsStr.replaceAll(/[\[\]]/, "").split(", ")
290289
str.addAll(jarsArr)
291290

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-tools/runtime-modules/runtime/build.gradle

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)