Skip to content

Commit

Permalink
Merge changes from origin/feat/ING-3392
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuelaepure10 committed Jan 25, 2024
2 parents bec259a + c7dce97 commit e8843e3
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>offline-resources</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
104 changes: 104 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,110 @@ class XmlSchemaDownloadTask extends DefaultTask {
}
}

/*
* Common task definition for inspire
*/
class ResourceBundleTask 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
@Optional
def archiveUrl
// the local ZIP archive file containing the resources
@Input
@Optional
def archive
// the prefix for the symbolic name
@Input
def symbolicNamePrefix = 'eu.esdihumboldt.util.resource'
// the bundle identifier (is appended to prefix sepearate by a dot)
@Input
def bundleId
// the served resource type
@Input
def resourceType = 'xmlSchema'
// the destination dir
@Input
def destDir = project.buildDir
// extra content for the plugin.xml - must be a closure taking a markup builder as argument
@Internal
java.util.function.Consumer<groovy.xml.MarkupBuilder> pluginExtra

ResourceBundleTask() {
getOutputs().upToDateWhen {
// we don't support proper up-to-date checking here
false
}
}

@TaskAction
def createBundle() {
assert host
assert archiveUrl || archive
assert bundleId
assert symbolicNamePrefix
assert resourceType // the primary resource type
assert destDir

// schemas from schemas.opengis.net
def stamp = new Date().format('yyyy.MM.dd')
def version = stamp //"1.0.0.$stamp"
def symbolicName = "$symbolicNamePrefix.$bundleId"
File bundle = new File(destDir, "${symbolicName}_${version}.jar")

File tmpDir = temporaryDir //File.createTempFile('resources', 'bundle')
tmpDir.delete()
tmpDir.mkdir()

File tmpSchemas
if (archive) {
// use existing schema archive
tmpSchemas = archive as File
}
else {
// download schema archive
tmpSchemas = new File(tmpDir, 'schemas.zip')
project.download.run {
src archiveUrl
dest tmpSchemas
}
}

// create plugin.xml
File tmpPluginXml = new File(tmpDir, 'plugin.xml')
tmpPluginXml.withWriter {
it << '<?xml version="1.0"?>\n'
it << '<?eclipse version="3.4"?>\n'
def xml = new groovy.xml.MarkupBuilder(it)
xml.plugin {
extension(point: 'eu.esdihumboldt.util.resource') {
resolver(id: bundleId, resourceType: resourceType) {
xml.host(name: host)
bundleResolver()
}
}
if (pluginExtra != null) {
pluginExtra.accept(xml)
}
}
}

// build jar
ant.jar(destfile: bundle) {
zipfileset (src: tmpSchemas, excludes: '**/*.zip')
fileset (dir: tmpPluginXml.parentFile, includes: tmpPluginXml.name)
manifest {
attribute(name: 'Bundle-Version', value: version)
attribute(name: 'Bundle-Name', value: "Resources from $host")
attribute(name: 'Bundle-ManifestVersion', value: 2)
attribute(name: 'Bundle-SymbolicName', value: "$symbolicName;singleton:=true")
}
}
}
}


/**
* Dummy task for testing (changes result on every run)
Expand Down

0 comments on commit e8843e3

Please sign in to comment.