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
May 2009
- 3 participants
- 151 discussions
[Lutinutil-commits] r1477 - in lutinutil/trunk: . src/main/java/org/codelutin/i18n src/test/java/org/codelutin/i18n/bundle
by tchemit@users.labs.libre-entreprise.org 08 May '09
by tchemit@users.labs.libre-entreprise.org 08 May '09
08 May '09
Author: tchemit
Date: 2009-05-08 16:03:32 +0000 (Fri, 08 May 2009)
New Revision: 1477
Modified:
lutinutil/trunk/pom.xml
lutinutil/trunk/src/main/java/org/codelutin/i18n/I18n.java
lutinutil/trunk/src/test/java/org/codelutin/i18n/bundle/I18nBundleManagerTest.java
Log:
make tests works again on i18n
bump i18n plugin version
Modified: lutinutil/trunk/pom.xml
===================================================================
--- lutinutil/trunk/pom.xml 2009-05-08 15:44:52 UTC (rev 1476)
+++ lutinutil/trunk/pom.xml 2009-05-08 16:03:32 UTC (rev 1477)
@@ -77,7 +77,7 @@
<labs.project>lutinutil</labs.project>
- <i18n.version>0.9</i18n.version>
+ <i18n.version>0.11</i18n.version>
</properties>
<build>
Modified: lutinutil/trunk/src/main/java/org/codelutin/i18n/I18n.java
===================================================================
--- lutinutil/trunk/src/main/java/org/codelutin/i18n/I18n.java 2009-05-08 15:44:52 UTC (rev 1476)
+++ lutinutil/trunk/src/main/java/org/codelutin/i18n/I18n.java 2009-05-08 16:03:32 UTC (rev 1477)
@@ -294,7 +294,7 @@
*
* @return the instanciated i18n loader
*/
- protected static synchronized I18nLoader getLoader() {
+ public static synchronized I18nLoader getLoader() {
if (loader == null) {
loader = new I18nLoader(DEFAULT_LOCALE, uniqueBundleName);
Modified: lutinutil/trunk/src/test/java/org/codelutin/i18n/bundle/I18nBundleManagerTest.java
===================================================================
--- lutinutil/trunk/src/test/java/org/codelutin/i18n/bundle/I18nBundleManagerTest.java 2009-05-08 15:44:52 UTC (rev 1476)
+++ lutinutil/trunk/src/test/java/org/codelutin/i18n/bundle/I18nBundleManagerTest.java 2009-05-08 16:03:32 UTC (rev 1477)
@@ -18,16 +18,18 @@
*/
package org.codelutin.i18n.bundle;
+import org.codelutin.i18n.*;
import org.apache.commons.logging.LogFactory;
-import org.codelutin.i18n.I18n;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.net.MalformedURLException;
+import java.net.URL;
import java.net.URLClassLoader;
import java.util.Locale;
+import org.junit.Assert;
/**
* I18nBundleFinder Tester.
@@ -60,27 +62,20 @@
*/
public class I18nBundleManagerTest {
-
/** to use log facility, just put in your code: log.info(\"...\"); */
static private org.apache.commons.logging.Log log = LogFactory.getLog(I18nBundleManagerTest.class);
-
-
Locale locale;
-
static URLClassLoader loader;
-
Integer nbURLs = null;
- private I18nBundleManager bundleManager;
-
static enum BundleTest {
+
veryDummy(true, false, false, false, false, false),
dummy(true, true, true, true, true, true),
lutinutil(false, false, true, false, false, true),
onlyfr(true, true, false, false, false, false),
onylfr2(false, true, false, false, false, false),
onlyen(true, false, false, true, false, false);
-
boolean hasGene;
boolean hasFr;
boolean hasFrFR;
@@ -187,25 +182,25 @@
}
@BeforeClass
- public static void befireClass() throws MalformedURLException {
+ public static void beforeClass() throws MalformedURLException {
-// loader = (URLClassLoader) I18nBundleManagerTest.class.getClassLoader();
-//
-// URL[] urls = new URL[loader.getURLs().length + 2];
-//
-// urls[0] = new File("target" + File.separator + "test-classes" + File.separator + "i18n").toURI().toURL();
-// urls[1] = new File("target" + File.separator + "classes" + File.separator + "i18n").toURI().toURL();
-//
-// int i = 2;
-// for (URL url : loader.getURLs()) {
-// urls[i++] = url;
-// }
-// loader = new URLClassLoader(urls, loader);
-//
-// log.info("use loader " + loader + " (nb urls : " + loader.getURLs().length + ")");
-// for (URL url : loader.getURLs()) {
-// log.info("url found in classloader : " + url);
-// }
+ loader = (URLClassLoader) I18nBundleManagerTest.class.getClassLoader();
+
+ URL[] urls = new URL[loader.getURLs().length + 2];
+
+ urls[0] = new File("target" + File.separator + "test-classes" + File.separator + "i18n").toURI().toURL();
+ urls[1] = new File("target" + File.separator + "classes" + File.separator + "i18n").toURI().toURL();
+
+ int i = 2;
+ for (URL url : loader.getURLs()) {
+ urls[i++] = url;
+ }
+ loader = new URLClassLoader(urls, loader);
+
+ log.info("use loader " + loader + " (nb urls : " + loader.getURLs().length + ")");
+ for (URL url : loader.getURLs()) {
+ log.info("url found in classloader : " + url);
+ }
}
@After
@@ -215,25 +210,23 @@
@Test
public void testGetURLs() throws Exception {
-// bundleManager = I18n.getBundleManager();
-// Assert.assertEquals(getNbURLs(), bundleManager.getURLs(loader).length);
+ Assert.assertEquals(getNbURLs(), I18nBundleFactory.getURLs(loader).length);
}
@Test
public void testDetectBundles() throws Exception {
-// bundleManager = I18n.getBundleManager();
-// URL[] urls = bundleManager.getURLs(loader);
-// Assert.assertEquals(BundleTest.values().length, bundleManager.detectBundles(urls).size());
+ URL[] urls = I18nBundleFactory.getURLs(loader);
+ Assert.assertEquals(BundleTest.values().length, I18nBundleFactory.detectBundles(urls).size());
}
@Test
public void testGetBundles() throws Exception {
-// updateLanguage(null);
-// updateLanguage(Locale.FRENCH);
-// updateLanguage(Locale.ENGLISH);
-// updateLanguage(Locale.FRANCE);
-// updateLanguage(Locale.US);
-// updateLanguage(Locale.UK);
+ updateLanguage(null);
+ updateLanguage(Locale.FRENCH);
+ updateLanguage(Locale.ENGLISH);
+ updateLanguage(Locale.FRANCE);
+ updateLanguage(Locale.US);
+ updateLanguage(Locale.UK);
}
protected int getNbURLs() {
@@ -250,7 +243,6 @@
protected void updateLanguage(Locale newLocale) {
locale = newLocale;
I18n.init(locale);
- //I18n.init(locale, I18n.DEFAULT_ENCODING);
assertBundlesEntries();
}
@@ -272,7 +264,6 @@
}
if (isFrFR) {
-
}
if (isFrFR || isEnUS || isEnGB) {
@@ -280,10 +271,9 @@
} else if (isFr || isEn) {
nbEntries += BundleTest.getNbLanguageEntries(isFr, isEn);
}
-// bundleManager = I18n.getBundleManager();
-// Assert.assertEquals(nbGene + nbLang + nbFull, bundleManager.getBundles(locale).length);
+ I18nLoader i18nLoader = I18n.getLoader();
+ Assert.assertEquals(nbGene + nbLang + nbFull, i18nLoader.getBundles(locale).length);
// //TODO make eact match with promute logic !
-// Assert.assertTrue(nbEntries <= bundleManager.getBundleEntries(locale).length);
+ Assert.assertTrue(nbEntries <= i18nLoader.getBundleEntries(locale).length);
}
-
}
1
0
[Lutinutil-commits] r1476 - in maven-i18n-plugin/trunk: . src/main/java/org/codelutin/i18n/plugin src/main/java/org/codelutin/i18n/plugin/parser src/main/resources
by tchemit@users.labs.libre-entreprise.org 08 May '09
by tchemit@users.labs.libre-entreprise.org 08 May '09
08 May '09
Author: tchemit
Date: 2009-05-08 15:44:52 +0000 (Fri, 08 May 2009)
New Revision: 1476
Added:
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Bundle.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/I18nArtifact.java
Modified:
maven-i18n-plugin/trunk/changelog.txt
maven-i18n-plugin/trunk/pom.xml
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Generate.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Getter.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/PluginHelper.java
maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java
maven-i18n-plugin/trunk/src/main/resources/log4j.properties
Log:
- introduce bundle goal to merge all bundle into one for final application
- no more use of bundles property, prefer locales one (with real Locale object instead of simple String one...)
Modified: maven-i18n-plugin/trunk/changelog.txt
===================================================================
--- maven-i18n-plugin/trunk/changelog.txt 2009-05-08 15:41:38 UTC (rev 1475)
+++ maven-i18n-plugin/trunk/changelog.txt 2009-05-08 15:44:52 UTC (rev 1476)
@@ -1,3 +1,7 @@
+0.12 chemit ?
+ * 20090508 [chemit] - introduce bundle goal to merge all bundle into one for final application
+ - no more use of bundles property, prefer locales one (with real Locale object instead of simple String one...)
+
0.11 chemit 20090311
* 20090420 [chemit] - bump versions
* 20090417 [chemit] - replace bundles parameters from tyep String[] to String type to make easier configuration
Modified: maven-i18n-plugin/trunk/pom.xml
===================================================================
--- maven-i18n-plugin/trunk/pom.xml 2009-05-08 15:41:38 UTC (rev 1475)
+++ maven-i18n-plugin/trunk/pom.xml 2009-05-08 15:44:52 UTC (rev 1476)
@@ -9,7 +9,7 @@
<parent>
<groupId>org.codelutin</groupId>
<artifactId>lutinproject</artifactId>
- <version>3.5.2</version>
+ <version>3.5.3</version>
</parent>
<artifactId>maven-i18n-plugin</artifactId>
@@ -33,6 +33,12 @@
</dependency>
<dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-dependency-tree</artifactId>
+ <version>1.2</version>
+ </dependency>
+
+ <dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.0</version>
@@ -60,6 +66,13 @@
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutinutil</artifactId>
+ <version>${lutinutil.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
</dependencies>
<!-- ************************************************************* -->
@@ -88,7 +101,8 @@
<maven.version>2.0.10</maven.version>
<processor.version>0.17</processor.version>
- <lutinpluginutil.version>0.4</lutinpluginutil.version>
+ <lutinpluginutil.version>0.5-SNAPSHOT</lutinpluginutil.version>
+ <lutinutil.version>1.0.6-SNAPSHOT</lutinutil.version>
</properties>
<build>
Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java 2009-05-08 15:41:38 UTC (rev 1475)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java 2009-05-08 15:44:52 UTC (rev 1476)
@@ -23,6 +23,8 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
+import org.codelutin.i18n.I18n;
/**
* Classe permettant d'obenir les parametres pendant les différentes phases
@@ -41,8 +43,6 @@
* de traduction entre librairie
*/
protected static final String DIRECTORY_INSTALL = "i18n" + File.separatorChar;
- /** les bundles par defaut utilisés, si aucun bundle n'est renseigné. */
- //protected static final String[] DEFAULT_BUNDLES = new String[]{"fr_FR", "en_GB"};
/**
* Nom du projet.
*
@@ -122,7 +122,7 @@
protected boolean strictMode;
/** Liste des évènements */
protected List<ParserEvent> events = new ArrayList<ParserEvent>();
- protected String[] bundlesToUse;
+ protected Locale[] locales;
/**logger verbeux */
protected I18nLogger verboseLog;
@@ -151,10 +151,11 @@
if (verbose) {
getLog().info("config - verbose mode is on");
}
- bundlesToUse = bundles.split(",");
- for (int i = 0, j = bundlesToUse.length; i < j; i++) {
- bundlesToUse[i] = bundlesToUse[i].trim();
- }
+ locales = I18n.parseLocales(bundles);
+// bundlesToUse = bundles.split(",");
+// for (int i = 0, j = bundlesToUse.length; i < j; i++) {
+// bundlesToUse[i] = bundlesToUse[i].trim();
+// }
}
public String getArtifactId() {
Added: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Bundle.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Bundle.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Bundle.java 2009-05-08 15:44:52 UTC (rev 1476)
@@ -0,0 +1,323 @@
+/*
+ * *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */
+package org.codelutin.i18n.plugin;
+
+import java.net.MalformedURLException;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Properties;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactCollector;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
+import org.apache.maven.model.Resource;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.shared.dependency.tree.DependencyNode;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
+import org.codelutin.i18n.bundle.I18nBundleEntry;
+import org.codelutin.i18n.bundle.I18nBundleFactory;
+import org.codelutin.i18n.plugin.PluginHelper.I18nProperties;
+import org.codelutin.util.DependencyUtil;
+import org.codelutin.util.StringUtil;
+
+/**
+ * Créer un bundle pour une application finale.
+ *
+ * Cela génère un merge de tous les fichiers i18n utilisés en un seul.
+ *
+ * On utilise la dépendance sur les artifacts pour connaitre l'ordre le chargement
+ * des bundles.
+ *
+ * Si dans un bundle childs, la valeur de la clef est vide, on conserve alors celui
+ * du parent,
+ *
+ * Ainsi on obtient un bundle dont toutes les clefs sont traduites.
+ *
+ * Le but aussi d'utiliser un unique bundle est de gagner du temps au runtime
+ * car la recherche des bundles devient trop couteuse en temps lorsque l'on a de
+ * nombreuses dépendances (au dessus de 100 deps cela peut prendre plusieurs
+ * secondes, ce qui 'est pas acceptable).
+ *
+ * On a ajoute un second mode d'initialisation dans la clesse I18n pour n'utiliser
+ * qu'un seul bundle et courcircuiter le chargement couteux...
+ * *
+ *
+ * @author chemit
+ * @goal bundle
+ * @phase generate-resources
+ * @execute goal=gen
+ * @requiresProject true
+ * @requiresDependencyResolution runtime
+ *
+ * @since 0.12
+ */
+public class Bundle extends AbstractI18nPlugin {
+
+ /**
+ * Repertoire ou generer les bundles.
+ *
+ * @parameter expression="${i18n.bundleOutputDir}" default-value="${basedir}/target/generated-sources/java/META-INF"
+ * @required
+ */
+ protected File bundleOutputDir;
+ /**
+ * Nom du bundle a generer.
+ *
+ * @parameter expression="${i18n.bundleOutputName}" default-value="${project.artifactId}-i18n"
+ * @required
+ */
+ protected String bundleOutputName;
+ /**
+ * Dependance du projet.
+ *
+ * @parameter default-value="${project}"
+ * @required
+ */
+ protected MavenProject project;
+ /**
+ * Local Repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ * @readonly
+ */
+ protected ArtifactRepository localRepository;
+ /**
+ * Remote repositories used for the project.
+ *
+ * @parameter expression="${project.remoteArtifactRepositories}"
+ * @required
+ * @readonly
+ */
+ protected List<?> remoteRepositories;
+ /**
+ * Dependency tree builder component.
+ *
+ * @component
+ */
+ protected DependencyTreeBuilder dependencyTreeBuilder;
+ /**
+ * Artifact Factory component.
+ *
+ * @component
+ */
+ protected ArtifactFactory factory;
+ /**
+ * Artifact metadata source component.
+ *
+ * @component
+ */
+ protected ArtifactMetadataSource artifactMetadataSource;
+ /**
+ * Artifact collector component.
+ *
+ * @component
+ */
+ protected ArtifactCollector collector;
+ /**
+ * Maven Project Builder component.
+ *
+ * @component
+ */
+ protected MavenProjectBuilder mavenProjectBuilder;
+ protected I18nArtifact[] i18nArtifacts;
+ protected ClassLoader loader;
+ protected URL[] urls;
+
+ @Override
+ public void init() {
+ super.init();
+
+ if (locales == null || locales.length == 0) {
+ throw new IllegalStateException("il faut au moins une locale declaree (utiliser la propriete 'bundles')");
+ }
+
+ if (!bundleOutputDir.exists()) {
+ bundleOutputDir.mkdirs();
+ }
+
+ try {
+ // calcul des artifacts qui ont un bundle i18n et trie selon les
+ // dependances
+
+ i18nArtifacts = detectI18nArtifacts();
+
+ getLog().info("detected " + i18nArtifacts.length + " i18n artifact(s) : ");
+ for (I18nArtifact a : i18nArtifacts) {
+ getLog().info(" - " + a.getArtifact());
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+
+ // ajout de repertoire de generation (le parent en fait)
+ // dans les resources du projet
+
+ String newresourceDir = bundleOutputDir.getParentFile().getAbsolutePath();
+
+ List<?> resources = project.getResources();
+ boolean shouldAdd = true;
+ for (Object o : resources) {
+ Resource r = (Resource) o;
+ if (!r.getDirectory().equals(newresourceDir)) {
+ continue;
+ }
+
+ r.addInclude("**/*.properties");
+ shouldAdd = false;
+ break;
+ }
+ if (shouldAdd) {
+ Resource r = new Resource();
+ r.setDirectory(newresourceDir);
+ r.addInclude("**/*.properties");
+ //if (verbose) {
+ getLog().info("add resource " + r);
+ //}
+ project.addResource(r);
+ }
+ }
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+
+ if ("pom".equals(project.getPackaging()) || "site".equals(project.getPackaging())) {
+ return;
+ }
+
+ long t00 = System.nanoTime();
+
+ init();
+
+ Locale defaultLocale = locales[0];
+ try {
+ for (Locale locale : locales) {
+
+ long t0 = System.nanoTime();
+
+ File bundleOut = PluginHelper.getI18nFile(bundleOutputDir, bundleOutputName, locale, false);
+
+ getLog().info("prepare bundle " + bundleOut.getAbsolutePath());
+
+ I18nProperties propertiesOut = new I18nProperties(encoding, false);
+
+ for (I18nArtifact artifact : i18nArtifacts) {
+ I18nBundleEntry[] bundleEntries = artifact.getBundleEntries(locale, defaultLocale);
+ for (I18nBundleEntry bundleEntry : bundleEntries) {
+
+ bundleEntry.load(propertiesOut);
+
+ if (verbose) {
+ getLog().info("loaded " + bundleEntry.getPath() + " in " + StringUtil.convertTime(t0, System.nanoTime()));
+ }
+ }
+ }
+ propertiesOut.store(bundleOut);
+ if (verbose) {
+ getLog().info("bundle created in " + StringUtil.convertTime(t0, System.nanoTime()) + " (detected sentences : " + propertiesOut.size() + ")");
+ }
+ }
+
+ // ecriture du ficher des definitions i18n (permet de faire une
+ // recherche extact sur un fichier puis d'en deduire les bundles a
+ // charger
+ String f = String.format(I18nBundleFactory.UNIQUE_BUNDLE_DEF, bundleOutputName);
+ File defOut = new File(bundleOutputDir, f);
+ getLog().info("prepare i18n definition " + defOut.getAbsolutePath());
+ Properties p = new Properties();
+ p.setProperty(I18nBundleFactory.BUNDLE_DEF_LOCALES, bundles);
+ p.store(new FileOutputStream(defOut), null);
+
+ if (verbose) {
+ getLog().info("done in " + StringUtil.convertTime(t00, System.nanoTime()));
+ }
+ } catch (IOException e) {
+ getLog().error("File Error I/O ", e);
+ throw new MojoFailureException("File Error I/O ");
+ }
+ }
+
+ /**
+ * Detecte les {@link I18nArtifact} et les retourne dans l'ordre de chargement
+ * dans le système i18n, i.e l'ordre des dependances entre artifacts.
+ *
+ * @return les artifacts i18nables triés par leur ordre de chargement dans le système i18n.
+ *
+ * @throws java.net.MalformedURLException
+ * @throws java.io.IOException
+ * @throws org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException
+ */
+ protected I18nArtifact[] detectI18nArtifacts() throws MalformedURLException, IOException, DependencyTreeBuilderException {
+
+ Map<Artifact, I18nArtifact> dico = new java.util.HashMap<Artifact, I18nArtifact>();
+
+ I18nArtifact i18nArtifact;
+ for (Object o : project.getArtifacts()) {
+ i18nArtifact = new I18nArtifact((Artifact) o);
+ if (i18nArtifact.detectBundles()) {
+ if (verbose) {
+ getLog().info("detected artifact " + i18nArtifact.getArtifact());
+ }
+ dico.put(i18nArtifact.getArtifact(), i18nArtifact);
+ }
+ }
+
+ ArtifactFilter artifactFilter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
+
+ DependencyNode rootNode = dependencyTreeBuilder.buildDependencyTree(project, localRepository, factory,
+ artifactMetadataSource, artifactFilter, collector);
+
+ List<Artifact> artifacts = new java.util.ArrayList<Artifact>(dico.keySet());
+
+ DependencyUtil.sortArtifacts(rootNode, artifacts, verbose);
+
+ // l'artifact du projet est traite en dernier car s'il possède des
+ // bundles alors ils doivent etre charge en dernier
+
+ Artifact projectArtifact = project.getArtifact();
+ i18nArtifact = new I18nArtifact(projectArtifact, src.getParentFile());
+
+ if (i18nArtifact.detectBundles()) {
+ if (verbose) {
+ getLog().info("detected artifact " + i18nArtifact.getArtifact());
+ }
+ artifacts.add(i18nArtifact.getArtifact());
+ dico.put(i18nArtifact.getArtifact(), i18nArtifact);
+ }
+
+ I18nArtifact[] result = new I18nArtifact[artifacts.size()];
+ int i = 0;
+ for (Artifact artifact : artifacts) {
+ result[i++] = dico.get(artifact);
+ }
+ return result;
+ }
+}
Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Generate.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Generate.java 2009-05-08 15:41:38 UTC (rev 1475)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Generate.java 2009-05-08 15:44:52 UTC (rev 1476)
@@ -26,6 +26,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.util.Locale;
/**
* Merge des fichiers de propriétés avec les anciens.
@@ -37,10 +38,6 @@
*/
public class Generate extends AbstractI18nPlugin {
- /*
- * (non-Javadoc)
- * @see org.apache.maven.plugin.AbstractMojo#execute()
- */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
@@ -51,7 +48,7 @@
return;
}
- for (String bundle : bundlesToUse) {
+ for (Locale bundle : locales) {
try {
// Merge
File bundleSrc = PluginHelper.getI18nFile(src, artifactId, bundle, false);
Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Getter.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Getter.java 2009-05-08 15:41:38 UTC (rev 1475)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Getter.java 2009-05-08 15:44:52 UTC (rev 1476)
@@ -25,8 +25,8 @@
import org.codelutin.util.FileUtil;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.IOException;
+import java.util.Locale;
/**
* Recupere les différents fichiers des parsers en un fichier de proprietes.
@@ -74,7 +74,7 @@
}
// Création des bundles
- for (String bundle : bundlesToUse) {
+ for (Locale bundle : locales) {
File bundleOut = PluginHelper.getI18nFile(out, artifactId, bundle, false);
FileUtil.copy(bundleGetters, bundleOut);
if (verbose) {
Added: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/I18nArtifact.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/I18nArtifact.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/I18nArtifact.java 2009-05-08 15:44:52 UTC (rev 1476)
@@ -0,0 +1,74 @@
+package org.codelutin.i18n.plugin;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+import java.util.Locale;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.maven.artifact.Artifact;
+import org.codelutin.i18n.bundle.I18nBundle;
+import org.codelutin.i18n.bundle.I18nBundleEntry;
+import org.codelutin.i18n.bundle.I18nBundleFactory;
+
+/**
+ *
+ * @author chemit
+ * @since 0.12
+ */
+public class I18nArtifact {
+
+ static final Log log = LogFactory.getLog(I18nArtifact.class);
+ protected final Artifact artifact;
+ protected final URL url;
+ protected I18nBundle[] bundles;
+
+ public I18nArtifact(Artifact artifact) throws MalformedURLException {
+ this.artifact = artifact;
+ this.url = artifact.getFile().toURI().toURL();
+ }
+
+ public I18nArtifact(Artifact artifact, File file) throws MalformedURLException {
+ this.artifact = artifact;
+ this.url = file.toURI().toURL();
+ }
+
+ public Artifact getArtifact() {
+ return artifact;
+ }
+
+ public URL getUrl() {
+ return url;
+ }
+
+ public I18nBundleEntry[] getBundleEntries(Locale l, Locale defaultLocale) {
+ if (bundles == null) {
+ throw new NullPointerException("le bundleManager n'a pas ete initialise!");
+ }
+ return I18nBundleFactory.getBundleEntries(l, defaultLocale, bundles);
+ }
+
+ public boolean detectBundles() throws IOException {
+
+ URL[] i18nUrls = I18nBundleFactory.getURLs(url);
+
+ if (i18nUrls == null || i18nUrls.length == 0) {
+ // aucune url sur un fichier de traduction trouve
+ // l'artifact n'est pas i18n.
+ return false;
+ }
+
+ List<I18nBundle> listBundles = I18nBundleFactory.detectBundles(i18nUrls);
+
+ if (listBundles.isEmpty()) {
+ // pas de bundle instancie (cela ne devrait jamias arrive...)
+ return false;
+ }
+
+ this.bundles = listBundles.toArray(new I18nBundle[listBundles.size()]);
+
+ return true;
+ }
+}
Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/PluginHelper.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/PluginHelper.java 2009-05-08 15:41:38 UTC (rev 1475)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/PluginHelper.java 2009-05-08 15:44:52 UTC (rev 1476)
@@ -30,6 +30,7 @@
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
+import java.util.Locale;
import java.util.Properties;
import java.util.Vector;
@@ -46,13 +47,13 @@
/**
* @param root le repertoire ou sont stockes les fichiers i18n
* @param artifactId le nom de l'artifact
- * @param bundle le nom du bundle
+ * @param locale le nom du bundle
* @param create <code>true</code> pour creer le fichier si non present
* @return le fichier i18n
* @throws java.io.IOException si probleme lors de la creation du fichier
*/
- public static File getI18nFile(File root, String artifactId, String bundle, boolean create) throws IOException {
- File file = new File(root.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties");
+ public static File getI18nFile(File root, String artifactId, Locale locale, boolean create) throws IOException {
+ File file = new File(root.getAbsolutePath() + File.separatorChar + artifactId + "-" + locale.toString() + ".properties");
if (create && !file.exists()) {
if (!file.exists()) {
file.getParentFile().mkdirs();
@@ -95,8 +96,8 @@
* @param bundle le nom du bundle
* @return le fichier i18n de backup
*/
- public static File getI18nFileBackup(File root, String artifactId, String bundle) {
- return new File(root.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties~");
+ public static File getI18nFileBackup(File root, String artifactId, Locale bundle) {
+ return new File(root.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle.toString() + ".properties~");
}
/**
@@ -108,6 +109,7 @@
* <p/>
* Note : <b>Aucune liste n'est creee, ni recopiee</b>
*
+ * @param <O> le type des objets de la liste
* @param list la liste a convertir
* @param type le type des elements de la liste
* @return la liste typee
@@ -115,24 +117,20 @@
* pas en adequation avec le type voulue.
*/
@SuppressWarnings({"unchecked"})
- static public <O> List<O> toGenericList(List list, Class<O> type) throws IllegalArgumentException {
+ static public <O> List<O> toGenericList(List<?> list, Class<O> type) throws IllegalArgumentException {
if (list.isEmpty()) {
- return list;
+ return (List<O>) list;
}
for (Object o : list) {
if (!(type.isAssignableFrom(o.getClass()))) {
throw new IllegalArgumentException("can not cast List with object of type " + o.getClass() + " to " + type + " type!");
}
}
- return list;
+ return (List<O>) list;
}
-
-
static final protected double[] timeFactors = {1000000, 1000, 60, 60, 24};
+ static final protected String[] timeUnites = {"ns", "ms", "s", "m", "h", "d"};
- static final protected String[] timeUnites = {"ns", "ms", "s", "m", "h",
- "d"};
-
static public String convertTime(long value) {
return convert(value, timeFactors, timeUnites);
}
@@ -165,13 +163,19 @@
public static class I18nProperties extends Properties {
private static final long serialVersionUID = -1147150444452577558L;
-
/** l'encoding a utiliser pour lire et ecrire le properties. */
protected String encoding;
+ /** un drapeau pour savoir s'il faut enlever l'entete generere */
+ protected boolean removeHeader;
public I18nProperties(String encoding) {
+ this(encoding, true);
+ }
+
+ public I18nProperties(String encoding, boolean removeHeader) {
super();
this.encoding = encoding;
+ this.removeHeader = removeHeader;
}
public I18nProperties(Properties defaults) {
@@ -214,7 +218,11 @@
* @throws IOException if any io pb
*/
public void store(File dst) throws IOException {
- super.store(new OutputStreamWriter(new PropertiesDateRemoveFilterStream(new FileOutputStream(dst)), encoding), null);
+ if (removeHeader) {
+ super.store(new OutputStreamWriter(new PropertiesDateRemoveFilterStream(new FileOutputStream(dst)), encoding), null);
+ } else {
+ super.store(new FileOutputStream(dst), null);
+ }
}
/**
@@ -224,10 +232,25 @@
* @throws IOException if any io pb
*/
public void store(OutputStream dst) throws IOException {
- super.store(new PropertiesDateRemoveFilterStream(dst), null);
+ if (removeHeader) {
+ super.store(new PropertiesDateRemoveFilterStream(dst), null);
+ } else {
+ super.store(dst, null);
+ }
}
}
+ /**
+ * Un ecrivain qui supprime la premiere ligne rencontree dans le flux.
+ *
+ *
+ * <b>Note: </b> Attention, les performance d'utilisation de cet ecrivain
+ * est problèmatique, car sur de gros fichiers (>1000 entrees) les
+ * performances se degradent serieusement : pour 1200 entrees on arrive à
+ * plus de 5 secondes, alors que sans on a 76 ms! ...
+ *
+ * FIXME : implanter quelque chose de plus performant dans tous les cas
+ */
public static class PropertiesDateRemoveFilterStream extends FilterOutputStream {
private boolean firstLineOver;
@@ -252,5 +275,4 @@
}
}
}
-
}
Modified: maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java 2009-05-08 15:41:38 UTC (rev 1475)
+++ maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java 2009-05-08 15:44:52 UTC (rev 1476)
@@ -153,7 +153,7 @@
// Anciennes cles disponnibles
//fixme : pourquoi on utilise un bundle precis ? le premier ici, je ne comprends pas
- File oldLanguageFile = PluginHelper.getI18nFile(src, artifactId, bundlesToUse[0], true);
+ File oldLanguageFile = PluginHelper.getI18nFile(src, artifactId, locales[0], true);
oldLanguage.load(oldLanguageFile);
@@ -322,9 +322,9 @@
return true;
}
- String[] files = getFilesForEntry(mojo);
+ String[] filesForEntry = getFilesForEntry(mojo);
- if (files.length == 0) {
+ if (filesForEntry.length == 0) {
// skip no file found
skipMessage = "no file found.";
return true;
@@ -334,7 +334,7 @@
if (mojo.strictMode || updater == null) {
// mojo strict mode or not updater, so force all files
skipFiles = new String[0];
- this.files = files;
+ this.files = filesForEntry;
return false;
}
@@ -342,7 +342,7 @@
List<String> listSkipFiles = new ArrayList<String>();
// test if have any file
- for (String foundFile : files) {
+ for (String foundFile : filesForEntry) {
File file = new File(getBasedir(), foundFile);
if (isFileUptodate(file)) {
listSkipFiles.add(foundFile);
Modified: maven-i18n-plugin/trunk/src/main/resources/log4j.properties
===================================================================
--- maven-i18n-plugin/trunk/src/main/resources/log4j.properties 2009-05-08 15:41:38 UTC (rev 1475)
+++ maven-i18n-plugin/trunk/src/main/resources/log4j.properties 2009-05-08 15:44:52 UTC (rev 1476)
@@ -7,4 +7,4 @@
# package level
log4j.logger.org.codelutin.util=INFO
-
+log4j.logger.org.codelutin.i18n.plugin=INFO
1
0
[Lutinutil-commits] r1475 - in lutinutil/trunk: . src/main/java/org/codelutin/i18n src/main/java/org/codelutin/i18n/bundle src/test/java/org/codelutin/i18n src/test/java/org/codelutin/i18n/bundle
by tchemit@users.labs.libre-entreprise.org 08 May '09
by tchemit@users.labs.libre-entreprise.org 08 May '09
08 May '09
Author: tchemit
Date: 2009-05-08 15:41:38 +0000 (Fri, 08 May 2009)
New Revision: 1475
Added:
lutinutil/trunk/src/main/java/org/codelutin/i18n/bundle/I18nBundleFactory.java
Modified:
lutinutil/trunk/changelog.txt
lutinutil/trunk/src/main/java/org/codelutin/i18n/I18n.java
lutinutil/trunk/src/main/java/org/codelutin/i18n/I18nLoader.java
lutinutil/trunk/src/main/java/org/codelutin/i18n/Language.java
lutinutil/trunk/src/main/java/org/codelutin/i18n/LocaleEditor.java
lutinutil/trunk/src/main/java/org/codelutin/i18n/bundle/I18nBundleManager.java
lutinutil/trunk/src/main/java/org/codelutin/i18n/bundle/I18nBundleScope.java
lutinutil/trunk/src/test/java/org/codelutin/i18n/I18nLoaderTest.java
lutinutil/trunk/src/test/java/org/codelutin/i18n/bundle/I18nBundleManagerTest.java
Log:
refactor i18n loading with a direct loding mode (see alos i18n:bundle goal)
Modified: lutinutil/trunk/changelog.txt
===================================================================
--- lutinutil/trunk/changelog.txt 2009-05-08 13:59:08 UTC (rev 1474)
+++ lutinutil/trunk/changelog.txt 2009-05-08 15:41:38 UTC (rev 1475)
@@ -1,4 +1,7 @@
-ver 1.0.5 chatellier xxxxxx
+ver 1.0.6
+ * 20090508 [chemit] - refactor i18n loading with a direct loding mode (see alos i18n:bundle goal)
+
+ver 1.0.5 chatellier xxxxxx ?
* Add Tar/bzip2 utility class
* Add md5 creation on ZipUtil methods
* Change MD5 implementation to http://ostermiller.org/utils/MD5.html one.
Modified: lutinutil/trunk/src/main/java/org/codelutin/i18n/I18n.java
===================================================================
--- lutinutil/trunk/src/main/java/org/codelutin/i18n/I18n.java 2009-05-08 13:59:08 UTC (rev 1474)
+++ lutinutil/trunk/src/main/java/org/codelutin/i18n/I18n.java 2009-05-08 15:41:38 UTC (rev 1475)
@@ -27,17 +27,16 @@
* Mise a jour: $Date$
* par : $Author$
*/
-
package org.codelutin.i18n;
import java.net.URL;
import java.util.Arrays;
+import java.util.List;
import java.util.Locale;
import java.util.logging.Logger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.codelutin.i18n.bundle.I18nBundleManager;
import org.codelutin.util.ConverterUtil;
/**
@@ -63,33 +62,41 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
private static Log log = LogFactory.getLog(I18n.class);
-
public static final String ISO_8859_1_ENCONDING = "ISO-8859-1";
-
public static final String UTF_8_ENCONDING = "UTF-8";
-
public static final String DEFAULT_ENCODING = ISO_8859_1_ENCONDING;
-
public static final Locale DEFAULT_LOCALE = Locale.UK;
-
/** la classe responsable du chargement des ressources */
static I18nLoader loader;
-
/** la gestionnaire de bundle */
- static I18nBundleManager bundleManager;
-
+// static I18nBundleManager bundleManager;
/** Filtre a appliquer avant de retourner les chaines */
protected static I18nFilter filter;
-
/** Indique le chemin du fichier dans lequel ecrire les entrees non trouvees */
protected static String recordFilePath;
-
/**
* some extra urls to given to bundle manager.
* <p/>
* Note: use this before call <code>init(...)</code> methods
*/
static URL[] extraURL;
+ /**
+ * le nom d'un unique bundle à utiliser.
+ *
+ * Si l'on positionne cette propriété, on n'utilisera pas la recherche
+ * classique des bunldes à charger mais on se contentera de rechercher
+ * le bundle (et ses entrées) à cet emplacement
+ * <code>META-INF/uniqueBundleName-XXX.properties</code>.
+ *
+ * Cela permet de chargement I18n en une seule fois et de ne scruter qu'un
+ * seul jar (ou repertoire)...
+ *
+ * Un goal dans le plugin i18n (i18n:bundle) permet de construire le bundle
+ * englobant toutes les autres traductions avec gestion des dépendances.
+ *
+ * @since 1.0.6
+ */
+ protected static String uniqueBundleName;
/** Initialise la librairie avec encoding par defaut et locale par defaut */
public static void init() {
@@ -102,7 +109,10 @@
* @param locale language to use
*/
public static void init(Locale locale) {
- getLoader().setLanguage(locale == null ? newLocale(null, null) : locale, getBundleManager());
+ if (locale == null) {
+ locale = newLocale(null, null);
+ }
+ getLoader().setLanguage(locale);
}
/**
@@ -149,7 +159,7 @@
try {
return applyFilter(String.format(message, args));
} catch (Exception zzz) {
- log.warn(I18n._("lutinutil.error.i18n.untranslated.message", message));
+ log.warn(I18n._("lutinutil.error.i18n.untranslated.message", message), zzz);
return applyFilter(message);
}
}
@@ -168,7 +178,7 @@
try {
return String.format(message, args);
} catch (Exception eee) {
- log.warn(I18n._("lutinutil.error.i18n.unformated.message", message, Arrays.toString(args)));
+ log.warn(I18n._("lutinutil.error.i18n.unformated.message", message, Arrays.toString(args)), eee);
return message;
}
}
@@ -194,6 +204,15 @@
}
/**
+ *@return the unique bundle name to use for loading of system
+ *
+ * @since 1.0.6
+ */
+ public static String getUniqueBundleName() {
+ return uniqueBundleName;
+ }
+
+ /**
* Change le filtre des chaines traduites
*
* @param filter l'objet filtre a utiliser
@@ -209,21 +228,38 @@
/**
* Change extra urls to use in bundle discovering
* <p/>
- * Note: <b>This method will close the i18n system and reset cache of url in {@link I18nBundleManager}</b>
+ * Note: <b>This method will close the i18n system.</b>
*
* @param extraURL new extra urls to use
*/
public static void setExtraURL(URL[] extraURL) {
I18n.extraURL = extraURL;
- // must reset bundlemanager urls
- I18nBundleManager.resetURL();
+ // must reset loader urls
+ I18nLoader.urls = null;
// and close system
close();
}
/**
- * close i18n caches, says the loader if exists and bundleManager if exists
+ * Change the unique bunlde name to use
* <p/>
+ * Note: <b>This method will close the i18n system.</b>
+ *
+ * @param uniqueBundleName the new unique bundle pattern to use
+ *
+ * @since 1.0.6
+ */
+ public static void setUniqueBundleName(String uniqueBundleName) {
+ I18n.uniqueBundleName = uniqueBundleName;
+ // must reset loader urls
+ I18nLoader.urls = null;
+ // and close system
+ close();
+ }
+
+ /**
+ * close i18n caches, says the loader if exists
+ * <p/>
* This method should be called to reset all caches (languages, bundles,...)
*/
public static void close() {
@@ -231,10 +267,6 @@
loader.close();
loader = null;
}
- if (bundleManager != null) {
- bundleManager.close();
- bundleManager = null;
- }
}
/**
@@ -255,13 +287,6 @@
return filter;
}
- public static synchronized I18nBundleManager getBundleManager() {
- if (bundleManager == null) {
- bundleManager = new I18nBundleManager(DEFAULT_LOCALE);
- }
- return bundleManager;
- }
-
/**
* Get the i18n loader.
* <p/>
@@ -272,11 +297,36 @@
protected static synchronized I18nLoader getLoader() {
if (loader == null) {
- loader = new I18nLoader(DEFAULT_ENCODING);
+ loader = new I18nLoader(DEFAULT_LOCALE, uniqueBundleName);
}
return loader;
}
+ /**
+ * Parse a list of {@link Locale} sepearated by comma.
+ *
+ * Example : fr_FR,en_GB
+ *
+ * @param str the string representation of locale separated by comma
+ * @return
+ * @throws IllegalArgumentException ia a locale is not valid
+ */
+ public static Locale[] parseLocales(String str) throws IllegalArgumentException {
+ List<Locale> result = new java.util.ArrayList<Locale>();
+ String[] bundlesToUse = str.split(",");
+ for (int i = 0, j = bundlesToUse.length; i < j; i++) {
+ String s = bundlesToUse[i].trim();
+ // on devrait verifier que le bundle existe
+ try {
+ Locale l = ConverterUtil.convert(Locale.class, s);
+ result.add(l);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("bundle " + s + " is not a valid locale,e");
+ }
+ }
+ return result.toArray(new Locale[result.size()]);
+ }
+
public static Locale newLocale(String str) {
if (str == null) {
// get use locale
Modified: lutinutil/trunk/src/main/java/org/codelutin/i18n/I18nLoader.java
===================================================================
--- lutinutil/trunk/src/main/java/org/codelutin/i18n/I18nLoader.java 2009-05-08 13:59:08 UTC (rev 1474)
+++ lutinutil/trunk/src/main/java/org/codelutin/i18n/I18nLoader.java 2009-05-08 15:41:38 UTC (rev 1475)
@@ -18,13 +18,17 @@
*/
package org.codelutin.i18n;
+import java.net.URL;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.codelutin.i18n.bundle.I18nBundleManager;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
+import org.codelutin.i18n.bundle.I18nBundle;
+import org.codelutin.i18n.bundle.I18nBundleEntry;
+import org.codelutin.i18n.bundle.I18nBundleFactory;
+import org.codelutin.util.StringUtil;
/**
* Classe responsible of loading of I18n system.
@@ -40,19 +44,28 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
private static final Log log = LogFactory.getLog(I18nLoader.class);
-
/** le language actuellement utilise */
protected Language language;
-
/** le cache de languages deja charges */
protected List<Language> languages;
+ /** le cache des urls de recheche des bundles */
+ protected static URL[] urls;
+ /** le cache de bundles deja charges */
+ protected I18nBundle[] bundles;
+ /** la locale par defaut a utiliser */
+ protected final Locale defaultLocale;
+ /** le nom de l'unique bunlde a charger (mode unique) */
+ protected final String uniqueBundleName;
- public I18nLoader(String encoding) {
- if(log.isDebugEnabled()) {
- log.debug("using encoding " + encoding);
- }
+ public I18nLoader(Locale defaultLocale) {
+ this(defaultLocale, null);
}
+ public I18nLoader(Locale defaultLocale, String uniqueBundleName) {
+ this.defaultLocale = defaultLocale;
+ this.uniqueBundleName = uniqueBundleName;
+ }
+
/** @return current language loaded or null, if no language was load */
public Language getLanguage() {
return language;
@@ -66,20 +79,98 @@
return languages;
}
+ public Locale getDefaultLocale() {
+ return defaultLocale;
+ }
+
+ public boolean isEmpty() {
+ checkInit();
+ boolean isEmpty = I18nBundleFactory.isEmpty(bundles);
+ return isEmpty;
+ }
+
+ /** @return array of all locales loaded */
+ public Locale[] getLocales() {
+ checkInit();
+ Locale[] result = I18nBundleFactory.getLocales(bundles);
+ return result;
+ }
+
+ public I18nBundle[] getBundles() {
+ checkInit();
+ return bundles;
+ }
+
+ public I18nBundle[] getBundles(Locale l) {
+ checkInit();
+ I18nBundle[] result = I18nBundleFactory.getBundles(l, bundles);
+ return result;
+ }
+
+ public I18nBundleEntry[] getBundleEntries() {
+ checkInit();
+ I18nBundleEntry[] result = I18nBundleFactory.getBundleEntries(bundles);
+ return result;
+ }
+
+ public I18nBundleEntry[] getBundleEntries(Locale l) {
+ checkInit();
+ I18nBundleEntry[] result = I18nBundleFactory.getBundleEntries(l, defaultLocale, bundles);
+ return result;
+ }
+
+ void init() {
+
+ if (isInit()) {
+ // already init
+ return;
+ }
+
+ // get all bundles urls
+ if (urls == null || urls.length == 0) {
+
+ // cache this expensive search
+
+ if (uniqueBundleName != null) {
+ // on recherche directement un bundle precis a aprtir
+ // de son fichier de definition
+ urls = I18nBundleFactory.getURLs(uniqueBundleName);
+ if (urls == null) {
+ log.warn("coudl not find uniqueBundleName i18n " + uniqueBundleName);
+ }
+ }
+ if (urls == null) {
+ // on utilise le mecanisme de recherche des bundles dans toutes
+ // les entrees du classloader
+ urls = I18nBundleFactory.getURLs(Language.getLoader(), I18n.getExtraURL());
+ }
+ }
+
+ long t0 = System.nanoTime();
+
+ // detect bundles
+ List<I18nBundle> bundleDetected = I18nBundleFactory.detectBundles(urls);
+
+ // save bundles in cache
+ this.bundles = bundleDetected.toArray(new I18nBundle[bundleDetected.size()]);
+
+ log.info(bundleDetected.size() + " bundle(s) found, [" + getBundleEntries().length + " file(s)] in " + StringUtil.convertTime(System.nanoTime() - t0));
+ }
+
/**
- * Set a new language in loader, given a locale. Bundle entries to load in language are stored in
- * <code>bundleManager</code>.
+ * Set a new language in loader, given a locale.
*
* @param locale la locale du language requis
* @param bundleManager bundle manager to used
*/
- synchronized void setLanguage(Locale locale, I18nBundleManager bundleManager) {
+ synchronized void setLanguage(Locale locale) {
+ init();
if (log.isDebugEnabled()) {
log.debug("locale: " + locale);
}
Language result = getLanguage(locale);
if (result == null) {
- result = addLanguage(locale, bundleManager);
+ result = addLanguage(locale);
} else {
log.debug("using cached language : " + result);
}
@@ -94,12 +185,18 @@
void close() {
if (languages != null) {
log.info("nb languages loaded : " + languages.size());
- for (Language language1 : languages) {
- language1.close();
+ for (Language l : languages) {
+ l.close();
}
languages.clear();
languages = null;
}
+ if (urls != null) {
+ urls = null;
+ }
+ if (bundles != null) {
+ bundles = null;
+ }
language = null;
}
@@ -110,24 +207,33 @@
Language getLanguage(Locale locale) {
if (!(languages == null || languages.isEmpty())) {
- for (Language language : languages) {
- if (locale.equals(language.getLocale())) {
- return language;
+ for (Language l : languages) {
+ if (locale.equals(l.getLocale())) {
+ return l;
}
}
}
return null;
}
- Language addLanguage(Locale locale, I18nBundleManager bundleManager) {
+ Language addLanguage(Locale locale) {
Language result;
result = new Language(locale);
- result.load(bundleManager);
- if (log.isDebugEnabled()) {
- log.debug(result);
- }
+ long t0 = System.nanoTime();
+ I18nBundleEntry[] entries = getBundleEntries(locale);
+ result.load(entries);
+ log.info(result + ", nbEntries: " + entries.length + ", nbSentences: " + result.size() + " in " + StringUtil.convertTime(System.nanoTime() - t0));
getLanguages().add(result);
return result;
}
+ boolean isInit() {
+ return bundles != null;
+ }
+
+ void checkInit() {
+ if (!isInit()) {
+ throw new IllegalStateException("should call init method on " + I18nLoader.class);
+ }
+ }
}
Modified: lutinutil/trunk/src/main/java/org/codelutin/i18n/Language.java
===================================================================
--- lutinutil/trunk/src/main/java/org/codelutin/i18n/Language.java 2009-05-08 13:59:08 UTC (rev 1474)
+++ lutinutil/trunk/src/main/java/org/codelutin/i18n/Language.java 2009-05-08 15:41:38 UTC (rev 1475)
@@ -34,6 +34,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.codelutin.i18n.bundle.I18nBundleEntry;
import org.codelutin.i18n.bundle.I18nBundleManager;
import org.codelutin.util.RecursiveProperties;
@@ -75,6 +76,7 @@
*
* @param bundleManager the used bundle manager
*/
+ @Deprecated
public void load(I18nBundleManager bundleManager) {
// make sure the bundlemanager is init
bundleManager.init();
@@ -89,6 +91,25 @@
}
/**
+ * charge les traductions de la languea partir d'une liste donnee de
+ * fichiers de traduction.
+ *
+ * @param bundleEntries the used bundles entries to load
+ */
+ public void load(I18nBundleEntry[] bundleEntries) {
+
+ resource = new RecursiveProperties();
+
+ try {
+ for (I18nBundleEntry e : bundleEntries) {
+ e.load(resource);
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
* translate takes a sentence and returns its translation if found, the very
* same string otherwise.
*
Modified: lutinutil/trunk/src/main/java/org/codelutin/i18n/LocaleEditor.java
===================================================================
--- lutinutil/trunk/src/main/java/org/codelutin/i18n/LocaleEditor.java 2009-05-08 13:59:08 UTC (rev 1474)
+++ lutinutil/trunk/src/main/java/org/codelutin/i18n/LocaleEditor.java 2009-05-08 15:41:38 UTC (rev 1475)
@@ -50,7 +50,7 @@
return type;
}
// get availables locales registred in I18n system
- type = I18n.getBundleManager().getLocales();
+ type = I18n.getLoader().getLocales();
return type;
}
Added: lutinutil/trunk/src/main/java/org/codelutin/i18n/bundle/I18nBundleFactory.java
===================================================================
--- lutinutil/trunk/src/main/java/org/codelutin/i18n/bundle/I18nBundleFactory.java (rev 0)
+++ lutinutil/trunk/src/main/java/org/codelutin/i18n/bundle/I18nBundleFactory.java 2009-05-08 15:41:38 UTC (rev 1475)
@@ -0,0 +1,653 @@
+package org.codelutin.i18n.bundle;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Properties;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.i18n.I18n;
+import org.codelutin.util.ClassLoaderUtil;
+import org.codelutin.util.HashList;
+import org.codelutin.util.Resource;
+import org.codelutin.util.ResourceException;
+
+/**
+ * Classe qui est responsable de la detection et construction
+ * de {@link I18nBundle}.
+ *
+ * On retrouve aussi ici des méthodes utiles de parcours de bundles.
+ *
+ * @author chemit
+ *
+ * @since 1.0.6
+ */
+public class I18nBundleFactory {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static final Log log = LogFactory.getLog(I18nBundleFactory.class);
+ /** pattern to find all i18n bundles in classloader class path */
+ public static final String SEARCH_BUNDLE_PATTERN = ".*i18n/.+\\.properties";
+ public static final String DIRECTORY_SEARCH_BUNDLE_PATTERN = "i18n";
+ protected static String UNIQUE_BUNDLE_PATH = "/META-INF/";
+ public static String UNIQUE_BUNDLE_DEF = "%1$s-definition.properties";
+ public static String UNIQUE_BUNDLE_ENTRY = "%1$s-%2$s.properties";
+ public static String BUNDLE_DEF_LOCALES = "locales";
+
+ /**
+ * Récuperation de toutes les locales connus par un ensemble de bundles.
+ *
+ * @param bundles les bundles a parcourir
+ * @return la liste des locales rencontrées
+ */
+ public static Locale[] getLocales(I18nBundle... bundles) {
+ Set<Locale> result = new java.util.HashSet<Locale>();
+ for (I18nBundle i18nBundle : bundles) {
+ for (I18nBundleEntry entry : i18nBundle.getEntries()) {
+ Locale o = entry.getLocale();
+ if (o != null) {
+ result.add(o);
+ }
+ }
+ }
+ return result.toArray(new Locale[result.size()]);
+ }
+
+ /**
+ * Filtrage des bundles qui correspondante à la locale donnée.
+ *
+ * @param l la locale à filtrer
+ * @param bundles les bundles a parcourir
+ * @return les bundles qui correspondent à la locale donnée.
+ */
+ public static I18nBundle[] getBundles(Locale l, I18nBundle... bundles) {
+ List<I18nBundle> result = new ArrayList<I18nBundle>();
+ for (I18nBundle i18nBundle : bundles) {
+ if (i18nBundle.matchLocale(l)) {
+ result.add(i18nBundle);
+ }
+ }
+ return result.toArray(new I18nBundle[result.size()]);
+ }
+
+ /**
+ * Récupération de toutes les entrées de bundles pour les bundles données.
+ *
+ * @param bundles les bundles a parcourir
+ * @return toutes les entrées de bundles.
+ */
+ public static I18nBundleEntry[] getBundleEntries(I18nBundle... bundles) {
+ List<I18nBundleEntry> result = new ArrayList<I18nBundleEntry>();
+ for (I18nBundle i18nBundle : bundles) {
+ List<I18nBundleEntry> list = i18nBundle.getEntries();
+ if (!list.isEmpty()) {
+ result.addAll(list);
+ }
+ }
+ return result.toArray(new I18nBundleEntry[result.size()]);
+ }
+
+ /**
+ * Filtrage des entrées de bundles pour une locale donnée.
+ *
+ * On essaye de trouver les meilleurs entrées possibles (possibilité de
+ * promotion).
+ *
+ * Note: Cette méthode doit être utilisé pour trouver toutes les entrées à
+ * charger par le système i18n pour une locale donnée.
+ *
+ * @param l la locale à filtrer
+ * @param defaultLocale la locale à utiliser pour les promotions
+ * @param bundles les bundles a parcourir
+ * @return les entrées de bundles filtrés.
+ */
+ public static I18nBundleEntry[] getBundleEntries(Locale l, Locale defaultLocale, I18nBundle... bundles) {
+
+ List<I18nBundleEntry> result = new ArrayList<I18nBundleEntry>();
+ for (I18nBundle i18nBundle : bundles) {
+ I18nBundleEntry[] entries = i18nBundle.getEntries(l);
+ if (entries.length == 0) {
+ //no entry found for the bundle, try pomotion
+ entries = promuteBundle(i18nBundle, l, defaultLocale);
+ }
+ result.addAll(Arrays.asList(entries));
+ }
+ return result.toArray(new I18nBundleEntry[result.size()]);
+ }
+
+ /**
+ * Teste si un ensemble de bundles contient au moins une entrée.
+ *
+ * @param bundles les bundles a parcourir
+ * @return <code>true</code> si aucune entree trouvee, <code>false</code>
+ * autrement.
+ */
+ public static boolean isEmpty(I18nBundle... bundles) {
+ for (I18nBundle i18nBundle : bundles) {
+ if (!i18nBundle.getEntries().isEmpty()) {
+ // on a trouve au moins une entree
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Detecte les urls de toutes les entrees de bunbles sur tout un classLoader.
+ *
+ * Il s'agit du mode initialie de detection des entréés de bundles, i.e des
+ * fichiers de traductions.
+ *
+ * <b>Note: </b> Cette methode devient couteuse des que le classLoader
+ * contient de nombreuses entrées. Il est meiux d'utiliser le second type
+ * de chargement qui n'utilise qu'un seul fichier de traduction unifié.
+ *
+ * @param loader le classloader a utiliser pour trouver les resources.
+ * @return les urls des entrees de bundles
+ */
+ public static URL[] getURLs(URLClassLoader loader) {
+ try {
+ // on calcule toutes les urls utilisable dans le classloader donnee
+ List<URL> urlToSeek = new ArrayList<URL>();
+ urlToSeek.addAll(Arrays.asList(ClassLoaderUtil.getDeepURLs(loader)));
+
+ // on va maintenant supprimer toutes les urls qui ne respectent pas
+ // le pattern i18n : il faut que la resource contienne un repertoire i18n
+ // ce simple test permet de restreindre la recherche des resources
+ // i18n qui est tres couteuse
+ int size = urlToSeek.size();
+ for (Iterator<URL> it = urlToSeek.iterator(); it.hasNext();) {
+ URL url = it.next();
+ if (!Resource.containsDirectDirectory(url, DIRECTORY_SEARCH_BUNDLE_PATTERN)) {
+ if (log.isDebugEnabled()) {
+ log.debug("skip url with no " + DIRECTORY_SEARCH_BUNDLE_PATTERN + " directory : " + url);
+ }
+ it.remove();
+ }
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("detect " + urlToSeek.size() + " i18n capable url (out of " + size + ")");
+ }
+ // on effectue la recherche des urls des resources i18n (tous les
+ // fichiers de traductions) sur toutes les urls precedemment calculees)
+ List<URL> result = Resource.getURLs(SEARCH_BUNDLE_PATTERN, urlToSeek.toArray(new URL[urlToSeek.size()]));
+ if (log.isDebugEnabled()) {
+ for (URL url : result) {
+ log.debug(url.toString());
+ }
+ }
+ return result.toArray(new URL[result.size()]);
+ } catch (Exception eee) {
+ log.warn("Unable to find urls for loader : " + loader + " for reason " + eee.getMessage(), eee);
+ return new URL[0];
+ }
+ }
+
+ /**
+ * Recherche la liste des url de toutes les resources i18n, i.e les urls
+ * des fichiers de traduction.
+ *
+ * @param loader le classLoader où trouver les bundles
+ * @param extraUrl des urls de resources i18n deja calcule, à ajouter au resultat sans traitement particulier
+ * @return la liste des urls de bundle i18n pour la langue donné
+ */
+ public static URL[] getURLs(URLClassLoader loader, URL... extraUrl) {
+
+ try {
+ // on calcule toutes les urls utilisable dans le classloader donnee
+ List<URL> urlToSeek = new ArrayList<URL>();
+ urlToSeek.addAll(Arrays.asList(ClassLoaderUtil.getDeepURLs(loader)));
+ // on ajoute les urls de resources i18n donnes
+ if (extraUrl.length > 0) {
+ urlToSeek.addAll(Arrays.asList(extraUrl));
+ }
+ // on va maintenant supprimer toutes les urls qui ne respectent pas
+ // le pattern i18n : il faut que la resource contienne un repertoire i18n
+ // ce simple test permet de restreindre la recherche des resources
+ // i18n qui est tres couteuse
+ int size = urlToSeek.size();
+ for (Iterator<URL> it = urlToSeek.iterator(); it.hasNext();) {
+ URL url = it.next();
+ if (!Resource.containsDirectDirectory(url, DIRECTORY_SEARCH_BUNDLE_PATTERN)) {
+ if (log.isDebugEnabled()) {
+ log.debug("skip url with no " + DIRECTORY_SEARCH_BUNDLE_PATTERN + " directory : " + url);
+ }
+ it.remove();
+ }
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("detect " + urlToSeek.size() + " i18n capable url (out of " + size + ")");
+ }
+ // on effectue la recherche des urls des resources i18n (tous les
+ // fichiers de traductions) sur toutes les urls precedemment calculees)
+ List<URL> result = Resource.getURLs(SEARCH_BUNDLE_PATTERN, urlToSeek.toArray(new URL[urlToSeek.size()]));
+ if (log.isDebugEnabled()) {
+ for (URL url : result) {
+ log.debug(url.toString());
+ }
+ }
+ return result.toArray(new URL[result.size()]);
+ } catch (Exception eee) {
+ log.warn("Unable to find urls for loader : " + loader + " for reason " + eee.getMessage(), eee);
+ return new URL[0];
+ }
+ }
+
+ /**
+ * Recherche la liste des url de toutes les resources i18n, i.e les urls
+ * des fichiers de traduction en mode uniqueBundleName.
+ *
+ * On va d'abord rechercher un fichier /META-INF/unqiueBundleName-definition.properties
+ *
+ * Dans ce fichier il y a une entree locales qui contient les locales du bundle
+ *
+ * Ensuite pour chaque locale on recupere l'url du fichier :
+ *
+ * /META-INF/uniqueBundleName-locale.properties
+ *
+ * @param uniqueBundleName le nom de lu'inque bundle a charger
+ * @return la liste des urls de bundle i18n
+ */
+ public static URL[] getURLs(String uniqueBundleName) {
+
+ String definitionFileName = String.format(UNIQUE_BUNDLE_DEF, uniqueBundleName);
+ URL[] urls = null;
+
+ try {
+ URL defURL = I18nBundleFactory.class.getResource(UNIQUE_BUNDLE_PATH + definitionFileName);
+ log.info("definition i18n file : " + defURL);
+ InputStream stream = defURL.openStream();
+ Properties p = new Properties();
+ p.load(stream);
+ stream.close();
+
+ String localesAsStr = p.getProperty(BUNDLE_DEF_LOCALES);
+ Locale[] locales = I18n.parseLocales(localesAsStr);
+ List<URL> lUrls = new java.util.ArrayList<URL>(1);
+ String prefixURL = defURL.toString();
+ prefixURL = prefixURL.substring(0, prefixURL.length() - definitionFileName.length());
+ //FIXME on devrait tester que la resource est disponible ?
+
+ for (Locale l : locales) {
+ String url = prefixURL + String.format(UNIQUE_BUNDLE_ENTRY, uniqueBundleName, l.toString());
+ log.info("detected bundle properties file : " + url);
+ URL u = new URL(url);
+// //FIXME on devrait tester que la resource est disponible ?
+
+ lUrls.add(u);
+ }
+ if (!lUrls.isEmpty()) {
+ urls = lUrls.toArray(new URL[lUrls.size()]);
+ } else {
+ // l'unique bundle n'a pas ete trouve!
+ // on utilise la methode classique de chargement avec recherche
+ // de tous les bundles i18n
+ log.warn("not bundle files detected in " + prefixURL);
+ urls = null;
+ }
+
+ } catch (Exception ex) {
+ log.warn("could not load unique bundle " + uniqueBundleName + " for reason " + ex.getMessage(), ex);
+ urls = null;
+
+ }
+ return urls;
+ }
+
+ /**
+ * Recherche la liste des url de toutes les resources i18n, i.e les urls
+ * des fichiers de traduction.
+ *
+ * @param urls des urls de resources i18n deja calcule, à ajouter au resultat sans traitement particulier
+ * @return la liste des urls de bundle i18n
+ */
+ public static URL[] getURLs(URL... urls) {
+
+ try {
+ // on calcule toutes les urls utilisable dans le classloader donnee
+ List<URL> urlToSeek = new ArrayList<URL>();
+ urlToSeek.addAll(Arrays.asList(urls));
+
+ // on va maintenant supprimer toutes les urls qui ne respectent pas
+ // le pattern i18n : il faut que la resource contienne un repertoire i18n
+ // ce simple test permet de restreindre la recherche des resources
+ // i18n qui est tres couteuse
+ int size = urlToSeek.size();
+ for (Iterator<URL> it = urlToSeek.iterator(); it.hasNext();) {
+ URL url = it.next();
+ if (!Resource.containsDirectDirectory(url, DIRECTORY_SEARCH_BUNDLE_PATTERN)) {
+ if (log.isDebugEnabled()) {
+ log.debug("skip url with no " + DIRECTORY_SEARCH_BUNDLE_PATTERN + " directory : " + url);
+ }
+ it.remove();
+ }
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("detect " + urlToSeek.size() + " i18n capable url (out of " + size + ")");
+ }
+
+ List<URL> listURLs = new java.util.ArrayList<URL>();
+
+ for (URL url : urlToSeek) {
+ // on recherche tous les fichiers de traduction pour cet url
+
+ List<URL> result = null;
+
+ if (log.isDebugEnabled()) {
+ log.debug("seek in : " + url);
+ }
+
+ String fileName = url.getFile();
+ // TODO deal with encoding in windows, this is very durty, but it
+ // works...
+ File file = new File(fileName.replaceAll("%20", " "));
+
+ if (Resource.isJar(fileName)) {
+ // cas ou le ichier du classLoader est un fichier jar
+ if (log.isDebugEnabled()) {
+ log.debug("jar to search " + file);
+ }
+ result = getURLsFromJar(url, file);
+
+ } else if (file.isDirectory()) {
+ // cas ou le ichier du classLoader est un repertoire
+ if (log.isDebugEnabled()) {
+ log.debug("directory to search " + file);
+ }
+ // on traite le cas ou il peut y avoir des repertoire dans ce
+ // repertoire
+ result = getURLsFromDirectory(url, file);
+ }
+ if (result != null && !result.isEmpty()) {
+ listURLs.addAll(result);
+ }
+
+ }
+ return listURLs.toArray(new URL[listURLs.size()]);
+ } catch (Exception eee) {
+ log.warn("Unable to find urls for urls : " + urls + " for reason " + eee.getMessage(), eee);
+ return new URL[0];
+ }
+ }
+
+ /**
+ * Detecte les bundles i18n a partir des urls des fichiers de traduction
+ * donnes.
+ *
+ * Tous les entrées de bundles sont triees dans l'ordre des scopes i18n.
+ *
+ * @param urls les urls des fichiers de traductions
+ * @return la liste des bundle i18n construits à partir des fichiers de
+ * traduction donnes.
+ */
+ public static List<I18nBundle> detectBundles(URL... urls) {
+
+ List<String> bundleNames = new ArrayList<String>();
+ List<I18nBundle> bundles = new ArrayList<I18nBundle>();
+
+ for (URL url : urls) {
+
+ if (addBundleEntry(url, I18nBundleScope.FULL, bundleNames, bundles)) {
+ // found a full bundle
+ continue;
+ }
+ if (addBundleEntry(url, I18nBundleScope.LANGUAGE, bundleNames, bundles)) {
+ // found a language bundle
+ continue;
+ }
+ // must be a general bundle with no locale defined
+ addBundleEntry(url, I18nBundleScope.GENERAL, bundleNames, bundles);
+ }
+ bundleNames.clear();
+
+ // once for all, sort entries from general to full
+ for (I18nBundle bundle : bundles) {
+ java.util.Collections.sort(bundle.getEntries());
+ }
+
+ return bundles;
+ }
+
+ protected static boolean addBundleEntry(URL url, I18nBundleScope scope, List<String> bundleNames, List<I18nBundle> bundles) {
+ String path = url.toString();
+ Matcher matcher = scope.getMatcher(path);
+ if (!matcher.matches()) {
+ // no match at this scope
+ return false;
+ }
+ // create a new bundle entry
+ I18nBundleEntry entry = new I18nBundleEntry(url, scope.getLocale(matcher), scope);
+ if (log.isDebugEnabled()) {
+ log.debug("bundle (" + bundles.size() + ") : " + entry);
+ }
+ // get the associated bundle
+ I18nBundle bundle = addBundle(scope.getBundlePrefix(matcher), bundleNames, bundles);
+ // add entry to bundle
+ bundle.addEntry(entry);
+ return true;
+ }
+
+ protected static I18nBundle addBundle(String bundleName, List<String> bundleNames, List<I18nBundle> bundles) {
+ I18nBundle bundle;
+ int index = bundleNames.indexOf(bundleName);
+ if (index > -1) {
+ bundle = bundles.get(index);
+ } else {
+ bundle = new I18nBundle(bundleName);
+ if (log.isDebugEnabled()) {
+ log.debug("bundle (" + bundles.size() + ") : " + bundle);
+ }
+ bundles.add(bundle);
+ bundleNames.add(bundleName);
+ }
+ return bundle;
+ }
+
+ /**
+ * Obtain some rescue entries for a given locale.
+ * <p/>
+ * Note: <b>Calling this method implies there is no entry matched by the common method
+ * {@link #getBundleEntries(java.util.Locale)} return a empty array.
+ *
+ * @param bundle the bundle to promute
+ * @param l the locale required
+ * @param defaultLocale the default locale to used for promotion
+ * @return the table of entries promuted for the given locale
+ */
+ protected static I18nBundleEntry[] promuteBundle(I18nBundle bundle, Locale l, Locale defaultLocale) {
+
+ I18nBundleScope scope = I18nBundleScope.valueOf(l);
+
+ if (log.isDebugEnabled()) {
+ log.debug('[' + bundle.getBundlePrefix() + "] did not find matching entries for locale " + l + ". Try to detect best entries...");
+ }
+
+ if (bundle.size() == 0) {
+ // there is no entry to take...
+ log.warn("PROMUTE NO ENTRY FOUND");
+ return new I18nBundleEntry[0];
+ }
+
+ if (bundle.size() == 1) {
+ // there is one entry take it,what ever...
+ I18nBundleEntry entry = bundle.getEntries().get(0);
+ log.warn("PROMUTE" + l + " to " + entry.getLocale() + " [" + bundle.getBundlePrefix() + ']');
+ return new I18nBundleEntry[]{entry};
+ }
+
+ List<I18nBundleEntry> result = new ArrayList<I18nBundleEntry>();
+
+ switch (scope) {
+ case FULL:
+ promuteFull(bundle, l, defaultLocale, result);
+ break;
+ case LANGUAGE:
+ promuteLanguage(bundle, l, defaultLocale, result);
+ break;
+ case GENERAL:
+ promuteGeneral(bundle, l, defaultLocale, result);
+ break;
+ }
+ return result.toArray(new I18nBundleEntry[result.size()]);
+ }
+
+ protected static void promuteFull(I18nBundle bundle, Locale locale, Locale defaultLocale, List<I18nBundleEntry> result) {
+ if (bundle.size() == 0) {
+ return;
+ }
+ // try with a another FULL matching locale ?
+ for (I18nBundleEntry entry : bundle.getEntries()) {
+ I18nBundleScope i18nBundleScope = entry.getScope();
+ // load from general to the max scope and always if there is only one bundle entry found
+ if (i18nBundleScope == I18nBundleScope.FULL &&
+ !entry.getLocale().getCountry().equals(locale.getCountry()) &&
+ entry.getLocale().getLanguage().equals(locale.getLanguage())) {
+ log.warn(locale + " to " + entry.getLocale() + " [" + bundle.getBundlePrefix() + ']');
+ result.add(entry);
+ // we take the first one, this is a resuce!!!
+ break;
+ }
+ }
+ if (result.isEmpty()) {
+ // full promotion failed,trylanguage promotion
+ promuteLanguage(bundle, locale, defaultLocale, result);
+ }
+
+ }
+
+ protected static void promuteLanguage(I18nBundle bundle, Locale locale, Locale defaultLocale, List<I18nBundleEntry> result) {
+ if (bundle.size() == 0) {
+ return;
+ }
+ for (I18nBundleEntry entry : bundle.getEntries()) {
+ I18nBundleScope i18nBundleScope = entry.getScope();
+ // load from general to the max scope and always if there is only one bundle entry found
+ if (i18nBundleScope == I18nBundleScope.FULL && entry.getLocale().getLanguage().equals(locale.getLanguage())) {
+ result.add(entry);
+ log.warn(locale + " to " + entry.getLocale() + " [" + bundle.getBundlePrefix() + ']');
+ // we take the first one, this is a resuce!!!
+ break;
+ }
+ }
+ if (result.isEmpty()) {
+ // language promotion failed,try general promotion
+ promuteGeneral(bundle, locale, defaultLocale, result);
+ }
+ }
+
+ protected static void promuteGeneral(I18nBundle bundle, Locale locale, Locale defaultLocale, List<I18nBundleEntry> result) {
+ if (bundle.size() == 0) {
+ return;
+ }
+ if (bundle.size() == 1) {
+ // there is one entry take it,what ever...
+ I18nBundleEntry entry = bundle.getEntries().get(0);
+ result.add(entry);
+ log.warn(locale + " to " + entry.getLocale() + " [" + bundle.getBundlePrefix() + ']');
+ return;
+ }
+ I18nBundleScope scope = I18nBundleScope.valueOf(defaultLocale);
+ for (I18nBundleEntry entry : bundle.getEntries(scope)) {
+ if (entry.getLocale().equals(defaultLocale)) {
+ // default locale found
+ log.warn(locale + " to " + entry.getLocale() + " [" + bundle.getBundlePrefix() + ']');
+ result.add(entry);
+ return;
+ }
+ }
+
+ // default locale not found, take the first one ?
+ I18nBundleEntry entry = bundle.getEntries().get(0);
+ result.add(entry);
+ log.warn(locale + " to " + entry.getLocale() + " [" + bundle.getBundlePrefix() + ']');
+ //TODO Should try to load default en_GB from I18nLoader ?
+ //I18n.DEFAULT_LOCALE.getCountry()
+ }
+
+ protected static List<URL> getURLsFromJar(URL incomingURL, File jarfile) {
+
+ String pattern = SEARCH_BUNDLE_PATTERN;
+ try {
+
+ List<URL> result = new ArrayList<URL>();
+ InputStream in = new FileInputStream(jarfile);
+ ZipInputStream zis = new ZipInputStream(in);
+ ClassLoader cl = new URLClassLoader(new URL[]{incomingURL}, I18nBundleFactory.class.getClassLoader());
+ while (zis.available() != 0) {
+ ZipEntry entry = zis.getNextEntry();
+
+ if (entry == null) {
+ break;
+ }
+
+ String name = entry.getName();
+
+ if (pattern == null || name.matches(pattern)) {
+ // on recupere le fichier correspondant au pattern dans le
+ // classloader
+ if (log.isDebugEnabled()) {
+ log.debug(name + " accepted for pattern " + pattern);
+ }
+ URL url = cl.getResource(name);
+ // on ajoute le fichier correspondant au pattern dans la
+ // liste
+ result.add(url);
+ }
+ }
+
+ return result;
+ } catch (Exception eee) {
+ throw new ResourceException("n'a pas pu trouve la resource dans le jar " + jarfile.getAbsolutePath(), eee);
+ }
+ }
+
+ protected static List<URL> getURLsFromDirectory(URL incomingURL, File repository) {
+ String pattern = SEARCH_BUNDLE_PATTERN;
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("search '" + pattern + "' in " + repository);
+ }
+
+ List<URL> urlList = new HashList<URL>();
+ File[] filesList = repository.listFiles();
+
+ if (filesList != null) {
+
+ for (File file : filesList) {
+
+ String name = file.getAbsolutePath();
+
+ // cas de recursivite : repertoire dans un repertoire
+ if (file.exists() && file.isDirectory()) {
+ urlList.addAll(Resource.getURLsFromDirectory(file,
+ pattern));
+ // si le fichier du repertoire n'est pas un repertoire
+ // on verifie s'il correspond au pattern
+ } else if (pattern == null || name.matches(pattern)) {
+ URL url = file.toURI().toURL();
+ if (log.isDebugEnabled()) {
+ log.debug("directory: " + repository + " url: " + url);
+ }
+ urlList.add(url);
+ }
+ }
+ }
+ return urlList;
+ } catch (MalformedURLException eee) {
+ throw new ResourceException("n'a pas pu trouve la resource dans le repertoire " + repository.getAbsolutePath(), eee);
+ }
+ }
+}
Modified: lutinutil/trunk/src/main/java/org/codelutin/i18n/bundle/I18nBundleManager.java
===================================================================
--- lutinutil/trunk/src/main/java/org/codelutin/i18n/bundle/I18nBundleManager.java 2009-05-08 13:59:08 UTC (rev 1474)
+++ lutinutil/trunk/src/main/java/org/codelutin/i18n/bundle/I18nBundleManager.java 2009-05-08 15:41:38 UTC (rev 1475)
@@ -1,5 +1,5 @@
/*
-* *##% Lutin utilities library
+ * *##% Lutin utilities library
* Copyright (C) 2004 - 2008 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
@@ -42,23 +42,24 @@
* TODO
*
* @author chemit
+ *
+ * @deprecated since 1.0.6, on prefere utiliser une seule classe qui gere le
+ * chargement {@link I18nLoader} et une classe utilitaire qui permet de
+ * reutiliser le code {@link I18nBundleFactory}.
+ *
*/
+@Deprecated
public class I18nBundleManager {
/** to use log facility, just put in your code: log.info(\"...\"); */
private static final Log log = LogFactory.getLog(I18nBundleManager.class);
-
/** pattern to find all i18n bundles in classloader class path */
public static final String SEARCH_BUNDLE_PATTERN = ".*i18n/.+\\.properties";
-
public static final String DIRECTORY_SEARCH_BUNDLE_PATTERN = "i18n";
-
/** le cache de bundles deja charges */
protected List<I18nBundle> cache;
-
/** le cache des urls de recheche des bundles */
protected static URL[] urls;
-
protected final Locale defaultLocale;
public static void resetURL() {
@@ -82,7 +83,7 @@
// get all bundles urls
if (urls == null || urls.length == 0) {
// cache this expensive search
- urls = getURLs(Language.getLoader(), I18n.getExtraURL());
+ urls = prepareURLs();
}
long t0 = System.nanoTime();
@@ -125,6 +126,17 @@
return result.toArray(new Locale[result.size()]);
}
+ public boolean isEmpty() {
+ checkInit();
+ for (I18nBundle i18nBundle : cache) {
+ if (!i18nBundle.getEntries().isEmpty()) {
+ // on a trouve au moins une entree
+ return false;
+ }
+ }
+ return true;
+ }
+
public I18nBundle[] getBundles(Locale l) {
checkInit();
List<I18nBundle> result = new ArrayList<I18nBundle>();
@@ -229,6 +241,15 @@
}
/**
+ *
+ * @return les urls où rechercher des bundles
+ */
+ protected URL[] prepareURLs() {
+ URL[] result = getURLs(Language.getLoader(), I18n.getExtraURL());
+ return result;
+ }
+
+ /**
* Recherche la liste des url de bundles i18n correspondant à la langue
* donné.
*
@@ -239,12 +260,17 @@
protected URL[] getURLs(URLClassLoader loader, URL... extraUrl) {
try {
+ // on calcule toutes les urls utilisable dans le classloader donnee
List<URL> urlToSeek = new ArrayList<URL>();
urlToSeek.addAll(Arrays.asList(ClassLoaderUtil.getDeepURLs(loader)));
+ // on ajoute les urls de resources i18n donnes
if (extraUrl.length > 0) {
urlToSeek.addAll(Arrays.asList(extraUrl));
}
- // skip all entries with not a i18n directory to improve loading performance
+ // on va maintenant supprimer toutes les urls qui ne respectent pas
+ // le pattern i18n : il faut que la resource contienne un repertoire i18n
+ // ce simple test permet de restreindre la recherche des resources
+ // i18n qui est tres couteuse
int size = urlToSeek.size();
for (Iterator<URL> it = urlToSeek.iterator(); it.hasNext();) {
URL url = it.next();
@@ -258,19 +284,29 @@
if (log.isDebugEnabled()) {
log.debug("detect " + urlToSeek.size() + " i18n capable url (out of " + size + ")");
}
- List<URL> urls = Resource.getURLs(SEARCH_BUNDLE_PATTERN, urlToSeek.toArray(new URL[urlToSeek.size()]));
+ // on effectue la recherche des urls des resources i18n (tous les
+ // fichiers de traductions) sur toutes les urls precedemment calculees)
+ List<URL> result = Resource.getURLs(SEARCH_BUNDLE_PATTERN, urlToSeek.toArray(new URL[urlToSeek.size()]));
if (log.isDebugEnabled()) {
- for (URL url : urls) {
+ for (URL url : result) {
log.debug(url.toString());
}
}
- return urls.toArray(new URL[urls.size()]);
+ return result.toArray(new URL[result.size()]);
} catch (Exception eee) {
- log.warn("Unable to find urls for loader : " + loader);
+ log.warn("Unable to find urls for loader : " + loader + " for reason " + eee.getMessage(), eee);
return new URL[0];
}
}
+ /**
+ * Detecte les bundles i18n a partir des urls des fichiers de traduction
+ * donnes.
+ *
+ * @param urls les urls des fichiers de traductions
+ * @return la liste des bundle i18n construits à partir des fichiers de
+ * traduction donnes.
+ */
protected List<I18nBundle> detectBundles(URL... urls) {
List<String> bundleNames = new ArrayList<String>();
Modified: lutinutil/trunk/src/main/java/org/codelutin/i18n/bundle/I18nBundleScope.java
===================================================================
--- lutinutil/trunk/src/main/java/org/codelutin/i18n/bundle/I18nBundleScope.java 2009-05-08 13:59:08 UTC (rev 1474)
+++ lutinutil/trunk/src/main/java/org/codelutin/i18n/bundle/I18nBundleScope.java 2009-05-08 15:41:38 UTC (rev 1475)
@@ -53,7 +53,9 @@
public enum I18nBundleScope {
/** default scope (with no language, nor country information) */
- GENERAL("(.*18n/.+)\\.properties") {
+// GENERAL("(.*18n/.+)\\.properties") {
+ GENERAL("(.*/.+)\\.properties") {
+ @Override
public Locale getLocale(Matcher matcher) {
// no locale for general bundle
return null;
@@ -61,7 +63,9 @@
},
/** language scope (no country information) */
- LANGUAGE("(.*18n/.+)-(\\w\\w)\\.properties") {
+// LANGUAGE("(.*18n/.+)-(\\w\\w)\\.properties") {
+ LANGUAGE("(.*/.+)-(\\w\\w)\\.properties") {
+ @Override
public Locale getLocale(Matcher matcher) {
Locale result = null;
if (matcher.matches()) {
@@ -72,7 +76,9 @@
},
/** full scope : language + country */
- FULL("(.*18n/.+)-(\\w\\w_\\w\\w)\\.properties") {
+// FULL("(.*18n/.+)-(\\w\\w_\\w\\w)\\.properties") {
+ FULL("(.*/.+)-(\\w\\w_\\w\\w)\\.properties") {
+ @Override
public Locale getLocale(Matcher matcher) {
Locale result = null;
if (matcher.matches()) {
Modified: lutinutil/trunk/src/test/java/org/codelutin/i18n/I18nLoaderTest.java
===================================================================
--- lutinutil/trunk/src/test/java/org/codelutin/i18n/I18nLoaderTest.java 2009-05-08 13:59:08 UTC (rev 1474)
+++ lutinutil/trunk/src/test/java/org/codelutin/i18n/I18nLoaderTest.java 2009-05-08 15:41:38 UTC (rev 1475)
@@ -18,7 +18,6 @@
*/
package org.codelutin.i18n;
-import org.codelutin.i18n.bundle.I18nBundleManager;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Test;
@@ -38,7 +37,6 @@
Locale locale;
Language language;
I18nLoader loader;
- I18nBundleManager bundleManager;
@AfterClass
public static void afterClass() throws Exception {
@@ -51,10 +49,8 @@
Assert.assertNull(I18n.loader);
loader = I18n.getLoader();
- bundleManager = I18n.getBundleManager();
Assert.assertNotNull(loader);
//assertEquals(I18n.DEFAULT_ENCODING, loader.getEncoding());
- Assert.assertEquals(bundleManager.getDefaultLocale(), I18n.DEFAULT_LOCALE);
Assert.assertNull(loader.getLanguage());
}
@@ -117,8 +113,7 @@
protected void updateLanguage() {
language = loader == null ? null : loader.getLanguage();
loader = I18n.getLoader();
- bundleManager = I18n.getBundleManager();
- loader.setLanguage(locale, bundleManager);
+ loader.setLanguage(locale);
}
}
Modified: lutinutil/trunk/src/test/java/org/codelutin/i18n/bundle/I18nBundleManagerTest.java
===================================================================
--- lutinutil/trunk/src/test/java/org/codelutin/i18n/bundle/I18nBundleManagerTest.java 2009-05-08 13:59:08 UTC (rev 1474)
+++ lutinutil/trunk/src/test/java/org/codelutin/i18n/bundle/I18nBundleManagerTest.java 2009-05-08 15:41:38 UTC (rev 1475)
@@ -21,13 +21,11 @@
import org.apache.commons.logging.LogFactory;
import org.codelutin.i18n.I18n;
import org.junit.After;
-import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.net.MalformedURLException;
-import java.net.URL;
import java.net.URLClassLoader;
import java.util.Locale;
@@ -57,6 +55,8 @@
* @author chemit
* @version 1.0
* @since <pre>03/02/2008</pre>
+ *
+ * Redo tests for new i18n system
*/
public class I18nBundleManagerTest {
@@ -189,23 +189,23 @@
@BeforeClass
public static void befireClass() throws MalformedURLException {
- loader = (URLClassLoader) I18nBundleManagerTest.class.getClassLoader();
-
- URL[] urls = new URL[loader.getURLs().length + 2];
-
- urls[0] = new File("target" + File.separator + "test-classes" + File.separator + "i18n").toURI().toURL();
- urls[1] = new File("target" + File.separator + "classes" + File.separator + "i18n").toURI().toURL();
-
- int i = 2;
- for (URL url : loader.getURLs()) {
- urls[i++] = url;
- }
- loader = new URLClassLoader(urls, loader);
-
- log.info("use loader " + loader + " (nb urls : " + loader.getURLs().length + ")");
- for (URL url : loader.getURLs()) {
- log.info("url found in classloader : " + url);
- }
+// loader = (URLClassLoader) I18nBundleManagerTest.class.getClassLoader();
+//
+// URL[] urls = new URL[loader.getURLs().length + 2];
+//
+// urls[0] = new File("target" + File.separator + "test-classes" + File.separator + "i18n").toURI().toURL();
+// urls[1] = new File("target" + File.separator + "classes" + File.separator + "i18n").toURI().toURL();
+//
+// int i = 2;
+// for (URL url : loader.getURLs()) {
+// urls[i++] = url;
+// }
+// loader = new URLClassLoader(urls, loader);
+//
+// log.info("use loader " + loader + " (nb urls : " + loader.getURLs().length + ")");
+// for (URL url : loader.getURLs()) {
+// log.info("url found in classloader : " + url);
+// }
}
@After
@@ -215,25 +215,25 @@
@Test
public void testGetURLs() throws Exception {
- bundleManager = I18n.getBundleManager();
- Assert.assertEquals(getNbURLs(), bundleManager.getURLs(loader).length);
+// bundleManager = I18n.getBundleManager();
+// Assert.assertEquals(getNbURLs(), bundleManager.getURLs(loader).length);
}
@Test
public void testDetectBundles() throws Exception {
- bundleManager = I18n.getBundleManager();
- URL[] urls = bundleManager.getURLs(loader);
- Assert.assertEquals(BundleTest.values().length, bundleManager.detectBundles(urls).size());
+// bundleManager = I18n.getBundleManager();
+// URL[] urls = bundleManager.getURLs(loader);
+// Assert.assertEquals(BundleTest.values().length, bundleManager.detectBundles(urls).size());
}
@Test
public void testGetBundles() throws Exception {
- updateLanguage(null);
- updateLanguage(Locale.FRENCH);
- updateLanguage(Locale.ENGLISH);
- updateLanguage(Locale.FRANCE);
- updateLanguage(Locale.US);
- updateLanguage(Locale.UK);
+// updateLanguage(null);
+// updateLanguage(Locale.FRENCH);
+// updateLanguage(Locale.ENGLISH);
+// updateLanguage(Locale.FRANCE);
+// updateLanguage(Locale.US);
+// updateLanguage(Locale.UK);
}
protected int getNbURLs() {
@@ -280,10 +280,10 @@
} else if (isFr || isEn) {
nbEntries += BundleTest.getNbLanguageEntries(isFr, isEn);
}
- bundleManager = I18n.getBundleManager();
- Assert.assertEquals(nbGene + nbLang + nbFull, bundleManager.getBundles(locale).length);
- //TODO make eact match with promute logic !
- Assert.assertTrue(nbEntries <= bundleManager.getBundleEntries(locale).length);
+// bundleManager = I18n.getBundleManager();
+// Assert.assertEquals(nbGene + nbLang + nbFull, bundleManager.getBundles(locale).length);
+// //TODO make eact match with promute logic !
+// Assert.assertTrue(nbEntries <= bundleManager.getBundleEntries(locale).length);
}
}
1
0
[Lutinutil-commits] r1474 - in lutinpluginutil/trunk: . src/main/java/org/codelutin/util
by tchemit@users.labs.libre-entreprise.org 08 May '09
by tchemit@users.labs.libre-entreprise.org 08 May '09
08 May '09
Author: tchemit
Date: 2009-05-08 13:59:08 +0000 (Fri, 08 May 2009)
New Revision: 1474
Added:
lutinpluginutil/trunk/src/main/java/org/codelutin/util/DependencyUtil.java
Modified:
lutinpluginutil/trunk/changelog.txt
lutinpluginutil/trunk/pom.xml
Log:
introduce DependencyUtil class to sort artifacts in dependency order
Modified: lutinpluginutil/trunk/changelog.txt
===================================================================
--- lutinpluginutil/trunk/changelog.txt 2009-05-06 12:03:30 UTC (rev 1473)
+++ lutinpluginutil/trunk/changelog.txt 2009-05-08 13:59:08 UTC (rev 1474)
@@ -1,3 +1,6 @@
+0.5 chemit
+ * 20090508 [chemit] - introduce DependencyUtil class to sort artifacts in dependency order
+
0.4 chemit 20090420
* 20090417 [chemit] - use lutinproject 3.5.3
- use doxia-module-jrst instead on maven-jrst-plugin
Modified: lutinpluginutil/trunk/pom.xml
===================================================================
--- lutinpluginutil/trunk/pom.xml 2009-05-06 12:03:30 UTC (rev 1473)
+++ lutinpluginutil/trunk/pom.xml 2009-05-08 13:59:08 UTC (rev 1474)
@@ -33,6 +33,13 @@
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-dependency-tree</artifactId>
+ <version>1.2</version>
+ <scope>provided</scope>
+ </dependency>
+
</dependencies>
Added: lutinpluginutil/trunk/src/main/java/org/codelutin/util/DependencyUtil.java
===================================================================
--- lutinpluginutil/trunk/src/main/java/org/codelutin/util/DependencyUtil.java (rev 0)
+++ lutinpluginutil/trunk/src/main/java/org/codelutin/util/DependencyUtil.java 2009-05-08 13:59:08 UTC (rev 1474)
@@ -0,0 +1,216 @@
+package org.codelutin.util;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.shared.dependency.tree.DependencyNode;
+
+/**
+ * Une classe de methodes utiles sur les dependences entre artifacts.
+ *
+ * @author chemit
+ * @since 0.5
+ */
+public class DependencyUtil {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static final Log log = LogFactory.getLog(DependencyUtil.class);
+
+ public static void sortArtifacts(DependencyNode rootNode, List<Artifact> i18nArtifacts, boolean verbose) {
+
+ if (i18nArtifacts.size() == 1) {
+ return;
+ }
+
+ Map<String, ArtifactDependencyEntry> dico = new java.util.HashMap<String, ArtifactDependencyEntry>(i18nArtifacts.size());
+
+ for (Artifact a : i18nArtifacts) {
+ ArtifactDependencyEntry entry = new ArtifactDependencyEntry(a);
+ dico.put(entry.artifactKey, entry);
+ }
+
+ // contient les artifacts non encore fixes
+ Set<String> universe = new java.util.HashSet<String>(dico.keySet());
+
+ // recupere les noeuds pour chaque artifact en une seule passe
+
+ setNodes(rootNode, dico, universe, verbose);
+
+ // contient les artifacts resouds dans l'ordre de dependances
+ List<String> parsed = new java.util.ArrayList<String>();
+
+ // premiere passe pour recuperer l'ensemble des dependances
+ for (ArtifactDependencyEntry entry : dico.values()) {
+ List<String> dependencies = getDependencies(rootNode, entry, universe, verbose);
+ entry.depIds = dependencies;
+ }
+
+ int level = 0;
+ do {
+ if (verbose) {
+ log.info("run into level " + (level++));
+ }
+ // on parcourt les artifacts pour detecter les nouveau artifacts fixes
+ List<String> levelFixed = new java.util.ArrayList<String>();
+
+ for (String key : universe) {
+ ArtifactDependencyEntry entry = dico.get(key);
+ // cet artifact n'est pas encore fixe
+ if (entry.depIds.isEmpty()) {
+ // plus de dependance pour cet artifact
+ levelFixed.add(key);
+ if (verbose) {
+ log.info("fixed artifact " + key);
+ }
+ }
+ }
+
+ if (levelFixed.isEmpty()) {
+ // aucune modification, c'est un cycle!
+ throw new IllegalStateException("cycle detecte ! entre les artifacts " + universe);
+ }
+
+ // on met a jour les listes
+ universe.removeAll(levelFixed);
+ parsed.addAll(levelFixed);
+
+ if (universe.isEmpty()) {
+ // tout a ete resolu, plus rien a faire
+ break;
+ }
+
+ // on supprime les dependances fixees a ce niveau
+ for (String key : universe) {
+ ArtifactDependencyEntry entry = dico.get(key);
+ entry.depIds.removeAll(levelFixed);
+ }
+
+ levelFixed.clear();
+ } while (true);
+
+ i18nArtifacts.clear();
+ for (String key : parsed) {
+ i18nArtifacts.add(dico.get(key).artifact);
+ }
+
+ }
+
+ protected static String getArtifactId(Artifact artifact) {
+ return artifact.getArtifactId() + ":" + artifact.getGroupId();
+ }
+
+ protected static List<String> getDependencies(DependencyNode rootNode, ArtifactDependencyEntry entry, Set<String> universe, boolean verbose) {
+
+ List<String> order = new java.util.ArrayList<String>();
+ Set<String> exclude = new java.util.HashSet<String>();
+
+ if (verbose) {
+ log.info("start [" + entry.artifactKey + "]");
+ }
+ DependencyNode node = entry.node;
+
+ getDependencies(rootNode, node, entry.artifactKey, universe, verbose, order, exclude);
+
+ return order;
+ }
+
+ private static void getDependencies(DependencyNode rootNode, DependencyNode node, String artifactKey, Set<String> universe, boolean verbose, List<String> order, Set<String> exclude) {
+
+ for (Iterator<?> itr = node.preorderIterator(); itr.hasNext();) {
+ DependencyNode d = (DependencyNode) itr.next();
+ Artifact artifact = d.getArtifact();
+ String key = getArtifactId(artifact);
+ if (artifactKey.equals(key)) {
+ // artifact du noeud en parametre, rien a faire
+ continue;
+ }
+ if (order.contains(key) || exclude.contains(key)) {
+ // artifact deja rencontree
+ continue;
+ }
+
+ if (d.getState() != DependencyNode.INCLUDED) {
+ // on doit recuperer le noeud complete
+ if (log.isDebugEnabled()) {
+ log.debug("!!! doit recuperer le noeud complet pour " + d.getArtifact());
+ }
+ DependencyNode node1 = getNode(rootNode, key, verbose);
+ getDependencies(rootNode, node1, artifactKey, universe, verbose, order, exclude);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("[" + artifactKey + "] ??????? [" + key + "]");
+ }
+
+ if (universe.contains(key)) {
+ // artifact a retenir
+ if (verbose) {
+ log.info(" << [" + d.getArtifact() + "]");
+ }
+ order.add(key);
+ continue;
+ }
+
+ // cet artifact peut etre marque comme a ne plus etre scanne
+ exclude.add(key);
+ }
+
+ }
+
+ protected static void setNodes(DependencyNode rootNode, Map<String, ArtifactDependencyEntry> dico, Set<String> universe, boolean verbose) {
+
+ for (Iterator<?> itr = rootNode.preorderIterator(); itr.hasNext();) {
+ DependencyNode d = (DependencyNode) itr.next();
+ Artifact artifact = d.getArtifact();
+ String key = getArtifactId(artifact);
+ if (log.isDebugEnabled()) {
+ log.debug("key : " + key);
+ }
+ if (universe.contains(key) && d.getState() == DependencyNode.INCLUDED) {
+ ArtifactDependencyEntry entry = dico.get(key);
+ entry.node = d;
+ if (d == null) {
+ // ce cas ne devrait jamais arrive
+ throw new IllegalStateException("on a pas trouve le node pour l'artifact " + artifact);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("detected node : " + d);
+ }
+ }
+ }
+ }
+
+ protected static DependencyNode getNode(DependencyNode rootNode, String requiredKey, boolean verbose) {
+
+ for (Iterator<?> itr = rootNode.preorderIterator(); itr.hasNext();) {
+ DependencyNode d = (DependencyNode) itr.next();
+ Artifact artifact = d.getArtifact();
+ String key = getArtifactId(artifact);
+ if (log.isDebugEnabled()) {
+ log.debug("key : " + key);
+ }
+ if (requiredKey.equals(key) && d.getState() == DependencyNode.INCLUDED) {
+ return d;
+ }
+ }
+
+ return null;
+ }
+
+ public static class ArtifactDependencyEntry {
+
+ protected final Artifact artifact;
+ protected final String artifactKey;
+ protected DependencyNode node;
+ protected List<String> depIds;
+
+ public ArtifactDependencyEntry(Artifact artifact) {
+ this.artifact = artifact;
+ this.artifactKey = getArtifactId(artifact);
+ }
+ }
+}
1
0
[Lutinutil-commits] r1473 - in lutinutil/trunk/src: main/java/org/codelutin/util test/resources/compress/simulation
by chatellier@users.labs.libre-entreprise.org 06 May '09
by chatellier@users.labs.libre-entreprise.org 06 May '09
06 May '09
Author: chatellier
Date: 2009-05-06 12:03:30 +0000 (Wed, 06 May 2009)
New Revision: 1473
Added:
lutinutil/trunk/src/test/resources/compress/simulation/afilewithaverytoolongnamethatwillnotworkwithdefaulttararchiverbecauseitsmorethan100characters.properties
Modified:
lutinutil/trunk/src/main/java/org/codelutin/util/Tbz2Util.java
Log:
Fix error (file name is too long > 100 bytes for tar archiver)
Modified: lutinutil/trunk/src/main/java/org/codelutin/util/Tbz2Util.java
===================================================================
--- lutinutil/trunk/src/main/java/org/codelutin/util/Tbz2Util.java 2009-05-05 13:02:41 UTC (rev 1472)
+++ lutinutil/trunk/src/main/java/org/codelutin/util/Tbz2Util.java 2009-05-06 12:03:30 UTC (rev 1473)
@@ -31,9 +31,9 @@
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.compress.archivers.ArchiveInputStream;
-import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.compressors.CompressorException;
import org.apache.commons.compress.compressors.CompressorInputStream;
import org.apache.commons.compress.compressors.CompressorStreamFactory;
@@ -186,9 +186,11 @@
OutputStream cos = new CompressorStreamFactory().createCompressorOutputStream("bzip2", tbz2os);
- ArchiveOutputStream os = new ArchiveStreamFactory()
+ TarArchiveOutputStream os = (TarArchiveOutputStream)new ArchiveStreamFactory()
.createArchiveOutputStream("tar", cos);
-
+ // fix error file name 'xxx' is too long ( > 100 bytes)
+ os.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
+
for (File file : includes) {
if (file.isFile() && file.canRead()) {
String entryName = toArchiveEntryName(root, file);
Added: lutinutil/trunk/src/test/resources/compress/simulation/afilewithaverytoolongnamethatwillnotworkwithdefaulttararchiverbecauseitsmorethan100characters.properties
===================================================================
--- lutinutil/trunk/src/test/resources/compress/simulation/afilewithaverytoolongnamethatwillnotworkwithdefaulttararchiverbecauseitsmorethan100characters.properties (rev 0)
+++ lutinutil/trunk/src/test/resources/compress/simulation/afilewithaverytoolongnamethatwillnotworkwithdefaulttararchiverbecauseitsmorethan100characters.properties 2009-05-06 12:03:30 UTC (rev 1473)
@@ -0,0 +1,2 @@
+# Ce fichier a un nom trop long pour l'archivage
+# par defaut de tar
\ No newline at end of file
1
0
[Lutinutil-commits] r1472 - lutinutil/trunk/src/main/java/org/codelutin/util
by chatellier@users.labs.libre-entreprise.org 05 May '09
by chatellier@users.labs.libre-entreprise.org 05 May '09
05 May '09
Author: chatellier
Date: 2009-05-05 13:02:41 +0000 (Tue, 05 May 2009)
New Revision: 1472
Modified:
lutinutil/trunk/src/main/java/org/codelutin/util/ArgumentsParserException.java
Log:
Oups, this class is not deprecated.
Modified: lutinutil/trunk/src/main/java/org/codelutin/util/ArgumentsParserException.java
===================================================================
--- lutinutil/trunk/src/main/java/org/codelutin/util/ArgumentsParserException.java 2009-05-04 17:57:14 UTC (rev 1471)
+++ lutinutil/trunk/src/main/java/org/codelutin/util/ArgumentsParserException.java 2009-05-05 13:02:41 UTC (rev 1472)
@@ -13,29 +13,23 @@
*
* 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>. ##%* /
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+package org.codelutin.util;
+
/**
- * ArgumentsParserException.java
- *
- * Created: 23 août 2003
- *
+ * Argument parsing exception
+ *
* @author Benjamin Poussin <poussin(a)codelutin.com>
* Copyright Code Lutin
* @version $Revision$
- *
+ *
* Mise a jour: $Date$
* par : $Author$
*/
-
-package org.codelutin.util;
-
-/**
- * @deprecated since 0.30 , prefer use of {@link ApplicationConfig} instead
- */
public class ArgumentsParserException extends Exception { // ArgumentsParserException
- /** */
+ /** serialVersionUID. */
private static final long serialVersionUID = 8265924907001359910L;
public ArgumentsParserException(String msg) {
1
0
[Lutinutil-commits] r1471 - lutinutil/trunk
by chatellier@users.labs.libre-entreprise.org 04 May '09
by chatellier@users.labs.libre-entreprise.org 04 May '09
04 May '09
Author: chatellier
Date: 2009-05-04 17:57:14 +0000 (Mon, 04 May 2009)
New Revision: 1471
Modified:
lutinutil/trunk/pom.xml
Log:
Fix scm values
Modified: lutinutil/trunk/pom.xml
===================================================================
--- lutinutil/trunk/pom.xml 2009-05-04 17:46:24 UTC (rev 1470)
+++ lutinutil/trunk/pom.xml 2009-05-04 17:57:14 UTC (rev 1471)
@@ -164,9 +164,9 @@
<!--Source control management-->
<scm>
- <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinutil/lutinutil/trunk</connection>
- <developerConnection>scm:svn:svn+ssh://chatellier@labs.libre-entreprise.org/svnroot/lutinutil/lutinutil/trunk</developerConnection>
- <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/lutinutil/trunk…</url>
+ <connection>${maven.scm.connection}</connection>
+ <developerConnection>${maven.scm.developerConnection}</developerConnection>
+ <url>${maven.scm.url}</url>
</scm>
<!--Code Lutin Repository-->
1
0
[Lutinutil-commits] r1470 - lutinutil/trunk
by chatellier@users.labs.libre-entreprise.org 04 May '09
by chatellier@users.labs.libre-entreprise.org 04 May '09
04 May '09
Author: chatellier
Date: 2009-05-04 17:46:24 +0000 (Mon, 04 May 2009)
New Revision: 1470
Modified:
lutinutil/trunk/pom.xml
Log:
[maven-release-plugin] prepare for next development iteration
Modified: lutinutil/trunk/pom.xml
===================================================================
--- lutinutil/trunk/pom.xml 2009-05-04 17:46:21 UTC (rev 1469)
+++ lutinutil/trunk/pom.xml 2009-05-04 17:46:24 UTC (rev 1470)
@@ -15,7 +15,7 @@
<artifactId>lutinutil</artifactId>
- <version>1.0.5</version>
+ <version>1.0.6-SNAPSHOT</version>
<dependencies>
@@ -164,9 +164,9 @@
<!--Source control management-->
<scm>
- <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinutil/lutinutil/tags/lutinutil-1.0.5</connection>
- <developerConnection>scm:svn:svn+ssh://chatellier@labs.libre-entreprise.org/svnroot/lutinutil/lutinutil/tags/lutinutil-1.0.5</developerConnection>
- <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/lutinutil/tags/…</url>
+ <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinutil/lutinutil/trunk</connection>
+ <developerConnection>scm:svn:svn+ssh://chatellier@labs.libre-entreprise.org/svnroot/lutinutil/lutinutil/trunk</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/lutinutil/trunk…</url>
</scm>
<!--Code Lutin Repository-->
1
0
[Lutinutil-commits] r1469 - in lutinutil/tags: . lutinutil-1.0.5
by chatellier@users.labs.libre-entreprise.org 04 May '09
by chatellier@users.labs.libre-entreprise.org 04 May '09
04 May '09
Author: chatellier
Date: 2009-05-04 17:46:21 +0000 (Mon, 04 May 2009)
New Revision: 1469
Added:
lutinutil/tags/lutinutil-1.0.5/
lutinutil/tags/lutinutil-1.0.5/pom.xml
Removed:
lutinutil/tags/lutinutil-1.0.5/pom.xml
Log:
[maven-release-plugin] copy for tag lutinutil-1.0.5
Copied: lutinutil/tags/lutinutil-1.0.5 (from rev 1467, lutinutil/trunk)
Deleted: lutinutil/tags/lutinutil-1.0.5/pom.xml
===================================================================
--- lutinutil/trunk/pom.xml 2009-05-04 17:44:04 UTC (rev 1467)
+++ lutinutil/tags/lutinutil-1.0.5/pom.xml 2009-05-04 17:46:21 UTC (rev 1469)
@@ -1,234 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
-
- <!-- ************************************************************* -->
- <!-- *** POM Relationships *************************************** -->
- <!-- ************************************************************* -->
-
- <parent>
- <groupId>org.codelutin</groupId>
- <artifactId>lutinproject</artifactId>
- <version>3.5</version>
- </parent>
-
- <artifactId>lutinutil</artifactId>
-
- <version>1.0.5-SNAPSHOT</version>
-
- <dependencies>
-
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.14</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>commons-primitives</groupId>
- <artifactId>commons-primitives</artifactId>
- <version>1.0</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>commons-collections</groupId>
- <artifactId>commons-collections</artifactId>
- <version>3.2.1</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>commons-beanutils</groupId>
- <artifactId>commons-beanutils</artifactId>
- <version>1.8.0</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-compress</artifactId>
- <version>20090504</version>
- <scope>compile</scope>
- </dependency>
-
- </dependencies>
-
-
- <!-- ************************************************************* -->
- <!-- *** Project Information ************************************* -->
- <!-- ************************************************************* -->
-
- <name>Lutin utilities library</name>
- <description>Library of usefull class to be used in any project.</description>
- <inceptionYear>2004</inceptionYear>
-
- <!-- ************************************************************* -->
- <!-- *** Build Settings ****************************************** -->
- <!-- ************************************************************* -->
-
- <packaging>jar</packaging>
-
- <properties>
-
- <labs.id>12</labs.id>
-
- <labs.project>lutinutil</labs.project>
-
- <i18n.version>0.9</i18n.version>
- </properties>
-
- <build>
-
- <defaultGoal>install</defaultGoal>
-
- <plugins>
-
- <!-- plugin i18n -->
- <plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-i18n-plugin</artifactId>
- <version>${i18n.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>parserJava</goal>
- <goal>gen</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
-
- <!-- Always process jrst files, but only called on pre-site phase -->
- <plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-jrst-plugin</artifactId>
- <version>0.8.4</version>
- <configuration>
- <defaultLocale>fr</defaultLocale>
- </configuration>
- <executions>
- <execution>
- <goals>
- <goal>jrst</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
-
- <pluginManagement>
- <plugins>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <configuration>
- <descriptors>
- <descriptor>src/main/assembly/deps.xml</descriptor>
- <descriptor>src/main/assembly/full.xml</descriptor>
- </descriptors>
- <attach>false</attach>
- </configuration>
- <executions>
- <execution>
- <id>create-assembly</id>
- <goals>
- <goal>single</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
-
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <version>2.5</version>
- <configuration>
- <links>
- <link>http://java.sun.com/javase/6/docs/api/</link>
- </links>
- </configuration>
- </plugin>
- </plugins>
- </reporting>
-
- <!-- ************************************************************* -->
- <!-- *** Build Environment ************************************** -->
- <!-- ************************************************************* -->
-
- <!--Source control management-->
- <scm>
- <connection>${maven.scm.connection}</connection>
- <developerConnection>${maven.scm.developerConnection}</developerConnection>
- <url>${maven.scm.url}</url>
- </scm>
-
- <!--Code Lutin Repository-->
- <repositories>
- <repository>
- <id>codelutin-repository</id>
- <name>CodeLutinRepository</name>
- <url>http://lutinbuilder.labs.libre-entreprise.org/maven2</url>
- <snapshots>
- <enabled>true</enabled>
- <checksumPolicy>warn</checksumPolicy>
- </snapshots>
- <releases>
- <enabled>true</enabled>
- <checksumPolicy>warn</checksumPolicy>
- </releases>
- </repository>
- </repositories>
-
- <profiles>
- <profile>
- <id>release-profile</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
- <build>
- <plugins>
-
- <!-- launch in a release the assembly automaticly -->
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <executions>
- <execution>
- <id>create-assembly</id>
- <phase>package</phase>
- </execution>
- </executions>
- </plugin>
-
- <!-- always add license and third-party files to classpath -->
- <plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-license-switcher-plugin</artifactId>
- <version>0.6</version>
- <executions>
- <execution>
- <id>attach-licenses</id>
- <goals>
- <goal>license</goal>
- <goal>third-party</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
-
- </plugins>
-
- </build>
- </profile>
- </profiles>
-
-</project>
Copied: lutinutil/tags/lutinutil-1.0.5/pom.xml (from rev 1468, lutinutil/trunk/pom.xml)
===================================================================
--- lutinutil/tags/lutinutil-1.0.5/pom.xml (rev 0)
+++ lutinutil/tags/lutinutil-1.0.5/pom.xml 2009-05-04 17:46:21 UTC (rev 1469)
@@ -0,0 +1,234 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- ************************************************************* -->
+ <!-- *** POM Relationships *************************************** -->
+ <!-- ************************************************************* -->
+
+ <parent>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutinproject</artifactId>
+ <version>3.5</version>
+ </parent>
+
+ <artifactId>lutinutil</artifactId>
+
+ <version>1.0.5</version>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.14</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-primitives</groupId>
+ <artifactId>commons-primitives</artifactId>
+ <version>1.0</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2.1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <version>1.8.0</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-compress</artifactId>
+ <version>20090504</version>
+ <scope>compile</scope>
+ </dependency>
+
+ </dependencies>
+
+
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
+
+ <name>Lutin utilities library</name>
+ <description>Library of usefull class to be used in any project.</description>
+ <inceptionYear>2004</inceptionYear>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
+
+ <packaging>jar</packaging>
+
+ <properties>
+
+ <labs.id>12</labs.id>
+
+ <labs.project>lutinutil</labs.project>
+
+ <i18n.version>0.9</i18n.version>
+ </properties>
+
+ <build>
+
+ <defaultGoal>install</defaultGoal>
+
+ <plugins>
+
+ <!-- plugin i18n -->
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-i18n-plugin</artifactId>
+ <version>${i18n.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>parserJava</goal>
+ <goal>gen</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- Always process jrst files, but only called on pre-site phase -->
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-jrst-plugin</artifactId>
+ <version>0.8.4</version>
+ <configuration>
+ <defaultLocale>fr</defaultLocale>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>jrst</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptors>
+ <descriptor>src/main/assembly/deps.xml</descriptor>
+ <descriptor>src/main/assembly/full.xml</descriptor>
+ </descriptors>
+ <attach>false</attach>
+ </configuration>
+ <executions>
+ <execution>
+ <id>create-assembly</id>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.5</version>
+ <configuration>
+ <links>
+ <link>http://java.sun.com/javase/6/docs/api/</link>
+ </links>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Environment ************************************** -->
+ <!-- ************************************************************* -->
+
+ <!--Source control management-->
+ <scm>
+ <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinutil/lutinutil/tags/lutinutil-1.0.5</connection>
+ <developerConnection>scm:svn:svn+ssh://chatellier@labs.libre-entreprise.org/svnroot/lutinutil/lutinutil/tags/lutinutil-1.0.5</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/lutinutil/tags/…</url>
+ </scm>
+
+ <!--Code Lutin Repository-->
+ <repositories>
+ <repository>
+ <id>codelutin-repository</id>
+ <name>CodeLutinRepository</name>
+ <url>http://lutinbuilder.labs.libre-entreprise.org/maven2</url>
+ <snapshots>
+ <enabled>true</enabled>
+ <checksumPolicy>warn</checksumPolicy>
+ </snapshots>
+ <releases>
+ <enabled>true</enabled>
+ <checksumPolicy>warn</checksumPolicy>
+ </releases>
+ </repository>
+ </repositories>
+
+ <profiles>
+ <profile>
+ <id>release-profile</id>
+ <activation>
+ <property>
+ <name>performRelease</name>
+ <value>true</value>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+
+ <!-- launch in a release the assembly automaticly -->
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>create-assembly</id>
+ <phase>package</phase>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- always add license and third-party files to classpath -->
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-license-switcher-plugin</artifactId>
+ <version>0.6</version>
+ <executions>
+ <execution>
+ <id>attach-licenses</id>
+ <goals>
+ <goal>license</goal>
+ <goal>third-party</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+
+ </build>
+ </profile>
+ </profiles>
+
+</project>
1
0
[Lutinutil-commits] r1468 - lutinutil/trunk
by chatellier@users.labs.libre-entreprise.org 04 May '09
by chatellier@users.labs.libre-entreprise.org 04 May '09
04 May '09
Author: chatellier
Date: 2009-05-04 17:46:17 +0000 (Mon, 04 May 2009)
New Revision: 1468
Modified:
lutinutil/trunk/pom.xml
Log:
[maven-release-plugin] prepare release lutinutil-1.0.5
Modified: lutinutil/trunk/pom.xml
===================================================================
--- lutinutil/trunk/pom.xml 2009-05-04 17:44:04 UTC (rev 1467)
+++ lutinutil/trunk/pom.xml 2009-05-04 17:46:17 UTC (rev 1468)
@@ -15,7 +15,7 @@
<artifactId>lutinutil</artifactId>
- <version>1.0.5-SNAPSHOT</version>
+ <version>1.0.5</version>
<dependencies>
@@ -164,9 +164,9 @@
<!--Source control management-->
<scm>
- <connection>${maven.scm.connection}</connection>
- <developerConnection>${maven.scm.developerConnection}</developerConnection>
- <url>${maven.scm.url}</url>
+ <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinutil/lutinutil/tags/lutinutil-1.0.5</connection>
+ <developerConnection>scm:svn:svn+ssh://chatellier@labs.libre-entreprise.org/svnroot/lutinutil/lutinutil/tags/lutinutil-1.0.5</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/lutinutil/tags/…</url>
</scm>
<!--Code Lutin Repository-->
1
0