Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 261   Methods: 10
NCLOC: 94   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
WsdlToDotnet.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2002-2003 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   
 package org.apache.tools.ant.taskdefs.optional.dotnet;
 55   
 
 56   
 import java.io.File;
 57   
 import org.apache.tools.ant.BuildException;
 58   
 import org.apache.tools.ant.Task;
 59   
 
 60   
 /**
 61   
  * Converts a WSDL file or URL resource into a .NET language.
 62   
  *
 63   
  * See "Creating an XML Web Service Proxy", "wsdl.exe" docs in
 64   
  * the framework SDK documentation
 65   
  * @author      Steve Loughran steve_l@iseran.com
 66   
  * @version     0.5
 67   
  * @ant.task    name="wsdltodotnet" category="dotnet"
 68   
  * @since       Ant 1.5
 69   
  */
 70   
 
 71   
 public class WsdlToDotnet extends Task  {
 72   
 
 73   
     /**
 74   
      * name of output file (required)
 75   
      */
 76   
     private File destFile = null;
 77   
 
 78   
     /**
 79   
      * url to retrieve
 80   
      */
 81   
     private String url = null;
 82   
 
 83   
     /**
 84   
      * name of source file
 85   
      */
 86   
     private File srcFile = null;
 87   
 
 88   
     /**
 89   
      * language; defaults to C#
 90   
      */
 91   
     private String language = "CS";
 92   
 
 93   
     /**
 94   
      * flag set to true to generate server side skeleton
 95   
      */
 96   
     private boolean server = false;
 97   
 
 98   
     /**
 99   
      * namespace
 100   
      */
 101   
     private String namespace = null;
 102   
 
 103   
     /**
 104   
      *  flag to control action on execution trouble
 105   
      */
 106   
     private boolean failOnError = true;
 107   
 
 108   
     /**
 109   
      *  any extra command options?
 110   
      */
 111   
     protected String extraOptions = null;
 112   
 
 113   
     /**
 114   
      * Name of the file to generate. Required
 115   
      * @param destFile filename
 116   
      */
 117  0
     public void setDestFile(File destFile) {
 118  0
         this.destFile = destFile;
 119   
     }
 120   
 
 121   
     /**
 122   
      * Sets the URL to fetch. Fetching is by wsdl.exe; Ant proxy settings
 123   
      * are ignored; either url or srcFile is required.
 124   
      * @param url url to save
 125   
      */
 126   
 
 127  0
     public void setUrl(String url) {
 128  0
         this.url = url;
 129   
     }
 130   
 
 131   
     /**
 132   
      * The local WSDL file to parse; either url or srcFile is required.
 133   
      * @param srcFile name of WSDL file
 134   
      */
 135  0
     public void setSrcFile(File srcFile) {
 136  0
         this.srcFile = srcFile;
 137   
     }
 138   
 
 139   
     /**
 140   
      * set the language; one of "CS", "JS", or "VB"
 141   
      * optional, default is CS for C# source
 142   
      * @param language language to generate
 143   
      */
 144  0
     public void setLanguage(String language) {
 145  0
         this.language = language;
 146   
     }
 147   
 
 148   
     /**
 149   
      * flag to enable server side code generation;
 150   
      * optional, default=false
 151   
      * @param server server-side flag
 152   
      */
 153   
 
 154  0
     public void setServer(boolean server) {
 155  0
         this.server = server;
 156   
     }
 157   
 
 158   
     /**
 159   
      * namespace to place  the source in.
 160   
      * optional; default ""
 161   
      * @param namespace new namespace
 162   
      */
 163  0
     public void setNamespace(String namespace) {
 164  0
         this.namespace = namespace;
 165   
     }
 166   
 
 167   
     /**
 168   
      * Whether or not a failure should halt the build.
 169   
      * Optional - default is <code>true</code>.
 170   
      * @param failOnError new failure option
 171   
      */
 172  0
     public void setFailOnError(boolean failOnError) {
 173  0
         this.failOnError = failOnError;
 174   
     }
 175   
 
 176   
     /**
 177   
      *  Any extra WSDL.EXE options which aren't explicitly
 178   
      *  supported by the ant wrapper task; optional
 179   
      *
 180   
      *@param  extraOptions  The new ExtraOptions value
 181   
      */
 182  0
     public void setExtraOptions(String extraOptions) {
 183  0
         this.extraOptions = extraOptions;
 184   
     }
 185   
 
 186   
     /**
 187   
      * validation code
 188   
      * @throws  BuildException  if validation failed
 189   
      */
 190  0
     protected void validate()
 191   
             throws BuildException {
 192  0
         if (destFile == null) {
 193  0
             throw new BuildException("destination file must be specified");
 194   
         }
 195  0
         if (destFile.isDirectory()) {
 196  0
             throw new BuildException(
 197   
                 "destination file is a directory");
 198   
         }
 199  0
         if (url != null && srcFile != null) {
 200  0
             throw new BuildException(
 201   
                     "you can not specify both a source file and a URL");
 202   
         }
 203  0
         if (url == null && srcFile == null) {
 204  0
             throw new BuildException(
 205   
                     "you must specify either a source file or a URL");
 206   
         }
 207  0
         if (srcFile != null) {
 208  0
             if (!srcFile.exists()) {
 209  0
                 throw new BuildException(
 210   
                     "source file does not exist");
 211   
             }
 212  0
             if (srcFile.isDirectory()) {
 213  0
                 throw new BuildException(
 214   
                     "source file is a directory");
 215   
             }
 216   
         }
 217   
 
 218   
     }
 219   
 
 220   
     /**
 221   
      *  do the work by building the command line and then calling it
 222   
      *
 223   
      *@throws  BuildException  if validation or execution failed
 224   
      */
 225  0
     public void execute()
 226   
              throws BuildException {
 227  0
         validate();
 228  0
         NetCommand command = new NetCommand(this, "WSDL", "wsdl");
 229  0
         command.setFailOnError(failOnError);
 230   
         //fill in args
 231  0
         command.addArgument("/nologo");
 232  0
         command.addArgument("/out:" + destFile);
 233  0
         command.addArgument("/language:", language);
 234  0
         if (server) {
 235  0
             command.addArgument("/server");
 236   
         }
 237  0
         command.addArgument("/namespace:", namespace);
 238  0
         command.addArgument(extraOptions);
 239   
 
 240   
         //set source and rebuild options
 241  0
         boolean rebuild = true;
 242  0
         if(srcFile!=null) {
 243  0
             command.addArgument(srcFile.toString());
 244   
             //rebuild unless the dest file is newer than the source file
 245  0
             if (srcFile.exists() && destFile.exists() &&
 246   
                 srcFile.lastModified() <= destFile.lastModified()) {
 247  0
                 rebuild = false;
 248   
             }
 249   
         } else {
 250   
             //no source file? must be a url, which has no dependency
 251   
             //handling
 252  0
             rebuild=true;
 253  0
             command.addArgument(url);
 254   
         }
 255  0
         if (rebuild) {
 256  0
             command.runCommand();
 257   
         }
 258   
     }
 259   
 }
 260   
 
 261