You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Russell Gold <ru...@acm.org> on 2000/07/24 18:36:24 UTC
[PATCH] Style task to reprocess all files if stylesheet is
modified.
Proposed patch: to take into consideration the data of the XLST stylesheet
as well as the file to be transformed
in deciding which files need to be processed.
----- begin patch ------
Index: src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java,v
retrieving revision 1.6
diff -u -r1.6 XSLTProcess.java
--- src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java 2000/07/21
09:43:15 1.6
+++ src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java 2000/07/24
16:33:01
@@ -83,6 +83,7 @@
*
* @author <a href="mailto:kvisco@exoffice.com">Keith Visco</a>
* @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
+ * @author <a href="mailto:russgold@acm.org">Russell Gold</a>
* @version $Revision: 1.6 $ $Date: 2000/07/21 09:43:15 $
*/
public class XSLTProcess extends MatchingTask {
@@ -138,22 +139,24 @@
log("Using "+liaison.getClass().toString(), Project.MSG_VERBOSE);
- try {
- // Create a new XSL processor with the specified stylesheet
- if (xslFile != null) {
- String file = new File(baseDir,xslFile.toString()).toString();
- log("Loading stylesheet " + file, Project.MSG_INFO);
- liaison.setStylesheet( file );
- }
- } catch (Exception ex) {
- log("Failed to read stylesheet " + xslFile, Project.MSG_INFO);
- throw new BuildException(ex);
- }
+ long styleSheetLastModified = 0;
+ if (xslFile != null) {
+ try {
+ // Create a new XSL processor with the specified stylesheet
+ File file = new File( baseDir, xslFile.toString() );
+ styleSheetLastModified = file.lastModified();
+ log( "Loading stylesheet " + file, Project.MSG_INFO);
+ liaison.setStylesheet( file.toString() );
+ } catch (Exception ex) {
+ log("Failed to read stylesheet " + xslFile, Project.MSG_INFO);
+ throw new BuildException(ex);
+ }
+ }
// Process all the files marked for styling
list = scanner.getIncludedFiles();
for (int i = 0;i < list.length; ++i) {
- process(baseDir,list[i],destDir);
+ process( baseDir, list[i], destDir, styleSheetLastModified );
}
// Process all the directoried marked for styling
@@ -161,7 +164,7 @@
for (int j = 0;j < dirs.length;++j){
list=new File(baseDir,dirs[j]).list();
for (int i = 0;i < list.length;++i)
- process(baseDir,list[i],destDir);
+ process( baseDir, list[i], destDir, styleSheetLastModified );
}
} //-- execute
@@ -284,9 +287,8 @@
* Processes the given input XML file and stores the result
* in the given resultFile.
**/
- private void process(File baseDir,String xmlFile,File destDir)
- throws BuildException
- {
+ private void process( File baseDir, String xmlFile, File destDir, long
styleSheetLastModified )
+ throws BuildException {
String fileExt=targetExtension;
File outFile=null;
File inFile=null;
@@ -294,12 +296,12 @@
try {
inFile = new File(baseDir,xmlFile);
outFile = new
File(destDir,xmlFile.substring(0,xmlFile.lastIndexOf('.'))+fileExt);
- if (inFile.lastModified() > outFile.lastModified()) {
- ensureDirectoryFor( outFile );
- //-- command line status
- log("Processing " + xmlFile + " to " + outFile,
Project.MSG_VERBOSE);
-
- liaison.transform(inFile.toString(), outFile.toString());
+ if (Math.max( styleSheetLastModified, inFile.lastModified() ) >
outFile.lastModified()) {
+ ensureDirectoryFor( outFile );
+ //-- command line status
+ log("Processing " + xmlFile + " to " + outFile,
Project.MSG_VERBOSE);
+
+ liaison.transform(inFile.toString(), outFile.toString());
}
}
catch (Exception ex) {
------ end patch -------