Index: maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/Generate.java diff -u maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/Generate.java:1.1 maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/Generate.java:1.2 --- maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/Generate.java:1.1 Wed Oct 24 10:01:44 2007 +++ maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/Generate.java Wed Oct 24 15:37:11 2007 @@ -5,7 +5,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.channels.FileChannel; @@ -18,10 +17,6 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; -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.util.FileUtil; /** @@ -58,46 +53,49 @@ protected File outJava; public void execute() throws MojoExecutionException, MojoFailureException { - Set artifacts = project.getArtifacts(); + if(gen) { + Set artifacts = project.getArtifacts(); - try { - for (String bundle : bundles) { - File bundleJava = new File(outJava.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties"); - FileChannel bundleJavaChannel = new FileOutputStream(bundleJava).getChannel(); - - File bundleOut = new File(out.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties"); - FileChannel bundleOutChannel = new FileInputStream(bundleOut).getChannel(); - bundleOutChannel.transferTo(0, bundleOutChannel.size(), bundleJavaChannel); - bundleOutChannel.close(); + try { + for (String bundle : bundles) { + File bundleJava = new File(outJava.getAbsolutePath() + File.separatorChar + "language-" + bundle + ".properties"); + FileChannel bundleJavaChannel = new FileOutputStream(bundleJava).getChannel(); + + File bundleOut = new File(out.getAbsolutePath() + File.separatorChar + "language-" + bundle + ".properties"); + FileChannel bundleOutChannel = new FileInputStream(bundleOut).getChannel(); + bundleOutChannel.transferTo(0, bundleOutChannel.size(), bundleJavaChannel); + bundleOutChannel.close(); - if(genDependencies) { for (Artifact artifact : artifacts) { - File libBundle = extract(artifact.getFile().getAbsolutePath(), artifact.getArtifactId() + "-" + bundle + ".properties"); + File libBundle = extract(artifact.getFile().getAbsolutePath(), "language-" + bundle + ".properties"); if(libBundle != null) { FileChannel libBundleChannel = new FileInputStream(libBundle).getChannel(); libBundleChannel.transferTo(0, libBundleChannel.size(), bundleJavaChannel); libBundleChannel.close(); + libBundle.delete(); } } - } - bundleJavaChannel.close(); - log.info("Generate bundle " + bundleJava.getAbsolutePath()); - } - }catch (Exception e) { - log.error("Generate Error I/O ", e); - throw new MojoFailureException("Generate Error I/O "); + bundleJavaChannel.close(); + FileUtil.copy(bundleJava, bundleOut); + + log.info("Generate bundle " + bundleJava.getAbsolutePath()); + } + } catch (Exception e) { + log.error("Generate Error I/O ", e); + throw new MojoFailureException("Generate Error I/O "); + } } } private File extract(String zipName, String fileName) { try { ZipFile file = new JarFile(zipName); - ZipEntry entry = file.getEntry(fileName); + ZipEntry entry = file.getEntry("i18n/" + fileName); if(entry != null) { InputStream in = file.getInputStream(entry); - File target = new File(out, entry.getName()); + File target = new File(out, fileName); OutputStream out = new BufferedOutputStream(new FileOutputStream(target)); byte[] buffer = new byte[BUFFER_SIZE]; Index: maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/Merge.java diff -u maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/Merge.java:1.1 maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/Merge.java:1.2 --- maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/Merge.java:1.1 Wed Oct 24 10:01:44 2007 +++ maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/Merge.java Wed Oct 24 15:37:11 2007 @@ -27,57 +27,65 @@ */ protected String msgmergeCmd; + /** + * @description Target java. + * @parameter expression="${i18n.outJava}" default-value="${project.build.outputDirectory}" + * @readonly + */ + protected File outJava; + public void execute() throws MojoExecutionException, MojoFailureException { for (String bundle : bundles) { - File bundleSrc = new File(src.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties"); - File bundleOut = new File(out.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties"); + // 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-by-file"); - msgmerge.createArgument().setValue("--add-location"); + 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 + "."); } - - if(genSrc) { - try { - FileUtil.copy(bundleSrc, new File(src.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties" + "~")); - FileUtil.copy(bundleOut, bundleSrc); - } catch (IOException e) { - log.error("File Error I/O ", e); - throw new MojoFailureException("File Error I/O "); - } - } - + + log.info("Merge bundle " + bundleSrc.getAbsolutePath()); - } else { + } + + try { + // Copie dans les sources if(genSrc) { - try { - bundleSrc.getParentFile().mkdirs(); - FileUtil.copy(bundleOut, bundleSrc); - log.info("Copy bundle " + bundleSrc.getAbsolutePath()); - } catch (IOException e) { - log.error("File Error I/O ", e); - throw new MojoFailureException("File Error I/O "); + if(bundleSrc.exists()) { + // Sauvegarde avant copie + FileUtil.copy(bundleSrc, new File(src.getAbsolutePath() + File.separatorChar + "language-" + bundle + ".properties" + "~")); } + FileUtil.copy(bundleOut, bundleSrc); + log.info("Copy bundle " + bundleSrc.getAbsolutePath()); } + + // Copie dans le classes + 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 "); } } } Index: maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/Gettext.java diff -u maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/Gettext.java:1.2 maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/Gettext.java:1.3 --- maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/Gettext.java:1.2 Wed Oct 24 10:01:44 2007 +++ maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/Gettext.java Wed Oct 24 15:37:11 2007 @@ -49,7 +49,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { // Initialisation du répertoire de travail out.mkdirs(); - File xgettextOut = new File(out.getAbsolutePath() + File.separatorChar + artifactId + ".properties"); + File xgettextOut = new File(out.getAbsolutePath() + File.separatorChar + "language.properties"); // Récupération des clés Commandline xgettext = new Commandline(); @@ -57,7 +57,8 @@ xgettext.createArgument().setValue("--from-code=" + encoding); xgettext.createArgument().setValue("--output=" + xgettextOut.getAbsolutePath()); xgettext.createArgument().setValue("--language=Java"); -// xgettext.createArgument().setValue("--omit-header"); + xgettext.createArgument().setValue("--no-location"); + xgettext.createArgument().setValue("--sort-output"); xgettext.createArgument().setValue("--msgstr-prefix="); xgettext.createArgument().setLine(keywords); xgettext.createArgument().setValue("--properties-output"); @@ -85,7 +86,7 @@ // Création des bundles for (String bundle : bundles) { - File bundleOut = new File(out.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties"); + File bundleOut = new File(out.getAbsolutePath() + File.separatorChar + "language-" + bundle + ".properties"); try { FileUtil.copy(xgettextOut, bundleOut); log.info("Generate bundle " + bundleOut.getAbsolutePath()); @@ -94,6 +95,7 @@ throw new MojoFailureException("File Error I/O "); } } + xgettextOut.delete(); } private String getAbsolutePath(String path) { Index: maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java diff -u maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java:1.2 maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java:1.3 --- maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java:1.2 Wed Oct 24 10:01:44 2007 +++ maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java Wed Oct 24 15:37:11 2007 @@ -22,23 +22,23 @@ /** * @description Répertoire sources des fichiers i18n. - * @parameter expression="${i18n.src}" default-value="${project.build}/resources/i18n" + * @parameter expression="${i18n.src}" default-value="${project.build}/src/i18n" * @required */ protected File src; /** * @description Répertoire des fichiers générés i18n. - * @parameter expression="${i18n.out}" default-value="${project.build}/target/i18n" + * @parameter expression="${i18n.out}" default-value="${project.build}/target/gen/i18n" * @required */ protected File out; /** - * @description Merge les les fichiers properties des dépendances. - * @parameter expression="${i18n.genDependenciess}" default-value="false" + * @description Récupère les fichiers de propriètés dans les dépendances du projet et génére le fichiers de propriété. + * @parameter expression="${i18n.gen}" default-value="false" */ - protected boolean genDependencies; + protected boolean gen; /** * @description Met les fichiers générés dans le répertoire des sources i18n. @@ -47,13 +47,6 @@ protected boolean genSrc; /** - * @description Nom du projet. - * @parameter default-value="${project.artifactId}" - * @readonly - */ - protected String artifactId; - - /** * Log */ protected Log log = getLog();