| 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 |