From cd304eb65b28bce8583cf3b71ed1e73dca6d4916 Mon Sep 17 00:00:00 2001 From: Tushar I Date: Tue, 5 Feb 2019 22:56:54 -0800 Subject: [PATCH] Issue #150: Ability to handle JAR directories in extraClasspath. (#3325) * Issue #150: Ability to handle JAR directories in extraClasspath. In keeping with Java conventions[0], any directory paths ending in /* should be considered a JAR directory and all jars in that directory will be added (non recursively) to the classpath. [0] https://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html Signed-off-by: Tushar Inamdar --- .../eclipse/jetty/webapp/WebAppClassLoader.java | 14 +++++++++++--- .../jetty/webapp/WebAppClassLoaderTest.java | 9 +++++++++ .../src/test/resources/ext/org-acme-ext-one.jar | Bin 0 -> 2605 bytes .../src/test/resources/ext/org-acme-ext-two.jar | Bin 0 -> 2491 bytes .../resources/ext/sub/org-acme-ext-three.jar | Bin 0 -> 2519 bytes 5 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 jetty-webapp/src/test/resources/ext/org-acme-ext-one.jar create mode 100644 jetty-webapp/src/test/resources/ext/org-acme-ext-two.jar create mode 100644 jetty-webapp/src/test/resources/ext/sub/org-acme-ext-three.jar diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java index bcee5a51529..7aae5555790 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java @@ -278,12 +278,20 @@ public class WebAppClassLoader extends URLClassLoader StringTokenizer tokenizer= new StringTokenizer(classPath, ",;"); while (tokenizer.hasMoreTokens()) { - Resource resource= _context.newResource(tokenizer.nextToken().trim()); + String token = tokenizer.nextToken().trim(); + Resource resource= _context.newResource(token); if (LOG.isDebugEnabled()) LOG.debug("Path resource=" + resource); - // Add the resource - if (resource.isDirectory() && resource instanceof ResourceCollection) + if(token.endsWith("*")) + { + if(token.length() > 1) + { + token = token.substring(0, token.length() - 1); + resource= _context.newResource(token); + addJars(resource); + } + } else if (resource.isDirectory() && resource instanceof ResourceCollection) addClassPath(resource); else { diff --git a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppClassLoaderTest.java b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppClassLoaderTest.java index 572c42b5aec..6b0e7e055d0 100644 --- a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppClassLoaderTest.java +++ b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppClassLoaderTest.java @@ -64,6 +64,7 @@ public class WebAppClassLoaderTest _context = new WebAppContext(); _context.setBaseResource(webapp); _context.setContextPath("/test"); + _context.setExtraClasspath("src/test/resources/ext/*"); _loader = new WebAppClassLoader(_context); _loader.addJars(webapp.addPath("WEB-INF/lib")); @@ -105,6 +106,10 @@ public class WebAppClassLoaderTest assertCanLoadClass("org.acme.webapp.ClassInJarB"); assertCanLoadClass("org.acme.other.ClassInClassesC"); + assertCanLoadClass("org.acme.extone.Main"); + assertCanLoadClass("org.acme.exttwo.Main"); + assertCantLoadClass("org.acme.extthree.Main"); + assertCantLoadClass("org.eclipse.jetty.webapp.Configuration"); Class clazzA = _loader.loadClass("org.acme.webapp.ClassInJarA"); @@ -119,6 +124,10 @@ public class WebAppClassLoaderTest assertCanLoadClass("org.acme.webapp.ClassInJarB"); assertCanLoadClass("org.acme.other.ClassInClassesC"); + assertCanLoadClass("org.acme.extone.Main"); + assertCanLoadClass("org.acme.exttwo.Main"); + assertCantLoadClass("org.acme.extthree.Main"); + assertCantLoadClass("org.eclipse.jetty.webapp.Configuration"); Class clazzA = _loader.loadClass("org.acme.webapp.ClassInJarA"); diff --git a/jetty-webapp/src/test/resources/ext/org-acme-ext-one.jar b/jetty-webapp/src/test/resources/ext/org-acme-ext-one.jar new file mode 100644 index 0000000000000000000000000000000000000000..e52c47a83d86d5a408809d61614293f6e47a86c3 GIT binary patch literal 2605 zcmWIWW@h1H00E!5u6|$!l;8x?zOEsTx}JV+`TuQ}lbAEG>!4=~NPm6TC&YjTl)^*}wf3hTOikS8R zm5QBnyo`&zO6F><74h=wHWq4BI_J8wQ+1_gg5mL|BTsrlSnnU%bj5}>+17Z%LIqjP zU2&Q>6})x6@I2zx?XB2Zv6BJjJO;4yfG&aq79cCXC>`zrOcfx1f>b0X=ceLOCV;Fg zwW1_H51|?oDtpzYiGo6884yciQSF&+Ry6+TE{%vQBI&fPbiuP8!0>2A{8J}|vkuqRcc zCZyA7zC_Wzu-S_BOR6U=lv&|2kLPip&v_U1MP8~GVgypbZ45Z6_|Z`Doc;*asZ6?%KQl!2;lm#$6WdJoPjNK1(6#m1{i%DC z`qVeaVsAe^bX2&nT<_lD0V8zHX7bp3L(WIz=23T6OthgOyJB|L&dH zPtL8Mu>MScz={uoT`kH}+zQg7Wu10c&pmR+?0Vo~BgMPlcNBk>gGD-KX6FY+Iy|%I zCYGho#)7vXkxT1>M*MDU9nL?nx{$q{Q77y4Mu3U>v&9&S1)!Xum%$}HYzhC&;UYQwDmX-Pb=QNE6rI-17ytIza3ZGl_ zecu^tKJhK@yp}D$yj*0?vV!_QCawk!|AjJL-)28#$~)N?Grj+1=S+b=$?DbjS&nu9uFd zZ=lDjkPp5(-e(^N@oD;o7I^yx85o2bY}sODxXH*Uh=YSK(7?!G%M&eVm0}94QM~j| z>Fa***?3mp>$9~1G*Uq1Q^~r zf@pX~Kxo5W?|~G9z>-Fkc;fnod%%mV-h CzC`{2 literal 0 HcmV?d00001 diff --git a/jetty-webapp/src/test/resources/ext/org-acme-ext-two.jar b/jetty-webapp/src/test/resources/ext/org-acme-ext-two.jar new file mode 100644 index 0000000000000000000000000000000000000000..f46fb20ad35ac003e7cff7e30199463db7fdb16b GIT binary patch literal 2491 zcmWIWW@h1H00E!5u6|$!l;8x?zOEsTx}JV+`TuQ}lbAEG>!4=~NPm6TC&YjTl)^*}wf3hTOikS8R zm5QBnyo`&zO6F><74h=wHWq4BI_J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