[Lutinutil-commits] r1476 - in maven-i18n-plugin/trunk: . src/main/java/org/codelutin/i18n/plugin src/main/java/org/codelutin/i18n/plugin/parser src/main/resources
Author: tchemit Date: 2009-05-08 15:44:52 +0000 (Fri, 08 May 2009) New Revision: 1476 Added: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Bundle.java maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/I18nArtifact.java Modified: maven-i18n-plugin/trunk/changelog.txt maven-i18n-plugin/trunk/pom.xml maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Generate.java maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Getter.java maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/PluginHelper.java maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java maven-i18n-plugin/trunk/src/main/resources/log4j.properties Log: - introduce bundle goal to merge all bundle into one for final application - no more use of bundles property, prefer locales one (with real Locale object instead of simple String one...) Modified: maven-i18n-plugin/trunk/changelog.txt =================================================================== --- maven-i18n-plugin/trunk/changelog.txt 2009-05-08 15:41:38 UTC (rev 1475) +++ maven-i18n-plugin/trunk/changelog.txt 2009-05-08 15:44:52 UTC (rev 1476) @@ -1,3 +1,7 @@ +0.12 chemit ? + * 20090508 [chemit] - introduce bundle goal to merge all bundle into one for final application + - no more use of bundles property, prefer locales one (with real Locale object instead of simple String one...) + 0.11 chemit 20090311 * 20090420 [chemit] - bump versions * 20090417 [chemit] - replace bundles parameters from tyep String[] to String type to make easier configuration Modified: maven-i18n-plugin/trunk/pom.xml =================================================================== --- maven-i18n-plugin/trunk/pom.xml 2009-05-08 15:41:38 UTC (rev 1475) +++ maven-i18n-plugin/trunk/pom.xml 2009-05-08 15:44:52 UTC (rev 1476) @@ -9,7 +9,7 @@ <parent> <groupId>org.codelutin</groupId> <artifactId>lutinproject</artifactId> - <version>3.5.2</version> + <version>3.5.3</version> </parent> <artifactId>maven-i18n-plugin</artifactId> @@ -33,6 +33,12 @@ </dependency> <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-dependency-tree</artifactId> + <version>1.2</version> + </dependency> + + <dependency> <groupId>xalan</groupId> <artifactId>xalan</artifactId> <version>2.7.0</version> @@ -60,6 +66,13 @@ <scope>provided</scope> </dependency> + <dependency> + <groupId>org.codelutin</groupId> + <artifactId>lutinutil</artifactId> + <version>${lutinutil.version}</version> + <scope>provided</scope> + </dependency> + </dependencies> <!-- ************************************************************* --> @@ -88,7 +101,8 @@ <maven.version>2.0.10</maven.version> <processor.version>0.17</processor.version> - <lutinpluginutil.version>0.4</lutinpluginutil.version> + <lutinpluginutil.version>0.5-SNAPSHOT</lutinpluginutil.version> + <lutinutil.version>1.0.6-SNAPSHOT</lutinutil.version> </properties> <build> Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java 2009-05-08 15:41:38 UTC (rev 1475) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java 2009-05-08 15:44:52 UTC (rev 1476) @@ -23,6 +23,8 @@ import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.Locale; +import org.codelutin.i18n.I18n; /** * Classe permettant d'obenir les parametres pendant les différentes phases @@ -41,8 +43,6 @@ * de traduction entre librairie */ protected static final String DIRECTORY_INSTALL = "i18n" + File.separatorChar; - /** les bundles par defaut utilisés, si aucun bundle n'est renseigné. */ - //protected static final String[] DEFAULT_BUNDLES = new String[]{"fr_FR", "en_GB"}; /** * Nom du projet. * @@ -122,7 +122,7 @@ protected boolean strictMode; /** Liste des évènements */ protected List<ParserEvent> events = new ArrayList<ParserEvent>(); - protected String[] bundlesToUse; + protected Locale[] locales; /**logger verbeux */ protected I18nLogger verboseLog; @@ -151,10 +151,11 @@ if (verbose) { getLog().info("config - verbose mode is on"); } - bundlesToUse = bundles.split(","); - for (int i = 0, j = bundlesToUse.length; i < j; i++) { - bundlesToUse[i] = bundlesToUse[i].trim(); - } + locales = I18n.parseLocales(bundles); +// bundlesToUse = bundles.split(","); +// for (int i = 0, j = bundlesToUse.length; i < j; i++) { +// bundlesToUse[i] = bundlesToUse[i].trim(); +// } } public String getArtifactId() { Added: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Bundle.java =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Bundle.java (rev 0) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Bundle.java 2009-05-08 15:44:52 UTC (rev 1476) @@ -0,0 +1,323 @@ +/* + * *##% Plugin maven pour lutini18n + * Copyright (C) 2007 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ +package org.codelutin.i18n.plugin; + +import java.net.MalformedURLException; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Properties; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactCollector; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; +import org.apache.maven.model.Resource; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectBuilder; +import org.apache.maven.shared.dependency.tree.DependencyNode; +import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder; +import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException; +import org.codelutin.i18n.bundle.I18nBundleEntry; +import org.codelutin.i18n.bundle.I18nBundleFactory; +import org.codelutin.i18n.plugin.PluginHelper.I18nProperties; +import org.codelutin.util.DependencyUtil; +import org.codelutin.util.StringUtil; + +/** + * Créer un bundle pour une application finale. + * + * Cela génère un merge de tous les fichiers i18n utilisés en un seul. + * + * On utilise la dépendance sur les artifacts pour connaitre l'ordre le chargement + * des bundles. + * + * Si dans un bundle childs, la valeur de la clef est vide, on conserve alors celui + * du parent, + * + * Ainsi on obtient un bundle dont toutes les clefs sont traduites. + * + * Le but aussi d'utiliser un unique bundle est de gagner du temps au runtime + * car la recherche des bundles devient trop couteuse en temps lorsque l'on a de + * nombreuses dépendances (au dessus de 100 deps cela peut prendre plusieurs + * secondes, ce qui 'est pas acceptable). + * + * On a ajoute un second mode d'initialisation dans la clesse I18n pour n'utiliser + * qu'un seul bundle et courcircuiter le chargement couteux... + * * + * + * @author chemit + * @goal bundle + * @phase generate-resources + * @execute goal=gen + * @requiresProject true + * @requiresDependencyResolution runtime + * + * @since 0.12 + */ +public class Bundle extends AbstractI18nPlugin { + + /** + * Repertoire ou generer les bundles. + * + * @parameter expression="${i18n.bundleOutputDir}" default-value="${basedir}/target/generated-sources/java/META-INF" + * @required + */ + protected File bundleOutputDir; + /** + * Nom du bundle a generer. + * + * @parameter expression="${i18n.bundleOutputName}" default-value="${project.artifactId}-i18n" + * @required + */ + protected String bundleOutputName; + /** + * Dependance du projet. + * + * @parameter default-value="${project}" + * @required + */ + protected MavenProject project; + /** + * Local Repository. + * + * @parameter expression="${localRepository}" + * @required + * @readonly + */ + protected ArtifactRepository localRepository; + /** + * Remote repositories used for the project. + * + * @parameter expression="${project.remoteArtifactRepositories}" + * @required + * @readonly + */ + protected List<?> remoteRepositories; + /** + * Dependency tree builder component. + * + * @component + */ + protected DependencyTreeBuilder dependencyTreeBuilder; + /** + * Artifact Factory component. + * + * @component + */ + protected ArtifactFactory factory; + /** + * Artifact metadata source component. + * + * @component + */ + protected ArtifactMetadataSource artifactMetadataSource; + /** + * Artifact collector component. + * + * @component + */ + protected ArtifactCollector collector; + /** + * Maven Project Builder component. + * + * @component + */ + protected MavenProjectBuilder mavenProjectBuilder; + protected I18nArtifact[] i18nArtifacts; + protected ClassLoader loader; + protected URL[] urls; + + @Override + public void init() { + super.init(); + + if (locales == null || locales.length == 0) { + throw new IllegalStateException("il faut au moins une locale declaree (utiliser la propriete 'bundles')"); + } + + if (!bundleOutputDir.exists()) { + bundleOutputDir.mkdirs(); + } + + try { + // calcul des artifacts qui ont un bundle i18n et trie selon les + // dependances + + i18nArtifacts = detectI18nArtifacts(); + + getLog().info("detected " + i18nArtifacts.length + " i18n artifact(s) : "); + for (I18nArtifact a : i18nArtifacts) { + getLog().info(" - " + a.getArtifact()); + } + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + // ajout de repertoire de generation (le parent en fait) + // dans les resources du projet + + String newresourceDir = bundleOutputDir.getParentFile().getAbsolutePath(); + + List<?> resources = project.getResources(); + boolean shouldAdd = true; + for (Object o : resources) { + Resource r = (Resource) o; + if (!r.getDirectory().equals(newresourceDir)) { + continue; + } + + r.addInclude("**/*.properties"); + shouldAdd = false; + break; + } + if (shouldAdd) { + Resource r = new Resource(); + r.setDirectory(newresourceDir); + r.addInclude("**/*.properties"); + //if (verbose) { + getLog().info("add resource " + r); + //} + project.addResource(r); + } + } + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + + if ("pom".equals(project.getPackaging()) || "site".equals(project.getPackaging())) { + return; + } + + long t00 = System.nanoTime(); + + init(); + + Locale defaultLocale = locales[0]; + try { + for (Locale locale : locales) { + + long t0 = System.nanoTime(); + + File bundleOut = PluginHelper.getI18nFile(bundleOutputDir, bundleOutputName, locale, false); + + getLog().info("prepare bundle " + bundleOut.getAbsolutePath()); + + I18nProperties propertiesOut = new I18nProperties(encoding, false); + + for (I18nArtifact artifact : i18nArtifacts) { + I18nBundleEntry[] bundleEntries = artifact.getBundleEntries(locale, defaultLocale); + for (I18nBundleEntry bundleEntry : bundleEntries) { + + bundleEntry.load(propertiesOut); + + if (verbose) { + getLog().info("loaded " + bundleEntry.getPath() + " in " + StringUtil.convertTime(t0, System.nanoTime())); + } + } + } + propertiesOut.store(bundleOut); + if (verbose) { + getLog().info("bundle created in " + StringUtil.convertTime(t0, System.nanoTime()) + " (detected sentences : " + propertiesOut.size() + ")"); + } + } + + // ecriture du ficher des definitions i18n (permet de faire une + // recherche extact sur un fichier puis d'en deduire les bundles a + // charger + String f = String.format(I18nBundleFactory.UNIQUE_BUNDLE_DEF, bundleOutputName); + File defOut = new File(bundleOutputDir, f); + getLog().info("prepare i18n definition " + defOut.getAbsolutePath()); + Properties p = new Properties(); + p.setProperty(I18nBundleFactory.BUNDLE_DEF_LOCALES, bundles); + p.store(new FileOutputStream(defOut), null); + + if (verbose) { + getLog().info("done in " + StringUtil.convertTime(t00, System.nanoTime())); + } + } catch (IOException e) { + getLog().error("File Error I/O ", e); + throw new MojoFailureException("File Error I/O "); + } + } + + /** + * Detecte les {@link I18nArtifact} et les retourne dans l'ordre de chargement + * dans le système i18n, i.e l'ordre des dependances entre artifacts. + * + * @return les artifacts i18nables triés par leur ordre de chargement dans le système i18n. + * + * @throws java.net.MalformedURLException + * @throws java.io.IOException + * @throws org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException + */ + protected I18nArtifact[] detectI18nArtifacts() throws MalformedURLException, IOException, DependencyTreeBuilderException { + + Map<Artifact, I18nArtifact> dico = new java.util.HashMap<Artifact, I18nArtifact>(); + + I18nArtifact i18nArtifact; + for (Object o : project.getArtifacts()) { + i18nArtifact = new I18nArtifact((Artifact) o); + if (i18nArtifact.detectBundles()) { + if (verbose) { + getLog().info("detected artifact " + i18nArtifact.getArtifact()); + } + dico.put(i18nArtifact.getArtifact(), i18nArtifact); + } + } + + ArtifactFilter artifactFilter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME); + + DependencyNode rootNode = dependencyTreeBuilder.buildDependencyTree(project, localRepository, factory, + artifactMetadataSource, artifactFilter, collector); + + List<Artifact> artifacts = new java.util.ArrayList<Artifact>(dico.keySet()); + + DependencyUtil.sortArtifacts(rootNode, artifacts, verbose); + + // l'artifact du projet est traite en dernier car s'il possède des + // bundles alors ils doivent etre charge en dernier + + Artifact projectArtifact = project.getArtifact(); + i18nArtifact = new I18nArtifact(projectArtifact, src.getParentFile()); + + if (i18nArtifact.detectBundles()) { + if (verbose) { + getLog().info("detected artifact " + i18nArtifact.getArtifact()); + } + artifacts.add(i18nArtifact.getArtifact()); + dico.put(i18nArtifact.getArtifact(), i18nArtifact); + } + + I18nArtifact[] result = new I18nArtifact[artifacts.size()]; + int i = 0; + for (Artifact artifact : artifacts) { + result[i++] = dico.get(artifact); + } + return result; + } +} Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Generate.java =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Generate.java 2009-05-08 15:41:38 UTC (rev 1475) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Generate.java 2009-05-08 15:44:52 UTC (rev 1476) @@ -26,6 +26,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.util.Locale; /** * Merge des fichiers de propriétés avec les anciens. @@ -37,10 +38,6 @@ */ public class Generate extends AbstractI18nPlugin { - /* - * (non-Javadoc) - * @see org.apache.maven.plugin.AbstractMojo#execute() - */ @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -51,7 +48,7 @@ return; } - for (String bundle : bundlesToUse) { + for (Locale bundle : locales) { try { // Merge File bundleSrc = PluginHelper.getI18nFile(src, artifactId, bundle, false); Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Getter.java =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Getter.java 2009-05-08 15:41:38 UTC (rev 1475) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Getter.java 2009-05-08 15:44:52 UTC (rev 1476) @@ -25,8 +25,8 @@ import org.codelutin.util.FileUtil; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; +import java.util.Locale; /** * Recupere les différents fichiers des parsers en un fichier de proprietes. @@ -74,7 +74,7 @@ } // Création des bundles - for (String bundle : bundlesToUse) { + for (Locale bundle : locales) { File bundleOut = PluginHelper.getI18nFile(out, artifactId, bundle, false); FileUtil.copy(bundleGetters, bundleOut); if (verbose) { Added: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/I18nArtifact.java =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/I18nArtifact.java (rev 0) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/I18nArtifact.java 2009-05-08 15:44:52 UTC (rev 1476) @@ -0,0 +1,74 @@ +package org.codelutin.i18n.plugin; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; +import java.util.Locale; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.maven.artifact.Artifact; +import org.codelutin.i18n.bundle.I18nBundle; +import org.codelutin.i18n.bundle.I18nBundleEntry; +import org.codelutin.i18n.bundle.I18nBundleFactory; + +/** + * + * @author chemit + * @since 0.12 + */ +public class I18nArtifact { + + static final Log log = LogFactory.getLog(I18nArtifact.class); + protected final Artifact artifact; + protected final URL url; + protected I18nBundle[] bundles; + + public I18nArtifact(Artifact artifact) throws MalformedURLException { + this.artifact = artifact; + this.url = artifact.getFile().toURI().toURL(); + } + + public I18nArtifact(Artifact artifact, File file) throws MalformedURLException { + this.artifact = artifact; + this.url = file.toURI().toURL(); + } + + public Artifact getArtifact() { + return artifact; + } + + public URL getUrl() { + return url; + } + + public I18nBundleEntry[] getBundleEntries(Locale l, Locale defaultLocale) { + if (bundles == null) { + throw new NullPointerException("le bundleManager n'a pas ete initialise!"); + } + return I18nBundleFactory.getBundleEntries(l, defaultLocale, bundles); + } + + public boolean detectBundles() throws IOException { + + URL[] i18nUrls = I18nBundleFactory.getURLs(url); + + if (i18nUrls == null || i18nUrls.length == 0) { + // aucune url sur un fichier de traduction trouve + // l'artifact n'est pas i18n. + return false; + } + + List<I18nBundle> listBundles = I18nBundleFactory.detectBundles(i18nUrls); + + if (listBundles.isEmpty()) { + // pas de bundle instancie (cela ne devrait jamias arrive...) + return false; + } + + this.bundles = listBundles.toArray(new I18nBundle[listBundles.size()]); + + return true; + } +} Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/PluginHelper.java =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/PluginHelper.java 2009-05-08 15:41:38 UTC (rev 1475) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/PluginHelper.java 2009-05-08 15:44:52 UTC (rev 1476) @@ -30,6 +30,7 @@ import java.util.Collections; import java.util.Enumeration; import java.util.List; +import java.util.Locale; import java.util.Properties; import java.util.Vector; @@ -46,13 +47,13 @@ /** * @param root le repertoire ou sont stockes les fichiers i18n * @param artifactId le nom de l'artifact - * @param bundle le nom du bundle + * @param locale le nom du bundle * @param create <code>true</code> pour creer le fichier si non present * @return le fichier i18n * @throws java.io.IOException si probleme lors de la creation du fichier */ - public static File getI18nFile(File root, String artifactId, String bundle, boolean create) throws IOException { - File file = new File(root.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties"); + public static File getI18nFile(File root, String artifactId, Locale locale, boolean create) throws IOException { + File file = new File(root.getAbsolutePath() + File.separatorChar + artifactId + "-" + locale.toString() + ".properties"); if (create && !file.exists()) { if (!file.exists()) { file.getParentFile().mkdirs(); @@ -95,8 +96,8 @@ * @param bundle le nom du bundle * @return le fichier i18n de backup */ - public static File getI18nFileBackup(File root, String artifactId, String bundle) { - return new File(root.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties~"); + public static File getI18nFileBackup(File root, String artifactId, Locale bundle) { + return new File(root.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle.toString() + ".properties~"); } /** @@ -108,6 +109,7 @@ * <p/> * Note : <b>Aucune liste n'est creee, ni recopiee</b> * + * @param <O> le type des objets de la liste * @param list la liste a convertir * @param type le type des elements de la liste * @return la liste typee @@ -115,24 +117,20 @@ * pas en adequation avec le type voulue. */ @SuppressWarnings({"unchecked"}) - static public <O> List<O> toGenericList(List list, Class<O> type) throws IllegalArgumentException { + static public <O> List<O> toGenericList(List<?> list, Class<O> type) throws IllegalArgumentException { if (list.isEmpty()) { - return list; + return (List<O>) list; } for (Object o : list) { if (!(type.isAssignableFrom(o.getClass()))) { throw new IllegalArgumentException("can not cast List with object of type " + o.getClass() + " to " + type + " type!"); } } - return list; + return (List<O>) list; } - - static final protected double[] timeFactors = {1000000, 1000, 60, 60, 24}; + static final protected String[] timeUnites = {"ns", "ms", "s", "m", "h", "d"}; - static final protected String[] timeUnites = {"ns", "ms", "s", "m", "h", - "d"}; - static public String convertTime(long value) { return convert(value, timeFactors, timeUnites); } @@ -165,13 +163,19 @@ public static class I18nProperties extends Properties { private static final long serialVersionUID = -1147150444452577558L; - /** l'encoding a utiliser pour lire et ecrire le properties. */ protected String encoding; + /** un drapeau pour savoir s'il faut enlever l'entete generere */ + protected boolean removeHeader; public I18nProperties(String encoding) { + this(encoding, true); + } + + public I18nProperties(String encoding, boolean removeHeader) { super(); this.encoding = encoding; + this.removeHeader = removeHeader; } public I18nProperties(Properties defaults) { @@ -214,7 +218,11 @@ * @throws IOException if any io pb */ public void store(File dst) throws IOException { - super.store(new OutputStreamWriter(new PropertiesDateRemoveFilterStream(new FileOutputStream(dst)), encoding), null); + if (removeHeader) { + super.store(new OutputStreamWriter(new PropertiesDateRemoveFilterStream(new FileOutputStream(dst)), encoding), null); + } else { + super.store(new FileOutputStream(dst), null); + } } /** @@ -224,10 +232,25 @@ * @throws IOException if any io pb */ public void store(OutputStream dst) throws IOException { - super.store(new PropertiesDateRemoveFilterStream(dst), null); + if (removeHeader) { + super.store(new PropertiesDateRemoveFilterStream(dst), null); + } else { + super.store(dst, null); + } } } + /** + * Un ecrivain qui supprime la premiere ligne rencontree dans le flux. + * + * + * <b>Note: </b> Attention, les performance d'utilisation de cet ecrivain + * est problèmatique, car sur de gros fichiers (>1000 entrees) les + * performances se degradent serieusement : pour 1200 entrees on arrive à + * plus de 5 secondes, alors que sans on a 76 ms! ... + * + * FIXME : implanter quelque chose de plus performant dans tous les cas + */ public static class PropertiesDateRemoveFilterStream extends FilterOutputStream { private boolean firstLineOver; @@ -252,5 +275,4 @@ } } } - } Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java =================================================================== --- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java 2009-05-08 15:41:38 UTC (rev 1475) +++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java 2009-05-08 15:44:52 UTC (rev 1476) @@ -153,7 +153,7 @@ // Anciennes cles disponnibles //fixme : pourquoi on utilise un bundle precis ? le premier ici, je ne comprends pas - File oldLanguageFile = PluginHelper.getI18nFile(src, artifactId, bundlesToUse[0], true); + File oldLanguageFile = PluginHelper.getI18nFile(src, artifactId, locales[0], true); oldLanguage.load(oldLanguageFile); @@ -322,9 +322,9 @@ return true; } - String[] files = getFilesForEntry(mojo); + String[] filesForEntry = getFilesForEntry(mojo); - if (files.length == 0) { + if (filesForEntry.length == 0) { // skip no file found skipMessage = "no file found."; return true; @@ -334,7 +334,7 @@ if (mojo.strictMode || updater == null) { // mojo strict mode or not updater, so force all files skipFiles = new String[0]; - this.files = files; + this.files = filesForEntry; return false; } @@ -342,7 +342,7 @@ List<String> listSkipFiles = new ArrayList<String>(); // test if have any file - for (String foundFile : files) { + for (String foundFile : filesForEntry) { File file = new File(getBasedir(), foundFile); if (isFileUptodate(file)) { listSkipFiles.add(foundFile); Modified: maven-i18n-plugin/trunk/src/main/resources/log4j.properties =================================================================== --- maven-i18n-plugin/trunk/src/main/resources/log4j.properties 2009-05-08 15:41:38 UTC (rev 1475) +++ maven-i18n-plugin/trunk/src/main/resources/log4j.properties 2009-05-08 15:44:52 UTC (rev 1476) @@ -7,4 +7,4 @@ # package level log4j.logger.org.codelutin.util=INFO - +log4j.logger.org.codelutin.i18n.plugin=INFO
participants (1)
-
tchemit@users.labs.libre-entreprise.org