org.nuiton.i18n.plugin.bundle.AbstractI18nBundleMojo Maven / Gradle / Ivy
/*
* *##%
* I18n :: Maven Plugin
* 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
* .
* ##%*
*/
package org.nuiton.i18n.plugin.bundle;
import org.nuiton.i18n.plugin.AbstractI18nMojo;
import org.nuiton.plugin.PluginHelper;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/**
* Created: 26 déc. 2009
*
* @author tchemit
* @version $Revision: 1719 $
*
* Mise a jour: $Date: 2010-03-15 23:16:25 +0100 (lun., 15 mars 2010) $
* par : $Author: tchemit $
*/
public abstract class AbstractI18nBundleMojo extends AbstractI18nMojo {
/**
* Repertoire ou generer les bundles.
*
* @parameter expression="${i18n.collectOutputDir}" default-value="${basedir}/target/i18n"
* @required
* @since 1.0.2
*/
protected File collectOutputDir;
/**
* Nom de base des fichiers qui contient les localisations des bundles.
*
* @parameter expression="${i18n.collectOutputName}" default-value="collect-${project.artifactId}-i18n"
* @required
* @since 1.0.2
*/
protected String collectOutputName;
/**
* Pour obtenir les urls des fichiers i18n d'un projet (avec recherche dans
* ses dépendances).
*
* Note: L'ordre des urls reflète l'ordre des dépendances.
*
* @param locale la locale a traiter
* @return les urls des bundles i18n detectees pour le projet.
* @throws Exception pour tout problème
*/
protected abstract URL[] getCollectI18nResources(Locale locale)
throws Exception;
/**
* Pour obtenir le fichier contenant les localisation des bundles i18n du
* projet pour une {@code locale} donnée.
*
* @param locale la locale
* @param create un drapeau pour forcer la création du fichier s'il n'existe
* pas
* @return le fichier qui contient les urls des bundles i18n pour la locale
* donnée.
* @throws IOException pour tout pb
*/
protected File getCollectOutputFile(Locale locale, boolean create)
throws IOException {
File bundleOut = getI18nFile(collectOutputDir, collectOutputName,
locale, create);
return bundleOut;
}
/**
* TODO Move this in PluginHelper.
*
* @param src the source file to read
* @return the url instanciated from lines of the source file.
* @throws IOException if any pb while reading file
*/
public static URL[] getLinesAsURL(File src) throws IOException {
List result = new ArrayList();
for (String line : PluginHelper.getLines(src)) {
if (!line.isEmpty()) {
result.add(new URL(line));
}
}
return result.toArray(new URL[result.size()]);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy