-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneratePartnerProjects.groovy
More file actions
78 lines (60 loc) · 2.5 KB
/
generatePartnerProjects.groovy
File metadata and controls
78 lines (60 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /cygdrive/d/tools/groovy-2.1.6/bin/groovy
import groovy.json.*
def slurper = new JsonSlurper()
def ctlJson = new File("project-control.json").getText("UTF-8")
def ctl = slurper.parseText(ctlJson)
println ("generating apiary projects")
//def baseFolder = "IMP-North-Implemented/"
def baseFolder = ""
def baseApiFileText = new File(baseFolder + "apiary.apib").getText() // the base apib file
ctl.Projects.each{
println "project: " + it.Project
def dirName = it.Project
def apiFileName = dirName + "/apiary.apib" // the apib file to be generated
println "apiFileName: " + apiFileName
def bakFileName = apiFileName + ".bak"
def bakFile = new File(bakFileName)
bakFile.delete()
def apiFile = new File(apiFileName)
apiFile.renameTo(bakFileName)
apiFile.append("FORMAT: 1A\n");
apiFile.append("HOST: " + it.Host + "\n\n")
println("host: " + it.Host + "\n")
apiFile.append("# " + it.Title + " \n")
apiFile.append(findProjIntro(baseApiFileText))
it.Chapters.each {
apiFile.append(findChapter(it, baseApiFileText))
}
}
def findChapter(chapName, baseApiFileText){
println("* chapter: " + chapName);
//def text = new File("IMP-North-Implemented/apiary.apib").getText() oldddddddddd
//def text = new File(baseFolder + "apiary.apib").getText()
assert '\n# ' + chapName + ' \n \n' ==~ /\n#\s*$chapName\s*\n/
//NOTE: Introduction has "# " before the chapter name
if (chapName ==~ /Introduction/)
{
// matches # Introduction blabla \n blabla \n# bebe
def chap = baseApiFileText.find(/\n#\s*$chapName\s*\n(?s).*?(?=\n#\s*)/) //matching anything but not (?=this)
// def chap = text.find(/\-\-\s*\n$chapName\s*\n(?s).*?(\n\-\-\s*\n)/) //matching anything until = (?s).*?(until here) oldddddddddddddddddddd
//println("* chap:\r\n" + chap)
assert chap != null
return chap
}
// NOTE: All other chapters have "# Group " before the chapter name
else
{
//matches \n# Group Chaptername \n bla bla till next \n# Group Chaptername
def chap = baseApiFileText.find(/\n#\s*Group\s*$chapName\s*\n(?s).*?(?=\n#\s*Group\s*)/) //matching but not (?=this)
//println("* chap:\r\n" + chap)
assert chap != null
return chap
}
}
// looking for proj intro
def findProjIntro(fileText){
def projIntroWithOldName = fileText.find(/\n# (?s).*?(?=\n#)/) // matching anything until = (?s).*?(?= until this BUT NOT including it)
def projOldName = projIntroWithOldName.find(/\n# (?s).*?(\n)/)
def projIntro = projIntroWithOldName.replace(projOldName, "")
return projIntro
}