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 8, 2024
1 parent 082ba97 commit 3efce11
Showing 1 changed file with 96 additions and 13 deletions.
109 changes: 96 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,97 @@ class ResourcesArchiveTask extends DefaultTask {
}
}

class INSPIREDownloadTask extends DefaultTask {
// the host that the resource bundle mirrors resources from
@Input
def host
// the remote URL to retrieve the resource ZIP archive from
@Input
def archiveUrl

@TaskAction
def downloadAndExtract() {
assert host
assert archiveUrl

// need a clean tmp dir
temporaryDir.deleteDir()
temporaryDir.mkdir()

// download archive
File tmpSchemas = new File(temporaryDir, 'schemas.zip')
project.download.run {
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 temporaryDir
}

/*
* The website does redirect for some schemas to a subfolder with older versions.
* For example `hy-p/3.0/HydroPhysicalWaters.xsd` is redirected to `2021.1/hy-p/3.0/HydroPhysicalWaters.xsd`
* The resource bundles don't know about these redirects, the file from the original folder is accessed.
* Loading the full schema may fail though, because some schema have been removed from the root and are only
* available in folders representing older versions.
* Examples:
* - `lc/0.0/LandCover.xsd`
* - `wfd/0.0/WaterFrameworkDirective.xsd`
*
* Since we don't know the exact redirection rules we attempt to have a copy of al schemas in the root, in
* their respective newest version, by copying newer versions over older versions.
*/

File applicationtempschemas = new File(temporaryDir, 'application-schemas-main')
File tempRoot = new File(applicationtempschemas, 'tmp-schemas')
def versions = ['2021.1', '2021.2', '2022.1', '2022.2']
// copy all versions in order
versions.each { v ->
project.copy {
from new File(applicationtempschemas, "schemas/$v")
into tempRoot
include '**/*'
}
}

project.copy {
from new File(applicationtempschemas, "schemas")
into tempRoot
include '**/*'
}

File applicationTempSchemasfolder = new File(applicationtempschemas, 'schemas')
applicationTempSchemasfolder.deleteDir()
File applicationTempSchemasfolderNew = new File(applicationtempschemas, 'schemas')
tempRoot.renameTo(applicationTempSchemasfolderNew)

// List all files in the subfolder
def files = applicationtempschemas.listFiles()

// Copy each file to the parent folder
files.each { file ->
def destination = new File(targetDir, file.name)
file.renameTo(destination)
}

// update version on change
md.setVersionIfChanged()
}
}

class WgetHostIndexDownloadTask extends DefaultTask {
// the list of URLs pointing to a web server index
@Input
Expand Down Expand Up @@ -515,21 +606,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) {
task inspireSchemas(type: INSPIREDownloadTask) {
group 'Download'
indexUrls = [
'https://inspire.ec.europa.eu/schemas/',
'https://inspire.ec.europa.eu/draft-schemas/'
]
fileExtensions = [
'xsd',
'xml',
'txt'
]
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 @@ -698,4 +781,4 @@ task('updateSite', type: GradleBuild) {
*/
task haleResourceBundles() {
//TODO separate task or adapt hale functionality to work with JARs built in jars task?
}
}

0 comments on commit 3efce11

Please sign in to comment.