587
|
1 |
/*
|
|
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 |
|
|
18 |
package com.nokia.ant.conditions;
|
|
19 |
|
|
20 |
import org.apache.log4j.Logger;
|
|
21 |
import org.apache.tools.ant.ProjectComponent;
|
|
22 |
import org.apache.tools.ant.taskdefs.condition.Condition;
|
|
23 |
|
|
24 |
import java.util.Iterator;
|
|
25 |
import java.net.MalformedURLException;
|
|
26 |
import java.net.URL;
|
|
27 |
|
|
28 |
import org.dom4j.Document;
|
|
29 |
import org.dom4j.DocumentException;
|
|
30 |
import org.dom4j.Element;
|
|
31 |
import org.dom4j.io.SAXReader;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* Condition to read check from diamonds and tell if ats has failed
|
|
35 |
* @ant.type name="hasAtsPassed"
|
|
36 |
*/
|
|
37 |
public class AtsCondition extends ProjectComponent implements Condition
|
|
38 |
{
|
|
39 |
private Logger log = Logger.getLogger(AtsCondition.class);
|
|
40 |
private int sleeptimesecs = 60;
|
|
41 |
|
|
42 |
public void setSleeptime(int seconds)
|
|
43 |
{
|
|
44 |
sleeptimesecs = seconds;
|
|
45 |
}
|
|
46 |
|
|
47 |
/** Read from diamonds and signal if ats failed */
|
|
48 |
public boolean eval()
|
|
49 |
{
|
|
50 |
String bid = getProject().getProperty("diamonds.build.id");
|
|
51 |
if (bid == null)
|
|
52 |
log.info("Diamonds not enabled");
|
|
53 |
else
|
|
54 |
{
|
|
55 |
boolean testsfound = false;
|
|
56 |
log.info("Looking for tests in diamonds");
|
|
57 |
SAXReader xmlReader = new SAXReader();
|
|
58 |
|
|
59 |
while (!testsfound)
|
|
60 |
{
|
|
61 |
Document antDoc = null;
|
|
62 |
|
|
63 |
try {
|
|
64 |
URL url = new URL("http://" + getProject().getProperty("diamonds.host") + bid + "?fmt=xml");
|
|
65 |
antDoc = xmlReader.read(url);
|
|
66 |
} catch (MalformedURLException e) {
|
|
67 |
// We are Ignoring the errors as no need to fail the build.
|
|
68 |
log.error("Not able to read the Diamonds URL http://" + getProject().getProperty("diamonds.host") + bid + "?fmt=xml: " + e.getMessage());
|
|
69 |
} catch (DocumentException e) {
|
|
70 |
log.error("Not able to read the Diamonds URL http://" + getProject().getProperty("diamonds.host") + bid + "?fmt=xml: " + e.getMessage());
|
|
71 |
}
|
|
72 |
|
|
73 |
for (Iterator iterator = antDoc.selectNodes("//test/failed").iterator(); iterator.hasNext();)
|
|
74 |
{
|
|
75 |
testsfound = true;
|
|
76 |
Element e = (Element) iterator.next();
|
|
77 |
String failed = e.getText();
|
|
78 |
if (!failed.equals("0"))
|
|
79 |
{
|
|
80 |
log.error("ATS tests failed");
|
|
81 |
|
|
82 |
for (Iterator iterator2 = antDoc.selectNodes("//actual_result").iterator(); iterator2.hasNext();)
|
|
83 |
{
|
|
84 |
Element e2 = (Element) iterator2.next();
|
|
85 |
log.error(e2.getText());
|
|
86 |
}
|
|
87 |
return false;
|
|
88 |
}
|
|
89 |
}
|
|
90 |
|
|
91 |
int noofdrops = Integer.parseInt(getProject().getProperty("drop.file.counter"));
|
|
92 |
if (noofdrops > 0)
|
|
93 |
{
|
|
94 |
int testsrun = antDoc.selectNodes("//test").size();
|
|
95 |
if (testsrun < noofdrops)
|
|
96 |
{
|
|
97 |
log.info(testsrun + " test completed, " + noofdrops + " total");
|
|
98 |
testsfound = false;
|
|
99 |
}
|
|
100 |
}
|
|
101 |
if (!testsfound)
|
|
102 |
{
|
|
103 |
log.info("Tests not found sleeping for " + sleeptimesecs + " seconds");
|
|
104 |
try {
|
|
105 |
Thread.sleep(sleeptimesecs * 1000);
|
|
106 |
} catch (InterruptedException e) {
|
|
107 |
// This will not affect the build process so ignoring.
|
|
108 |
log.debug("Interrupted while reading ATS build status " + e.getMessage());
|
|
109 |
}
|
|
110 |
}
|
|
111 |
}
|
|
112 |
}
|
|
113 |
return true;
|
|
114 |
}
|
|
115 |
} |