419 lines
12 KiB
Groovy
419 lines
12 KiB
Groovy
|
|
abstract class GISJsonSerialised implements Serializable {
|
|
def script
|
|
|
|
GISJsonSerialised(script) {
|
|
this.script = script
|
|
}
|
|
|
|
abstract LinkedHashMap serialisationdata();
|
|
|
|
def saveJsonSerialised(String outputfile, int prettylevel = 4) {
|
|
def outJson = script.readJSON text: groovy.json.JsonOutput.toJson(serialisationdata())
|
|
script.writeJSON(file: outputfile, json: outJson, pretty: prettylevel)
|
|
}
|
|
}
|
|
|
|
class ProductInfo extends GISJsonSerialised {
|
|
private String productname
|
|
private String subcomponentname
|
|
String jirakey
|
|
|
|
ProductInfo(script, productname = "", subcomponentname = "", jirakey = "") {
|
|
super(script)
|
|
this.productname = productname
|
|
this.subcomponentname = subcomponentname
|
|
this.jirakey = jirakey
|
|
}
|
|
|
|
void set(String productname, String subcomponentname, String jirakey) {
|
|
this.productname = productname
|
|
this.subcomponentname = subcomponentname
|
|
this.jirakey = jirakey
|
|
}
|
|
|
|
LinkedHashMap serialisationdata() {
|
|
def data = [
|
|
'productname' : productname,
|
|
'subcomponentname' : subcomponentname,
|
|
'jirakey' : jirakey,
|
|
]
|
|
return data
|
|
}
|
|
}
|
|
|
|
class GitInfo extends GISJsonSerialised {
|
|
private String sourcepath
|
|
private String sourcerevision
|
|
private String gitrevision
|
|
private String remoteurl
|
|
private String remoteinfo
|
|
|
|
GitInfo(script, sourcepath = "", sourcerevision = "", gitrevision = "", remoteurl = "", remoteinfo = "") {
|
|
super(script)
|
|
this.sourcepath = sourcepath
|
|
this.sourcerevision = sourcerevision
|
|
this.gitrevision = gitrevision
|
|
this.remoteurl = remoteurl
|
|
this.remoteinfo = remoteinfo
|
|
}
|
|
|
|
void set(String sourcepath, String sourcerevision, String gitrevision, String remoteurl, String remoteinfo) {
|
|
this.sourcepath = sourcepath
|
|
this.sourcerevision = sourcerevision
|
|
this.gitrevision = gitrevision
|
|
this.remoteurl = remoteurl
|
|
this.remoteinfo = remoteinfo
|
|
}
|
|
|
|
LinkedHashMap serialisationdata() {
|
|
def data = [
|
|
'sourcepath' : sourcepath,
|
|
'sourcerevision' : sourcerevision,
|
|
'gitrevision' : gitrevision,
|
|
'remoteurl' : remoteurl,
|
|
'remoteinfo' : remoteinfo,
|
|
]
|
|
return data
|
|
}
|
|
}
|
|
|
|
class JenkinsBuildInfo extends GISJsonSerialised {
|
|
private String buildjobname
|
|
private int buildnumber
|
|
private String buildmachine
|
|
private String builddate
|
|
|
|
JenkinsBuildInfo(script, String buildjobname = "", int buildnumber = 0, String buildmachine = "", String builddate = "") {
|
|
super(script)
|
|
this.buildjobname = buildjobname
|
|
this.buildnumber = buildnumber
|
|
this.buildmachine = buildmachine
|
|
this.builddate = builddate
|
|
}
|
|
|
|
void set(String buildjobname, int buildnumber, String buildmachine, String builddate) {
|
|
this.buildjobname = buildjobname
|
|
this.buildnumber = buildnumber
|
|
this.buildmachine = buildmachine
|
|
this.builddate = builddate
|
|
}
|
|
|
|
LinkedHashMap serialisationdata() {
|
|
def data = [
|
|
'buildjobname' : buildjobname,
|
|
'buildnumber' : buildnumber,
|
|
'buildmachine' : buildmachine,
|
|
'builddate' : builddate,
|
|
]
|
|
return data
|
|
}
|
|
}
|
|
|
|
class BuildStampInfo extends GISJsonSerialised {
|
|
private String buildstampprefix
|
|
private int revision
|
|
private String buildstamp
|
|
private String buildstampcommasep
|
|
|
|
BuildStampInfo(script, buildstampprefix = "", revision = 0, buildstamp = "", buildstampcommasep = "") {
|
|
super(script)
|
|
this.buildstampprefix = buildstampprefix
|
|
this.revision = revision
|
|
this.buildstamp = buildstamp
|
|
this.buildstampcommasep = buildstampcommasep
|
|
}
|
|
|
|
void set(String buildstampprefix, int revision, String buildstamp, String buildstampcommasep) {
|
|
this.buildstampprefix = buildstampprefix
|
|
this.revision = revision
|
|
this.buildstamp = buildstamp
|
|
this.buildstampcommasep = buildstampcommasep
|
|
}
|
|
|
|
LinkedHashMap serialisationdata() {
|
|
def data = [
|
|
'buildstampprefix' : buildstampprefix,
|
|
'revision' : revision,
|
|
'buildstamp' : buildstamp,
|
|
'buildstampcommasep' : buildstampcommasep,
|
|
]
|
|
return data
|
|
}
|
|
}
|
|
|
|
class ReleaseInfo extends GISJsonSerialised {
|
|
private String releaserepoURL
|
|
private ArrayList<String> releaseitems
|
|
|
|
ReleaseInfo(script, releaserepoURL = "") {
|
|
super(script)
|
|
this.releaserepoURL = releaserepoURL
|
|
this.releaseitems = new ArrayList<String>()
|
|
}
|
|
|
|
void set(String releaserepoURL = "") {
|
|
this.releaserepoURL = releaserepoURL
|
|
}
|
|
|
|
void addReleaseItem(String releaseitem) {
|
|
releaseitems.add(releaseitem)
|
|
}
|
|
|
|
List releaseitemssserialised() {
|
|
def items = []
|
|
for (ri in releaseitems) {
|
|
items.add(ri)
|
|
}
|
|
return items
|
|
}
|
|
|
|
LinkedHashMap serialisationdata() {
|
|
def data = [
|
|
'releaserepoURL' : releaserepoURL,
|
|
'releaseitems' : releaseitemssserialised(),
|
|
]
|
|
return data
|
|
}
|
|
}
|
|
|
|
class ConfigurationInfo extends GISJsonSerialised {
|
|
private String configurationname
|
|
private String configurationURL
|
|
private String configurationversion
|
|
private String configurationSHA
|
|
|
|
ConfigurationInfo(script, configurationname = "", configurationURL = "", configurationversion = "", configurationSHA = "") {
|
|
super(script)
|
|
this.configurationname = configurationname
|
|
this.configurationURL = configurationURL
|
|
this.configurationversion = configurationversion
|
|
this.configurationSHA = configurationSHA
|
|
}
|
|
|
|
LinkedHashMap serialisationdata() {
|
|
def data = [
|
|
'configurationname' : configurationname,
|
|
'configurationURL' : configurationURL,
|
|
'configurationversion' : configurationversion,
|
|
'configurationSHA' : configurationSHA,
|
|
]
|
|
return data
|
|
}
|
|
}
|
|
|
|
class ChecksumPair extends GISJsonSerialised {
|
|
private String filepath
|
|
private String sum
|
|
|
|
ChecksumPair(script, String filepath, String sum) {
|
|
super(script)
|
|
this.filepath = filepath
|
|
this.sum = sum
|
|
}
|
|
|
|
LinkedHashMap serialisationdata() {
|
|
def data = [
|
|
'filepath' : filepath,
|
|
'sum' : sum,
|
|
]
|
|
return data
|
|
}
|
|
}
|
|
|
|
class ChecksumSet extends GISJsonSerialised {
|
|
private String artifactpath
|
|
private ArrayList<ChecksumPair> checksumpairs
|
|
|
|
ChecksumSet(script, artifactpath) {
|
|
super(script)
|
|
this.artifactpath = artifactpath
|
|
checksumpairs = new ArrayList<ChecksumPair>()
|
|
}
|
|
|
|
ChecksumPair addChecksumPair(String filepath, String sum) {
|
|
def cp = new ChecksumPair(script, filepath, sum)
|
|
checksumpairs.add(cp)
|
|
return cp
|
|
}
|
|
|
|
List checksumpairsserialised() {
|
|
def associated = []
|
|
for (cp in checksumpairs) {
|
|
associated.add(cp.serialisationdata())
|
|
}
|
|
return associated
|
|
}
|
|
|
|
LinkedHashMap serialisationdata() {
|
|
def data = [
|
|
'artifactpath' : artifactpath,
|
|
'checksumpairs' : checksumpairsserialised(),
|
|
]
|
|
return data
|
|
}
|
|
}
|
|
|
|
class ChecksumInfo extends GISJsonSerialised {
|
|
private ArrayList<ChecksumSet> checksumsets
|
|
|
|
ChecksumInfo(script) {
|
|
super(script)
|
|
checksumsets = new ArrayList<ChecksumSet>()
|
|
}
|
|
|
|
ChecksumSet addChecksumSet(String artifactpath) {
|
|
def cs = new ChecksumSet(script, artifactpath)
|
|
checksumsets.add(cs)
|
|
return cs
|
|
}
|
|
|
|
List checksumsetsserialised() {
|
|
def associated = []
|
|
for (cs in checksumsets) {
|
|
associated.add(cs.serialisationdata())
|
|
}
|
|
return associated
|
|
}
|
|
|
|
LinkedHashMap serialisationdata() {
|
|
def data = [
|
|
'checksumsets' : checksumsetsserialised(),
|
|
]
|
|
return data
|
|
}
|
|
}
|
|
|
|
class PublishableInfo extends GISJsonSerialised {
|
|
private String filepath
|
|
|
|
PublishableInfo(script, String filepath = "") {
|
|
super(script)
|
|
this.filepath = filepath
|
|
}
|
|
|
|
LinkedHashMap serialisationdata() {
|
|
def data = [
|
|
'filepath' : filepath,
|
|
]
|
|
return data
|
|
}
|
|
}
|
|
|
|
class MetaInfo extends GISJsonSerialised {
|
|
private String METAFOLDERNAME = "meta"
|
|
private String METAFILENAME = "info.json"
|
|
private String METAARTIFACTS = "${METAFOLDERNAME}/**"
|
|
|
|
private String format = '0.1'
|
|
ProductInfo productinfo
|
|
GitInfo gitinfo
|
|
JenkinsBuildInfo jenkinsbuildinfo
|
|
BuildStampInfo buildstampinfo
|
|
ReleaseInfo releaseinfo
|
|
ChecksumInfo checksuminfo
|
|
private ArrayList<ConfigurationInfo> configurationinfo
|
|
private ArrayList<PublishableInfo> publishableinfo
|
|
private ArrayList<MetaInfo> associatedmeta
|
|
|
|
MetaInfo(script) {
|
|
super(script)
|
|
productinfo = new ProductInfo(script)
|
|
gitinfo = new GitInfo(script)
|
|
jenkinsbuildinfo = new JenkinsBuildInfo(script)
|
|
buildstampinfo = new BuildStampInfo(script)
|
|
releaseinfo = new ReleaseInfo(script)
|
|
checksuminfo = new ChecksumInfo(script)
|
|
configurationinfo = new ArrayList<ConfigurationInfo>()
|
|
publishableinfo = new ArrayList<PublishableInfo>()
|
|
associatedmeta = new ArrayList<MetaInfo>()
|
|
}
|
|
|
|
List configurationinfoserialised() {
|
|
def configuration = []
|
|
for (configurationitem in configurationinfo) {
|
|
configuration.add(configurationitem.serialisationdata())
|
|
}
|
|
return configuration
|
|
}
|
|
|
|
void addPublishable(String filepath) {
|
|
def PublishableInfo pi = new PublishableInfo(script, filepath)
|
|
publishableinfo.add(pi)
|
|
}
|
|
|
|
void addConfigurationInfo(String configurationname, String configurationURL, String configurationversion, String configurationSHA) {
|
|
def ConfigurationInfo ci = new ConfigurationInfo(script, configurationname, configurationURL, configurationversion, configurationSHA)
|
|
configurationinfo.add(ci)
|
|
}
|
|
|
|
List publishableinfoserialised() {
|
|
def publishable = []
|
|
for (publishableitem in publishableinfo) {
|
|
publishable.add(publishableitem.serialisationdata())
|
|
}
|
|
return publishable
|
|
}
|
|
|
|
List associatedmetaserialised() {
|
|
def associated = []
|
|
for (metaitem in associatedmeta) {
|
|
associated.add(metaitem.serialisationdata())
|
|
}
|
|
return associated
|
|
}
|
|
|
|
void addAssociatedMetaInfo(mi) {
|
|
associatedmeta.add(mi)
|
|
}
|
|
|
|
LinkedHashMap serialisationdata() {
|
|
def data = [
|
|
'format' : format,
|
|
'productinfo' : productinfo.serialisationdata(),
|
|
'gitinfo' : gitinfo.serialisationdata(),
|
|
'jenkinsbuildinfo' : jenkinsbuildinfo.serialisationdata(),
|
|
'buildstampinfo' : buildstampinfo.serialisationdata(),
|
|
'releaseinfo' : releaseinfo.serialisationdata(),
|
|
'configuration' : configurationinfoserialised(),
|
|
'checksuminfo' : checksuminfo.serialisationdata(),
|
|
'publishableinfo' : publishableinfoserialised(),
|
|
'associatedmeta' : associatedmetaserialised(),
|
|
]
|
|
return data
|
|
}
|
|
|
|
|
|
String folder() {
|
|
return METAFOLDERNAME
|
|
}
|
|
|
|
String generateartifacts(ArrayList<String> releasedfromhere = new ArrayList<String>(),
|
|
ArrayList<String> releasedfromsubmeta = new ArrayList<String>(),
|
|
String metafilepath ="${METAFOLDERNAME}/${METAFILENAME}"
|
|
) {
|
|
def String artifactlist = METAARTIFACTS
|
|
releaseinfo.addReleaseItem(METAARTIFACTS)
|
|
for (releaseitem in releasedfromhere) {
|
|
artifactlist += "," + releaseitem
|
|
releaseinfo.addReleaseItem(releaseitem)
|
|
}
|
|
for (releaseitem in releasedfromsubmeta) {
|
|
artifactlist += "," + releaseitem
|
|
}
|
|
saveJsonSerialised(metafilepath)
|
|
return artifactlist
|
|
}
|
|
}
|
|
|
|
MetaInfo metareset(script) {
|
|
echo "Resetting meta folder"
|
|
def mi = new MetaInfo(script)
|
|
|
|
dir(mi.folder()) {
|
|
deleteDir()
|
|
}
|
|
return mi
|
|
}
|
|
|
|
return this;
|