branch develop updated (1a898f0 -> 4252f47)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository i18n. See https://gitlab.nuiton.org/nuiton/i18n.git from 1a898f0 Upgrade jacoco plugin to 0.8.6 in order to build with Java 15+ new 43660c7 ClassPathI18nInitializer nécessite un URLClassLoader new b242da4 Scinde la méthode I18nBundleUtil#getURLs(URL[]) en 2 pour éviter l'usage inutile du tableau new 4252f47 Ignore certains tests qui ne peuvent fonctionner en l'état The 3 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 4252f47f724798d0dcc73a06d0439e02fdfc4dc5 Author: Arnaud Thimel <thimel@codelutin.com> Date: Wed Mar 24 10:49:37 2021 +0100 Ignore certains tests qui ne peuvent fonctionner en l'état commit b242da40d790ca6c8b98bccd03ad97104a8492bf Author: Arnaud Thimel <thimel@codelutin.com> Date: Wed Mar 24 10:15:50 2021 +0100 Scinde la méthode I18nBundleUtil#getURLs(URL[]) en 2 pour éviter l'usage inutile du tableau commit 43660c73a504fa2b1883a05f2b48d316adf0970b Author: Arnaud Thimel <thimel@codelutin.com> Date: Wed Mar 24 09:19:06 2021 +0100 ClassPathI18nInitializer nécessite un URLClassLoader Summary of changes: .../src/main/java/org/nuiton/i18n/I18nUtil.java | 61 ---------------------- .../org/nuiton/i18n/bundle/I18nBundleUtil.java | 21 ++++++-- .../nuiton/i18n/init/ClassPathI18nInitializer.java | 15 ++++-- .../src/test/java/org/nuiton/i18n/I18nTest.java | 9 ++++ 4 files changed, 37 insertions(+), 69 deletions(-) -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository i18n. See https://gitlab.nuiton.org/nuiton/i18n.git commit 43660c73a504fa2b1883a05f2b48d316adf0970b Author: Arnaud Thimel <thimel@codelutin.com> Date: Wed Mar 24 09:19:06 2021 +0100 ClassPathI18nInitializer nécessite un URLClassLoader --- .../src/main/java/org/nuiton/i18n/I18nUtil.java | 61 ---------------------- .../nuiton/i18n/init/ClassPathI18nInitializer.java | 12 ++++- 2 files changed, 10 insertions(+), 63 deletions(-) diff --git a/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nUtil.java b/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nUtil.java index d9883b3..bc7fd3d 100644 --- a/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nUtil.java +++ b/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nUtil.java @@ -272,67 +272,6 @@ public class I18nUtil { } } - /** - * Returns the all URLs to be used in a {@link ClassLoader}. - * - * If the given classloader is an URLClassLoader, will do the same as {@link #getDeepURLs(URLClassLoader)}. - * Otherwise this method will try to find URLs by another way. - * - * @param loader the classloader (if null will use system one) - * @return all the url found in the classloader if applicable - * @see #getDeepURLs(URLClassLoader) - */ - public static Optional<URL[]> tryGetDeepURLs(ClassLoader loader) { - - if (loader instanceof URLClassLoader) { - URLClassLoader urlClassLoader = (URLClassLoader) loader; - URL[] result = getDeepURLs(urlClassLoader); - return Optional.of(result); - } else { - try { - - List<URL> classpathUris = new ArrayList<>(); - - Enumeration<URL> urls = ClassLoader.getSystemResources(""); - while (urls.hasMoreElements()) { - try (Stream<Path> walk = Files.walk(Paths.get(urls.nextElement().toURI()))) { - - walk.filter(Files::isRegularFile) - .map(Path::toUri) - .map(I18nUtil::safeUriToUrlOrNull) - .filter(Objects::nonNull) - .forEach(classpathUris::add); - - } catch (IOException | URISyntaxException | FileSystemNotFoundException e) { - if (log.isWarnEnabled()) { - log.warn("An error occurred while walking through classpath, it may not work as expected", e); - } - } - } - - URL[] result = classpathUris.toArray(new URL[0]); - return Optional.of(result); - } catch (IOException e) { - if (log.isWarnEnabled()) { - log.warn("An error occured while walking through classpath, it may not work as expected",e); - } - return Optional.empty(); - } - - } - } - - private static URL safeUriToUrlOrNull(URI uri) { - try { - return uri.toURL(); - } catch (MalformedURLException e) { - if (log.isWarnEnabled()) { - log.warn("An error occured while walking through classpath, it may not work as expected",e); - } - return null; - } - } - /** * Returns the all urls to be used in a {@link URLClassLoader}. * diff --git a/nuiton-i18n/src/main/java/org/nuiton/i18n/init/ClassPathI18nInitializer.java b/nuiton-i18n/src/main/java/org/nuiton/i18n/init/ClassPathI18nInitializer.java index f2768e8..459ceb2 100644 --- a/nuiton-i18n/src/main/java/org/nuiton/i18n/init/ClassPathI18nInitializer.java +++ b/nuiton-i18n/src/main/java/org/nuiton/i18n/init/ClassPathI18nInitializer.java @@ -32,6 +32,7 @@ import org.nuiton.i18n.bundle.I18nBundle; import org.nuiton.i18n.bundle.I18nBundleUtil; import java.net.URL; +import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -44,6 +45,8 @@ import java.util.List; * * Will scan all classpath. * + * This class requires an URLClassLoader, otherwise an exception will be thrown. + * * <b>Note:</b> No order can be predicted with this implementation on bundles. * * @author Tony Chemit - chemit@codelutin.com @@ -74,9 +77,13 @@ public class ClassPathI18nInitializer extends I18nInitializer { } public URL[] resolvURLs() throws Exception { + // on calcule toutes les urls utilisable dans le classloader donnee - ClassLoader classLoader = getLoader(); - URL[] deepURLs = I18nUtil.tryGetDeepURLs(classLoader).orElse(new URL[0]); + if (!(loader instanceof URLClassLoader)) { + throw new IllegalStateException("This instance of I18nInitializer is only compatible with URLClassLoader"); + } + URLClassLoader urlClassLoader = (URLClassLoader) loader; + URL[] deepURLs = I18nUtil.getDeepURLs(urlClassLoader); List<URL> urlToSeek = new ArrayList<>(Arrays.asList(deepURLs)); // on va maintenant supprimer toutes les urls qui ne respectent pas @@ -100,6 +107,7 @@ public class ClassPathI18nInitializer extends I18nInitializer { 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) URL[] url1 = urlToSeek.toArray(new URL[urlToSeek.size()]); -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository i18n. See https://gitlab.nuiton.org/nuiton/i18n.git commit b242da40d790ca6c8b98bccd03ad97104a8492bf Author: Arnaud Thimel <thimel@codelutin.com> Date: Wed Mar 24 10:15:50 2021 +0100 Scinde la méthode I18nBundleUtil#getURLs(URL[]) en 2 pour éviter l'usage inutile du tableau --- .../java/org/nuiton/i18n/bundle/I18nBundleUtil.java | 21 +++++++++++++++++---- .../nuiton/i18n/init/ClassPathI18nInitializer.java | 3 +-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleUtil.java b/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleUtil.java index 46466ee..825f26f 100644 --- a/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleUtil.java +++ b/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleUtil.java @@ -36,6 +36,7 @@ import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; @@ -199,11 +200,11 @@ public class I18nBundleUtil { * @param urls les urls à inspecter pour trouver des resources i18n * @return la liste des urls de bundle i18n */ - public static URL[] getURLs(URL... urls) { + public static URL[] getURLs(Collection<URL> urls) { try { // on calcule toutes les urls utilisable dans le classloader donnee - List<URL> urlToSeek = new ArrayList<>(Arrays.asList(urls)); + List<URL> urlToSeek = new ArrayList<>(urls); // on va maintenant supprimer toutes les urls qui ne respectent pas // le pattern i18n : il faut que la resource contienne un @@ -229,7 +230,7 @@ public class I18nBundleUtil { " i18n capable url (out of " + size + ")"); } - List<URL> listURLs = new ArrayList<URL>(); + List<URL> listURLs = new ArrayList<>(); for (URL url : urlToSeek) { // on recherche tous les fichiers de traduction pour cet url @@ -272,13 +273,25 @@ public class I18nBundleUtil { return listURLs.toArray(new URL[listURLs.size()]); } catch (Exception eee) { if (log.isWarnEnabled()) { - log.warn("Unable to find urls for urls : " + Arrays.toString(urls) + + log.warn("Unable to find urls for urls : " + urls + " for reason " + eee.getMessage(), eee); } return EMPTY_URL_ARRAY; } } + /** + * Recherche la liste des url de toutes les resources i18n, i.e les urls des + * fichiers de traduction. + * + * @param url l'URL à inspecter pour trouver des resources i18n + * @return la liste des urls de bundle i18n + */ + public static URL[] getURLs(URL url) { + URL[] result = getURLs(Collections.singleton(url)); + return result; + } + /** * Teste si un ensemble de bundles contient au moins une entrée. * diff --git a/nuiton-i18n/src/main/java/org/nuiton/i18n/init/ClassPathI18nInitializer.java b/nuiton-i18n/src/main/java/org/nuiton/i18n/init/ClassPathI18nInitializer.java index 459ceb2..4b6bcde 100644 --- a/nuiton-i18n/src/main/java/org/nuiton/i18n/init/ClassPathI18nInitializer.java +++ b/nuiton-i18n/src/main/java/org/nuiton/i18n/init/ClassPathI18nInitializer.java @@ -110,8 +110,7 @@ public class ClassPathI18nInitializer extends I18nInitializer { // on effectue la recherche des urls des resources i18n (tous les // fichiers de traductions) sur toutes les urls precedemment calculees) - URL[] url1 = urlToSeek.toArray(new URL[urlToSeek.size()]); - URL[] result = I18nBundleUtil.getURLs(url1); + URL[] result = I18nBundleUtil.getURLs(urlToSeek); if (log.isDebugEnabled()) { for (URL url : result) { log.debug(url.toString()); -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository i18n. See https://gitlab.nuiton.org/nuiton/i18n.git commit 4252f47f724798d0dcc73a06d0439e02fdfc4dc5 Author: Arnaud Thimel <thimel@codelutin.com> Date: Wed Mar 24 10:49:37 2021 +0100 Ignore certains tests qui ne peuvent fonctionner en l'état --- nuiton-i18n/src/test/java/org/nuiton/i18n/I18nTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nTest.java b/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nTest.java index 7afafe6..724a926 100644 --- a/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nTest.java +++ b/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nTest.java @@ -26,11 +26,13 @@ package org.nuiton.i18n; import org.junit.After; import org.junit.Assert; +import org.junit.Assume; import org.junit.Before; import org.junit.Test; import org.nuiton.i18n.format.MessageFormatI18nMessageFormatter; import org.nuiton.i18n.init.DefaultI18nInitializer; +import java.net.URLClassLoader; import java.util.Arrays; import java.util.Date; import java.util.GregorianCalendar; @@ -63,6 +65,8 @@ public class I18nTest { @Test public void testWithNoInit() { + // Ce test ne peut pas fonctionner avec un ClassPathI18nInitializer si on a pas d'URLClassLoader + Assume.assumeTrue(getClass().getClassLoader() instanceof URLClassLoader); String expected; String actual; @@ -78,6 +82,8 @@ public class I18nTest { @Test public void testWithNoInit2() { + // Ce test ne peut pas fonctionner avec un ClassPathI18nInitializer si on a pas d'URLClassLoader + Assume.assumeTrue(getClass().getClassLoader() instanceof URLClassLoader); String expected; String actual; @@ -97,6 +103,9 @@ public class I18nTest { @Test public void testDefaultInit() { + // Ce test ne peut pas fonctionner avec un ClassPathI18nInitializer si on a pas d'URLClassLoader + Assume.assumeTrue(getClass().getClassLoader() instanceof URLClassLoader); + Assert.assertNull(I18n.store); I18n.init(null, (Locale) null); -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm