Use an iteration variable in walker

This commit is contained in:
Dan Hawkins 2021-12-21 17:14:26 +00:00
commit 902ec6591a

View file

@ -925,11 +925,41 @@ class MetaInfo extends GISJsonSerialised {
}
}
def openchildmeta(String gatheredpath, String gatheredmetapath, RelatedMetaInfo relatedmetainfo) {
class IterationInfo {
private ArrayList<CollectedMeta> metacollection
private String comment
private int level
private String gatheredpath
private String gatheredmetapath
private boolean limiteddepth
private int maxdepth
IterationInfo(ArrayList<CollectedMeta> metacollection = new ArrayList<CollectedMeta>(),
String comment = '',
int level = 0,
String gatheredpath = '',
String gatheredmetapath = '',
boolean limiteddepth = false,
int maxdepth = 0) {
this.metacollection = metacollection
this.comment = comment
this.level = level
this.gatheredpath = gatheredpath
this.gatheredmetapath = gatheredmetapath
this.limiteddepth = limiteddepth
this.maxdepth = maxdepth
}
String show() {
return "Iteration:\nLevel: ${level}\nGathered path: ${gatheredpath}\nGathered meta path: ${gatheredmetapath}\nLimited depth: ${limiteddepth}\nMax depth: ${maxdepth}"
}
}
def openchildmeta(IterationInfo ii, RelatedMetaInfo relatedmetainfo) {
def MetaInfo mi = new MetaInfo(script)
def String nextgatheredpath = (gatheredpath == '' ? relatedmetainfo.offsetpath : "${gatheredpath}/${relatedmetainfo.offsetpath}")
def String nextgatheredmetapath = (gatheredmetapath == '' ? "${relatedmetainfo.offsetpath}/${METAFOLDERNAME}" : "${gatheredmetapath}/${relatedmetainfo.offsetpath}")
def String nextgatheredpath = (ii.gatheredpath == '' ? relatedmetainfo.offsetpath : "${ii.gatheredpath}/${relatedmetainfo.offsetpath}")
def String nextgatheredmetapath = (ii.gatheredmetapath == '' ? "${relatedmetainfo.offsetpath}/${METAFOLDERNAME}" : "${ii.gatheredmetapath}/${relatedmetainfo.offsetpath}")
def importedmetafile = "${nextgatheredmetapath}/${METAFILENAME}"
def boolean imported
if (script.fileExists(importedmetafile)) {
@ -949,92 +979,79 @@ class MetaInfo extends GISJsonSerialised {
return childmetainfo
}
def walkrelated_v0_1(ArrayList<CollectedMeta> metacollection,
String comment = '',
int level = 0,
String gatheredpath = '',
String gatheredmetapath = '',
boolean limiteddepth = false,
int maxdepth = 0) {
script.echo("walkrelated_v0_1 Iteration:\nLevel: ${level}\nGathered path: ${gatheredpath}\nGathered meta path: ${gatheredmetapath}\nLimited depth: ${limiteddepth}\nMax depth: ${maxdepth}")
def results = [
'metacollection' : metacollection,
'comment': comment
]
if (!limiteddepth || maxdepth > 0) {
results.metacollection.add(new CollectedMeta(this, gatheredpath, gatheredmetapath))
results.comment += "${level} ".padRight(level * 4) + globalreleasetag() + '\n'
def walkrelated_v0_1(IterationInfo ii) {
script.echo("Walk related v0.1: ${ii.show()}")
if (!ii.limiteddepth || ii.maxdepth > 0) {
ii.metacollection.add(new CollectedMeta(this, ii.gatheredpath, ii.gatheredmetapath))
ii.comment += "${ii.level} ".padRight(ii.level * 4) + globalreleasetag() + '\n'
for (relatedmetainfo in associatedmeta) {
if (!relatedmetainfo.format || relatedmetainfo.format == '0.1') {
def MetaInfo othermeta = relatedmetainfo.meta
def String nextgatheredpath = (gatheredpath == '' ? relatedmetainfo.offsetpath : "${gatheredpath}/${relatedmetainfo.offsetpath}")
def String nextgatheredmetapath = (gatheredmetapath == '' ? relatedmetainfo.offsetpath : "${gatheredmetapath}/${relatedmetainfo.offsetpath}")
results = othermeta.walkrelated_v0_1(results.metacollection,
results.comment,
level + 1,
nextgatheredpath,
nextgatheredmetapath,
limiteddepth,
maxdepth - 1)
def String nextgatheredpath = (ii.gatheredpath == '' ? relatedmetainfo.offsetpath : "${ii.gatheredpath}/${relatedmetainfo.offsetpath}")
def String nextgatheredmetapath = (ii.gatheredmetapath == '' ? relatedmetainfo.offsetpath : "${ii.gatheredmetapath}/${relatedmetainfo.offsetpath}")
def nextii = new IterationInfo(ii.metacollection,
ii.comment,
ii.level + 1,
nextgatheredpath,
nextgatheredmetapath,
ii.limiteddepth
ii.maxdepth - 1)
def results = othermeta.walkrelated_v0_1(nextii)
ii.metacollection = results.metacollection
ii.comment = results.comment
} else {
script.error("There is non v0.1 format related meta info under v0.1 related meta info")
}
}
}
return [ 'metacollection' : results.metacollection, 'comment': results.comment ]
return [ 'metacollection' : ii.metacollection, 'comment': ii.comment ]
}
def walkrelated(ArrayList<CollectedMeta> metacollection,
String comment = '',
int level = 0,
String gatheredpath = '',
String gatheredmetapath = '',
boolean limiteddepth = false,
int maxdepth = 0) {
script.echo("walkrelated Iteration:\nLevel: ${level}\nGathered path: ${gatheredpath}\nGathered meta path: ${gatheredmetapath}\nLimited depth: ${limiteddepth}\nMax depth: ${maxdepth}")
def results = [
'metacollection' : metacollection,
'comment': comment
]
if (!limiteddepth || maxdepth > 0) {
results.metacollection.add(new CollectedMeta(this, gatheredpath, gatheredmetapath))
results.comment += "${level} ".padRight(level * 4) + globalreleasetag() + '\n'
def walkrelated(IterationInfo ii) {
script.echo("Walk related: ${ii.show()}")
if (!ii.limiteddepth || ii.maxdepth > 0) {
ii.metacollection.add(new CollectedMeta(this, ii.gatheredpath, ii.gatheredmetapath))
ii.comment += "${ii.level} ".padRight(ii.level * 4) + globalreleasetag() + '\n'
for (relatedmetainfo in associatedmeta) {
script.echo("Related meta info: ${relatedmetainfo.offsetpath} format: ${relatedmetainfo.format}")
if (relatedmetainfo.format == '0.2') {
def childmetainfo = openchildmeta(gatheredpath, gatheredmetapath, relatedmetainfo)
def childmetainfo = openchildmeta(ii, relatedmetainfo)
if (childmetainfo.imported) {
results = childmetainfo.childmeta.walkrelated(results.metacollection,
results.comment,
level + 1,
childmetainfo.nextgatheredpath,
childmetainfo.nextgatheredmetapath,
limiteddepth,
maxdepth - 1)
def nextii = new IterationInfo(ii.metacollection,
ii.comment,
ii.level + 1,
childmetainfo.nextgatheredpath,
childmetainfo.nextgatheredmetapath,
ii.limiteddepth
ii.maxdepth - 1)
def results = childmetainfo.childmeta.walkrelated(nextii)
ii.metacollection = results.metacollection
ii.comment = results.comment
}
} else if (!relatedmetainfo.format || relatedmetainfo.format == '0.1') {
def MetaInfo othermeta = relatedmetainfo.meta
results = othermeta.walkrelated_v0_1(results.metacollection,
results.comment,
level + 1,
gatheredpath,
gatheredmetapath,
limiteddepth,
maxdepth - 1)
def nextii = new IterationInfo(ii.metacollection,
ii.comment,
ii.level + 1,
ii.gatheredpath,
ii.gatheredmetapath,
ii.limiteddepth
ii.maxdepth - 1)
def results = othermeta.walkrelated_v0_1(nextii)
ii.metacollection = results.metacollection
ii.comment = results.comment
}
}
}
return [ 'metacollection' : results.metacollection, 'comment': results.comment ]
return [ 'metacollection' : ii.metacollection, 'comment': ii.comment ]
}
def allrelatedmeta(String metapath = '') {
ArrayList<CollectedMeta> metacollection = new ArrayList<CollectedMeta>()
return walkrelated(metacollection, '', 0, '', metapath)
return walkrelated(new IterationInfo(metacollection, '', 0, '', metapath))
}
ArrayList<CollectedMeta> releasewalker(int maxdepth, String startpath = '', String startmetapath = '') {
def ArrayList<CollectedMeta> metacollection = new ArrayList<CollectedMeta>()
def results = walkrelated(metacollection, 'meta', 0, startpath, startmetapath, true, maxdepth)
def results = walkrelated(new IterationInfo(metacollection, 'meta', 0, startpath, startmetapath, true, maxdepth))
return results.metacollection
}