mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-25 11:45:49 +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,31 +20,39 @@ outputDirectory = new File(request.getOutputDirectory())
|
|||||||
* Find which bundle the new binding should be added
|
* Find which bundle the new binding should be added
|
||||||
*/
|
*/
|
||||||
def String findAfterBundle(newBundle, codeownersFile) {
|
def String findAfterBundle(newBundle, codeownersFile) {
|
||||||
def codeowners = codeownersFile.getText('UTF-8') + '/bundles/' + newBundle
|
def codeowners = codeownersFile.getText('UTF-8')
|
||||||
def lines = codeowners.split('\n').sort()
|
|
||||||
def lastIndex
|
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 ->
|
lines.eachWithIndex { line, index ->
|
||||||
if (line.contains(newBundle)) {
|
if (line.contains(newBundle)) {
|
||||||
lastIndex = index-1
|
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]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the new bundle to the CODEWONERS file
|
* Add the new bundle to the CODEWONERS file
|
||||||
*/
|
*/
|
||||||
def addUserToCodewoners(githubUser, codeownersFile, bundleAfter, newBundle) {
|
def addUserToCodewoners(githubUser, codeownersFile, bundleAfter, newBundle) {
|
||||||
def newContent = ''
|
def newContent = ''
|
||||||
def lines = codeownersFile.eachLine { line, index ->
|
// if new binding is a new first entry it's inserted directly after depencies tag
|
||||||
newContent += line + nl
|
def matchBundleAfter = bundleAfter.isEmpty() ? '# Add-on maintainers:' : (bundleAfter + '/')
|
||||||
if (line.contains(bundleAfter)) {
|
def lines = codeownersFile.eachLine { line, index ->
|
||||||
newContent += '/bundles/' + newBundle + '/ @' + githubUser + nl
|
newContent += line + nl
|
||||||
}
|
if (line.contains(matchBundleAfter)) {
|
||||||
}
|
newContent += '/bundles/' + newBundle + '/ @' + githubUser + nl
|
||||||
codeownersFile.write(newContent)
|
}
|
||||||
println 'Added github user to CODEOWNERS file'
|
}
|
||||||
|
codeownersFile.write(newContent)
|
||||||
|
println 'Added github user to CODEOWNERS file'
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,19 +68,22 @@ def addBundleToBom(bundleAfter, newBundle) {
|
|||||||
'''.replace('###', newBundle)
|
'''.replace('###', newBundle)
|
||||||
def bomFile = new File(outputDirectory, '../bom/openhab-addons/pom.xml')
|
def bomFile = new File(outputDirectory, '../bom/openhab-addons/pom.xml')
|
||||||
def newContent = ''
|
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 insertIndex = 0;
|
||||||
def lines = bomFile.eachLine { line, index ->
|
def lines = bomFile.eachLine { line, index ->
|
||||||
newContent += line + nl
|
newContent += line + nl
|
||||||
if (line.contains(bundleAfter)) {
|
if (line.contains(matchBundleAfter)) {
|
||||||
insertIndex = index + 2
|
insertIndex = index + offset
|
||||||
}
|
}
|
||||||
if (insertIndex > 0 && index == insertIndex) {
|
if (insertIndex > 0 && index == insertIndex) {
|
||||||
newContent += bomDependency
|
newContent += bomDependency
|
||||||
insertIndex = 0
|
insertIndex = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bomFile.write(newContent)
|
bomFile.write(newContent)
|
||||||
println 'Added bundle to bom pom'
|
println 'Added bundle to bom pom'
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -84,13 +95,15 @@ def fixBundlePom(bundleAfter, newBundle) {
|
|||||||
def bomFile = new File(outputDirectory, 'pom.xml')
|
def bomFile = new File(outputDirectory, 'pom.xml')
|
||||||
def module = '<module>' + newBundle + '</module>'
|
def module = '<module>' + newBundle + '</module>'
|
||||||
def newContent = ''
|
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 insertIndex = 0;
|
||||||
def lines = bomFile.eachLine { line, index ->
|
def lines = bomFile.eachLine { line, index ->
|
||||||
if (!line.contains(module)) {
|
if (!line.contains(module)) {
|
||||||
// filter out the already added module by the achetype
|
// filter out the already added module by the achetype
|
||||||
newContent += line + nl
|
newContent += line + nl
|
||||||
}
|
}
|
||||||
if (line.contains(bundleAfter)) {
|
if (line.contains(matchBundleAfter)) {
|
||||||
insertIndex = index
|
insertIndex = index
|
||||||
}
|
}
|
||||||
if (insertIndex > 0 && index == insertIndex) {
|
if (insertIndex > 0 && index == insertIndex) {
|
||||||
@ -126,4 +139,3 @@ if (codeownersFile.exists()) {
|
|||||||
} else {
|
} else {
|
||||||
println 'Could not find the CODEOWNERS files to perform additional annotations: ' + codeownersFile
|
println 'Could not find the CODEOWNERS files to perform additional annotations: ' + codeownersFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user