forked from openhab/openhab-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_addons.groovy
127 lines (123 loc) · 7.81 KB
/
process_addons.groovy
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
def collect_feature_xml = { features, xml, attrs ->
def feature = new File(project.basedir, xml)
def root = new XmlParser().parse(feature)
root.feature.each {
def name = it['@name']
features[name] = attrs
}
}
def collect_features = { features ->
collect_feature_xml(features, '.external-resources/openhab-distro/features/addons-esh/src/main/feature/feature.xml', ['install': 'auto', 'since': '2x'])
collect_feature_xml(features, '.external-resources/openhab-distro/features/addons/src/main/feature/feature.xml', ['install': 'auto', 'since': '2x'])
collect_feature_xml(features, '.external-resources/openhab2-addons/features/openhab-addons/src/main/feature/feature.xml', ['install': 'auto', 'since': '2x'])
collect_feature_xml(features, '.external-resources/openhab1-addons/features/openhab-addons/src/main/feature/feature.xml', ['install': 'auto', 'since': '1x'])
collect_feature_xml(features, '.external-resources/openhab1-addons/features/openhab-addons-legacy/src/main/feature/feature.xml', ['install': 'legacy', 'since': '1x'])
}
def process_addon_type = { features, sources, type, collection, suffix, lblremoves, pkgremoves ->
sources.each { source ->
println "--------------------------------------------------"
println "Processing: _" + collection + "/" + source + "\n"
def files = new File(project.basedir, "_${collection}/".concat(source))
if (! files.exists()) {
println "No resources found."
return
}
files.eachFile {
def name = it.name
println name
if (! name.contains(type)) println "[WARN] Addon package name doesn't contain '${type}'."
if (name.endsWith('.test')) {
println "[INFO] Skip."
it.deleteDir()
} else {
def id = it.name
for (pkg in pkgremoves) {
id = id.replace(pkg, '')
}
def target = new File(project.basedir, "_${collection}")
def simpleNameDir = new File(target.path, (source == 'oh1' && type == 'binding') ? id + '1' : id)
it.renameTo(simpleNameDir)
def readme = new File(simpleNameDir.path, 'README.md')
if (! readme.exists()) {
println "[WARNING] No README.md found."
} else {
readme.renameTo(new File(simpleNameDir.path, 'readme.md'))
//println readme
def label = readme.readLines().find{it.startsWith('#')}
if (label == null) {
println "[WARNING] No level 1 header found."
label = id
} else {
label = label.replace('#', '')
for (remove in lblremoves) {
label = label.replaceFirst(remove, '')
}
label = label.trim()
}
def logo = new File(project.basedir, 'images/addons/' + id + '.png').exists()
if (! logo) println "[INFO] No logo found."
def description = ""
boolean firstHeadline = false
for (def line : readme.readLines()) {
if (line.startsWith('#')) {
if (! firstHeadline) {
firstHeadline = true
}
} else {
if(firstHeadline && line.trim().size() > 0) {
description = line.trim().replace('\"', '\'')
break
}
}
}
def front = ['id': "${id}", 'label': "${label}", 'title': "${label}${suffix}", 'type': "${type}", description: "\"${description}\""]
if (source == 'oh1') {
front['source'] = "https://github.com/openhab/openhab1-addons/blob/master/bundles/${type}/org.openhab.${type}.${id}/README.md"
front['since'] = '1x'
} else {
front['since'] = '2x'
}
if (logo) {
front['logo'] = 'images/addons/' + id + '.png'
}
def feature_id = (source == 'oh1' && (type == 'binding' || type == 'io')) ? id + '1' : id
def feature = features.find {
it.key.startsWith("openhab-${type}-${feature_id}") ||
(type == 'io' && it.key.startsWith("openhab-misc-${feature_id}")) ||
(type == 'transform' && it.key.startsWith("openhab-transformation-${feature_id}"))
}?.value
if (feature == null) {
feature = ['install': 'manual']
}
front = front + feature
def toYaml = { '---\n' + it.collect{ /$it.key: $it.value/ }.join('\n') + '\n---\n\n' }
readme.write(toYaml(front) + '<!-- Attention authors: Do not edit directly. Please add your changes to the appropriate source repository -->\n\n{% include base.html %}\n\n' + readme.text)
}
}
print "\n"
}
def temp_folder = new File(project.basedir, "_${collection}/".concat(source))
if (temp_folder.list().length > 0) {
println "[WARNING] Folder not empty after processing."
}
temp_folder.deleteDir()
}
}
def process_addon_files = { features ->
// features, sources, type, collection, suffix, lblremoves, pkgremoves
process_addon_type(features, ['oh1'], 'action', 'addons_actions', ' - Actions', [' Actions', ' Action'], ['org.openhab.action.'] )
process_addon_type(features, ['oh1', 'oh2'], 'binding', 'addons_bindings', ' - Bindings', [' Binding'], ['org.openhab.binding.','org.eclipse.smarthome.binding.'])
process_addon_type(features, ['oh2'], 'iconset', 'addons_iconsets', ' - Icon Sets', [:], ['org.eclipse.smarthome.ui.iconset.'] )
process_addon_type(features, ['oh1', 'oh2', 'ext'], 'io', 'addons_ios', ' - System Integrations', [' Service'], ['org.openhab.io.','org.eclipse.smarthome.io'] )
process_addon_type(features, ['oh1'], 'persistence', 'addons_persistences', ' - Persistence Services', ['\\s*Persistence\\s*$'], ['org.openhab.persistence.'] )
process_addon_type(features, ['oh2'], 'transform', 'addons_transformations', ' - Transformation Services', [' Transformation Service'], ['org.eclipse.smarthome.transform.'] )
process_addon_type(features, ['oh2'], 'ui', 'addons_uis', ' - UIs', [:], ['org.openhab.ui.','org.eclipse.smarthome.ui.'] )
process_addon_type(features, ['oh2'], 'voice', 'addons_voices', ' - Voices', [:], ['org.openhab.voice.','org.eclipse.smarthome.voice.'] )
}
if (! new File(project.basedir, ".external-resources").exists()) {
println "\n\n[WARNING] Folder '.external-resources' missing. Please use the update script to run all steps in order. Exiting.\n\n"
return
}
def features = [:]
collect_features(features)
process_addon_files(features)