Author: tchemit Date: 2009-02-14 12:54:21 +0000 (Sat, 14 Feb 2009) New Revision: 1341 Added: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/I18nLogger.java 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/Generate.java maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Getter.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/ParserValidation.java maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserXml.java Log: can use no config in plugin nicer plugin logging 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 2009-02-14 11:27:26 UTC (rev 1340) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java 2009-02-14 12:54:21 UTC (rev 1341) @@ -18,11 +18,12 @@ package org.codelutin.i18n.plugin; +import org.apache.maven.plugin.AbstractMojo; import org.codelutin.i18n.plugin.parser.ParserEvent; -import org.apache.maven.plugin.AbstractMojo; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -34,17 +35,36 @@ public abstract class AbstractI18nPlugin extends AbstractMojo { /** + * Répertoire de stockage des fichiers i18n pour la recuperation des fichiers + * de traduction entre librairie + */ + protected static final String DIRECTORY_INSTALL = "i18n" + File.separatorChar; + + /** les bundles par defaut utilisés, si aucun bundle n'est renseigné. */ + protected static final String[] DEFAULT_BUNDLES = new String[]{"fr_FR", "en_GB"}; + + + /** + * Nom du projet. + * + * @parameter expression="${i18n.artifactId}" default-value="${project.artifactId}" + * @readonly + */ + protected String artifactId; + + /** * Langues des bundles generes. + * <p/> + * Note: Si aucun bundle n'est definie, on utilise par defaut {@link #DEFAULT_BUNDLES}. * - * @parameter expression="${i18n.bundles}" default-value="" - * @required + * @parameter expression="${i18n.bundles}" */ - protected String[] bundles; + protected String[] bundles = DEFAULT_BUNDLES; /** * Repertoire sources des fichiers i18n. * - * @parameter expression="${i18n.src}" default-value="${basedir}/src/resources/i18n" + * @parameter expression="${i18n.src}" default-value="${basedir}/src/main/resources/i18n" * @required */ protected File src; @@ -58,14 +78,6 @@ protected File out; /** - * Nom du projet. - * - * @parameter expression="${i18n.artifactId}" default-value="${project.artifactId}" - * @readonly - */ - protected String artifactId; - - /** * encoding a utiliser pour charger et sauver les bundles * * @parameter expression="${i18n.encoding}" default-value="${maven.compile.encoding}" @@ -75,13 +87,17 @@ /** * Met les fichiers generes dans le repertoire des sources i18n. + * <p/> + * Note: Par défaut active, pour pouvoir paquager avec les bundles mis a jour. * * @parameter expression="${i18n.genSrc}" default-value="true" */ protected boolean genSrc; /** - * Active la modification de cle + * Active la modification de cle. + * <p/> + * Note: par defaut, on ne l'active pas (build sur serveur non ui). * * @parameter expression="${i18n.keysModifier}" default-value="false" */ @@ -89,6 +105,8 @@ /** * verbose flag + * <p/> + * Note: si non renseigne, on utilise la propiété <code>maven.verbose</code>. * * @parameter expression="${i18n.verbose}" default-value="${maven.verbose}" */ @@ -96,8 +114,10 @@ /** * conserve les anciens fichiers de traduction avec un suffix ~ + * <p/> + * Note: par defaut, on ne l'active pas. * - * @parameter expression="${i18n.keepBackup}" default-value="true" + * @parameter expression="${i18n.keepBackup}" default-value="false" */ protected boolean keepBackup; @@ -108,15 +128,10 @@ */ protected boolean strictMode; - /** - * Répertoire de stockage des fichiers i18n pour la recuperation des fichiers - * de traduction entre librairie - */ - protected static String DIRECTORY_INSTALL = "i18n" + File.separatorChar; - /** Liste des évènements */ protected List<ParserEvent> events = new ArrayList<ParserEvent>(); + /** * Ajoute un évènement * @@ -135,5 +150,28 @@ this.events.remove(parserEvent); } + @Override + public I18nLogger getLog() { + return (I18nLogger) super.getLog(); + } + public void init() { + + // set logger + setLog(new I18nLogger(this)); + if (verbose) { + getLog().infoAction("config", "verbose mode is on"); + } + // set default bundle in none specified + if (bundles == null || bundles.length == 0 || (bundles.length == 1 && (bundles[0] == null || bundles[0].trim().isEmpty()))) { + if (verbose) { + getLog().infoAction("config", "use default bundles " + Arrays.toString(DEFAULT_BUNDLES)); + } + bundles = DEFAULT_BUNDLES; + } + } + + public String getArtifactId() { + return artifactId; + } } Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Generate.java =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Generate.java 2009-02-14 11:27:26 UTC (rev 1340) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Generate.java 2009-02-14 12:54:21 UTC (rev 1341) @@ -20,7 +20,6 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.codelutin.i18n.plugin.PluginHelper; import org.codelutin.i18n.plugin.PluginHelper.I18nProperties; import org.codelutin.util.FileUtil; @@ -43,6 +42,9 @@ * @see org.apache.maven.plugin.AbstractMojo#execute() */ public void execute() throws MojoExecutionException, MojoFailureException { + + init(); + for (String bundle : bundles) { try { // Merge @@ -87,13 +89,15 @@ FileUtil.copy(bundleSrc, PluginHelper.getI18nFileBackup(src, artifactId, bundle)); } - getLog().info("Merge bundle " + bundleSrc.getAbsolutePath()); + getLog().infoAction("merge", bundleSrc.getAbsolutePath()); } if (genSrc) { // Copie des fichiers dans les sources FileUtil.copy(bundleOut, bundleSrc); - getLog().info("Copy bundle " + bundleSrc.getAbsolutePath()); + if (verbose) { + getLog().infoAction("copy", bundleSrc.getAbsolutePath()); + } } } catch (IOException e) { Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Getter.java =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Getter.java 2009-02-14 11:27:26 UTC (rev 1340) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Getter.java 2009-02-14 12:54:21 UTC (rev 1341) @@ -21,7 +21,6 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.codehaus.plexus.util.DirectoryScanner; -import org.codelutin.i18n.plugin.PluginHelper; import org.codelutin.i18n.plugin.PluginHelper.I18nProperties; import org.codelutin.util.FileUtil; @@ -43,6 +42,9 @@ * @see org.apache.maven.plugin.AbstractMojo#execute() */ public void execute() throws MojoExecutionException, MojoFailureException { + + init(); + try { File bundleGetters = new File(out.getAbsolutePath() + File.separatorChar + artifactId + ".properties"); bundleGetters.createNewFile(); @@ -60,14 +62,16 @@ if (genSrc) { bundleGetter.delete(); } - getLog().info("Create bundle with " + bundleGetter.getAbsolutePath()); + getLog().infoAction("create", bundleGetter.getAbsolutePath()); } // Création des bundles for (String bundle : bundles) { File bundleOut = PluginHelper.getI18nFile(out, artifactId, bundle, false); FileUtil.copy(bundleGetters, bundleOut); - getLog().info("Generate bundle " + bundleOut.getAbsolutePath()); + if (verbose) { + getLog().infoAction("generate", bundleOut.getAbsolutePath()); + } } bundleGetters.delete(); Added: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/I18nLogger.java =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/I18nLogger.java (rev 0) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/I18nLogger.java 2009-02-14 12:54:21 UTC (rev 1341) @@ -0,0 +1,98 @@ +package org.codelutin.i18n.plugin; + +import org.apache.maven.plugin.logging.SystemStreamLog; + +import java.beans.Introspector; +import java.io.File; + +/** + * Le logger utilisé par les mojo. + * + * @author chemit + * @since 0.9 + */ +public class I18nLogger extends SystemStreamLog { + + /** l'entrée en cours de traitement (pour les parseurs) */ + private SourceEntry entry; + + /** le fichier en cours de traitement (pour les parseurs) */ + protected File file; + + /** le prefix du mojo courant a ajouter dans les logs. */ + protected String parser; + + public I18nLogger(AbstractI18nPlugin parser) { + this.parser = "i18n:" + Introspector.decapitalize(parser.getClass().getSimpleName()) + " on " + parser.getArtifactId(); + } + + @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)); + } + + public void infoAction(String action, String content) { + print(2, "INFO", action, (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 + */ + public 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 void setFile(File file) { + this.file = file; + } + +} 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 2009-02-14 11:27:26 UTC (rev 1340) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java 2009-02-14 12:54:21 UTC (rev 1341) @@ -19,16 +19,15 @@ 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.I18nLogger; 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; @@ -106,11 +105,8 @@ protected List<File> treadedFiles; @Override - public ParserLog getLog() { - return (ParserLog) super.getLog(); - } - public void init() { + super.init(); t0 = System.nanoTime(); result = new I18nProperties(encoding); oldParser = new I18nProperties(encoding); @@ -133,8 +129,6 @@ */ public void execute() throws MojoExecutionException, MojoFailureException { - setLog(new ParserLog(this)); - init(); if (entries == null || entries.length == 0 && !treateDefaultEntry) { // nothing to do @@ -142,10 +136,10 @@ } if (safeMode) { - getLog().infoAction("[config]"," safeMode is active (could be slower)."); + getLog().infoAction("config","safeMode is active (could be slower)."); } if (strictMode) { - getLog().infoAction("[config]"," strictMode is active (all files will be parsed)."); + getLog().infoAction("config","strictMode is active (all files will be parsed)."); } try { @@ -217,7 +211,7 @@ if (verbose) { // log skipped files for (String skipFile : entry.getSkipFiles()) { - getLog().file = new File(entry.getBasedir(), skipFile); + getLog().setFile( new File(entry.getBasedir(), skipFile)); getLog().infoFile("skip", null); } } @@ -265,7 +259,7 @@ for (ParserEvent event : events) { event.eventChangeFile(file); } - getLog().file = file; + getLog().setFile(file); touchFile = false; int size = result.size(); @@ -314,85 +308,6 @@ } - 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)); - } - - public void infoAction(String action, String content) { - print(2, "INFO", action, (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) { 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 2009-02-14 11:27:26 UTC (rev 1340) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJava.java 2009-02-14 12:54:21 UTC (rev 1341) @@ -51,7 +51,7 @@ /** * default src for an entry. * - * @parameter expression="${i18n.defaultBasedir}" default-value="${basedir}/src/java" + * @parameter expression="${i18n.defaultBasedir}" default-value="${basedir}/src/main/java" */ protected File defaultBasedir; Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserValidation.java =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserValidation.java 2009-02-14 11:27:26 UTC (rev 1340) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserValidation.java 2009-02-14 12:54:21 UTC (rev 1341) @@ -60,7 +60,7 @@ /** * default src for an entry. * - * @parameter expression="${i18n.defaultBasedir}" default-value="${basedir}/src/resources" + * @parameter expression="${i18n.defaultBasedir}" default-value="${basedir}/src/main/resources" * @required */ protected File defaultBasedir; 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 2009-02-14 11:27:26 UTC (rev 1340) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserXml.java 2009-02-14 12:54:21 UTC (rev 1341) @@ -49,7 +49,7 @@ /** * default src for an entry. * - * @parameter expression="${i18n.defaultBasedir}" default-value="${basedir}/src/uimodel" + * @parameter expression="${i18n.defaultBasedir}" default-value="${basedir}/src/main/uimodel" * @required */ protected File defaultBasedir;