You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2009/07/24 16:39:18 UTC

svn commit: r797496 - in /ant/core/trunk: ./ docs/manual/OptionalTasks/ src/etc/testcases/taskdefs/optional/ src/main/org/apache/tools/ant/taskdefs/optional/splash/

Author: bodewig
Date: Fri Jul 24 14:39:17 2009
New Revision: 797496

URL: http://svn.apache.org/viewvc?rev=797496&view=rev
Log:
configurable display text and more control over progressbar in splash task.  Submitted by Tomasz Bech.  PR 39957

Added:
    ant/core/trunk/src/etc/testcases/taskdefs/optional/splash-test.xml   (with props)
Modified:
    ant/core/trunk/CONTRIBUTORS
    ant/core/trunk/WHATSNEW
    ant/core/trunk/contributors.xml
    ant/core/trunk/docs/manual/OptionalTasks/splash.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashScreen.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java

Modified: ant/core/trunk/CONTRIBUTORS
URL: http://svn.apache.org/viewvc/ant/core/trunk/CONTRIBUTORS?rev=797496&r1=797495&r2=797496&view=diff
==============================================================================
Binary files - no diff available.

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=797496&r1=797495&r2=797496&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Jul 24 14:39:17 2009
@@ -804,6 +804,10 @@
    the http condition.
    Bugzilla Report 30244
 
+ * <splash> now supports a configurable display text and a regular
+   expression based way to determine progress based on logged messages.
+   Bugzilla Report 39957.
+
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================
 

Modified: ant/core/trunk/contributors.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/contributors.xml?rev=797496&r1=797495&r2=797496&view=diff
==============================================================================
--- ant/core/trunk/contributors.xml (original)
+++ ant/core/trunk/contributors.xml Fri Jul 24 14:39:17 2009
@@ -1244,6 +1244,10 @@
     <last>May</last>
   </name>
   <name>
+    <first>Tomasz</first>
+    <last>Bech</last>
+  </name>
+  <name>
     <first>Trejkaz</first>
     <last>Xaoz</last>
   </name>

Modified: ant/core/trunk/docs/manual/OptionalTasks/splash.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/OptionalTasks/splash.html?rev=797496&r1=797495&r2=797496&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/OptionalTasks/splash.html (original)
+++ ant/core/trunk/docs/manual/OptionalTasks/splash.html Fri Jul 24 14:39:17 2009
@@ -52,10 +52,28 @@
     splash in milliseconds.</td>
     <td valign="top" align="center">No</td>
     <td valign="top" align="center">5000 ms</td>
-  </tr>  
+  </tr>
+  <tr>
+    <td valign="top">progressregexp</td>
+    <td valign="top">Progress regular expression which is used to
+      parse the output and dig out current progress. Exactly one group
+      pattern must exists, and it represents the progress number (0-100)
+      (i.e "Progress: (.*)%")<br/>
+      <em>since Ant 1.8.0</em></td>
+    <td valign="top" align="center">No</td>
+    <td valign="top" align="center">progress is increased every action
+      and log output line</td>
+  </tr>
+  <tr>
+    <td valign="top">displaytext</td>
+    <td valign="top">display text presented in the splash window<br/>
+      <em>since Ant 1.8.0</em></td>
+    <td valign="top" align="center">No</td>
+    <td valign="top" align="center">Building ...</td>
+  </tr>
 </table>
 <h3>Deprecated properties</h3>
-  
+
 The following properties can be used to configure the proxy settings to retrieve
 an image from behind a firewall. However, the settings apply not just to this
 task, but to all following tasks. Therefore they are now mostly deprecated in 
@@ -63,7 +81,7 @@
 the build exactly what is going on. We say mostly as this task's support
 includes proxy authentication, so you may still need to use its
 proxy attributes.
-  
+
 <table border="1" cellpadding="2" cellspacing="0">
   <tr>
     <td valign="top">useproxy</td>
@@ -110,8 +128,27 @@
            showduration=&quot;5000&quot;/&gt;
 
 </pre></blockquote>
-<p>Splashes the jakarta logo, for
-an initial period of 5 seconds.</p>
+<p>Splashes the jakarta logo, for an initial period of 5 seconds.</p>
+
+<p>Splash with controlled progress and nondefault text</p>
+<blockquote><pre>
+        &lt;target name="test_new_features"&gt;
+                &lt;echo&gt;New features&lt;/echo&gt;
+                &lt;splash progressRegExp="Progress: (.*)%" showduration="0" displayText="Test text"/&gt;
+                &lt;sleep seconds="1"/&gt;
+                &lt;echo&gt;Progress: 10%&lt;/echo&gt;
+                &lt;sleep seconds="1"/&gt;
+                &lt;echo&gt;Progress: 20%&lt;/echo&gt;
+                &lt;sleep seconds="1"/&gt;
+                &lt;echo&gt;Progress: 50%&lt;/echo&gt;
+                &lt;sleep seconds="1"/&gt;
+                &lt;echo&gt;Progress: 70%&lt;/echo&gt;
+                &lt;sleep seconds="1"/&gt;
+                &lt;echo&gt;Progress: 100%&lt;/echo&gt;
+                &lt;sleep seconds="3"/&gt;
+        &lt;/target&gt;
+</pre></blockquote>
+
 
 
 </body>

Added: ant/core/trunk/src/etc/testcases/taskdefs/optional/splash-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/taskdefs/optional/splash-test.xml?rev=797496&view=auto
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/optional/splash-test.xml (added)
+++ ant/core/trunk/src/etc/testcases/taskdefs/optional/splash-test.xml Fri Jul 24 14:39:17 2009
@@ -0,0 +1,45 @@
+<?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 default="test_new_features" name="splash-test" basedir=".">
+
+  <target name="test_old_behaviour">
+    <echo>Old behaviour</echo>
+    <splash showduration="0"/>
+    <sleep seconds="1"/>
+    <sleep seconds="1"/>
+    <sleep seconds="1"/>
+    <sleep seconds="1"/>
+    <sleep seconds="1"/>
+  </target>
+
+  <target name="test_new_features">
+    <echo>New features</echo>
+    <splash progressregexp="Progress: (.*)%" showduration="0" displayText="Test text"/>
+    <sleep seconds="1"/>
+    <echo>Progress: 10%</echo>
+    <sleep seconds="1"/>
+    <echo>Progress: 20%</echo>
+    <sleep seconds="1"/>
+    <echo>Progress: 50%</echo>
+    <sleep seconds="1"/>
+    <echo>Progress: 70%</echo>
+    <sleep seconds="1"/>
+    <echo>Progress: 100%</echo>
+    <sleep seconds="3"/>
+  </target>
+</project>

Propchange: ant/core/trunk/src/etc/testcases/taskdefs/optional/splash-test.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashScreen.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashScreen.java?rev=797496&r1=797495&r2=797496&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashScreen.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashScreen.java Fri Jul 24 14:39:17 2009
@@ -25,6 +25,9 @@
 import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 import javax.swing.BorderFactory;
 import javax.swing.ImageIcon;
 import javax.swing.JLabel;
@@ -41,17 +44,35 @@
     private int total;
     private static final int MIN = 0;
     private static final int MAX = 200;
+    private Pattern progressRegExpPattern;
 
     public SplashScreen(String msg) {
-        init(null);
-        setText(msg);
+        this(msg, null, null);
     }
 
     public SplashScreen(ImageIcon img) {
-        init(img);
+        this(img, null, null);
+    }
+
+    public SplashScreen(String msg, String progressRegExp, String displayText) {
+        init(null, progressRegExp, displayText);
+        setText(msg);
+    }
+
+    public SplashScreen(ImageIcon img, String progressRegExp,
+                        String displayText) {
+        init(img, progressRegExp, displayText);
     }
 
     protected void init(ImageIcon img) {
+        init(img, null, null);
+    }
+
+    protected void init(ImageIcon img, String progressRegExp,
+                        String displayText) {
+        if (progressRegExp != null) {
+            progressRegExpPattern = Pattern.compile(progressRegExp);
+        }
 
         JPanel pan = (JPanel) getContentPane();
         JLabel piccy;
@@ -62,7 +83,10 @@
         }
 
         piccy.setBorder(BorderFactory.createLineBorder(Color.black, 1));
-        text = new JLabel("Building....", JLabel.CENTER);
+        if (displayText == null) {
+            displayText = "Building....";
+        }
+        text = new JLabel(displayText, JLabel.CENTER);
         text.setFont(new Font("Sans-Serif", Font.BOLD, FONT_SIZE));
         text.setBorder(BorderFactory.createEtchedBorder());
 
@@ -94,12 +118,14 @@
     }
 
     public void actionPerformed(ActionEvent a) {
-        if (total < MAX) {
-            total++;
-        } else {
-            total = MIN;
+        if (!hasProgressPattern()) {
+            if (total < MAX) {
+                total++;
+            } else {
+                total = MIN;
+            }
+            pb.setValue(total);
         }
-        pb.setValue(total);
     }
 
     public void buildStarted(BuildEvent event) {
@@ -129,6 +155,26 @@
 
     public void messageLogged(BuildEvent event) {
         actionPerformed(null);
+        if (hasProgressPattern()) {
+            String message = event.getMessage();
+            Matcher matcher = progressRegExpPattern.matcher(message);
+            if (matcher != null && matcher.matches()) {
+                String gr = matcher.group(1);
+                try {
+                    int i = Math.min(new Integer(gr).intValue() * 2, MAX);
+                    pb.setValue(i);
+                } catch (NumberFormatException e) {
+                    //TODO: how to reach logger?!?
+                    //log("Number parsing error in progressRegExp", Project.MSG_VERBOSE);
+
+                }
+            }
+        }
+    }
+
+    protected boolean hasProgressPattern() {
+        return progressRegExpPattern != null;
     }
+
 }
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java?rev=797496&r1=797495&r2=797496&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java Fri Jul 24 14:39:17 2009
@@ -47,6 +47,8 @@
     private String port = "80";
     private int showDuration = DEFAULT_SHOW_DURATION;
     private boolean useProxy = false;
+    private String progressRegExp = null;
+    private String displayText = null;
 
     private static SplashScreen splash = null;
 
@@ -113,6 +115,29 @@
 
 
     /**
+     * Progress regular expression which is used to parse the output
+     * and dig out current progress optional; if not provided,
+     * progress is increased every action and log output line
+     * @param progressRegExp Progress regular expression, exactly one
+     * group pattern must exists, and it represents the progress
+     * number (0-100) (i.e "Progress: (.*)%")
+     * @since Ant 1.8.0
+     */
+    public void setProgressRegExp(String progressRegExp) {
+        this.progressRegExp = progressRegExp;
+    }
+
+    /**
+     * Sets the display text presented in the splash window.
+     * optional; defaults to "Building ..." 
+     * @param displayText the display text presented the splash window
+     * @since Ant 1.8.0
+     */
+    public void setDisplayText(String displayText) {
+        this.displayText = displayText;
+    }
+
+    /**
      * Execute the task.
      * @throws BuildException on error
      */
@@ -201,7 +226,7 @@
 
                 try {
                     ImageIcon img = new ImageIcon(bout.toByteArray());
-                    splash = new SplashScreen(img);
+                    splash = new SplashScreen(img, progressRegExp, displayText);
                     success = true;
                 } catch (Throwable e) {
                     logHeadless(e);
@@ -221,7 +246,8 @@
             }
         } else {
             try {
-                splash = new SplashScreen("Image Unavailable.");
+                splash = new SplashScreen("Image Unavailable.", progressRegExp,
+                                          displayText);
                 success = true;
             } catch (Throwable e) {
                 logHeadless(e);
@@ -245,4 +271,5 @@
             + e.getClass().getName() + " with message: " + e.getMessage(),
             Project.MSG_WARN);
     }
+
 }