forked from ProtocolSupport/ProtocolSupport
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhelper.gradle
82 lines (67 loc) · 2.24 KB
/
helper.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import java.text.MessageFormat
ext.newFile = {File parent, String... childs ->
for (String child : childs) {
parent = new File(parent, child);
}
return parent;
}
class UpdateLibrariesTask extends DefaultTask {
File directory
List<Map> libraries
Set<String> manualLibraries = new HashSet<>();
@TaskAction
def update() {
Set<String> librariesNames = new HashSet<>()
libraries.each({
String url = it.get("url")
String libraryName = it.get("name")
librariesNames.add(libraryName)
File libraryFile = new File(directory, libraryName)
if (!libraryFile.exists()) {
logger.lifecycle(MessageFormat.format("Downloading library {0} from {1}", libraryName, url))
ant.get(src: url, dest: libraryFile)
} else {
logger.lifecycle(MessageFormat.format("Skipping download of library {0} because it already exists", libraryName))
}
})
directory.listFiles()
.findAll({
!librariesNames.contains(it.getName()) && !manualLibraries.contains(it.getName())
})
.each({
logger.lifecycle(MessageFormat.format("Deleting old library {0}", it.getName()))
it.delete()
})
}
}
ext.UpdateLibrariesTask = UpdateLibrariesTask
class BuildLibraryTask extends DefaultTask {
File targetDirectory
String targetLibraryName
String builderUrl
String buildCommand
String[] builtLibraryName
String builderName = "library_builder"
@TaskAction
def update() {
File libraryFile = new File(targetDirectory, targetLibraryName)
File buildDirectory = new File(new File("build_libraries"), targetLibraryName)
buildDirectory.mkdirs()
if (!libraryFile.exists()) {
logger.lifecycle(MessageFormat.format("Building library {0} from {1}", targetLibraryName, builderUrl))
File builder = new File(buildDirectory, builderName)
ant.get(src: builderUrl, dest: builder)
getProject().exec {
workingDir = buildDirectory
commandLine = buildCommand.replace("{BUILDER}", builderName).split("\\s+")
}
java.nio.file.Files.copy(
getProject().newFile(buildDirectory, builtLibraryName).getAbsoluteFile().toPath(),
libraryFile.getAbsoluteFile().toPath()
)
} else {
logger.lifecycle(MessageFormat.format("Skipping building of library {0} because it already exists", targetLibraryName))
}
}
}
ext.BuildLibraryTask = BuildLibraryTask