This is an automated email from the git hooks/post-receive script. New commit to branch feature/integrity in repository i18n. See https://gitlab.nuiton.org/nuiton/i18n.git commit 1916ebb5e164c8f4d9b7bc8bf0d8496b610fc803 Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Apr 8 15:44:35 2016 +0200 Introduce BundleValidation object to gather validation results --- .../org/nuiton/i18n/plugin/AbstractI18nMojo.java | 7 +++--- .../org/nuiton/i18n/plugin/bundle/BundleMojo.java | 22 +++++++++++-------- .../i18n/plugin/bundle/BundleValidation.java | 25 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/AbstractI18nMojo.java b/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/AbstractI18nMojo.java index 8934acb..11663c3 100644 --- a/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/AbstractI18nMojo.java +++ b/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/AbstractI18nMojo.java @@ -29,6 +29,7 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.nuiton.i18n.I18nUtil; +import org.nuiton.i18n.plugin.bundle.BundleValidation; import org.nuiton.plugin.AbstractPlugin; import org.nuiton.plugin.PluginHelper; import org.nuiton.plugin.PluginWithEncoding; @@ -121,13 +122,13 @@ public abstract class AbstractI18nMojo extends AbstractPlugin implements PluginW protected void checkBundle(Locale locale, Properties propertiesOut, boolean showEmpty, - Map<Locale, SortedSet<String>> unsafeHolder) { + BundleValidation bundleValidation) { // on verifie qu'il n'y a pas de traduction vide SortedSet<String> emptyEntries = PluginHelper.getEmptyKeys(propertiesOut); if (!emptyEntries.isEmpty()) { - if (unsafeHolder != null) { - + if (bundleValidation != null) { + Map<Locale, SortedSet<String>> unsafeHolder = bundleValidation.getKeysMissingValues(); // push empties i18n keys in the holder SortedSet<String> empties = unsafeHolder.get(locale); if (empties == null) { diff --git a/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/BundleMojo.java b/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/BundleMojo.java index 1e99715..cf6e681 100644 --- a/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/BundleMojo.java +++ b/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/BundleMojo.java @@ -52,7 +52,6 @@ import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -61,7 +60,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Properties; import java.util.Set; -import java.util.SortedSet; /** * Generate an aggregate i18n bundle for all dependencies of the project. @@ -185,8 +183,14 @@ public class BundleMojo extends AbstractI18nBundleMojo { @Parameter(property = "i18n.failsIfWarning", defaultValue = "false") protected boolean failsIfWarning; - /** to keep all none translated i18n keys by locale. */ - protected Map<Locale, SortedSet<String>> unsafeMapping; + /** + * Contains validation result after {@link #checkBundle(Locale, Properties, boolean, BundleValidation)}. + * + * May be null if validation is disabled. + * + * @since 3.5 + */ + protected BundleValidation bundleValidation; /** * The definitive directory where to generate the bundles (includes the @@ -271,9 +275,9 @@ public class BundleMojo extends AbstractI18nBundleMojo { // check bundle if wants to fail on unsafe bundles checkBundle = true; - unsafeMapping = new HashMap<Locale, SortedSet<String>>(); + bundleValidation = new BundleValidation(); } else { - unsafeMapping = null; + bundleValidation = null; } // get the definitive folder where to generate bundles (including @@ -435,7 +439,7 @@ public class BundleMojo extends AbstractI18nBundleMojo { " (detected sentences : " + propertiesOut.size() + ")"); } if (checkBundle) { - checkBundle(locale, propertiesOut, showEmpty, unsafeMapping); + checkBundle(locale, propertiesOut, showEmpty, bundleValidation); } } @@ -588,11 +592,11 @@ public class BundleMojo extends AbstractI18nBundleMojo { return; } - if (unsafeMapping != null && !unsafeMapping.isEmpty()) { + if (bundleValidation != null && bundleValidation.isFail()) { // there is at least one not complete bundle, faisl the build throw new MojoFailureException( - "Bundles for locale(s) " + unsafeMapping.keySet() + + "Bundles for locale(s) " + bundleValidation.getKeysMissingValues().keySet() + " are not complete. Use the -Di18n.showEmpty to see " + "missing translations."); } diff --git a/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/BundleValidation.java b/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/BundleValidation.java new file mode 100644 index 0000000..d168358 --- /dev/null +++ b/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/BundleValidation.java @@ -0,0 +1,25 @@ +package org.nuiton.i18n.plugin.bundle; + +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.SortedSet; + +/** + * The validation result of a validation check over multiple bundles. + * + * @since 3.5 + */ +public class BundleValidation { + + /** to keep all none translated i18n keys by locale. */ + protected Map<Locale, SortedSet<String>> keysMissingValues = new HashMap<Locale, SortedSet<String>>(); + + public Map<Locale, SortedSet<String>> getKeysMissingValues() { + return keysMissingValues; + } + + public boolean isFail() { + return ! keysMissingValues.isEmpty(); + } +} -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.