4
4
5
5
import groovy.json.JsonSlurper
6
6
import groovy.io.FileType
7
+ import java.nio.charset.StandardCharsets
8
+ import java.nio.file.Files
9
+ import java.nio.file.Paths
7
10
8
- def isWinOs = System . properties[' os.name' ]. toLowerCase(). contains(' windows' )
9
-
10
- def astParserDir = " $projectDir /parser"
11
11
def interfaceNamesFileP = " $projectDir /interfaces-names.txt"
12
12
def bindingsFileP = " $projectDir /bindings.txt"
13
13
def cachedJarsFilePath = " $projectDir /cached.txt"
@@ -30,13 +30,12 @@ if (workersExcludeFile.exists()) {
30
30
def absoluteOutDir;
31
31
if (project. hasProperty(" outDir" )) {
32
32
absoluteOutDir = project. outDir;
33
-
33
+
34
34
if (! absoluteOutDir. exists()) {
35
35
absoluteOutDir. mkdirs()
36
36
}
37
37
}
38
38
39
-
40
39
// def absoluteJsCodeDir = new File("./jsCodeDir").getAbsolutePath()//project.jsCodeDir
41
40
def absoluteJsCodeDir;
42
41
def jsCodeAbsolutePath;
@@ -45,31 +44,30 @@ if (!project.hasProperty("test")) {
45
44
jsCodeAbsolutePath = absoluteJsCodeDir. getAbsolutePath()
46
45
}
47
46
48
- def utf8 = java.nio.charset. StandardCharsets. UTF_8
49
- def current = " "
47
+ def utf8 = StandardCharsets . UTF_8
48
+ def jarsList = " "
50
49
51
50
def shouldRun = true
52
51
def rootTraversed = false ;
53
52
def inputJsFiles = new LinkedList <String > ();
54
53
55
54
// depends on passed jars and generated interface-names
56
- task generateInterfaceNamesList () {
57
-
55
+ task generateInterfaceNamesList {
58
56
doFirst {
59
57
if (! project. hasProperty(" test" )) {
60
- current = project. jarFiles
58
+ jarsList = project. jarFiles
61
59
def cache = new File (cachedJarsFilePath)
62
-
60
+
63
61
if (cache. exists()) {
64
62
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())
66
64
}
67
65
68
66
if (shouldRun) {
69
67
javaexec {
70
68
main " -jar"
71
69
72
- def jarsAsStr = current . toString();
70
+ def jarsAsStr = jarsList . toString();
73
71
def jarsArr = jarsAsStr. replaceAll(/ [\[\] ]/ , " " ). split(" , " )
74
72
75
73
def str = new LinkedList <String > ();
@@ -80,7 +78,7 @@ task generateInterfaceNamesList() {
80
78
81
79
args str. toArray()
82
80
}
83
- java.nio.file. Files. write(java.nio.file. Paths. get(cachedJarsFilePath), [current . toString()], utf8)
81
+ Files . write(Paths . get(cachedJarsFilePath), [jarsList . toString()], utf8)
84
82
}
85
83
}
86
84
}
@@ -95,9 +93,7 @@ def isWorkerScript = { fileName ->
95
93
}
96
94
97
95
def traverseDirectory
98
-
99
96
traverseDirectory = { dir , traverseExplicitly ->
100
-
101
97
def currentDir = new File (dir)
102
98
def pJsonFile = false ;
103
99
@@ -141,14 +137,23 @@ traverseDirectory = { dir, traverseExplicitly ->
141
137
}
142
138
}
143
139
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 );
148
145
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
+ }
149
+
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)
152
157
153
158
def list = new ArrayList<String > ();
154
159
list. add(" node" )
@@ -187,7 +192,7 @@ task runAstParser(type: RunAstParserTask) {
187
192
// traverses the javascript code input directory
188
193
// 1. traverses all root directory files
189
194
// 2. all subdirectories that do not have a package.json containing a "nativescript" key are skipped
190
- task traverseJsFiles () {
195
+ task traverseJsFiles {
191
196
doFirst {
192
197
// invalidate previously generated bindings.txt file
193
198
// todo: remove when removing previously generated bindings is implemented
@@ -285,7 +290,7 @@ task generateBindings() {
285
290
str. add(bindingsFileP)
286
291
str. add(absoluteOutDir)
287
292
288
- def jarsAsStr = current . toString();
293
+ def jarsAsStr = jarsList . toString();
289
294
def jarsArr = jarsAsStr. replaceAll(/ [\[\] ]/ , " " ). split(" , " )
290
295
str. addAll(jarsArr)
291
296
0 commit comments