| Home >> All >> com >> thermidor >> build >> [ man Javadoc ] |
Source code: com/thermidor/build/man/DocBook2ManTask.java
1 package com.thermidor.build.man; 2 import com.thermidor.tools.man.D2MParser; 3 import java.io.File; 4 import java.io.FileInputStream; 5 import java.io.FileOutputStream; 6 import java.io.IOException; 7 import java.util.Arrays; 8 import java.util.Iterator; 9 import java.util.LinkedList; 10 import org.apache.tools.ant.BuildException; 11 import org.apache.tools.ant.DirectoryScanner; 12 import org.apache.tools.ant.Project; 13 import org.apache.tools.ant.Task; 14 import org.apache.tools.ant.types.FileSet; 15 public class DocBook2ManTask extends Task { 16 /** 17 * The filesets that are provided to and by the task 18 */ 19 private LinkedList fileSets = new LinkedList(); 20 21 /** 22 * The root output directory that man pages will be emitted to. 23 */ 24 private File output; 25 public void execute() throws BuildException { 26 if (output == null) { 27 throw new BuildException("output attribute is required"); 28 } 29 30 Iterator it = fileSets.iterator(); 31 D2MParser parser = new D2MParser(); 32 33 while (it.hasNext()) { 34 FileSet temp = (FileSet)it.next(); 35 DirectoryScanner ds = temp.getDirectoryScanner(getProject()); 36 String[] included = ds.getIncludedFiles(); 37 for(int cnt = 0; cnt < included.length ; cnt++) { 38 String path = included[cnt]; 39 File tpFile = new File(temp.getDir(getProject()),path); 40 File in = tpFile; 41 FileInputStream fin = null; 42 43 try { 44 fin = new FileInputStream(in); 45 46 } catch (IOException ioe) { 47 log("could not read file [" + ioe.getMessage() + 48 "]" + in, Project.MSG_ERR); 49 throw new BuildException("could not read file " + in); 50 } 51 try { 52 parser.parse(fin,output); 53 54 } catch (Throwable se ) { 55 se.printStackTrace(); 56 log("Parser error:: " + se.getMessage() + 57 " [" + in + "]", Project.MSG_ERR); 58 throw new BuildException("Parser error:: " + 59 se.getMessage() + " [" + in + "]"); 60 } 61 } 62 } 63 } 64 65 /** 66 * Ant task attribute setter for the output directory. 67 * @param out the base directory for output. 68 */ 69 public void setOutput(File out) { 70 output = out; 71 } 72 /** 73 * Ant task operation to allow filesets to be added to the task. 74 * @param fileset a FileSet that identifies the files that are to be 75 * compiled 76 */ 77 public void addFileset(FileSet fileset) { 78 fileSets.add(fileset); 79 } 80 }