From 94581505567f09e2fa90f4d41b7fea7cbae1b250 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Wed, 8 Jul 2015 17:17:00 +0300 Subject: Fix version number resolution for validation scripts Change-Id: I799553cea50cb8e81ab06482f1a971f324da8fa1 --- scripts/BuildArchetypes.py | 27 ++++++++++++++------------- scripts/BuildDemos.py | 10 +++++++--- scripts/BuildHelpers.py | 23 +++++++++++++++-------- 3 files changed, 36 insertions(+), 24 deletions(-) (limited to 'scripts') diff --git a/scripts/BuildArchetypes.py b/scripts/BuildArchetypes.py index 4242134573..1e787c25f7 100644 --- a/scripts/BuildArchetypes.py +++ b/scripts/BuildArchetypes.py @@ -10,8 +10,8 @@ # python BuildArchetypes.py version fw-repo-id archetype-repo-id plugin-repo-id # -import subprocess -from BuildHelpers import mavenValidate, copyWarFiles, repo, getLogFile, mavenCmd, updateRepositories, getArgs, removeDir, parser, resultPath +import subprocess, sys +from BuildHelpers import mavenValidate, copyWarFiles, getLogFile, mavenCmd, updateRepositories, getArgs, removeDir, parser, resultPath from DeployHelpers import deployWar ## DEFAULT VARIABLES ## @@ -36,9 +36,7 @@ args = None ## BUILDING METHODS ## # Generates and modifies a maven pom file -def generateArchetype(archetype): - artifactId = "test-%s-%s" % (archetype, args.version.replace(".", "-")) - +def generateArchetype(archetype, artifactId): # Generate the required command line for archetype generation cmd = [mavenCmd, "archetype:generate"] cmd.append("-DarchetypeGroupId=%s" % (archetypeGroup)) @@ -51,41 +49,44 @@ def generateArchetype(archetype): cmd.append("-Dversion=1.0-SNAPSHOT") cmd.append("-DinteractiveMode=false") if hasattr(args, "maven") and args.maven is not None: - cmd.extends(args.maven.split(" ")) + cmd.extend(args.maven.strip('"').split(" ")) # Generate pom.xml print("Generating pom.xml for archetype %s" % (archetype)) subprocess.check_call(cmd, cwd=resultPath, stdout=log) - # Return the artifactId so we know the name in the future - return artifactId - ## DO THIS IF RUN AS A SCRIPT (not import) ## if __name__ == "__main__": # Add command line arguments for staging repos parser.add_argument("framework", type=int, help="Framework repo id (comvaadin-XXXX)", nargs='?') parser.add_argument("archetype", type=int, help="Archetype repo id (comvaadin-XXXX)", nargs='?') parser.add_argument("plugin", type=int, help="Maven Plugin repo id (comvaadin-XXXX)", nargs='?') + parser.add_argument("--repo", type=str, help="Staging repository template", required=True) archetypesFailed = False # Parse the arguments args = getArgs() + + if hasattr(args, "artifactPath") and args.artifactPath is not None: + raise Exception("Archetype validation build does not support artifactPath") + for archetype in archetypes: + artifactId = "test-%s-%s" % (archetype, args.version.replace(".", "-")) try: log = getLogFile(archetype) - artifactId = generateArchetype(archetype) + generateArchetype(archetype, artifactId) updateRepositories(artifactId) mavenValidate(artifactId, logFile=log) warFiles = copyWarFiles(artifactId, name=archetype) for war in warFiles: try: - deployWar(war, "%s.war" % (archetype.split("-", 2)[2])) + deployWar(war, "%s-%s.war" % (archetype.split("-", 2)[2], args.version)) except Exception as e: print("War %s failed to deploy: %s" % (war, e)) archetypesFailed = True - except: - print("Archetype %s build failed" % (archetype)) + except Exception as e: + print("Archetype %s build failed" % (archetype, e)) archetypesFailed = True removeDir(artifactId) print("") diff --git a/scripts/BuildDemos.py b/scripts/BuildDemos.py index 9306153b9a..a13b5ac033 100644 --- a/scripts/BuildDemos.py +++ b/scripts/BuildDemos.py @@ -12,6 +12,7 @@ import sys, os from os.path import join, isfile from fnmatch import fnmatch +from xml.etree.ElementTree import ElementTree # Validated demos. name -> git url demos = { @@ -31,11 +32,11 @@ if __name__ == "__main__": except: print("BuildDemos depends on gitpython. Install it with `pip install gitpython`") sys.exit(1) - from BuildHelpers import updateRepositories, mavenValidate, copyWarFiles, getLogFile, removeDir, getArgs, mavenInstall, resultPath + from BuildHelpers import updateRepositories, mavenValidate, copyWarFiles, getLogFile, removeDir, getArgs, mavenInstall, resultPath, readPomFile from DeployHelpers import deployWar - if hasattr(getArgs(), "artifactPath") and getArgs().artifactPath is not None: + version = False basePath = getArgs().artifactPath poms = [] for root, dirs, files in os.walk(basePath): @@ -48,7 +49,10 @@ if __name__ == "__main__": mavenInstall(pom, jarFile) else: mavenInstall(pom) - + if "vaadin-server" in pom: + pomXml, nameSpace = readPomFile(pom) + for version in pomXml.getroot().findall("./{%s}version" % (nameSpace)): + getArgs().version = version.text demosFailed = False for demo in demos: diff --git a/scripts/BuildHelpers.py b/scripts/BuildHelpers.py index 7068168052..3302649c81 100644 --- a/scripts/BuildHelpers.py +++ b/scripts/BuildHelpers.py @@ -26,9 +26,11 @@ args = None # Default argument parser parser = argparse.ArgumentParser(description="Automated staging validation") -parser.add_argument("version", type=str, help="Vaadin version to use") +group = parser.add_mutually_exclusive_group(required=True) +group.add_argument("--version", help="Vaadin version to use") +group.add_argument("--artifactPath", help="Path to local folder with Vaadin artifacts") + parser.add_argument("--maven", help="Additional maven command line parameters", default=None) -parser.add_argument("--artifactPath", help="Path to local folder with Vaadin artifacts", default=None) # Parse command line arguments def parseArgs(): @@ -99,6 +101,16 @@ def copyWarFiles(artifactId, resultDir = resultPath, name = None): copiedWars.append(join(resultDir, deployName)) return copiedWars +def readPomFile(pomFile): + # pom.xml namespace workaround + root = ElementTree.parse(pomFile).getroot() + nameSpace = root.tag[1:root.tag.index('}')] + print("Using namespace: %s" % (nameSpace)) + ElementTree.register_namespace('', nameSpace) + + # Read the pom.xml correctly + return ElementTree.parse(pomFile), nameSpace + # Recursive pom.xml update script def updateRepositories(path, repoIds = None, repoUrl = repo): # If versions are not supplied, parse arguments @@ -108,13 +120,8 @@ def updateRepositories(path, repoIds = None, repoUrl = repo): # Read pom.xml pomXml = join(path, "pom.xml") if isfile(pomXml): - # pom.xml namespace workaround - root = ElementTree.parse(pomXml).getroot() - nameSpace = root.tag[1:root.tag.index('}')] - ElementTree.register_namespace('', nameSpace) - # Read the pom.xml correctly - tree = ElementTree.parse(pomXml) + tree, nameSpace = readPomFile(pomXml) # NameSpace needed for finding the repositories node repoNode = tree.getroot().find("{%s}repositories" % (nameSpace)) -- cgit v1.2.3