1 19 20 package org.netbeans.nbbuild; 21 22 import org.apache.tools.ant.*; 23 import org.apache.tools.ant.types.*; 24 import java.util.StringTokenizer ; 25 import java.io.File ; 26 import java.util.ArrayList ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 import java.util.Map ; 31 32 35 public class CheckClustersContent extends Task { 36 private String clustersName = null; 37 private File trackingPath = null; 38 private File kitDir = null; 39 private List <Exclude> excludes = new ArrayList <Exclude>(); 40 41 42 public void setClusters( String clusters ) { 43 this.clustersName = clusters; 44 } 45 46 public void setTrackingPath( File path ) { 47 this.trackingPath = path; 48 } 49 50 public void setKitDestDir( File kitDir ) { 51 this.kitDir = kitDir; 52 } 53 54 public Exclude createExclude() { 55 Exclude ex = new Exclude(); 56 excludes.add(ex); 57 return ex; 58 } 59 60 public void execute() throws BuildException { 61 if (clustersName == null) { 62 throw new BuildException("Cluster property must be set", getLocation()); 63 } 64 if (trackingPath == null) { 65 throw new BuildException("Path to module_tracking.xml file must be set.", getLocation()); 66 } 67 Map <String ,String > listOfFiles = new HashMap <String ,String >(); 68 69 StringTokenizer clusterTokens = new StringTokenizer (clustersName, " \t\n\f\r,"); 70 boolean error = false; 71 String message = ""; 72 while (clusterTokens.hasMoreTokens()) { 73 String clusterName = clusterTokens.nextToken(); 74 String clusterList = this.getProject().getProperty(clusterName); 75 if (clusterList == null) { 76 throw new BuildException("Cluster " + clusterName + " doesn't exist", getLocation()); 77 } 78 ModuleTracking tracking = new ModuleTracking(trackingPath.getAbsolutePath()); 79 StringTokenizer moduleTokens = new StringTokenizer (clusterList, " \t\n\f\r,"); 80 while (moduleTokens.hasMoreTokens()) { 81 String module = moduleTokens.nextToken(); 82 String path = tracking.getModulePath(module); 83 Iterator files = tracking.getFilesForModule(module); 84 if (files==null) { 85 log("This module doesn't have module tracking info: " + module, Project.MSG_INFO); 86 continue; 87 } 88 while (files.hasNext()) { 89 String file = path.replace(File.separatorChar, '/') + '/' + ((String )files.next()).replace(File.separatorChar, '/'); if (listOfFiles.containsKey(file)) { 92 error = true; 93 message += "\nThe file: " + file + " from module: " + module + " is also in module: " + listOfFiles.get(file); 94 } 95 listOfFiles.put(file,module); 96 } 97 } 98 } 99 FileSet fileset = new FileSet(); 100 fileset.setDir(kitDir); 101 if (excludes.size() > 0) { 102 Iterator it = excludes.iterator(); 103 while (it.hasNext()) { 104 Exclude ex = (Exclude) it.next(); 105 fileset.createExclude().setName(ex.getName()); 106 } 107 } 108 DirectoryScanner ds = fileset.getDirectoryScanner(this.getProject()); 109 ds.scan(); 110 String included[] = ds.getIncludedFiles(); 111 for (int i = 0; i < included.length; i++) 112 if (!listOfFiles.containsKey(included[i].replace(File.separatorChar, '/'))) { 113 error = true; 114 message += "\nThe file: " + included[i] + " isn't included in any module's NBM"; 115 } 116 if (error) 117 throw new BuildException("Check of content of clusters and NBMs FAILED because of those issues:" + message, getLocation()); 118 } 119 120 public class Exclude { 121 String name = null; 122 public void setName(String name) { 123 this.name = name; 124 } 125 public String getName() { 126 return name; 127 } 128 } 129 } 130 | Popular Tags |