Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 246   Methods: 8
NCLOC: 125   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SplashTask.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2002 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 
 55   
 package org.apache.tools.ant.taskdefs.optional.splash;
 56   
 
 57   
 import java.io.ByteArrayOutputStream;
 58   
 import java.io.DataInputStream;
 59   
 import java.io.IOException;
 60   
 import java.io.InputStream;
 61   
 import java.net.URL;
 62   
 import java.net.URLConnection;
 63   
 import javax.swing.ImageIcon;
 64   
 import org.apache.tools.ant.BuildException;
 65   
 import org.apache.tools.ant.Project;
 66   
 import org.apache.tools.ant.Task;
 67   
  
 68   
 /**
 69   
  * Creates a splash screen. The splash screen is displayed
 70   
  * for the duration of the build and includes a handy progress bar as
 71   
  * well. Use in conjunction with the sound task to provide interest
 72   
  * whilst waiting for your builds to complete...
 73   
  * @since Ant1.5 
 74   
  * @author Les Hughes (leslie.hughes@rubus.com)
 75   
  */
 76   
 public class SplashTask extends Task {
 77   
 
 78   
     private String imgurl = null;
 79   
     private String proxy = null;
 80   
     private String user = null;
 81   
     private String password = null;
 82   
     private String port = "80";
 83   
     private int showDuration = 5000;
 84   
     private boolean useProxy = false;
 85   
 
 86   
     private static SplashScreen splash = null;
 87   
 
 88   
     /**
 89   
      * A URL pointing to an image to display; optional, default antlogo.gif
 90   
      * from the classpath.
 91   
      */
 92  0
     public void setImageURL(String imgurl) {
 93  0
         this.imgurl = imgurl;
 94   
     }
 95   
     
 96   
     /**
 97   
      * flag to enable proxy settings; optional, deprecated : consider
 98   
      * using &lt;setproxy&gt; instead 
 99   
      * @deprecated use org.apache.tools.ant.taskdefs.optional.SetProxy
 100   
      */
 101  0
     public void setUseproxy(boolean useProxy) {
 102  0
         this.useProxy = useProxy;
 103   
     }
 104   
 
 105   
     /**
 106   
      * name of proxy; optional.
 107   
      */
 108  0
     public void setProxy(String proxy){
 109  0
         this.proxy = proxy;
 110   
     }
 111   
     
 112   
     /**
 113   
      * Proxy port; optional, default 80. 
 114   
      */
 115  0
     public void setPort(String port){
 116  0
         this.port = port;
 117   
     }
 118   
 
 119   
     /**
 120   
      * Proxy user; optional, default =none. 
 121   
      */
 122  0
     public void setUser(String user){
 123  0
         this.user = user;
 124   
     }
 125   
     
 126   
     /**
 127   
      * Proxy password; required if <tt>user</tt> is set.
 128   
      */
 129  0
      public void setPassword(String password){
 130  0
         this.password = password;
 131   
     }
 132   
     
 133   
     /**
 134   
      * how long to show the splash screen in milliseconds,
 135   
      * optional; default 5000 ms.
 136   
      */
 137  0
     public void setShowduration(int duration) {
 138  0
         this.showDuration = duration;
 139   
     }
 140   
    
 141   
 
 142  0
     public void execute() throws BuildException {
 143  0
         if (splash != null) {
 144  0
             splash.setVisible(false);
 145  0
             getProject().removeBuildListener(splash);
 146  0
             splash.dispose();
 147  0
             splash = null;
 148   
         }
 149   
       
 150  0
         log("Creating new SplashScreen", Project.MSG_VERBOSE);
 151  0
         InputStream in = null;
 152   
 
 153  0
         if (imgurl != null) {
 154  0
             try {
 155  0
                 URLConnection conn = null;
 156   
                 
 157  0
                 if (useProxy &&
 158   
                    (proxy != null && proxy.length() > 0) &&
 159   
                    (port != null && port.length() > 0)) {
 160   
                     
 161  0
                     log("Using proxied Connection",  Project.MSG_DEBUG);
 162  0
                     System.getProperties().put("http.proxySet", "true");
 163  0
                     System.getProperties().put("http.proxyHost", proxy);
 164  0
                     System.getProperties().put("http.proxyPort", port);
 165   
                     
 166  0
                     URL url = new URL(imgurl);
 167   
                     
 168  0
                     conn = url.openConnection();
 169  0
                     if (user != null && user.length() > 0) {
 170  0
                         String encodedcreds = 
 171   
                             new sun.misc.BASE64Encoder().encode((new String(user + ":" + password)).getBytes());
 172  0
                         conn.setRequestProperty("Proxy-Authorization", 
 173   
                                                 encodedcreds);
 174   
                     }
 175   
                     
 176   
                 } else {
 177  0
                     System.getProperties().put("http.proxySet", "false");
 178  0
                     System.getProperties().put("http.proxyHost", "");
 179  0
                     System.getProperties().put("http.proxyPort", "");
 180  0
                     log("Using Direction HTTP Connection", Project.MSG_DEBUG);
 181  0
                     URL url = new URL(imgurl);
 182  0
                     conn = url.openConnection();
 183   
                 }
 184  0
                 conn.setDoInput(true);
 185  0
                 conn.setDoOutput(false);
 186   
                 
 187  0
                 in = conn.getInputStream();
 188   
 
 189   
                 // Catch everything - some of the above return nulls, throw exceptions or generally misbehave
 190   
                 // in the event of a problem etc
 191   
                 
 192   
             } catch (Throwable ioe) {
 193  0
                 log("Unable to download image, trying default Ant Logo", 
 194   
                     Project.MSG_DEBUG);
 195  0
                 log("(Exception was \"" + ioe.getMessage() + "\"", 
 196   
                     Project.MSG_DEBUG);
 197   
             }
 198   
         }
 199   
 
 200  0
         if (in == null) {
 201  0
             in = SplashTask.class.getClassLoader().getResourceAsStream("images/ant_logo_large.gif");
 202   
         }
 203   
 
 204  0
         if (in != null) {
 205  0
             DataInputStream din = new DataInputStream(in);
 206  0
             boolean success = false;
 207  0
             try {
 208  0
                 ByteArrayOutputStream bout = new ByteArrayOutputStream();
 209  0
                 int data;
 210  0
                 while ((data = din.read()) != -1) {
 211  0
                     bout.write((byte) data);
 212   
                 }
 213   
                 
 214  0
                 log("Got ByteArray, creating splash",  Project.MSG_DEBUG);
 215  0
                 ImageIcon img = new ImageIcon(bout.toByteArray());
 216   
                 
 217  0
                 splash = new SplashScreen(img);
 218  0
                 success = true;
 219   
             } catch (Exception e) {
 220  0
                 throw new BuildException(e);
 221   
             } finally {
 222  0
                 try {
 223  0
                     din.close();
 224   
                 } catch (IOException ioe) {
 225   
                     // swallow if there was an error before so that
 226   
                     // original error will be passed up
 227  0
                     if (success) {
 228  0
                         throw new BuildException(ioe);
 229   
                     }
 230   
                 }
 231   
             }
 232   
         } else {
 233  0
             splash = new SplashScreen("Image Unavailable.");
 234   
         }
 235   
 
 236  0
         splash.setVisible(true);
 237  0
         splash.toFront();
 238  0
         getProject().addBuildListener(splash);
 239  0
         try {
 240  0
             Thread.currentThread().sleep(showDuration);
 241   
         } catch (InterruptedException e) {
 242   
         }
 243   
         
 244   
     }
 245   
 }
 246