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,32 +137,34 @@ 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
+ }
152
149
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
+ }
170
168
}
171
169
}
172
170
@@ -187,7 +185,7 @@ task runAstParser(type: RunAstParserTask) {
187
185
// traverses the javascript code input directory
188
186
// 1. traverses all root directory files
189
187
// 2. all subdirectories that do not have a package.json containing a "nativescript" key are skipped
190
- task traverseJsFiles () {
188
+ task traverseJsFiles {
191
189
doFirst {
192
190
// invalidate previously generated bindings.txt file
193
191
// todo: remove when removing previously generated bindings is implemented
@@ -274,9 +272,10 @@ task generateBindings() {
274
272
inputs. dir (bindingsFile)
275
273
276
274
doFirst {
277
- if (! file(bindingsFileP). exists()) {
275
+ if (! file(bindingsFileP). exists()) {
278
276
throw new GradleException (" No ${ bindingsFileP} was found after runAstParser task was ran! Check to see if there are any .js files inside ${ jsCodeDir} " )
279
277
}
278
+
280
279
javaexec {
281
280
main " -jar"
282
281
@@ -285,7 +284,7 @@ task generateBindings() {
285
284
str. add(bindingsFileP)
286
285
str. add(absoluteOutDir)
287
286
288
- def jarsAsStr = current . toString();
287
+ def jarsAsStr = jarsList . toString();
289
288
def jarsArr = jarsAsStr. replaceAll(/ [\[\] ]/ , " " ). split(" , " )
290
289
str. addAll(jarsArr)
291
290
0 commit comments