branch feature/integrity created (now 9821f61)
This is an automated email from the git hooks/post-receive script. New change to branch feature/integrity in repository i18n. See https://gitlab.nuiton.org/nuiton/i18n.git at 9821f61 POC This branch includes the following new commits: new a49991d Fix typos in javadoc new 1916ebb Introduce BundleValidation object to gather validation results new 9821f61 POC The 3 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 9821f619667b6bb470d9419831658e520d06c4bd Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Apr 8 18:04:04 2016 +0200 POC 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 commit a49991df366d72e76ffbda764bf4341dbfae4d6a Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Apr 8 14:15:37 2016 +0200 Fix typos in javadoc -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
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 a49991df366d72e76ffbda764bf4341dbfae4d6a Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Apr 8 14:15:37 2016 +0200 Fix typos in javadoc --- .../src/main/java/org/nuiton/i18n/plugin/bundle/BundleMojo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 ad80e6a..1e99715 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 @@ -66,11 +66,11 @@ import java.util.SortedSet; /** * Generate an aggregate i18n bundle for all dependencies of the project. * - * The main idea is to have a final unique i18n bundle for a application to + * The main idea is to have a final unique i18n bundle for an application to * launch, this really improve i18n loading time to have a unique named bundle, * no need to seek in all dependencies... * - * Moreover, this permits also to deal with order of i18n keys, more precisly, + * Moreover, this permits also to deal with order of i18n keys, more precisely, * we want to use the higher level i18n key for an application. If the i18n * key is present on a library, we want to be able to override it in * application (or user wants it:)). -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
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>.
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 9821f619667b6bb470d9419831658e520d06c4bd Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Apr 8 18:04:04 2016 +0200 POC --- .../resources/i18n/evo-integrity_en_GB.properties | 1 + .../resources/i18n/evo-integrity_fr_FR.properties | 1 + i18n-maven-plugin/src/it/evo-integrity/src/pom.xml | 94 ++++++++++++++++++++++ .../i18n/plugin/CheckBundlesIntegrityMojo.java | 90 +++++++++++++++++++++ 4 files changed, 186 insertions(+) diff --git a/i18n-maven-plugin/src/it/evo-integrity/src/main/resources/i18n/evo-integrity_en_GB.properties b/i18n-maven-plugin/src/it/evo-integrity/src/main/resources/i18n/evo-integrity_en_GB.properties new file mode 100644 index 0000000..9f75c23 --- /dev/null +++ b/i18n-maven-plugin/src/it/evo-integrity/src/main/resources/i18n/evo-integrity_en_GB.properties @@ -0,0 +1 @@ +app.property=My application {0} \ No newline at end of file diff --git a/i18n-maven-plugin/src/it/evo-integrity/src/main/resources/i18n/evo-integrity_fr_FR.properties b/i18n-maven-plugin/src/it/evo-integrity/src/main/resources/i18n/evo-integrity_fr_FR.properties new file mode 100644 index 0000000..6b86078 --- /dev/null +++ b/i18n-maven-plugin/src/it/evo-integrity/src/main/resources/i18n/evo-integrity_fr_FR.properties @@ -0,0 +1 @@ +app.property=Mon application {0} \ No newline at end of file diff --git a/i18n-maven-plugin/src/it/evo-integrity/src/pom.xml b/i18n-maven-plugin/src/it/evo-integrity/src/pom.xml new file mode 100644 index 0000000..44c3045 --- /dev/null +++ b/i18n-maven-plugin/src/it/evo-integrity/src/pom.xml @@ -0,0 +1,94 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + I18n :: Maven Plugin + + $Id$ + $HeadURL$ + %% + Copyright (C) 2007 - 2010 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>. + #L% + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <!-- ************************************************************* --> + <!-- *** POM Relationships *************************************** --> + <!-- ************************************************************* --> + + <parent> + <groupId>org.nuiton</groupId> + <artifactId>i18n</artifactId> + <version>@pom.version@</version> + </parent> + + <groupId>org.nuiton.i18n</groupId> + <artifactId>evo-integrity</artifactId> + + <name>I18n Test :: check bundle integrity plugin</name> + + <dependencies> + + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>nuiton-i18n</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <scope>test</scope> + </dependency> + + </dependencies> + + <build> + + <plugins> + + <plugin> + <groupId>org.nuiton.i18n</groupId> + <artifactId>i18n-maven-plugin</artifactId> + <version>@pom.version@</version> + <configuration> + <verbose>true</verbose> + </configuration> + <executions> + <execution> + <id>check-integrity</id> + <goals> + <goal>check-integrity</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project> + + diff --git a/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/CheckBundlesIntegrityMojo.java b/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/CheckBundlesIntegrityMojo.java new file mode 100644 index 0000000..8abcb6c --- /dev/null +++ b/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/CheckBundlesIntegrityMojo.java @@ -0,0 +1,90 @@ +/* + * #%L + * I18n :: Maven Plugin + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2007 - 2010 CodeLutin, Tony Chemit + * %% + * 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>. + * #L% + */ + +package org.nuiton.i18n.plugin; + +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.nuiton.io.SortedProperties; + +import java.io.File; +import java.util.Arrays; +import java.util.Locale; + +/** + * Check bundles integrity. That all keys have a value in all bundles. + * + * @since 3.5 + */ +@Mojo(name = "check-bundles-integrity", defaultPhase = LifecyclePhase.PREPARE_PACKAGE) +public class CheckBundlesIntegrityMojo extends AbstractI18nGenerateMojo { + + /** Directory where to find project i18n files. */ + @Parameter(property = "i18n.src", defaultValue = "${basedir}/src/main/resources/i18n", required = true) + protected File src; + + /** + * A flag to check that bundles are complete (no missing i18n translations). + * + * @since 1.0.0 + */ + @Parameter(property = "i18n.checkBundle", defaultValue = "true", required = true) + protected boolean checkBundle; + + + + + /** + * A flag to show missing i18n translation. + * + * <b>Note :</b> Need the {@link #checkBundle} to be activated). + * + * @since 1.0.0 + */ + @Parameter(property = "i18n.showEmpty", defaultValue = "false", required = true) + protected boolean showEmpty; + + + @Override + protected void doAction() throws Exception { + if (!silent) { + getLog().info("config - src basedir : " + src.getAbsolutePath()); + getLog().info("config - locales : " + Arrays.toString(locales)); + } + for (Locale locale : locales) { + + File bundleSrc = I18nUtil.getI18nFile(src, artifactId, locale, false); + + SortedProperties propertiesSrc = new SortedProperties(encoding); + + if (bundleSrc.exists()) { + propertiesSrc.load(bundleSrc); + } + + checkBundle(locale, propertiesSrc, showEmpty, null); + } + } +} -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm