
org.nuiton.i18n.plugin.bundle.CheckI18nArtifactsMojo Maven / Gradle / Ivy
package org.nuiton.i18n.plugin.bundle;
/*-
* #%L
* I18n :: Maven Plugin
* %%
* Copyright (C) 2007 - 2017 Code Lutin, Ultreia.io
* %%
* 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
* .
* #L%
*/
import com.google.common.base.Joiner;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.stream.Collectors;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Execute;
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.bundle.I18nBundleUtil;
import org.nuiton.plugin.PluginHelper;
/**
* Performs some checks on i18n artifacts (remember a i18n artifact is just a maven module using i18n API (it can be
* your module or any dependency)).
*
* - Check convergence : means if a key is present in more than one bundle, then it must have exactly the same translation
* - Check integrity : means that a key should be present for all locales
*
* Created by tchemit on 12/07/17.
*
* @author Tony Chemit - [email protected]
* @since 4.0
*/
@Mojo(name = "check-i18n-artifacts", defaultPhase = LifecyclePhase.INITIALIZE)
@Execute(goal = "collect-i18n-artifacts")
public class CheckI18nArtifactsMojo extends AbstractI18nBundleMojo {
/**
* To check if i18n artifacts converge.
*/
@Parameter(property = "i18n.checkConvergence", defaultValue = "true")
private boolean checkConvergence;
/**
* To check i18n artifacts integrity.
*/
@Parameter(property = "i18n.checkIntegrity", defaultValue = "true")
private boolean checkIntegrity;
@Override
public void init() throws Exception {
super.init();
createDirectoryIfNecessary(collectDirectory);
}
@Override
protected void doAction() throws Exception {
Multimap allKeysByLocale = HashMultimap.create();
Map bundlesCount = new LinkedHashMap<>();
for (Locale locale : locales) {
Map keys = new TreeMap<>();
URL[] urls = getCollectI18nResources(locale);
bundlesCount.put(locale, urls.length);
for (URL url : urls) {
Properties p = new Properties();
try (Reader reader = new InputStreamReader(url.openStream(), charset)) {
p.load(reader);
}
for (Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy