From 975416c24ba1f5cbf70270bc25a06197cc7a577a Mon Sep 17 00:00:00 2001 From: Emanuela Epure <67077116+emanuelaepure10@users.noreply.github.com> Date: Mon, 22 Jan 2024 10:28:00 +0100 Subject: [PATCH] feat: update download inspire schemas Update for using the new way of downloading the INSPIRE schemas. ING-3392 --- build.gradle | 79 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index 035d8c74..2eb77bdc 100644 --- a/build.gradle +++ b/build.gradle @@ -237,6 +237,63 @@ class ResourcesArchiveTask extends DefaultTask { } } +class INSPIREDownloadTask extends DefaultTask { + // the host that the resource bundle mirrors resources from + def host + // the remote URL to retrieve the resource ZIP archive from + def archiveUrl + + @TaskAction + def downloadAndExtract() { + assert host + assert archiveUrl + + inputs.property("archiveUrl", archiveUrl) // Declare archiveUrl as an input property + + // download archive + File tmpSchemas = new File(temporaryDir, 'schemas.zip') + project.download { + src archiveUrl + dest tmpSchemas + onlyIfModified true + } + File targetDir = project.file("${project.ext.hostsFolder}/$host") + // delete folder + targetDir.deleteDir() + targetDir.mkdirs() + + def md = new MetadataHelper(project, targetDir) + md.cleanFolderKeepMetadata() + + project.copy { + // Exclude Zip files, 'governance' folder, and 'readme.md' file + exclude('**/*.zip', 'application-schemas-main/governance-release-process/**', 'application-schemas-main/README.md', 'application-schemas-main/.github/**') + + from project.zipTree(tmpSchemas) + into targetDir + } + + File applicationSchemas = new File(targetDir, 'application-schemas-main') + // Check if the subfolder exists + if (applicationSchemas.exists() && applicationSchemas.isDirectory()) { + // List all files in the subfolder + def files = applicationSchemas.listFiles() + + // Copy each file to the parent folder + files.each { file -> + def destination = new File(targetDir, file.name) + file.renameTo(destination) + } + applicationSchemas.deleteDir() + } else { + println "Subfolder does not exist or is not a directory." + } + + // update version on change + md.setVersionIfChanged() + } + } + class WgetHostIndexDownloadTask extends DefaultTask { // the list of URLs pointing to a web server index List indexUrls @@ -263,7 +320,7 @@ class WgetHostIndexDownloadTask extends DefaultTask { project.exec { workingDir = targetDir executable = 'wget' // requires wget - def runArgs = ['-e', 'robots=off', '-r', '--no-parent', '--no-host-directories'] + def runArgs = ['-e', 'robots=off', '-r', '--no-parent', '--no-host-directories'] if (fileExtensions) { runArgs << '-A' runArgs << fileExtensions.join(',') @@ -486,21 +543,13 @@ tasks.downloads.dependsOn(porteleSchemas) /** * INSPIRE schemas */ -/* FIXME download of INSPIRE schemas is currently broken because of changes to how the schemas are served -task inspireSchemas(type: WgetHostIndexDownloadTask) { - group 'Download' - indexUrls = [ - 'https://inspire.ec.europa.eu/schemas/', - 'https://inspire.ec.europa.eu/draft-schemas/' - ] - fileExtensions = [ - 'xsd', - 'xml', - 'txt' - ] +task inspireSchemas(type: INSPIREDownloadTask) { + group 'Download' + host = "inspire.ec.europa.eu" + archiveUrl = "https://github.com/INSPIRE-MIF/application-schemas/archive/refs/heads/main.zip" } tasks.downloads.dependsOn(inspireSchemas) -*/ + /** * Schemas for metadata validation: @@ -643,4 +692,4 @@ task('publishJars', type: GradleBuild) { */ task haleResourceBundles() { //TODO separate task or adapt hale functionality to work with JARs built in jars task? -} +} \ No newline at end of file