Index: maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/SourceEntry.java diff -u maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/SourceEntry.java:1.2 maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/SourceEntry.java:1.3 --- maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/SourceEntry.java:1.2 Fri Jan 11 22:55:25 2008 +++ maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/SourceEntry.java Wed Jan 23 09:41:17 2008 @@ -124,7 +124,6 @@ return foundFiles; } - @Override public String toString() { StringBuilder sb = new StringBuilder("basedir:").append(basedir); if (includes != null) { 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.6 maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/Generate.java:1.7 --- maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/Generate.java:1.6 Tue Nov 6 11:58:42 2007 +++ maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/Generate.java Wed Jan 23 09:41:17 2008 @@ -19,122 +19,83 @@ package org.codelutin.i18n.plugin.core; - -import java.io.BufferedOutputStream; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Set; -import java.util.jar.JarFile; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; +import java.io.IOException; +import java.util.Properties; -import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.project.MavenProject; +import org.codelutin.i18n.plugin.util.SortedProperties; import org.codelutin.util.FileUtil; /** - * Permet de générer les fichiers de traduction avec les fichiers de traducton - * des librairies et + * Merge des fichiers de propriétés avec les anciens. * * @author julien * * @goal gen - * @phase compile - * @execute goal=merge + * @phase generate-resources + * @execute goal=get */ public class Generate extends AbstractI18nPlugin { - /** - * @description msgcat command. - * @parameter expression="${i18n.msgmergeCmd}" default-value="msgmerge" - */ - protected String msgmergeCmd; - - /** - * @description Dépendance du projet. - * @parameter default-value="${project}" - * @readonly - */ - protected MavenProject project; - - /** - * @description Target java. - * @parameter expression="${i18n.outJava}" default-value="${project.build.outputDirectory}" - * @readonly - */ - protected File outJava; - /* * (non-Javadoc) * @see org.apache.maven.plugin.AbstractMojo#execute() */ public void execute() throws MojoExecutionException, MojoFailureException { - // Récupére les libs seulement si le plugin est lancé après la phase de compilation - Set artifacts = project.getArtifacts(); + for (String bundle : bundles) { + try { + // Merge + File bundleSrc = new File(src.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties"); + File bundleOut = new File(out.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties"); + + if(bundleSrc.exists()) { + Properties propertiesSrc = new Properties(); + propertiesSrc.load(new FileInputStream(bundleSrc)); + + Properties propertiesBundle = new SortedProperties(); + propertiesBundle.load(new FileInputStream(bundleOut)); + + // Parcours des clés + for (Object key : propertiesBundle.keySet()) { + Object oldKey = propertiesBundle.get(key); + Object value = propertiesSrc.get(oldKey); + + // Récupération de la clé si elle a été renommé + if(!key.equals(oldKey) && value == null) { + value = propertiesSrc.get(key); + } + + if(value != null) { + propertiesBundle.put(key, value); + } else { + propertiesBundle.put(key, ""); + } + } + + propertiesBundle.store(new FileOutputStream(bundleOut), null); - try { - for (String bundle : bundles) { - File bundleOut = new File(out.getAbsolutePath() + File.separatorChar + "language-" + bundle + ".properties"); - - // Récupération dans les libs les fichiers de traduction - for (Artifact artifact : artifacts) { - String fileName = artifact.getArtifactId() + "-" + bundle + ".properties"; - File libBundle = extract(artifact.getFile().getAbsolutePath(), - DIRECTORY_INSTALL + fileName, - out.getAbsolutePath() + File.separatorChar + fileName); - - if(libBundle != null) { - concactProperties(libBundle, bundleOut); - log.info("Processing library " + libBundle.getAbsolutePath()); - libBundle.delete(); + // Sauvegarde avant copie + if(genSrc) { + FileUtil.copy(bundleSrc, new File(src.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties" + "~")); } + + log.info("Merge bundle " + bundleSrc.getAbsolutePath()); } - // Copie dans le répertoire de compilation des fichiers de traduction - File bundleJava = new File(outJava.getAbsolutePath() + File.separatorChar + "language-" + bundle + ".properties"); - FileUtil.copy(bundleOut, bundleJava); - - log.info("Generate bundle " + bundleJava.getAbsolutePath()); - } - } catch (Exception e) { - log.error("Generate Error I/O ", e); - throw new MojoFailureException("Generate Error I/O "); - } - } - - /** - * Extrait un fichier i18n d'une librairie - * @param zipName - * @param fileNameIn - * @param fileNameOut - * @return - */ - protected File extract(String zipName, String fileNameIn, String fileNameOut) { - try { - ZipFile file = new JarFile(zipName); - ZipEntry entry = file.getEntry(fileNameIn); - if(entry != null) { - InputStream in = file.getInputStream(entry); - File target = new File(fileNameOut); - - OutputStream out = new BufferedOutputStream(new FileOutputStream(target)); - byte[] buffer = new byte[BUFFER_SIZE]; - int len = 0; - while ((len = in.read(buffer, 0, BUFFER_SIZE)) != -1) { - out.write(buffer, 0, len); + if(genSrc) { + // Copie des fichiers dans les sources + FileUtil.copy(bundleOut, bundleSrc); + log.info("Copy bundle " + bundleSrc.getAbsolutePath()); } - out.close(); - in.close(); - return target; + } catch (IOException e) { + log.error("File Error I/O ", e); + throw new MojoFailureException("File Error I/O "); } - } catch (Exception e) { - log.error(e); } - return null; } } Index: maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/Getter.java diff -u maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/Getter.java:1.7 maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/Getter.java:1.8 --- maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/Getter.java:1.7 Thu Nov 8 14:33:41 2007 +++ maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/Getter.java Wed Jan 23 09:41:17 2008 @@ -33,7 +33,7 @@ * @author julien * * @goal get - * @phase compile + * @phase generate-resources */ public class Getter extends AbstractI18nPlugin { @@ -43,7 +43,7 @@ */ public void execute() throws MojoExecutionException, MojoFailureException { try { - File bundleGetters = new File(out.getAbsolutePath() + File.separatorChar + "language.properties"); + File bundleGetters = new File(out.getAbsolutePath() + File.separatorChar + artifactId + ".properties"); bundleGetters.createNewFile(); DirectoryScanner ds = new DirectoryScanner(); @@ -64,7 +64,7 @@ // Création des bundles for (String bundle : bundles) { - File bundleOut = new File(out.getAbsolutePath() + File.separatorChar + "language-" + bundle + ".properties"); + File bundleOut = new File(out.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties"); FileUtil.copy(bundleGetters, bundleOut); log.info("Generate bundle " + bundleOut.getAbsolutePath()); } Index: maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java diff -u maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java:1.2 maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java:1.3 --- maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java:1.2 Fri Jan 11 22:57:43 2008 +++ maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java Wed Jan 23 09:41:17 2008 @@ -104,7 +104,7 @@ FileUtil.copy(oldParserFile, saveFile); // Anciennes clés disponnibles - File oldLanguageFile = new File(src.getAbsolutePath() + File.separatorChar + "language-" + bundles[0] + ".properties"); + File oldLanguageFile = new File(src.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundles[0] + ".properties"); oldLanguageFile.createNewFile(); oldLanguage.load(new FileInputStream(oldLanguageFile)); 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.10 maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java:1.11 --- maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java:1.10 Fri Jan 11 22:56:30 2008 +++ maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java Wed Jan 23 09:41:17 2008 @@ -50,7 +50,7 @@ /** * @description Répertoire sources des fichiers i18n. - * @parameter expression="${i18n.src}" default-value="${basedir}/src/i18n" + * @parameter expression="${i18n.src}" default-value="${basedir}/src/resources/i18n" * @required */ protected File src; @@ -81,6 +81,13 @@ protected boolean verbose; /** + * @description Nom du projet. + * @parameter expression="${i18n.artifactId}" default-value="${project.artifactId}" + * @readonly + */ + protected String artifactId; + + /** * Log */ protected Log log = getLog();