aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/BuildDemos.py
blob: 451715f3c516b5144a901fdc9eb00c561809cc80 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#coding=UTF-8

# See BuildArchetypes for details on environment
# BuildDemos needs git in PATH and depends on gitpython library
# gitpython can be installed with python installer script "pip":
# pip install gitpython	
#
# Deployment dependency: requests
# pip install requests
# Deploy depends on .deployUrl and .deployCredentials files in home folder

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 = {
	"dashboard" : "https://github.com/vaadin/dashboard-demo.git",
	"parking" : "https://github.com/vaadin/parking-demo.git",
	"addressbook" : "https://github.com/vaadin/addressbook.git",
	"grid-gwt" : "https://github.com/vaadin/grid-gwt.git"
}

def checkout(folder, url):
	Repo.clone_from(url, join(resultPath, folder))

if __name__ == "__main__":
	# Do imports.	
	try:
		from git import Repo
	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, readPomFile, parser
	from DeployHelpers import deployWar

	# Add command line argument for staging repos
	parser.add_argument("--repo", type=str, help="Staging repository URL", default=None)

	# Add command line agrument for ignoring failing demos
	parser.add_argument("--ignore", type=str, help="Ignored demos", default="")

	args = getArgs()
	if hasattr(args, "artifactPath") and args.artifactPath is not None:
		version = False
		basePath = args.artifactPath
		poms = []
		for root, dirs, files in os.walk(basePath):
			for name in files:
				if fnmatch(name, "*.pom"):
					poms.append(join(root, name))
		for pom in poms:
			jarFile = pom.replace(".pom", ".jar")
			if isfile(jarFile):
				mavenInstall(pom, jarFile)
			else:
				mavenInstall(pom)
			if "vaadin-server" in pom:
				pomXml, nameSpace = readPomFile(pom)
				for version in pomXml.getroot().findall("./{%s}version" % (nameSpace)):
					args.version = version.text
	demosFailed = False
	ignoredDemos = args.ignore.split(",")
	
	for demo in demos:
		print("Validating demo %s" % (demo))
		try:
			checkout(demo, demos[demo])
			if hasattr(args, "repo") and args.repo is not None:
				updateRepositories(join(resultPath, demo), args.repo)
			mavenValidate(demo, logFile=getLogFile(demo))
			resultWars = copyWarFiles(demo)
			for war in resultWars:
				try:
					deployWar(war)
				except Exception as e:
					print("War %s failed to deploy: %s" % (war, e))
					demosFailed = True
			print("%s demo validation succeeded!" % (demo))
		except Exception as e:
			print("%s demo validation failed: %s" % (demo, e))
			if demo not in ignoredDemos:
				demosFailed = True
		removeDir(demo)
		print("")
	if demosFailed:
		sys.exit(1)
transform(src, res); } finally { out.close(); } } catch (Exception e) { e.printStackTrace(System.err); System.exit(-1); } } /** * Main method. * @param args command-line arguments */ public static void main(String[] args) { try { System.out.println("FOP ExampleDOM2PDF\n"); //Setup directories File baseDir = new File("."); File outDir = new File(baseDir, "out"); outDir.mkdirs(); //Setup output file File pdffile = new File(outDir, "ResultDOM2PDF.pdf"); System.out.println("PDF Output File: " + pdffile); System.out.println(); Document foDoc = buildDOMDocument(); ExampleDOM2PDF app = new ExampleDOM2PDF(); app.convertDOM2PDF(foDoc, pdffile); System.out.println("Success!"); } catch (Exception e) { e.printStackTrace(System.err); System.exit(-1); } } /** * Builds the example FO document as a DOM in memory. * @return the FO document * @throws ParserConfigurationException In case there is a problem creating a DOM document */ private static Document buildDOMDocument() throws ParserConfigurationException { // Create a sample XSL-FO DOM document Document foDoc = null; Element root = null, ele1 = null, ele2 = null, ele3 = null; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); foDoc = db.newDocument(); root = foDoc.createElementNS(foNS, "fo:root"); foDoc.appendChild(root); ele1 = foDoc.createElementNS(foNS, "fo:layout-master-set"); root.appendChild(ele1); ele2 = foDoc.createElementNS(foNS, "fo:simple-page-master"); ele1.appendChild(ele2); ele2.setAttributeNS(null, "master-name", "letter"); ele2.setAttributeNS(null, "page-height", "11in"); ele2.setAttributeNS(null, "page-width", "8.5in"); ele2.setAttributeNS(null, "margin-top", "1in"); ele2.setAttributeNS(null, "margin-bottom", "1in"); ele2.setAttributeNS(null, "margin-left", "1in"); ele2.setAttributeNS(null, "margin-right", "1in"); ele3 = foDoc.createElementNS(foNS, "fo:region-body"); ele2.appendChild(ele3); ele1 = foDoc.createElementNS(foNS, "fo:page-sequence"); root.appendChild(ele1); ele1.setAttributeNS(null, "master-reference", "letter"); ele2 = foDoc.createElementNS(foNS, "fo:flow"); ele1.appendChild(ele2); ele2.setAttributeNS(null, "flow-name", "xsl-region-body"); addElement(ele2, "fo:block", "Hello World!"); return foDoc; } /** * Adds an element to the DOM. * @param parent parent node to attach the new element to * @param newNodeName name of the new node * @param textVal content of the element */ protected static void addElement(Node parent, String newNodeName, String textVal) { if (textVal == null) { return; } // use only with text nodes Element newElement = parent.getOwnerDocument().createElementNS( foNS, newNodeName); Text elementText = parent.getOwnerDocument().createTextNode(textVal); newElement.appendChild(elementText); parent.appendChild(newElement); } }