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.Iterator ; 27 28 31 public class ModuleInfo extends Task { 32 private String property; 33 private String fileset; 34 private String moduleName; 35 private String clusterdir; 36 private File trackingPath; 37 private boolean failOnError; 38 39 public void setModule (String moduleName){ 40 this.moduleName = moduleName; 41 } 42 43 public void setPatternSetName( String name ) { 44 property = name; 45 } 46 47 public void setFileSetName (String name) { 48 fileset = name; 49 } 50 51 public void setClusterDirName (String name) { 52 clusterdir = name; 53 } 54 55 public void setTrackingPath( File path ) { 56 trackingPath = path; 57 } 58 59 public void setFailOnError (boolean b) { 60 failOnError = b; 61 } 62 63 64 public void execute() throws BuildException { 65 if (moduleName == null) { 66 throw new BuildException("Module property must be set", getLocation()); 67 } 68 if (property == null && fileset == null) { 69 throw new BuildException("Name of the patternset or fileset must be set.", getLocation()); 70 } 71 if (trackingPath == null) { 72 throw new BuildException("Path to module_tracking.xml file must be set.", getLocation()); 73 } 74 75 String c = this.getProject ().getProperty (moduleName + ".dir"); 76 if (c == null) { 77 throw new BuildException ("No property " + moduleName + ".dir is defined"); 78 } 79 File cluster = new File (c); 80 log ("Cluster dir for " + moduleName + " is " + cluster, Project.MSG_VERBOSE); 81 82 if (this.clusterdir != null) { 83 this.getProject ().setProperty (this.clusterdir, cluster.getPath ()); 84 } 85 86 PatternSet pattern = (PatternSet) this.getProject().createDataType("patternset"); 87 88 ModuleTracking tracking = new ModuleTracking(trackingPath.getAbsolutePath()); 89 Iterator files = tracking.getFilesForModule(moduleName); 90 if (files==null) { 91 String msg = moduleName + " module doesn't have module tracking info in " + trackingPath; 92 if (failOnError) { 93 throw new BuildException (msg); 94 } else { 95 log (msg, Project.MSG_ERR); 96 files = java.util.Collections.EMPTY_LIST.iterator (); 97 } 98 } 99 100 while (files.hasNext()) { 101 String f = (String )files.next (); 102 log ("Adding include " + f, Project.MSG_VERBOSE); 103 pattern.createInclude().setName(f); 104 } 105 106 if (property != null) { 107 log ("Setting refid " + property); 108 this.getProject().addReference(property, pattern); 109 } 110 111 if (fileset != null) { 112 FileSet fs = (FileSet) this.getProject().createDataType("fileset"); 113 fs.setDir (cluster); 114 fs.createPatternSet ().append (pattern, getProject ()); 115 log ("Setting refid " + fileset); 116 this.getProject().addReference(fileset, fs); 117 } 118 } 119 } 120 | Popular Tags |