Author: tchemit Date: 2010-03-07 17:03:59 +0100 (Sun, 07 Mar 2010) New Revision: 1703 Log: - reformat code (80 car per line max) - fix javadoc - remove comment old code - use new api from nuiton-i18n-api Modified: trunk/maven-i18n-plugin/pom.xml trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/AbstractI18nBundleMojo.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/AbstractI18nMojo.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/BundleMojo.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/CollectI18nArtifactsMojo.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/GenerateMojo.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/GetterMojo.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/I18nArtifact.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/I18nLogger.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/SourceEntry.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/AbstractI18nParserMojo.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/I18nSourceEntry.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/KeysModifier.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/Parser.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/ParserEvent.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/ParserException.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaMojo.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserValidationMojo.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserXmlMojo.java Modified: trunk/maven-i18n-plugin/pom.xml =================================================================== --- trunk/maven-i18n-plugin/pom.xml 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/pom.xml 2010-03-07 16:03:59 UTC (rev 1703) @@ -9,7 +9,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>i18n</artifactId> - <version>1.0.2-SNAPSHOT</version> + <version>1.1-SNAPSHOT</version> </parent> <groupId>org.nuiton.i18n</groupId> Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/AbstractI18nBundleMojo.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/AbstractI18nBundleMojo.java 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/AbstractI18nBundleMojo.java 2010-03-07 16:03:59 UTC (rev 1703) @@ -28,7 +28,7 @@ /** * Created: 26 déc. 2009 * - * @author Tony Chemit <chemit@codelutin.com> Copyright Code Lutin + * @author tchemit <chemit@codelutin.com> * @version $Revision$ * <p/> * Mise a jour: $Date$ par : @@ -44,6 +44,7 @@ * @since 1.0.2 */ protected File collectOutputDir; + /** * Nom de base des fichiers qui contient les localisations des bundles. * @@ -63,19 +64,24 @@ * @return les urls des bundles i18n detectees pour le projet. * @throws Exception pour tout problème */ - protected abstract URL[] getCollectI18nResources(Locale locale) throws Exception; + protected abstract URL[] getCollectI18nResources(Locale locale) + throws Exception; /** - * Pour obtenir le fichier contenant les localisation des bundles i18n du projet - * pour une {@code locale} donnée. + * Pour obtenir le fichier contenant les localisation des bundles i18n du + * projet pour une {@code locale} donnée. * * @param locale la locale - * @param create un drapeau pour forcer la création du fichier s'il n'existe pas - * @return le fichier qui contient les urls des bundles i18n pour la locale donnée. + * @param create un drapeau pour forcer la création du fichier + * s'il n'existe pas + * @return le fichier qui contient les urls des bundles i18n pour la + * locale donnée. * @throws IOException pour tout pb */ - protected File getCollectOutputFile(Locale locale, boolean create) throws IOException { - File bundleOut = getI18nFile(collectOutputDir, collectOutputName, locale, create); + protected File getCollectOutputFile(Locale locale, boolean create) + throws IOException { + File bundleOut = getI18nFile(collectOutputDir, collectOutputName, + locale, create); return bundleOut; } Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/AbstractI18nMojo.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/AbstractI18nMojo.java 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/AbstractI18nMojo.java 2010-03-07 16:03:59 UTC (rev 1703) @@ -42,6 +42,7 @@ * Le nombre de getters détectés pendant le cycle de vie du build. */ private static int NB_GETTER_FILES = 0; + /** * Dependance du projet. * @@ -50,6 +51,7 @@ * @since 1.0.2 */ protected MavenProject project; + /** * Nom du projet. * @@ -57,6 +59,7 @@ * @readonly */ protected String artifactId; + /** * Langues des bundles generes. * <p/> @@ -65,6 +68,7 @@ * @required */ protected String bundles; + /** * Repertoire sources des fichiers i18n. * @@ -72,6 +76,7 @@ * @required */ protected File src; + /** * Repertoire des fichiers generes i18n. * @@ -79,6 +84,7 @@ * @required */ protected File out; + /** * encoding a utiliser pour charger et sauver les bundles * @@ -86,6 +92,7 @@ * @required */ protected String encoding; + /** * Met les fichiers generes dans le repertoire des sources i18n. * <p/> @@ -94,6 +101,7 @@ * @parameter expression="${i18n.genSrc}" default-value="true" */ protected boolean genSrc; + /** * verbose flag * <p/> @@ -102,6 +110,7 @@ * @parameter expression="${i18n.verbose}" default-value="${maven.verbose}" */ protected boolean verbose; + /** * silent flag * @@ -109,6 +118,7 @@ * @since 1.0.0-rc-5 */ protected boolean silent; + /** * ne conserve que les clef scannees (et donc traite tous les fichiers) * <p/> @@ -119,10 +129,12 @@ * @parameter expression="${i18n.strictMode}" default-value="false" */ protected boolean strictMode; + /** * les locales a traiter */ protected Locale[] locales; + /** * logger verbeux */ @@ -144,7 +156,9 @@ } locales = I18nUtil.parseLocales(bundles); if (locales == null || locales.length == 0) { - throw new IllegalStateException("Il faut au moins une locale declaree (utiliser la propriete 'bundles')"); + throw new IllegalStateException( + "Il faut au moins une locale declaree (utiliser " + + "la propriete 'bundles')"); } // return true; } @@ -182,10 +196,13 @@ * @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 + * @throws IOException si probleme lors de la creation du fichier */ - public File getI18nFile(File root, String artifactId, Locale locale, boolean create) throws IOException { - File file = new File(root.getAbsolutePath() + File.separatorChar + artifactId + "-" + locale.toString() + ".properties"); + public 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()) { createNewFile(file); } @@ -197,10 +214,12 @@ * @param getter le nom du getter * @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 + * @throws IOException si probleme lors de la creation du fichier */ - public File getGetterFile(File root, String getter, boolean create) throws IOException { - File file = new File(root.getAbsolutePath() + File.separatorChar + getter); + public File getGetterFile(File root, String getter, boolean create) + throws IOException { + File file = new File( + root.getAbsolutePath() + File.separatorChar + getter); if (create && !file.exists()) { createNewFile(file); } @@ -227,7 +246,8 @@ // return new File(root.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle.toString() + ".properties~"); // } - protected void checkBundle(Locale locale, Properties propertiesOut, boolean showEmpty) { + protected void checkBundle(Locale locale, Properties propertiesOut, + boolean showEmpty) { // on verifie qu'il n'y a pas de traduction vide SortedSet<String> emptyEntries = PluginHelper.getEmptyKeys(propertiesOut); if (!emptyEntries.isEmpty()) { @@ -243,15 +263,22 @@ if (showEmpty) { int index = 0; for (String key : emptyEntries) { - buffer.append("\n - ").append(index++).append("/").append(size).append(" : ").append(key); + buffer.append("\n - "); + buffer.append(index++); + buffer.append("/"); + buffer.append(size); + buffer.append(" : "); + buffer.append(key); } } else { - buffer.append(" (use -Di18n.showEmpty to see these entries)"); + buffer.append(" (use -Di18n.showEmpty to see these" + + " entries)"); } getLog().warn(buffer.toString()); } else { if (!silent && verbose) { - getLog().info("bundle " + locale + " is valid (no empty entries)."); + getLog().info("bundle " + locale + " is valid (no empty" + + " entries)."); } } } @@ -266,11 +293,6 @@ copyFile(f, dst); } -// protected void copyFile(File src, File dst) throws IOException { -// PluginHelper.copy(src, dst); -// } - - public String getEncoding() { return encoding; } Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/BundleMojo.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/BundleMojo.java 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/BundleMojo.java 2010-03-07 16:03:59 UTC (rev 1703) @@ -20,11 +20,14 @@ package org.nuiton.i18n.plugin; import org.nuiton.i18n.bundle.I18nBundleEntry; -import org.nuiton.i18n.bundle.I18nBundleFactory; +import org.nuiton.i18n.bundle.I18nBundleUtil; +import org.nuiton.i18n.init.DefaultI18nInitializer; import org.nuiton.io.SortedProperties; import org.nuiton.plugin.PluginHelper; -import java.io.*; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; import java.net.URL; import java.util.*; import java.util.Map.Entry; @@ -34,11 +37,11 @@ * <p/> * Cela génère un merge de tous les fichiers i18n utilisés en un seul. * <p/> - * On utilise la dépendance sur les artifacts pour connaitre l'ordre le chargement - * des bundles. + * On utilise la dépendance sur les artifacts pour connaitre l'ordre le + * chargement des bundles. * <p/> - * Si dans un bundle childs, la valeur de la clef est vide, on conserve alors celui - * du parent, + * Si dans un bundle childs, la valeur de la clef est vide, on conserve alors + * celui du parent, * <p/> * Ainsi on obtient un bundle dont toutes les clefs sont traduites. * <p/> @@ -47,11 +50,10 @@ * nombreuses dépendances (au dessus de 100 deps cela peut prendre plusieurs * secondes, ce qui 'est pas acceptable). * <p/> - * On a ajoute un second mode d'initialisation dans la clesse I18n pour n'utiliser - * qu'un seul bundle et courcircuiter le chargement couteux... - * * + * 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 + * @author tchemit <chemit@codelutin.com> * @goal bundle * @phase generate-resources * @execute goal=collect-i18n-artifacts @@ -60,6 +62,7 @@ * @since 0.12 */ public class BundleMojo extends AbstractI18nBundleMojo { + /** * Repertoire ou generer les bundles. * @@ -68,6 +71,7 @@ * @since 1.0.0 */ protected File bundleOutputDir; + /** * Nom du bundle a generer. * @@ -76,16 +80,20 @@ * @since 1.0.2 */ protected String bundleOutputName; + /** - * Un drapeau pour vérifier que les bundles ne contiennent pas d'entrées vides. + * Un drapeau pour vérifier que les bundles ne contiennent pas d'entrées + * vides. * * @parameter expression="${i18n.checkBundle}" default-value="true" * @required * @since 1.0.0 */ protected boolean checkBundle; + /** - * Un drapeau pour afficher les entrées vides. (nécessite {@link #checkBundle} activé). + * Un drapeau pour afficher les entrées vides. (nécessite {@link + * #checkBundle} activé). * * @parameter expression="${i18n.showEmpty}" default-value="false" * @required @@ -109,25 +117,32 @@ protected void doAction() throws Exception { long t00 = System.nanoTime(); + String version = getProject().getVersion(); + version = PluginHelper.removeSnapshotSuffix(version); + if (!silent) { getLog().info("config - bundle name : " + bundleOutputName); getLog().info("config - basedir : " + bundleOutputDir); getLog().info("config - locales : " + Arrays.toString(locales)); + getLog().info("config - version : " + version); } - Map<Locale, String> bundleDico = new LinkedHashMap<Locale, String>(locales.length); + Map<Locale, String> bundleDico = + new LinkedHashMap<Locale, String>(locales.length); for (Locale locale : locales) { long t0 = System.nanoTime(); - File bundleOut = getI18nFile(bundleOutputDir, bundleOutputName, locale, false); + File bundleOut = getI18nFile(bundleOutputDir, bundleOutputName, + locale, false); if (!silent) { getLog().info("generate bundle for locale " + locale); } - SortedProperties propertiesOut = new SortedProperties(encoding, false); + SortedProperties propertiesOut = + new SortedProperties(encoding, false); StringBuilder buffer = new StringBuilder(); URL[] urls = getCollectI18nResources(locale); @@ -138,26 +153,33 @@ for (URL url : urls) { long t000 = System.nanoTime(); - I18nBundleEntry bundleEntry = new I18nBundleEntry(url, locale, null); + I18nBundleEntry bundleEntry = + new I18nBundleEntry(url, locale, null); bundleEntry.load(propertiesOut); String strPath = bundleEntry.getPath().toString(); int index = strPath.indexOf("i18n/"); buffer.append(',').append(strPath.substring(index)); if (verbose) { - getLog().info("loaded " + bundleEntry.getPath() + " in " + PluginHelper.convertTime(t000, System.nanoTime())); + getLog().info( + "loaded " + bundleEntry.getPath() + " in " + + PluginHelper.convertTime(t000, System.nanoTime())); } } if (buffer.length() > 0) { bundleDico.put(locale, buffer.substring(1)); if (!silent) { - getLog().info("bundles for locale : " + bundleDico.get(locale)); + getLog().info( + "bundles for locale : " + bundleDico.get(locale)); } } propertiesOut.store(bundleOut); if (!silent && verbose) { - getLog().info("bundle created in " + PluginHelper.convertTime(t0, System.nanoTime()) + " (detected sentences : " + propertiesOut.size() + ")"); + getLog().info( + "bundle created in " + + PluginHelper.convertTime(t0, System.nanoTime()) + + " (detected sentences : " + propertiesOut.size() + ")"); } if (checkBundle) { checkBundle(locale, propertiesOut, showEmpty); @@ -167,136 +189,57 @@ // 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); + String f = String.format(DefaultI18nInitializer.UNIQUE_BUNDLE_DEF, + bundleOutputName); File defOut = new File(bundleOutputDir, f); if (!silent) { - getLog().info("prepare i18n definition " + defOut.getAbsolutePath()); + getLog().info("prepare i18n definition " + + defOut.getAbsolutePath()); } SortedProperties p = new SortedProperties(encoding, false); - p.setProperty(I18nBundleFactory.BUNDLE_DEF_LOCALES, bundles); + p.setProperty(DefaultI18nInitializer.BUNDLE_DEF_LOCALES, bundles); + p.setProperty(DefaultI18nInitializer.BUNDLE_DEF_VERSION, version); for (Entry<Locale, String> e : bundleDico.entrySet()) { - p.setProperty(I18nBundleFactory.BUNDLES_FOR_LOCALE + e.getKey().toString(), e.getValue()); + p.setProperty(DefaultI18nInitializer.BUNDLES_FOR_LOCALE + + e.getKey().toString(), e.getValue()); } - p.store(new FileOutputStream(defOut), null); + FileOutputStream out = new FileOutputStream(defOut); + try { + p.store(out, null); + } finally { + out.close(); + } if (!silent && verbose) { - getLog().info("done in " + PluginHelper.convertTime(t00, System.nanoTime())); + getLog().info("done in " + + PluginHelper.convertTime(t00, System.nanoTime())); } } -// @Override -// public void execute() throws MojoExecutionException, MojoFailureException { -// -// if ("pom".equals(project.getPackaging()) || "site".equals(project.getPackaging())) { -// return; -// } -// -// long t00 = System.nanoTime(); -// -// try { -// init(); -// } catch (Exception e) { -// throw new MojoExecutionException("could not init gaol for reason " + e.getMessage(), e); -// } -// -// if (!silent) { -// getLog().info("config - bundle name : " + bundleOutputName); -// getLog().info("config - basedir : " + bundleOutputDir); -// getLog().info("config - locales : " + Arrays.toString(locales)); -// } -// -// Map<Locale, String> bundleDico = new LinkedHashMap<Locale, String>(locales.length); -// -// try { -// -// for (Locale locale : locales) { -// -// long t0 = System.nanoTime(); -// -// File bundleOut = getI18nFile(bundleOutputDir, bundleOutputName, locale, false); -// -// if (!silent) { -// getLog().info("generate bundle for locale " + locale); -// } -// -// SortedProperties propertiesOut = new SortedProperties(encoding, false); -// StringBuilder buffer = new StringBuilder(); -// -// URL[] urls = getCollectI18nResources(locale); -// if (urls.length == 0) { -// getLog().warn("no bundle for locale " + locale); -// continue; -// } -// -// for (URL url : urls) { -// long t000 = System.nanoTime(); -// I18nBundleEntry bundleEntry = new I18nBundleEntry(url, locale, null); -// bundleEntry.load(propertiesOut); -// String strPath = bundleEntry.getPath().toString(); -// int index = strPath.indexOf("i18n/"); -// -// buffer.append(',').append(strPath.substring(index)); -// if (verbose) { -// getLog().info("loaded " + bundleEntry.getPath() + " in " + PluginHelper.convertTime(t000, System.nanoTime())); -// } -// } -// -// if (buffer.length() > 0) { -// bundleDico.put(locale, buffer.substring(1)); -// if (!silent) { -// getLog().info("bundles for locale : " + bundleDico.get(locale)); -// } -// } -// propertiesOut.store(bundleOut); -// if (!silent && verbose) { -// getLog().info("bundle created in " + PluginHelper.convertTime(t0, System.nanoTime()) + " (detected sentences : " + propertiesOut.size() + ")"); -// } -// if (checkBundle) { -// checkBundle(locale, propertiesOut, showEmpty); -// } -// } -// -// // 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); -// if (!silent) { -// getLog().info("prepare i18n definition " + defOut.getAbsolutePath()); -// } -// SortedProperties p = new SortedProperties(encoding, false); -// p.setProperty(I18nBundleFactory.BUNDLE_DEF_LOCALES, bundles); -// for (Entry<Locale, String> e : bundleDico.entrySet()) { -// p.setProperty(I18nBundleFactory.BUNDLES_FOR_LOCALE + e.getKey().toString(), e.getValue()); -// } -// p.store(new FileOutputStream(defOut), null); -// -// if (!silent && verbose) { -// getLog().info("done in " + PluginHelper.convertTime(t00, System.nanoTime())); -// } -// } catch (IOException e) { -// getLog().error("File Error I/O ", e); -// throw new MojoFailureException("File Error I/O "); -// } -// } - - @Override protected URL[] getCollectI18nResources(Locale locale) throws IOException { File file = getCollectOutputFile(locale, false); if (!file.exists()) { - return new URL[0]; + return I18nBundleUtil.EMPTY_URL_ARRAY; } + URL[] urls = getLinesAsURL(file); + return urls; + } - List<URL> urls = new ArrayList<URL>(); - BufferedReader stream = new BufferedReader(new InputStreamReader(new FileInputStream(file))); - while (stream.ready()) { - String line = stream.readLine().trim(); + /** + * TODO Move this in PluginHelper. + * + * @param src the source file to read + * @return the url instanciated from lines of the source file. + * @throws IOException if any pb while reading file + */ + public static URL[] getLinesAsURL(File src) throws IOException { + List<URL> result = new ArrayList<URL>(); + for (String line : PluginHelper.getLines(src)) { if (!line.isEmpty()) { - URL f = new URL(line); - urls.add(f); + result.add(new URL(line)); } } - return urls.toArray(new URL[urls.size()]); + return result.toArray(new URL[result.size()]); } } Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/CollectI18nArtifactsMojo.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/CollectI18nArtifactsMojo.java 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/CollectI18nArtifactsMojo.java 2010-03-07 16:03:59 UTC (rev 1703) @@ -38,6 +38,7 @@ import java.io.IOException; import java.net.URL; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -47,7 +48,7 @@ * <p/> * Created: 24 déc. 2009 * - * @author Tony Chemit <chemit@codelutin.com> Copyright Code Lutin + * @author tchemit <chemit@codelutin.com> * @version $Revision$ * <p/> * Mise a jour: $Date$ par : @@ -59,6 +60,7 @@ * @since 1.0.2 */ public class CollectI18nArtifactsMojo extends AbstractI18nBundleMojo { + /** * Local Repository. * @@ -68,6 +70,7 @@ * @since 1.0.2 */ protected ArtifactRepository localRepository; + /** * Dependency tree builder component. * @@ -75,6 +78,7 @@ * @since 1.0.2 */ protected DependencyTreeBuilder dependencyTreeBuilder; + /** * Artifact Factory component. * @@ -82,6 +86,7 @@ * @since 1.0.2 */ protected ArtifactFactory factory; + /** * Artifact metadata source component. * @@ -89,6 +94,7 @@ * @since 1.0.2 */ protected ArtifactMetadataSource artifactMetadataSource; + /** * Artifact collector component. * @@ -120,7 +126,8 @@ for (Locale locale : locales) { if (!silent) { - getLog().info("generate collected i18n artifacts for locale " + locale); + getLog().info("generate collected i18n artifacts for locale " + + locale); } URL[] urls = getCollectI18nResources(locale); @@ -133,7 +140,9 @@ storeCollectI18nResources(bundleOut, urls); - getLog().info("collected " + urls.length + " i18n artifacts for locale " + locale + " stored in " + bundleOut); + getLog().info("collected " + urls.length + + " i18n artifacts for locale " + locale + + " stored in " + bundleOut); } } @@ -187,14 +196,16 @@ // } @Override - protected URL[] getCollectI18nResources(Locale locale) throws IOException, DependencyTreeBuilderException { + protected URL[] getCollectI18nResources(Locale locale) + throws IOException, DependencyTreeBuilderException { // la locale par defaut est la première Locale defaultLocale = locales[0]; List<URL> urls = new ArrayList<URL>(); for (I18nArtifact artifact : i18nArtifacts) { - I18nBundleEntry[] bundleEntries = artifact.getBundleEntries(locale, defaultLocale); + I18nBundleEntry[] bundleEntries = + artifact.getBundleEntries(locale, defaultLocale); for (I18nBundleEntry bundleEntry : bundleEntries) { URL path = bundleEntry.getPath(); @@ -207,7 +218,8 @@ return urls.toArray(new URL[urls.size()]); } - protected void storeCollectI18nResources(File bundleOut, URL[] urls) throws IOException { + protected void storeCollectI18nResources(File bundleOut, URL[] urls) + throws IOException { StringBuilder buffer = new StringBuilder(); for (URL path : urls) { @@ -222,17 +234,20 @@ } /** - * 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. + * 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.io.IOException while detecting bundles from artifacts - * @throws org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException - * if any error while building the depencendy tree + * @return les artifacts i18nables triés par leur ordre de chargement dans + * le système i18n. + * @throws IOException while detecting bundles from artifacts + * @throws DependencyTreeBuilderException if any error while building the + * depencendy tree */ - protected I18nArtifact[] detectI18nArtifacts() throws IOException, DependencyTreeBuilderException { + protected I18nArtifact[] detectI18nArtifacts() + throws IOException, DependencyTreeBuilderException { - Map<Artifact, I18nArtifact> dico = new java.util.HashMap<Artifact, I18nArtifact>(); + Map<Artifact, I18nArtifact> dico = new HashMap<Artifact, I18nArtifact>(); I18nArtifact i18nArtifact; for (Object o : project.getArtifacts()) { @@ -249,14 +264,17 @@ } } - ArtifactFilter artifactFilter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME); + ArtifactFilter artifactFilter + = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME); - DependencyNode rootNode = dependencyTreeBuilder.buildDependencyTree(project, localRepository, factory, + DependencyNode rootNode = dependencyTreeBuilder.buildDependencyTree( + project, localRepository, factory, artifactMetadataSource, artifactFilter, collector); - List<Artifact> artifacts = new java.util.ArrayList<Artifact>(dico.keySet()); + List<Artifact> artifacts = new ArrayList<Artifact>(dico.keySet()); - DependencyUtil.sortArtifacts(rootNode, artifacts, getLog().isDebugEnabled()); + DependencyUtil.sortArtifacts(rootNode, artifacts, + getLog().isDebugEnabled()); // l'artifact du projet est traite en dernier car s'il possède des // bundles alors ils doivent etre charge en dernier Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/GenerateMojo.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/GenerateMojo.java 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/GenerateMojo.java 2010-03-07 16:03:59 UTC (rev 1703) @@ -93,7 +93,8 @@ SortedProperties propertiesOut = new SortedProperties(encoding); if (!strictMode) { - // si on n'est pas en mode strict, on doit push back in bundle out, all the bundle src keys + // si on n'est pas en mode strict, on doit push back in + // bundle out, all the bundle src keys propertiesOut.putAll(propertiesSrc); } propertiesOut.load(bundleOut); Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/GetterMojo.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/GetterMojo.java 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/GetterMojo.java 2010-03-07 16:03:59 UTC (rev 1703) @@ -57,7 +57,9 @@ getLog().info("config - locales : " + Arrays.toString(locales)); } - File bundleGetters = new File(out.getAbsolutePath() + File.separatorChar + artifactId + ".properties"); + File bundleGetters = new File(out.getAbsolutePath() + + File.separatorChar + artifactId + + ".properties"); createNewFile(bundleGetters); DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir(out); @@ -74,7 +76,9 @@ deleteFile(bundleGetter); } if (!silent) { - getLog().info("import getter " + bundleGetter.getName() + " in " + PluginHelper.convertTime(System.nanoTime() - t0)); + String time = PluginHelper.convertTime(System.nanoTime() - t0); + getLog().info("import getter " + bundleGetter.getName() + + " in " + time); } } @@ -161,11 +165,13 @@ * * @param in le fichier entrant * @param out le fichier sortant - * @throws IOException si problème pendant la sauvegarde ou fichier non trouvé. + * @throws IOException si problème pendant la sauvegarde ou fichier non + * trouvé. */ protected void concactProperties(File in, File out) throws IOException { SortedProperties propertiesIn = new SortedProperties(encoding).load(in); - SortedProperties propertiesOut = new SortedProperties(encoding).load(out); + SortedProperties propertiesOut = + new SortedProperties(encoding).load(out); propertiesOut.putAll(propertiesIn); propertiesOut.store(out); } Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/I18nArtifact.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/I18nArtifact.java 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/I18nArtifact.java 2010-03-07 16:03:59 UTC (rev 1703) @@ -1,4 +1,4 @@ -/** +/* * *##% * I18n :: Maven Plugin * Copyright (C) 2007 - 2009 CodeLutin @@ -25,7 +25,7 @@ import org.apache.maven.artifact.Artifact; import org.nuiton.i18n.bundle.I18nBundle; import org.nuiton.i18n.bundle.I18nBundleEntry; -import org.nuiton.i18n.bundle.I18nBundleFactory; +import org.nuiton.i18n.bundle.I18nBundleUtil; import java.io.File; import java.io.IOException; @@ -35,24 +35,28 @@ import java.util.Locale; /** - * @author chemit + * @author tchemit <chemit@codelutin.com> * @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(); + url = artifact.getFile().toURI().toURL(); } - public I18nArtifact(Artifact artifact, File file) throws MalformedURLException { + public I18nArtifact(Artifact artifact, + File file) throws MalformedURLException { this.artifact = artifact; - this.url = file.toURI().toURL(); + url = file.toURI().toURL(); } public Artifact getArtifact() { @@ -65,14 +69,15 @@ public I18nBundleEntry[] getBundleEntries(Locale l, Locale defaultLocale) { if (bundles == null) { - throw new NullPointerException("le bundleManager n'a pas ete initialise!"); + throw new NullPointerException( + "le bundleManager n'a pas ete initialise!"); } - return I18nBundleFactory.getBundleEntries(l, defaultLocale, bundles); + return I18nBundleUtil.getBundleEntries(l, defaultLocale, bundles); } public boolean detectBundles() throws IOException { - URL[] i18nUrls = I18nBundleFactory.getURLs(url); + URL[] i18nUrls = I18nBundleUtil.getURLs(url); if (i18nUrls == null || i18nUrls.length == 0) { // aucune url sur un fichier de traduction trouve @@ -83,20 +88,22 @@ return false; } - List<I18nBundle> listBundles = I18nBundleFactory.detectBundles(i18nUrls); + List<I18nBundle> listBundles = + I18nBundleUtil.detectBundles(i18nUrls); if (listBundles.isEmpty()) { // pas de bundle instancie (cela ne devrait jamais arrive...) return false; } - this.bundles = listBundles.toArray(new I18nBundle[listBundles.size()]); + bundles = listBundles.toArray(new I18nBundle[listBundles.size()]); return true; } @Override public String toString() { - return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion(); + return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + + artifact.getVersion(); } } Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/I18nLogger.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/I18nLogger.java 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/I18nLogger.java 2010-03-07 16:03:59 UTC (rev 1703) @@ -29,7 +29,7 @@ /** * Le logger utilisé par les mojo. * - * @author chemit + * @author tchemit <chemit@codelutin.com> * @since 0.9 */ public class I18nLogger extends SystemStreamLog { @@ -50,7 +50,9 @@ protected String parser; public I18nLogger(AbstractI18nMojo parser) { - this.parser = "i18n:" + Introspector.decapitalize(parser.getClass().getSimpleName()) + " on " + parser.getArtifactId(); + this.parser = "i18n:" + Introspector.decapitalize( + parser.getClass().getSimpleName()) + " on " + + parser.getArtifactId(); } @Override @@ -64,18 +66,22 @@ } public void infoEntry(String action, CharSequence content) { - print(0, "INFO", action, entry.toString() + (content == null ? "" : " - " + content.toString())); + print(0, "INFO", action, + entry.toString() + + (content == null ? "" : " - " + content.toString())); } public void infoFile(String action, String content) { - print(2, "INFO", action, file.toString() + (content == null ? "" : " - " + content)); + print(2, "INFO", action, file.toString() + + (content == null ? "" : " - " + content)); } public void infoAction(String action, String content) { - print(2, "INFO", action, (content == null ? "" : " - " + content)); + print(2, "INFO", action, content == null ? "" : " - " + content); } - private void print(int start, String prefix, String context, String content) { + private void print(int start, String prefix, String context, + String content) { StringBuilder sb = new StringBuilder(); sb.append("[").append(prefix).append("] [").append(parser).append("] "); @@ -113,7 +119,8 @@ s += "(total time:" + PluginHelper.convertTime(now - all) + ")"; } if (nbFiles > 0) { - s += " ( ~ " + PluginHelper.convertTime(((now - all) / (nbFiles))) + " / file)"; + s += " ( ~ " + + PluginHelper.convertTime((now - all) / nbFiles) + " / file)"; } return s; } Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/SourceEntry.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/SourceEntry.java 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/SourceEntry.java 2010-03-07 16:03:59 UTC (rev 1703) @@ -32,21 +32,24 @@ import java.util.List; /** - * A simple model for a sourceEntry represents by a basedir and includes and/or exlucdes pattern. + * A simple model for a sourceEntry represents by a basedir and includes + * and/or exlucdes pattern. * <p/> * The class offers the usefull method : * {@link #getIncludedFiles(File, String[], String[])} * <p/> * to obtain the list of files from * the {@link #basedir} directory which respects the {@link #includes} and/or - * {@link #excludes} patterns using an internal {@link DirectoryScanner} object. + * {@link #excludes} patterns using an internal {@link DirectoryScanner} + * object. * <p/> - * Note : <b>The class does not extends <code>DirectoryScanner</code> since we DO not want - * to expose his methods.</b> + * Note : <b>The class does not extends <code>DirectoryScanner</code> since + * we DO not want to expose his methods.</b> * - * @author tony + * @author tchemit <chemit@codelutin.com> */ public class SourceEntry { + /** * If you want to restrict use of the entry, set the class name goal to * this property via {@link #setSpecificGoal(String)}. @@ -58,7 +61,9 @@ protected File basedir; protected String[] includes; + protected String[] excludes; + /** * Files to be find */ @@ -123,14 +128,16 @@ * <p/> * * @param file the file path to test - * @return <code>true</code> if file is up to date and do not need to be parsed + * @return {@code true} if file is up to date and do not need to be parsed * @see FileUpdater */ public final boolean isFileUptodate(File file) { return updater != null && updater.isFileUpToDate(file); } - public String[] getIncludedFiles(File defaultBasedir, String[] defaultIncludes, String[] defaultExcludes) { + public String[] getIncludedFiles(File defaultBasedir, + String[] defaultIncludes, + String[] defaultExcludes) { // normalized entry if (!hasSrc()) { setBasedir(defaultBasedir); @@ -168,10 +175,16 @@ return sb.toString(); } - public String[] getIncludedFiles(File basedir, String[] defaultIncludes, String[] defaultExcludes, URLClassLoader loader, List<String> annotationClass, Log log) { + public String[] getIncludedFiles(File basedir, + String[] defaultIncludes, + String[] defaultExcludes, + URLClassLoader loader, + List<String> annotationClass, + Log log) { List<String> result = new ArrayList<String>(); - for (String s : getIncludedFiles(basedir, defaultIncludes, defaultExcludes)) { + for (String s : + getIncludedFiles(basedir, defaultIncludes, defaultExcludes)) { if (filterByAnnotation(s, loader, annotationClass, log)) { result.add(s); } @@ -179,10 +192,14 @@ return result.toArray(new String[result.size()]); } - protected boolean filterByAnnotation(String file, URLClassLoader loader, List<String> annotationClass, Log log) { + protected boolean filterByAnnotation(String file, + URLClassLoader loader, + List<String> annotationClass, + Log log) { - Annotation annotation = getAnnotation(file, loader, annotationClass, log); + Annotation annotation = getAnnotation(file, loader, annotationClass, + log); boolean result = annotation != null; @@ -210,7 +227,10 @@ } } - public Annotation getAnnotation(String file, URLClassLoader loader, List<String> annotationClass, Log log) { + public Annotation getAnnotation(String file, + URLClassLoader loader, + List<String> annotationClass, + Log log) { Class<?> currentClass = getClass(file, loader, log); @@ -218,7 +238,8 @@ Annotation[] annos = currentClass.getAnnotations(); if (annos != null && annos.length > 0) { for (Annotation anno : annos) { - if (annotationClass.contains(anno.annotationType().getName())) { + if (annotationClass.contains( + anno.annotationType().getName())) { return anno; } } @@ -231,12 +252,17 @@ } public Class<?> getClass(File file, URLClassLoader loader, Log log) { - String f = file.getAbsolutePath().substring(basedir.getAbsolutePath().length() + 1); + String f = file.getAbsolutePath().substring( + basedir.getAbsolutePath().length() + 1); return getClass(f, loader, log); } - public Annotation getAnnotation(File file, URLClassLoader loader, List<String> annotationClass, Log log) { - String f = file.getAbsolutePath().substring(basedir.getAbsolutePath().length() + 1); + public Annotation getAnnotation(File file, + URLClassLoader loader, + List<String> annotationClass, + Log log) { + String f = file.getAbsolutePath().substring( + basedir.getAbsolutePath().length() + 1); return getAnnotation(f, loader, annotationClass, log); } Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/AbstractI18nParserMojo.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/AbstractI18nParserMojo.java 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/AbstractI18nParserMojo.java 2010-03-07 16:03:59 UTC (rev 1703) @@ -77,18 +77,21 @@ * @parameter expression="${i18n.keysModifier}" default-value="false" */ protected boolean keysModifier; + /** * treate default entry * * @parameter expression="${i18n.treateDefaultEntry}" default-value="true" */ protected boolean treateDefaultEntry; + /** * Source entries (src+includes+excludes) . * * @parameter expression="${i18n.entries}" */ protected I18nSourceEntry[] entries; + /** * flag to display touched files while parsing. * <p/> @@ -99,6 +102,7 @@ * @since 0.9 */ protected boolean showTouchedFiles; + /** * flag to save at eachfile treated the getter file * @@ -106,6 +110,7 @@ * @since 0.9 */ protected boolean safeMode; + /** * flag to save previous getter in a backup before doing parsing. * <p/> @@ -115,16 +120,24 @@ * @since 1.0.2 */ protected boolean backupGetter; + /** * Liste des évènements */ protected List<ParserEvent> events = new ArrayList<ParserEvent>(); + protected SortedProperties result; + protected SortedProperties oldParser; + protected SortedProperties oldLanguage; + protected int fileTreated = 0; + protected long t0; + protected boolean touchFile; + protected List<File> treadedFiles; public boolean isStrictMode() { @@ -142,13 +155,16 @@ // out.mkdirs(); // evenements if (keysModifier) { - addParserEvent(KeysModifier.getInstance(getKeyModifierStart(), getKeyModifierEnd(), encoding)); + addParserEvent(KeysModifier.getInstance( + getKeyModifierStart(), getKeyModifierEnd(), encoding)); } // check there is something to treate if (entries == null || entries.length == 0 && !treateDefaultEntry) { // nothing to do - throw new IllegalStateException("No entry defined and treateDefaultEntry is false, will skip the goal."); + throw new IllegalStateException( + "No entry defined and treateDefaultEntry is false, " + + "will skip the goal."); } treadedFiles = new ArrayList<File>(); @@ -163,7 +179,8 @@ getLog().info("config - safeMode is on (could be slower)."); } if (!silent && strictMode) { - getLog().info("config - strictMode is on (all files will be parsed)."); + getLog().info("config - strictMode is on (all files will be" + + " parsed)."); } // Reprise sur un ancien parsing @@ -178,7 +195,8 @@ } // Anciennes cles disponnibles - //fixme : pourquoi on utilise un bundle precis ? le premier ici, je ne comprends pas + //fixme : pourquoi on utilise un bundle precis ? le premier ici, + // je ne comprends pas File oldLanguageFile = getI18nFile(src, artifactId, locales[0], true); oldLanguage.load(oldLanguageFile); @@ -199,7 +217,9 @@ } } else { if (!silent) { - getLog().info(getVerboseLog().getLogEntry("Parsing is done. [treated file(s) : " + i + '/' + fileTreated + "]", fileTreated, 0, t0)); + getLog().info(getVerboseLog().getLogEntry( + "Parsing is done. [treated file(s) : " + i + '/' + + fileTreated + "]", fileTreated, 0, t0)); } addGetter(); } @@ -291,7 +311,9 @@ long t000 = System.nanoTime(); int nbFiles = entry.getFiles().length; if (!silent && verbose) { - vLog.infoEntry("start", vLog.getLogEntry("[incoming file(s) : " + entry.getFoudFiles() + "]", 0, 0, 0)); + vLog.infoEntry("start", vLog.getLogEntry( + "[incoming file(s) : " + entry.getFoudFiles() + "]", + 0, 0, 0)); } // launch parser for found files @@ -306,7 +328,9 @@ } fileTreated += nbFiles; if (!silent && verbose) { - vLog.infoEntry("end", vLog.getLogEntry("[treated file(s) : " + nbFiles + "]", nbFiles, t000, t00)); + vLog.infoEntry("end", vLog.getLogEntry( + "[treated file(s) : " + nbFiles + "]", nbFiles, t000, + t00)); } t00 = System.nanoTime(); } @@ -323,7 +347,8 @@ getLog().info("add default entry"); } boolean hasEntries = entries != null && entries.length > 0; - I18nSourceEntry[] tmp = new I18nSourceEntry[hasEntries ? entries.length + 1 : 1]; + I18nSourceEntry[] tmp = + new I18nSourceEntry[hasEntries ? entries.length + 1 : 1]; if (hasEntries) { System.arraycopy(entries, 0, tmp, 0, entries.length); } @@ -344,7 +369,8 @@ for (int i = 0, max = files.length; i < max; i++) { String file1 = files[i]; long t000 = System.nanoTime(); - String fileName = entry.getBasedir().getAbsolutePath() + File.separator + file1; + String fileName = entry.getBasedir().getAbsolutePath() + + File.separator + file1; File file = new File(fileName); for (ParserEvent event : events) { event.eventChangeFile(file); @@ -359,10 +385,11 @@ } parseFile(file); - //TC-20090214 pour des questions de performance, on ne sauvegarde pas - // a chaque traitement de fichier, les clefs mais une fois pour chaque - // source entry - // Detection de nouvelles cles, sauvegarde du fichier pour pouvoir le restaurer en cas de plantage + //TC-20090214 pour des questions de performance, on ne sauvegarde + // pas a chaque traitement de fichier, les clefs mais une fois pour + // chaque source entry + // Detection de nouvelles cles, sauvegarde du fichier pour pouvoir + // le restaurer en cas de plantage if (safeMode) { if (size != result.size()) { saveGetterFile(); Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/I18nSourceEntry.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/I18nSourceEntry.java 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/I18nSourceEntry.java 2010-03-07 16:03:59 UTC (rev 1703) @@ -33,6 +33,8 @@ */ public class I18nSourceEntry extends SourceEntry { + public static final String[] EMPTY_STRING_ARRAY = new String[0]; + public boolean init(AbstractI18nParserMojo mojo) { if (!useForGoal(mojo.getClass().getSimpleName())) { // skip not for this goal @@ -51,8 +53,8 @@ if (mojo.isStrictMode() || updater == null) { // mojo strict mode or not updater, so force all files - skipFiles = new String[0]; - this.files = filesForEntry; + skipFiles = EMPTY_STRING_ARRAY; + files = filesForEntry; return false; } @@ -72,12 +74,13 @@ if (!todo) { // skip, no file out-of -date skipMessage = "all files are up to date."; - this.skipFiles = listSkipFiles.toArray(new String[listSkipFiles.size()]); - this.files = new String[0]; + skipFiles = listSkipFiles.toArray( + new String[listSkipFiles.size()]); + files = EMPTY_STRING_ARRAY; return true; } - this.skipFiles = listSkipFiles.toArray(new String[listSkipFiles.size()]); - this.files = listFiles.toArray(new String[listFiles.size()]); + skipFiles = listSkipFiles.toArray(new String[listSkipFiles.size()]); + files = listFiles.toArray(new String[listFiles.size()]); return false; } @@ -88,6 +91,8 @@ * @return the list of relative path of files for the given entry */ protected String[] getFilesForEntry(AbstractI18nParserMojo mojo) { - return getIncludedFiles(mojo.getDefaultBasedir(), mojo.getDefaultIncludes(), mojo.getDefaultExcludes()); + return getIncludedFiles(mojo.getDefaultBasedir(), + mojo.getDefaultIncludes(), + mojo.getDefaultExcludes()); } } Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/KeysModifier.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/KeysModifier.java 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/KeysModifier.java 2010-03-07 16:03:59 UTC (rev 1703) @@ -48,20 +48,28 @@ // Modification des clés dans le fichier protected List<String> newKeys; + protected boolean needModifiedFile; + protected String patternLeft; + protected String patternRight; + protected String encoding; // Interface protected JLabel name = new JLabel(); + protected JLabel path = new JLabel(); + protected JTextField key = new JTextField(); + protected JTextField pattern = new JTextField(".*"); + protected JCheckBox onlyNewKey = new JCheckBox(); + protected JButton next = new JButton("Next >>"); - protected JButton next = new JButton("Next >>"); private static KeysModifier keysModifier; /** @@ -72,7 +80,9 @@ * @param encoding encoding * @return the shared instance with new config */ - public static KeysModifier getInstance(String patternLeft, String patternRight, String encoding) { + public static KeysModifier getInstance(String patternLeft, + String patternRight, + String encoding) { if (keysModifier == null) { keysModifier = new KeysModifier(); } @@ -149,10 +159,13 @@ throw new ParserException(e); } - for (Iterator<String> iterator = newKeys.iterator(); iterator.hasNext();) { + for (Iterator<String> iterator = newKeys.iterator(); + iterator.hasNext();) { String oldKey = iterator.next(); String realKey = iterator.next(); - Pattern p = Pattern.compile("(" + patternLeft + ")(" + Pattern.quote(oldKey) + ")(" + patternRight + ")"); + Pattern p = Pattern.compile("(" + patternLeft + + ")(" + Pattern.quote(oldKey) + + ")(" + patternRight + ")"); Matcher matcher = p.matcher(content); matcher.region(region, content.length()); matcher.find(); @@ -173,7 +186,9 @@ key.setText(keyI18n); newKeys.add(key.getText()); repaint(); - if (isVisible() && keyI18n.matches(pattern.getText()) && (!onlyNewKey.isSelected() || newKey)) { + if (isVisible() && + keyI18n.matches(pattern.getText()) && + (!onlyNewKey.isSelected() || newKey)) { try { wait(); } catch (InterruptedException e) { @@ -185,7 +200,8 @@ @Override public String eventGetRealKey() { newKeys.add(key.getText()); - needModifiedFile |= !newKeys.get(newKeys.size() - 1).equals(newKeys.get(newKeys.size() - 2)); + needModifiedFile |= !newKeys.get(newKeys.size() - 1).equals( + newKeys.get(newKeys.size() - 2)); return key.getText(); } Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/Parser.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/Parser.java 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/Parser.java 2010-03-07 16:03:59 UTC (rev 1703) @@ -35,7 +35,7 @@ /** * Lancement du parser * - * @throws java.io.IOException if any io pb + * @throws IOException if any io pb */ void parse() throws IOException; @@ -50,8 +50,8 @@ * Parse une partie du fichier * * @param file le fichier à parser - * @param args ? TODO + * @param line la ligne à parser */ - void parseLine(File file, String args); + void parseLine(File file, String line); } Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/ParserEvent.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/ParserEvent.java 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/ParserEvent.java 2010-03-07 16:03:59 UTC (rev 1703) @@ -32,22 +32,22 @@ /** * Méthode appelée quand on change de fichier parsé * - * @param file + * @param file le nouveau fichier a parser */ void eventChangeFile(File file); /** * Méthode appelée après le parsing du fichier * - * @param file + * @param file le prochain fichier a parser */ void eventNextFile(File file); /** * Méthode appelée quand on change de clé * - * @param keyI18n - * @param newKey + * @param keyI18n la clef i18n + * @param newKey la nouvelle clef i18n */ void eventChangeKey(String keyI18n, boolean newKey); Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/ParserException.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/ParserException.java 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/ParserException.java 2010-03-07 16:03:59 UTC (rev 1703) @@ -30,7 +30,6 @@ private static final long serialVersionUID = 1L; public ParserException() { - super(); } public ParserException(String message, Throwable cause) { Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaMojo.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaMojo.java 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaMojo.java 2010-03-07 16:03:59 UTC (rev 1703) @@ -22,6 +22,7 @@ import org.nuiton.i18n.plugin.SourceEntry; import org.nuiton.i18n.plugin.parser.AbstractI18nParserMojo; +import org.nuiton.i18n.plugin.parser.I18nSourceEntry; import org.nuiton.i18n.plugin.parser.ParserEvent; import org.nuiton.i18n.plugin.parser.ParserException; import org.nuiton.io.FileUpdater; @@ -71,7 +72,7 @@ @Override public String[] getDefaultExcludes() { - return new String[]{}; + return I18nSourceEntry.EMPTY_STRING_ARRAY; } @Override @@ -112,7 +113,8 @@ LineNumberReader lnr; String line = null; try { - lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(srcFile))); + lnr = new LineNumberReader(new InputStreamReader( + new FileInputStream(srcFile))); while (lnr.ready()) { line = lnr.readLine(); Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserValidationMojo.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserValidationMojo.java 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserValidationMojo.java 2010-03-07 16:03:59 UTC (rev 1703) @@ -20,6 +20,7 @@ package org.nuiton.i18n.plugin.parser.impl; import org.nuiton.i18n.plugin.SourceEntry; +import org.nuiton.i18n.plugin.parser.I18nSourceEntry; import org.nuiton.io.FileUpdater; import org.nuiton.io.MirroredFileUpdater; import org.xml.sax.EntityResolver; @@ -45,24 +46,28 @@ public class ParserValidationMojo extends ParserXmlMojo { final URL xworksResource = getClass().getResource("/xwork-validator-1.0.2.dtd"); + /** * Source entries (src+includes+excludes) . * * @parameter expression="${i18n.defaultIncludes}" default-value="**\/**-validation.xml" */ protected String defaultIncludes; + /** * Where jaxx files should have been generated. * * @parameter expression="${i18n.cp}" default-value="${basedir}/target/classes" */ protected File cp; + /** * Regles xml. * * @parameter expression="${i18n.rulesValidation}" default-value="validation.rules" */ protected String rulesValidation; + /** * default src for an entry. * @@ -70,6 +75,7 @@ * @required */ protected File defaultBasedir; + /** * Always use the local xowrks dtd to increase performance. * @@ -85,7 +91,7 @@ @Override public String[] getDefaultExcludes() { - return new String[]{}; + return I18nSourceEntry.EMPTY_STRING_ARRAY; } @Override @@ -95,12 +101,13 @@ @Override public FileUpdater newFileUpdater(SourceEntry entry) { - return new MirroredFileUpdater("", "", entry.getBasedir(), this.cp) { + return new MirroredFileUpdater("", "", entry.getBasedir(), cp) { @Override public File getMirrorFile(File f) { - String file = f.getAbsolutePath().substring(this.prefixSourceDirecotory); - return new File(this.destinationDirectory + File.separator + file); + String file = + f.getAbsolutePath().substring(prefixSourceDirecotory); + return new File(destinationDirectory + File.separator + file); } }; } @@ -152,13 +159,16 @@ return new EntityResolver() { - public static final String XWORK_PUBLIC_ID = "-//OpenSymphony Group//XWork Validator 1.0.2//EN"; + public static final String XWORK_PUBLIC_ID = + "-//OpenSymphony Group//XWork Validator 1.0.2//EN"; boolean useLocal = useLocalResolver; @Override - public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException, IOException { if (getLog().isDebugEnabled()) { - getLog().debug("publicID:" + publicId + ", systemId:" + systemId); + getLog().debug("publicID:" + publicId + ", systemId:" + + systemId); } if (XWORK_PUBLIC_ID.equals(publicId)) { if (!useLocal) { @@ -171,7 +181,8 @@ openConnection.setConnectTimeout(1000); try { openConnection.connect(); - return new InputSource(openConnection.getInputStream()); + return new InputSource( + openConnection.getInputStream()); } catch (SocketTimeoutException e) { useLocal = true; } catch (IOException e) { @@ -180,7 +191,8 @@ } // use directly local resource - InputSource inputSource = new InputSource(xworksResource.openStream()); + InputSource inputSource = + new InputSource(xworksResource.openStream()); return inputSource; } // use the default behaviour Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserXmlMojo.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserXmlMojo.java 2010-03-07 16:02:33 UTC (rev 1702) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserXmlMojo.java 2010-03-07 16:03:59 UTC (rev 1703) @@ -55,9 +55,13 @@ * @required */ protected File defaultBasedir; + protected String rules; + protected XPathFactory factory; + protected XPath xpath; + protected DocumentBuilder builder; /** @@ -81,10 +85,11 @@ @Override public void init() throws Exception { super.init(); - this.factory = XPathFactory.newInstance(); - this.rules = getRules(getFileRules()); - this.xpath = factory.newXPath(); - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + factory = XPathFactory.newInstance(); + rules = getRules(getFileRules()); + xpath = factory.newXPath(); + DocumentBuilderFactory documentBuilderFactory = + DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); // never forget this! try { @@ -98,7 +103,9 @@ } } catch (ParserConfigurationException ex) { - throw new IllegalStateException("could not load DocumentBuilder for reason " + ex.getMessage(), ex); + throw new IllegalStateException( + "could not load DocumentBuilder for reason " + + ex.getMessage(), ex); } } @@ -128,7 +135,8 @@ parseLine(file, node.getTextContent()); } if (safeMode) { - // Détection de nouvelles clés, sauvegarde du fichier pour pouvoir le restaurer en cas de plantage + // Détection de nouvelles clés, sauvegarde du fichier pour + // pouvoir le restaurer en cas de plantage if (size != result.size()) { saveGetterFile(); } @@ -213,7 +221,8 @@ inputStream = classLoader.getResourceAsStream(fileRules); } if (inputStream == null) { - throw new ParserException("could not found file of rules : " + fileRules); + throw new ParserException( + "could not found file of rules : " + fileRules); } inputStream = new BufferedInputStream(inputStream); @@ -247,9 +256,12 @@ in.close(); // Suppression String txt = sb.toString().trim(); - txt = txt.replaceAll("#.*\n", ""); // suppression des commentaires - txt = txt.replaceAll("\\s+", " | "); // contruction du xpath avec des ou - txt = txt.replaceAll("(^ \\| )|( \\| $)", ""); // suppression des ou de début ee fin + // suppression des commentaires + txt = txt.replaceAll("#.*\n", ""); + // contruction du xpath avec des ou + txt = txt.replaceAll("\\s+", " | "); + // suppression des ou de début ee fin + txt = txt.replaceAll("(^ \\| )|( \\| $)", ""); return txt; } }