Hi all,
I developed a simple task that can be used to process a fileset of TeX files. If you think that task is useful to others too, then you may include it in the Ant distribution. You may choose to change the package where I decided to place the task.
Cheers, --Stefan
<target name="pdf" depends="compile, context">
<tex dir="${stammPdfBuildDir}" includes="**/*.tex" verbose="false" mode="context"/>
</target>
package de.vdp.ant;
import java.io.ByteArrayOutputStream; import java.io.File; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.Execute; import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; import org.apache.tools.ant.taskdefs.LogStreamHandler; import org.apache.tools.ant.taskdefs.MatchingTask; import org.apache.tools.ant.taskdefs.PumpStreamHandler; /** * Executes TeX on a fileset of files. * * @author Stefan Wachter */ public class TeXTask extends MatchingTask { private boolean myVerbose = false; private File myDir = null; private String myMode = "pdflatex"; private boolean myShowFiles = true; private String myDstExtension = "pdf"; public void setVerbose(boolean aBoolean) { myVerbose = aBoolean; } /** * Directory containing the files to process. * * @param aFile <i>(required)</i>. */ public void setDir(File aFile) { myDir = aFile; } /** * Different execution modes. Valid values are: * <ul> * <li>pdflatex (default): pdflatex is executed.</li> * <li>context: texexec is excuted.</li> * </ul> * * @param aMode <i>(required)</i>. */ public void setMode(String aMode) { myMode = aMode; } /** * Determines if the filenames of the files that are processed are output. * * @param aBoolean The default is <code>true</code>. */ public void setShowFiles(boolean aBoolean) { myShowFiles = aBoolean; } /** * Filename extension of the destination files. This extension is used to * construct the filename of the destination file. The resulting file name * is used to check if a destination file is already up to date. In that * case its processing is skipped. * * @param aString A filename extension (without leading dot). */ public void setDstExtension(String aString) { myDstExtension = aString; } public void execute() throws BuildException { DirectoryScanner ds = getDirectoryScanner(myDir); File basedir = ds.getBasedir(); System.out.println("basedir: " + basedir); String[] files = ds.getIncludedFiles(); try { for (int i = 0; i < files.length; i++) { String srcFn = files[i]; File srcFile = new File(myDir, srcFn); int idx = srcFn.lastIndexOf("."); if (idx >= 0) { String dstFn = srcFn.substring(0, idx + 1) + myDstExtension; File dstFile = new File(myDir, dstFn); if (srcFile.exists() && dstFile.exists() && srcFile.lastModified() < dstFile.lastModified()) continue; } if (myShowFiles) System.out.println("processing: " + srcFile); String[] command = null; if (myMode.equalsIgnoreCase("pdflatex")) { command = new String[] { "pdflatex", " &pdflatex \\nonstopmode\\input{" + srcFile.getName() + "}"}; } else if (myMode.equalsIgnoreCase("context")) { command = new String[] {"texexec", "--silent " + srcFile.getName()}; } else { throw new BuildException("unknown mode: " + myMode + "; (use 'latex' or 'context')"); } ExecuteStreamHandler streamHandler = null; if (myVerbose) { streamHandler = new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN); } else { ByteArrayOutputStream os = new ByteArrayOutputStream(); streamHandler = new PumpStreamHandler(os); } Execute exec = new Execute(streamHandler); exec.setWorkingDirectory(srcFile.getParentFile()); exec.setCommandline(command); exec.setAntRun(project); int exitCode = exec.execute(); if (exitCode != 0) throw new BuildException("exit code: " + exitCode); } } catch (BuildException e) { throw e; } catch (Exception e) { throw new BuildException(e); } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]