branch feature/integrity updated (9821f61 -> b5cec22)
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 discards 9821f61 POC new b5cec22 POC This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (9821f61) \ N -- N -- N refs/heads/feature/integrity (b5cec22) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omits" are not gone; other references still refer to them. Any revisions marked "discards" are gone forever. The 1 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 b5cec22873fffcd35bb9b34fc79d91ef571e60d9 Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Apr 8 18:04:04 2016 +0200 POC Summary of changes: .../withNewKeys => evo-integrity/src}/LICENSE.txt | 0 .../src/it/evo-integrity/src/README.md | 1 + i18n-maven-plugin/src/it/evo-integrity/src/pom.xml | 4 +- .../i18n/plugin/CheckBundlesIntegrityMojo.java | 71 ++++++++++++++++++---- .../org/nuiton/i18n/plugin/bundle/BundleMojo.java | 2 +- .../i18n/plugin/bundle/BundleValidation.java | 62 ++++++++++++++++++- 6 files changed, 123 insertions(+), 17 deletions(-) copy i18n-maven-plugin/src/it/{parsers/withNewKeys => evo-integrity/src}/LICENSE.txt (100%) create mode 100644 i18n-maven-plugin/src/it/evo-integrity/src/README.md -- 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 b5cec22873fffcd35bb9b34fc79d91ef571e60d9 Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Apr 8 18:04:04 2016 +0200 POC --- .../src/it/evo-integrity/src/LICENSE.txt | 166 +++++++++++++++++++++ .../src/it/evo-integrity/src/README.md | 1 + .../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 | 137 +++++++++++++++++ .../org/nuiton/i18n/plugin/bundle/BundleMojo.java | 2 +- .../i18n/plugin/bundle/BundleValidation.java | 62 +++++++- 8 files changed, 461 insertions(+), 3 deletions(-) diff --git a/i18n-maven-plugin/src/it/evo-integrity/src/LICENSE.txt b/i18n-maven-plugin/src/it/evo-integrity/src/LICENSE.txt new file mode 100644 index 0000000..3f7b8b1 --- /dev/null +++ b/i18n-maven-plugin/src/it/evo-integrity/src/LICENSE.txt @@ -0,0 +1,166 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + diff --git a/i18n-maven-plugin/src/it/evo-integrity/src/README.md b/i18n-maven-plugin/src/it/evo-integrity/src/README.md new file mode 100644 index 0000000..592f930 --- /dev/null +++ b/i18n-maven-plugin/src/it/evo-integrity/src/README.md @@ -0,0 +1 @@ +This is a test of check-bundles-integrity goal. \ No newline at end of file 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..cfcad99 --- /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-bundles-integrity</id> + <goals> + <goal>check-bundles-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..6337d1b --- /dev/null +++ b/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/CheckBundlesIntegrityMojo.java @@ -0,0 +1,137 @@ +/* + * #%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 com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; +import com.google.common.collect.SortedSetMultimap; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.nuiton.i18n.plugin.bundle.BundleValidation; +import org.nuiton.io.SortedProperties; + +import java.io.File; +import java.util.Arrays; +import java.util.Collection; +import java.util.Locale; +import java.util.Map; + +/** + * 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 show empty 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; + + /** + * A flag to show missing i18n translation. + * + * @since 3.5 + */ + @Parameter(property = "i18n.showMissing", defaultValue = "false", required = true) + protected boolean showMissing; + + /** + * A flag to make the build fails if there is some warnings while generating + * bundle, says when it misses some translations. + * + * <b>Note :</b> This parameter should be used in a release profile to + * ensure bundles are complete. + * + * @since 2.0 + */ + @Parameter(property = "i18n.failsIfWarning", defaultValue = "false") + protected boolean failsIfWarning; + + @Override + protected void doAction() throws Exception { + if (!silent) { + getLog().info("config - src basedir : " + src.getAbsolutePath()); + getLog().info("config - locales : " + Arrays.toString(locales)); + } + + BundleValidation bundleValidation = new BundleValidation(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, bundleValidation); + + ImmutableSet<String> keys = Maps.fromProperties(propertiesSrc).keySet(); + bundleValidation.getKeysPerLocale().putAll(locale, keys); + } + + SortedSetMultimap<Locale, String> missingKeysPerLocale = bundleValidation.getMissingKeysPerLocale(); + if (missingKeysPerLocale.isEmpty()) { + if (!silent) { + getLog().info("all bundles are consistent"); + } + } else { + if (showMissing) { + for (Map.Entry<Locale, String> entry : missingKeysPerLocale.entries()) { + Locale locale = entry.getKey(); + String missingKey = entry.getValue(); + getLog().warn("bundle " + locale + " misses key " + missingKey); + } + } else { + for (Map.Entry<Locale, Collection<String>> entry : missingKeysPerLocale.asMap().entrySet()) { + Locale locale = entry.getKey(); + int numberOfMissingKeys = entry.getValue().size(); + getLog().warn("bundle " + locale + " misses " + numberOfMissingKeys + " keys! (use -Di18n.showMissing to see these entries)"); + } + } + } + + if (failsIfWarning && bundleValidation.isFail()) { + // there is at least one not complete bundle, fail the build + throw new MojoFailureException("Bundles validation failed, see warning above for details about how to fix"); + } + } +} 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 cf6e681..7a4e5a8 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 @@ -275,7 +275,7 @@ public class BundleMojo extends AbstractI18nBundleMojo { // check bundle if wants to fail on unsafe bundles checkBundle = true; - bundleValidation = new BundleValidation(); + bundleValidation = new BundleValidation(locales); } else { bundleValidation = null; } 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 index d168358..24eff5c 100644 --- 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 @@ -1,8 +1,17 @@ package org.nuiton.i18n.plugin.bundle; +import com.google.common.collect.ImmutableSortedSet; +import com.google.common.collect.Ordering; +import com.google.common.collect.Sets; +import com.google.common.collect.SortedSetMultimap; +import com.google.common.collect.TreeMultimap; + +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; import java.util.SortedSet; /** @@ -12,14 +21,63 @@ import java.util.SortedSet; */ public class BundleValidation { + protected ImmutableSortedSet<Locale> locales; + /** to keep all none translated i18n keys by locale. */ - protected Map<Locale, SortedSet<String>> keysMissingValues = new HashMap<Locale, SortedSet<String>>(); + protected Map<Locale, SortedSet<String>> keysMissingValues = new HashMap<>(); + + /** + * Store all keys declared for each {@link Locale}. + */ + protected SortedSetMultimap<Locale, String> keysPerLocale; + + /** + * Sort locales according to the order used in the POM file. + */ + protected Ordering<Locale> localeOrdering; + + public BundleValidation(Locale[] locales) { + List<Locale> localesList = Arrays.asList(locales); + localeOrdering = Ordering.explicit(localesList); + this.locales = ImmutableSortedSet.orderedBy(localeOrdering).addAll(localesList).build(); + this.keysPerLocale = newEmptyMapForBundles(); + } public Map<Locale, SortedSet<String>> getKeysMissingValues() { return keysMissingValues; } + public SortedSetMultimap<Locale, String> getKeysPerLocale() { + return keysPerLocale; + } + + public SortedSetMultimap<Locale, String> getMissingKeysPerLocale() { + ImmutableSortedSet<String> allKeysFromAllBundles = ImmutableSortedSet.copyOf(keysPerLocale.values()); + SortedSetMultimap<Locale, String> missingKeysPerLocale = newEmptyMapForBundles(); + for (Locale locale : locales) { + Set<String> keysInBundle = keysPerLocale.get(locale); + Set<String> missingKeysInBundle = Sets.symmetricDifference(allKeysFromAllBundles, keysInBundle); + missingKeysPerLocale.putAll(locale, missingKeysInBundle); + } + return missingKeysPerLocale; + } + + public boolean isAnyKeyMissingInBundle() { + return ! getMissingKeysPerLocale().isEmpty(); + } + + public boolean isAnyKeyMissingValue() { + return ! getKeysMissingValues().isEmpty(); + } + public boolean isFail() { - return ! keysMissingValues.isEmpty(); + return isAnyKeyMissingValue() || isAnyKeyMissingInBundle(); + } + + /** + * Factory method for a method suitable to deterministically store bundles. + */ + protected SortedSetMultimap<Locale, String> newEmptyMapForBundles() { + return TreeMultimap.create(localeOrdering, Ordering.natural()); } } -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm