Author: tchemit Date: 2011-03-21 21:28:14 +0100 (Mon, 21 Mar 2011) New Revision: 1889 Url: http://nuiton.org/repositories/revision/i18n/1889 Log: Evolution #1402: Add bundleOutputPackage parameter to specify package of generated bundle folder Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/AbstractMakeI18nBundleMojo.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/BundleMojo.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/TapestryBundleMojo.java Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/AbstractMakeI18nBundleMojo.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/AbstractMakeI18nBundleMojo.java 2011-03-12 14:20:53 UTC (rev 1888) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/AbstractMakeI18nBundleMojo.java 2011-03-21 20:28:14 UTC (rev 1889) @@ -25,6 +25,7 @@ package org.nuiton.i18n.plugin.bundle; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringUtils; import org.apache.maven.plugin.MojoFailureException; import java.io.File; @@ -43,15 +44,38 @@ public abstract class AbstractMakeI18nBundleMojo extends AbstractI18nBundleMojo { /** - * Directory where to generate aggregated bundles. + * Root directory where to generate aggregated bundles (this directory will + * be added as resources of the project). * - * @parameter expression="${i18n.bundleOutputDir}" default-value="${basedir}/target/generated-sources/resources/META-INF" + * @parameter expression="${i18n.bundleOutputDir}" default-value="${basedir}/target/generated-sources/resources" * @required * @since 1.0.0 */ protected File bundleOutputDir; + /** + * Package name of the generate aggregated bundles. + * <p/> + * <strong>Note:</strong> By default we use the <code>META-INF</code> package + * since it is the favorite package of <code>I18n</code> runtime initializer. + * <p/> + * The package name is dotted as it will be stored as folder like in Java + * language. + * <p/> + * Example : + * <pre> + * package name : foo.bar + * directory : foo/bar + * </pre> + * + * @parameter expression="${i18n.bundleOutputPackage}" default-value="META-INF" + * @required + * @since 2.3.2 + */ + protected String bundleOutputPackage; + + /** * Name of the bundle to generate. * * @parameter expression="${i18n.bundleOutputName}" default-value="${project.artifactId}-i18n" @@ -104,6 +128,14 @@ /** to keep all none translated i18n keys by locale. */ protected Map<Locale, SortedSet<String>> unsafeMapping; + /** + * The definitive directory where to generate the bundles (includes the + * package of bunlde). + * + * @since 2.3.2 + */ + protected File outputFolder; + @Override public void init() throws Exception { super.init(); @@ -118,7 +150,15 @@ unsafeMapping = null; } - createDirectoryIfNecessary(bundleOutputDir); + // get the definitive folder where to generate bundles (including + // bundle package) + + outputFolder = getBundleOutputFolder(); + + if (isVerbose()) { + getLog().info("Will generates bundles in " + outputFolder); + } + createDirectoryIfNecessary(outputFolder); } protected void failsIfWarning() throws MojoFailureException { @@ -165,13 +205,13 @@ */ protected void generateDefaultBundle() throws IOException { - File bundleFirstLocale = getBundleFile(bundleOutputDir, + File bundleFirstLocale = getBundleFile(outputFolder, bundleOutputName, locales[0], false ); - File bundleWithoutLocale = getBundleFile(bundleOutputDir, + File bundleWithoutLocale = getBundleFile(outputFolder, bundleOutputName, null, false @@ -184,4 +224,15 @@ FileUtils.copyFile(bundleFirstLocale, bundleWithoutLocale); } + protected File getBundleOutputFolder() { + File result = bundleOutputDir; + if (StringUtils.isNotEmpty(bundleOutputPackage)) { + String[] paths = bundleOutputPackage.split("\\."); + for (String path : paths) { + result = new File(result, path); + } + } + return result; + } + } Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/BundleMojo.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/BundleMojo.java 2011-03-12 14:20:53 UTC (rev 1888) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/BundleMojo.java 2011-03-21 20:28:14 UTC (rev 1889) @@ -25,8 +25,6 @@ package org.nuiton.i18n.plugin.bundle; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; import org.nuiton.i18n.bundle.I18nBundleEntry; import org.nuiton.i18n.bundle.I18nBundleUtil; import org.nuiton.i18n.init.DefaultI18nInitializer; @@ -70,21 +68,6 @@ public class BundleMojo extends AbstractMakeI18nBundleMojo { /** - * A flag to use the parent of directory {@link #bundleOutputDir} - * as directory to add in build ressources. - * <p/> - * If the flag is not activated, the, we use directly the given - * {@link #bundleOutputDir} directory. - * <p/> - * <b>Note :</b> By default we use the parent directory, since this is more - * natural, only special cases should desactivate this parameter. - * - * @parameter expression="${i18n.addBundleOuputDirParent}" default-value="true" - * @since 2.0 - */ - protected boolean addBundleOuputDirParent; - - /** * A flag to generate the i18n definition file. * <p/> * This file contains all generated bundles and the paths of all i18n @@ -99,15 +82,9 @@ public void init() throws Exception { super.init(); - // ajout de repertoire de generation (le parent en fait) - // dans les resources du projet - - File ressourceDir = bundleOutputDir; - - if (addBundleOuputDirParent) { - ressourceDir = ressourceDir.getParentFile(); - } - addResourceDir(ressourceDir, "**/*.properties"); + // add root bundle directory as resources of the project + + addResourceDir(bundleOutputDir, "**/*.properties"); } @Override @@ -118,10 +95,11 @@ version = PluginHelper.removeSnapshotSuffix(version); if (!silent) { - getLog().info("config - bundle name : " + bundleOutputName); - getLog().info("config - basedir : " + bundleOutputDir); - getLog().info("config - locales : " + Arrays.toString(locales)); - getLog().info("config - version : " + version); + getLog().info("config - resources dir : " + bundleOutputDir); + getLog().info("config - package name : " + bundleOutputPackage); + getLog().info("config - bundle name : " + bundleOutputName); + getLog().info("config - locales : " + Arrays.toString(locales)); + getLog().info("config - version : " + version); } Map<Locale, String> bundleDico = @@ -131,7 +109,7 @@ long t0 = System.nanoTime(); - File bundleOut = getI18nFile(bundleOutputDir, + File bundleOut = getI18nFile(outputFolder, bundleOutputName, locale, false @@ -227,7 +205,7 @@ // charger String f = String.format(DefaultI18nInitializer.UNIQUE_BUNDLE_DEF, bundleOutputName); - File defOut = new File(bundleOutputDir, f); + File defOut = new File(outputFolder, f); if (!silent) { getLog().info("prepare i18n definition file in " + defOut.getAbsolutePath()); Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/TapestryBundleMojo.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/TapestryBundleMojo.java 2011-03-12 14:20:53 UTC (rev 1888) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/TapestryBundleMojo.java 2011-03-21 20:28:14 UTC (rev 1889) @@ -73,7 +73,7 @@ long t0 = System.nanoTime(); File bundleOut = getBundleFile( - bundleOutputDir, + outputFolder, bundleOutputName, locale, false