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>.