Index: maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/Generate.java diff -u maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/Generate.java:1.3 maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/Generate.java:1.4 --- maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/Generate.java:1.3 Mon Oct 29 17:29:39 2007 +++ maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/Generate.java Fri Nov 2 15:02:59 2007 @@ -58,21 +58,20 @@ try { for (String bundle : bundles) { - File bundleJava = new File(outJava.getAbsolutePath() + File.separatorChar + "language-" + bundle + ".properties"); - File bundleOut = new File(out.getAbsolutePath() + File.separatorChar + "language-" + bundle + ".properties"); - concactProperties(bundleOut, bundleJava); - + for (Artifact artifact : artifacts) { File libBundle = extract(artifact.getFile().getAbsolutePath(), "language-" + bundle + ".properties"); if(libBundle != null) { - concactProperties(libBundle, bundleJava); + concactProperties(libBundle, bundleOut); log.info("Processing library " + libBundle.getAbsolutePath()); libBundle.delete(); } } - FileUtil.copy(bundleJava, bundleOut); + + File bundleJava = new File(outJava.getAbsolutePath() + File.separatorChar + "language-" + bundle + ".properties"); + FileUtil.copy(bundleOut, bundleJava); log.info("Generate bundle " + bundleJava.getAbsolutePath()); } Index: maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java diff -u maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java:1.5 maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java:1.6 --- maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java:1.5 Fri Nov 2 10:28:07 2007 +++ maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java Fri Nov 2 15:02:59 2007 @@ -5,16 +5,13 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.util.Iterator; +import java.util.ArrayList; import java.util.List; import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.logging.Log; import org.codelutin.i18n.plugin.util.SortedProperties; -import org.codelutin.util.FileUtil; /** * Classe permettant d'obenir les paramètres pendant les différentes phases @@ -58,11 +55,38 @@ protected boolean gen; /** + * @description Active la modification de clé + * @parameter expression="${i18n.keysModifier}" default-value="true" + */ + protected boolean keysModifier; + + /** * Log */ protected Log log = getLog(); /** + * Liste des événements + */ + protected List events = new ArrayList(); + + /** + * Ajoute un événement + * @param parserEvent + */ + protected void addParserEvent(ParserEvent parserEvent) { + this.events.add(parserEvent); + } + + /** + * Supprime un événement + * @param parserEvent + */ + protected void removeParserEvent(ParserEvent parserEvent) { + this.events.remove(parserEvent); + } + + /** * Concatène deux fichiers de propriétés * @param in * @param out Index: maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/Merge.java diff -u maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/Merge.java:1.2 maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/Merge.java:1.3 --- maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/Merge.java:1.2 Fri Oct 26 15:39:23 2007 +++ maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/Merge.java Fri Nov 2 15:02:59 2007 @@ -1,15 +1,14 @@ package org.codelutin.i18n.plugin.core; import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; +import java.util.Properties; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.codehaus.plexus.util.cli.CommandLineException; -import org.codehaus.plexus.util.cli.CommandLineUtils; -import org.codehaus.plexus.util.cli.Commandline; -import org.codehaus.plexus.util.cli.StreamConsumer; -import org.codelutin.i18n.plugin.util.LoggerStreamConsumer; +import org.codelutin.i18n.plugin.util.SortedProperties; import org.codelutin.util.FileUtil; /** @@ -42,44 +41,44 @@ */ public void execute() throws MojoExecutionException, MojoFailureException { for (String bundle : bundles) { - // Merge - File bundleSrc = new File(src.getAbsolutePath() + File.separatorChar + "language-" + bundle + ".properties"); - File bundleOut = new File(out.getAbsolutePath() + File.separatorChar + "language-" + bundle + ".properties"); - - if(bundleSrc.exists()) { - Commandline msgmerge = new Commandline(); - msgmerge.setExecutable(msgmergeCmd); - msgmerge.createArgument().setValue("-q"); - msgmerge.createArgument().setValue("--sort-output"); - msgmerge.createArgument().setValue("--no-location"); - msgmerge.createArgument().setValue("--output-file=" + bundleOut.getAbsolutePath()); - msgmerge.createArgument().setValue("--properties-input"); - msgmerge.createArgument().setValue("--properties-output"); - msgmerge.createArgument().setValue(bundleSrc.getAbsolutePath()); - msgmerge.createArgument().setValue(bundleOut.getAbsolutePath()); - - log.info("Msgmerge command : " + msgmerge); - - StreamConsumer outLog = new LoggerStreamConsumer(log, LoggerStreamConsumer.INFO); - StreamConsumer errLog = new LoggerStreamConsumer(log, LoggerStreamConsumer.WARN); - - try { - CommandLineUtils.executeCommandLine(msgmerge, outLog, errLog); - } catch (CommandLineException e) { - log.error("Could not execute " + msgmergeCmd + ".", e); - throw new MojoFailureException("Could not execute " + msgmergeCmd + "."); - } + try { + // Merge + File bundleSrc = new File(src.getAbsolutePath() + File.separatorChar + "language-" + bundle + ".properties"); + File bundleOut = new File(out.getAbsolutePath() + File.separatorChar + "language-" + bundle + ".properties"); + + if(bundleSrc.exists()) { + Properties propertiesSrc = new Properties(); + propertiesSrc.load(new FileInputStream(bundleSrc)); + + Properties propertiesBundle = new SortedProperties(); + propertiesBundle.load(new FileInputStream(bundleOut)); + + for (Object key : propertiesBundle.keySet()) { + Object oldKey = propertiesBundle.get(key); + Object value = propertiesSrc.get(oldKey); + + if(!key.equals(oldKey) && value == null) { + value = propertiesSrc.get(key); + } + + if(value != null) { + propertiesBundle.put(key, value); + } else { + propertiesBundle.put(key, key); + } + } - log.info("Merge bundle " + bundleSrc.getAbsolutePath()); - } + propertiesBundle.store(new FileOutputStream(bundleOut), null); - try { - // Copie dans les sources - if(genSrc) { - if(bundleSrc.exists()) { - // Sauvegarde avant copie + // Sauvegarde avant copie + if(genSrc) { FileUtil.copy(bundleSrc, new File(src.getAbsolutePath() + File.separatorChar + "language-" + bundle + ".properties" + "~")); } + + log.info("Merge bundle " + bundleSrc.getAbsolutePath()); + } + + if(genSrc) { FileUtil.copy(bundleOut, bundleSrc); log.info("Copy bundle " + bundleSrc.getAbsolutePath()); } @@ -88,6 +87,7 @@ File bundleJava = new File(outJava.getAbsolutePath() + File.separatorChar + "i18n" + File.separatorChar + "language-" + bundle + ".properties"); FileUtil.copy(bundleOut, bundleJava); log.info("Copy bundle " + bundleJava.getAbsolutePath()); + } catch (IOException e) { log.error("File Error I/O ", e); throw new MojoFailureException("File Error I/O ");