| import java.nio.file.Path |
| import java.nio.file.Paths |
| import java.nio.file.Files |
| import java.text.MessageFormat |
| |
| |
| class UpdateLibrariesTask extends DefaultTask { |
| Path 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) |
| |
| Path libraryFile = directory.resolve(libraryName) |
| if (Files.notExists(libraryFile)) { |
| 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)) |
| } |
| }) |
| |
| Files.list(directory) |
| .filter({ |
| String filename = it.getFileName().toString() |
| !librariesNames.contains(filename) && !manualLibraries.contains(filename) |
| }) |
| .each({ |
| logger.lifecycle(MessageFormat.format("Deleting old library {0}", it.getFileName())) |
| Files.delete(it) |
| }) |
| } |
| |
| } |
| |
| ext.UpdateLibrariesTask = UpdateLibrariesTask |
| |
| |
| class BuildLibraryTask extends DefaultTask { |
| Path targetDirectory |
| String targetLibraryName |
| String builderUrl |
| String buildCommand |
| String[] builtLibraryName |
| String builderName = "library_builder" |
| |
| @TaskAction |
| def update() { |
| Path libraryFile = targetDirectory.resolve(targetLibraryName) |
| Path buildDirectory = getProject().buildDir.toPath().toAbsolutePath().resolve("libraries").resolve(targetLibraryName) |
| Files.createDirectories(buildDirectory) |
| if (Files.notExists(libraryFile)) { |
| logger.lifecycle(MessageFormat.format("Building library {0} from {1}", targetLibraryName, builderUrl)) |
| ant.get(src: builderUrl, dest: buildDirectory.resolve(builderName)) |
| getProject().exec { |
| workingDir = buildDirectory.toFile() |
| commandLine = buildCommand.replace("{BUILDER}", builderName).split("\\s+") |
| } |
| Path builtLibraryFile = buildDirectory |
| for (String builtLibraryElementName : builtLibraryName) { |
| builtLibraryFile = builtLibraryFile.resolve(builtLibraryElementName) |
| } |
| Files.copy(builtLibraryFile, libraryFile) |
| } else { |
| logger.lifecycle(MessageFormat.format("Skipping building of library {0} because it already exists", targetLibraryName)) |
| } |
| } |
| } |
| |
| ext.BuildLibraryTask = BuildLibraryTask |