aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/BuildArchetypes.py
blob: 80dd745bfb43eb42e34590915153fe4d52209f9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#coding=UTF-8

#
# Windows users: 
# You need to setup your environment so that you have mvn on your PATH.
# Maven needs that JAVA_HOME environment is set and points to a JDK
# Python3 is required as this script uses some Python3 specific features.
# Might work with Python2, haven't tested.
#
# python BuildArchetypes.py version fw-repo-id archetype-repo-id plugin-repo-id
#

import subprocess
from BuildHelpers import mavenValidate, copyWarFiles, repo, getLogFile, parseArgs, mavenCmd, updateRepositories

## DEFAULT VARIABLES ##

# ArchetypeGroupId
archetypeGroup = "com.vaadin"

# List of built archetypes
archetypes = [
	"vaadin-archetype-widget", 
	"vaadin-archetype-application", 
	"vaadin-archetype-application-example", 
	"vaadin-archetype-application-multimodule"
]

# Maven GroupID
group = "testpkg"

log = None
args = None

## BUILDING METHODS ##

# Generates and modifies a maven pom file
def generateArchetype(archetype):
	artifactId = "test-%s-%s" % (archetype, args.version.replace(".", "-"))

	# Generate the required command line for archetype generation
	cmd = [mavenCmd, "archetype:generate"]
	cmd.append("-DarchetypeGroupId=%s" % (archetypeGroup))
	cmd.append("-DarchetypeArtifactId=%s" % (archetype))
	cmd.append("-DarchetypeVersion=%s" % (args.version))
	if hasattr(args, "archetype") and args.archetype != None:
		cmd.append("-DarchetypeRepository=%s" % (repo % (args.archetype)))
	cmd.append("-DgroupId=%s" % (group))
	cmd.append("-DartifactId=%s" % (artifactId))
	cmd.append("-Dversion=1.0-SNAPSHOT")
	cmd.append("-DinteractiveMode=false")
	
	# Generate pom.xml
	print("Generating pom.xml for archetype %s" % (archetype))
	subprocess.check_call(cmd, 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__":
	args = parseArgs()
	for archetype in archetypes:
		log = getLogFile(archetype)
		artifactId = generateArchetype(archetype)
		updateRepositories(artifactId)
		mavenValidate(artifactId, logFile=log)	
		copyWarFiles(artifactId, name=archetype)