mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 21:31:53 +01:00
[archetype] Fix groovy script to handle certain cases (#980)
This change handles the following cases: - New binding that will be the first entry in the list - New binding that is placed after/between multi project bindings. Like bluetooth and mqtt (reported in openhab/openhab2-addons#5860) Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl>
This commit is contained in:
parent
608507e451
commit
78cd43061c
@ -20,16 +20,22 @@ outputDirectory = new File(request.getOutputDirectory())
|
||||
* Find which bundle the new binding should be added
|
||||
*/
|
||||
def String findAfterBundle(newBundle, codeownersFile) {
|
||||
def codeowners = codeownersFile.getText('UTF-8') + '/bundles/' + newBundle
|
||||
def lines = codeowners.split('\n').sort()
|
||||
def codeowners = codeownersFile.getText('UTF-8')
|
||||
def lastIndex
|
||||
|
||||
def lines = codeowners.split('\n')
|
||||
.findAll{ it =~ /^.bundles/}
|
||||
.collect { it.replaceAll(/\/bundles\/([^\/]+)\/.+/, '$1')}
|
||||
lines.add(newBundle)
|
||||
lines = lines.sort()
|
||||
lines.eachWithIndex { line, index ->
|
||||
if (line.contains(newBundle)) {
|
||||
lastIndex = index-1
|
||||
}
|
||||
}
|
||||
return lines[lastIndex].replaceAll(/\/bundles\/([^\/]+)\/.+/, '$1')
|
||||
// if index == -1 it means its before all other bindings.
|
||||
// To handle this case an empty string is returned.
|
||||
// The other code handles the empty string as a special case
|
||||
return lastIndex < 0 ? "" : lines[lastIndex]
|
||||
}
|
||||
|
||||
/**
|
||||
@ -37,9 +43,11 @@ def String findAfterBundle(newBundle, codeownersFile) {
|
||||
*/
|
||||
def addUserToCodewoners(githubUser, codeownersFile, bundleAfter, newBundle) {
|
||||
def newContent = ''
|
||||
// if new binding is a new first entry it's inserted directly after depencies tag
|
||||
def matchBundleAfter = bundleAfter.isEmpty() ? '# Add-on maintainers:' : (bundleAfter + '/')
|
||||
def lines = codeownersFile.eachLine { line, index ->
|
||||
newContent += line + nl
|
||||
if (line.contains(bundleAfter)) {
|
||||
if (line.contains(matchBundleAfter)) {
|
||||
newContent += '/bundles/' + newBundle + '/ @' + githubUser + nl
|
||||
}
|
||||
}
|
||||
@ -60,11 +68,14 @@ def addBundleToBom(bundleAfter, newBundle) {
|
||||
'''.replace('###', newBundle)
|
||||
def bomFile = new File(outputDirectory, '../bom/openhab-addons/pom.xml')
|
||||
def newContent = ''
|
||||
// if new binding is a new first entry it's inserted directly after dependencies tag
|
||||
def matchBundleAfter = bundleAfter.isEmpty() ? '<dependencies>' : (bundleAfter + '<')
|
||||
def offset = bundleAfter.isEmpty() ? 0 : 2
|
||||
def insertIndex = 0;
|
||||
def lines = bomFile.eachLine { line, index ->
|
||||
newContent += line + nl
|
||||
if (line.contains(bundleAfter)) {
|
||||
insertIndex = index + 2
|
||||
if (line.contains(matchBundleAfter)) {
|
||||
insertIndex = index + offset
|
||||
}
|
||||
if (insertIndex > 0 && index == insertIndex) {
|
||||
newContent += bomDependency
|
||||
@ -84,13 +95,15 @@ def fixBundlePom(bundleAfter, newBundle) {
|
||||
def bomFile = new File(outputDirectory, 'pom.xml')
|
||||
def module = '<module>' + newBundle + '</module>'
|
||||
def newContent = ''
|
||||
// if new binding is a new first entry it's inserted directly after modules tag
|
||||
def matchBundleAfter = bundleAfter.isEmpty() ? '<modules>' : (bundleAfter + '<')
|
||||
def insertIndex = 0;
|
||||
def lines = bomFile.eachLine { line, index ->
|
||||
if (!line.contains(module)) {
|
||||
// filter out the already added module by the achetype
|
||||
newContent += line + nl
|
||||
}
|
||||
if (line.contains(bundleAfter)) {
|
||||
if (line.contains(matchBundleAfter)) {
|
||||
insertIndex = index
|
||||
}
|
||||
if (insertIndex > 0 && index == insertIndex) {
|
||||
@ -126,4 +139,3 @@ if (codeownersFile.exists()) {
|
||||
} else {
|
||||
println 'Could not find the CODEOWNERS files to perform additional annotations: ' + codeownersFile
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user