Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 40867 invoked from network); 6 Aug 2004 10:29:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 6 Aug 2004 10:29:27 -0000 Received: (qmail 244 invoked by uid 500); 6 Aug 2004 10:29:24 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 204 invoked by uid 500); 6 Aug 2004 10:29:24 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 185 invoked by uid 99); 6 Aug 2004 10:29:24 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FORGED_RCVD_HELO,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received: from [213.165.64.20] (HELO mail.gmx.net) (213.165.64.20) by apache.org (qpsmtpd/0.27.1) with SMTP; Fri, 06 Aug 2004 03:29:22 -0700 Received: (qmail 25735 invoked by uid 65534); 6 Aug 2004 10:29:20 -0000 Received: from p508A37AE.dip.t-dialin.net (EHLO gmx.de) (80.138.55.174) by mail.gmx.net (mp025) with SMTP; 06 Aug 2004 12:29:20 +0200 X-Authenticated: #10144042 Message-ID: <41136953.4090000@gmx.de> Date: Fri, 06 Aug 2004 13:19:47 +0200 From: Stefan Wachter User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113 X-Accept-Language: en-us, en MIME-Version: 1.0 To: dev@ant.apache.org Subject: new task to execute TeX Content-Type: multipart/mixed; boundary="------------080800090205060807060205" X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N --------------080800090205060807060205 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 --------------080800090205060807060205 Content-Type: text/plain; name="TeXTask.java" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="TeXTask.java" 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 (required). */ public void setDir(File aFile) { myDir = aFile; } /** * Different execution modes. Valid values are: *
    *
  • pdflatex (default): pdflatex is executed.
  • *
  • context: texexec is excuted.
  • *
* * @param aMode (required). */ public void setMode(String aMode) { myMode = aMode; } /** * Determines if the filenames of the files that are processed are output. * * @param aBoolean The default is true. */ 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); } } } --------------080800090205060807060205 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org --------------080800090205060807060205--