git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@797496 13f79535-47bb-0310-9956-ffa450edef68master
@@ -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 | ||||
@@ -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 | ||||
============================================= | ============================================= | ||||
@@ -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> | ||||
@@ -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><setproxy></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="5000"/> | showduration="5000"/> | ||||
</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> | |||||
<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> | |||||
</pre></blockquote> | |||||
</body> | </body> | ||||
@@ -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> |
@@ -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; | |||||
} | } | ||||
} | } | ||||
@@ -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); | ||||
} | } | ||||
} | } |