Author: bodewig
Date: Mon Jul  4 06:56:09 2005
New Revision: 209080

URL: http://svn.apache.org/viewcvs?rev=209080&view=rev
Log:
logcontains condition - only usable during antunit runs

Added:
    
ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContains.java
   (with props)
Modified:
    ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml

Added: 
ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContains.java
URL: 
http://svn.apache.org/viewcvs/ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContains.java?rev=209080&view=auto
==============================================================================
--- 
ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContains.java
 (added)
+++ 
ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContains.java
 Mon Jul  4 06:56:09 2005
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.ant.antunit;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.ProjectComponent;
+import org.apache.tools.ant.taskdefs.Echo;
+import org.apache.tools.ant.taskdefs.condition.Condition;
+
+/**
+ * A condition that tests the log output of the current project for a
+ * given string.
+ */
+public class LogContains extends ProjectComponent implements Condition {
+
+    private String text;
+    private int logLevel = Project.MSG_INFO;
+
+    public void setText(String t) {
+        text = t;
+    }
+
+    public void setLevel(Echo.EchoLevel echoLevel) {
+        logLevel = echoLevel.getLevel();
+    }
+
+    public boolean eval() {
+        if (text == null) {
+            throw new BuildException("the text attribute is required");
+        }
+        Object o = getProject().getReference(LogCapturer.REFERENCE_ID);
+        if (o != null && o instanceof LogCapturer) {
+            LogCapturer c = (LogCapturer) o;
+            String log;
+            switch (logLevel) {
+            case Project.MSG_ERR:
+                log = c.getErrLog();
+                break;
+            case Project.MSG_WARN:
+                log = c.getWarnLog();
+                break;
+            case Project.MSG_INFO:
+                log = c.getInfoLog();
+                break;
+            case Project.MSG_VERBOSE:
+                log = c.getVerboseLog();
+                break;
+            case Project.MSG_DEBUG:
+                log = c.getDebugLog();
+                break;
+                
+            default:
+                throw new BuildException("Unknown logLevel: " + logLevel);
+            }
+            return log.indexOf(text) > -1;
+        } else {
+            return false;
+        }
+    }
+}
\ No newline at end of file

Propchange: 
ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContains.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml
URL: 
http://svn.apache.org/viewcvs/ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml?rev=209080&r1=209079&r2=209080&view=diff
==============================================================================
--- 
ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml 
(original)
+++ 
ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml 
Mon Jul  4 06:56:09 2005
@@ -27,6 +27,9 @@
   <typedef name="plainlistener"
     classname="org.apache.ant.antunit.PlainAntUnitListener"/>
 
+  <typedef name="logcontains"
+    classname="org.apache.ant.antunit.LogContains"/>
+
   <macrodef name="assertFalse">
     <attribute name="message" default="Assertion failed"/>
     <element name="assertion" implicit="true"/>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to