codevalet/scripts/plugins-from-pom

48 lines
2.0 KiB
Python
Executable File

#!/usr/bin/env python
import sys
from xml.etree.ElementTree import ElementTree
def main():
document = ElementTree(file=sys.argv[1])
plugins = []
ns = {'mvn' : 'http://maven.apache.org/POM/4.0.0'}
packaging = document.find('mvn:packaging', ns)
if (packaging is not None) and (packaging.text == 'hpi'):
for e in document.findall('mvn:dependencies', ns):
for dep in list(e):
scope = dep.find('mvn:scope', ns)
if scope is None:
optional = dep.find('mvn:optional', ns)
if optional is None:
group = dep.find('mvn:groupId', ns).text
plugin = dep.find('mvn:artifactId', ns).text
# Avoid the github-organization-folder since it's
# tombstoned
if plugin == 'github-organization-folder':
next
try:
['org.jvnet.hudson.plugins', 'org.jenkins-ci.plugins',
'org.jenkinsci.plugins', 'org.jenkins-ci.plugins.icon-shim',
'${project.groupId}', 'io.jenkins.plugins',
'io.jenkins.blueocean',
'org.jenkins-ci.main', 'com.coravy.hudson.plugins.github',
'org.6wind.jenkins', 'org.jenkins-ci.plugins.pipeline-stage-view',
'org.jenkins-ci.ui', 'org.jenkins-ci.plugins.workflow'].index(group)
# Let's only bother with dependencies that are actually Jenkins
# plugins :)
plugins.append(plugin)
except ValueError:
pass
with open('.plugins.txt', 'w+') as fd:
for plugin in plugins:
fd.write(plugin)
fd.write('\n')
if __name__ == '__main__':
main()