Author: tchemit Date: 2009-02-23 16:47:47 +0000 (Mon, 23 Feb 2009) New Revision: 1400 Modified: maven-i18n-plugin/trunk/changelog.txt 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 Log: will skip get and gen goal if no getters were registred while parsing goals Modified: maven-i18n-plugin/trunk/changelog.txt =================================================================== --- maven-i18n-plugin/trunk/changelog.txt 2009-02-23 13:08:50 UTC (rev 1399) +++ maven-i18n-plugin/trunk/changelog.txt 2009-02-23 16:47:47 UTC (rev 1400) @@ -1,3 +1,5 @@ +0.10 ??? 2009???? + * 20090223 [chemit] will skip get and gen goal if no getters were registred while parsing goals 0.9 chemit 20090218 * 20090217 [chemit] use project.build.sourceEncoding instead of maven.compile.encoding as default encoding * 20090214 [chemit] add safeMode, showTouchedFiles properties in parser mojo (none safeMode will improve performance) 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-23 13:08:50 UTC (rev 1399) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java 2009-02-23 16:47:47 UTC (rev 1400) @@ -35,6 +35,11 @@ public abstract class AbstractI18nPlugin extends AbstractMojo { /** + * Le nombre de getters détectés pendant le cycle de vie du build. + */ + private static int NB_GETTER_FILES = 0; + + /** * Répertoire de stockage des fichiers i18n pour la recuperation des fichiers * de traduction entre librairie */ @@ -43,7 +48,6 @@ /** 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. * @@ -124,6 +128,9 @@ /** * ne conserve que les clef scannees (et donc traite tous les fichiers) * + * <p/> + * Note : par default, on ne l'active car rescanne tous les fichiers. + *s * @parameter expression="${i18n.strictMode}" default-value="false" */ protected boolean strictMode; @@ -131,6 +138,8 @@ /** Liste des évènements */ protected List<ParserEvent> events = new ArrayList<ParserEvent>(); + /**logger verbeux */ + protected I18nLogger verboseLog; /** * Ajoute un évènement @@ -150,22 +159,17 @@ this.events.remove(parserEvent); } - @Override - public I18nLogger getLog() { - return (I18nLogger) super.getLog(); - } - public void init() { - // set logger - setLog(new I18nLogger(this)); + verboseLog = new I18nLogger(this); + if (verbose) { - getLog().infoAction("config", "verbose mode is on"); + getLog().info("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)); + getLog().info("config - use default bundles " + Arrays.toString(DEFAULT_BUNDLES)); } bundles = DEFAULT_BUNDLES; } @@ -174,4 +178,29 @@ public String getArtifactId() { return artifactId; } + + /** + * + * @return <code>true</code> si des getters ont etes enregistres pendant + * le cycle de vie, <code>false</code> sinon. + */ + protected boolean needGeneration(){ + boolean needGeneration = NB_GETTER_FILES > 0; + return needGeneration; + } + + /** + * Prend en compte qu'un getter a été détecté. + * + * Cela veut dire qu'un goal de parser a détecté des clefs. Il + * faudra donc activer les goal get et gen. + */ + protected void addGetter() { + NB_GETTER_FILES++; + } + + protected I18nLogger getVerboseLog() { + return verboseLog; + } + } 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-23 13:08:50 UTC (rev 1399) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Generate.java 2009-02-23 16:47:47 UTC (rev 1400) @@ -41,10 +41,16 @@ * (non-Javadoc) * @see org.apache.maven.plugin.AbstractMojo#execute() */ + @Override public void execute() throws MojoExecutionException, MojoFailureException { init(); - + + if (!needGeneration()) { + getLog().info("Nothing to generate - all files are up to date."); + return; + } + for (String bundle : bundles) { try { // Merge @@ -89,14 +95,14 @@ FileUtil.copy(bundleSrc, PluginHelper.getI18nFileBackup(src, artifactId, bundle)); } - getLog().infoAction("merge", bundleSrc.getAbsolutePath()); + getLog().info("merge bundle " + bundleSrc.getAbsolutePath()); } if (genSrc) { // Copie des fichiers dans les sources FileUtil.copy(bundleOut, bundleSrc); if (verbose) { - getLog().infoAction("copy", bundleSrc.getAbsolutePath()); + getVerboseLog().infoAction("copy", bundleSrc.getAbsolutePath()); } } 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-23 13:08:50 UTC (rev 1399) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Getter.java 2009-02-23 16:47:47 UTC (rev 1400) @@ -41,10 +41,18 @@ * (non-Javadoc) * @see org.apache.maven.plugin.AbstractMojo#execute() */ + @Override public void execute() throws MojoExecutionException, MojoFailureException { init(); + if (!needGeneration()) { + if (verbose) { + getLog().info("Nothing to generate - all files are up to date."); + } + return; + } + try { File bundleGetters = new File(out.getAbsolutePath() + File.separatorChar + artifactId + ".properties"); bundleGetters.createNewFile(); @@ -62,7 +70,7 @@ if (genSrc) { bundleGetter.delete(); } - getLog().infoAction("create", bundleGetter.getAbsolutePath()); + getLog().info("create bundle " + bundleGetter.getAbsolutePath()); } // Création des bundles @@ -70,7 +78,7 @@ File bundleOut = PluginHelper.getI18nFile(out, artifactId, bundle, false); FileUtil.copy(bundleGetters, bundleOut); if (verbose) { - getLog().infoAction("generate", bundleOut.getAbsolutePath()); + getVerboseLog().infoAction("generate", bundleOut.getAbsolutePath()); } } @@ -86,8 +94,7 @@ * * @param in le fichier entrant * @param out le fichier sortant - * @throws FileNotFoundException si fichier non trouvé - * @throws IOException si problème pendant la sauvegarde + * @throws IOException si problème pendant la sauvegarde ou fichier non trouvé. */ protected void concactProperties(File in, File out) throws IOException { I18nProperties propertiesIn = new I18nProperties(encoding).load(in); 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-23 13:08:50 UTC (rev 1399) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java 2009-02-23 16:47:47 UTC (rev 1400) @@ -20,10 +20,10 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.codelutin.i18n.plugin.AbstractI18nPlugin; +import org.codelutin.i18n.plugin.I18nLogger; 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; @@ -127,6 +127,7 @@ * (non-Javadoc) * @see org.apache.maven.plugin.AbstractMojo#execute() */ + @Override public void execute() throws MojoExecutionException, MojoFailureException { init(); @@ -136,10 +137,10 @@ } if (safeMode) { - getLog().infoAction("config","safeMode is on (could be slower)."); + getLog().info("config - safeMode is on (could be slower)."); } if (strictMode) { - getLog().infoAction("config","strictMode is on (all files will be parsed)."); + getLog().info("config - strictMode is on (all files will be parsed)."); } try { @@ -164,9 +165,10 @@ int i = treadedFiles.size(); if (fileTreated == 0) { - getLog().info(getLog().getLogEntry("parsing is done. [no files treated]", 0, 0, t0)); + getLog().info("Nothing to generate - all files are up to date."); } else { - getLog().info(getLog().getLogEntry("parsing is done. [treated file(s) : " + i + '/' + fileTreated + "]", fileTreated, 0, t0)); + getLog().info(getVerboseLog().getLogEntry("parsing is done. [treated file(s) : " + i + '/' + fileTreated + "]", fileTreated, 0, t0)); + addGetter(); } } catch (Exception e) { @@ -181,20 +183,22 @@ * * @throws IOException if any io pb */ + @Override public void parse() throws IOException { if (treateDefaultEntry) { addDefaultEntry(); } long t00 = System.nanoTime(); for (MySourceEntry entry : this.entries) { + I18nLogger vLog = getVerboseLog(); - getLog().setEntry(entry); + vLog.setEntry(entry); boolean skip = entry.init(this); if (skip) { if (verbose) { - getLog().infoEntry("skip", entry.getSkipMessage()); + getLog().info("skip - " + entry.getSkipMessage()); } continue; } @@ -202,7 +206,7 @@ long t000 = System.nanoTime(); int nbFiles = entry.getFiles().length; if (verbose) { - getLog().infoEntry("start", getLog().getLogEntry("[incoming file(s) : " + entry.getFoudFiles() + "]", 0, 0, 0)); + vLog.infoEntry("start", vLog.getLogEntry("[incoming file(s) : " + entry.getFoudFiles() + "]", 0, 0, 0)); } // launch parser for found files @@ -211,13 +215,13 @@ if (verbose) { // log skipped files for (String skipFile : entry.getSkipFiles()) { - getLog().setFile( new File(entry.getBasedir(), skipFile)); - getLog().infoFile("skip", null); + vLog.setFile( new File(entry.getBasedir(), skipFile)); + vLog.infoFile("skip", null); } } fileTreated += nbFiles; if (verbose) { - getLog().infoEntry("end", getLog().getLogEntry("[treated file(s) : " + nbFiles + "]", nbFiles, t000, t00)); + vLog.infoEntry("end", vLog.getLogEntry("[treated file(s) : " + nbFiles + "]", nbFiles, t000, t00)); } t00 = System.nanoTime(); } @@ -259,12 +263,13 @@ for (ParserEvent event : events) { event.eventChangeFile(file); } - getLog().setFile(file); + I18nLogger vLog = getVerboseLog(); + vLog.setFile(file); touchFile = false; int size = result.size(); if (verbose) { - getLog().infoFile("parse", null); + vLog.infoFile("parse", null); } parseFile(file); @@ -279,11 +284,11 @@ } if (touchFile) { if (showTouchedFiles) { - getLog().infoFile("touch", null); + vLog.infoFile("touch", null); } treadedFiles.add(file); if (getLog().isDebugEnabled()) { - getLog().debug(getLog().getLogEntry(fileName, i, t000, t00)); + vLog.debug(vLog.getLogEntry(fileName, i, t000, t00)); } } for (ParserEvent event : events) {