|
4 | 4 |
|
5 | 5 | def isWinOs = System.properties['os.name'].toLowerCase().contains('windows') |
6 | 6 |
|
7 | | -def bgRootDir = "$rootDir/build-tools/android-static-binding-generator" |
8 | | -def astParserDir = "$bgRootDir/ast-parser" |
9 | | -def interfaceNamesFilePath = "$bgRootDir/interfaces-names.txt" |
10 | | -def bindingsFilePath = "$bgRootDir/bindings.txt" |
11 | | -def cachedJarsFilePath = "$bgRootDir/cached.dat" |
| 7 | +def astParserDir = "$projectDir/ast-parser" |
| 8 | +def interfaceNamesFilePath = "$projectDir/interfaces-names.txt" |
| 9 | +def bindingsFilePath = "$projectDir/bindings.txt" |
| 10 | +def cachedJarsFilePath = "$projectDir/cached.txt" |
12 | 11 |
|
13 | | -def absoluteOutDir = "$rootDir/$project.outDir" |
14 | | -def absoluteJsCodeDir = "$rootDir/$project.jsCodeDir" |
| 12 | +def shouldRun = true |
| 13 | +def absoluteOutDir = project.outDir |
| 14 | +def absoluteJsCodeDir = project.jsCodeDir |
15 | 15 |
|
16 | 16 | // depends on passed jars and generated interface-names |
17 | | -task generateInterfaceNamesList(type: JavaExec) { |
18 | | - def cachedJars = new File(cachedJarsFilePath) |
19 | | - |
20 | | - inputs.file(cachedJars) |
21 | | - outputs.files(interfaceNamesFilePath) |
22 | | - |
| 17 | +task generateInterfaceNamesList() { |
23 | 18 | doFirst { |
24 | | - main "-jar" |
25 | | - |
26 | | - def jarsAsStr = rootProject.jarFiles.toString(); |
27 | | - def jarsArr = jarsAsStr.replaceAll(/[\[\]]/, "").split(", ") |
28 | | - |
29 | | - def str = new LinkedList <String> (); |
30 | | - str.add("interfacenamegenerator.jar") |
31 | | - str.addAll(jarsArr) |
| 19 | + def current = project.jarFiles |
| 20 | + def cache = new File(cachedJarsFilePath) |
| 21 | + def utf8 = java.nio.charset.StandardCharsets.UTF_8 |
| 22 | + if (cache.exists()) { |
| 23 | + def contents = new String(java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(cachedJarsFilePath)), utf8).trim() |
| 24 | + shouldRun = !contents.equals(current.toString()) |
| 25 | + } |
| 26 | + |
| 27 | + if (shouldRun) { |
| 28 | + javaexec { |
| 29 | + main "-jar" |
| 30 | + |
| 31 | + def jarsAsStr = current.toString(); |
| 32 | + def jarsArr = jarsAsStr.replaceAll(/[\[\]]/, "").split(", ") |
| 33 | + |
| 34 | + def str = new LinkedList <String> (); |
| 35 | + str.add("interfacenamegenerator.jar") |
| 36 | + str.addAll(jarsArr) |
32 | 37 |
|
33 | | - args str.toArray() |
34 | | - |
35 | | - cachedJars.text = jarsAsStr |
| 38 | + args str.toArray() |
| 39 | + } |
| 40 | + java.nio.file.Files.write(java.nio.file.Paths.get(cachedJarsFilePath), [current.toString()], utf8) |
| 41 | + } |
36 | 42 | } |
37 | 43 | } |
38 | 44 |
|
39 | 45 | // won't run if node_modules are installed |
40 | | -task runNpmInstallForAstParser (type: Exec) { |
41 | | - |
42 | | - //check this way so it doesn't slow down the build by snapshot-ing the node_modules |
43 | | - outputs.upToDateWhen { |
44 | | - (new File("$astParserDir/node_modules")).exists() |
45 | | - } |
| 46 | +task runNpmInstallForAstParser () { |
| 47 | + doFirst { |
| 48 | + if (shouldRun) { |
| 49 | + exec { |
| 50 | + workingDir astParserDir |
46 | 51 |
|
47 | | - workingDir astParserDir |
48 | | - |
49 | | - if(isWinOs) { |
50 | | - commandLine "cmd", "/c", "npm", "install" |
51 | | - } |
52 | | - else { |
53 | | - commandLine "npm", "install" |
| 52 | + if(isWinOs) { |
| 53 | + commandLine "cmd", "/c", "npm", "install" |
| 54 | + } |
| 55 | + else { |
| 56 | + commandLine "npm", "install" |
| 57 | + } |
| 58 | + } |
| 59 | + } |
54 | 60 | } |
55 | 61 | } |
56 | 62 |
|
57 | 63 | // if there are new dependencies the parser will run again |
58 | | -task runAstParser (type: Exec) { |
59 | | - |
60 | | - inputs.files fileTree(dir: absoluteJsCodeDir) |
61 | | - outputs.files(bindingsFilePath) |
62 | | - |
63 | | - workingDir astParserDir |
64 | | - |
65 | | - if(isWinOs) { |
66 | | - commandLine "cmd", "/c", "node", "js_parser.js" , absoluteJsCodeDir, "../bindings.txt" |
67 | | - } |
68 | | - else { |
69 | | - commandLine "node", "js_parser.js", absoluteJsCodeDir, "../bindings.txt" |
| 64 | +task runAstParser () { |
| 65 | + doFirst { |
| 66 | + if (shouldRun) { |
| 67 | + exec { |
| 68 | + workingDir astParserDir |
| 69 | + |
| 70 | + if(isWinOs) { |
| 71 | + commandLine "cmd", "/c", "node", "js_parser.js" , absoluteJsCodeDir, "../bindings.txt" |
| 72 | + } |
| 73 | + else { |
| 74 | + commandLine "node", "js_parser.js", absoluteJsCodeDir, "../bindings.txt" |
| 75 | + } |
| 76 | + } |
| 77 | + } |
70 | 78 | } |
71 | 79 | } |
72 | | - |
73 | 80 | // run the static binding generator |
74 | | -task generateBindings(type: JavaExec) { |
75 | | - |
76 | | - inputs.files(bindingsFilePath) |
77 | | - outputs.dir(absoluteOutDir) |
78 | | - |
| 81 | +task generateBindings() { |
79 | 82 | doFirst { |
80 | | - main "-jar" |
81 | | - |
82 | | - def str = new LinkedList <String> (); |
83 | | - str.add("staticbindinggenerator.jar") |
84 | | - str.add(bindingsFilePath) |
85 | | - str.add(absoluteOutDir) |
86 | | - str.addAll(project.jarFiles) |
87 | | - |
88 | | - args str.toArray() |
| 83 | + if (shouldRun) { |
| 84 | + javaexec { |
| 85 | + main "-jar" |
| 86 | + |
| 87 | + def str = new LinkedList <String> (); |
| 88 | + str.add("staticbindinggenerator.jar") |
| 89 | + str.add(bindingsFilePath) |
| 90 | + str.add(absoluteOutDir) |
| 91 | + str.addAll(project.jarFiles) |
| 92 | + |
| 93 | + args str.toArray() |
| 94 | + } |
| 95 | + } |
89 | 96 | } |
90 | 97 | } |
91 | 98 |
|
|
0 commit comments