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