Skip to content

Instantly share code, notes, and snippets.

@sametserpil
Created March 20, 2017 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sametserpil/3b55e6a58871c4b2d5a103bc9e069e91 to your computer and use it in GitHub Desktop.
Save sametserpil/3b55e6a58871c4b2d5a103bc9e069e91 to your computer and use it in GitHub Desktop.
Nexus 3 batch jar deployer
import os
import xml.etree.ElementTree
import time
rootDir = '.'
def tag_uri_and_name(elem):
if elem.tag[0] == "{":
uri, ignore, tag = elem.tag[1:].partition("}")
else:
uri = None
tag = elem.tag
return uri, tag
for dirName, subdirList, fileList in os.walk(rootDir):
#print('Found directory: %s' % dirName)
for fname in fileList:
if (fname.endswith('.jar')):
try:
print(dirName+'\\'+fname.replace('.jar','.pom'))
e = xml.etree.ElementTree.parse(dirName+'\\'+fname.replace('.jar','.pom')).getroot()
uri, tag = tag_uri_and_name(e)
if(uri is None):
groupId = e.findtext('groupId')
artifactId = e.findtext('artifactId')
version = e.findtext('version')
packaging = e.findtext('packaging')
else:
groupId = e.findtext('{'+uri+'}groupId')
artifactId = e.findtext('{'+uri+'}artifactId')
version = e.findtext('{'+uri+'}version')
packaging = e.findtext('{'+uri+'}packaging')
if(groupId is None or artifactId is None or version is None):
if(uri is None):
p = e.find('parent')
if(p is None):
continue
groupId = p.findtext('groupId')
artifactId = p.findtext('artifactId')
version = p.findtext('version')
packaging = p.findtext('packaging')
else:
p = e.find('{'+uri+'}parent')
if(p is None):
continue
groupId = p.findtext('{'+uri+'}groupId')
artifactId = p.findtext('{'+uri+'}artifactId')
version = p.findtext('{'+uri+'}version')
packaging = p.findtext('{'+uri+'}packaging')
if(groupId is None or artifactId is None or version is None):
continue
if(packaging is None):
packaging = 'jar'
print('\t Uploading file=%s artifactId=%s groupId=%s version=%s packaging=%s' % (fname,artifactId,groupId,version,packaging))
os.system('mvn deploy:deploy-file -DgroupId='+groupId+' -DartifactId='+artifactId+' -Dpackaging='+packaging+' -Dfile='+dirName+'/'+fname+' -Dversion='+version+' -DrepositoryId=semper-repo -Durl=http://nexus.semper-tech.com/repository/semper-repo/')
time.sleep(10)
except IOError as e:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment