ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r426650 - in /ant/antlibs/antunit/trunk: docs/antunit.html src/etc/testcases/antunit.xml src/etc/testcases/antunit/echo.xml src/main/org/apache/ant/antunit/AntUnit.java
Date Fri, 28 Jul 2006 19:16:30 GMT
Author: bodewig
Date: Fri Jul 28 12:16:29 2006
New Revision: 426650

URL: http://svn.apache.org/viewvc?rev=426650&view=rev
Log:
<propertyset> support for <antunit>

Added:
    ant/antlibs/antunit/trunk/src/etc/testcases/antunit/echo.xml   (with props)
Modified:
    ant/antlibs/antunit/trunk/docs/antunit.html
    ant/antlibs/antunit/trunk/src/etc/testcases/antunit.xml
    ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java

Modified: ant/antlibs/antunit/trunk/docs/antunit.html
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/docs/antunit.html?rev=426650&r1=426649&r2=426650&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/docs/antunit.html (original)
+++ ant/antlibs/antunit/trunk/docs/antunit.html Fri Jul 28 12:16:29 2006
@@ -131,6 +131,12 @@
     &lt;plainlistener/&gt; this one creates reports similar to the
     "plain" &lt;formatter&gt; of the &lt;junit&gt; task.</p>
 
+    <h4>propertyset</h4>
+
+    <p><a
+    href="http://ant.apache.org/manual/CoreTypes/propertyset.html">&lt;propertyset&gt;</a>s
+    can be used to pass properties to the build files under test.</p>
+
     <h3>Examples</h3>
 
     <p>This build file snippet (from src/etc/testcases/antunit/base.xml)</p>

Modified: ant/antlibs/antunit/trunk/src/etc/testcases/antunit.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/etc/testcases/antunit.xml?rev=426650&r1=426649&r2=426650&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/etc/testcases/antunit.xml (original)
+++ ant/antlibs/antunit/trunk/src/etc/testcases/antunit.xml Fri Jul 28 12:16:29 2006
@@ -50,6 +50,23 @@
     </au:antunit>
   </target>
 
+  <target name="testNoPropertySet">
+    <au:antunit>
+      <file file="antunit/echo.xml"/>
+      <au:plainlistener/>
+    </au:antunit>
+  </target>
+
+  <target name="testPropertySet">
+    <au:antunit>
+      <file file="antunit/echo.xml"/>
+      <au:plainlistener/>
+      <propertyset>
+        <propertyref builtin="system"/>
+      </propertyset>
+    </au:antunit>
+  </target>
+
   <target name="antunit-copy">
     <au:antunit>
       <fileset dir="antunit" includes="copy.xml"/>

Added: ant/antlibs/antunit/trunk/src/etc/testcases/antunit/echo.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/etc/testcases/antunit/echo.xml?rev=426650&view=auto
==============================================================================
--- ant/antlibs/antunit/trunk/src/etc/testcases/antunit/echo.xml (added)
+++ ant/antlibs/antunit/trunk/src/etc/testcases/antunit/echo.xml Fri Jul 28 12:16:29 2006
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<project name="echo-test" basedir="." default="all"
+  xmlns:au="antlib:org.apache.ant.antunit">
+
+  <target name="all">
+    <fail>Not a self-contained build file</fail>
+  </target>
+
+  <target name="testEcho">
+    <echo>${java.class.path}</echo>
+    <au:assertLogContains text="ant.jar"/>
+  </target>
+</project>
\ No newline at end of file

Propchange: ant/antlibs/antunit/trunk/src/etc/testcases/antunit/echo.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java?rev=426650&r1=426649&r2=426650&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java (original)
+++ ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java Fri Jul 28 12:16:29
2006
@@ -30,14 +30,16 @@
 import org.apache.tools.ant.BuildEvent;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.BuildListener;
+import org.apache.tools.ant.MagicNames;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.ProjectHelper;
 import org.apache.tools.ant.Target;
 import org.apache.tools.ant.Task;
 import org.apache.tools.ant.taskdefs.LogOutputStream;
+import org.apache.tools.ant.types.PropertySet;
 import org.apache.tools.ant.types.ResourceCollection;
-import org.apache.tools.ant.types.resources.Union;
 import org.apache.tools.ant.types.resources.FileResource;
+import org.apache.tools.ant.types.resources.Union;
 
 /**
  * Run all targets in a given build file who's name starts with "test".
@@ -79,6 +81,11 @@
     private ArrayList listeners = new ArrayList();
 
     /**
+     * propertysets.
+     */
+    private ArrayList propertySets = new ArrayList();
+
+    /**
      * has a failure occured?
      */
     private int failures=0;
@@ -123,6 +130,13 @@
     }
 
     /**
+     * Adds a PropertySet.
+     */
+    public void addPropertySet(PropertySet ps) {
+        propertySets.add(ps);
+    }
+
+    /**
      * stop testing if an error or failure occurs?
      */
     public void setFailOnError(boolean failOnError) {
@@ -169,13 +183,7 @@
         log("Running tests in build file " + f, Project.MSG_DEBUG);
 
         // setup project instance
-        newProject = new Project();
-        newProject.setDefaultInputStream(getProject().getDefaultInputStream());
-        newProject.setJavaVersionProperty();
-        newProject.setInputHandler(getProject().getInputHandler());
-        getProject().initSubProject(newProject);
-        newProject.setUserProperty("ant.file" , f.getAbsolutePath());
-        attachListeners(f, newProject);
+        newProject = createProjectForFile(f);
 
         // read build file
         ProjectHelper.configureProject(newProject, f);
@@ -292,6 +300,38 @@
         } else {
             super.handleErrorFlush(errorOutputToFlush);
         }
+    }
+
+    /**
+     * Creates a new project instance and configures it.
+     */
+    private Project createProjectForFile(File f) {
+        Project p = new Project();
+        p.setDefaultInputStream(getProject().getDefaultInputStream());
+        p.setJavaVersionProperty();
+        p.setInputHandler(getProject().getInputHandler());
+        getProject().initSubProject(p);
+        for (Iterator outer = propertySets.iterator(); outer.hasNext(); ) {
+            PropertySet set = (PropertySet) outer.next();
+            Map props = set.getProperties();
+            for (Iterator keys = props.keySet().iterator();
+                 keys.hasNext(); ) {
+                String key = keys.next().toString();
+                if (MagicNames.PROJECT_BASEDIR.equals(key)
+                    || MagicNames.ANT_FILE.equals(key)) {
+                    continue;
+                }
+
+                Object value = props.get(key);
+                if (value != null && value instanceof String
+                    && p.getProperty(key) == null) {
+                    p.setNewProperty(key, (String) value);
+                }
+            }
+        }
+        p.setUserProperty(MagicNames.ANT_FILE, f.getAbsolutePath());
+        attachListeners(f, p);
+        return p;
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message