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.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 fw-repo-id archetype-repo-id plugin-repo-id
  10. #
  11. import subprocess, sys
  12. from BuildHelpers import mavenValidate, copyWarFiles, getLogFile, mavenCmd, updateRepositories, getArgs, removeDir, parser, resultPath
  13. from DeployHelpers import deployWar
  14. from os.path import join
  15. ## DEFAULT VARIABLES ##
  16. # ArchetypeGroupId
  17. archetypeGroup = "com.vaadin"
  18. # List of built archetypes
  19. archetypes = [
  20. "vaadin-archetype-widget",
  21. "vaadin-archetype-application",
  22. "vaadin-archetype-application-example",
  23. "vaadin-archetype-application-multimodule"
  24. ]
  25. # Maven GroupID
  26. group = "testpkg"
  27. log = None
  28. args = None
  29. ## BUILDING METHODS ##
  30. # Generates and modifies a maven pom file
  31. def generateArchetype(archetype, artifactId, repo):
  32. # Generate the required command line for archetype generation
  33. cmd = [mavenCmd, "archetype:generate"]
  34. cmd.append("-DarchetypeGroupId=%s" % (archetypeGroup))
  35. cmd.append("-DarchetypeArtifactId=%s" % (archetype))
  36. cmd.append("-DarchetypeVersion=%s" % (args.version))
  37. if hasattr(args, "archetype") and args.archetype != None:
  38. cmd.append("-DarchetypeRepository=%s" % (repo % (args.archetype)))
  39. cmd.append("-DgroupId=%s" % (group))
  40. cmd.append("-DartifactId=%s" % (artifactId))
  41. cmd.append("-Dversion=1.0-SNAPSHOT")
  42. cmd.append("-DinteractiveMode=false")
  43. if hasattr(args, "maven") and args.maven is not None:
  44. cmd.extend(args.maven.strip('"').split(" "))
  45. # Generate pom.xml
  46. print("Generating pom.xml for archetype %s" % (archetype))
  47. subprocess.check_call(cmd, cwd=resultPath, stdout=log)
  48. ## DO THIS IF RUN AS A SCRIPT (not import) ##
  49. if __name__ == "__main__":
  50. # Add command line arguments for staging repos
  51. parser.add_argument("framework", type=int, help="Framework repo id (comvaadin-XXXX)", nargs='?')
  52. parser.add_argument("archetype", type=int, help="Archetype repo id (comvaadin-XXXX)", nargs='?')
  53. parser.add_argument("plugin", type=int, help="Maven Plugin repo id (comvaadin-XXXX)", nargs='?')
  54. parser.add_argument("--repo", type=str, help="Staging repository template", required=True)
  55. archetypesFailed = False
  56. # Parse the arguments
  57. args = getArgs()
  58. if hasattr(args, "artifactPath") and args.artifactPath is not None:
  59. raise Exception("Archetype validation build does not support artifactPath")
  60. for archetype in archetypes:
  61. artifactId = "test-%s-%s" % (archetype, args.version.replace(".", "-"))
  62. try:
  63. log = getLogFile(archetype)
  64. generateArchetype(archetype, artifactId, args.repo)
  65. updateRepositories(join(resultPath, artifactId))
  66. mavenValidate(artifactId, logFile=log)
  67. warFiles = copyWarFiles(artifactId, name=archetype)
  68. for war in warFiles:
  69. try:
  70. deployWar(war, "%s-%s.war" % (archetype.split("-", 2)[2], args.version))
  71. except Exception as e:
  72. print("War %s failed to deploy: %s" % (war, e))
  73. archetypesFailed = True
  74. except Exception as e:
  75. print("Archetype %s build failed:" % (archetype), e)
  76. archetypesFailed = True
  77. # removeDir(artifactId)
  78. print("")
  79. if archetypesFailed:
  80. sys.exit(1)