Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 184   Methods: 3
NCLOC: 52   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ImportTask.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   
 
 55   
 package org.apache.tools.ant.taskdefs;
 56   
 
 57   
 import org.apache.tools.ant.*;
 58   
 import org.apache.tools.ant.helper.ProjectHelper2;
 59   
 
 60   
 import java.io.File;
 61   
 import java.io.IOException;
 62   
 import java.util.Vector;
 63   
 
 64   
 /**
 65   
  * <i>EXPERIMENTAL:</i> This task is experimental and may be under continual
 66   
  * change till Ant1.6 ships; it may even be omitted from the product.
 67   
  * <p>
 68   
  * Task to import another build file into the current project.
 69   
  * <p>
 70   
  * It must be 'top level'. On execution it'll read another file
 71   
  * into the same Project.
 72   
  * <p>
 73   
  * <b>Important</b>: there is one limitation related to the top level
 74   
  * elements in the imported files. The current implementation will
 75   
  * add them at the end of the top-level ( instead of replacing the
 76   
  * import element - which would be more intuitive ).
 77   
  * <p>
 78   
  * <b>Important</b>: we have not finalized how relative file references
 79   
  * will be resolved in deep/complex build hierarchies -such as what happens
 80   
  * when an imported file imports another file. Use absolute references for
 81   
  * enhanced build file stability. 
 82   
  *
 83   
  * @author Nicola Ken Barozzi nicolaken@apache.org
 84   
  * @author Dominique Devienne DDevienne@lgc.com
 85   
  * @author Costin Manolache
 86   
  */
 87   
 public class ImportTask extends Task {
 88   
     String file;
 89   
 
 90   
     /**
 91   
      * the name of the file to import. How relative paths are resolved is still
 92   
      * in flux: use absolute paths for safety.
 93   
      * @param file
 94   
      */
 95  0
     public void setFile( String file ) {
 96   
         // I don't think we can use File - different rules
 97   
         // for relative paths.
 98  0
         this.file=file;
 99   
     }
 100   
     
 101   
     /**
 102   
      *  This relies on the task order model.
 103   
      *
 104   
      */
 105  0
     public void execute() throws BuildException
 106   
     {
 107  0
         if (file == null) {
 108  0
             throw new BuildException("import requires file attribute");
 109   
         }
 110   
 
 111  0
         ProjectHelper helper=
 112   
                 (ProjectHelper)getProject().getReference("ant.projectHelper");
 113  0
         Vector importStack=helper.getImportStack();
 114  0
         if( importStack.size() == 0) {
 115   
             // this happens if ant is used with a project
 116   
             // helper that doesn't set the import.
 117  0
             throw new BuildException("import requires support in ProjectHelper");
 118   
         }
 119  0
         Object currentSource=importStack.elementAt(importStack.size() - 1);
 120   
 
 121   
 //        ProjectHelper2.AntXmlContext context;
 122   
 //        context=(ProjectHelper2.AntXmlContext)project.getReference("ant.parsing.context");
 123   
 
 124   
 //        File buildFile=context.buildFile;
 125   
 //        File buildFileParent=context.buildFileParent;
 126  0
         File buildFile=(File)currentSource;
 127  0
         buildFile=new File( buildFile.getAbsolutePath());
 128   
         //System.out.println("Importing from " + currentSource);
 129  0
         File buildFileParent=new File(buildFile.getParent());
 130   
 
 131  0
         getProject().log("Importing file "+ file +" from "+
 132   
                     buildFile.getAbsolutePath(), Project.MSG_VERBOSE);
 133   
 
 134   
         // Paths are relative to the build file they're imported from,
 135   
         // *not* the current directory (same as entity includes).
 136  0
         File importedFile = new File(file);
 137  0
         if (!importedFile.isAbsolute()) {
 138  0
             importedFile = new File( buildFileParent, file);
 139   
         }
 140   
 
 141  0
         if (!importedFile.exists()) {
 142  0
                 throw new BuildException("Cannot find "+file+" imported from "+
 143   
                                          buildFile.getAbsolutePath());
 144   
         }
 145   
 
 146  0
         if( importStack.contains(importedFile) ) {
 147  0
             getProject().log("\nSkipped already imported file to avoid loop:\n   "+
 148   
                     importedFile + "\n",Project.MSG_WARN);
 149  0
             return;
 150   
         }
 151   
 
 152   
 //        // Add parent build file to the map to avoid cycles...
 153   
 //        String parentFilename = getPath(buildFile);
 154   
 //        if (!context.importedFiles.containsKey(parentFilename)) {
 155   
 //            context.importedFiles.put(parentFilename, buildFile);
 156   
 //        }
 157   
 //
 158   
 //        // Make sure we import the file only once
 159   
 //        String importedFilename = getPath(importedFile);
 160   
 //        if (context.importedFiles.containsKey(importedFilename)) {
 161   
 //            project.log("\nSkipped already imported file:\n   "+
 162   
 //                    importedFilename+"\n",Project.MSG_WARN);
 163   
 //            return;
 164   
 //        } else {
 165   
 //            context.importedFiles.put(importedFilename, importedFile);
 166   
 //        }
 167   
 
 168   
 //        context.ignoreProjectTag=true;
 169   
 //        context.helper.parse(project, importedFile,
 170   
 //                new ProjectHelper2.RootHandler(context));
 171   
 
 172  0
         helper.parse( getProject(), importedFile );
 173   
     }
 174   
 
 175  0
     private static String getPath(File file) {
 176  0
         try {
 177  0
             return file.getCanonicalPath();
 178   
         }
 179   
         catch (IOException e) {
 180  0
             return file.getAbsolutePath();
 181   
         }
 182   
     }
 183   
 }
 184