1 19 20 package org.netbeans.nbbuild; 21 22 import java.io.File ; 23 import java.util.*; 24 25 import org.apache.tools.ant.BuildException; 26 import org.apache.tools.ant.Project; 27 import org.apache.tools.ant.Task; 28 import org.apache.tools.ant.taskdefs.Copy; 29 import org.apache.tools.ant.types.FileSet; 30 31 38 public class SimpleMerge extends Task { 39 40 private File dest; 41 private List<String > modules = new ArrayList<String >(); 42 private List<File > topdirs = new ArrayList<File >(); 43 private List<String > subdirs = new ArrayList<String >(); 44 45 46 public void setDest (File f) { 47 dest = f; 48 } 49 50 51 public void setModules (String s) { 52 StringTokenizer tok = new StringTokenizer (s, ", "); 53 modules = new ArrayList<String >(); 54 while (tok.hasMoreTokens ()) 55 modules.add(tok.nextToken ()); 56 } 57 58 61 public void setTopdir (File t) { 62 topdirs.add (t); 63 } 64 65 66 public class Topdir { 67 68 public void setPath (File t) { 69 topdirs.add (t); 70 } 71 } 72 78 public Topdir createTopdir () { 79 return new Topdir (); 80 } 81 82 85 public void setSubdir (String t) { 86 subdirs.add (t); 87 } 88 89 90 public class Subdir { 91 92 public void setPath (String t) { 93 subdirs.add (t); 94 } 95 } 96 102 public Subdir createSubdir () { 103 return new Subdir (); 104 } 105 106 public void execute () throws BuildException { 107 if (topdirs.isEmpty ()) { 108 throw new BuildException("You must set at least one topdir attribute", getLocation()); 109 } 110 111 if (subdirs.isEmpty ()) { 112 throw new BuildException("You must set at least one subdir attribute", getLocation()); 113 } 114 115 log ( "Starting merge to " + dest.getAbsolutePath() ); 116 for (File topdir : topdirs) { 117 for (String module : modules) { 118 for (String sdir : subdirs) { 119 File subdir = new File (new File (topdir, module), sdir); 120 if (!subdir.exists()) { 121 log("Dir " + subdir + " does not exist, skipping...", Project.MSG_WARN); 122 continue; 123 } 124 Copy copy = (Copy) getProject().createTask("copy"); 125 FileSet fs = new FileSet(); 126 fs.setDir(subdir); 127 copy.addFileset(fs); 128 copy.setTodir(dest); 129 copy.setIncludeEmptyDirs(true); 130 copy.init(); 131 copy.setLocation(getLocation()); 132 copy.execute(); 133 } 134 } 135 } 136 log ( "Merge finished" ); 137 } 138 } 139 | Popular Tags |