Nuiton-utils-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
September 2008
- 6 participants
- 79 discussions
[Lutinutil-commits] r1145 - in maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin: . parser parser/event parser/impl
by ruchaud@users.labs.libre-entreprise.org 29 Sep '08
by ruchaud@users.labs.libre-entreprise.org 29 Sep '08
29 Sep '08
Author: ruchaud
Date: 2008-09-29 08:49:13 +0000 (Mon, 29 Sep 2008)
New Revision: 1145
Added:
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/ParserEvent.java
Removed:
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/ParserEvent.java
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/parser/AbstractI18nParser.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/KeysModifier.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJava.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJavaActionConfig.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserXml.java
Log:
D?\195?\169placement des fichiers dans la nouvelle arborescence (correction)
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 2008-09-29 08:47:23 UTC (rev 1144)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java 2008-09-29 08:49:13 UTC (rev 1145)
@@ -18,7 +18,7 @@
package org.codelutin.i18n.plugin;
-import org.codelutin.i18n.plugin.parser.event.ParserEvent;
+import org.codelutin.i18n.plugin.parser.ParserEvent;
import org.apache.maven.plugin.AbstractMojo;
import org.codelutin.i18n.plugin.PluginHelper;
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 2008-09-29 08:47:23 UTC (rev 1144)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java 2008-09-29 08:49:13 UTC (rev 1145)
@@ -19,7 +19,7 @@
import org.codelutin.i18n.plugin.SourceEntry;
import org.codelutin.i18n.plugin.AbstractI18nPlugin;
-import org.codelutin.i18n.plugin.parser.event.ParserEvent;
+import org.codelutin.i18n.plugin.parser.ParserEvent;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.codelutin.i18n.plugin.PluginHelper;
Copied: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/ParserEvent.java (from rev 1143, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/ParserEvent.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/ParserEvent.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/ParserEvent.java 2008-09-29 08:49:13 UTC (rev 1145)
@@ -0,0 +1,59 @@
+/*
+ * *##% 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.parser;
+
+import java.io.File;
+
+/**
+ * Permet d'ajouter des évènements sur les parsers
+ *
+ * @author julien
+ */
+public interface ParserEvent {
+
+ /**
+ * M�thode appelée quand on change de fichier parsé
+ *
+ * @param file
+ */
+ public void eventChangeFile(File file);
+
+ /**
+ * Méthode appelée après le parsing du fichier
+ *
+ * @param file
+ */
+ public void eventNextFile(File file);
+
+ /**
+ * M�thode appelée quand on change de clé
+ *
+ * @param keyI18n
+ * @param newKey
+ */
+ public void eventChangeKey(String keyI18n, boolean newKey);
+
+ /**
+ * M�thode appelée pour récupérer la nouvelle valeur de clé
+ *
+ * @return
+ */
+ public String eventGetRealKey();
+
+}
Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/KeysModifier.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/KeysModifier.java 2008-09-29 08:47:23 UTC (rev 1144)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/KeysModifier.java 2008-09-29 08:49:13 UTC (rev 1145)
@@ -18,7 +18,7 @@
package org.codelutin.i18n.plugin.parser.event;
-import org.codelutin.i18n.plugin.parser.event.ParserEvent;
+import org.codelutin.i18n.plugin.parser.ParserEvent;
import org.codelutin.i18n.plugin.parser.ParserException;
import org.codelutin.util.FileUtil;
Deleted: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/ParserEvent.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/ParserEvent.java 2008-09-29 08:47:23 UTC (rev 1144)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/ParserEvent.java 2008-09-29 08:49:13 UTC (rev 1145)
@@ -1,59 +0,0 @@
-/*
- * *##% 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.parser.event;
-
-import java.io.File;
-
-/**
- * Permet d'ajouter des évènements sur les parsers
- *
- * @author julien
- */
-public interface ParserEvent {
-
- /**
- * M�thode appelée quand on change de fichier parsé
- *
- * @param file
- */
- public void eventChangeFile(File file);
-
- /**
- * Méthode appelée après le parsing du fichier
- *
- * @param file
- */
- public void eventNextFile(File file);
-
- /**
- * M�thode appelée quand on change de clé
- *
- * @param keyI18n
- * @param newKey
- */
- public void eventChangeKey(String keyI18n, boolean newKey);
-
- /**
- * M�thode appelée pour récupérer la nouvelle valeur de clé
- *
- * @return
- */
- public String eventGetRealKey();
-
-}
Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJava.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJava.java 2008-09-29 08:47:23 UTC (rev 1144)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJava.java 2008-09-29 08:49:13 UTC (rev 1145)
@@ -20,7 +20,7 @@
import org.apache.maven.project.MavenProject;
import org.codelutin.i18n.plugin.parser.AbstractI18nParser;
-import org.codelutin.i18n.plugin.parser.event.ParserEvent;
+import org.codelutin.i18n.plugin.parser.ParserEvent;
import org.codelutin.i18n.plugin.parser.ParserException;
import org.codelutin.processor.filters.I18nFilter;
import org.codelutin.util.FileUpdaterHelper;
Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJavaActionConfig.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJavaActionConfig.java 2008-09-29 08:47:23 UTC (rev 1144)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJavaActionConfig.java 2008-09-29 08:49:13 UTC (rev 1145)
@@ -17,7 +17,7 @@
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */
package org.codelutin.i18n.plugin.parser.impl;
-import org.codelutin.i18n.plugin.parser.event.ParserEvent;
+import org.codelutin.i18n.plugin.parser.ParserEvent;
import java.io.File;
import java.util.regex.Matcher;
Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserXml.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserXml.java 2008-09-29 08:47:23 UTC (rev 1144)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserXml.java 2008-09-29 08:49:13 UTC (rev 1145)
@@ -19,7 +19,7 @@
package org.codelutin.i18n.plugin.parser.impl;
import org.codelutin.i18n.plugin.parser.AbstractI18nParser;
-import org.codelutin.i18n.plugin.parser.event.ParserEvent;
+import org.codelutin.i18n.plugin.parser.ParserEvent;
import org.codelutin.i18n.plugin.parser.ParserException;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
1
0
[Lutinutil-commits] r1144 - maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin
by ruchaud@users.labs.libre-entreprise.org 29 Sep '08
by ruchaud@users.labs.libre-entreprise.org 29 Sep '08
29 Sep '08
Author: ruchaud
Date: 2008-09-29 08:47:23 +0000 (Mon, 29 Sep 2008)
New Revision: 1144
Removed:
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/ui/
Log:
Suppression de l'ancienne arborescence
1
0
[Lutinutil-commits] r1143 - in maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin: . core extension parser parser/event parser/impl ui
by ruchaud@users.labs.libre-entreprise.org 29 Sep '08
by ruchaud@users.labs.libre-entreprise.org 29 Sep '08
29 Sep '08
Author: ruchaud
Date: 2008-09-29 08:45:36 +0000 (Mon, 29 Sep 2008)
New Revision: 1143
Added:
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/SourceEntry.java
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/Parser.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/ParserException.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/KeysModifier.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/ParserEvent.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJava.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJavaActionConfig.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJavaTabConfig.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJaxx.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserSwixat.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserXml.java
Removed:
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/Generate.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/Getter.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/Parser.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/ParserEvent.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/ParserException.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/SourceEntry.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJava.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJavaActionConfig.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJavaTabConfig.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJaxx.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserSwixat.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserXml.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/ui/KeysModifier.java
Log:
D?\195?\169placement des fichiers dans la nouvelle arborescence
Copied: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java (from rev 1141, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -0,0 +1,161 @@
+/*
+ * *##% 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 org.codelutin.i18n.plugin.parser.event.ParserEvent;
+import org.apache.maven.plugin.AbstractMojo;
+import org.codelutin.i18n.plugin.PluginHelper;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Classe permettant d'obenir les parametres pendant les différentes phases
+ * du plugin.
+ *
+ * @author julien
+ */
+public abstract class AbstractI18nPlugin extends AbstractMojo {
+
+ /**
+ * Langues des bundles generes.
+ *
+ * @parameter expression="${i18n.bundles}" default-value=""
+ * @required
+ */
+ protected String[] bundles;
+
+ /**
+ * Repertoire sources des fichiers i18n.
+ *
+ * @parameter expression="${i18n.src}" default-value="${basedir}/src/resources/i18n"
+ * @required
+ */
+ protected File src;
+
+ /**
+ * Repertoire des fichiers generes i18n.
+ *
+ * @parameter expression="${i18n.out}" default-value="${basedir}/target/gen/i18n"
+ * @required
+ */
+ protected File out;
+
+ /**
+ * Nom du projet.
+ *
+ * @parameter expression="${i18n.artifactId}" default-value="${project.artifactId}"
+ * @readonly
+ */
+ protected String artifactId;
+
+ /**
+ * encoding a utiliser pour charger et sauver les bundles
+ *
+ * @parameter expression="${i18n.encoding}" default-value="${maven.compile.encoding}"
+ * @required
+ */
+ protected String encoding;
+
+ /**
+ * Met les fichiers generes dans le repertoire des sources i18n.
+ *
+ * @parameter expression="${i18n.genSrc}" default-value="true"
+ */
+ protected boolean genSrc;
+
+ /**
+ * Active la modification de cle
+ *
+ * @parameter expression="${i18n.keysModifier}" default-value="false"
+ */
+ protected boolean keysModifier;
+
+ /**
+ * verbose flag
+ *
+ * @parameter expression="${i18n.verbose}" default-value="false"
+ */
+ protected boolean verbose;
+
+ /**
+ * conserve les anciens fichiers de traduction avec un suffix ~
+ *
+ * @parameter expression="${i18n.keepBackup}" default-value="true"
+ */
+ protected boolean keepBackup;
+
+ /**
+ * ne conserve que les clef scannees (et donc traite tous les fichiers)
+ *
+ * @parameter expression="${i18n.strictMode}" default-value="false"
+ */
+ protected boolean strictMode;
+
+ /**
+ * Répertoire de stockage des fichiers i18n pour la recuperation des fichiers
+ * de traduction entre librairie
+ */
+ protected static String DIRECTORY_INSTALL = "i18n" + File.separatorChar;
+
+ /** Liste des évènements */
+ protected List<ParserEvent> events = new ArrayList<ParserEvent>();
+
+ /**
+ * Ajoute un évènement
+ *
+ * @param parserEvent l'évènement d'ajout
+ */
+ protected void addParserEvent(ParserEvent parserEvent) {
+ this.events.add(parserEvent);
+ }
+
+ /**
+ * Supprime un évènement
+ *
+ * @param parserEvent l'évènement de suppression
+ */
+ protected void removeParserEvent(ParserEvent parserEvent) {
+ this.events.remove(parserEvent);
+ }
+
+ /**
+ * Construit une chaine de log formatée.
+ *
+ * @param msg le prefix du message
+ * @param nbFiles le nombre de fichiers actuellement traités
+ * @param time le time de traitement de ce fichier
+ * @param all le temps de traitement de tous les fichiers
+ * @return la chaine de log formatée
+ */
+ protected String getLogEntry(String msg, int nbFiles, long time, long all) {
+ long now = System.nanoTime();
+ long delta = now - time;
+ String s = "[" + artifactId + "] i18n." + getClass().getSimpleName() + " : " + msg;
+ if (time > 0) {
+ s += " (" + PluginHelper.convertTime(delta) + ")";
+ }
+ if (all > 0 && nbFiles > -1) {
+ s += "(total time:" + PluginHelper.convertTime(now - all) + ") ( ~ " + PluginHelper.convertTime(((now - all) / (nbFiles + 1))) + " / file)";
+ }
+ return s;
+ }
+
+}
Copied: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Generate.java (from rev 1141, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/Generate.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Generate.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Generate.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -0,0 +1,106 @@
+/*
+ * *##% 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 org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.codelutin.i18n.plugin.PluginHelper;
+import org.codelutin.i18n.plugin.PluginHelper.I18nProperties;
+import org.codelutin.util.FileUtil;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * Merge des fichiers de propriétés avec les anciens.
+ *
+ * @author julien
+ * @goal gen
+ * @phase generate-resources
+ * @execute goal=get
+ */
+public class Generate extends AbstractI18nPlugin {
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.maven.plugin.AbstractMojo#execute()
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ for (String bundle : bundles) {
+ try {
+ // Merge
+ File bundleSrc = PluginHelper.getI18nFile(src, artifactId, bundle, false);
+ File bundleOut = PluginHelper.getI18nFile(out, artifactId, bundle, false);
+
+ if (bundleSrc.exists()) {
+
+ I18nProperties propertiesSrc = new I18nProperties(encoding).load(bundleSrc);
+
+ I18nProperties propertiesOut = new I18nProperties(encoding);
+
+ if (!strictMode) {
+ // push back in bundle out, all the bundle src keys
+ propertiesOut.putAll(propertiesSrc);
+ }
+ propertiesOut.load(bundleOut);
+
+ // Parcours des clés
+ for (Object key : propertiesOut.keySet()) {
+ Object oldKey = propertiesOut.get(key);
+ Object value = propertiesSrc.get(oldKey);
+
+ // Récupération de la clé si elle a été renommée
+ if (!key.equals(oldKey) && value == null) {
+ value = propertiesSrc.get(key);
+ }
+
+ if (value != null) {
+ propertiesOut.put(key, value);
+ } else {
+ propertiesOut.put(key, "");
+ }
+ }
+
+ //fixme : on devrait laisser le fichier en utf8 ?
+ //propertiesOut.store(bundleOut);
+ propertiesOut.store(new FileOutputStream(bundleOut));
+
+ // Sauvegarde avant copie
+ if (genSrc && keepBackup) {
+ FileUtil.copy(bundleSrc, PluginHelper.getI18nFileBackup(src, artifactId, bundle));
+ }
+
+ getLog().info("Merge bundle " + bundleSrc.getAbsolutePath());
+ }
+
+ if (genSrc) {
+ // Copie des fichiers dans les sources
+ FileUtil.copy(bundleOut, bundleSrc);
+ getLog().info("Copy bundle " + bundleSrc.getAbsolutePath());
+ }
+
+ } catch (IOException e) {
+ getLog().error("File Error I/O ", e);
+ throw new MojoFailureException("File Error I/O ");
+ }
+ }
+ }
+
+}
Copied: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Getter.java (from rev 1141, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/Getter.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Getter.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Getter.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -0,0 +1,95 @@
+/*
+ * *##% 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 org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.util.DirectoryScanner;
+import org.codelutin.i18n.plugin.PluginHelper;
+import org.codelutin.i18n.plugin.PluginHelper.I18nProperties;
+import org.codelutin.util.FileUtil;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+/**
+ * Recupere les différents fichiers des parsers en un fichier de proprietes.
+ *
+ * @author julien
+ * @goal get
+ * @phase generate-resources
+ */
+public class Getter extends AbstractI18nPlugin {
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.maven.plugin.AbstractMojo#execute()
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ try {
+ File bundleGetters = new File(out.getAbsolutePath() + File.separatorChar + artifactId + ".properties");
+ bundleGetters.createNewFile();
+
+ DirectoryScanner ds = new DirectoryScanner();
+ ds.setBasedir(out);
+ ds.setIncludes(new String[]{"*.getter"});
+ ds.scan();
+ String[] files = ds.getIncludedFiles();
+
+ // Fusion des fichiers propriétés des différents parsers
+ for (String file : files) {
+ File bundleGetter = PluginHelper.getGetterFile(out, file, false);
+ concactProperties(bundleGetter, bundleGetters);
+ if (genSrc) {
+ bundleGetter.delete();
+ }
+ getLog().info("Create bundle with " + bundleGetter.getAbsolutePath());
+ }
+
+ // Création des bundles
+ for (String bundle : bundles) {
+ File bundleOut = PluginHelper.getI18nFile(out, artifactId, bundle, false);
+ FileUtil.copy(bundleGetters, bundleOut);
+ getLog().info("Generate bundle " + bundleOut.getAbsolutePath());
+ }
+
+ bundleGetters.delete();
+ } catch (IOException e) {
+ getLog().error("File Error I/O ", e);
+ throw new MojoFailureException("File Error I/O");
+ }
+ }
+
+ /**
+ * Concatene deux fichiers de proprietes
+ *
+ * @param in le fichier entrant
+ * @param out le fichier sortant
+ * @throws FileNotFoundException si fichier non trouvé
+ * @throws IOException si problème pendant la sauvegarde
+ */
+ protected void concactProperties(File in, File out) throws IOException {
+ I18nProperties propertiesIn = new I18nProperties(encoding).load(in);
+
+ I18nProperties propertiesOut = new I18nProperties(encoding).load(out);
+ propertiesOut.putAll(propertiesIn);
+ propertiesOut.store(out);
+ }
+}
Copied: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/SourceEntry.java (from rev 1141, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/SourceEntry.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/SourceEntry.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/SourceEntry.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -0,0 +1,217 @@
+/*
+* *##% 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 org.apache.maven.plugin.logging.Log;
+import org.codehaus.plexus.util.DirectoryScanner;
+
+import java.io.File;
+import java.lang.annotation.Annotation;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * 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.
+ * <p/>
+ * Note : <b>The class does not extends <code>DirectoryScanner</code> since we DO not want
+ * to expose his methods.</b>
+ *
+ * @author tony
+ */
+public class SourceEntry {
+ /**
+ * If you want to restrict use of the entry, set the class name goal to
+ * this property via {@link #setSpecificGoal(String)}.
+ * <p/>
+ * If let to <code>null</code>, all goals can use this entry.
+ */
+ protected String specificGoal = null;
+
+ protected File basedir;
+
+ protected String[] includes;
+
+ protected String[] excludes;
+
+ public String[] getExcludes() {
+ return excludes;
+ }
+
+ public void setExcludes(String[] excludes) {
+ this.excludes = excludes;
+ }
+
+ public String[] getIncludes() {
+ return includes;
+ }
+
+ public void setIncludes(String[] includes) {
+ this.includes = includes;
+ }
+
+ public File getBasedir() {
+ return basedir;
+ }
+
+ public void setBasedir(File basedir) {
+ this.basedir = basedir;
+ }
+
+ public String getSpecificGoal() {
+ return specificGoal;
+ }
+
+ public void setSpecificGoal(String specificGoal) {
+ this.specificGoal = specificGoal;
+ }
+
+ public boolean useForGoal(String goal) {
+ return specificGoal == null || specificGoal.equalsIgnoreCase(goal);
+ }
+
+ public boolean hasSrc() {
+ return basedir != null;
+ }
+
+ public boolean hasIncludes() {
+ return includes != null && includes.length > 0;
+ }
+
+ public boolean hasExcludes() {
+ return excludes != null && excludes.length > 0;
+ }
+
+ public String[] getIncludedFiles(File defaultBasedir, String[] defaultIncludes, String[] defaultExcludes) {
+ // normalized entry
+ if (!hasSrc()) {
+ setBasedir(defaultBasedir);
+ }
+ if (!hasIncludes()) {
+ setIncludes(defaultIncludes);
+ }
+ if (!hasExcludes()) {
+ setExcludes(defaultExcludes);
+ }
+ // init directory scanner
+ DirectoryScanner ds = new DirectoryScanner();
+ ds.setBasedir(getBasedir());
+ ds.setIncludes(getIncludes());
+ if (hasExcludes()) {
+ ds.setExcludes(getExcludes());
+ }
+ // scan
+ ds.scan();
+ // get found files
+ String[] foundFiles;
+ foundFiles = ds.getIncludedFiles();
+ return foundFiles;
+ }
+
+ public String toString() {
+ StringBuilder sb = new StringBuilder("basedir:").append(basedir);
+ if (includes != null) {
+ sb.append(", includes:").append(Arrays.toString(includes));
+ }
+ if (excludes != null) {
+ sb.append(", excludes:").append(Arrays.toString(excludes));
+ }
+ return sb.toString();
+ }
+
+ 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)) {
+ if (filterByAnnotation(s, loader, annotationClass, log)) {
+ result.add(s);
+ }
+ }
+ return result.toArray(new String[result.size()]);
+ }
+
+ protected boolean filterByAnnotation(String file, URLClassLoader loader, List<String> annotationClass, Log log) {
+
+
+ Annotation annotation = getAnnotation(file, loader, annotationClass, log);
+
+ boolean result = annotation != null;
+
+ if (result && log.isDebugEnabled()) {
+ log.debug("find i18n annotated file : " + file);
+ }
+ return result;
+ }
+
+ protected String getFQN(String file) {
+ String filePath = file;
+ filePath = filePath.substring(0, filePath.length() - ".java".length());
+ String replaceEx = File.separator.equals("\\") ? "\\\\" : File.separator;
+ return filePath.replaceAll(replaceEx, ".");
+ }
+
+ public Class getClass(String file, URLClassLoader loader, Log log) {
+ String fqn = getFQN(file);
+ try {
+ return loader.loadClass(fqn);
+
+ } catch (Throwable e) {
+ log.warn("could not find class " + fqn + " " + e);
+ return null;
+ }
+ }
+
+ public Annotation getAnnotation(String file, URLClassLoader loader, List<String> annotationClass, Log log) {
+
+ Class<?> currentClass = getClass(file, loader, log);
+
+ try {
+ Annotation[] annos = currentClass.getAnnotations();
+ if (annos != null && annos.length > 0) {
+ for (Annotation anno : annos) {
+ if (annotationClass.contains(anno.annotationType().getName())) {
+ return anno;
+ }
+ }
+ }
+ } catch (Throwable e) {
+ log.warn("could not find annotation for " + file + " " + e);
+ }
+ return null;
+
+ }
+
+ public Class getClass(File file, URLClassLoader loader, Log log) {
+ 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);
+ return getAnnotation(f, loader, annotationClass, log);
+ }
+
+}
Deleted: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java 2008-09-29 08:42:28 UTC (rev 1142)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -1,273 +0,0 @@
-/*
-* *##% 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.core;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.codelutin.i18n.plugin.PluginHelper;
-import org.codelutin.i18n.plugin.PluginHelper.I18nProperties;
-import org.codelutin.i18n.plugin.ui.KeysModifier;
-import org.codelutin.util.FileUpdater;
-import org.codelutin.util.FileUtil;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Abstract implementation for parsing goal.
- *
- * @author tony
- */
-public abstract class AbstractI18nParser extends AbstractI18nPlugin implements Parser {
-
- /** @return the outGetter to use for the instance (java.getter,...) */
- protected abstract String getOutGetter();
-
- /** @return the starting regex expression to catch keys in key modifier */
- protected abstract String getKeyModifierStart();
-
- /** @return the ending regex expression to catch keys in key modifier */
- protected abstract String getKeyModifierEnd();
-
- /** @return the default includes to add to directory scanner */
- protected abstract String[] getDefaultIncludes();
-
- /** @return the default excludes to add to directory scanner */
- protected abstract String[] getDefaultExcludes();
-
- /** @return the default src directory to use in directory scanner */
- protected abstract File getDefaultBasedir();
-
- /**
- * treate default entry
- *
- * @parameter expression="${i18n.treateDefault}" default-value="true"
- */
- protected boolean treateDefaultEntry;
-
- /**
- * Source entries (src+includes+excludes) .
- *
- * @parameter expression="${i18n.entries}"
- */
- protected SourceEntry[] entries;
-
- protected I18nProperties result;
-
- protected I18nProperties oldParser;
-
- protected I18nProperties oldLanguage;
- protected int fileTreated = 0;
- protected long t0;
-
- protected boolean touchFile;
- protected List<File> treadedFiles;
-
- protected SourceEntry currentEntry;
-
- protected FileUpdater updater;
-
- public void init() {
- t0 = System.nanoTime();
- result = new I18nProperties(encoding);
- oldParser = new I18nProperties(encoding);
- oldLanguage = new I18nProperties(encoding);
- out.mkdirs();
- // evenements
- if (keysModifier) {
- addParserEvent(KeysModifier.getInstance(getKeyModifierStart(), getKeyModifierEnd(), encoding));
- }
- treadedFiles = new ArrayList<File>();
- }
-
- /**
- * Test if a file is up to date and not to be treated.
- * <p/>
- * This method is called on a file only in not {@link #strictMode}.
- * <p/>
- * If {@link #updater} is null, then it considers that file as always to be treated.
- *
- * @param file the file path to test
- * @return <code>true</code> if file is up to date and do not need to be parsed
- * @see FileUpdater
- */
- protected final boolean isFileUptodate(File file) {
- return updater != null && updater.isFileUpToDate(file);
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.maven.plugin.AbstractMojo#execute()
- */
- public void execute() throws MojoExecutionException, MojoFailureException {
-
- init();
- if (entries == null || entries.length == 0 && !treateDefaultEntry) {
- // nothing to do
- return;
- }
- try {
- // Reprise sur un ancien parsing
- File oldParserFile = PluginHelper.getGetterFile(out, getOutGetter(), true);
- File saveFile = PluginHelper.getGetterFileBackup(out, getOutGetter());
-
- oldParser.load(oldParserFile);
- FileUtil.copy(oldParserFile, saveFile);
-
- // Anciennes cles disponnibles
- //fixme : pourquoi on utilise un bundle precis ? le premier ici, je ne comprends pas
- File oldLanguageFile = PluginHelper.getI18nFile(src, artifactId, bundles[0], true);
-
- oldLanguage.load(oldLanguageFile);
-
- // Parsing
- parse();
-
- // Suppression du fichier sauvegarder
- saveFile.delete();
-
- int i = treadedFiles.size();
- getLog().info(getLogEntry(" success <getter:" + getOutGetter() + "> [treated file(s) : " + i + '/' + fileTreated + "]", fileTreated, 0, t0));
-
- } catch (Exception e) {
- getLog().error("Error code parsing ", e);
- throw new MojoFailureException("Error code parsing");
- }
-
- }
-
- /**
- * launch the parse on every given entries.
- *
- * @throws IOException if any io pb
- */
- public void parse() throws IOException {
- if (treateDefaultEntry) {
- addDefaultEntry();
- }
- long t00 = System.nanoTime();
- for (SourceEntry entry : entries) {
- if (!entry.useForGoal(getClass().getSimpleName())) {
- if (verbose) {
- getLog().debug("skip entry " + entry.toString());
- }
- continue;
- }
- currentEntry = entry;
- // get found files
- String[] foundFiles = getFilesForEntry(entry);
- long t000 = System.nanoTime();
- if (verbose) {
- getLog().debug(getLogEntry(" parse <" + entry + "> [incoming file(s) : " + foundFiles.length + "]", 0, 0, 0));
- } else {
- getLog().info(getLogEntry(" parse <" + entry.getBasedir() + "> [incoming file(s) : " + foundFiles.length + "]", 0, 0, 0));
- }
- // launch parser for found files
- parseEntry(entry.getBasedir(), foundFiles);
- fileTreated += foundFiles.length;
- if (verbose) {
- getLog().debug(getLogEntry(" success <" + entry.getBasedir() + "> [treated file(s) : " + foundFiles.length + "]", foundFiles.length - 1, t000, t00));
- }
- t00 = System.nanoTime();
- }
- }
-
- /**
- * Obtain all the relative path of files to treate for a given entry.
- *
- * @param entry the given entry
- * @return the list of relative path of files for the given entry
- */
- protected String[] getFilesForEntry(SourceEntry entry) {
- return entry.getIncludedFiles(getDefaultBasedir(), getDefaultIncludes(), getDefaultExcludes());
- }
-
- /**
- * Add the default entry to entries given in configuration.
- * <p/>
- * This is a convinient method to simplify the configuration of the plugin.
- */
- protected void addDefaultEntry() {
- List<SourceEntry> list;
-
- if (entries == null || entries.length == 0) {
- list = new ArrayList<SourceEntry>();
- } else {
- list = new ArrayList<SourceEntry>(Arrays.asList(entries));
- }
- list.add(new SourceEntry());
- entries = list.toArray(new SourceEntry[list.size()]);
- }
-
- /**
- * launch parsing on a given entry.
- *
- * @param basedir the basedir of the entry
- * @param files the relative path of files to be treated for the entry.
- * @throws IOException if any io pb.
- */
- protected void parseEntry(File basedir, String[] files) throws IOException {
- long t00 = System.nanoTime();
- for (int i = 0; i < files.length; i++) {
- String file1 = files[i];
- long t000 = System.nanoTime();
- String fileName = basedir.getAbsolutePath() + File.separator + file1;
- File file = new File(fileName);
- for (ParserEvent event : events) {
- event.eventChangeFile(file);
- }
- touchFile = false;
- int size = result.size();
- if (strictMode || !isFileUptodate(file)) {
- // on parse toujours en mode strict ou quand le fichier n'est pas à jour
- getLog().info("parseFile " + file);
- parseFile(file);
- }
-
- // Detection de nouvelles cles, sauvegarde du fichier pour pouvoir le restaurer en cas de plantage
- if (size != result.size()) {
- saveGetterFile();
- }
- if (touchFile) {
- if (verbose) {
- getLog().info("touched file " + file);
- }
- treadedFiles.add(file);
- if (verbose) {
- getLog().debug(getLogEntry(fileName, i, t000, t00));
- }
- }
- for (ParserEvent event : events) {
- event.eventNextFile(file);
- }
- }
- }
-
- /**
- * Save the result in the getter file.
- *
- * @throws IOException if any io pb
- */
- protected void saveGetterFile() throws IOException {
- File getterFile = PluginHelper.getGetterFile(out, getOutGetter(), false);
- result.store(getterFile);
- }
-}
Deleted: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java 2008-09-29 08:42:28 UTC (rev 1142)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -1,160 +0,0 @@
-/*
- * *##% 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.core;
-
-import org.apache.maven.plugin.AbstractMojo;
-import org.codelutin.i18n.plugin.PluginHelper;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Classe permettant d'obenir les parametres pendant les différentes phases
- * du plugin.
- *
- * @author julien
- */
-public abstract class AbstractI18nPlugin extends AbstractMojo {
-
- /**
- * Langues des bundles generes.
- *
- * @parameter expression="${i18n.bundles}" default-value=""
- * @required
- */
- protected String[] bundles;
-
- /**
- * Repertoire sources des fichiers i18n.
- *
- * @parameter expression="${i18n.src}" default-value="${basedir}/src/resources/i18n"
- * @required
- */
- protected File src;
-
- /**
- * Repertoire des fichiers generes i18n.
- *
- * @parameter expression="${i18n.out}" default-value="${basedir}/target/gen/i18n"
- * @required
- */
- protected File out;
-
- /**
- * Nom du projet.
- *
- * @parameter expression="${i18n.artifactId}" default-value="${project.artifactId}"
- * @readonly
- */
- protected String artifactId;
-
- /**
- * encoding a utiliser pour charger et sauver les bundles
- *
- * @parameter expression="${i18n.encoding}" default-value="${maven.compile.encoding}"
- * @required
- */
- protected String encoding;
-
- /**
- * Met les fichiers generes dans le repertoire des sources i18n.
- *
- * @parameter expression="${i18n.genSrc}" default-value="true"
- */
- protected boolean genSrc;
-
- /**
- * Active la modification de cle
- *
- * @parameter expression="${i18n.keysModifier}" default-value="false"
- */
- protected boolean keysModifier;
-
- /**
- * verbose flag
- *
- * @parameter expression="${i18n.verbose}" default-value="false"
- */
- protected boolean verbose;
-
- /**
- * conserve les anciens fichiers de traduction avec un suffix ~
- *
- * @parameter expression="${i18n.keepBackup}" default-value="true"
- */
- protected boolean keepBackup;
-
- /**
- * ne conserve que les clef scannees (et donc traite tous les fichiers)
- *
- * @parameter expression="${i18n.strictMode}" default-value="false"
- */
- protected boolean strictMode;
-
- /**
- * Répertoire de stockage des fichiers i18n pour la recuperation des fichiers
- * de traduction entre librairie
- */
- protected static String DIRECTORY_INSTALL = "i18n" + File.separatorChar;
-
- /** Liste des évènements */
- protected List<ParserEvent> events = new ArrayList<ParserEvent>();
-
- /**
- * Ajoute un évènement
- *
- * @param parserEvent l'évènement d'ajout
- */
- protected void addParserEvent(ParserEvent parserEvent) {
- this.events.add(parserEvent);
- }
-
- /**
- * Supprime un évènement
- *
- * @param parserEvent l'évènement de suppression
- */
- protected void removeParserEvent(ParserEvent parserEvent) {
- this.events.remove(parserEvent);
- }
-
- /**
- * Construit une chaine de log formatée.
- *
- * @param msg le prefix du message
- * @param nbFiles le nombre de fichiers actuellement traités
- * @param time le time de traitement de ce fichier
- * @param all le temps de traitement de tous les fichiers
- * @return la chaine de log formatée
- */
- protected String getLogEntry(String msg, int nbFiles, long time, long all) {
- long now = System.nanoTime();
- long delta = now - time;
- String s = "[" + artifactId + "] i18n." + getClass().getSimpleName() + " : " + msg;
- if (time > 0) {
- s += " (" + PluginHelper.convertTime(delta) + ")";
- }
- if (all > 0 && nbFiles > -1) {
- s += "(total time:" + PluginHelper.convertTime(now - all) + ") ( ~ " + PluginHelper.convertTime(((now - all) / (nbFiles + 1))) + " / file)";
- }
- return s;
- }
-
-}
Deleted: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/Generate.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/Generate.java 2008-09-29 08:42:28 UTC (rev 1142)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/Generate.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -1,106 +0,0 @@
-/*
- * *##% 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.core;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.codelutin.i18n.plugin.PluginHelper;
-import org.codelutin.i18n.plugin.PluginHelper.I18nProperties;
-import org.codelutin.util.FileUtil;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-/**
- * Merge des fichiers de propriétés avec les anciens.
- *
- * @author julien
- * @goal gen
- * @phase generate-resources
- * @execute goal=get
- */
-public class Generate extends AbstractI18nPlugin {
-
- /*
- * (non-Javadoc)
- * @see org.apache.maven.plugin.AbstractMojo#execute()
- */
- public void execute() throws MojoExecutionException, MojoFailureException {
- for (String bundle : bundles) {
- try {
- // Merge
- File bundleSrc = PluginHelper.getI18nFile(src, artifactId, bundle, false);
- File bundleOut = PluginHelper.getI18nFile(out, artifactId, bundle, false);
-
- if (bundleSrc.exists()) {
-
- I18nProperties propertiesSrc = new I18nProperties(encoding).load(bundleSrc);
-
- I18nProperties propertiesOut = new I18nProperties(encoding);
-
- if (!strictMode) {
- // push back in bundle out, all the bundle src keys
- propertiesOut.putAll(propertiesSrc);
- }
- propertiesOut.load(bundleOut);
-
- // Parcours des clés
- for (Object key : propertiesOut.keySet()) {
- Object oldKey = propertiesOut.get(key);
- Object value = propertiesSrc.get(oldKey);
-
- // Récupération de la clé si elle a été renommée
- if (!key.equals(oldKey) && value == null) {
- value = propertiesSrc.get(key);
- }
-
- if (value != null) {
- propertiesOut.put(key, value);
- } else {
- propertiesOut.put(key, "");
- }
- }
-
- //fixme : on devrait laisser le fichier en utf8 ?
- //propertiesOut.store(bundleOut);
- propertiesOut.store(new FileOutputStream(bundleOut));
-
- // Sauvegarde avant copie
- if (genSrc && keepBackup) {
- FileUtil.copy(bundleSrc, PluginHelper.getI18nFileBackup(src, artifactId, bundle));
- }
-
- getLog().info("Merge bundle " + bundleSrc.getAbsolutePath());
- }
-
- if (genSrc) {
- // Copie des fichiers dans les sources
- FileUtil.copy(bundleOut, bundleSrc);
- getLog().info("Copy bundle " + bundleSrc.getAbsolutePath());
- }
-
- } catch (IOException e) {
- getLog().error("File Error I/O ", e);
- throw new MojoFailureException("File Error I/O ");
- }
- }
- }
-
-}
Deleted: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/Getter.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/Getter.java 2008-09-29 08:42:28 UTC (rev 1142)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/Getter.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -1,95 +0,0 @@
-/*
- * *##% 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.core;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.codehaus.plexus.util.DirectoryScanner;
-import org.codelutin.i18n.plugin.PluginHelper;
-import org.codelutin.i18n.plugin.PluginHelper.I18nProperties;
-import org.codelutin.util.FileUtil;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-
-/**
- * Recupere les différents fichiers des parsers en un fichier de proprietes.
- *
- * @author julien
- * @goal get
- * @phase generate-resources
- */
-public class Getter extends AbstractI18nPlugin {
-
- /*
- * (non-Javadoc)
- * @see org.apache.maven.plugin.AbstractMojo#execute()
- */
- public void execute() throws MojoExecutionException, MojoFailureException {
- try {
- File bundleGetters = new File(out.getAbsolutePath() + File.separatorChar + artifactId + ".properties");
- bundleGetters.createNewFile();
-
- DirectoryScanner ds = new DirectoryScanner();
- ds.setBasedir(out);
- ds.setIncludes(new String[]{"*.getter"});
- ds.scan();
- String[] files = ds.getIncludedFiles();
-
- // Fusion des fichiers propriétés des différents parsers
- for (String file : files) {
- File bundleGetter = PluginHelper.getGetterFile(out, file, false);
- concactProperties(bundleGetter, bundleGetters);
- if (genSrc) {
- bundleGetter.delete();
- }
- getLog().info("Create bundle with " + bundleGetter.getAbsolutePath());
- }
-
- // Création des bundles
- for (String bundle : bundles) {
- File bundleOut = PluginHelper.getI18nFile(out, artifactId, bundle, false);
- FileUtil.copy(bundleGetters, bundleOut);
- getLog().info("Generate bundle " + bundleOut.getAbsolutePath());
- }
-
- bundleGetters.delete();
- } catch (IOException e) {
- getLog().error("File Error I/O ", e);
- throw new MojoFailureException("File Error I/O");
- }
- }
-
- /**
- * Concatene deux fichiers de proprietes
- *
- * @param in le fichier entrant
- * @param out le fichier sortant
- * @throws FileNotFoundException si fichier non trouvé
- * @throws IOException si problème pendant la sauvegarde
- */
- protected void concactProperties(File in, File out) throws IOException {
- I18nProperties propertiesIn = new I18nProperties(encoding).load(in);
-
- I18nProperties propertiesOut = new I18nProperties(encoding).load(out);
- propertiesOut.putAll(propertiesIn);
- propertiesOut.store(out);
- }
-}
Deleted: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/Parser.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/Parser.java 2008-09-29 08:42:28 UTC (rev 1142)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/Parser.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -1,55 +0,0 @@
-/*
- * *##% 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.core;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * Interface type pour la définition d'un nouveau parser.
- * <p/>
- * Une implantation abstraite est proposée : {@link AbstractI18nParser}.
- *
- * @author julien
- */
-public interface Parser {
-
- /**
- * Lancement du parser
- *
- * @throws java.io.IOException if any io pb
- */
- public void parse() throws IOException;
-
- /**
- * Parse sur un fichier
- *
- * @param file le fichier à parser
- */
- public void parseFile(File file);
-
- /**
- * Parse une partie du fichier
- *
- * @param file le fichier à parser
- * @param args ? TODO
- */
- public void parseLine(File file, String args);
-
-}
Deleted: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/ParserEvent.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/ParserEvent.java 2008-09-29 08:42:28 UTC (rev 1142)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/ParserEvent.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -1,59 +0,0 @@
-/*
- * *##% 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.core;
-
-import java.io.File;
-
-/**
- * Permet d'ajouter des évènements sur les parsers
- *
- * @author julien
- */
-public interface ParserEvent {
-
- /**
- * M�thode appelée quand on change de fichier parsé
- *
- * @param file
- */
- public void eventChangeFile(File file);
-
- /**
- * Méthode appelée après le parsing du fichier
- *
- * @param file
- */
- public void eventNextFile(File file);
-
- /**
- * M�thode appelée quand on change de clé
- *
- * @param keyI18n
- * @param newKey
- */
- public void eventChangeKey(String keyI18n, boolean newKey);
-
- /**
- * M�thode appelée pour récupérer la nouvelle valeur de clé
- *
- * @return
- */
- public String eventGetRealKey();
-
-}
Deleted: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/ParserException.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/ParserException.java 2008-09-29 08:42:28 UTC (rev 1142)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/ParserException.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -1,45 +0,0 @@
-/*
- * *##% 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.core;
-
-/**
- * Permet la gestion des exceptions dans les parsers et dans les évènements
- *
- * @author julien
- */
-public class ParserException extends RuntimeException {
-
- private static final long serialVersionUID = 1L;
-
- public ParserException() {
- super();
- }
-
- public ParserException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public ParserException(String message) {
- super(message);
- }
-
- public ParserException(Throwable cause) {
- super(cause);
- }
-}
Deleted: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/SourceEntry.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/SourceEntry.java 2008-09-29 08:42:28 UTC (rev 1142)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/SourceEntry.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -1,217 +0,0 @@
-/*
-* *##% 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.core;
-
-import org.apache.maven.plugin.logging.Log;
-import org.codehaus.plexus.util.DirectoryScanner;
-
-import java.io.File;
-import java.lang.annotation.Annotation;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * 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.
- * <p/>
- * Note : <b>The class does not extends <code>DirectoryScanner</code> since we DO not want
- * to expose his methods.</b>
- *
- * @author tony
- */
-public class SourceEntry {
- /**
- * If you want to restrict use of the entry, set the class name goal to
- * this property via {@link #setSpecificGoal(String)}.
- * <p/>
- * If let to <code>null</code>, all goals can use this entry.
- */
- protected String specificGoal = null;
-
- protected File basedir;
-
- protected String[] includes;
-
- protected String[] excludes;
-
- public String[] getExcludes() {
- return excludes;
- }
-
- public void setExcludes(String[] excludes) {
- this.excludes = excludes;
- }
-
- public String[] getIncludes() {
- return includes;
- }
-
- public void setIncludes(String[] includes) {
- this.includes = includes;
- }
-
- public File getBasedir() {
- return basedir;
- }
-
- public void setBasedir(File basedir) {
- this.basedir = basedir;
- }
-
- public String getSpecificGoal() {
- return specificGoal;
- }
-
- public void setSpecificGoal(String specificGoal) {
- this.specificGoal = specificGoal;
- }
-
- public boolean useForGoal(String goal) {
- return specificGoal == null || specificGoal.equalsIgnoreCase(goal);
- }
-
- public boolean hasSrc() {
- return basedir != null;
- }
-
- public boolean hasIncludes() {
- return includes != null && includes.length > 0;
- }
-
- public boolean hasExcludes() {
- return excludes != null && excludes.length > 0;
- }
-
- public String[] getIncludedFiles(File defaultBasedir, String[] defaultIncludes, String[] defaultExcludes) {
- // normalized entry
- if (!hasSrc()) {
- setBasedir(defaultBasedir);
- }
- if (!hasIncludes()) {
- setIncludes(defaultIncludes);
- }
- if (!hasExcludes()) {
- setExcludes(defaultExcludes);
- }
- // init directory scanner
- DirectoryScanner ds = new DirectoryScanner();
- ds.setBasedir(getBasedir());
- ds.setIncludes(getIncludes());
- if (hasExcludes()) {
- ds.setExcludes(getExcludes());
- }
- // scan
- ds.scan();
- // get found files
- String[] foundFiles;
- foundFiles = ds.getIncludedFiles();
- return foundFiles;
- }
-
- public String toString() {
- StringBuilder sb = new StringBuilder("basedir:").append(basedir);
- if (includes != null) {
- sb.append(", includes:").append(Arrays.toString(includes));
- }
- if (excludes != null) {
- sb.append(", excludes:").append(Arrays.toString(excludes));
- }
- return sb.toString();
- }
-
- 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)) {
- if (filterByAnnotation(s, loader, annotationClass, log)) {
- result.add(s);
- }
- }
- return result.toArray(new String[result.size()]);
- }
-
- protected boolean filterByAnnotation(String file, URLClassLoader loader, List<String> annotationClass, Log log) {
-
-
- Annotation annotation = getAnnotation(file, loader, annotationClass, log);
-
- boolean result = annotation != null;
-
- if (result && log.isDebugEnabled()) {
- log.debug("find i18n annotated file : " + file);
- }
- return result;
- }
-
- protected String getFQN(String file) {
- String filePath = file;
- filePath = filePath.substring(0, filePath.length() - ".java".length());
- String replaceEx = File.separator.equals("\\") ? "\\\\" : File.separator;
- return filePath.replaceAll(replaceEx, ".");
- }
-
- public Class getClass(String file, URLClassLoader loader, Log log) {
- String fqn = getFQN(file);
- try {
- return loader.loadClass(fqn);
-
- } catch (Throwable e) {
- log.warn("could not find class " + fqn + " " + e);
- return null;
- }
- }
-
- public Annotation getAnnotation(String file, URLClassLoader loader, List<String> annotationClass, Log log) {
-
- Class<?> currentClass = getClass(file, loader, log);
-
- try {
- Annotation[] annos = currentClass.getAnnotations();
- if (annos != null && annos.length > 0) {
- for (Annotation anno : annos) {
- if (annotationClass.contains(anno.annotationType().getName())) {
- return anno;
- }
- }
- }
- } catch (Throwable e) {
- log.warn("could not find annotation for " + file + " " + e);
- }
- return null;
-
- }
-
- public Class getClass(File file, URLClassLoader loader, Log log) {
- 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);
- return getAnnotation(f, loader, annotationClass, log);
- }
-
-}
Deleted: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJava.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJava.java 2008-09-29 08:42:28 UTC (rev 1142)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJava.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -1,159 +0,0 @@
-/*
- * *##% 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.extension;
-
-import org.apache.maven.project.MavenProject;
-import org.codelutin.i18n.plugin.core.AbstractI18nParser;
-import org.codelutin.i18n.plugin.core.ParserEvent;
-import org.codelutin.i18n.plugin.core.ParserException;
-import org.codelutin.processor.filters.I18nFilter;
-import org.codelutin.util.FileUpdaterHelper;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.LineNumberReader;
-
-/**
- * Récupération des chaine a traduire depuis les fichiers java.
- *
- * @author julien
- * @goal parserJava
- * @phase generate-resources
- */
-public class ParserJava extends AbstractI18nParser {
-
- /**
- * Source entries (src+includes+excludes) .
- *
- * @parameter expression="${i18n.defaultIncludes}" default-value="**\\/*.java"
- */
- protected String defaultIncludes;
-
- /**
- * default src for an entry.
- *
- * @parameter expression="${i18n.defaultBasedir}" default-value="${basedir}/src/java"
- */
- protected File defaultBasedir;
-
- /**
- * Dependance du projet.
- *
- * @parameter default-value="${project}"
- * @readonly
- */
- protected MavenProject project;
-
- /**
- * Repertoire sources des fichiers i18n.
- *
- * @parameter expression="${i18n.cp}" default-value="${basedir}/target/classes"
- * @required
- */
- protected File cp;
-
- @Override
- protected String[] getDefaultIncludes() {
- return new String[]{defaultIncludes};
- }
-
- @Override
- protected String[] getDefaultExcludes() {
- return new String[]{};
- }
-
- @Override
- protected File getDefaultBasedir() {
- return defaultBasedir;
- }
-
- @Override
- protected String getKeyModifierStart() {
- return "_\\(\\s*\"";
- }
-
- @Override
- protected String getKeyModifierEnd() {
- return "\"\\s*(\\)|,|\\+|$)";
- }
-
- @Override
- protected String getOutGetter() {
- return "java.getter";
- }
-
- protected I18nFilter filter;
-
- @Override
- public void init() {
- super.init();
- filter = new I18nFilter();
- }
-
- protected void parseEntry(File basedir, String[] files) throws IOException {
- // prepare new file updater
- updater = FileUpdaterHelper.newJavaFileUpdater(basedir, cp);
- super.parseEntry(basedir, files);
- }
-
- @Override
- public void parseFile(File srcFile) {
- try {
-
- LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(srcFile)));
- while (lnr.ready()) {
- String line = lnr.readLine();
- parseLine(srcFile, line);
- }
-
- } catch (Exception e) {
- throw new ParserException(e);
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.i18n.plugin.core.Parser#parseLine(java.io.File, java.lang.String)
- */
- @Override
- public void parseLine(File srcFile, String line) {
- String keysSet = filter.parse(line);
-
- if (!keysSet.equals(I18nFilter.EMPTY_STRING)) {
- touchFile = true;
- // Found a set of i18n Strings, split it.
- String[] keys = keysSet.split("=");
- for (String key : keys) {
- String keyModified = key;
- for (ParserEvent event : events) {
- event.eventChangeKey(key, !oldLanguage.containsKey(key));
- keyModified = event.eventGetRealKey();
- }
- if (oldParser.containsKey(key)) {
- result.put(keyModified, oldParser.get(key));
- } else {
- result.put(keyModified, key);
- }
- }
- }
- }
-
-}
Deleted: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJavaActionConfig.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJavaActionConfig.java 2008-09-29 08:42:28 UTC (rev 1142)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJavaActionConfig.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -1,87 +0,0 @@
-/*
-* *##% 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.extension;
-
-import org.codelutin.i18n.plugin.core.ParserEvent;
-
-import java.io.File;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Un parseur java pour scanner les annotations ActionConfig
- *
- * @author chemit
- * @goal parserJavaActionConfig
- * @phase generate-resources
- */
-public class ParserJavaActionConfig extends ParserJava {
-
- protected static final Pattern MATCH_PATTERN = Pattern.compile("(name|shortDescription|longDescription|name2|shortDescription2|longDescription2)\\s*=\\s*\"([\\w|\\.]+)\"(|\\s*|\\s*,\\s*$)");
-
- @Override
- protected String getKeyModifierStart() {
- return "[\\w|\\.]+\\s*=\\s*\"";
- }
-
- @Override
- protected String getKeyModifierEnd() {
- return "\"\\s*(\\)|,|\\+|$)";
- }
-
- @Override
- protected String getOutGetter() {
- return "java-action-config.getter";
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.i18n.plugin.extension.XmlParser#extract(java.lang.String)
- */
-
- public String extract(String i18nString) {
- Matcher matcher = MATCH_PATTERN.matcher(i18nString.trim());
- if (matcher.matches()) {
- return matcher.group(2);
- }
- return null;
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.i18n.plugin.core.Parser#parseLine(java.io.File, java.lang.String)
- */
- @Override
- public void parseLine(File srcFile, String line) {
- String key = extract(line);
- if (key != null) {
- touchFile = true;
- String keyModified = key;
- for (ParserEvent event : events) {
- event.eventChangeKey(key, !oldLanguage.containsKey(key));
- keyModified = event.eventGetRealKey();
- }
- if (oldParser.containsKey(key)) {
- result.put(keyModified, oldParser.get(key));
- } else {
- result.put(keyModified, key);
- }
- }
- }
-
-}
Deleted: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJavaTabConfig.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJavaTabConfig.java 2008-09-29 08:42:28 UTC (rev 1142)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJavaTabConfig.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -1,35 +0,0 @@
-/**
- * *##% 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.extension;
-
-/**
- * Un parseur java pour scanner les annotations TabContentConfig.
- *
- * @author chemit
- * @goal parserJavaTabConfig
- * @phase generate-resources
- */
-public class ParserJavaTabConfig extends ParserJavaActionConfig {
-
- @Override
- protected String getOutGetter() {
- return "java-tab-config.getter";
- }
-
-}
Deleted: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJaxx.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJaxx.java 2008-09-29 08:42:28 UTC (rev 1142)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJaxx.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -1,110 +0,0 @@
-/*
- * *##% 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.extension;
-
-import org.codelutin.util.FileUpdaterHelper;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * Récupération des chaine à traduire depuis les fichiers xml Jaxx.
- *
- * @author julien
- * @goal parserJaxx
- * @phase generate-resources
- */
-public class ParserJaxx extends ParserXml {
-
- /**
- * Source entries (src+includes+excludes) .
- *
- * @parameter expression="${i18n.defaultIncludes}" default-value="**\\/*.jaxx"
- */
- protected String defaultIncludes;
-
- /**
- * Where jaxx files should have been generated.
- *
- * @parameter expression="${i18n.defaultGenerateBasedir}" default-value="${basedir}/target/generated-sources/java"
- */
- protected File defaultGenerateBasedir;
-
- /**
- * Regles xml.
- *
- * @parameter expression="${i18n.rulesJaxx}" default-value="jaxx.rules"
- */
- protected String rulesJaxx;
-
- @Override
- protected String[] getDefaultIncludes() {
- return new String[]{defaultIncludes};
- }
-
- @Override
- protected String[] getDefaultExcludes() {
- return new String[]{};
- }
-
- protected void parseEntry(File basedir, String[] files) throws IOException {
- // prepare new file updater
- updater = FileUpdaterHelper.newJavaFileUpdater(basedir, defaultGenerateBasedir);
- super.parseEntry(basedir, files);
- }
-
- @Override
- protected String getOutGetter() {
- return "jaxx.getter";
- }
-
- @Override
- protected String getKeyModifierStart() {
- return "=\\s*[\"\']";
- }
-
- @Override
- protected String getKeyModifierEnd() {
- return "[\"\']";
- }
-
- @Override
- protected String getFileRules() {
- return rulesJaxx;
- }
-
- @Override
- protected String getCoreFileRules() {
- return "jaxx.rules";
- }
-
- public void setRulesJaxx(String rulesJaxx) {
- this.rulesJaxx = rulesJaxx;
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.i18n.plugin.extension.XmlParser#extract(java.lang.String)
- */
- @Override
- public String extract(String i18nString) {
- return i18nString.length() == 0 ? null : i18nString;
- }
-
-}
Deleted: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserSwixat.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserSwixat.java 2008-09-29 08:42:28 UTC (rev 1142)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserSwixat.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -1,94 +0,0 @@
-/*
- * *##% 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.extension;
-
-/**
- * Recuperation des chaines à traduire depuis les fichiers xml Swixat.
- *
- * @author julien
- * @goal parserSwixat
- * @phase generate-resources
- */
-public class ParserSwixat extends ParserXml {
-
- /**
- * Source entries (src+includes) .
- *
- * @parameter expression="${i18n.defaultIncludes}" default-value="**\\/*.xml"
- */
- protected String defaultIncludes;
-
- /**
- * Source entries (src+excludes) .
- *
- * @parameter expression="${i18n.defaultIncludes}" default-value="**\\/context.xml"
- */
- protected String defaultExcludes;
-
- /**
- * Regles xml.
- *
- * @parameter expression="${i18n.rulesSwixat}" default-value="swixat.rules"
- */
- protected String rulesSwixat;
-
- @Override
- protected String[] getDefaultIncludes() {
- return new String[]{defaultIncludes};
- }
-
- @Override
- protected String[] getDefaultExcludes() {
- return new String[]{defaultExcludes};
- }
-
- @Override
- protected String getKeyModifierStart() {
- return "=\\s*[\"\']";
- }
-
- @Override
- protected String getKeyModifierEnd() {
- return "[\"\']";
- }
-
- @Override
- protected String getOutGetter() {
- return "swixat.getter";
- }
-
- @Override
- protected String getFileRules() {
- return rulesSwixat;
- }
-
- @Override
- protected String getCoreFileRules() {
- return "swixat.rules";
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.i18n.plugin.extension.XmlParser#extract(java.lang.String)
- */
- @Override
- public String extract(String i18nString) {
- return i18nString;
- }
-}
Deleted: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserXml.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserXml.java 2008-09-29 08:42:28 UTC (rev 1142)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserXml.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -1,228 +0,0 @@
-/*
- * *##% 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.extension;
-
-import org.codelutin.i18n.plugin.core.AbstractI18nParser;
-import org.codelutin.i18n.plugin.core.ParserEvent;
-import org.codelutin.i18n.plugin.core.ParserException;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpression;
-import javax.xml.xpath.XPathFactory;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * Récupération des chaines à traduire depuis les fichiers xml.
- *
- * @author julien
- */
-public abstract class ParserXml extends AbstractI18nParser {
-
- /** Taille du buffer pour les lectures/écritures */
- protected static final int BUFFER_SIZE = 8 * 1024;
-
- /**
- * default src for an entry.
- *
- * @parameter expression="${i18n.defaultBasedir}" default-value="${basedir}/src/uimodel"
- * @required
- */
- protected File defaultBasedir;
-
- protected String rules;
- protected XPathFactory factory;
- protected XPath xpath;
-
- /**
- * Fonction d'extraction de la chaine
- *
- * @param i18nString le clef i18n
- * @return la chaine
- */
- public abstract String extract(String i18nString);
-
- /** @return le fichier des rules */
- protected abstract String getFileRules();
-
- /** @return le fichier des rules de base à toujours charger */
- protected abstract String getCoreFileRules();
-
- @Override
- public void init() {
- super.init();
- this.factory = XPathFactory.newInstance();
- this.rules = getRules(getFileRules());
- this.xpath = factory.newXPath();
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.i18n.plugin.core.Parser#parseFile(java.io.File)
- */
- public void parseFile(File file) {
- NodeList list;
- InputSource inputSource = new InputSource(file.getAbsolutePath()); // TODO: A d�placer pour les performances
-
- try {
- int size = result.size();
-
- // Recherche des clés à partir d'un xpath
- XPathExpression expression = xpath.compile(rules);
- list = (NodeList) expression.evaluate(inputSource, XPathConstants.NODESET);
-
- for (int index = 0; index < list.getLength(); index++) {
- Node node = list.item(index);
- parseLine(file, node.getTextContent());
- }
-
- // Détection de nouvelles clés, sauvegarde du fichier pour pouvoir le restaurer en cas de plantage
- if (size != result.size()) {
- saveGetterFile();
- }
- } catch (Exception e) {
- throw new ParserException(e);
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.i18n.plugin.core.Parser#parseLine(java.io.File, java.lang.String)
- */
- public void parseLine(File file, String key) {
- key = extract(key);
- if (key != null) {
- touchFile = true;
- String keyModified = key;
- for (ParserEvent event : events) {
- event.eventChangeKey(key, !oldLanguage.containsKey(key));
- keyModified = event.eventGetRealKey();
- }
-
- if (oldParser.containsKey(key)) {
- result.put(keyModified, oldParser.get(key));
- } else {
- result.put(keyModified, key);
- }
- }
- }
-
- protected File getDefaultBasedir() {
- return defaultBasedir;
- }
-
- /**
- * Récupère le xpath à partir d'un fichier
- *
- * @param fileRules le nom du fichier contant les règles
- * @return le xpath à partir d'un fichier
- */
- private String getRules(String fileRules) {
- StringBuilder result = new StringBuilder();
-
- try {
- String readInputStream;
-
- // load core rules
- readInputStream = loadRulesFile(getCoreFileRules());
- if (verbose) {
- getLog().debug("core rules : " + readInputStream);
- }
- result.append(readInputStream);
-
- if (!fileRules.equals(getCoreFileRules())) {
- // add custom rules
- readInputStream = loadRulesFile(fileRules);
- if (verbose) {
- getLog().debug("custom rules : " + readInputStream);
- }
- result.append(" | ").append(readInputStream);
- }
- } catch (IOException e) {
- throw new ParserException(e);
- }
-
- return result.toString();
- }
-
- private String loadRulesFile(String fileRules) throws IOException {
- File f = new File(fileRules);
-
- InputStream inputStream;
- if (f.exists()) {
- // load from a file
- try {
- inputStream = new FileInputStream(f);
- } catch (FileNotFoundException e) {
- throw new ParserException(e);
- }
- } else {
- // load from classpath
- ClassLoader classLoader = getClass().getClassLoader();
- inputStream = classLoader.getResourceAsStream(fileRules);
- }
- if (inputStream == null) {
- throw new ParserException("could not found file of rules : " + fileRules);
- }
-
- inputStream = new BufferedInputStream(inputStream);
-
- try {
- // Lecture
- String readInputStream;
- readInputStream = readInputStream(inputStream);
- return readInputStream;
- } catch (IOException e) {
- throw new ParserException(e);
- } finally {
- inputStream.close();
- }
- }
-
- /**
- * Permet la lecture d'un InputStream et Suppressions.
- *
- * @param in le flux entrant
- * @return le contenu du flux
- * @throws IOException si problème de lecture dans flux entrant
- */
- private String readInputStream(InputStream in) throws IOException {
- StringBuilder sb = new StringBuilder();
- byte[] buffer = new byte[BUFFER_SIZE];
- while (in.read(buffer, 0, BUFFER_SIZE) != -1) {
- String tmp = new String(buffer);
- sb.append(tmp);
- }
- in.close();
- // Suppression
- String result = sb.toString().trim();
- result = result.replaceAll("#.*\n", ""); // suppression des commentaires
- result = result.replaceAll("\\s+", " | "); // contruction du xpath avec des ou
- result = result.replaceAll("(^ \\| )|( \\| $)", ""); // suppression des ou de début ee fin
- return result;
- }
-}
Copied: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java (from rev 1141, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -0,0 +1,276 @@
+/*
+* *##% 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.parser;
+
+import org.codelutin.i18n.plugin.SourceEntry;
+import org.codelutin.i18n.plugin.AbstractI18nPlugin;
+import org.codelutin.i18n.plugin.parser.event.ParserEvent;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.codelutin.i18n.plugin.PluginHelper;
+import org.codelutin.i18n.plugin.PluginHelper.I18nProperties;
+import org.codelutin.i18n.plugin.parser.event.KeysModifier;
+import org.codelutin.util.FileUpdater;
+import org.codelutin.util.FileUtil;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Abstract implementation for parsing goal.
+ *
+ * @author tony
+ */
+public abstract class AbstractI18nParser extends AbstractI18nPlugin implements Parser {
+
+ /** @return the outGetter to use for the instance (java.getter,...) */
+ protected abstract String getOutGetter();
+
+ /** @return the starting regex expression to catch keys in key modifier */
+ protected abstract String getKeyModifierStart();
+
+ /** @return the ending regex expression to catch keys in key modifier */
+ protected abstract String getKeyModifierEnd();
+
+ /** @return the default includes to add to directory scanner */
+ protected abstract String[] getDefaultIncludes();
+
+ /** @return the default excludes to add to directory scanner */
+ protected abstract String[] getDefaultExcludes();
+
+ /** @return the default src directory to use in directory scanner */
+ protected abstract File getDefaultBasedir();
+
+ /**
+ * treate default entry
+ *
+ * @parameter expression="${i18n.treateDefault}" default-value="true"
+ */
+ protected boolean treateDefaultEntry;
+
+ /**
+ * Source entries (src+includes+excludes) .
+ *
+ * @parameter expression="${i18n.entries}"
+ */
+ protected SourceEntry[] entries;
+
+ protected I18nProperties result;
+
+ protected I18nProperties oldParser;
+
+ protected I18nProperties oldLanguage;
+ protected int fileTreated = 0;
+ protected long t0;
+
+ protected boolean touchFile;
+ protected List<File> treadedFiles;
+
+ protected SourceEntry currentEntry;
+
+ protected FileUpdater updater;
+
+ public void init() {
+ t0 = System.nanoTime();
+ result = new I18nProperties(encoding);
+ oldParser = new I18nProperties(encoding);
+ oldLanguage = new I18nProperties(encoding);
+ out.mkdirs();
+ // evenements
+ if (keysModifier) {
+ addParserEvent(KeysModifier.getInstance(getKeyModifierStart(), getKeyModifierEnd(), encoding));
+ }
+ treadedFiles = new ArrayList<File>();
+ }
+
+ /**
+ * Test if a file is up to date and not to be treated.
+ * <p/>
+ * This method is called on a file only in not {@link #strictMode}.
+ * <p/>
+ * If {@link #updater} is null, then it considers that file as always to be treated.
+ *
+ * @param file the file path to test
+ * @return <code>true</code> if file is up to date and do not need to be parsed
+ * @see FileUpdater
+ */
+ protected final boolean isFileUptodate(File file) {
+ return updater != null && updater.isFileUpToDate(file);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.maven.plugin.AbstractMojo#execute()
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException {
+
+ init();
+ if (entries == null || entries.length == 0 && !treateDefaultEntry) {
+ // nothing to do
+ return;
+ }
+ try {
+ // Reprise sur un ancien parsing
+ File oldParserFile = PluginHelper.getGetterFile(out, getOutGetter(), true);
+ File saveFile = PluginHelper.getGetterFileBackup(out, getOutGetter());
+
+ oldParser.load(oldParserFile);
+ FileUtil.copy(oldParserFile, saveFile);
+
+ // Anciennes cles disponnibles
+ //fixme : pourquoi on utilise un bundle precis ? le premier ici, je ne comprends pas
+ File oldLanguageFile = PluginHelper.getI18nFile(src, artifactId, bundles[0], true);
+
+ oldLanguage.load(oldLanguageFile);
+
+ // Parsing
+ parse();
+
+ // Suppression du fichier sauvegarder
+ saveFile.delete();
+
+ int i = treadedFiles.size();
+ getLog().info(getLogEntry(" success <getter:" + getOutGetter() + "> [treated file(s) : " + i + '/' + fileTreated + "]", fileTreated, 0, t0));
+
+ } catch (Exception e) {
+ getLog().error("Error code parsing ", e);
+ throw new MojoFailureException("Error code parsing");
+ }
+
+ }
+
+ /**
+ * launch the parse on every given entries.
+ *
+ * @throws IOException if any io pb
+ */
+ public void parse() throws IOException {
+ if (treateDefaultEntry) {
+ addDefaultEntry();
+ }
+ long t00 = System.nanoTime();
+ for (SourceEntry entry : entries) {
+ if (!entry.useForGoal(getClass().getSimpleName())) {
+ if (verbose) {
+ getLog().debug("skip entry " + entry.toString());
+ }
+ continue;
+ }
+ currentEntry = entry;
+ // get found files
+ String[] foundFiles = getFilesForEntry(entry);
+ long t000 = System.nanoTime();
+ if (verbose) {
+ getLog().debug(getLogEntry(" parse <" + entry + "> [incoming file(s) : " + foundFiles.length + "]", 0, 0, 0));
+ } else {
+ getLog().info(getLogEntry(" parse <" + entry.getBasedir() + "> [incoming file(s) : " + foundFiles.length + "]", 0, 0, 0));
+ }
+ // launch parser for found files
+ parseEntry(entry.getBasedir(), foundFiles);
+ fileTreated += foundFiles.length;
+ if (verbose) {
+ getLog().debug(getLogEntry(" success <" + entry.getBasedir() + "> [treated file(s) : " + foundFiles.length + "]", foundFiles.length - 1, t000, t00));
+ }
+ t00 = System.nanoTime();
+ }
+ }
+
+ /**
+ * Obtain all the relative path of files to treate for a given entry.
+ *
+ * @param entry the given entry
+ * @return the list of relative path of files for the given entry
+ */
+ protected String[] getFilesForEntry(SourceEntry entry) {
+ return entry.getIncludedFiles(getDefaultBasedir(), getDefaultIncludes(), getDefaultExcludes());
+ }
+
+ /**
+ * Add the default entry to entries given in configuration.
+ * <p/>
+ * This is a convinient method to simplify the configuration of the plugin.
+ */
+ protected void addDefaultEntry() {
+ List<SourceEntry> list;
+
+ if (entries == null || entries.length == 0) {
+ list = new ArrayList<SourceEntry>();
+ } else {
+ list = new ArrayList<SourceEntry>(Arrays.asList(entries));
+ }
+ list.add(new SourceEntry());
+ entries = list.toArray(new SourceEntry[list.size()]);
+ }
+
+ /**
+ * launch parsing on a given entry.
+ *
+ * @param basedir the basedir of the entry
+ * @param files the relative path of files to be treated for the entry.
+ * @throws IOException if any io pb.
+ */
+ protected void parseEntry(File basedir, String[] files) throws IOException {
+ long t00 = System.nanoTime();
+ for (int i = 0; i < files.length; i++) {
+ String file1 = files[i];
+ long t000 = System.nanoTime();
+ String fileName = basedir.getAbsolutePath() + File.separator + file1;
+ File file = new File(fileName);
+ for (ParserEvent event : events) {
+ event.eventChangeFile(file);
+ }
+ touchFile = false;
+ int size = result.size();
+ if (strictMode || !isFileUptodate(file)) {
+ // on parse toujours en mode strict ou quand le fichier n'est pas à jour
+ getLog().info("parseFile " + file);
+ parseFile(file);
+ }
+
+ // Detection de nouvelles cles, sauvegarde du fichier pour pouvoir le restaurer en cas de plantage
+ if (size != result.size()) {
+ saveGetterFile();
+ }
+ if (touchFile) {
+ if (verbose) {
+ getLog().info("touched file " + file);
+ }
+ treadedFiles.add(file);
+ if (verbose) {
+ getLog().debug(getLogEntry(fileName, i, t000, t00));
+ }
+ }
+ for (ParserEvent event : events) {
+ event.eventNextFile(file);
+ }
+ }
+ }
+
+ /**
+ * Save the result in the getter file.
+ *
+ * @throws IOException if any io pb
+ */
+ protected void saveGetterFile() throws IOException {
+ File getterFile = PluginHelper.getGetterFile(out, getOutGetter(), false);
+ result.store(getterFile);
+ }
+}
Copied: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/Parser.java (from rev 1141, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/Parser.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/Parser.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/Parser.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -0,0 +1,55 @@
+/*
+ * *##% 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.parser;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Interface type pour la définition d'un nouveau parser.
+ * <p/>
+ * Une implantation abstraite est proposée : {@link AbstractI18nParser}.
+ *
+ * @author julien
+ */
+public interface Parser {
+
+ /**
+ * Lancement du parser
+ *
+ * @throws java.io.IOException if any io pb
+ */
+ public void parse() throws IOException;
+
+ /**
+ * Parse sur un fichier
+ *
+ * @param file le fichier à parser
+ */
+ public void parseFile(File file);
+
+ /**
+ * Parse une partie du fichier
+ *
+ * @param file le fichier à parser
+ * @param args ? TODO
+ */
+ public void parseLine(File file, String args);
+
+}
Copied: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/ParserException.java (from rev 1141, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/ParserException.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/ParserException.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/ParserException.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -0,0 +1,45 @@
+/*
+ * *##% 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.parser;
+
+/**
+ * Permet la gestion des exceptions dans les parsers et dans les évènements
+ *
+ * @author julien
+ */
+public class ParserException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ public ParserException() {
+ super();
+ }
+
+ public ParserException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ParserException(String message) {
+ super(message);
+ }
+
+ public ParserException(Throwable cause) {
+ super(cause);
+ }
+}
Copied: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/KeysModifier.java (from rev 1141, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/ui/KeysModifier.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/KeysModifier.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/KeysModifier.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -0,0 +1,230 @@
+/*
+ * *##% 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.parser.event;
+
+import org.codelutin.i18n.plugin.parser.event.ParserEvent;
+import org.codelutin.i18n.plugin.parser.ParserException;
+import org.codelutin.util.FileUtil;
+
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JTextField;
+import java.awt.Container;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * IHM permettant de modifier les clés de traduction en direct dans les fichiers
+ * parsés et les fichiers de propriétés.
+ *
+ * @author julien
+ */
+public class KeysModifier extends JFrame implements ParserEvent {
+
+ private static final long serialVersionUID = 1L;
+
+ // 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 >>");
+ private static KeysModifier keysModifier;
+
+ /**
+ * Récupération d'une instance de l'interface
+ *
+ * @param patternLeft left pattern
+ * @param patternRight right pattern
+ * @param encoding encoding
+ * @return the shared instance with new config
+ */
+ public static KeysModifier getInstance(String patternLeft, String patternRight, String encoding) {
+ if (keysModifier == null) {
+ keysModifier = new KeysModifier();
+ }
+
+
+ keysModifier.encoding = encoding;
+ keysModifier.patternLeft = patternLeft;
+ keysModifier.patternRight = patternRight;
+
+ return keysModifier;
+ }
+
+ /** Contructeur de l'interface */
+ private KeysModifier() {
+ setLayout(new GridLayout(9, 2, 10, 10));
+
+ Container pane = getContentPane();
+ pane.add(new JLabel("--- File information ---"));
+ pane.add(new JLabel());
+
+ pane.add(new JLabel("Name :"));
+ pane.add(name);
+
+ pane.add(new JLabel("Path : "));
+ pane.add(path);
+
+ pane.add(new JLabel("--- Files language ---"));
+ pane.add(new JLabel());
+
+ pane.add(new JLabel("Key :"));
+ pane.add(key);
+
+ pane.add(new JLabel("--- Filters ---"));
+ pane.add(new JLabel());
+
+ pane.add(new JLabel("Pattern :"));
+ pane.add(pattern);
+
+ pane.add(new JLabel("Only new key :"));
+ pane.add(onlyNewKey);
+
+ pane.add(new JLabel());
+ pane.add(next);
+
+ next.addActionListener(new EventNextKey());
+ addWindowListener(new EventWindows());
+
+ setTitle("Keys modifier");
+ setSize(800, 400);
+// pack();
+ setVisible(true);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.i18n.plugin.core.ParserEvent#eventChangeFile(java.io.File)
+ */
+ public void eventChangeFile(File file) {
+ name.setText(file.getName());
+ path.setText(file.getPath());
+ key.setText("");
+ repaint();
+
+ newKeys = new ArrayList<String>();
+ needModifiedFile = false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.i18n.plugin.core.ParserEvent#eventNextFile(java.io.File)
+ */
+ public void eventNextFile(File file) {
+ if (needModifiedFile) {
+ String content;
+ int region = 0;
+
+ try {
+ content = FileUtil.readAsString(file, encoding);
+ } catch (IOException e) {
+ throw new ParserException(e);
+ }
+
+ for (Iterator<String> iterator = newKeys.iterator(); iterator.hasNext();) {
+ String oldKey = iterator.next();
+ String realKey = iterator.next();
+ Pattern pattern = Pattern.compile("(" + patternLeft + ")(" + Pattern.quote(oldKey) + ")(" + patternRight + ")");
+ Matcher matcher = pattern.matcher(content);
+ matcher.region(region, content.length());
+ matcher.find();
+ region = matcher.start();
+ content = matcher.replaceFirst("$1" + realKey + "$3");
+ }
+
+ try {
+ FileUtil.writeString(file, content, encoding);
+ } catch (IOException e) {
+ throw new ParserException(e);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.i18n.plugin.core.ParserEvent#eventChangeKey(java.lang.String)
+ */
+ public synchronized void eventChangeKey(String keyI18n, boolean newKey) {
+ key.setText(keyI18n);
+ newKeys.add(key.getText());
+ repaint();
+ if (isVisible() && keyI18n.matches(pattern.getText()) && (!onlyNewKey.isSelected() || newKey)) {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ throw new ParserException(e);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.i18n.plugin.core.ParserEvent#eventGetRealKey()
+ */
+ public String eventGetRealKey() {
+ newKeys.add(key.getText());
+ needModifiedFile |= !newKeys.get(newKeys.size() - 1).equals(newKeys.get(newKeys.size() - 2));
+ return key.getText();
+ }
+
+ /** Action sur le boutton pour passer � la cl� suivante */
+ class EventNextKey implements ActionListener {
+ public void actionPerformed(ActionEvent e) {
+ eventNextKey();
+ }
+ }
+
+ /** Action sur la fermeture de la frame */
+ class EventWindows extends WindowAdapter {
+
+ @Override
+ public void windowClosing(WindowEvent e) {
+ setVisible(false);
+ eventNextKey();
+ }
+ }
+
+ /** Permet de passer à la clé suivante */
+ public synchronized void eventNextKey() {
+ notifyAll();
+ }
+}
Copied: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/ParserEvent.java (from rev 1141, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/core/ParserEvent.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/ParserEvent.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/ParserEvent.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -0,0 +1,59 @@
+/*
+ * *##% 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.parser.event;
+
+import java.io.File;
+
+/**
+ * Permet d'ajouter des évènements sur les parsers
+ *
+ * @author julien
+ */
+public interface ParserEvent {
+
+ /**
+ * M�thode appelée quand on change de fichier parsé
+ *
+ * @param file
+ */
+ public void eventChangeFile(File file);
+
+ /**
+ * Méthode appelée après le parsing du fichier
+ *
+ * @param file
+ */
+ public void eventNextFile(File file);
+
+ /**
+ * M�thode appelée quand on change de clé
+ *
+ * @param keyI18n
+ * @param newKey
+ */
+ public void eventChangeKey(String keyI18n, boolean newKey);
+
+ /**
+ * M�thode appelée pour récupérer la nouvelle valeur de clé
+ *
+ * @return
+ */
+ public String eventGetRealKey();
+
+}
Copied: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJava.java (from rev 1141, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJava.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJava.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJava.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -0,0 +1,159 @@
+/*
+ * *##% 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.parser.impl;
+
+import org.apache.maven.project.MavenProject;
+import org.codelutin.i18n.plugin.parser.AbstractI18nParser;
+import org.codelutin.i18n.plugin.parser.event.ParserEvent;
+import org.codelutin.i18n.plugin.parser.ParserException;
+import org.codelutin.processor.filters.I18nFilter;
+import org.codelutin.util.FileUpdaterHelper;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+
+/**
+ * Récupération des chaine a traduire depuis les fichiers java.
+ *
+ * @author julien
+ * @goal parserJava
+ * @phase generate-resources
+ */
+public class ParserJava extends AbstractI18nParser {
+
+ /**
+ * Source entries (src+includes+excludes) .
+ *
+ * @parameter expression="${i18n.defaultIncludes}" default-value="**\\/*.java"
+ */
+ protected String defaultIncludes;
+
+ /**
+ * default src for an entry.
+ *
+ * @parameter expression="${i18n.defaultBasedir}" default-value="${basedir}/src/java"
+ */
+ protected File defaultBasedir;
+
+ /**
+ * Dependance du projet.
+ *
+ * @parameter default-value="${project}"
+ * @readonly
+ */
+ protected MavenProject project;
+
+ /**
+ * Repertoire sources des fichiers i18n.
+ *
+ * @parameter expression="${i18n.cp}" default-value="${basedir}/target/classes"
+ * @required
+ */
+ protected File cp;
+
+ @Override
+ protected String[] getDefaultIncludes() {
+ return new String[]{defaultIncludes};
+ }
+
+ @Override
+ protected String[] getDefaultExcludes() {
+ return new String[]{};
+ }
+
+ @Override
+ protected File getDefaultBasedir() {
+ return defaultBasedir;
+ }
+
+ @Override
+ protected String getKeyModifierStart() {
+ return "_\\(\\s*\"";
+ }
+
+ @Override
+ protected String getKeyModifierEnd() {
+ return "\"\\s*(\\)|,|\\+|$)";
+ }
+
+ @Override
+ protected String getOutGetter() {
+ return "java.getter";
+ }
+
+ protected I18nFilter filter;
+
+ @Override
+ public void init() {
+ super.init();
+ filter = new I18nFilter();
+ }
+
+ protected void parseEntry(File basedir, String[] files) throws IOException {
+ // prepare new file updater
+ updater = FileUpdaterHelper.newJavaFileUpdater(basedir, cp);
+ super.parseEntry(basedir, files);
+ }
+
+ @Override
+ public void parseFile(File srcFile) {
+ try {
+
+ LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(srcFile)));
+ while (lnr.ready()) {
+ String line = lnr.readLine();
+ parseLine(srcFile, line);
+ }
+
+ } catch (Exception e) {
+ throw new ParserException(e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.i18n.plugin.core.Parser#parseLine(java.io.File, java.lang.String)
+ */
+ @Override
+ public void parseLine(File srcFile, String line) {
+ String keysSet = filter.parse(line);
+
+ if (!keysSet.equals(I18nFilter.EMPTY_STRING)) {
+ touchFile = true;
+ // Found a set of i18n Strings, split it.
+ String[] keys = keysSet.split("=");
+ for (String key : keys) {
+ String keyModified = key;
+ for (ParserEvent event : events) {
+ event.eventChangeKey(key, !oldLanguage.containsKey(key));
+ keyModified = event.eventGetRealKey();
+ }
+ if (oldParser.containsKey(key)) {
+ result.put(keyModified, oldParser.get(key));
+ } else {
+ result.put(keyModified, key);
+ }
+ }
+ }
+ }
+
+}
Copied: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJavaActionConfig.java (from rev 1141, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJavaActionConfig.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJavaActionConfig.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJavaActionConfig.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -0,0 +1,87 @@
+/*
+* *##% 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.parser.impl;
+
+import org.codelutin.i18n.plugin.parser.event.ParserEvent;
+
+import java.io.File;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Un parseur java pour scanner les annotations ActionConfig
+ *
+ * @author chemit
+ * @goal parserJavaActionConfig
+ * @phase generate-resources
+ */
+public class ParserJavaActionConfig extends ParserJava {
+
+ protected static final Pattern MATCH_PATTERN = Pattern.compile("(name|shortDescription|longDescription|name2|shortDescription2|longDescription2)\\s*=\\s*\"([\\w|\\.]+)\"(|\\s*|\\s*,\\s*$)");
+
+ @Override
+ protected String getKeyModifierStart() {
+ return "[\\w|\\.]+\\s*=\\s*\"";
+ }
+
+ @Override
+ protected String getKeyModifierEnd() {
+ return "\"\\s*(\\)|,|\\+|$)";
+ }
+
+ @Override
+ protected String getOutGetter() {
+ return "java-action-config.getter";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.i18n.plugin.extension.XmlParser#extract(java.lang.String)
+ */
+
+ public String extract(String i18nString) {
+ Matcher matcher = MATCH_PATTERN.matcher(i18nString.trim());
+ if (matcher.matches()) {
+ return matcher.group(2);
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.i18n.plugin.core.Parser#parseLine(java.io.File, java.lang.String)
+ */
+ @Override
+ public void parseLine(File srcFile, String line) {
+ String key = extract(line);
+ if (key != null) {
+ touchFile = true;
+ String keyModified = key;
+ for (ParserEvent event : events) {
+ event.eventChangeKey(key, !oldLanguage.containsKey(key));
+ keyModified = event.eventGetRealKey();
+ }
+ if (oldParser.containsKey(key)) {
+ result.put(keyModified, oldParser.get(key));
+ } else {
+ result.put(keyModified, key);
+ }
+ }
+ }
+
+}
Copied: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJavaTabConfig.java (from rev 1141, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJavaTabConfig.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJavaTabConfig.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJavaTabConfig.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -0,0 +1,35 @@
+/**
+ * *##% 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.parser.impl;
+
+/**
+ * Un parseur java pour scanner les annotations TabContentConfig.
+ *
+ * @author chemit
+ * @goal parserJavaTabConfig
+ * @phase generate-resources
+ */
+public class ParserJavaTabConfig extends ParserJavaActionConfig {
+
+ @Override
+ protected String getOutGetter() {
+ return "java-tab-config.getter";
+ }
+
+}
Copied: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJaxx.java (from rev 1141, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserJaxx.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJaxx.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJaxx.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -0,0 +1,110 @@
+/*
+ * *##% 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.parser.impl;
+
+import org.codelutin.util.FileUpdaterHelper;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Récupération des chaine à traduire depuis les fichiers xml Jaxx.
+ *
+ * @author julien
+ * @goal parserJaxx
+ * @phase generate-resources
+ */
+public class ParserJaxx extends ParserXml {
+
+ /**
+ * Source entries (src+includes+excludes) .
+ *
+ * @parameter expression="${i18n.defaultIncludes}" default-value="**\\/*.jaxx"
+ */
+ protected String defaultIncludes;
+
+ /**
+ * Where jaxx files should have been generated.
+ *
+ * @parameter expression="${i18n.defaultGenerateBasedir}" default-value="${basedir}/target/generated-sources/java"
+ */
+ protected File defaultGenerateBasedir;
+
+ /**
+ * Regles xml.
+ *
+ * @parameter expression="${i18n.rulesJaxx}" default-value="jaxx.rules"
+ */
+ protected String rulesJaxx;
+
+ @Override
+ protected String[] getDefaultIncludes() {
+ return new String[]{defaultIncludes};
+ }
+
+ @Override
+ protected String[] getDefaultExcludes() {
+ return new String[]{};
+ }
+
+ protected void parseEntry(File basedir, String[] files) throws IOException {
+ // prepare new file updater
+ updater = FileUpdaterHelper.newJavaFileUpdater(basedir, defaultGenerateBasedir);
+ super.parseEntry(basedir, files);
+ }
+
+ @Override
+ protected String getOutGetter() {
+ return "jaxx.getter";
+ }
+
+ @Override
+ protected String getKeyModifierStart() {
+ return "=\\s*[\"\']";
+ }
+
+ @Override
+ protected String getKeyModifierEnd() {
+ return "[\"\']";
+ }
+
+ @Override
+ protected String getFileRules() {
+ return rulesJaxx;
+ }
+
+ @Override
+ protected String getCoreFileRules() {
+ return "jaxx.rules";
+ }
+
+ public void setRulesJaxx(String rulesJaxx) {
+ this.rulesJaxx = rulesJaxx;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.i18n.plugin.extension.XmlParser#extract(java.lang.String)
+ */
+ @Override
+ public String extract(String i18nString) {
+ return i18nString.length() == 0 ? null : i18nString;
+ }
+
+}
Copied: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserSwixat.java (from rev 1141, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserSwixat.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserSwixat.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserSwixat.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -0,0 +1,94 @@
+/*
+ * *##% 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.parser.impl;
+
+/**
+ * Recuperation des chaines à traduire depuis les fichiers xml Swixat.
+ *
+ * @author julien
+ * @goal parserSwixat
+ * @phase generate-resources
+ */
+public class ParserSwixat extends ParserXml {
+
+ /**
+ * Source entries (src+includes) .
+ *
+ * @parameter expression="${i18n.defaultIncludes}" default-value="**\\/*.xml"
+ */
+ protected String defaultIncludes;
+
+ /**
+ * Source entries (src+excludes) .
+ *
+ * @parameter expression="${i18n.defaultIncludes}" default-value="**\\/context.xml"
+ */
+ protected String defaultExcludes;
+
+ /**
+ * Regles xml.
+ *
+ * @parameter expression="${i18n.rulesSwixat}" default-value="swixat.rules"
+ */
+ protected String rulesSwixat;
+
+ @Override
+ protected String[] getDefaultIncludes() {
+ return new String[]{defaultIncludes};
+ }
+
+ @Override
+ protected String[] getDefaultExcludes() {
+ return new String[]{defaultExcludes};
+ }
+
+ @Override
+ protected String getKeyModifierStart() {
+ return "=\\s*[\"\']";
+ }
+
+ @Override
+ protected String getKeyModifierEnd() {
+ return "[\"\']";
+ }
+
+ @Override
+ protected String getOutGetter() {
+ return "swixat.getter";
+ }
+
+ @Override
+ protected String getFileRules() {
+ return rulesSwixat;
+ }
+
+ @Override
+ protected String getCoreFileRules() {
+ return "swixat.rules";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.i18n.plugin.extension.XmlParser#extract(java.lang.String)
+ */
+ @Override
+ public String extract(String i18nString) {
+ return i18nString;
+ }
+}
Copied: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserXml.java (from rev 1141, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/extension/ParserXml.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserXml.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserXml.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -0,0 +1,228 @@
+/*
+ * *##% 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.parser.impl;
+
+import org.codelutin.i18n.plugin.parser.AbstractI18nParser;
+import org.codelutin.i18n.plugin.parser.event.ParserEvent;
+import org.codelutin.i18n.plugin.parser.ParserException;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathFactory;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Récupération des chaines à traduire depuis les fichiers xml.
+ *
+ * @author julien
+ */
+public abstract class ParserXml extends AbstractI18nParser {
+
+ /** Taille du buffer pour les lectures/écritures */
+ protected static final int BUFFER_SIZE = 8 * 1024;
+
+ /**
+ * default src for an entry.
+ *
+ * @parameter expression="${i18n.defaultBasedir}" default-value="${basedir}/src/uimodel"
+ * @required
+ */
+ protected File defaultBasedir;
+
+ protected String rules;
+ protected XPathFactory factory;
+ protected XPath xpath;
+
+ /**
+ * Fonction d'extraction de la chaine
+ *
+ * @param i18nString le clef i18n
+ * @return la chaine
+ */
+ public abstract String extract(String i18nString);
+
+ /** @return le fichier des rules */
+ protected abstract String getFileRules();
+
+ /** @return le fichier des rules de base à toujours charger */
+ protected abstract String getCoreFileRules();
+
+ @Override
+ public void init() {
+ super.init();
+ this.factory = XPathFactory.newInstance();
+ this.rules = getRules(getFileRules());
+ this.xpath = factory.newXPath();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.i18n.plugin.core.Parser#parseFile(java.io.File)
+ */
+ public void parseFile(File file) {
+ NodeList list;
+ InputSource inputSource = new InputSource(file.getAbsolutePath()); // TODO: A d�placer pour les performances
+
+ try {
+ int size = result.size();
+
+ // Recherche des clés à partir d'un xpath
+ XPathExpression expression = xpath.compile(rules);
+ list = (NodeList) expression.evaluate(inputSource, XPathConstants.NODESET);
+
+ for (int index = 0; index < list.getLength(); index++) {
+ Node node = list.item(index);
+ parseLine(file, node.getTextContent());
+ }
+
+ // Détection de nouvelles clés, sauvegarde du fichier pour pouvoir le restaurer en cas de plantage
+ if (size != result.size()) {
+ saveGetterFile();
+ }
+ } catch (Exception e) {
+ throw new ParserException(e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.i18n.plugin.core.Parser#parseLine(java.io.File, java.lang.String)
+ */
+ public void parseLine(File file, String key) {
+ key = extract(key);
+ if (key != null) {
+ touchFile = true;
+ String keyModified = key;
+ for (ParserEvent event : events) {
+ event.eventChangeKey(key, !oldLanguage.containsKey(key));
+ keyModified = event.eventGetRealKey();
+ }
+
+ if (oldParser.containsKey(key)) {
+ result.put(keyModified, oldParser.get(key));
+ } else {
+ result.put(keyModified, key);
+ }
+ }
+ }
+
+ protected File getDefaultBasedir() {
+ return defaultBasedir;
+ }
+
+ /**
+ * Récupère le xpath à partir d'un fichier
+ *
+ * @param fileRules le nom du fichier contant les règles
+ * @return le xpath à partir d'un fichier
+ */
+ private String getRules(String fileRules) {
+ StringBuilder result = new StringBuilder();
+
+ try {
+ String readInputStream;
+
+ // load core rules
+ readInputStream = loadRulesFile(getCoreFileRules());
+ if (verbose) {
+ getLog().debug("core rules : " + readInputStream);
+ }
+ result.append(readInputStream);
+
+ if (!fileRules.equals(getCoreFileRules())) {
+ // add custom rules
+ readInputStream = loadRulesFile(fileRules);
+ if (verbose) {
+ getLog().debug("custom rules : " + readInputStream);
+ }
+ result.append(" | ").append(readInputStream);
+ }
+ } catch (IOException e) {
+ throw new ParserException(e);
+ }
+
+ return result.toString();
+ }
+
+ private String loadRulesFile(String fileRules) throws IOException {
+ File f = new File(fileRules);
+
+ InputStream inputStream;
+ if (f.exists()) {
+ // load from a file
+ try {
+ inputStream = new FileInputStream(f);
+ } catch (FileNotFoundException e) {
+ throw new ParserException(e);
+ }
+ } else {
+ // load from classpath
+ ClassLoader classLoader = getClass().getClassLoader();
+ inputStream = classLoader.getResourceAsStream(fileRules);
+ }
+ if (inputStream == null) {
+ throw new ParserException("could not found file of rules : " + fileRules);
+ }
+
+ inputStream = new BufferedInputStream(inputStream);
+
+ try {
+ // Lecture
+ String readInputStream;
+ readInputStream = readInputStream(inputStream);
+ return readInputStream;
+ } catch (IOException e) {
+ throw new ParserException(e);
+ } finally {
+ inputStream.close();
+ }
+ }
+
+ /**
+ * Permet la lecture d'un InputStream et Suppressions.
+ *
+ * @param in le flux entrant
+ * @return le contenu du flux
+ * @throws IOException si problème de lecture dans flux entrant
+ */
+ private String readInputStream(InputStream in) throws IOException {
+ StringBuilder sb = new StringBuilder();
+ byte[] buffer = new byte[BUFFER_SIZE];
+ while (in.read(buffer, 0, BUFFER_SIZE) != -1) {
+ String tmp = new String(buffer);
+ sb.append(tmp);
+ }
+ in.close();
+ // Suppression
+ String result = sb.toString().trim();
+ result = result.replaceAll("#.*\n", ""); // suppression des commentaires
+ result = result.replaceAll("\\s+", " | "); // contruction du xpath avec des ou
+ result = result.replaceAll("(^ \\| )|( \\| $)", ""); // suppression des ou de début ee fin
+ return result;
+ }
+}
Deleted: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/ui/KeysModifier.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/ui/KeysModifier.java 2008-09-29 08:42:28 UTC (rev 1142)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/ui/KeysModifier.java 2008-09-29 08:45:36 UTC (rev 1143)
@@ -1,230 +0,0 @@
-/*
- * *##% 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.ui;
-
-import org.codelutin.i18n.plugin.core.ParserEvent;
-import org.codelutin.i18n.plugin.core.ParserException;
-import org.codelutin.util.FileUtil;
-
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JTextField;
-import java.awt.Container;
-import java.awt.GridLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * IHM permettant de modifier les clés de traduction en direct dans les fichiers
- * parsés et les fichiers de propriétés.
- *
- * @author julien
- */
-public class KeysModifier extends JFrame implements ParserEvent {
-
- private static final long serialVersionUID = 1L;
-
- // 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 >>");
- private static KeysModifier keysModifier;
-
- /**
- * Récupération d'une instance de l'interface
- *
- * @param patternLeft left pattern
- * @param patternRight right pattern
- * @param encoding encoding
- * @return the shared instance with new config
- */
- public static KeysModifier getInstance(String patternLeft, String patternRight, String encoding) {
- if (keysModifier == null) {
- keysModifier = new KeysModifier();
- }
-
-
- keysModifier.encoding = encoding;
- keysModifier.patternLeft = patternLeft;
- keysModifier.patternRight = patternRight;
-
- return keysModifier;
- }
-
- /** Contructeur de l'interface */
- private KeysModifier() {
- setLayout(new GridLayout(9, 2, 10, 10));
-
- Container pane = getContentPane();
- pane.add(new JLabel("--- File information ---"));
- pane.add(new JLabel());
-
- pane.add(new JLabel("Name :"));
- pane.add(name);
-
- pane.add(new JLabel("Path : "));
- pane.add(path);
-
- pane.add(new JLabel("--- Files language ---"));
- pane.add(new JLabel());
-
- pane.add(new JLabel("Key :"));
- pane.add(key);
-
- pane.add(new JLabel("--- Filters ---"));
- pane.add(new JLabel());
-
- pane.add(new JLabel("Pattern :"));
- pane.add(pattern);
-
- pane.add(new JLabel("Only new key :"));
- pane.add(onlyNewKey);
-
- pane.add(new JLabel());
- pane.add(next);
-
- next.addActionListener(new EventNextKey());
- addWindowListener(new EventWindows());
-
- setTitle("Keys modifier");
- setSize(800, 400);
-// pack();
- setVisible(true);
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.i18n.plugin.core.ParserEvent#eventChangeFile(java.io.File)
- */
- public void eventChangeFile(File file) {
- name.setText(file.getName());
- path.setText(file.getPath());
- key.setText("");
- repaint();
-
- newKeys = new ArrayList<String>();
- needModifiedFile = false;
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.i18n.plugin.core.ParserEvent#eventNextFile(java.io.File)
- */
- public void eventNextFile(File file) {
- if (needModifiedFile) {
- String content;
- int region = 0;
-
- try {
- content = FileUtil.readAsString(file, encoding);
- } catch (IOException e) {
- throw new ParserException(e);
- }
-
- for (Iterator<String> iterator = newKeys.iterator(); iterator.hasNext();) {
- String oldKey = iterator.next();
- String realKey = iterator.next();
- Pattern pattern = Pattern.compile("(" + patternLeft + ")(" + Pattern.quote(oldKey) + ")(" + patternRight + ")");
- Matcher matcher = pattern.matcher(content);
- matcher.region(region, content.length());
- matcher.find();
- region = matcher.start();
- content = matcher.replaceFirst("$1" + realKey + "$3");
- }
-
- try {
- FileUtil.writeString(file, content, encoding);
- } catch (IOException e) {
- throw new ParserException(e);
- }
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.i18n.plugin.core.ParserEvent#eventChangeKey(java.lang.String)
- */
- public synchronized void eventChangeKey(String keyI18n, boolean newKey) {
- key.setText(keyI18n);
- newKeys.add(key.getText());
- repaint();
- if (isVisible() && keyI18n.matches(pattern.getText()) && (!onlyNewKey.isSelected() || newKey)) {
- try {
- wait();
- } catch (InterruptedException e) {
- throw new ParserException(e);
- }
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.i18n.plugin.core.ParserEvent#eventGetRealKey()
- */
- public String eventGetRealKey() {
- newKeys.add(key.getText());
- needModifiedFile |= !newKeys.get(newKeys.size() - 1).equals(newKeys.get(newKeys.size() - 2));
- return key.getText();
- }
-
- /** Action sur le boutton pour passer � la cl� suivante */
- class EventNextKey implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- eventNextKey();
- }
- }
-
- /** Action sur la fermeture de la frame */
- class EventWindows extends WindowAdapter {
-
- @Override
- public void windowClosing(WindowEvent e) {
- setVisible(false);
- eventNextKey();
- }
- }
-
- /** Permet de passer à la clé suivante */
- public synchronized void eventNextKey() {
- notifyAll();
- }
-}
1
0
[Lutinutil-commits] r1142 - in maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin: . parser
by ruchaud@users.labs.libre-entreprise.org 29 Sep '08
by ruchaud@users.labs.libre-entreprise.org 29 Sep '08
29 Sep '08
Author: ruchaud
Date: 2008-09-29 08:42:28 +0000 (Mon, 29 Sep 2008)
New Revision: 1142
Added:
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/
Log:
Cr?\195?\169ation de la nouvelle arborescence
1
0
25 Sep '08
Author: tchemit
Date: 2008-09-25 11:48:09 +0000 (Thu, 25 Sep 2008)
New Revision: 1141
Modified:
lutinutil/trunk/pom.xml
Log:
commentaire
Modified: lutinutil/trunk/pom.xml
===================================================================
--- lutinutil/trunk/pom.xml 2008-09-25 11:46:47 UTC (rev 1140)
+++ lutinutil/trunk/pom.xml 2008-09-25 11:48:09 UTC (rev 1141)
@@ -107,6 +107,7 @@
<artifactId>maven-jrst-plugin</artifactId>
</plugin>
+ <!-- javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
1
0
[Lutinutil-commits] r1140 - in lutinutil/trunk: . src/main/java/org/codelutin/util src/test/java/org/codelutin/i18n
by tchemit@users.labs.libre-entreprise.org 25 Sep '08
by tchemit@users.labs.libre-entreprise.org 25 Sep '08
25 Sep '08
Author: tchemit
Date: 2008-09-25 11:46:47 +0000 (Thu, 25 Sep 2008)
New Revision: 1140
Modified:
lutinutil/trunk/changelog
lutinutil/trunk/src/main/java/org/codelutin/util/FileCompletion.java
lutinutil/trunk/src/test/java/org/codelutin/i18n/I18nLoaderTest.java
Log:
changelog
+ ligne a la fin des sources
Modified: lutinutil/trunk/changelog
===================================================================
--- lutinutil/trunk/changelog 2008-09-25 11:46:30 UTC (rev 1139)
+++ lutinutil/trunk/changelog 2008-09-25 11:46:47 UTC (rev 1140)
@@ -1,4 +1,5 @@
ver-0-31 chemit 2008????
+ * always build javadoc
* Change group id
* utilisation de lutinproject 2.4 et nettoyage du pom
* reorganisation du site
Modified: lutinutil/trunk/src/main/java/org/codelutin/util/FileCompletion.java
===================================================================
--- lutinutil/trunk/src/main/java/org/codelutin/util/FileCompletion.java 2008-09-25 11:46:30 UTC (rev 1139)
+++ lutinutil/trunk/src/main/java/org/codelutin/util/FileCompletion.java 2008-09-25 11:46:47 UTC (rev 1140)
@@ -246,4 +246,5 @@
System.out.println();
}
}
-}
\ No newline at end of file
+}
+
Modified: lutinutil/trunk/src/test/java/org/codelutin/i18n/I18nLoaderTest.java
===================================================================
--- lutinutil/trunk/src/test/java/org/codelutin/i18n/I18nLoaderTest.java 2008-09-25 11:46:30 UTC (rev 1139)
+++ lutinutil/trunk/src/test/java/org/codelutin/i18n/I18nLoaderTest.java 2008-09-25 11:46:47 UTC (rev 1140)
@@ -130,4 +130,5 @@
loader.setLanguage(locale, bundleManager);
}
-}
\ No newline at end of file
+}
+
1
0
25 Sep '08
Author: tchemit
Date: 2008-09-25 11:46:30 +0000 (Thu, 25 Sep 2008)
New Revision: 1139
Modified:
lutinutil/trunk/pom.xml
Log:
ajout generation javadoc
suppression de url (gere par le superpom)
Modified: lutinutil/trunk/pom.xml
===================================================================
--- lutinutil/trunk/pom.xml 2008-09-25 11:34:05 UTC (rev 1138)
+++ lutinutil/trunk/pom.xml 2008-09-25 11:46:30 UTC (rev 1139)
@@ -57,8 +57,7 @@
<version>0.31-SNAPSHOT</version>
<description>Library of usefull class to be used in any project.</description>
<inceptionYear>2004</inceptionYear>
- <url>${labs.project.url}</url>
-
+
<!-- ************************************************************* -->
<!-- *** Build Settings ****************************************** -->
<!-- ************************************************************* -->
@@ -81,8 +80,7 @@
<scm>
<connection>${maven.scm.connection}</connection>
<developerConnection>${maven.scm.developerConnection}</developerConnection>
- <!-- This does'nt work for viewcvs.php with stat-scm with svn conf :(
- <url>${maven.scm.url}</url> -->
+ <url>${maven.scm.url}</url>
</scm>
<build>
@@ -109,6 +107,11 @@
<artifactId>maven-jrst-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ </plugin>
+
</plugins>
</build>
1
0
[Lutinutil-commits] r1138 - maven-i18n-plugin/trunk
by tchemit@users.labs.libre-entreprise.org 25 Sep '08
by tchemit@users.labs.libre-entreprise.org 25 Sep '08
25 Sep '08
Author: tchemit
Date: 2008-09-25 11:34:05 +0000 (Thu, 25 Sep 2008)
New Revision: 1138
Modified:
maven-i18n-plugin/trunk/changelog
maven-i18n-plugin/trunk/pom.xml
Log:
ajout du profile license pour pouvoir mettre a jour les entete des fichiers sources
utilisation lutinpluginutil 0.2
execution explicite du plugin license-siwtcher (car plus dans superpom)
application des dernieres optimisations sur les variables
Modified: maven-i18n-plugin/trunk/changelog
===================================================================
--- maven-i18n-plugin/trunk/changelog 2008-09-25 11:26:34 UTC (rev 1137)
+++ maven-i18n-plugin/trunk/changelog 2008-09-25 11:34:05 UTC (rev 1138)
@@ -1,4 +1,5 @@
ver-0-6 thimel 20080922
+ * 20080925 [chemit] Using lutinpluginutil 0.2 and license-switcher in pom (no more in superpom)
* 20080922 [thimel] Using lutinpluginproject 3.0
ver-0-5 chemit 20080824
Modified: maven-i18n-plugin/trunk/pom.xml
===================================================================
--- maven-i18n-plugin/trunk/pom.xml 2008-09-25 11:26:34 UTC (rev 1137)
+++ maven-i18n-plugin/trunk/pom.xml 2008-09-25 11:34:05 UTC (rev 1138)
@@ -13,15 +13,15 @@
<version>3.0</version>
</parent>
- <groupId>org.codelutin</groupId>
+ <!--groupId>org.codelutin</groupId-->
<artifactId>maven-i18n-plugin</artifactId>
<dependencies>
<dependency>
- <groupId>lutinlib</groupId>
+ <groupId>org.codelutin</groupId>
<artifactId>lutinprocessor</artifactId>
- <version>[0.12,]</version>
+ <version>0.15</version>
<scope>compile</scope>
</dependency>
@@ -42,7 +42,7 @@
<dependency>
<groupId>org.codelutin</groupId>
<artifactId>lutinpluginutil</artifactId>
- <version>[0.1,]</version>
+ <version>0.2</version>
<scope>compile</scope>
</dependency>
@@ -59,9 +59,6 @@
</description>
<inceptionYear>2007</inceptionYear>
- <!-- BE WARE, this value must rewritten here since it will be otherwise suffixed by inheritance -->
- <url>${labs.project.url}</url>
-
<!-- ************************************************************* -->
<!-- *** Build Settings ****************************************** -->
<!-- ************************************************************* -->
@@ -77,6 +74,21 @@
<artifactId>maven-jrst-plugin</artifactId>
</plugin>
+ <!-- plugin license-switcher -->
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-license-switcher-plugin</artifactId>
+ <version>0.2</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>license</goal>
+ <goal>third-party</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
</plugins>
</build>
@@ -88,29 +100,45 @@
<!-- nom du projet sur le labs -->
<labs.project>lutinutil</labs.project>
- <!-- BE WARE, this value must rewritten here since it will be otherwise suffixed by inheritance -->
- <maven.scm.url>https://${labs.host}/plugins/scmsvn/viewcvs.php/trunk/${pom.artifactId}?root=${labs.project}
- </maven.scm.url>
-
</properties>
<!-- ************************************************************* -->
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
+ <!--Source control management-->
<scm>
+ <connection>${maven.scm.connection}</connection>
+ <developerConnection>${maven.scm.developerConnection}</developerConnection>
<url>${maven.scm.url}</url>
</scm>
- <reporting>
- <plugins>
- <!--Site report's plugin-->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-plugin-plugin</artifactId>
- </plugin>
- </plugins>
- </reporting>
+ <!-- Maven Environment : profiles -->
+ <profiles>
+ <profile>
+ <id>license</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-license-switcher-plugin</artifactId>
+ <version>0.2</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>switch</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
</project>
1
0
[Lutinutil-commits] r1137 - maven-license-switcher-plugin/trunk
by tchemit@users.labs.libre-entreprise.org 25 Sep '08
by tchemit@users.labs.libre-entreprise.org 25 Sep '08
25 Sep '08
Author: tchemit
Date: 2008-09-25 11:26:34 +0000 (Thu, 25 Sep 2008)
New Revision: 1137
Modified:
maven-license-switcher-plugin/trunk/pom.xml
Log:
ajout du profile license pour pouvoir mettre a jour les entete des fichiers sources
Modified: maven-license-switcher-plugin/trunk/pom.xml
===================================================================
--- maven-license-switcher-plugin/trunk/pom.xml 2008-09-25 11:18:33 UTC (rev 1136)
+++ maven-license-switcher-plugin/trunk/pom.xml 2008-09-25 11:26:34 UTC (rev 1137)
@@ -103,4 +103,30 @@
<url>${maven.scm.url}</url>
</scm>
+ <!-- Maven Environment : profiles -->
+ <profiles>
+ <profile>
+ <id>license</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-license-switcher-plugin</artifactId>
+ <version>0.2</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>switch</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
</project>
1
0
[Lutinutil-commits] r1136 - maven-license-switcher-plugin/trunk
by tchemit@users.labs.libre-entreprise.org 25 Sep '08
by tchemit@users.labs.libre-entreprise.org 25 Sep '08
25 Sep '08
Author: tchemit
Date: 2008-09-25 11:18:33 +0000 (Thu, 25 Sep 2008)
New Revision: 1136
Modified:
maven-license-switcher-plugin/trunk/pom.xml
Log:
dependance explicite vers lutinpluginutil
execution du plugin sur lui-meme pour genere le third-party (cela implique un double install pour pouvoir utiliser la nouvelle version au sein du plugin)
Modified: maven-license-switcher-plugin/trunk/pom.xml
===================================================================
--- maven-license-switcher-plugin/trunk/pom.xml 2008-09-25 11:17:01 UTC (rev 1135)
+++ maven-license-switcher-plugin/trunk/pom.xml 2008-09-25 11:18:33 UTC (rev 1136)
@@ -13,7 +13,7 @@
<version>3.0</version>
</parent>
- <groupId>org.codelutin</groupId>
+ <!--groupId>org.codelutin</groupId-->
<artifactId>maven-license-switcher-plugin</artifactId>
<dependencies>
@@ -27,10 +27,17 @@
<dependency>
<groupId>org.codelutin</groupId>
<artifactId>lutinprocessor</artifactId>
- <version>0.14</version>
+ <version>0.15</version>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutinpluginutil</artifactId>
+ <version>0.2</version>
+ <scope>compile</scope>
+ </dependency>
+
</dependencies>
<!-- ************************************************************* -->
@@ -41,9 +48,6 @@
<description>Plugin pour switcher de license dans un module maven 2</description>
<inceptionYear>2008</inceptionYear>
- <!-- BE WARE, this value must rewritten here since it will be otherwise suffixed by inheritance -->
- <url>${labs.project.url}</url>
-
<!-- ************************************************************* -->
<!-- *** Build Settings ****************************************** -->
<!-- ************************************************************* -->
@@ -58,19 +62,18 @@
<groupId>org.codelutin</groupId>
<artifactId>maven-jrst-plugin</artifactId>
<version>0.8.2</version>
- <configuration>
- <directoryIn>${maven.src.dir}/site</directoryIn>
- <directoryOut>${maven.site.gen.dir}</directoryOut>
- <verbose>${maven.verbose}</verbose>
- <defaultLocale>fr</defaultLocale>
- <inputEncoding>${maven.compile.encoding}</inputEncoding>
- <outputEncoding>${maven.compile.encoding}</outputEncoding>
- </configuration>
+ </plugin>
+
+ <!-- plugin jrst -->
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-license-switcher-plugin</artifactId>
+ <version>0.2</version>
<executions>
<execution>
- <phase>pre-site</phase>
<goals>
- <goal>jrst</goal>
+ <goal>license</goal>
+ <goal>third-party</goal>
</goals>
</execution>
</executions>
@@ -97,8 +100,7 @@
<scm>
<connection>${maven.scm.connection}</connection>
<developerConnection>${maven.scm.developerConnection}</developerConnection>
- <!-- This does'nt work for viewcvs.php with stat-scm with svn conf :(
- <url>${maven.scm.url}</url> -->
+ <url>${maven.scm.url}</url>
</scm>
</project>
1
0