587
|
1 |
/*
|
628
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
587
|
18 |
package com.nokia.ant.conditions;
|
|
19 |
|
628
|
20 |
import java.net.MalformedURLException;
|
|
21 |
import java.net.URL;
|
|
22 |
import java.util.Iterator;
|
|
23 |
|
|
24 |
import org.apache.tools.ant.Project;
|
587
|
25 |
import org.apache.tools.ant.ProjectComponent;
|
|
26 |
import org.apache.tools.ant.taskdefs.condition.Condition;
|
|
27 |
import org.dom4j.Document;
|
|
28 |
import org.dom4j.DocumentException;
|
|
29 |
import org.dom4j.Element;
|
|
30 |
import org.dom4j.io.SAXReader;
|
|
31 |
|
|
32 |
/**
|
|
33 |
* Condition to read check from diamonds and tell if ats has failed
|
628
|
34 |
*
|
587
|
35 |
* @ant.type name="hasAtsPassed"
|
|
36 |
*/
|
628
|
37 |
public class AtsCondition extends ProjectComponent implements Condition {
|
587
|
38 |
private int sleeptimesecs = 60;
|
628
|
39 |
|
|
40 |
public void setSleeptime(int seconds) {
|
587
|
41 |
sleeptimesecs = seconds;
|
|
42 |
}
|
628
|
43 |
|
587
|
44 |
/** Read from diamonds and signal if ats failed */
|
628
|
45 |
public boolean eval() {
|
587
|
46 |
String bid = getProject().getProperty("diamonds.build.id");
|
628
|
47 |
if (bid == null) {
|
|
48 |
log("Diamonds not enabled");
|
|
49 |
}
|
|
50 |
else {
|
587
|
51 |
boolean testsfound = false;
|
628
|
52 |
log("Looking for tests in diamonds");
|
587
|
53 |
SAXReader xmlReader = new SAXReader();
|
628
|
54 |
|
|
55 |
while (!testsfound) {
|
587
|
56 |
Document antDoc = null;
|
628
|
57 |
|
587
|
58 |
try {
|
628
|
59 |
URL url = new URL("http://" + getProject().getProperty("diamonds.host") + bid
|
|
60 |
+ "?fmt=xml");
|
587
|
61 |
antDoc = xmlReader.read(url);
|
628
|
62 |
}
|
|
63 |
catch (MalformedURLException e) {
|
587
|
64 |
// We are Ignoring the errors as no need to fail the build.
|
628
|
65 |
log("Not able to read the Diamonds URL http://"
|
|
66 |
+ getProject().getProperty("diamonds.host") + bid + "?fmt=xml: "
|
|
67 |
+ e.getMessage(), Project.MSG_ERR);
|
587
|
68 |
}
|
628
|
69 |
catch (DocumentException e) {
|
|
70 |
log("Not able to read the Diamonds URL http://"
|
|
71 |
+ getProject().getProperty("diamonds.host") + bid + "?fmt=xml: "
|
|
72 |
+ e.getMessage(), Project.MSG_ERR);
|
|
73 |
}
|
|
74 |
|
|
75 |
for (Iterator iterator = antDoc.selectNodes("//test/failed").iterator(); iterator.hasNext();) {
|
587
|
76 |
testsfound = true;
|
588
|
77 |
Element element = (Element) iterator.next();
|
|
78 |
String failed = element.getText();
|
628
|
79 |
if (!failed.equals("0")) {
|
|
80 |
log("ATS tests failed", Project.MSG_ERR);
|
|
81 |
|
|
82 |
for (Iterator iterator2 = antDoc.selectNodes("//actual_result").iterator(); iterator2.hasNext();) {
|
588
|
83 |
Element resultElement = (Element) iterator2.next();
|
628
|
84 |
log(resultElement.getText(), Project.MSG_ERR);
|
587
|
85 |
}
|
|
86 |
return false;
|
|
87 |
}
|
|
88 |
}
|
628
|
89 |
|
587
|
90 |
int noofdrops = Integer.parseInt(getProject().getProperty("drop.file.counter"));
|
628
|
91 |
if (noofdrops > 0) {
|
587
|
92 |
int testsrun = antDoc.selectNodes("//test").size();
|
628
|
93 |
if (testsrun < noofdrops) {
|
|
94 |
log(testsrun + " test completed, " + noofdrops + " total");
|
587
|
95 |
testsfound = false;
|
|
96 |
}
|
|
97 |
}
|
628
|
98 |
if (!testsfound) {
|
|
99 |
log("Tests not found sleeping for " + sleeptimesecs + " seconds");
|
587
|
100 |
try {
|
628
|
101 |
Thread.sleep(sleeptimesecs * 1000);
|
|
102 |
}
|
|
103 |
catch (InterruptedException e) {
|
587
|
104 |
// This will not affect the build process so ignoring.
|
628
|
105 |
log("Interrupted while reading ATS build status " + e.getMessage(), Project.MSG_DEBUG);
|
587
|
106 |
}
|
|
107 |
}
|
|
108 |
}
|
|
109 |
}
|
|
110 |
return true;
|
|
111 |
}
|
|
112 |
} |