Browse Source

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
master
Stefan Bodewig 16 years ago
parent
commit
a1003b0b8e
7 changed files with 180 additions and 16 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +4
    -0
      WHATSNEW
  3. +4
    -0
      contributors.xml
  4. +42
    -5
      docs/manual/OptionalTasks/splash.html
  5. +45
    -0
      src/etc/testcases/taskdefs/optional/splash-test.xml
  6. +55
    -9
      src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashScreen.java
  7. +29
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java

+ 1
- 0
CONTRIBUTORS View File

@@ -307,6 +307,7 @@ Tom Cunningham
Tom Dimock Tom Dimock
Tom Eugelink Tom Eugelink
Tom May Tom May
Tomasz Bech
Trejkaz Xaoza Trejkaz Xaoza
Ulrich Schmidt Ulrich Schmidt
Victor Toni Victor Toni


+ 4
- 0
WHATSNEW View File

@@ -804,6 +804,10 @@ Other changes:
the http condition. the http condition.
Bugzilla Report 30244 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 Changes from Ant 1.7.0 TO Ant 1.7.1
============================================= =============================================




+ 4
- 0
contributors.xml View File

@@ -1243,6 +1243,10 @@
<first>Tom</first> <first>Tom</first>
<last>May</last> <last>May</last>
</name> </name>
<name>
<first>Tomasz</first>
<last>Bech</last>
</name>
<name> <name>
<first>Trejkaz</first> <first>Trejkaz</first>
<last>Xaoz</last> <last>Xaoz</last>


+ 42
- 5
docs/manual/OptionalTasks/splash.html View File

@@ -52,10 +52,28 @@ whilst waiting for your builds to complete...</p>
splash in milliseconds.</td> splash in milliseconds.</td>
<td valign="top" align="center">No</td> <td valign="top" align="center">No</td>
<td valign="top" align="center">5000 ms</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> </table>
<h3>Deprecated properties</h3> <h3>Deprecated properties</h3>
The following properties can be used to configure the proxy settings to retrieve 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 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 task, but to all following tasks. Therefore they are now mostly deprecated in
@@ -63,7 +81,7 @@ preference to the <code>&lt;setproxy&gt;</code> task, that makes it clear to rea
the build exactly what is going on. We say mostly as this task's support 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 includes proxy authentication, so you may still need to use its
proxy attributes. proxy attributes.
<table border="1" cellpadding="2" cellspacing="0"> <table border="1" cellpadding="2" cellspacing="0">
<tr> <tr>
<td valign="top">useproxy</td> <td valign="top">useproxy</td>
@@ -110,8 +128,27 @@ proxy attributes.
showduration=&quot;5000&quot;/&gt; showduration=&quot;5000&quot;/&gt;


</pre></blockquote> </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> </body>


+ 45
- 0
src/etc/testcases/taskdefs/optional/splash-test.xml View File

@@ -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>

+ 55
- 9
src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashScreen.java View File

@@ -25,6 +25,9 @@ import java.awt.Font;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JLabel; import javax.swing.JLabel;
@@ -41,17 +44,35 @@ class SplashScreen extends JWindow implements ActionListener, BuildListener {
private int total; private int total;
private static final int MIN = 0; private static final int MIN = 0;
private static final int MAX = 200; private static final int MAX = 200;
private Pattern progressRegExpPattern;


public SplashScreen(String msg) { public SplashScreen(String msg) {
init(null);
setText(msg);
this(msg, null, null);
} }


public SplashScreen(ImageIcon img) { 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) { 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(); JPanel pan = (JPanel) getContentPane();
JLabel piccy; JLabel piccy;
@@ -62,7 +83,10 @@ class SplashScreen extends JWindow implements ActionListener, BuildListener {
} }


piccy.setBorder(BorderFactory.createLineBorder(Color.black, 1)); 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.setFont(new Font("Sans-Serif", Font.BOLD, FONT_SIZE));
text.setBorder(BorderFactory.createEtchedBorder()); text.setBorder(BorderFactory.createEtchedBorder());


@@ -94,12 +118,14 @@ class SplashScreen extends JWindow implements ActionListener, BuildListener {
} }


public void actionPerformed(ActionEvent a) { 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) { public void buildStarted(BuildEvent event) {
@@ -129,6 +155,26 @@ class SplashScreen extends JWindow implements ActionListener, BuildListener {


public void messageLogged(BuildEvent event) { public void messageLogged(BuildEvent event) {
actionPerformed(null); 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;
} }

} }



+ 29
- 2
src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java View File

@@ -47,6 +47,8 @@ public class SplashTask extends Task {
private String port = "80"; private String port = "80";
private int showDuration = DEFAULT_SHOW_DURATION; private int showDuration = DEFAULT_SHOW_DURATION;
private boolean useProxy = false; private boolean useProxy = false;
private String progressRegExp = null;
private String displayText = null;


private static SplashScreen splash = 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. * Execute the task.
* @throws BuildException on error * @throws BuildException on error
@@ -201,7 +226,7 @@ public class SplashTask extends Task {


try { try {
ImageIcon img = new ImageIcon(bout.toByteArray()); ImageIcon img = new ImageIcon(bout.toByteArray());
splash = new SplashScreen(img);
splash = new SplashScreen(img, progressRegExp, displayText);
success = true; success = true;
} catch (Throwable e) { } catch (Throwable e) {
logHeadless(e); logHeadless(e);
@@ -221,7 +246,8 @@ public class SplashTask extends Task {
} }
} else { } else {
try { try {
splash = new SplashScreen("Image Unavailable.");
splash = new SplashScreen("Image Unavailable.", progressRegExp,
displayText);
success = true; success = true;
} catch (Throwable e) { } catch (Throwable e) {
logHeadless(e); logHeadless(e);
@@ -245,4 +271,5 @@ public class SplashTask extends Task {
+ e.getClass().getName() + " with message: " + e.getMessage(), + e.getClass().getName() + " with message: " + e.getMessage(),
Project.MSG_WARN); Project.MSG_WARN);
} }

} }

Loading…
Cancel
Save