You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2019/06/17 17:05:43 UTC

[logging-log4j2] branch master updated (3cfcbd2 -> e1cc626)

This is an automated email from the ASF dual-hosted git repository.

rgoers pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git.


    from 3cfcbd2  Merge pull request #279 from carterkozak/ckozak/LOG4J2-2629
     new c63c66c  LOG4J2-1852 - Locate plugins inside a Jar using a URLConnection
     new e1cc626  LOG4J2-1852 - Locate plugins inside a Jar using a URLConnection

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../logging/log4j/plugins/util/ResolverUtil.java   | 40 ++++++++++++++++++++++
 src/changes/changes.xml                            |  9 +++--
 2 files changed, 44 insertions(+), 5 deletions(-)


[logging-log4j2] 01/02: LOG4J2-1852 - Locate plugins inside a Jar using a URLConnection

Posted by rg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rgoers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit c63c66c2730f181d8151235731f819481085a871
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Sun Jun 16 21:45:21 2019 -0700

    LOG4J2-1852 - Locate plugins inside a Jar using a URLConnection
---
 .../logging/log4j/plugins/util/ResolverUtil.java   | 40 ++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/ResolverUtil.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/ResolverUtil.java
index a57356c..d6b4085 100644
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/ResolverUtil.java
+++ b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/ResolverUtil.java
@@ -23,6 +23,7 @@ import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.wiring.BundleWiring;
 
 import java.io.*;
+import java.net.JarURLConnection;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -30,6 +31,7 @@ import java.net.URLDecoder;
 import java.nio.charset.StandardCharsets;
 import java.util.*;
 import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
 import java.util.jar.JarInputStream;
 
 /**
@@ -77,6 +79,8 @@ public class ResolverUtil {
 
     private static final String VFS = "vfs";
 
+    private static final String JAR = "jar";
+
     private static final String BUNDLE_RESOURCE = "bundleresource";
 
     /** The set of matches being accumulated. */
@@ -216,6 +220,8 @@ public class ResolverUtil {
                     }
                 } else if (BUNDLE_RESOURCE.equals(url.getProtocol())) {
                     loadImplementationsInBundle(test, packageName);
+                } else if (JAR.equals(url.getProtocol())) {
+                    loadImplementationsInJar(test, packageName, url);
                 } else {
                     final File file = new File(urlPath);
                     if (file.isDirectory()) {
@@ -357,6 +363,40 @@ public class ResolverUtil {
      *        a Test used to filter the classes that are discovered
      * @param parent
      *        the parent package under which classes must be in order to be considered
+     * @param url
+     *        the url that identifies the jar containing the resource.
+     */
+    private void loadImplementationsInJar(final Test test, final String parent, final URL url) {
+        JarURLConnection connection = null;
+        try {
+            connection = (JarURLConnection) url.openConnection();
+            if (connection != null) {
+                JarFile jarFile = connection.getJarFile();
+                Enumeration<JarEntry> entries = jarFile.entries();
+                while (entries.hasMoreElements()) {
+                    JarEntry entry = entries.nextElement();
+                    final String name = entry.getName();
+                    if (!entry.isDirectory() && name.startsWith(parent) && isTestApplicable(test, name)) {
+                        addIfMatching(test, name);
+                    }
+                }
+            } else {
+                LOGGER.error("Could not establish connection to {}", url.toString());
+            }
+        } catch (final IOException ex) {
+            LOGGER.error("Could not search JAR file '{}' for classes matching criteria {}, file not found",
+                    url.toString(), test, ex);
+        }
+    }
+
+    /**
+     * Finds matching classes within a jar files that contains a folder structure matching the package structure. If the
+     * File is not a JarFile or does not exist a warning will be logged, but no error will be raised.
+     *
+     * @param test
+     *        a Test used to filter the classes that are discovered
+     * @param parent
+     *        the parent package under which classes must be in order to be considered
      * @param stream
      *        The jar InputStream
      */


[logging-log4j2] 02/02: LOG4J2-1852 - Locate plugins inside a Jar using a URLConnection

Posted by rg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rgoers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit e1cc626e78cd0518946b5033d9ad44ac7ecad440
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Mon Jun 17 10:05:29 2019 -0700

    LOG4J2-1852 - Locate plugins inside a Jar using a URLConnection
---
 src/changes/changes.xml | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index dd0e8d2..4d5b1b5 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -73,11 +73,7 @@
       </action>
       <action issue="LOG4J2-2232" dev="ggregory" type="update">
         Move JMS code to a new module log4j-jms.
-      </acti
-
-
-
-
+      </action>
       <action issue="LOG4J2-2233" dev="ggregory" type="update">
         Move JDBC code to a new module log4j-jdbc.
       </action>
@@ -146,6 +142,9 @@
       </action>
     </release>
     <release version="2.12.0" date="2019-MM-DD" description="GA Release 2.12.0">
+      <action issue="LOG4J2-1852" dev="rgoers" type="fix" due-to="Tanner Altares">
+        Locate plugins within a Jar using a URL Connection.
+      </action>
       <action issue="LOG4J2-2610" dev="rgoers" type="fix">
         Explicitly set file creation time.
       </action>