Author: tchemit Date: 2010-11-11 12:16:40 +0100 (Thu, 11 Nov 2010) New Revision: 1797 Url: http://nuiton.org/repositories/revision/i18n/1797 Log: Evolution #754: Add a flag failsIfWarning on bundle mojos Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/AbstractI18nMojo.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/BundleMojo.java Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/AbstractI18nMojo.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/AbstractI18nMojo.java 2010-11-11 11:00:37 UTC (rev 1796) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/AbstractI18nMojo.java 2010-11-11 11:16:40 UTC (rev 1797) @@ -223,11 +223,14 @@ return file; } - protected void checkBundle(Locale locale, Properties propertiesOut, + protected boolean checkBundle(Locale locale, Properties propertiesOut, boolean showEmpty) { + + boolean safe = true; // on verifie qu'il n'y a pas de traduction vide SortedSet<String> emptyEntries = PluginHelper.getEmptyKeys(propertiesOut); if (!emptyEntries.isEmpty()) { + safe=false; StringBuilder buffer = new StringBuilder(); int size = emptyEntries.size(); buffer.append("bundle "); @@ -258,6 +261,7 @@ " entries)."); } } + return safe; } Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/BundleMojo.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/BundleMojo.java 2010-11-11 11:00:37 UTC (rev 1796) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/BundleMojo.java 2010-11-11 11:16:40 UTC (rev 1797) @@ -25,6 +25,7 @@ package org.nuiton.i18n.plugin.bundle; +import org.apache.maven.plugin.MojoFailureException; import org.nuiton.i18n.bundle.I18nBundleEntry; import org.nuiton.i18n.bundle.I18nBundleUtil; import org.nuiton.i18n.init.DefaultI18nInitializer; @@ -133,6 +134,18 @@ */ protected boolean generateDefinitionFile; + /** + * A flag to make the build fails if there is some warnings while generating + * bundle, says when it misses some translations. + * <p/> + * <b>Note :</b> This parameter should be used in a release profile to + * ensure bundles are complete. + * + * @parameter expression="${i18n.failsIfWarning}" default-value="false" + * @since 2.0 + */ + protected boolean failsIfWarning; + @Override public void init() throws Exception { super.init(); @@ -167,6 +180,7 @@ Map<Locale, String> bundleDico = new LinkedHashMap<Locale, String>(locales.length); + List<Locale> unsafeLocales = new ArrayList<Locale>(); for (Locale locale : locales) { long t0 = System.nanoTime(); @@ -227,13 +241,23 @@ PluginHelper.convertTime(t0, System.nanoTime()) + " (detected sentences : " + propertiesOut.size() + ")"); } - if (checkBundle) { - checkBundle(locale, propertiesOut, showEmpty); + if (checkBundle || failsIfWarning) { + boolean localSafe = + checkBundle(locale, propertiesOut, showEmpty); + if (!localSafe) { + unsafeLocales.add(locale); + } } } + if (failsIfWarning && !unsafeLocales.isEmpty()) { + + // there is at least one not complete bundle, faisl the build + throw new MojoFailureException("Bundles for locale(s) " + unsafeLocales + " are not complete"); + } + if (generateDefinitionFile) { - + // ecriture du ficher des definitions i18n (permet de faire une // recherche exacte sur un fichier puis d'en deduire les bundles a // charger