1402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
2402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Created on Apr 8, 2003
3402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
4402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * To change the template for this generated file go to
5402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Window>Preferences>Java>Code Generation>Code and Comments
6402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
7402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpackage org.eclipse.releng.generators;
8402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.io.File;
9402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
10402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
11402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
12402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
13402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @author SDimitrov
14402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
15402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * To change the template for this generated type comment go to
16402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Window>Preferences>Java>Code Generation>Code and Comments
17402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
18402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic class EclipseTestResultsGeneratorNoMail extends TestResultsGenerator {
19402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
20402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
21402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// buildType used to determine if mail should be sent on
22402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// successful build completion
23402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	private String buildType;
24402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	private boolean sendMail=true;
25402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	/**
26402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	 * @return
27402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	 */
28402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public String getBuildType() {
29402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		return buildType;
30402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
31402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
32402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	/**
33402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	 * @param buildType
34402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	 */
35402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public void setBuildType(String buildType) {
36402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.buildType = buildType;
37402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
38402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
39402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public static void main(String[] args) {
40402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		String publishingContent="C:\\Documents and Settings\\IBMEmployee\\workspace\\org.eclipse.releng.eclipsebuilder\\eclipse\\publishingFiles";
41402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
42402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		EclipseTestResultsGeneratorNoMail test = new EclipseTestResultsGeneratorNoMail();
43402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		test.buildType="N";
44402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		test.setIsBuildTested(true);
45402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		test.setDropTokenList(
46402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		"%sdk%,%tests%,%example%,%rcpruntime%,%rcpsdk%,%deltapack%,%icubase%,%runtime%,%platformsdk%,%jdt%,%jdtsdk%,%jdtc%,%jarprocessor%,%pde%,%pdesdk%,%cvs%,%cvssdk%,%teamextras%,%swt%,%relengtools%");
47402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		test.getDropTokensFromList(test.getDropTokenList());
48402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		test.setXmlDirectoryName("C:\\junk\\testresults\\xml");
49402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		test.setHtmlDirectoryName("C:\\junk\\testresults\\html");
50402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		test.setDropDirectoryName("C:\\junk");
51402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		test.setTestResultsTemplateFileName(
52402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				publishingContent+"\\templateFiles\\testResults.php.template");
53402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		test.setDropTemplateFileName(
54402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				publishingContent+"\\templateFiles\\index.php.template");
55402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		test.setTestResultsHtmlFileName("testResults.php");
56402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		test.setDropHtmlFileName("index.php");
57402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		//test.setDropHtmlFileName("index.html");
58402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		test.setPlatformIdentifierToken("%platform%");
59402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
60402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		test.setPlatformSpecificTemplateList("Windows,"+publishingContent+"/templateFiles/platform.php.template,winPlatform.php;Linux,"+publishingContent+"/templateFiles/platform.php.template,linPlatform.php;Solaris,"+publishingContent+"/templateFiles/platform.php.template,solPlatform.php;AIX,"+publishingContent+"/templateFiles/platform.php.template,aixPlatform.php;Macintosh,"+publishingContent+"/templateFiles/platform.php.template,macPlatform.php;Source Build,"+publishingContent+"/templateFiles/sourceBuilds.php.template,sourceBuilds.php");
61402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		/*<property name="platformIdentifierToken" value="%platform%" />
62402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			<property name="platformSpecificTemplateList" value="Windows,${publishingContent}/templateFiles/platform.php.template,winPlatform.php;Linux,${publishingContent}/templateFiles/platform.php.template,linPlatform.php;Solaris,${publishingContent}/templateFiles/platform.php.template,solPlatform.php;AIX,${publishingContent}/templateFiles/platform.php.template,aixPlatform.php;Macintosh,${publishingContent}/templateFiles/platform.php.template,macPlatform.php;Source Build,${publishingContent}/templateFiles/sourceBuilds.php.template,sourceBuilds.php" />
63402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			*/
64402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
65402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		test.setHrefTestResultsTargetPath("testresults");
66402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		test.setCompileLogsDirectoryName(
67402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			"C:\\junk\\compilelogs");
68402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		test.setHrefCompileLogsTargetPath("compilelogs");
69402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		test.setTestManifestFileName("C:\\junk\\testManifest.xml");
70402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		test.execute();
71402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
72402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
73402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public void execute() {
74402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		super.execute();
75402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		if (sendMail)
76402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//			mailResults();
77402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
78402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
79402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	protected String processDropRow(PlatformStatus aPlatform) {
80402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		String imageName = "";
81402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
82402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (aPlatform.hasErrors()) {
83402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			imageName =
84402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				"<a href=\"" + getTestResultsHtmlFileName() + "\"><img src = \"FAIL.gif\" width=19 height=23></a>";
85402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			testResultsStatus = "failed";
86402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
87402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		} else {
88402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			if (testsRan()) {
89402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				imageName = "<img src = \"OK.gif\" width=19 height=23>";
90402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			} else {
91402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				if (isBuildTested()) {
92402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					imageName =
93402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll						"<font size=\"-1\" color=\"#FF0000\">pending</font>";
94402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					testResultsStatus = "pending";
95402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				} else {
96402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					imageName = "<img src = \"OK.gif\" width=19 height=23>";
97402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				}
98402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
99402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
100402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
101402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		String result = "<tr>";
102402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
103402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		result = result + "<td><div align=left>" + imageName + "</div></td>\n";
104402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		result = result + "<td>" + aPlatform.getName() + "</td>";
105402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
106402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		//generate http, md5 and sha1 links by calling php functions in the template
107402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		result = result + "<td><?php genLinks($_SERVER[\"SERVER_NAME\"],\"@buildlabel@\",\"" + aPlatform.getFileName() +"\"); ?></td>\n";
108402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		result = result + "</tr>\n";
109402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
110402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		return result;
111402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
112402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
113402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//	private void mailResults() {
114402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		//send a different message for the following cases:
115402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		//build is not tested at all
116402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		//build is tested, tests have not run
117402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		//build is tested, tests have run with error and or failures
118402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		//build is tested, tests have run with no errors or failures
119402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		try {
120402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//			mailer = new Mailer();
121402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		} catch (NoClassDefFoundError e) {
122402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//			return;
123402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		}
124402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		String buildLabel = mailer.getBuildProperties().getBuildLabel();
125402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		String httpUrl = mailer.getBuildProperties().getHttpUrl()+"/"+buildLabel;
126402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll////		String ftpUrl = mailer.getBuildProperties().getftpUrl()+"/"+buildLabel;
127402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//
128402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		String subject = "Build is complete.  ";
129402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//
130402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		String downloadLinks="\n\nHTTP Download:\n\n\t"+httpUrl+" \n\n";
131402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//	/*	downloadLinks=downloadLinks.concat("FTP Download:\n\n");
132402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		downloadLinks=downloadLinks.concat("\tuser: anonymous\n\tpassword: (e-mail address or leave blank)\n\tserver:  download.eclipse.org\n\tcd to directory:  "+buildLabel);
133402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		downloadLinks=downloadLinks.concat("\n\n\tor");
134402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		downloadLinks=downloadLinks.concat("\n\n\t"+ftpUrl);*/
135402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//
136402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		//provide http links
137402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		String message = "The build is complete."+downloadLinks;
138402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//
139402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		if (testsRan()) {
140402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//			subject = "Automated JUnit testing complete.  ";
141402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//			message = "Automated JUnit testing is complete.  ";
142402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//			subject =
143402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//				subject.concat(
144402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//					(getTestResultsWithProblems().endsWith("\n"))
145402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//						? "All tests pass."
146402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//						: "Test failures/errors occurred.");
147402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//			message =
148402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//				message.concat(
149402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//					(getTestResultsWithProblems().endsWith("\n"))
150402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//						? "All tests pass."
151402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//						: "Test failures/errors occurred in the following:  "
152402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//							+ getTestResultsWithProblems())+downloadLinks;
153402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		} else if (isBuildTested() && (!buildType.equals("N"))) {
154402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//			subject = subject.concat("Automated JUnit testing is starting.");
155402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//			message = "The " + subject+downloadLinks;
156402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		}
157402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//
158402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		if (subject.endsWith("Test failures/errors occurred."))
159402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//			mailer.sendMessage(subject, message);
160402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		else if (!buildType.equals("N"))
161402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//			mailer.sendMessage(subject, message);
162402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//
163402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//	}
164402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
165402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public boolean isSendMail() {
166402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		return sendMail;
167402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
168402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
169402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public void setSendMail(boolean sendMail) {
170402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.sendMail = sendMail;
171402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
172402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
173402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
174