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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 repo is not 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. archetypesFailed = False
  53. # Parse the arguments
  54. args = getArgs()
  55. wars = {}
  56. for archetype in archetypes:
  57. artifactId = "test-%s-%s" % (archetype, args.version.replace(".", "-"))
  58. try:
  59. log = getLogFile(archetype)
  60. generateArchetype(archetype, artifactId, args.pluginRepo)
  61. if hasattr(args, "fwRepo") and args.fwRepo is not None:
  62. updateRepositories(join(resultPath, artifactId), args.fwRepo)
  63. if hasattr(args, "pluginRepo") and args.pluginRepo is not None:
  64. updateRepositories(join(resultPath, artifactId), args.pluginRepo, postfix="plugin")
  65. mavenValidate(artifactId, logFile=log)
  66. warFiles = copyWarFiles(artifactId, name=archetype)
  67. for war in warFiles:
  68. wars[war] = "%s.war" % (getDeploymentContext(archetype, args.version))
  69. print("%s validation succeeded!" % (archetype))
  70. except Exception as e:
  71. print("Archetype %s build failed:" % (archetype), e)
  72. archetypesFailed = True
  73. try:
  74. removeDir(artifactId)
  75. except:
  76. pass
  77. print("")
  78. for i in wars:
  79. try:
  80. deployWar(i, wars[i])
  81. except Exception as e:
  82. print("War %s failed to deploy: %s" % (war, e))
  83. archetypesFailed = True
  84. if archetypesFailed:
  85. sys.exit(1)