Author: chatellier Date: 2009-02-20 15:49:02 +0000 (Fri, 20 Feb 2009) New Revision: 181 Modified: lutinprocessor/trunk/src/main/java/org/codelutin/processor/ant/ProcessorTask.java Log: Update ant using doc, and class code style Modified: lutinprocessor/trunk/src/main/java/org/codelutin/processor/ant/ProcessorTask.java =================================================================== --- lutinprocessor/trunk/src/main/java/org/codelutin/processor/ant/ProcessorTask.java 2009-02-20 13:40:21 UTC (rev 180) +++ lutinprocessor/trunk/src/main/java/org/codelutin/processor/ant/ProcessorTask.java 2009-02-20 15:49:02 UTC (rev 181) @@ -1,6 +1,6 @@ /* * *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin + * Copyright (C) 2002 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -17,18 +17,6 @@ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ -/******************************************************************************* - * GeneratorTemplatesTask.java - * - * Created: 14 janv. 2004 - * - * @author Benjamin Poussin <poussin@codelutin.com> Copyright Code Lutin - * - * @version $Revision$ - * - * Mise a jour: $Date$ par : $Author$ - */ - package org.codelutin.processor.ant; import java.io.File; @@ -42,41 +30,30 @@ import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; +/** + * Tache ant pour lutinprocessor. + * + * To use this task, put this code in ant build file: + * + * <taskdef name="processor" classname="org.codelutin.processor.ant.ProcessorTask" + * classpath="lib/lutinprocessor.jar" /> + * + * and use it with: + * + * <processor srcdir="${src}" destdir="${targetgen}" filters="org.codelutin.processor.filters.GeneratorTemplatesFilter" /> + * + * Created: 14 janv. 2004 + * + * @author Benjamin Poussin <poussin@codelutin.com> Copyright Code Lutin + * + * @version $Revision$ + * + * Mise a jour: $Date$ par : $Author$ + */ public class ProcessorTask extends MatchingTask { // ProcessorTask - public ProcessorTask() { - } + public static final int MSG_VERBOSE = Project.MSG_VERBOSE; - protected String applyTransformationFilename(String filename) { - return filename.replaceAll(fileInPattern, fileOutPattern); - } - - protected void doExecute() throws BuildException { - Processor processor = new Processor(getFilters()); - int numberFiles; - for (numberFiles = 0; numberFiles < files.length; numberFiles++) { - String inputFileName = absoluteSourceName(files[numberFiles]); - String outputFileName = absoluteDestinationName(applyTransformationFilename(files[numberFiles])); - if(verbose) - log("Using " + inputFileName); - if (overwrite || isNewer(inputFileName, outputFileName)) { - if(verbose) - log("Generating " + outputFileName); - // creation du repertoire pour le fichier destination - new File(outputFileName).getParentFile().mkdirs(); - try { - processor.process(new FileReader(inputFileName), - new FileWriter(outputFileName)); - } catch (IOException eee) { - throw new BuildException(eee); - } - } - } - log("Generating " + numberFiles + " files to " + destDir); - } - - static int MSG_VERBOSE = Project.MSG_VERBOSE; - protected File srcDir; protected File destDir; @@ -94,17 +71,21 @@ protected String filters = "org.codelutin.processor.filters.NoActionFilter"; protected boolean overwrite = true; - + protected boolean verbose = false; - - public void setVerbose(boolean v) { - verbose = v; + + public ProcessorTask() { + } - public void setOverwrite(boolean v) { - overwrite = v; + public void setVerbose(boolean verbose) { + this.verbose = verbose; } + public void setOverwrite(boolean overwrite) { + this.overwrite = overwrite; + } + public void setFileOutPattern(String fileOutPattern) { this.fileOutPattern = fileOutPattern; } @@ -125,6 +106,36 @@ this.filters = filters; } + protected String applyTransformationFilename(String filename) { + return filename.replaceAll(fileInPattern, fileOutPattern); + } + + protected void doExecute() throws BuildException { + Processor processor = new Processor(getFilters()); + int numberFiles; + for (numberFiles = 0; numberFiles < files.length; numberFiles++) { + String inputFileName = absoluteSourceName(files[numberFiles]); + String outputFileName = absoluteDestinationName(applyTransformationFilename(files[numberFiles])); + if (verbose) { + log("Using " + inputFileName); + } + if (overwrite || isNewer(inputFileName, outputFileName)) { + if (verbose) { + log("Generating " + outputFileName); + } + // creation du repertoire pour le fichier destination + new File(outputFileName).getParentFile().mkdirs(); + try { + processor.process(new FileReader(inputFileName), + new FileWriter(outputFileName)); + } catch (IOException eee) { + throw new BuildException(eee); + } + } + } + log("Generating " + numberFiles + " files to " + destDir); + } + protected Filter[] getFilters() throws BuildException { String[] filterList = filters.split(","); Filter[] result = new Filter[filterList.length]; @@ -132,7 +143,8 @@ try { // Class.forName semble fonctionner maintenant // avant il fallait utiliser getClass().forName - result[i] = (Filter) Class.forName(filterList[i].trim()).newInstance(); + result[i] = (Filter) Class.forName(filterList[i].trim()) + .newInstance(); } catch (Exception eee) { throw new BuildException("Error during looking for '" + filterList[i].trim() + "' class", eee); @@ -152,8 +164,9 @@ + "\" does not exist!", getLocation()); } - if (destDir == null) + if (destDir == null) { destDir = srcDir; + } if (!destDir.isDirectory()) { throw new BuildException("destination directory \"" + destDir + "\" does not exist or is not a directory", getLocation()); @@ -172,12 +185,14 @@ DirectoryScanner ds = getDirectoryScanner(srcDir); String[] includes = getIncludes(); - if (includes.length > 0) + if (includes.length > 0) { ds.setIncludes(includes); + } String[] excludes = getExcludes(); - if (excludes.length > 0) + if (excludes.length > 0) { ds.setExcludes(excludes); - + } + ds.scan(); // on recherche ceux que l'on doit vraiment refaire @@ -187,8 +202,9 @@ protected boolean isNewer(String filein, String fileout) { boolean result = new File(filein).lastModified() > new File(fileout) .lastModified(); - if (result) + if (result) { log(filein + " is newer than " + fileout, MSG_VERBOSE); + } return result; }