Store offset paths relative to WORKSPACE if given as absolute paths

This commit is contained in:
Dan Hawkins 2018-11-23 19:54:32 +00:00
commit 5d333d926d

View file

@ -1,3 +1,5 @@
import java.nio.file.Paths
import java.nio.file.Path
abstract class GISJsonSerialised implements Serializable {
def script
@ -494,16 +496,27 @@ class MetaInfo extends GISJsonSerialised {
def rawmeta = script.readJSON(file: filepath)
deserialiseJson(rawmeta)
}
String relativize(String path) {
def Path thispath = Paths.get(path)
if (thispath.startsWith(script.WORKSPACE)) {
def Path wspath = Paths.get(script.WORKSPACE)
def Path wsrelativePath = wspath.relativize(thispath)
return wsrelativePath.toString()
}
return path
}
MetaInfo importrelated(String destpath) {
MetaInfo mi = new MetaInfo(script)
def importedmetafile = destpath + "/" + METAFOLDERNAME + "/" + METAFILENAME
def String adjustedpath = relativize(destpath)
def importedmetafile = adjustedpath + "/" + METAFOLDERNAME + "/" + METAFILENAME
if (script.fileExists(importedmetafile)) {
mi.deserialiseJson(importedmetafile)
}
RelatedMetaInfo rmi = new RelatedMetaInfo(script, destpath, mi)
RelatedMetaInfo rmi = new RelatedMetaInfo(script, adjustedpath, mi)
associatedmeta.add(rmi)
return mi