blob: a89801e460c73b06204bcdd955e7f084f440cff3 [file] [log] [blame] [raw]
import java.text.MessageFormat
class UpdateLibrariesTask extends DefaultTask {
File directory
List<Map> libraries
@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())
})
.each({
logger.lifecycle(MessageFormat.format("Deleting old library {0}", it.getName()))
it.delete()
})
}
}
ext.UpdateLibrariesTask = UpdateLibrariesTask