All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nuiton.i18n.plugin.GetterMojo Maven / Gradle / Ivy

/*
 * #%L
 * I18n :: Maven Plugin
 * 
 * $Id: GetterMojo.java 1961 2012-07-09 13:12:35Z tchemit $
 * $HeadURL: http://svn.nuiton.org/svn/i18n/tags/i18n-2.5.2/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/GetterMojo.java $
 * %%
 * 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
 * .
 * #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.codehaus.plexus.util.DirectoryScanner;
import org.nuiton.io.SortedProperties;
import org.nuiton.plugin.PluginHelper;

import java.io.File;
import java.util.Arrays;
import java.util.Locale;

/**
 * Recupere les différents fichiers des parsers en un fichier de proprietes.
 *
 * @author julien
 */
@Mojo(name = "get", defaultPhase = LifecyclePhase.GENERATE_RESOURCES)
public class GetterMojo extends AbstractI18nMojo {

    /**
     * To keep generated getter files.
     * 

* Note: By default, this property is not active. */ @Parameter(property = "i18n.keepGetters", defaultValue = "false") protected boolean keepGetters; protected static final String FROM_GETTERS = "-fromGetters"; @Override protected boolean checkSkip() { if (!needGeneration()) { getLog().info("No getter detected - all files are up to date."); return false; } return true; } @Override protected void doAction() throws Exception { if (!silent) { getLog().info("config - basedir : " + out.getAbsolutePath()); getLog().info("config - locales : " + Arrays.toString(locales)); } File bundleGetters = new File(out.getAbsoluteFile(), artifactId + ".properties"); createDirectoryIfNecessary(bundleGetters.getParentFile()); SortedProperties propertiesOut = new SortedProperties(encoding); DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir(out); ds.setIncludes(new String[]{"*.getter"}); ds.scan(); String[] files = ds.getIncludedFiles(); // Fusion des fichiers propriétés des différents parsers for (String file : files) { long t0 = System.nanoTime(); File bundleGetter = getGetterFile(out, file, false); // chargement du getter SortedProperties propertiesIn = new SortedProperties(encoding).load(bundleGetter); // ajout des entrées dans le bundle propertiesOut.putAll(propertiesIn); if (!keepGetters) { if (isVerbose()) { getLog().info("Will delete getter " + bundleGetter); } deleteFile(bundleGetter); } if (!silent) { String time = PluginHelper.convertTime(System.nanoTime() - t0); getLog().info("import getter " + bundleGetter.getName() + " in " + time); } } // sauvegarde du fichier des getters propertiesOut.store(bundleGetters); // Création des bundles for (Locale locale : locales) { if (getLog().isDebugEnabled()) { getLog().debug("generate bundle for locale " + locale); } File bundleOut = getI18nFile(out, artifactId + FROM_GETTERS, locale, false); copyFile(bundleGetters, bundleOut); if (!silent && verbose) { getLog().info("generate bundle " + locale); } } if (!keepGetters) { deleteFile(bundleGetters); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy