diff --git a/.travis.yml b/.travis.yml index f5c99a7f..a6a03765 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1 +1,15 @@ -language: java \ No newline at end of file +language: java + +# Snapshot deployment to Sonatype Maven repository +# The password is encrypted using "travis encrypt -r echo3/echo3extras SONATYPE_PASSWORD=password" +# and only decrypted and set as environment variable by travis-ci if the build runs in the context of +# the echo3/echo3extras github repository. + +env: + global: + - SONATYPE_USERNAME=bschmid + - secure: "WkgVn7wbMe7C1KKAFZrvy2BR2eZZ6Bnv1/BPJFHOI+u172wnFPX5FDyjZQiU9xipocnWfa5MZCCpyKBJrNDnWEVlM75bZG6Xpq+yu3tbZgxyNZ3JLxU6a7m5OJo4XjhBiVbX7b+BmD5qHCO5CTgxZIJbKIz0ToUU+ALLcdVlsS8=" + +after_success: +- python resource/travis-ci/addServer.py +- ant travis.mvn.snapshot diff --git a/build.xml b/build.xml index 06c88c07..447a6e9d 100644 --- a/build.xml +++ b/build.xml @@ -414,8 +414,24 @@ - + + + + + + + + + + + + + + + + diff --git a/resource/travis-ci/addServer.py b/resource/travis-ci/addServer.py new file mode 100644 index 00000000..22380931 --- /dev/null +++ b/resource/travis-ci/addServer.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +""" + Add sonatype snapshot server and credentials to ~/.m2/settings.xml + Username and password are passed in by travis-ci as environment + variables. +""" +import sys +import os +import os.path +import xml.dom.minidom + +if os.environ["TRAVIS_SECURE_ENV_VARS"] == "false": + print "no secure env vars available, skipping deployment" + sys.exit() + +homedir = os.path.expanduser("~") + +m2 = xml.dom.minidom.parse(homedir + '/.m2/settings.xml') +settings = m2.getElementsByTagName("settings")[0] + +serversNodes = settings.getElementsByTagName("servers") +if not serversNodes: + serversNode = m2.createElement("servers") + settings.appendChild(serversNode) +else: + serversNode = serversNodes[0] + +sonatypeServerNode = m2.createElement("server") +sonatypeServerId = m2.createElement("id") +sonatypeServerUser = m2.createElement("username") +sonatypeServerPass = m2.createElement("password") + +idNode = m2.createTextNode("sonatype-nexus-snapshots") +userNode = m2.createTextNode(os.environ["SONATYPE_USERNAME"]) +passNode = m2.createTextNode(os.environ["SONATYPE_PASSWORD"]) + +sonatypeServerId.appendChild(idNode) +sonatypeServerUser.appendChild(userNode) +sonatypeServerPass.appendChild(passNode) + +sonatypeServerNode.appendChild(sonatypeServerId) +sonatypeServerNode.appendChild(sonatypeServerUser) +sonatypeServerNode.appendChild(sonatypeServerPass) + +serversNode.appendChild(sonatypeServerNode) + +m2Str = m2.toxml() +f = open(homedir + '/.m2/settings.xml', 'w') +f.write(m2Str + '\n') +f.close() \ No newline at end of file