This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository i18n. See http://git.nuiton.org/i18n.git commit 772ea4ffb86e9816c9a26bd5fa7d16f8ea41ef57 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Jul 27 13:05:11 2014 +0200 refs #3356 : improve the way of storing the generated csv file + fix doc --- .../plugin/bundle/csv/GenerateCsvBundleMojo.java | 120 +++++++++++++-------- i18n-maven-plugin/src/site/apt/usages.apt | 8 +- 2 files changed, 78 insertions(+), 50 deletions(-) diff --git a/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/csv/GenerateCsvBundleMojo.java b/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/csv/GenerateCsvBundleMojo.java index 4250d9e..2f9ed92 100644 --- a/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/csv/GenerateCsvBundleMojo.java +++ b/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/csv/GenerateCsvBundleMojo.java @@ -6,6 +6,7 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.nuiton.csv.Export; +import org.nuiton.i18n.plugin.I18nUtil; import org.nuiton.io.SortedProperties; import java.io.File; @@ -35,29 +36,23 @@ import java.util.TreeMap; public class GenerateCsvBundleMojo extends AbstractCsvBundleMojo { /** - * Name of the bundle to generate. - * - * @since 1.0.2 + * Name of the bundle to use. */ @Parameter(property = "i18n.bundleOutputName", defaultValue = "${project.artifactId}-i18n", required = true) protected String bundleOutputName; /** - * Encoding used to load any i18n property files. + * Encoding used to read any i18n property files. * <p/> * If not defined, will use the {@link #encoding} parameter. - * - * @since 2.4 */ @Parameter(property = "i18n.bundleInputEncoding") protected String bundleInputEncoding; /** - * Encoding used to write any i18n property files. + * Encoding used to write any files. * <p/> * If not defined, will use the {@link #encoding} parameter. - * - * @since 2.4 */ @Parameter(property = "i18n.bundleOutputEncoding") protected String bundleOutputEncoding; @@ -65,14 +60,12 @@ public class GenerateCsvBundleMojo extends AbstractCsvBundleMojo { /** * Root directory where to generate aggregated bundles (this directory will * be added as resources of the project). - * - * @since 1.0.0 */ @Parameter(property = "i18n.bundleOutputDir", defaultValue = "${project.build.directory}/generated-sources/resources", required = true) protected File bundleOutputDir; /** - * Package name of the generate aggregated bundles. + * 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. @@ -85,39 +78,53 @@ public class GenerateCsvBundleMojo extends AbstractCsvBundleMojo { * package name : foo.bar * directory : foo/bar * </pre> - * - * @since 2.3.2 */ @Parameter(property = "i18n.bundleOutputPackage", defaultValue = "META-INF", required = true) protected String bundleOutputPackage; /** * To add the generated csv file in the classpath. - * - * @since 3.3 + * <p/> + * If {@link #bundleCsvDirectory} is filled, then will add the generated csv file at the root of class-path, + * otherwise will add add it in the {@link #bundleOutputPackage} package. */ @Parameter(property = "i18n.addInClassPath", defaultValue = "true") protected boolean addInClassPath; /** - * The definitive directory where to generate the bundles (includes the - * package of bundle). - * - * @since 2.3.2 + * Location of the csv file to split. + */ + @Parameter(property = "i18n.bundleCsvFile", defaultValue = "${i18n.bundleOutputName}-i18n.csv", required = true) + protected String bundleCsvFileName; + + /** + * If you want to specify where to generate the csv file. + * <p/> + * If not filled, then will generate it in the same directory where bundles are stored. + */ + @Parameter(property = "i18n.bundleCsvDirectory") + protected File bundleCsvDirectory; + + /** + * The definitive directory where to load the bundles (includes the package of bundle). */ protected File outputFolder; + /** + * The definitive file where to write the csv file. + */ + protected File bundleCsvFile; + @Override public void init() throws Exception { super.init(); - // get the definitive folder where to generate bundles (including - // bundle package) + // get the definitive folder where to generate bundles (including bundle package) outputFolder = getBundleOutputFolder(); if (isVerbose()) { - getLog().info("Will generates bundles in " + outputFolder); + getLog().info("Will load bundles from " + outputFolder); } createDirectoryIfNecessary(outputFolder); @@ -142,26 +149,54 @@ public class GenerateCsvBundleMojo extends AbstractCsvBundleMojo { } } - if (addInClassPath) { + if (bundleCsvDirectory == null) { if (isVerbose()) { - getLog().info("Will add **/*.csv in classpath"); + getLog().info("Will generate csv bundle in bundle directory " + outputFolder); } - addResourceDir(bundleOutputDir, "**/*.csv"); + bundleCsvDirectory = outputFolder; + + if (addInClassPath) { + + if (isVerbose()) { + getLog().info("Will add " + bundleCsvFileName + " in classpath"); + } + addResourceDir(bundleOutputDir, "**/" + bundleCsvFileName); + } + } else { + if (isVerbose()) { + getLog().info("Will generate csv bundle in given directory " + bundleCsvDirectory); + } + + if (addInClassPath) { + + if (isVerbose()) { + getLog().info("Will add " + bundleCsvFileName + " in classpath"); + } + addResourceDir(bundleCsvDirectory, bundleCsvFileName); + } + } + createDirectoryIfNecessary(outputFolder); + + bundleCsvFile = new File(bundleCsvDirectory, bundleCsvFileName); + + if (!bundleCsvFile.exists()) { + createNewFile(bundleCsvFile); } + } @Override protected void doAction() throws Exception { - if (!silent) { - getLog().info("config - locales : " + Arrays.toString(locales)); - getLog().info("config - bundle dir : " + outputFolder); - getLog().info("config - bundle name : " + bundleOutputName); - getLog().info("config - csv separator : " + bundleCsvSeparator); - getLog().info("config - csv file : " + bundleCsvFile); - getLog().info("config - input encoding : " + bundleInputEncoding); - getLog().info("config - output encoding : " + bundleOutputEncoding); + if (!isSilent()) { + getLog().info("config - locales : " + Arrays.toString(locales)); + getLog().info("config - bundle dir : " + outputFolder); + getLog().info("config - bundle name : " + bundleOutputName); + getLog().info("config - csv separator : " + bundleCsvSeparator); + getLog().info("config - csv file name : " + bundleCsvFileName); + getLog().info("config - input encoding : " + bundleInputEncoding); + getLog().info("config - output encoding : " + bundleOutputEncoding); } // fill rows to export @@ -170,11 +205,10 @@ public class GenerateCsvBundleMojo extends AbstractCsvBundleMojo { for (Locale locale : locales) { - File bundleFile = getI18nFile(outputFolder, - bundleOutputName, - locale, - false - ); + File bundleFile = I18nUtil.getI18nFile(outputFolder, + bundleOutputName, + locale, + false); SortedProperties properties = new SortedProperties(bundleOutputEncoding); properties.load(bundleFile); @@ -193,16 +227,11 @@ public class GenerateCsvBundleMojo extends AbstractCsvBundleMojo { List<I18nBundleModelRow> rows = new LinkedList<I18nBundleModelRow>(rowsByKey.values()); if (!isSilent()) { - - getLog().info(String.format("Found %d translations.", rows.size())); + getLog().info(String.format("Found %d translations to export.", rows.size())); } // do the export - if (!bundleCsvFile.exists()) { - createNewFile(bundleCsvFile); - } - if (!isSilent()) { getLog().info("Generate csv bundle file at " + bundleCsvFile); } @@ -213,7 +242,6 @@ public class GenerateCsvBundleMojo extends AbstractCsvBundleMojo { } - protected File getBundleOutputFolder() { File result = bundleOutputDir; if (StringUtils.isNotEmpty(bundleOutputPackage)) { diff --git a/i18n-maven-plugin/src/site/apt/usages.apt b/i18n-maven-plugin/src/site/apt/usages.apt index ffbf520..c8b4518 100644 --- a/i18n-maven-plugin/src/site/apt/usages.apt +++ b/i18n-maven-plugin/src/site/apt/usages.apt @@ -235,7 +235,7 @@ Csv Bundle (since 3.3) * Generate a csv bundle - You can generate a single csv file with the bundles via the generate-csv-file (after a bundle invocation). + You can generate a single csv file with the bundles via the generate-csv-bundle (after a bundle invocation). ----------------------------------------------------------------------------- <plugin> @@ -245,7 +245,7 @@ Csv Bundle (since 3.3) <execution> <goals> <goal>bundle</goal> - <goal>generate-csv-file</goal> + <goal>generate-csv-bundle</goal> </goals> </execution> </executions> @@ -257,9 +257,9 @@ Csv Bundle (since 3.3) * Split or merge a csv bundle Having them the csv file filled by people you can then split it back to some i18n bundle files with - the split-csv-file mojo. + the <<split-csv-bundle>> mojo. - Event better you can merge it back to the i18n files of a module using the <<merge-back-csv-file>> mojo. + Event better you can merge it back to the i18n files of a module using the <<merge-back-csv-bundle>> mojo. And there is more for you! -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.