Skip to content

Commit

Permalink
feat: update download inspire schemas
Browse files Browse the repository at this point in the history
Update for using the new way of downloading the INSPIRE schemas.

ING-3392
  • Loading branch information
emanuelaepure10 committed Feb 5, 2024
1 parent faddb31 commit 975416c
Showing 1 changed file with 64 additions and 15 deletions.
79 changes: 64 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> indexUrls
Expand All @@ -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(',')
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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?
}
}

0 comments on commit 975416c

Please sign in to comment.