1 17 package org.apache.tools.ant.taskdefs.optional.ide; 18 19 import com.ibm.ivj.util.base.IvjException; 20 import com.ibm.ivj.util.base.Package; 21 import com.ibm.ivj.util.base.Project; 22 import java.io.File ; 23 import java.util.Enumeration ; 24 import java.util.StringTokenizer ; 25 import java.util.Vector ; 26 import org.apache.tools.ant.DirectoryScanner; 27 28 50 class VAJWorkspaceScanner extends DirectoryScanner { 51 52 private static final String [] DEFAULTEXCLUDES = { 54 "IBM*/**", 55 "Java class libraries/**", 56 "Sun class libraries*/**", 57 "JSP Page Compile Generated Code/**", 58 "VisualAge*/**", 59 }; 60 61 private Vector packagesIncluded = new Vector (); 64 65 68 public void addDefaultExcludes() { 69 int excludesLength = excludes == null ? 0 : excludes.length; 70 String [] newExcludes; 71 newExcludes = new String [excludesLength + DEFAULTEXCLUDES.length]; 72 if (excludesLength > 0) { 73 System.arraycopy(excludes, 0, newExcludes, 0, excludesLength); 74 } 75 for (int i = 0; i < DEFAULTEXCLUDES.length; i++) { 76 newExcludes[i + excludesLength] = DEFAULTEXCLUDES[i]. 77 replace('/', File.separatorChar). 78 replace('\\', File.separatorChar); 79 } 80 excludes = newExcludes; 81 } 82 83 88 public Vector findMatchingProjects() { 89 Project[] projects = VAJLocalUtil.getWorkspace().getProjects(); 90 91 Vector matchingProjects = new Vector (); 92 93 boolean allProjectsMatch = false; 94 for (int i = 0; i < projects.length; i++) { 95 Project project = projects[i]; 96 for (int j = 0; j < includes.length && !allProjectsMatch; j++) { 97 StringTokenizer tok = 98 new StringTokenizer (includes[j], File.separator); 99 String projectNamePattern = tok.nextToken(); 100 if (projectNamePattern.equals("**")) { 101 allProjectsMatch = true; 104 } else 105 if (match(projectNamePattern, project.getName())) { 106 matchingProjects.addElement(project); 107 break; 108 } 109 } 110 } 111 112 if (allProjectsMatch) { 113 matchingProjects = new Vector (); 114 for (int i = 0; i < projects.length; i++) { 115 matchingProjects.addElement(projects[i]); 116 } 117 } 118 119 return matchingProjects; 120 } 121 122 128 public Package [] getIncludedPackages() { 129 int count = packagesIncluded.size(); 130 Package [] packages = new Package [count]; 131 for (int i = 0; i < count; i++) { 132 packages[i] = (Package ) packagesIncluded.elementAt(i); 133 } 134 return packages; 135 } 136 137 142 public void scan() { 143 if (includes == null) { 144 includes = new String [1]; 146 includes[0] = "**"; 147 } 148 if (excludes == null) { 149 excludes = new String [0]; 150 } 151 152 Vector matchingProjects = findMatchingProjects(); 154 for (Enumeration e = matchingProjects.elements(); e.hasMoreElements();) { 155 Project project = (Project) e.nextElement(); 156 scanProject(project); 157 } 158 } 159 160 165 public void scanProject(Project project) { 166 try { 167 Package [] packages = project.getPackages(); 168 if (packages != null) { 169 for (int i = 0; i < packages.length; i++) { 170 Package item = packages[i]; 171 String name = 175 project.getName() 176 + File.separator 177 + item.getName().replace('.', File.separatorChar); 178 if (isIncluded(name) && !isExcluded(name)) { 179 packagesIncluded.addElement(item); 180 } 181 } 182 } 183 } catch (IvjException e) { 184 throw VAJLocalUtil.createBuildException("VA Exception occurred: ", e); 185 } 186 } 187 } 188 | Popular Tags |