Author: tchemit Date: 2009-10-09 19:56:12 +0200 (Fri, 09 Oct 2009) New Revision: 280 Added: trunk/ant-processor-task/ trunk/ant-processor-task/LICENSE.txt trunk/ant-processor-task/README.txt trunk/ant-processor-task/changelog.txt trunk/ant-processor-task/pom.xml trunk/ant-processor-task/src/ trunk/ant-processor-task/src/main/ trunk/ant-processor-task/src/main/java/ trunk/ant-processor-task/src/main/java/org/ trunk/ant-processor-task/src/main/java/org/nuiton/ trunk/ant-processor-task/src/main/java/org/nuiton/processor/ trunk/ant-processor-task/src/main/java/org/nuiton/processor/ant/ trunk/ant-processor-task/src/main/java/org/nuiton/processor/ant/I18nExtractorTask.java trunk/ant-processor-task/src/main/java/org/nuiton/processor/ant/ProcessorTask.java trunk/ant-processor-task/src/main/resources/ trunk/ant-processor-task/src/site/ trunk/ant-processor-task/src/site/apt/ trunk/ant-processor-task/src/site/apt/index.apt trunk/ant-processor-task/src/site/site.xml Removed: trunk/maven-processor-plugin/src/main/java/org/nuiton/processor/ant/I18nExtractorTask.java trunk/maven-processor-plugin/src/main/java/org/nuiton/processor/ant/ProcessorTask.java Modified: trunk/maven-processor-plugin/pom.xml trunk/pom.xml Log: Evolution #81: creer un module pour les taches ant Property changes on: trunk/ant-processor-task ___________________________________________________________________ Added: svn:ignore + target Added: trunk/ant-processor-task/LICENSE.txt =================================================================== --- trunk/ant-processor-task/LICENSE.txt (rev 0) +++ trunk/ant-processor-task/LICENSE.txt 2009-10-09 17:56:12 UTC (rev 280) @@ -0,0 +1,166 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + Added: trunk/ant-processor-task/README.txt =================================================================== --- trunk/ant-processor-task/README.txt (rev 0) +++ trunk/ant-processor-task/README.txt 2009-10-09 17:56:12 UTC (rev 280) @@ -0,0 +1,2 @@ +To deploy new version of pom: mvn deploy +To install localy: mvn install Added: trunk/ant-processor-task/changelog.txt =================================================================== --- trunk/ant-processor-task/changelog.txt (rev 0) +++ trunk/ant-processor-task/changelog.txt 2009-10-09 17:56:12 UTC (rev 280) @@ -0,0 +1 @@ +No more used, we will soon make optional multi-module childs changelog.txt (mavenpom>1.0.0) \ No newline at end of file Added: trunk/ant-processor-task/pom.xml =================================================================== --- trunk/ant-processor-task/pom.xml (rev 0) +++ trunk/ant-processor-task/pom.xml 2009-10-09 17:56:12 UTC (rev 280) @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <!-- ************************************************************* --> + <!-- *** POM Relationships *************************************** --> + <!-- ************************************************************* --> + + <parent> + <groupId>org.nuiton</groupId> + <artifactId>processor</artifactId> + <version>1.0.1-SNAPSHOT</version> + </parent> + + <groupId>org.nuiton.processor</groupId> + <artifactId>ant-processor-task</artifactId> + + <dependencies> + + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>nuiton-processor</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.ant</groupId> + <artifactId>ant</artifactId> + </dependency> + + <!-- tests dependencies --> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + + </dependencies> + + <!-- ************************************************************* --> + <!-- *** Project Information ************************************* --> + <!-- ************************************************************* --> + <name>Nuiton processor ant task</name> + <inceptionYear>2009</inceptionYear> + + <!-- ************************************************************* --> + <!-- *** Build Settings ****************************************** --> + <!-- ************************************************************* --> + + <packaging>jar</packaging> + +</project> Copied: trunk/ant-processor-task/src/main/java/org/nuiton/processor/ant/I18nExtractorTask.java (from rev 277, trunk/maven-processor-plugin/src/main/java/org/nuiton/processor/ant/I18nExtractorTask.java) =================================================================== --- trunk/ant-processor-task/src/main/java/org/nuiton/processor/ant/I18nExtractorTask.java (rev 0) +++ trunk/ant-processor-task/src/main/java/org/nuiton/processor/ant/I18nExtractorTask.java 2009-10-09 17:56:12 UTC (rev 280) @@ -0,0 +1,158 @@ +/* + * *##% + * Nuiton processor maven plugin + * Copyright (C) 2006 - 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 + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * ##%* + */ + +package org.nuiton.processor.ant; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +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.nuiton.processor.I18nExtractor; + +/** + * I18nExtractorTask. + * + * Created: Aug 16, 2004 + * + * @author Cédric Pineau <pineau@codelutin.com> + * @version $Revision$ + * + * Last update : $Date$ + * by : $Author$ + */ +public class I18nExtractorTask extends MatchingTask { + + public static final 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 I18nExtractorTask() { + + } + + protected void doExecute() throws BuildException { + // creation du repertoire pour le fichier destination + destFile.getParentFile().mkdirs(); + List<File> fileList = new ArrayList<File>(); + for (int i = 0; i < srcFileNames.length; i++) { + fileList.add(new File(srcFileNames[i])); + } + try { + new I18nExtractor() + .extract(fileList.toArray(new File[0]), destFile); + } catch (IOException eee) { + throw new BuildException(eee); + } + } + + public void setSrcdir(File srcDir) { + this.srcDir = srcDir; + } + + public void setDestFile(File destFile) { + this.destFile = destFile; + } + + @Override + 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[] ins = getIncludes(); + if (ins.length > 0) { + ds.setIncludes(ins); + } + String[] exs = getExcludes(); + if (exs.length > 0) { + ds.setExcludes(exs); + } + + 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; + } + + @Override + public void setIncludes(String includes) { + this.includes = includes.split(","); + } + + @Override + public void setExcludes(String excludes) { + this.excludes = excludes.split(","); + } + +} Copied: trunk/ant-processor-task/src/main/java/org/nuiton/processor/ant/ProcessorTask.java (from rev 276, trunk/maven-processor-plugin/src/main/java/org/nuiton/processor/ant/ProcessorTask.java) =================================================================== --- trunk/ant-processor-task/src/main/java/org/nuiton/processor/ant/ProcessorTask.java (rev 0) +++ trunk/ant-processor-task/src/main/java/org/nuiton/processor/ant/ProcessorTask.java 2009-10-09 17:56:12 UTC (rev 280) @@ -0,0 +1,245 @@ +/* + * *##% + * Nuiton processor maven plugin + * Copyright (C) 2006 - 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 + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * ##%* + */ +package org.nuiton.processor.ant; + +import java.io.File; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.MatchingTask; +import org.nuiton.processor.Processor; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.Project; +import org.nuiton.processor.ProcessorUtil; + +/** + * Tache ant pour lutinprocessor. + * + * To use this task, put this code in ant build file: + * <pre> + * <taskdef name="processor" classname="org.nuiton.processor.ant.ProcessorTask" + * classpath="lib/lutinprocessor.jar" /> + * </pre> + * + * and use it with: + * <pre> + * <processor srcdir="${src}" destdir="${targetgen}" filters="org.nuiton.processor.filters.GeneratorTemplatesFilter" /> + * </pre> + * 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 static final int MSG_VERBOSE = Project.MSG_VERBOSE; + protected File srcDir; + protected File destDir; + protected String[] includes = new String[]{}; + protected String[] excludes = new String[]{}; + protected String[] files; + protected String fileInPattern = ""; + protected String fileOutPattern = ""; + protected String filters = "org.nuiton.processor.filters.NoActionFilter"; + protected boolean overwrite = true; + protected boolean verbose = false; + + public ProcessorTask() { + } + + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + public void setOverwrite(boolean overwrite) { + this.overwrite = overwrite; + } + + public void setFileOutPattern(String fileOutPattern) { + this.fileOutPattern = fileOutPattern; + } + + public void setFileInPattern(String fileInPattern) { + this.fileInPattern = fileInPattern; + } + + public void setSrcdir(File srcDir) { + this.srcDir = srcDir; + } + + public void setDestdir(File destDir) { + this.destDir = destDir; + } + + public void setFilters(String filters) { + this.filters = filters; + } + + protected String applyTransformationFilename(String filename) { + return filename.replaceAll(fileInPattern, fileOutPattern); + } + + protected void doExecute() throws BuildException { + Processor processor=null; + try { + processor = ProcessorUtil.newProcessor(this.filters, ","); + } catch (Exception ex) { + throw new BuildException("Could nto instanciate processor for reason : "+ex.getMessage(), ex); + } +// 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 { +// Filter[] result; +// try { +// result = ProcessorUtil.getFilters(filters, ","); +// } catch (Exception eee) { +// throw new BuildException(eee.getMessage(), eee); +// } +//// String[] filterList = filters.split(","); +//// Filter[] result = new Filter[filterList.length]; +//// for (int i = 0; i < filterList.length; i++) { +//// try { +//// // Class.forName semble fonctionner maintenant +//// // avant il fallait utiliser getClass().forName +//// result[i] = (Filter) Class.forName(filterList[i].trim()) +//// .newInstance(); +//// } catch (Exception eee) { +//// throw new BuildException("Error during looking for '" +//// + filterList[i].trim() + "' class", eee); +//// } +//// } +// return result; +// } + + @Override + 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 (destDir == null) { + destDir = srcDir; + } + if (!destDir.isDirectory()) { + throw new BuildException("destination directory \"" + destDir + "\" does not exist or is not a directory", 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[] in = getIncludes(); + if (in.length > 0) { + ds.setIncludes(in); + } + String[] ex = getExcludes(); + if (ex.length > 0) { + ds.setExcludes(ex); + } + + ds.scan(); + + // on recherche ceux que l'on doit vraiment refaire + files = 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; + } + + @Override + public void setIncludes(String includes) { + setIncludes(includes.split(",")); + } + + public void setExcludes(String[] excludes) { + this.excludes = excludes; + } + + @Override + public void setExcludes(String excludes) { + setExcludes(excludes.split(",")); + } + + protected String absoluteDestinationName(String fileName) { + return destDir.getPath() + File.separator + fileName; + } + + protected String absoluteSourceName(String fileName) { + return srcDir.getPath() + File.separator + fileName; + } +} // ProcessorTask Added: trunk/ant-processor-task/src/site/apt/index.apt =================================================================== --- trunk/ant-processor-task/src/site/apt/index.apt (rev 0) +++ trunk/ant-processor-task/src/site/apt/index.apt 2009-10-09 17:56:12 UTC (rev 280) @@ -0,0 +1,29 @@ +---- +Ant-processor-task +---- +---- +2009-08-22 +---- + + +Présentation + + Le module <ant-processor-task> permet l'utilisation depuis ant de + Nuiton Processor. Pour plus de détails sur Nuiton Processor veuillez consulter + {{{http://maven-site.nuiton.org./processor/nuiton-processor}l'adresse suivante}}. + +Utilisation dans le pom.xml + + Voici une déclaration d'une utilisation de ant-processor-task dans un + build.xml. Il permet dans ce cas utiliser les fitres nécessaires pour + {{{http://maven-site.nuiton.org/topia}ToPIA}}. + +------------------------------------------------------------ + + <taskdef name="processor" classname="org.nuiton.processor.ant.ProcessorTask" + classpath="lib/nuiton-processor.jar" /> + + <processor srcdir="${src}" destdir="${targetgen}" + filters="org.nuiton.processor.filters.GeneratorTemplatesFilter" /> + +------------------------------------------------------------ Added: trunk/ant-processor-task/src/site/site.xml =================================================================== --- trunk/ant-processor-task/src/site/site.xml (rev 0) +++ trunk/ant-processor-task/src/site/site.xml 2009-10-09 17:56:12 UTC (rev 280) @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project name="${project.name}"> + + <bannerLeft> + <name>${project.name}</name> + <href>index.html</href> + </bannerLeft> + + <body> + <links> + <item name="Nuiton Processor" href="../nuiton-processor"/> + </links> + + <breadcrumbs> + <item name="${project.name}" href="${project.url}" /> + </breadcrumbs> + + <menu ref="parent"/> + + <menu name="Utilisateur"> + <item href="index.html" name="Accueil"/> + </menu> + + <menu name="Téléchargement"> + <item href="${repository.home.url}/org/nuiton/processor/${project.artifactId}/${project.version}/${project.build.finalName}.jar" + name="Librairie (jar)"/> + <item href="${repository.home.url}/org/nuiton/processor/${project.artifactId}/${project.version}/${project.build.finalName}-javadoc.jar" + name="Javadoc (jar)"/> + <item href="${repository.home.url}/org/nuiton/processor/${project.artifactId}/${project.version}/${project.build.finalName}-sources.jar" + name="Sources (jar)"/> + </menu> + + <menu ref="reports"/> + + </body> +</project> Modified: trunk/maven-processor-plugin/pom.xml =================================================================== --- trunk/maven-processor-plugin/pom.xml 2009-10-09 15:20:57 UTC (rev 279) +++ trunk/maven-processor-plugin/pom.xml 2009-10-09 17:56:12 UTC (rev 280) @@ -36,11 +36,6 @@ <artifactId>plexus-utils</artifactId> </dependency> - <dependency> - <groupId>org.apache.ant</groupId> - <artifactId>ant</artifactId> - </dependency> - <!-- tests dependencies --> <dependency> Deleted: trunk/maven-processor-plugin/src/main/java/org/nuiton/processor/ant/I18nExtractorTask.java =================================================================== --- trunk/maven-processor-plugin/src/main/java/org/nuiton/processor/ant/I18nExtractorTask.java 2009-10-09 15:20:57 UTC (rev 279) +++ trunk/maven-processor-plugin/src/main/java/org/nuiton/processor/ant/I18nExtractorTask.java 2009-10-09 17:56:12 UTC (rev 280) @@ -1,158 +0,0 @@ -/* - * *##% - * Nuiton processor maven plugin - * Copyright (C) 2006 - 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 - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * ##%* - */ - -package org.nuiton.processor.ant; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -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.nuiton.processor.I18nExtractor; - -/** - * I18nExtractorTask. - * - * Created: Aug 16, 2004 - * - * @author Cédric Pineau <pineau@codelutin.com> - * @version $Revision$ - * - * Last update : $Date$ - * by : $Author$ - */ -public class I18nExtractorTask extends MatchingTask { - - public static final 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 I18nExtractorTask() { - - } - - protected void doExecute() throws BuildException { - // creation du repertoire pour le fichier destination - destFile.getParentFile().mkdirs(); - List<File> fileList = new ArrayList<File>(); - for (int i = 0; i < srcFileNames.length; i++) { - fileList.add(new File(srcFileNames[i])); - } - try { - new I18nExtractor() - .extract(fileList.toArray(new File[0]), destFile); - } catch (IOException eee) { - throw new BuildException(eee); - } - } - - public void setSrcdir(File srcDir) { - this.srcDir = srcDir; - } - - public void setDestFile(File destFile) { - this.destFile = destFile; - } - - @Override - 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[] ins = getIncludes(); - if (ins.length > 0) { - ds.setIncludes(ins); - } - String[] exs = getExcludes(); - if (exs.length > 0) { - ds.setExcludes(exs); - } - - 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; - } - - @Override - public void setIncludes(String includes) { - this.includes = includes.split(","); - } - - @Override - public void setExcludes(String excludes) { - this.excludes = excludes.split(","); - } - -} Deleted: trunk/maven-processor-plugin/src/main/java/org/nuiton/processor/ant/ProcessorTask.java =================================================================== --- trunk/maven-processor-plugin/src/main/java/org/nuiton/processor/ant/ProcessorTask.java 2009-10-09 15:20:57 UTC (rev 279) +++ trunk/maven-processor-plugin/src/main/java/org/nuiton/processor/ant/ProcessorTask.java 2009-10-09 17:56:12 UTC (rev 280) @@ -1,245 +0,0 @@ -/* - * *##% - * Nuiton processor maven plugin - * Copyright (C) 2006 - 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 - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * ##%* - */ -package org.nuiton.processor.ant; - -import java.io.File; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.taskdefs.MatchingTask; -import org.nuiton.processor.Processor; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import org.apache.tools.ant.DirectoryScanner; -import org.apache.tools.ant.Project; -import org.nuiton.processor.ProcessorUtil; - -/** - * Tache ant pour lutinprocessor. - * - * To use this task, put this code in ant build file: - * <pre> - * <taskdef name="processor" classname="org.nuiton.processor.ant.ProcessorTask" - * classpath="lib/lutinprocessor.jar" /> - * </pre> - * - * and use it with: - * <pre> - * <processor srcdir="${src}" destdir="${targetgen}" filters="org.nuiton.processor.filters.GeneratorTemplatesFilter" /> - * </pre> - * 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 static final int MSG_VERBOSE = Project.MSG_VERBOSE; - protected File srcDir; - protected File destDir; - protected String[] includes = new String[]{}; - protected String[] excludes = new String[]{}; - protected String[] files; - protected String fileInPattern = ""; - protected String fileOutPattern = ""; - protected String filters = "org.nuiton.processor.filters.NoActionFilter"; - protected boolean overwrite = true; - protected boolean verbose = false; - - public ProcessorTask() { - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - public void setOverwrite(boolean overwrite) { - this.overwrite = overwrite; - } - - public void setFileOutPattern(String fileOutPattern) { - this.fileOutPattern = fileOutPattern; - } - - public void setFileInPattern(String fileInPattern) { - this.fileInPattern = fileInPattern; - } - - public void setSrcdir(File srcDir) { - this.srcDir = srcDir; - } - - public void setDestdir(File destDir) { - this.destDir = destDir; - } - - public void setFilters(String filters) { - this.filters = filters; - } - - protected String applyTransformationFilename(String filename) { - return filename.replaceAll(fileInPattern, fileOutPattern); - } - - protected void doExecute() throws BuildException { - Processor processor=null; - try { - processor = ProcessorUtil.newProcessor(this.filters, ","); - } catch (Exception ex) { - throw new BuildException("Could nto instanciate processor for reason : "+ex.getMessage(), ex); - } -// 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 { -// Filter[] result; -// try { -// result = ProcessorUtil.getFilters(filters, ","); -// } catch (Exception eee) { -// throw new BuildException(eee.getMessage(), eee); -// } -//// String[] filterList = filters.split(","); -//// Filter[] result = new Filter[filterList.length]; -//// for (int i = 0; i < filterList.length; i++) { -//// try { -//// // Class.forName semble fonctionner maintenant -//// // avant il fallait utiliser getClass().forName -//// result[i] = (Filter) Class.forName(filterList[i].trim()) -//// .newInstance(); -//// } catch (Exception eee) { -//// throw new BuildException("Error during looking for '" -//// + filterList[i].trim() + "' class", eee); -//// } -//// } -// return result; -// } - - @Override - 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 (destDir == null) { - destDir = srcDir; - } - if (!destDir.isDirectory()) { - throw new BuildException("destination directory \"" + destDir + "\" does not exist or is not a directory", 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[] in = getIncludes(); - if (in.length > 0) { - ds.setIncludes(in); - } - String[] ex = getExcludes(); - if (ex.length > 0) { - ds.setExcludes(ex); - } - - ds.scan(); - - // on recherche ceux que l'on doit vraiment refaire - files = 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; - } - - @Override - public void setIncludes(String includes) { - setIncludes(includes.split(",")); - } - - public void setExcludes(String[] excludes) { - this.excludes = excludes; - } - - @Override - public void setExcludes(String excludes) { - setExcludes(excludes.split(",")); - } - - protected String absoluteDestinationName(String fileName) { - return destDir.getPath() + File.separator + fileName; - } - - protected String absoluteSourceName(String fileName) { - return srcDir.getPath() + File.separator + fileName; - } -} // ProcessorTask Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-10-09 15:20:57 UTC (rev 279) +++ trunk/pom.xml 2009-10-09 17:56:12 UTC (rev 280) @@ -18,6 +18,7 @@ <modules> <module>nuiton-processor</module> <module>maven-processor-plugin</module> + <module>ant-processor-task</module> </modules> <dependencyManagement>