buildframework/helium/sf/java/legacy/src/com/nokia/ant/conditions/AtsCondition.java
changeset 628 7c4a911dc066
parent 588 c7c26511138f
--- a/buildframework/helium/sf/java/legacy/src/com/nokia/ant/conditions/AtsCondition.java	Wed Jun 16 16:51:40 2010 +0300
+++ b/buildframework/helium/sf/java/legacy/src/com/nokia/ant/conditions/AtsCondition.java	Fri Aug 13 14:59:05 2010 +0300
@@ -1,30 +1,29 @@
 /*
-* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
-* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of the License "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
-*
-* Contributors:
-*
-* Description: 
-*
-*/
- 
+ * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description: 
+ *
+ */
+
 package com.nokia.ant.conditions;
 
-import org.apache.log4j.Logger;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Iterator;
+
+import org.apache.tools.ant.Project;
 import org.apache.tools.ant.ProjectComponent;
 import org.apache.tools.ant.taskdefs.condition.Condition;
-
-import java.util.Iterator;
-import java.net.MalformedURLException;
-import java.net.URL;
-
 import org.dom4j.Document;
 import org.dom4j.DocumentException;
 import org.dom4j.Element;
@@ -32,80 +31,78 @@
 
 /**
  * Condition to read check from diamonds and tell if ats has failed
+ * 
  * @ant.type name="hasAtsPassed"
  */
-public class AtsCondition extends ProjectComponent implements Condition
-{
-    private Logger log = Logger.getLogger(AtsCondition.class);
+public class AtsCondition extends ProjectComponent implements Condition {
     private int sleeptimesecs = 60;
-    
-    public void setSleeptime(int seconds)
-    {
+
+    public void setSleeptime(int seconds) {
         sleeptimesecs = seconds;
     }
-    
+
     /** Read from diamonds and signal if ats failed */
-    public boolean eval()
-    {
+    public boolean eval() {
         String bid = getProject().getProperty("diamonds.build.id");
-        if (bid == null)
-            log.info("Diamonds not enabled");
-        else
-        {
+        if (bid == null) {
+            log("Diamonds not enabled");
+        }
+        else {
             boolean testsfound = false;
-            log.info("Looking for tests in diamonds");
+            log("Looking for tests in diamonds");
             SAXReader xmlReader = new SAXReader();
-            
-            while (!testsfound)
-            {
+
+            while (!testsfound) {
                 Document antDoc = null;
-                
+
                 try {
-                    URL url = new URL("http://" + getProject().getProperty("diamonds.host") + bid + "?fmt=xml");
+                    URL url = new URL("http://" + getProject().getProperty("diamonds.host") + bid
+                        + "?fmt=xml");
                     antDoc = xmlReader.read(url);
-                } catch (MalformedURLException  e) {
+                }
+                catch (MalformedURLException e) {
                     // We are Ignoring the errors as no need to fail the build.
-                    log.error("Not able to read the Diamonds URL http://" + getProject().getProperty("diamonds.host") + bid + "?fmt=xml: " + e.getMessage());
-                } catch (DocumentException e) {
-                    log.error("Not able to read the Diamonds URL http://" + getProject().getProperty("diamonds.host") + bid + "?fmt=xml: " + e.getMessage());
+                    log("Not able to read the Diamonds URL http://"
+                        + getProject().getProperty("diamonds.host") + bid + "?fmt=xml: "
+                        + e.getMessage(), Project.MSG_ERR);
                 }
-                  
-                for (Iterator iterator = antDoc.selectNodes("//test/failed").iterator(); iterator.hasNext();)
-                {
+                catch (DocumentException e) {
+                    log("Not able to read the Diamonds URL http://"
+                        + getProject().getProperty("diamonds.host") + bid + "?fmt=xml: "
+                        + e.getMessage(), Project.MSG_ERR);
+                }
+
+                for (Iterator iterator = antDoc.selectNodes("//test/failed").iterator(); iterator.hasNext();) {
                     testsfound = true;
                     Element element = (Element) iterator.next();
                     String failed = element.getText();
-                    if (!failed.equals("0"))
-                    {
-                        log.error("ATS tests failed");
-                        
-                        for (Iterator iterator2 = antDoc.selectNodes("//actual_result").iterator(); iterator2.hasNext();)
-                        {
+                    if (!failed.equals("0")) {
+                        log("ATS tests failed", Project.MSG_ERR);
+
+                        for (Iterator iterator2 = antDoc.selectNodes("//actual_result").iterator(); iterator2.hasNext();) {
                             Element resultElement = (Element) iterator2.next();
-                            log.error(resultElement.getText());
+                            log(resultElement.getText(), Project.MSG_ERR);
                         }
                         return false;
                     }
                 }
-                
+
                 int noofdrops = Integer.parseInt(getProject().getProperty("drop.file.counter"));
-                if (noofdrops > 0)
-                {
+                if (noofdrops > 0) {
                     int testsrun = antDoc.selectNodes("//test").size();
-                    if (testsrun < noofdrops)
-                    {
-                        log.info(testsrun + " test completed, " + noofdrops + " total");
+                    if (testsrun < noofdrops) {
+                        log(testsrun + " test completed, " + noofdrops + " total");
                         testsfound = false;
                     }
                 }
-                if (!testsfound)
-                {
-                    log.info("Tests not found sleeping for " + sleeptimesecs + " seconds");
+                if (!testsfound) {
+                    log("Tests not found sleeping for " + sleeptimesecs + " seconds");
                     try {
-                    Thread.sleep(sleeptimesecs * 1000);
-                    } catch (InterruptedException e) {
+                        Thread.sleep(sleeptimesecs * 1000);
+                    }
+                    catch (InterruptedException e) {
                         // This will not affect the build process so ignoring.
-                        log.debug("Interrupted while reading ATS build status " + e.getMessage());
+                        log("Interrupted while reading ATS build status " + e.getMessage(), Project.MSG_DEBUG);
                     }
                 }
             }