Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 227   Methods: 5
NCLOC: 102   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
VAJWorkspaceScanner.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2001-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   
 package org.apache.tools.ant.taskdefs.optional.ide;
 55   
 
 56   
 import com.ibm.ivj.util.base.IvjException;
 57   
 import com.ibm.ivj.util.base.Package;
 58   
 import com.ibm.ivj.util.base.Project;
 59   
 import java.io.File;
 60   
 import java.util.Enumeration;
 61   
 import java.util.StringTokenizer;
 62   
 import java.util.Vector;
 63   
 import org.apache.tools.ant.DirectoryScanner;
 64   
 
 65   
 /**
 66   
  * Class for scanning a Visual Age for Java workspace for packages matching
 67   
  * a certain criteria.
 68   
  * <p>
 69   
  * These criteria consist of a set of include and exclude patterns. With these
 70   
  * patterns, you can select which packages you want to have included, and which
 71   
  * packages you want to have excluded.  You can add patterns to be excluded by
 72   
  * default with the addDefaultExcludes method.  The patters that are excluded
 73   
  * by default include
 74   
  * <ul>
 75   
  *   <li>IBM*\**</li>
 76   
  *   <li>Java class libraries\**</li>
 77   
  *   <li>Sun class libraries*\**</li>
 78   
  *   <li>JSP Page Compile Generated Code\**</li>
 79   
  *   <li>VisualAge*\**</li>
 80   
  * </ul>
 81   
  * <p>
 82   
  * This class works like DirectoryScanner.
 83   
  *
 84   
  * @see org.apache.tools.ant.DirectoryScanner
 85   
  *
 86   
  * @author Wolf Siberski, TUI Infotec (based on Arnout J. Kuipers DirectoryScanner)
 87   
  */
 88   
 class VAJWorkspaceScanner extends DirectoryScanner {
 89   
 
 90   
     // Patterns that should be excluded by default.
 91   
     private static final String[] DEFAULTEXCLUDES =
 92   
     {
 93   
         "IBM*/**",
 94   
         "Java class libraries/**",
 95   
         "Sun class libraries*/**",
 96   
         "JSP Page Compile Generated Code/**",
 97   
         "VisualAge*/**",
 98   
     };
 99   
 
 100   
     // The packages that where found and matched at least
 101   
     // one includes, and matched no excludes.
 102   
     private Vector packagesIncluded = new Vector();
 103   
 
 104   
     /**
 105   
      * Adds the array with default exclusions to the current exclusions set.
 106   
      */
 107  0
     public void addDefaultExcludes() {
 108  0
         int excludesLength = excludes == null ? 0 : excludes.length;
 109  0
         String[] newExcludes;
 110  0
         newExcludes = new String[excludesLength + DEFAULTEXCLUDES.length];
 111  0
         if (excludesLength > 0) {
 112  0
             System.arraycopy(excludes, 0, newExcludes, 0, excludesLength);
 113   
         }
 114  0
         for (int i = 0; i < DEFAULTEXCLUDES.length; i++) {
 115  0
             newExcludes[i + excludesLength] = DEFAULTEXCLUDES[i].
 116   
                 replace('/', File.separatorChar).
 117   
                 replace('\\', File.separatorChar);
 118   
         }
 119  0
         excludes = newExcludes;
 120   
     }
 121   
 
 122   
     /**
 123   
      * Finds all Projects specified in include patterns.
 124   
      *
 125   
      * @return the projects
 126   
      */
 127  0
     public Vector findMatchingProjects() {
 128  0
         Project[] projects = VAJLocalUtil.getWorkspace().getProjects();
 129   
 
 130  0
         Vector matchingProjects = new Vector();
 131   
 
 132  0
         boolean allProjectsMatch = false;
 133  0
         for (int i = 0; i < projects.length; i++) {
 134  0
             Project project = projects[i];
 135  0
             for (int j = 0; j < includes.length && !allProjectsMatch; j++) {
 136  0
                 StringTokenizer tok =
 137   
                     new StringTokenizer(includes[j], File.separator);
 138  0
                 String projectNamePattern = tok.nextToken();
 139  0
                 if (projectNamePattern.equals("**")) {
 140   
                     // if an include pattern starts with '**',
 141   
                     // all projects match
 142  0
                     allProjectsMatch = true;
 143   
                 } else
 144  0
                     if (match(projectNamePattern, project.getName())) {
 145  0
                         matchingProjects.addElement(project);
 146  0
                         break;
 147   
                     }
 148   
             }
 149   
         }
 150   
 
 151  0
         if (allProjectsMatch) {
 152  0
             matchingProjects = new Vector();
 153  0
             for (int i = 0; i < projects.length; i++) {
 154  0
                 matchingProjects.addElement(projects[i]);
 155   
             }
 156   
         }
 157   
 
 158  0
         return matchingProjects;
 159   
     }
 160   
 
 161   
     /**
 162   
      * Get the names of the packages that matched at least one of the include
 163   
      * patterns, and didn't match one of the exclude patterns.
 164   
      *
 165   
      * @return the matching packages
 166   
      */
 167  0
     public Package[] getIncludedPackages() {
 168  0
         int count = packagesIncluded.size();
 169  0
         Package[] packages = new Package[count];
 170  0
         for (int i = 0; i < count; i++) {
 171  0
             packages[i] = (Package) packagesIncluded.elementAt(i);
 172   
         }
 173  0
         return packages;
 174   
     }
 175   
 
 176   
     /**
 177   
      * Scans the workspace for packages that match at least one include
 178   
      * pattern, and don't match any exclude patterns.
 179   
      *
 180   
      */
 181  0
     public void scan() {
 182  0
         if (includes == null) {
 183   
             // No includes supplied, so set it to 'matches all'
 184  0
             includes = new String[1];
 185  0
             includes[0] = "**";
 186   
         }
 187  0
         if (excludes == null) {
 188  0
             excludes = new String[0];
 189   
         }
 190   
 
 191   
         // only scan projects which are included in at least one include pattern
 192  0
         Vector matchingProjects = findMatchingProjects();
 193  0
         for (Enumeration e = matchingProjects.elements(); e.hasMoreElements();) {
 194  0
             Project project = (Project) e.nextElement();
 195  0
             scanProject(project);
 196   
         }
 197   
     }
 198   
 
 199   
     /**
 200   
      * Scans a project for packages that match at least one include
 201   
      * pattern, and don't match any exclude patterns.
 202   
      *
 203   
      */
 204  0
     public void scanProject(Project project) {
 205  0
         try {
 206  0
             Package[] packages = project.getPackages();
 207  0
             if (packages != null) {
 208  0
                 for (int i = 0; i < packages.length; i++) {
 209  0
                     Package item = packages[i];
 210   
                     // replace '.' by file seperator because the patterns are
 211   
                     // using file seperator syntax (and we can use the match
 212   
                     // methods this way).
 213  0
                     String name =
 214   
                         project.getName()
 215   
                         + File.separator
 216   
                         + item.getName().replace('.', File.separatorChar);
 217  0
                     if (isIncluded(name) && !isExcluded(name)) {
 218  0
                         packagesIncluded.addElement(item);
 219   
                     }
 220   
                 }
 221   
             }
 222   
         } catch (IvjException e) {
 223  0
             throw VAJLocalUtil.createBuildException("VA Exception occured: ", e);
 224   
         }
 225   
     }
 226   
 }
 227