Index: lutinprocessor/src/java/org/codelutin/processor/ant/I18nExtractorTask.java diff -u /dev/null lutinprocessor/src/java/org/codelutin/processor/ant/I18nExtractorTask.java:1.1 --- /dev/null Mon Aug 16 20:47:17 2004 +++ lutinprocessor/src/java/org/codelutin/processor/ant/I18nExtractorTask.java Mon Aug 16 20:47:12 2004 @@ -0,0 +1,147 @@ +/* *##% + * Copyright (C) 2002, 2003, 2004 + * Code Lutin, Cédric Pineau, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * I18nExtractorTask.java + * + * Created: Aug 16, 2004 + * + * @author Cédric Pineau + * @version $Revision: 1.1 $ + * + * Last update : $Date: 2004/08/16 20:47:12 $ + * by : $Author: pineau $ + */ + + +package org.codelutin.processor.ant; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.MatchingTask; +import org.codelutin.processor.I18nExtractor; + +public class I18nExtractorTask extends MatchingTask { + + public I18nExtractorTask() { + } + + protected void doExecute() throws BuildException { + // creation du repertoire pour le fichier destination + destFile.getParentFile().mkdirs(); + try { + new I18nExtractor().extract(srcFileNames, destFile.getAbsolutePath()); + } catch (IOException eee) { + throw new BuildException(eee); + } + } + + static int MSG_VERBOSE = Project.MSG_VERBOSE; + + protected File srcDir; + protected File destFile; + protected String[] includes = new String[] { + }; + protected String[] excludes = new String[] { + }; + protected String[] srcFileNames; + + public void setSrcdir(File srcDir) { + this.srcDir = srcDir; + } + + public void setDestFile(File destFile) { + this.destFile = destFile; + } + + public void execute() throws BuildException { + // first of all, make sure that we've got a srcdir + if (srcDir == null) { + throw new BuildException( + "srcdir attribute must be set!", + getLocation()); + } + if (!srcDir.exists()) { + throw new BuildException( + "srcdir \"" + srcDir.getPath() + "\" does not exist!", + getLocation()); + } + + if (destFile == null) { + throw new BuildException( + "destFile attribute must be set!", + getLocation()); + } + + // Build the list of files to compute + buildFileList(); + + // generate the source files + doExecute(); + } + + protected void buildFileList() { + + // Obtain this list of files within the source directory + DirectoryScanner ds = getDirectoryScanner(srcDir); + + String[] includes = getIncludes(); + if (includes.length > 0) + ds.setIncludes(includes); + String[] excludes = getExcludes(); + if (excludes.length > 0) + ds.setExcludes(excludes); + + ds.scan(); + + // on met le resultat dans files + srcFileNames = ds.getIncludedFiles(); + } + + protected boolean isNewer(String filein, String fileout) { + boolean result = + new File(filein).lastModified() > new File(fileout).lastModified(); + if (result) + log(filein + " is newer than " + fileout, MSG_VERBOSE); + return result; + } + + protected String[] getExcludes() { + return excludes; + } + + protected String[] getIncludes() { + return includes; + } + + public void setIncludes(String includes) { + this.includes = includes.split(","); + } + + public void setExcludes(String excludes) { + this.excludes = excludes.split(","); + } + + +}