1 19 20 package org.netbeans.nbbuild; 21 22 import java.io.File ; 23 import java.io.FileWriter ; 24 import java.io.IOException ; 25 import java.util.*; 26 27 import org.apache.tools.ant.FileScanner; 28 import org.apache.tools.ant.BuildException; 29 import org.apache.tools.ant.taskdefs.MatchingTask; 30 import org.apache.tools.ant.taskdefs.UpToDate; 31 32 36 public class MakeLayer extends MatchingTask { 37 38 private File dest = null; 39 private File topdir = null; 40 private boolean absolutePath = false; 41 42 43 public void setDestfile(File f) { 44 dest = f; 45 } 46 47 50 public void setTopdir (File t) { 51 topdir = t; 52 } 53 54 57 public void setAbsolutePath( boolean absolutePath ) { 58 this.absolutePath = absolutePath; 59 } 60 61 62 public void execute() throws BuildException { 63 if (topdir == null) { 64 throw new BuildException("You must set at topdir attribute", getLocation()); 65 } 66 if (dest == null) { 67 throw new BuildException("You must specify output file", getLocation()); 68 } 69 UpToDate upToDate = (UpToDate) this.getProject().createTask( "uptodate" ); fileset.setDir( topdir ); 71 upToDate.addSrcfiles( fileset ); 72 upToDate.setTargetFile( dest ); 73 upToDate.setProperty(dest.getAbsolutePath() + ".property"); upToDate.execute(); 75 if (this.getProject().getProperty(dest.getAbsolutePath() + ".property") != null) return; 77 78 int lengthAdjust = (absolutePath) ? 0 : 1; 79 FileWriter layerFile; 80 try { 81 layerFile = new FileWriter (dest); 82 } 83 catch (IOException e) { 84 throw new BuildException(e, getLocation()); 85 } 86 87 FileScanner scanner = getDirectoryScanner (topdir); 88 for (String file : scanner.getIncludedFiles()) { 89 File aFileName = new File (topdir, file); 90 try { 91 layerFile.write(("<file name=\""+aFileName.getName()+"\"\n").replace(File.separatorChar,'/')); layerFile.write((" url=\""+aFileName.getAbsolutePath().substring(topdir.getAbsolutePath().length()+lengthAdjust)+"\"/>\n").replace(File.separatorChar,'/')); } 94 catch(IOException ex) { 95 throw new BuildException("I/O error while writing layer file "+dest.getAbsolutePath(), ex, getLocation()); 96 } 97 } 98 99 try { 100 layerFile.close(); 101 } 102 catch (IOException e) { 103 throw new BuildException("I/O error when trying to close layer file "+dest.getAbsolutePath(), e, getLocation()); 104 } 105 } 106 } 107 108 109 110 | Popular Tags |