[Lutinutil-commits] r1227 - in maven-i18n-plugin/trunk: . src/main/java/org/codelutin/i18n/plugin src/main/java/org/codelutin/i18n/plugin/parser src/main/java/org/codelutin/i18n/plugin/parser/impl src/main/resources
Author: tchemit Date: 2008-10-26 13:42:43 +0000 (Sun, 26 Oct 2008) New Revision: 1227 Added: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserValidation.java maven-i18n-plugin/trunk/src/main/resources/validation.rules Modified: maven-i18n-plugin/trunk/changelog maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/SourceEntry.java maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJava.java maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJaxx.java maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserSwixat.java maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserXml.java Log: * add validator parser * improve parser mojos Modified: maven-i18n-plugin/trunk/changelog =================================================================== --- maven-i18n-plugin/trunk/changelog 2008-10-24 08:33:10 UTC (rev 1226) +++ maven-i18n-plugin/trunk/changelog 2008-10-26 13:42:43 UTC (rev 1227) @@ -1,3 +1,7 @@ +ver-0-7 chemit 200810?? + * 20081026 [chemit] add xworks validator parse + * 20081026 [chemit] improve parser mojo logging + ver-0-6 thimel 20080922 * 20080925 [chemit] Using lutinpluginutil 0.2 and license-switcher in pom (no more in superpom) * 20080922 [thimel] Using lutinpluginproject 3.0 Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java 2008-10-24 08:33:10 UTC (rev 1226) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java 2008-10-26 13:42:43 UTC (rev 1227) @@ -20,7 +20,6 @@ import org.codelutin.i18n.plugin.parser.ParserEvent; import org.apache.maven.plugin.AbstractMojo; -import org.codelutin.i18n.plugin.PluginHelper; import java.io.File; import java.util.ArrayList; @@ -53,7 +52,7 @@ /** * Repertoire des fichiers generes i18n. * - * @parameter expression="${i18n.out}" default-value="${basedir}/target/gen/i18n" + * @parameter expression="${i18n.out}" default-value="${basedir}/target/generated-sources/i18n" * @required */ protected File out; @@ -136,26 +135,5 @@ this.events.remove(parserEvent); } - /** - * Construit une chaine de log formatée. - * - * @param msg le prefix du message - * @param nbFiles le nombre de fichiers actuellement traités - * @param time le time de traitement de ce fichier - * @param all le temps de traitement de tous les fichiers - * @return la chaine de log formatée - */ - protected String getLogEntry(String msg, int nbFiles, long time, long all) { - long now = System.nanoTime(); - long delta = now - time; - String s = "[" + artifactId + "] i18n." + getClass().getSimpleName() + " : " + msg; - if (time > 0) { - s += " (" + PluginHelper.convertTime(delta) + ")"; - } - if (all > 0 && nbFiles > -1) { - s += "(total time:" + PluginHelper.convertTime(now - all) + ") ( ~ " + PluginHelper.convertTime(((now - all) / (nbFiles + 1))) + " / file)"; - } - return s; - } } Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/SourceEntry.java =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/SourceEntry.java 2008-10-24 08:33:10 UTC (rev 1226) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/SourceEntry.java 2008-10-26 13:42:43 UTC (rev 1227) @@ -19,6 +19,7 @@ import org.apache.maven.plugin.logging.Log; import org.codehaus.plexus.util.DirectoryScanner; +import org.codelutin.util.FileUpdater; import java.io.File; import java.lang.annotation.Annotation; @@ -54,9 +55,16 @@ protected File basedir; protected String[] includes; - protected String[] excludes; + /** Files to be find */ + protected String[] files; + protected String[] skipFiles; + + protected String skipMessage; + + protected FileUpdater updater; + public String[] getExcludes() { return excludes; } @@ -105,6 +113,18 @@ return excludes != null && excludes.length > 0; } + /** + * Test if a file is up to date and not to be treated. + * <p/> + * + * @param file the file path to test + * @return <code>true</code> if file is up to date and do not need to be parsed + * @see FileUpdater + */ + public final boolean isFileUptodate(File file) { + return updater != null && updater.isFileUpToDate(file); + } + public String[] getIncludedFiles(File defaultBasedir, String[] defaultIncludes, String[] defaultExcludes) { // normalized entry if (!hasSrc()) { @@ -131,6 +151,7 @@ return foundFiles; } + @Override public String toString() { StringBuilder sb = new StringBuilder("basedir:").append(basedir); if (includes != null) { @@ -214,4 +235,27 @@ return getAnnotation(f, loader, annotationClass, log); } + public String getSkipMessage() { + return skipMessage; + } + + public String[] getFiles() { + return files; + } + + public String[] getSkipFiles() { + return skipFiles; + } + + public int getFoudFiles() { + return skipFiles.length + files.length; + } + + public FileUpdater getUpdater() { + return updater; + } + + public void setUpdater(FileUpdater updater) { + this.updater = updater; + } } Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java 2008-10-24 08:33:10 UTC (rev 1226) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java 2008-10-26 13:42:43 UTC (rev 1227) @@ -17,17 +17,18 @@ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ package org.codelutin.i18n.plugin.parser; -import org.codelutin.i18n.plugin.SourceEntry; -import org.codelutin.i18n.plugin.AbstractI18nPlugin; -import org.codelutin.i18n.plugin.parser.ParserEvent; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.logging.SystemStreamLog; +import org.codelutin.i18n.plugin.AbstractI18nPlugin; import org.codelutin.i18n.plugin.PluginHelper; import org.codelutin.i18n.plugin.PluginHelper.I18nProperties; +import org.codelutin.i18n.plugin.SourceEntry; import org.codelutin.i18n.plugin.parser.event.KeysModifier; import org.codelutin.util.FileUpdater; import org.codelutin.util.FileUtil; +import java.beans.Introspector; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -59,6 +60,8 @@ /** @return the default src directory to use in directory scanner */ protected abstract File getDefaultBasedir(); + public abstract FileUpdater newFileUpdater(SourceEntry entry); + /** * treate default entry * @@ -71,7 +74,7 @@ * * @parameter expression="${i18n.entries}" */ - protected SourceEntry[] entries; + protected MySourceEntry[] entries; protected I18nProperties result; @@ -84,10 +87,11 @@ protected boolean touchFile; protected List<File> treadedFiles; - protected SourceEntry currentEntry; + @Override + public ParserLog getLog() { + return (ParserLog) super.getLog(); + } - protected FileUpdater updater; - public void init() { t0 = System.nanoTime(); result = new I18nProperties(encoding); @@ -101,20 +105,6 @@ treadedFiles = new ArrayList<File>(); } - /** - * Test if a file is up to date and not to be treated. - * <p/> - * This method is called on a file only in not {@link #strictMode}. - * <p/> - * If {@link #updater} is null, then it considers that file as always to be treated. - * - * @param file the file path to test - * @return <code>true</code> if file is up to date and do not need to be parsed - * @see FileUpdater - */ - protected final boolean isFileUptodate(File file) { - return updater != null && updater.isFileUpToDate(file); - } /* * (non-Javadoc) @@ -122,6 +112,8 @@ */ public void execute() throws MojoExecutionException, MojoFailureException { + setLog(new ParserLog(this)); + init(); if (entries == null || entries.length == 0 && !treateDefaultEntry) { // nothing to do @@ -148,7 +140,11 @@ saveFile.delete(); int i = treadedFiles.size(); - getLog().info(getLogEntry(" success <getter:" + getOutGetter() + "> [treated file(s) : " + i + '/' + fileTreated + "]", fileTreated, 0, t0)); + if (fileTreated == 0) { + getLog().info(getLog().getLogEntry("parsing is done. [no files treated]", 0, 0, t0)); + } else { + getLog().info(getLog().getLogEntry("parsing is done. [treated file(s) : " + i + '/' + fileTreated + "]", fileTreated, 0, t0)); + } } catch (Exception e) { getLog().error("Error code parsing ", e); @@ -167,41 +163,43 @@ addDefaultEntry(); } long t00 = System.nanoTime(); - for (SourceEntry entry : entries) { - if (!entry.useForGoal(getClass().getSimpleName())) { + for (MySourceEntry entry : this.entries) { + + getLog().setEntry(entry); + + boolean skip = entry.init(this); + + if (skip) { if (verbose) { - getLog().debug("skip entry " + entry.toString()); + getLog().infoEntry("skip", entry.getSkipMessage()); } continue; } - currentEntry = entry; - // get found files - String[] foundFiles = getFilesForEntry(entry); + long t000 = System.nanoTime(); + int nbFiles = entry.getFiles().length; if (verbose) { - getLog().debug(getLogEntry(" parse <" + entry + "> [incoming file(s) : " + foundFiles.length + "]", 0, 0, 0)); - } else { - getLog().info(getLogEntry(" parse <" + entry.getBasedir() + "> [incoming file(s) : " + foundFiles.length + "]", 0, 0, 0)); + getLog().infoEntry("start", getLog().getLogEntry("[incoming file(s) : " + entry.getFoudFiles() + "]", 0, 0, 0)); } + // launch parser for found files - parseEntry(entry.getBasedir(), foundFiles); - fileTreated += foundFiles.length; + parseEntry(entry); + if (verbose) { - getLog().debug(getLogEntry(" success <" + entry.getBasedir() + "> [treated file(s) : " + foundFiles.length + "]", foundFiles.length - 1, t000, t00)); + // log skipped files + for (String skipFile : entry.getSkipFiles()) { + getLog().file = new File(entry.getBasedir(), skipFile); + getLog().infoFile("skip", null); + } } + fileTreated += nbFiles; + if (verbose) { + getLog().infoEntry("end", getLog().getLogEntry("[treated file(s) : " + nbFiles + "]", nbFiles, t000, t00)); + } t00 = System.nanoTime(); } } - /** - * Obtain all the relative path of files to treate for a given entry. - * - * @param entry the given entry - * @return the list of relative path of files for the given entry - */ - protected String[] getFilesForEntry(SourceEntry entry) { - return entry.getIncludedFiles(getDefaultBasedir(), getDefaultIncludes(), getDefaultExcludes()); - } /** * Add the default entry to entries given in configuration. @@ -209,53 +207,52 @@ * This is a convinient method to simplify the configuration of the plugin. */ protected void addDefaultEntry() { - List<SourceEntry> list; + List<MySourceEntry> list; if (entries == null || entries.length == 0) { - list = new ArrayList<SourceEntry>(); + list = new ArrayList<MySourceEntry>(); } else { - list = new ArrayList<SourceEntry>(Arrays.asList(entries)); + list = new ArrayList<MySourceEntry>(Arrays.asList(entries)); } - list.add(new SourceEntry()); - entries = list.toArray(new SourceEntry[list.size()]); + list.add(new MySourceEntry()); + entries = list.toArray(new MySourceEntry[list.size()]); } /** * launch parsing on a given entry. * - * @param basedir the basedir of the entry - * @param files the relative path of files to be treated for the entry. + * @param entry currentEntry to treate * @throws IOException if any io pb. */ - protected void parseEntry(File basedir, String[] files) throws IOException { + protected final void parseEntry(SourceEntry entry) throws IOException { long t00 = System.nanoTime(); - for (int i = 0; i < files.length; i++) { + String[] files = entry.getFiles(); + for (int i = 0, max = files.length; i < max; i++) { String file1 = files[i]; long t000 = System.nanoTime(); - String fileName = basedir.getAbsolutePath() + File.separator + file1; + String fileName = entry.getBasedir().getAbsolutePath() + File.separator + file1; File file = new File(fileName); for (ParserEvent event : events) { event.eventChangeFile(file); } + getLog().file = file; + touchFile = false; int size = result.size(); - if (strictMode || !isFileUptodate(file)) { - // on parse toujours en mode strict ou quand le fichier n'est pas à jour - getLog().info("parseFile " + file); - parseFile(file); + if (verbose) { + getLog().infoFile("parse", null); } + parseFile(file); // Detection de nouvelles cles, sauvegarde du fichier pour pouvoir le restaurer en cas de plantage if (size != result.size()) { saveGetterFile(); } if (touchFile) { - if (verbose) { - getLog().info("touched file " + file); - } + getLog().infoFile("touch", null); treadedFiles.add(file); - if (verbose) { - getLog().debug(getLogEntry(fileName, i, t000, t00)); + if (getLog().isDebugEnabled()) { + getLog().debug(getLog().getLogEntry(fileName, i, t000, t00)); } } for (ParserEvent event : events) { @@ -273,4 +270,143 @@ File getterFile = PluginHelper.getGetterFile(out, getOutGetter(), false); result.store(getterFile); } + + + public static class ParserLog extends SystemStreamLog { + + private SourceEntry entry; + + protected File file; + + protected String parser; + + public ParserLog(AbstractI18nParser parser) { + this.parser = "i18n:" + Introspector.decapitalize(parser.getClass().getSimpleName()) + " on " + parser.artifactId; + } + + @Override + public void info(CharSequence content) { + print(0, "INFO", null, content.toString()); + } + + @Override + public void debug(CharSequence content) { + print(0, "DEBUG", null, content.toString()); + } + + public void infoEntry(String action, CharSequence content) { + print(0, "INFO", action, entry.toString() + (content == null ? "" : " - " + content.toString())); + } + + public void infoFile(String action, String content) { + print(2, "INFO", action, file.toString() + (content == null ? "" : " - " + content)); + } + + private void print(int start, String prefix, String context, String content) { + StringBuilder sb = new StringBuilder(); + sb.append("[").append(prefix).append("] [").append(parser).append("] "); + + for (int i = 0; i < start; i++) { + sb.append(' '); + } + if (context != null) { + sb.append("<").append(context).append("> "); + } + sb.append(content); + System.out.println(sb.toString()); + } + + public void setEntry(SourceEntry entry) { + this.entry = entry; + } + + /** + * Construit une chaine de log formatée. + * + * @param msg le prefix du message + * @param nbFiles le nombre de fichiers actuellement traités + * @param time le time de traitement de ce fichier + * @param all le temps de traitement de tous les fichiers + * @return la chaine de log formatée + */ + protected String getLogEntry(String msg, int nbFiles, long time, long all) { + long now = System.nanoTime(); + long delta = now - time; + String s = msg; + if (time > 0) { + s += " (" + PluginHelper.convertTime(delta) + ")"; + } + if (all > 0) { + s += "(total time:" + PluginHelper.convertTime(now - all) + ")"; + } + if (nbFiles > 0) { + s += " ( ~ " + PluginHelper.convertTime(((now - all) / (nbFiles))) + " / file)"; + } + return s; + } + + } + + public static class MySourceEntry extends SourceEntry { + + public boolean init(AbstractI18nParser mojo) { + if (!useForGoal(mojo.getClass().getSimpleName())) { + // skip not for this goal + skipMessage = "exclude for this goal."; + return true; + } + + String[] files = getFilesForEntry(mojo); + + if (files.length == 0) { + // skip no file found + skipMessage = "no file found."; + return true; + } + setUpdater(mojo.newFileUpdater(this)); + + if (mojo.strictMode || updater == null) { + // mojo strict mode or not updater, so force all files + skipFiles = new String[0]; + this.files = files; + return false; + } + + List<String> listFiles = new ArrayList<String>(); + List<String> listSkipFiles = new ArrayList<String>(); + + // test if have any file + for (String foundFile : files) { + File file = new File(getBasedir(), foundFile); + if (isFileUptodate(file)) { + listSkipFiles.add(foundFile); + } else { + listFiles.add(foundFile); + } + } + boolean todo = !listFiles.isEmpty(); + if (!todo) { + // skip, no file out-of -date + skipMessage = "all files are up to date."; + this.skipFiles = listSkipFiles.toArray(new String[listSkipFiles.size()]); + this.files = new String[0]; + return true; + } + this.skipFiles = listSkipFiles.toArray(new String[listSkipFiles.size()]); + this.files = listFiles.toArray(new String[listFiles.size()]); + return false; + } + + + /** + * Obtain all the relative path of files to treate for a given entry. + * + * @param mojo the given mojo + * @return the list of relative path of files for the given entry + */ + protected String[] getFilesForEntry(AbstractI18nParser mojo) { + return getIncludedFiles(mojo.getDefaultBasedir(), mojo.getDefaultIncludes(), mojo.getDefaultExcludes()); + } + + } } Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJava.java =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJava.java 2008-10-24 08:33:10 UTC (rev 1226) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJava.java 2008-10-26 13:42:43 UTC (rev 1227) @@ -19,15 +19,16 @@ package org.codelutin.i18n.plugin.parser.impl; import org.apache.maven.project.MavenProject; +import org.codelutin.i18n.plugin.SourceEntry; import org.codelutin.i18n.plugin.parser.AbstractI18nParser; import org.codelutin.i18n.plugin.parser.ParserEvent; import org.codelutin.i18n.plugin.parser.ParserException; import org.codelutin.processor.filters.I18nFilter; +import org.codelutin.util.FileUpdater; import org.codelutin.util.FileUpdaterHelper; import java.io.File; import java.io.FileInputStream; -import java.io.IOException; import java.io.InputStreamReader; import java.io.LineNumberReader; @@ -71,20 +72,24 @@ protected File cp; @Override - protected String[] getDefaultIncludes() { + public String[] getDefaultIncludes() { return new String[]{defaultIncludes}; } @Override - protected String[] getDefaultExcludes() { + public String[] getDefaultExcludes() { return new String[]{}; } @Override - protected File getDefaultBasedir() { + public File getDefaultBasedir() { return defaultBasedir; } + public FileUpdater newFileUpdater(SourceEntry entry) { + return FileUpdaterHelper.newJavaFileUpdater(entry.getBasedir(), cp); + } + @Override protected String getKeyModifierStart() { return "_\\(\\s*\""; @@ -108,12 +113,6 @@ filter = new I18nFilter(); } - protected void parseEntry(File basedir, String[] files) throws IOException { - // prepare new file updater - updater = FileUpdaterHelper.newJavaFileUpdater(basedir, cp); - super.parseEntry(basedir, files); - } - @Override public void parseFile(File srcFile) { try { Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJaxx.java =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJaxx.java 2008-10-24 08:33:10 UTC (rev 1226) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJaxx.java 2008-10-26 13:42:43 UTC (rev 1227) @@ -18,10 +18,11 @@ package org.codelutin.i18n.plugin.parser.impl; +import org.codelutin.i18n.plugin.SourceEntry; +import org.codelutin.util.FileUpdater; import org.codelutin.util.FileUpdaterHelper; import java.io.File; -import java.io.IOException; /** * Récupération des chaine à traduire depuis les fichiers xml Jaxx. @@ -54,19 +55,17 @@ protected String rulesJaxx; @Override - protected String[] getDefaultIncludes() { + public String[] getDefaultIncludes() { return new String[]{defaultIncludes}; } @Override - protected String[] getDefaultExcludes() { + public String[] getDefaultExcludes() { return new String[]{}; } - protected void parseEntry(File basedir, String[] files) throws IOException { - // prepare new file updater - updater = FileUpdaterHelper.newJavaFileUpdater(basedir, defaultGenerateBasedir); - super.parseEntry(basedir, files); + public FileUpdater newFileUpdater(SourceEntry entry) { + return FileUpdaterHelper.newJavaFileUpdater(entry.getBasedir(), defaultGenerateBasedir); } @Override Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserSwixat.java =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserSwixat.java 2008-10-24 08:33:10 UTC (rev 1226) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserSwixat.java 2008-10-26 13:42:43 UTC (rev 1227) @@ -18,6 +18,9 @@ package org.codelutin.i18n.plugin.parser.impl; +import org.codelutin.i18n.plugin.SourceEntry; +import org.codelutin.util.FileUpdater; + /** * Recuperation des chaines à traduire depuis les fichiers xml Swixat. * @@ -49,15 +52,19 @@ protected String rulesSwixat; @Override - protected String[] getDefaultIncludes() { + public String[] getDefaultIncludes() { return new String[]{defaultIncludes}; } @Override - protected String[] getDefaultExcludes() { + public String[] getDefaultExcludes() { return new String[]{defaultExcludes}; } + public FileUpdater newFileUpdater(SourceEntry entry) { + return null; + } + @Override protected String getKeyModifierStart() { return "=\\s*[\"\']"; Copied: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserValidation.java (from rev 1226, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJaxx.java) =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserValidation.java (rev 0) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserValidation.java 2008-10-26 13:42:43 UTC (rev 1227) @@ -0,0 +1,126 @@ +/* + * *##% Plugin maven pour lutini18n + * Copyright (C) 2007 - 2008 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.codelutin.i18n.plugin.parser.impl; + +import org.codelutin.i18n.plugin.SourceEntry; +import org.codelutin.util.FileUpdater; +import org.codelutin.util.MirroredFileUpdater; + +import java.io.File; + +/** + * Récupération des chaine à traduire depuis les fichiers xml de validation. + * <p/> + * Le goal doit etre execute avant que les resources soient copiees dans target/classes + * pour rendre operatne le file updater (sinon lesfichiers sont toujours a jour...) + * + * @author chemit + * @goal parserValidation + * @phase generate-resources + */ +public class ParserValidation extends ParserXml { + + /** + * Source entries (src+includes+excludes) . + * + * @parameter expression="${i18n.defaultIncludes}" default-value="**\\/**-validation.xml" + */ + protected String defaultIncludes; + + /** + * Where jaxx files should have been generated. + * + * @parameter expression="${i18n.cp}" default-value="${basedir}/target/classes" + */ + protected File cp; + + /** + * Regles xml. + * + * @parameter expression="${i18n.rulesValidation}" default-value="validation.rules" + */ + protected String rulesValidation; + + /** + * default src for an entry. + * + * @parameter expression="${i18n.defaultBasedir}" default-value="${basedir}/src/resources" + * @required + */ + protected File defaultBasedir; + + public String[] getDefaultIncludes() { + return new String[]{defaultIncludes}; + } + + public String[] getDefaultExcludes() { + return new String[]{}; + } + + @Override + public File getDefaultBasedir() { + return defaultBasedir; + } + + public FileUpdater newFileUpdater(SourceEntry entry) { + return new MirroredFileUpdater(entry.getBasedir(), this.cp) { + public File getMirrorFile(File f) { + String file = f.getAbsolutePath().substring(this.prefixSourceDirecotory); + return new File(this.destinationDirectory + File.separator + file); + } + }; + } + + protected String getOutGetter() { + return "validation.getter"; + } + + protected String getKeyModifierStart() { + return "=\\s*[\"\']"; + } + + protected String getKeyModifierEnd() { + return "[\"\']"; + } + + protected String getFileRules() { + return rulesValidation; + } + + protected String getCoreFileRules() { + return "validation.rules"; + } + + public void setRulesJaxx(String rulesJaxx) { + this.rulesValidation = rulesJaxx; + } + + /* + * (non-Javadoc) + * @see org.codelutin.i18n.plugin.extension.XmlParser#extract(java.lang.String) + */ + public String extract(String i18nString) { + String s = i18nString.length() == 0 ? null : i18nString; + if (getLog().isDebugEnabled()) { + getLog().debug(i18nString + " = " + s); + } + return s; + } + +} \ No newline at end of file Property changes on: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserValidation.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserXml.java =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserXml.java 2008-10-24 08:33:10 UTC (rev 1226) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserXml.java 2008-10-26 13:42:43 UTC (rev 1227) @@ -86,7 +86,7 @@ */ public void parseFile(File file) { NodeList list; - InputSource inputSource = new InputSource(file.getAbsolutePath()); // TODO: A d�placer pour les performances + InputSource inputSource = new InputSource(file.getAbsolutePath()); // TODO: A deplacer pour les performances try { int size = result.size(); @@ -131,7 +131,7 @@ } } - protected File getDefaultBasedir() { + public File getDefaultBasedir() { return defaultBasedir; } @@ -150,7 +150,7 @@ // load core rules readInputStream = loadRulesFile(getCoreFileRules()); if (verbose) { - getLog().debug("core rules : " + readInputStream); + getLog().info("core rules : " + getCoreFileRules()); } result.append(readInputStream); @@ -158,7 +158,7 @@ // add custom rules readInputStream = loadRulesFile(fileRules); if (verbose) { - getLog().debug("custom rules : " + readInputStream); + getLog().info("custom rules : " + fileRules); } result.append(" | ").append(readInputStream); } Copied: maven-i18n-plugin/trunk/src/main/resources/validation.rules (from rev 1226, maven-i18n-plugin/trunk/src/main/resources/jaxx.rules) =================================================================== --- maven-i18n-plugin/trunk/src/main/resources/validation.rules (rev 0) +++ maven-i18n-plugin/trunk/src/main/resources/validation.rules 2008-10-26 13:42:43 UTC (rev 1227) @@ -0,0 +1,3 @@ +# Règles pour la validation XWorks + +//validators/field/field-validator/message Property changes on: maven-i18n-plugin/trunk/src/main/resources/validation.rules ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native
participants (1)
-
tchemit@users.labs.libre-entreprise.org