From a1003b0b8e5e18840b648d7da746efe92b093f74 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 24 Jul 2009 14:39:17 +0000 Subject: [PATCH] configurable display text and more control over progressbar in splash task. Submitted by Tomasz Bech. PR 39957 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@797496 13f79535-47bb-0310-9956-ffa450edef68 --- CONTRIBUTORS | 1 + WHATSNEW | 4 ++ contributors.xml | 4 ++ docs/manual/OptionalTasks/splash.html | 47 ++++++++++++-- .../taskdefs/optional/splash-test.xml | 45 +++++++++++++ .../optional/splash/SplashScreen.java | 64 ++++++++++++++++--- .../taskdefs/optional/splash/SplashTask.java | 31 ++++++++- 7 files changed, 180 insertions(+), 16 deletions(-) create mode 100644 src/etc/testcases/taskdefs/optional/splash-test.xml diff --git a/CONTRIBUTORS b/CONTRIBUTORS index abc1d3df8..6efe8d18c 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -307,6 +307,7 @@ Tom Cunningham Tom Dimock Tom Eugelink Tom May +Tomasz Bech Trejkaz Xaoza Ulrich Schmidt Victor Toni diff --git a/WHATSNEW b/WHATSNEW index 42623f167..438a53dee 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -804,6 +804,10 @@ Other changes: the http condition. Bugzilla Report 30244 + * 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 ============================================= diff --git a/contributors.xml b/contributors.xml index 14c6f3852..0e31cbb4c 100644 --- a/contributors.xml +++ b/contributors.xml @@ -1243,6 +1243,10 @@ Tom May + + Tomasz + Bech + Trejkaz Xaoz diff --git a/docs/manual/OptionalTasks/splash.html b/docs/manual/OptionalTasks/splash.html index bfa10a36d..f3a2f4421 100644 --- a/docs/manual/OptionalTasks/splash.html +++ b/docs/manual/OptionalTasks/splash.html @@ -52,10 +52,28 @@ whilst waiting for your builds to complete...

splash in milliseconds. No 5000 ms - + + + progressregexp + 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: (.*)%")
+ since Ant 1.8.0 + No + progress is increased every action + and log output line + + + displaytext + display text presented in the splash window
+ since Ant 1.8.0 + No + Building ... +

Deprecated properties

- + 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 @@ preference to the <setproxy> task, that makes it clear to rea 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. - + @@ -110,8 +128,27 @@ proxy attributes. showduration="5000"/> -

Splashes the jakarta logo, for -an initial period of 5 seconds.

+

Splashes the jakarta logo, for an initial period of 5 seconds.

+ +

Splash with controlled progress and nondefault text

+
+        <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>
+
+ diff --git a/src/etc/testcases/taskdefs/optional/splash-test.xml b/src/etc/testcases/taskdefs/optional/splash-test.xml new file mode 100644 index 000000000..5b5bbe282 --- /dev/null +++ b/src/etc/testcases/taskdefs/optional/splash-test.xml @@ -0,0 +1,45 @@ + + + + + + Old behaviour + + + + + + + + + + New features + + + Progress: 10% + + Progress: 20% + + Progress: 50% + + Progress: 70% + + Progress: 100% + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashScreen.java b/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashScreen.java index 49863b2b3..ff1cb5c1b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashScreen.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashScreen.java @@ -25,6 +25,9 @@ import java.awt.Font; 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 @@ class SplashScreen extends JWindow implements ActionListener, BuildListener { 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 @@ class SplashScreen extends JWindow implements ActionListener, BuildListener { } 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 @@ class SplashScreen extends JWindow implements ActionListener, BuildListener { } 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 @@ class SplashScreen extends JWindow implements ActionListener, BuildListener { 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; } + } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java index 768a49c8a..6e92fa877 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java @@ -47,6 +47,8 @@ public class SplashTask extends Task { 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; @@ -112,6 +114,29 @@ public class SplashTask extends Task { } + /** + * 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 @@ public class SplashTask extends Task { 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 @@ public class SplashTask extends Task { } } 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 @@ public class SplashTask extends Task { + e.getClass().getName() + " with message: " + e.getMessage(), Project.MSG_WARN); } + }
useproxy