forked from openhab/openhab-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_addons.groovy
103 lines (98 loc) · 6.31 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
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, '_repos/openhab-distro/features/addons-esh/src/main/feature/feature.xml', ['install': 'auto', 'since': '2x'])
collect_feature_xml(features, '_repos/openhab-distro/features/addons/src/main/feature/feature.xml', ['install': 'auto', 'since': '2x'])
collect_feature_xml(features, '_repos/openhab2-addons/features/openhab-addons/src/main/feature/feature.xml', ['install': 'auto', 'since': '2x'])
collect_feature_xml(features, '_repos/openhab/features/openhab-addons/src/main/feature/feature.xml', ['install': 'auto', 'since': '1x'])
collect_feature_xml(features, '_repos/openhab/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 ->
def files = new File(project.basedir, "_${collection}/".concat(source))
files.eachFile {
def name = it.name
if(name.contains(type) && !name.endsWith('.test')) {
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 readme
readme.renameTo(new File(simpleNameDir.path, 'readme.md'))
def label = readme.readLines().find{it.startsWith('#')}
if(label == null) {
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()
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)
}
}
}
}
}
def process_addon_files = { features ->
// features, sources, type, collection, suffix, lblremoves, pkgremoves
process_addon_type(features, ['oh1', 'oh2'], 'binding', 'bindings', ' - Bindings', [' Binding'], ['org.openhab.binding.','org.eclipse.smarthome.binding.'])
process_addon_type(features, ['oh1'], , 'action', 'actions', ' - Actions', [' Actions', ' Action'], ['org.openhab.action.'] )
process_addon_type(features, ['oh1'], , 'persistence', 'persistence', ' - Persistence', ['\\s*Persistence\\s*$'], ['org.openhab.persistence.'] )
process_addon_type(features, ['oh1', 'oh2'], 'io', 'io', ' - Services', [' Service'], ['org.openhab.io.','org.eclipse.smarthome.io'] )
process_addon_type(features, ['oh2'], 'transform', 'transformations', ' - Transformations', [' Transformation Service'], ['org.eclipse.smarthome.transform.'] )
process_addon_type(features, ['oh2'], 'voice', 'voice', ' - Voice', [:], ['org.openhab.voice.','org.eclipse.smarthome.voice.'] )
process_addon_type(features, ['oh2'], 'iconset', 'iconsets', ' - Icon Sets', [:], ['org.eclipse.smarthome.ui.iconset.'] )
process_addon_type(features, ['oh2'], 'ui', 'uis', ' - UI', [:], ['org.openhab.ui.','org.eclipse.smarthome.ui.'] )
}
def features = [:]
collect_features(features)
process_addon_files(features)