You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BuildArchetypes.py 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #coding=UTF-8
  2. #
  3. # Windows users:
  4. # You need to setup your environment so that you have mvn on your PATH.
  5. # Maven needs that JAVA_HOME environment is set and points to a JDK
  6. # Python3 is required as this script uses some Python3 specific features.
  7. # Might work with Python2, haven't tested.
  8. #
  9. # python BuildArchetypes.py version --repo staging-repo-url
  10. #
  11. import subprocess, sys
  12. from os.path import join
  13. ## DEFAULT VARIABLES ##
  14. # ArchetypeGroupId
  15. archetypeGroup = "com.vaadin"
  16. # List of built archetypes
  17. archetypes = [
  18. "vaadin-archetype-widget",
  19. "vaadin-archetype-application",
  20. "vaadin-archetype-application-example",
  21. "vaadin-archetype-application-multimodule"
  22. ]
  23. # Maven GroupID
  24. group = "testpkg"
  25. log = None
  26. args = None
  27. ## BUILDING METHODS ##
  28. # Generates and modifies a maven pom file
  29. def generateArchetype(archetype, artifactId, repo):
  30. # Generate the required command line for archetype generation
  31. cmd = [mavenCmd, "archetype:generate"]
  32. cmd.append("-DarchetypeGroupId=%s" % (archetypeGroup))
  33. cmd.append("-DarchetypeArtifactId=%s" % (archetype))
  34. cmd.append("-DarchetypeVersion=%s" % (args.version))
  35. if hasattr(args, "repo") and args.repo != None:
  36. cmd.append("-DarchetypeRepository=%s" % repo)
  37. cmd.append("-DgroupId=%s" % (group))
  38. cmd.append("-DartifactId=%s" % (artifactId))
  39. cmd.append("-Dversion=1.0-SNAPSHOT")
  40. cmd.append("-DinteractiveMode=false")
  41. if hasattr(args, "maven") and args.maven is not None:
  42. cmd.extend(args.maven.strip('"').split(" "))
  43. # Generate pom.xml
  44. print("Generating pom.xml for archetype %s" % (archetype))
  45. subprocess.check_call(cmd, cwd=resultPath, stdout=log)
  46. def getDeploymentContext(archetype, version):
  47. return "%s-%s" % (archetype.split("-", 2)[2], version)
  48. ## DO THIS IF RUN AS A SCRIPT (not import) ##
  49. if __name__ == "__main__":
  50. from BuildHelpers import mavenValidate, copyWarFiles, getLogFile, mavenCmd, updateRepositories, getArgs, removeDir, parser, resultPath
  51. from DeployHelpers import deployWar
  52. # Add command line arguments for staging repos
  53. parser.add_argument("--repo", type=str, help="Staging repository URL", required=True)
  54. archetypesFailed = False
  55. # Parse the arguments
  56. args = getArgs()
  57. if hasattr(args, "artifactPath") and args.artifactPath is not None:
  58. raise Exception("Archetype validation build does not support artifactPath")
  59. for archetype in archetypes:
  60. artifactId = "test-%s-%s" % (archetype, args.version.replace(".", "-"))
  61. try:
  62. log = getLogFile(archetype)
  63. generateArchetype(archetype, artifactId, args.repo)
  64. updateRepositories(join(resultPath, artifactId), args.repo)
  65. mavenValidate(artifactId, logFile=log)
  66. warFiles = copyWarFiles(artifactId, name=archetype)
  67. for war in warFiles:
  68. try:
  69. deployWar(war, "%s.war" % (getDeploymentContext(archetype, args.version)))
  70. except Exception as e:
  71. print("War %s failed to deploy: %s" % (war, e))
  72. archetypesFailed = True
  73. except Exception as e:
  74. print("Archetype %s build failed:" % (archetype), e)
  75. archetypesFailed = True
  76. # removeDir(artifactId)
  77. print("")
  78. if archetypesFailed:
  79. sys.exit(1)