Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 101   Methods: 5
NCLOC: 72   Classes: 1
This license of Clover is provided to support the development of JBind only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
ExecuteTask.java 0% 0% 0% 0%
 1   
 /*
 2   
  * JBind
 3   
  *
 4   
  * Copyright (c) by Stefan Wachter. All rights reserved.
 5   
  *
 6   
  * Usage, modification, and redistribution is subject to license terms that are
 7   
  * available at 'http://www.jbind.org'. The JBind license is like the
 8   
  * 'Apache Software License V 1.1'.
 9   
  */
 10   
 package org.jbind.xml.ant;
 11   
 
 12   
 import java.io.File;
 13   
 import java.net.URL;
 14   
 import java.util.ArrayList;
 15   
 import java.util.Iterator;
 16   
 
 17   
 import org.apache.tools.ant.BuildException;
 18   
 import org.apache.tools.ant.DirectoryScanner;
 19   
 import org.apache.tools.ant.Task;
 20   
 import org.apache.tools.ant.types.FileSet;
 21   
 import org.jbind.xml.code.IApplicationCode;
 22   
 import org.jbind.xml.facade.JBindFacade;
 23   
 
 24   
 public class ExecuteTask extends Task {
 25   
 
 26   
   private File myFile = null;
 27   
   private String myUrl = null;
 28   
   private ArrayList myFileSets = new ArrayList();
 29   
 
 30  0
   public ExecuteTask() {}
 31   
 
 32  0
   public void setFile(File aFile) {
 33  0
     myFile = aFile;
 34   
   }
 35  0
   public void setUrl(String aUrl) {
 36  0
     myUrl = aUrl;
 37   
   }
 38   
 
 39  0
   public void addFileset(FileSet aFileSet) {
 40  0
     myFileSets.add(aFileSet);
 41   
   }
 42   
 
 43  0
   public void execute() throws BuildException {
 44  0
     ArrayList failed = new ArrayList();
 45   
 
 46  0
     ClassLoader saveClassLoader = Thread.currentThread().getContextClassLoader();
 47   
 
 48  0
     try {
 49   
 
 50  0
       Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
 51   
 
 52   
       // collect the URLs
 53   
 
 54  0
       ArrayList urls = new ArrayList();
 55  0
       if (null != myFile) {
 56  0
         urls.add(myFile.toURL());
 57   
       }
 58  0
       if (null != myUrl) {
 59  0
         urls.add(new URL(myUrl));
 60   
       }
 61   
 
 62  0
       for (Iterator i = myFileSets.iterator(); i.hasNext(); ) {
 63  0
         FileSet fs = (FileSet)i.next();
 64  0
         DirectoryScanner ds = fs.getDirectoryScanner(project);
 65  0
         File baseDir = ds.getBasedir();
 66  0
         String[] files = ds.getIncludedFiles();
 67  0
         for (int idx = 0; idx < files.length; idx++) {
 68  0
           File f = new File(baseDir, files[idx]);
 69  0
           urls.add(f.toURL());
 70   
         }
 71   
       }
 72   
 
 73  0
       for (int i = 0; i < urls.size(); i++) {
 74  0
         URL url = (URL)urls.get(i);
 75  0
         IApplicationCode ac = JBindFacade.createApplicationCode(url, null);
 76  0
         int errorCode = ac.execute();
 77  0
         if (errorCode != 0) {
 78  0
           failed.add(url);
 79   
         }
 80   
       }
 81   
 
 82   
     } catch (Exception e) {
 83  0
       throw new BuildException(e, location);
 84   
     } finally {
 85  0
       Thread.currentThread().setContextClassLoader(saveClassLoader);
 86   
     }
 87   
 
 88  0
     if (failed.size() > 0) {
 89  0
       StringBuffer sb = new StringBuffer("the followiwng applications failed to execute:\n");
 90  0
       for (Iterator i = failed.iterator(); i.hasNext(); ) {
 91  0
         sb.append(i.next());
 92  0
         if (i.hasNext()) {
 93  0
           sb.append("\n");
 94   
         }
 95   
       }
 96  0
       throw new BuildException(sb.toString());
 97   
     }
 98   
   }
 99   
 
 100   
 }
 101