From 2ed620b1f493857a92d27199e0ccf5ecc23367d7 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 23 Aug 2017 14:46:41 -0700 Subject: [PATCH 01/14] Fixed #1766 - removing common executor/bufferpool in JettyClientContainerProvider --- .../jsr356/JettyClientContainerProvider.java | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/JettyClientContainerProvider.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/JettyClientContainerProvider.java index 65056797bed..69037a24f65 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/JettyClientContainerProvider.java +++ b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/JettyClientContainerProvider.java @@ -19,17 +19,13 @@ package org.eclipse.jetty.websocket.jsr356; import java.lang.reflect.Method; -import java.util.concurrent.Executor; import javax.websocket.ContainerProvider; import javax.websocket.WebSocketContainer; -import org.eclipse.jetty.io.ByteBufferPool; -import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.ShutdownThread; import org.eclipse.jetty.websocket.api.WebSocketPolicy; import org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope; @@ -47,11 +43,9 @@ public class JettyClientContainerProvider extends ContainerProvider private static final Logger LOG = Log.getLogger(JettyClientContainerProvider.class); private static boolean useSingleton = false; - private static WebSocketContainer INSTANCE; private static boolean useServerContainer = false; - private static Executor commonExecutor; - private static ByteBufferPool commonBufferPool; - + private static WebSocketContainer INSTANCE; + private static Object lock = new Object(); /** @@ -185,21 +179,7 @@ public class JettyClientContainerProvider extends ContainerProvider // Still no instance? if (webSocketContainer == null) { - if (commonExecutor == null) - { - QueuedThreadPool threadPool = new QueuedThreadPool(); - String name = "Jsr356Client@" + hashCode(); - threadPool.setName(name); - threadPool.setDaemon(true); - commonExecutor = threadPool; - } - - if (commonBufferPool == null) - { - commonBufferPool = new MappedByteBufferPool(); - } - - SimpleContainerScope containerScope = new SimpleContainerScope(WebSocketPolicy.newClientPolicy(), commonBufferPool, commonExecutor, null); + SimpleContainerScope containerScope = new SimpleContainerScope(WebSocketPolicy.newClientPolicy()); ClientContainer clientContainer = new ClientContainer(containerScope); if (contextHandler != null && contextHandler instanceof ContainerLifeCycle) From f8d29c5f284baa3407e1a5c9765f66569736d0ff Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 23 Aug 2017 15:20:47 -0700 Subject: [PATCH 02/14] Fixed #1766 - client container is managed now --- .../jetty/websocket/jsr356/JettyClientContainerProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/JettyClientContainerProvider.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/JettyClientContainerProvider.java index 69037a24f65..c1d7a6a23af 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/JettyClientContainerProvider.java +++ b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/JettyClientContainerProvider.java @@ -186,7 +186,7 @@ public class JettyClientContainerProvider extends ContainerProvider { // Add as bean to contextHandler // Allow startup to follow Jetty lifecycle - ((ContainerLifeCycle) contextHandler).addBean(clientContainer); + ((ContainerLifeCycle) contextHandler).addManaged(clientContainer); } else { From 1ba12a4b3d2a971549567e46e7e018afd0aa316b Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 23 Aug 2017 15:57:53 -0700 Subject: [PATCH 03/14] Upgrading to recently released jetty-test-helper:4.2 (for jdk9 reasons) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ef01338ce86..cee3076f5c9 100644 --- a/pom.xml +++ b/pom.xml @@ -936,7 +936,7 @@ org.eclipse.jetty.toolchain jetty-test-helper - 4.1 + 4.2 org.eclipse.jetty.toolchain From 9f28d26cffdb6466bddcc53eb8b6a868ca860212 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 23 Aug 2017 15:58:22 -0700 Subject: [PATCH 04/14] Fixed #1766 - Fixing test case results --- .../jsr356/server/DelayedStartClientOnServerTest.java | 2 +- .../org/eclipse/jetty/websocket/client/WebSocketClient.java | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java index 9da6b911cb1..602e8920a6d 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java @@ -247,7 +247,7 @@ public class DelayedStartClientOnServerTest assertThat("Response", response, startsWith("Connected to ws://")); List threadNames = getThreadNames(server); assertNoHttpClientPoolThreads(threadNames); - assertThat("Threads", threadNames, hasItem(containsString("Jsr356Client@"))); + assertThat("Threads", threadNames, hasItem(containsString("WebSocketContainer@"))); } finally { diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java index 04d6e64a543..8f4149ddd03 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java @@ -392,11 +392,7 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont if (LOG.isDebugEnabled()) LOG.debug("Stopping {}",this); - - if (ShutdownThread.isRegistered(this)) - { - ShutdownThread.deregister(this); - } + ShutdownThread.deregister(this); super.doStop(); From de9ac99fb278e7cee1e7036de5574ef3f124f34c Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Thu, 24 Aug 2017 17:00:19 +1000 Subject: [PATCH 05/14] Document 'env' config param for jetty-maven-plugin. --- .../main/asciidoc/development/maven/jetty-maven-plugin.adoc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jetty-documentation/src/main/asciidoc/development/maven/jetty-maven-plugin.adoc b/jetty-documentation/src/main/asciidoc/development/maven/jetty-maven-plugin.adoc index a54362e6492..b5c9303359e 100644 --- a/jetty-documentation/src/main/asciidoc/development/maven/jetty-maven-plugin.adoc +++ b/jetty-documentation/src/main/asciidoc/development/maven/jetty-maven-plugin.adoc @@ -596,6 +596,9 @@ The available configuration parameters - in addition to those for the `jetty:run jvmArgs:: Optional. A string representing arbitrary arguments to pass to the forked JVM. +env:: +Optional. +Map of key/value pairs to pass as environment to the forked JVM. waitForChild:: Default is `true`. This causes the parent process to wait for the forked process to exit. From 2a3deb0a10b8d4a655e3fab262a2a9df9e8e6ae5 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Thu, 24 Aug 2017 10:46:30 +0200 Subject: [PATCH 06/14] Removed leftover System.err debug line. --- .../java/org/eclipse/jetty/security/AbstractLoginService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/jetty-security/src/main/java/org/eclipse/jetty/security/AbstractLoginService.java b/jetty-security/src/main/java/org/eclipse/jetty/security/AbstractLoginService.java index fd652bb479a..fb15581c9c6 100644 --- a/jetty-security/src/main/java/org/eclipse/jetty/security/AbstractLoginService.java +++ b/jetty-security/src/main/java/org/eclipse/jetty/security/AbstractLoginService.java @@ -25,7 +25,6 @@ import java.security.Principal; import javax.security.auth.Subject; import javax.servlet.ServletRequest; - import org.eclipse.jetty.server.UserIdentity; import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.util.log.Log; @@ -203,7 +202,6 @@ public abstract class AbstractLoginService extends AbstractLifeCycle implements if (user.getUserPrincipal() instanceof UserPrincipal) { - System.err.println("VALIDATING user "+fresh.getName()); return fresh.authenticate(((UserPrincipal)user.getUserPrincipal())._credential); } From 1d1ba56c886da4590c1d952ca037e5c9b1cd0e5c Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Tue, 22 Aug 2017 17:02:17 +1000 Subject: [PATCH 07/14] Issue #1499 ClasspathPattern module support Added simple but inefficient implementation for jrt matching --- .../jetty/webapp/ClasspathPattern.java | 78 +++++++++++----- .../jetty/webapp/ClasspathPatternTest.java | 93 +++++++++++++++++++ 2 files changed, 147 insertions(+), 24 deletions(-) diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java index 5c089b1a331..1ccc7fd35b3 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java @@ -79,7 +79,8 @@ public class ClasspathPattern extends AbstractSet _pattern=pattern; _inclusive = !pattern.startsWith("-"); _name = _inclusive ? pattern : pattern.substring(1).trim(); - _type = _name.startsWith("file:")?Type.LOCATION:(_name.endsWith(".")?Type.PACKAGE:Type.CLASSNAME); + boolean is_location = _name.startsWith("file:") || _name.startsWith("jrt:"); + _type = is_location?Type.LOCATION:(_name.endsWith(".")?Type.PACKAGE:Type.CLASSNAME); } Entry(String name, boolean include) @@ -87,7 +88,8 @@ public class ClasspathPattern extends AbstractSet _pattern=include?name:("-"+name); _inclusive = include; _name = name; - _type = _name.startsWith("file:")?Type.LOCATION:(_name.endsWith(".")?Type.PACKAGE:Type.CLASSNAME); + boolean is_location = _name.startsWith("file:") || _name.startsWith("jrt:"); + _type = is_location?Type.LOCATION:(_name.endsWith(".")?Type.PACKAGE:Type.CLASSNAME); } @@ -308,36 +310,65 @@ public class ClasspathPattern extends AbstractSet } @SuppressWarnings("serial") - public static class ByLocation extends HashSet implements Predicate + public static class ByLocation extends HashSet implements Predicate { @Override - public boolean test(Path path) + public boolean test(URI uri) { - for (File file: this) + // TODO this is very inefficient with object creation + + switch(uri.getScheme()) { - if (file.isDirectory()) + case "file": { - if (path.startsWith(file.toPath())) + Path path = Paths.get(uri); + for (URI u: this) { - return true; - } - } - else - { - if (path.equals(file.toPath())) - { - return true; + if (u.getScheme().equals("file")) + { + File file = new File(u); + if (file.isDirectory()) + { + if (path.startsWith(file.toPath())) + { + return true; + } + } else + { + if (path.equals(file.toPath())) + { + return true; + } + } + } } + return false; } + + case "jrt": + { + String module = uri.getPath().split("/")[1]; + for (URI u: this) + { + if (u.getScheme().equals("jrt")) + { + String m = u.toString().split("/")[1]; + if (module.equals(m)) + return true; + } + } + return false; + } + + default: + throw new IllegalStateException("unknown URI scheme: "+uri); } - - return false; } } Map _entries = new HashMap<>(); IncludeExcludeSet _patterns = new IncludeExcludeSet<>(ByPackageOrName.class); - IncludeExcludeSet _locations = new IncludeExcludeSet<>(ByLocation.class); + IncludeExcludeSet _locations = new IncludeExcludeSet<>(ByLocation.class); public ClasspathPattern() { @@ -412,11 +443,11 @@ public class ClasspathPattern extends AbstractSet { try { - File file = Resource.newResource(entry.getName()).getFile().getAbsoluteFile().getCanonicalFile(); + URI uri = Resource.newResource(entry.getName()).getURI(); if (entry.isInclusive()) - _locations.include(file); + _locations.include(uri); else - _locations.exclude(file); + _locations.exclude(uri); } catch (Exception e) { @@ -526,7 +557,7 @@ public class ClasspathPattern extends AbstractSet return byName; // Already excluded so no need to check location. URI location = TypeUtil.getLocationOfClass(clazz); Boolean byLocation = location == null ? null - : _locations.isIncludedAndNotExcluded(Paths.get(location)); + : _locations.isIncludedAndNotExcluded(location); if (LOG.isDebugEnabled()) LOG.debug("match {} from {} byName={} byLocation={} in {}",clazz,location,byName,byLocation,this); @@ -564,8 +595,7 @@ public class ClasspathPattern extends AbstractSet URI jarUri = URIUtil.getJarSource(url.toURI()); if ("file".equalsIgnoreCase(jarUri.getScheme())) { - File file = new File(jarUri); - byLocation = _locations.isIncludedAndNotExcluded(file.toPath()); + byLocation = _locations.isIncludedAndNotExcluded(jarUri); } } catch(Exception e) diff --git a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClasspathPatternTest.java b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClasspathPatternTest.java index 26561839de0..13d817531a3 100644 --- a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClasspathPatternTest.java +++ b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClasspathPatternTest.java @@ -154,6 +154,49 @@ public class ClasspathPatternTest Assert.assertThat(pattern.match(ClasspathPatternTest.class), Matchers.is(true)); } + @SuppressWarnings("restriction") + @Test + public void testIncludedLocationsOrModule() throws Exception + { + Assume.assumeTrue(JDK.IS_9); + + // jar from JVM classloader + URI mod_string = TypeUtil.getLocationOfClass(String.class); + // System.err.println(mod_string); + + // a jar from maven repo jar + URI loc_junit = TypeUtil.getLocationOfClass(Test.class); + // System.err.println(loc_junit); + + // class file + URI loc_test = TypeUtil.getLocationOfClass(ClasspathPatternTest.class); + // System.err.println(loc_test); + + ClasspathPattern pattern = new ClasspathPattern(); + pattern.include("something"); + Assert.assertThat(pattern.match(String.class), Matchers.is(false)); + Assert.assertThat(pattern.match(Test.class), Matchers.is(false)); + Assert.assertThat(pattern.match(JDK.class), Matchers.is(false)); + Assert.assertThat(pattern.match(ClasspathPatternTest.class), Matchers.is(false)); + + // Add module for all JVM base classes + pattern.include("jrt:/java.base"); + + // Add jar for individual class and classes directory + pattern.include(loc_junit.toString(), loc_test.toString()); + + Assert.assertThat(pattern.match(String.class), Matchers.is(true)); + Assert.assertThat(pattern.match(Test.class), Matchers.is(true)); + Assert.assertThat(pattern.match(JDK.class), Matchers.is(false)); + Assert.assertThat(pattern.match(ClasspathPatternTest.class), Matchers.is(true)); + + pattern.add("-java.lang.String"); + Assert.assertThat(pattern.match(String.class), Matchers.is(false)); + Assert.assertThat(pattern.match(Test.class), Matchers.is(true)); + Assert.assertThat(pattern.match(JDK.class), Matchers.is(false)); + Assert.assertThat(pattern.match(ClasspathPatternTest.class), Matchers.is(true)); + } + @SuppressWarnings("restriction") @Test public void testExcludeLocations() throws Exception @@ -194,6 +237,46 @@ public class ClasspathPatternTest Assert.assertThat(pattern.match(ClasspathPatternTest.class), Matchers.is(false)); } + @SuppressWarnings("restriction") + @Test + public void testExcludeLocationsOrModule() throws Exception + { + Assume.assumeTrue(JDK.IS_9); + + // jar from JVM classloader + URI mod_string = TypeUtil.getLocationOfClass(String.class); + // System.err.println(mod_string); + + // a jar from maven repo jar + URI loc_junit = TypeUtil.getLocationOfClass(Test.class); + // System.err.println(loc_junit); + + // class file + URI loc_test = TypeUtil.getLocationOfClass(ClasspathPatternTest.class); + // System.err.println(loc_test); + + ClasspathPattern pattern = new ClasspathPattern(); + + // include everything + pattern.include("."); + + Assert.assertThat(pattern.match(String.class), Matchers.is(true)); + Assert.assertThat(pattern.match(Test.class), Matchers.is(true)); + Assert.assertThat(pattern.match(JDK.class), Matchers.is(true)); + Assert.assertThat(pattern.match(ClasspathPatternTest.class), Matchers.is(true)); + + // Add directory for both JVM classes + pattern.exclude("jrt:/java.base/"); + + // Add jar for individual class and classes directory + pattern.exclude(loc_junit.toString(), loc_test.toString()); + + Assert.assertThat(pattern.match(String.class), Matchers.is(false)); + Assert.assertThat(pattern.match(Test.class), Matchers.is(false)); + Assert.assertThat(pattern.match(JDK.class), Matchers.is(true)); + Assert.assertThat(pattern.match(ClasspathPatternTest.class), Matchers.is(false)); + } + @Test public void testLarge() { @@ -208,4 +291,14 @@ public class ClasspathPatternTest Assert.assertTrue(pattern.match("n" + i + "." + Integer.toHexString(100 + i) + ".Name")); } } + + + @Test + public void testJvmModule() + { + URI uri = TypeUtil.getLocationOfClass(String.class); + System.err.println(uri); + System.err.println(uri.toString().split("/")[0]); + System.err.println(uri.toString().split("/")[1]); + } } From 8e02bfef3693db0db1d969c1170de84ff4a90c8e Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 24 Aug 2017 10:11:55 +1000 Subject: [PATCH 08/14] Issue #1499 ClasspathPattern module support More efficient implementation that precomputes Path and modules --- .../jetty/webapp/ClasspathPattern.java | 387 ++++++++++++------ 1 file changed, 260 insertions(+), 127 deletions(-) diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java index 1ccc7fd35b3..ae6e3c8523e 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.webapp; import java.io.File; +import java.io.IOException; import java.net.URI; import java.net.URL; import java.nio.file.Path; @@ -32,8 +33,10 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.function.Predicate; +import org.eclipse.jetty.io.RuntimeIOException; import org.eclipse.jetty.util.ArrayTernaryTrie; import org.eclipse.jetty.util.IncludeExcludeSet; import org.eclipse.jetty.util.TypeUtil; @@ -55,6 +58,7 @@ import org.eclipse.jetty.util.resource.Resource; * the class was loaded *
  • 'file:///some/location.jar' - The URI of a jar file from which * the class was loaded + *
  • 'jrt:/modulename' - A Java9 module name
  • *
  • Any of the above patterns preceeded by '-' will exclude rather than include the match. * * When class is initialized from a classpath pattern string, entries @@ -64,54 +68,24 @@ import org.eclipse.jetty.util.resource.Resource; public class ClasspathPattern extends AbstractSet { private static final Logger LOG = Log.getLogger(ClasspathPattern.class); - - enum Type { PACKAGE, CLASSNAME, LOCATION } private static class Entry { private final String _pattern; private final String _name; private final boolean _inclusive; - private final Type _type; - - Entry(String pattern) + + protected Entry(String name, boolean inclusive) { - _pattern=pattern; - _inclusive = !pattern.startsWith("-"); - _name = _inclusive ? pattern : pattern.substring(1).trim(); - boolean is_location = _name.startsWith("file:") || _name.startsWith("jrt:"); - _type = is_location?Type.LOCATION:(_name.endsWith(".")?Type.PACKAGE:Type.CLASSNAME); - } - - Entry(String name, boolean include) - { - _pattern=include?name:("-"+name); - _inclusive = include; _name = name; - boolean is_location = _name.startsWith("file:") || _name.startsWith("jrt:"); - _type = is_location?Type.LOCATION:(_name.endsWith(".")?Type.PACKAGE:Type.CLASSNAME); + _inclusive = inclusive; + _pattern = inclusive ? _name : ("-"+_name); } - public String getPattern() { return _pattern; } - - public boolean isPackage() - { - return _type==Type.PACKAGE; - } - - public boolean isClassName() - { - return _type==Type.CLASSNAME; - } - - public boolean isLocation() - { - return _type==Type.LOCATION; - } public String getName() { @@ -142,7 +116,68 @@ public class ClasspathPattern extends AbstractSet return _inclusive; } } - + + private static class PackageEntry extends Entry + { + protected PackageEntry(String name, boolean inclusive) + { + super(name, inclusive); + } + } + + private static class ClassEntry extends Entry + { + protected ClassEntry(String name, boolean inclusive) + { + super(name, inclusive); + } + } + + private static class LocationEntry extends Entry + { + private final File _file; + + protected LocationEntry(String name, boolean inclusive) + { + super(name, inclusive); + if (!getName().startsWith("file:")) + throw new IllegalArgumentException(name); + try + { + _file = Resource.newResource(getName()).getFile(); + } + catch(IOException e) + { + throw new RuntimeIOException(e); + } + } + + public File getFile() + { + return _file; + } + } + + private static class ModuleEntry extends Entry + { + private final String _module; + + protected ModuleEntry(String name, boolean inclusive) + { + super(name, inclusive); + if (!getName().startsWith("jrt:")) + throw new IllegalArgumentException(name); + _module = getName().split("/")[1]; + } + + public String getModule() + { + return _module; + } + } + + + public static class ByPackage extends AbstractSet implements Predicate { @@ -176,9 +211,9 @@ public class ClasspathPattern extends AbstractSet public boolean add(Entry entry) { String name = entry.getName(); - if (entry.isClassName()) + if (entry instanceof ClassEntry) name+="$"; - else if (entry.isLocation()) + else if (!(entry instanceof PackageEntry)) throw new IllegalArgumentException(entry.toString()); else if (".".equals(name)) name=""; @@ -206,7 +241,7 @@ public class ClasspathPattern extends AbstractSet } @SuppressWarnings("serial") - public static class ByName extends HashSet implements Predicate + public static class ByClass extends HashSet implements Predicate { private final Map _entries = new HashMap<>(); @@ -231,7 +266,7 @@ public class ClasspathPattern extends AbstractSet @Override public boolean add(Entry entry) { - if (!entry.isClassName()) + if (!(entry instanceof ClassEntry)) throw new IllegalArgumentException(entry.toString()); return _entries.put(entry.getName(),entry)==null; } @@ -248,14 +283,14 @@ public class ClasspathPattern extends AbstractSet public static class ByPackageOrName extends AbstractSet implements Predicate { - private final ByName _byName = new ByName(); + private final ByClass _byClass = new ByClass(); private final ByPackage _byPackage = new ByPackage(); @Override public boolean test(String name) { - return _byPackage.test(name) - || _byName.test(name) ; + return _byPackage.test(name) + || _byClass.test(name) ; } @Override @@ -272,19 +307,21 @@ public class ClasspathPattern extends AbstractSet } @Override - public boolean add(Entry e) + public boolean add(Entry entry) { - if (e.isLocation()) - throw new IllegalArgumentException(); - - if (e.isPackage()) - return _byPackage.add(e); - - // Add class name to packages also as classes act - // as packages for nested classes. - boolean added = _byPackage.add(e); - added = _byName.add(e) || added; - return added; + if (entry instanceof PackageEntry) + return _byPackage.add(entry); + + if (entry instanceof ClassEntry) + { + // Add class name to packages also as classes act + // as packages for nested classes. + boolean added = _byPackage.add(entry); + added = _byClass.add(entry) || added; + return added; + } + + throw new IllegalArgumentException(); } @Override @@ -293,82 +330,166 @@ public class ClasspathPattern extends AbstractSet if (!(o instanceof Entry)) return false; - boolean removed = _byPackage.remove(o); - - if (!((Entry)o).isPackage()) - removed = _byName.remove(o) || removed; - - return removed; + boolean removedPackage = _byPackage.remove(o); + boolean removedClass = _byClass.remove(o); + + return removedPackage || removedClass; } @Override public void clear() { _byPackage.clear(); - _byName.clear(); + _byClass.clear(); } } @SuppressWarnings("serial") - public static class ByLocation extends HashSet implements Predicate + public static class ByLocation extends HashSet implements Predicate { @Override public boolean test(URI uri) { - // TODO this is very inefficient with object creation + if (!uri.getScheme().equals("file")) + return false; + Path path = Paths.get(uri); - switch(uri.getScheme()) + for (Entry entry : this) { - case "file": - { - Path path = Paths.get(uri); - for (URI u: this) - { - if (u.getScheme().equals("file")) - { - File file = new File(u); - if (file.isDirectory()) - { - if (path.startsWith(file.toPath())) - { - return true; - } - } else - { - if (path.equals(file.toPath())) - { - return true; - } - } - } - } - return false; - } + if (!(entry instanceof LocationEntry)) + throw new IllegalStateException(); - case "jrt": - { - String module = uri.getPath().split("/")[1]; - for (URI u: this) - { - if (u.getScheme().equals("jrt")) - { - String m = u.toString().split("/")[1]; - if (module.equals(m)) - return true; - } - } - return false; - } + File file = ((LocationEntry)entry).getFile(); - default: - throw new IllegalStateException("unknown URI scheme: "+uri); + if (file.isDirectory()) + { + if (path.startsWith(file.toPath())) + { + return true; + } + } else + { + if (path.equals(file.toPath())) + { + return true; + } + } } + return false; } } - + + @SuppressWarnings("serial") + public static class ByModule extends HashSet implements Predicate + { + private final ArrayTernaryTrie.Growing _entries = new ArrayTernaryTrie.Growing<>(false,512,512); + + @Override + public boolean test(URI uri) + { + if (!uri.getScheme().equalsIgnoreCase("jrt")) + return false; + String module = uri.getPath(); + int end = module.indexOf('/',1); + if (end<1) + end = module.length(); + return _entries.get(module,1,end-1)!=null; + } + + @Override + public Iterator iterator() + { + return _entries.keySet().stream().map(_entries::get).iterator(); + } + + @Override + public int size() + { + return _entries.size(); + } + + @Override + public boolean add(Entry entry) + { + if (!(entry instanceof ModuleEntry)) + throw new IllegalArgumentException(entry.toString()); + String module = ((ModuleEntry)entry).getModule(); + + if (_entries.get(module)!=null) + return false; + _entries.put(module,entry); + return true; + } + + @Override + public boolean remove(Object entry) + { + if (!(entry instanceof Entry)) + return false; + + return _entries.remove(((Entry)entry).getName())!=null; + } + } + + + public static class ByLocationOrModule extends AbstractSet implements Predicate + { + private final ByLocation _byLocation = new ByLocation(); + private final ByModule _byModule = new ByModule(); + + @Override + public boolean test(URI name) + { + return _byLocation.test(name) || _byModule.test(name); + } + + @Override + public Iterator iterator() + { + Set entries = new HashSet<>(); + entries.addAll(_byLocation); + entries.addAll(_byModule); + return entries.iterator(); + } + + @Override + public int size() + { + return _byLocation.size()+_byModule.size(); + } + + @Override + public boolean add(Entry entry) + { + if (entry instanceof LocationEntry) + return _byLocation.add(entry); + if (entry instanceof ModuleEntry) + return _byModule.add(entry); + + throw new IllegalArgumentException(entry.toString()); + } + + @Override + public boolean remove(Object o) + { + if (o instanceof LocationEntry) + return _byLocation.remove(o); + if (o instanceof ModuleEntry) + return _byModule.remove(o); + return false; + } + + @Override + public void clear() + { + _byLocation.clear(); + _byModule.clear(); + } + } + Map _entries = new HashMap<>(); IncludeExcludeSet _patterns = new IncludeExcludeSet<>(ByPackageOrName.class); - IncludeExcludeSet _locations = new IncludeExcludeSet<>(ByLocation.class); + IncludeExcludeSet _locations = new IncludeExcludeSet<>(ByLocationOrModule.class); public ClasspathPattern() { @@ -388,7 +509,7 @@ public class ClasspathPattern extends AbstractSet { if (name==null) return false; - return add(new Entry(name,true)); + return add(newEntry(name,true)); } public boolean include(String... name) @@ -396,7 +517,7 @@ public class ClasspathPattern extends AbstractSet boolean added = false; for (String n:name) if (n!=null) - added = add(new Entry(n,true)) || added; + added = add(newEntry(n,true)) || added; return added; } @@ -404,7 +525,7 @@ public class ClasspathPattern extends AbstractSet { if (name==null) return false; - return add(new Entry(name,false)); + return add(newEntry(name,false)); } public boolean exclude(String... name) @@ -412,7 +533,7 @@ public class ClasspathPattern extends AbstractSet boolean added = false; for (String n:name) if (n!=null) - added = add(new Entry(n,false)) || added; + added = add(newEntry(n,false)) || added; return added; } @@ -421,7 +542,7 @@ public class ClasspathPattern extends AbstractSet { if (pattern==null) return false; - return add(new Entry(pattern)); + return add(newEntry(pattern)); } public boolean add(String... pattern) @@ -429,30 +550,42 @@ public class ClasspathPattern extends AbstractSet boolean added = false; for (String p:pattern) if (p!=null) - added = add(new Entry(p)) || added; + added = add(newEntry(p)) || added; return added; } - + + protected Entry newEntry(String pattern) + { + if (pattern.startsWith("-")) + return newEntry(pattern.substring(1),false); + return newEntry(pattern,true); + } + + protected Entry newEntry(String name, boolean inclusive) + { + if (name.startsWith("-")) + throw new IllegalStateException(name); + if (name.startsWith("file:")) + return new LocationEntry(name, inclusive); + if (name.startsWith("jrt:")) + return new ModuleEntry(name, inclusive); + if (name.endsWith(".")) + return new PackageEntry(name, inclusive); + return new ClassEntry(name,inclusive); + } + protected boolean add(Entry entry) { if (_entries.containsKey(entry.getPattern())) return false; _entries.put(entry.getPattern(),entry); - if (entry.isLocation()) + if (entry instanceof LocationEntry || entry instanceof ModuleEntry) { - try - { - URI uri = Resource.newResource(entry.getName()).getURI(); - if (entry.isInclusive()) - _locations.include(uri); - else - _locations.exclude(uri); - } - catch (Exception e) - { - throw new IllegalArgumentException(e); - } + if (entry.isInclusive()) + _locations.include(entry); + else + _locations.exclude(entry); } else { From b8e5a1f0182986f290b8687716f314a49cb1f290 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 24 Aug 2017 13:01:03 +1000 Subject: [PATCH 09/14] Issue #1498 RTResource Added a test that indicates the existing URLResource is adequate for JRT --- .../jetty/util/resource/URLResource.java | 9 +- .../jetty/util/resource/JrtResourceTest.java | 126 ++++++++++++++++++ 2 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 jetty-util/src/test/java/org/eclipse/jetty/util/resource/JrtResourceTest.java diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/URLResource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/URLResource.java index 7839e557456..2349747065c 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/URLResource.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/URLResource.java @@ -32,7 +32,7 @@ import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; /* ------------------------------------------------------------ */ -/** Abstract resource class. +/** URL resource class. */ public class URLResource extends Resource { @@ -179,10 +179,6 @@ public class URLResource extends Resource return new File(perm.getName()); } - // Try the URL file arg - try {return new File(_url.getFile());} - catch(Exception e) {LOG.ignore(e);} - // Don't know the file return null; } @@ -196,7 +192,6 @@ public class URLResource extends Resource { return _url.toExternalForm(); } - /* ------------------------------------------------------------ */ /** @@ -209,8 +204,6 @@ public class URLResource extends Resource { return getInputStream (true); //backwards compatibility } - - /* ------------------------------------------------------------ */ /** diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/JrtResourceTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/JrtResourceTest.java new file mode 100644 index 00000000000..8f9b3d11a23 --- /dev/null +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/JrtResourceTest.java @@ -0,0 +1,126 @@ +// +// ======================================================================== +// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.util.resource; + +import java.net.URI; +import java.util.Arrays; + +import org.eclipse.jetty.toolchain.test.JDK; +import org.eclipse.jetty.toolchain.test.MavenTestingUtils; +import org.eclipse.jetty.util.IO; +import org.eclipse.jetty.util.TypeUtil; +import org.hamcrest.Matchers; +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Test; + +import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.Matchers.startsWith; +import static org.junit.Assert.assertThat; + + +public class JrtResourceTest +{ + private String testResURI = MavenTestingUtils.getTestResourcesDir().getAbsoluteFile().toURI().toASCIIString(); + + @Test + public void testResourceFromUriForString() + throws Exception + { + + Assume.assumeTrue(JDK.IS_9); + + URI string_loc = TypeUtil.getLocationOfClass(String.class); + Resource resource = Resource.newResource(string_loc); + + assertThat(resource.exists(), is(true)); + assertThat(resource.isDirectory(), is(false)); + assertThat(IO.readBytes(resource.getInputStream()).length,Matchers.greaterThan(0)); + assertThat(IO.readBytes(resource.getInputStream()).length,is((int)resource.length())); + assertThat(resource.getWeakETag("-xxx"),startsWith("W/\"")); + assertThat(resource.getWeakETag("-xxx"),endsWith("-xxx\"")); + + } + + @Test + public void testResourceFromStringForString() + throws Exception + { + Assume.assumeTrue(JDK.IS_9); + + URI string_loc = TypeUtil.getLocationOfClass(String.class); + Resource resource = Resource.newResource(string_loc.toASCIIString()); + + assertThat(resource.exists(), is(true)); + assertThat(resource.isDirectory(), is(false)); + assertThat(IO.readBytes(resource.getInputStream()).length,Matchers.greaterThan(0)); + assertThat(IO.readBytes(resource.getInputStream()).length,is((int)resource.length())); + assertThat(resource.getWeakETag("-xxx"),startsWith("W/\"")); + assertThat(resource.getWeakETag("-xxx"),endsWith("-xxx\"")); + } + + @Test + public void testResourceFromURLForString() + throws Exception + { + Assume.assumeTrue(JDK.IS_9); + + URI string_loc = TypeUtil.getLocationOfClass(String.class); + Resource resource = Resource.newResource(string_loc.toURL()); + + assertThat(resource.exists(), is(true)); + assertThat(resource.isDirectory(), is(false)); + assertThat(IO.readBytes(resource.getInputStream()).length,Matchers.greaterThan(0)); + assertThat(IO.readBytes(resource.getInputStream()).length,is((int)resource.length())); + assertThat(resource.getWeakETag("-xxx"),startsWith("W/\"")); + assertThat(resource.getWeakETag("-xxx"),endsWith("-xxx\"")); + } + + + @Test + public void testResourceModule() + throws Exception + { + Assume.assumeTrue(JDK.IS_9); + + Resource resource = Resource.newResource("jrt:/java.base"); + + assertThat(resource.exists(), is(false)); + assertThat(resource.isDirectory(), is(false)); + assertThat(resource.length(),is(-1L)); + } + + @Test + public void testResourceAllModules() + throws Exception + { + Assume.assumeTrue(JDK.IS_9); + + Resource resource = Resource.newResource("jrt:/"); + + assertThat(resource.exists(), is(false)); + assertThat(resource.isDirectory(), is(false)); + assertThat(resource.length(),is(-1L)); + } + + + +} From 6390b335fca1d1dd8cfe7bf2919790f671b6373e Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 28 Aug 2017 15:59:36 +1000 Subject: [PATCH 10/14] Issue #1520 Removed a lot of cruft from this class that had accumulated over the years. Deprecated methods like setConfigPath(File) and setConfigPath(String) removed asymmetries like setConfigPath(String) and Path getConfigPath() removed redundant configResource field improved jarfile extraction to work for all string setters. do not hot reload extracted config fixed code style issues --- .../jetty/security/PropertyUserStore.java | 140 +++++++++--------- .../jetty/security/PropertyUserStoreTest.java | 2 +- .../jetty/util/resource/JarFileResource.java | 2 +- 3 files changed, 74 insertions(+), 70 deletions(-) diff --git a/jetty-security/src/main/java/org/eclipse/jetty/security/PropertyUserStore.java b/jetty-security/src/main/java/org/eclipse/jetty/security/PropertyUserStore.java index 0c418ea65a6..4630ae6cfd9 100644 --- a/jetty-security/src/main/java/org/eclipse/jetty/security/PropertyUserStore.java +++ b/jetty-security/src/main/java/org/eclipse/jetty/security/PropertyUserStore.java @@ -18,17 +18,8 @@ package org.eclipse.jetty.security; -import org.eclipse.jetty.util.PathWatcher; -import org.eclipse.jetty.util.PathWatcher.PathWatchEvent; -import org.eclipse.jetty.util.StringUtil; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.resource.JarResource; -import org.eclipse.jetty.util.resource.PathResource; -import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.util.security.Credential; - import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -41,6 +32,17 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import org.eclipse.jetty.toolchain.test.IO; +import org.eclipse.jetty.util.PathWatcher; +import org.eclipse.jetty.util.PathWatcher.PathWatchEvent; +import org.eclipse.jetty.util.StringUtil; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.resource.JarFileResource; +import org.eclipse.jetty.util.resource.PathResource; +import org.eclipse.jetty.util.resource.Resource; +import org.eclipse.jetty.util.security.Credential; + /** * PropertyUserStore *

    @@ -59,13 +61,10 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener { private static final Logger LOG = Log.getLogger(PropertyUserStore.class); - private static final String JAR_FILE = "jar:file:"; - protected Path _configPath; - protected Resource _configResource; - protected PathWatcher pathWatcher; - protected boolean hotReload = false; // default is not to reload + protected PathWatcher _pathWatcher; + protected boolean _hotReload = false; // default is not to reload protected boolean _firstLoad = true; // true if first load, false from that point on protected List _listeners; @@ -73,9 +72,7 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener /** * Get the config (as a string) * @return the config path as a string - * @deprecated use {@link #getConfigPath()} instead */ - @Deprecated public String getConfig() { if (_configPath != null) @@ -89,16 +86,28 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener */ public void setConfig(String config) { + if (config == null) + { + _configPath = null; + return; + } + try { Resource configResource = Resource.newResource(config); - if (configResource.getFile() != null) - setConfigPath(configResource.getFile()); + + if (configResource instanceof JarFileResource) + _configPath = extractPackedFile((JarFileResource)configResource); + else if (configResource instanceof PathResource) + _configPath = ((PathResource)configResource).getPath(); + else if (configResource.getFile() != null) + setConfigFile(configResource.getFile()); else - throw new IllegalArgumentException(config+" is not a file"); + throw new IllegalArgumentException(config); } catch (Exception e) { + _configPath = null; throw new IllegalStateException(e); } @@ -117,44 +126,33 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener * Set the Config Path from a String reference to a file * @param configFile the config file can a be a file path or a reference to a file within a jar file jar:file: */ + @Deprecated public void setConfigPath(String configFile) { - if (configFile == null) - { - _configPath = null; - } - else if (new File( configFile ).exists()) - { - _configPath = new File(configFile).toPath(); - } - if ( !new File( configFile ).exists() && configFile.startsWith( JAR_FILE )) - { - // format of the url is jar:file:/foo/bar/beer.jar!/mountain_goat/pale_ale.txt - // ideally we'd like to extract this to Resource class? - try - { - _configPath = extractPackedFile( configFile ); - } - catch ( IOException e ) - { - throw new RuntimeException( "cannot extract file from url:" + configFile, e ); - } - } + setConfig(configFile); } - private Path extractPackedFile( String configFile ) + private Path extractPackedFile( JarFileResource configResource ) throws IOException { - int fileIndex = configFile.indexOf( "!" ); - String entryPath = configFile.substring( fileIndex + 1, configFile.length() ); + String uri = configResource.getURI().toASCIIString(); + int colon = uri.lastIndexOf(":"); + int bang_slash = uri.indexOf("!/"); + if (colon<0 || bang_slash<0 || colon>bang_slash) + throw new IllegalArgumentException("Not resolved JarFile resource: "+uri); + String entry_path = uri.substring(colon+2).replace("!/","__").replace('/','_').replace('.','_'); Path tmpDirectory = Files.createTempDirectory( "users_store" ); - Path extractedPath = Paths.get(tmpDirectory.toString(), entryPath); - // delete if exists as copyTo do not overwrite + tmpDirectory.toFile().deleteOnExit(); + Path extractedPath = Paths.get(tmpDirectory.toString(), entry_path); Files.deleteIfExists( extractedPath ); - // delete on shutdown extractedPath.toFile().deleteOnExit(); - JarResource.newResource( configFile ).copyTo( tmpDirectory.toFile() ); + IO.copy(configResource.getInputStream(),new FileOutputStream(extractedPath.toFile())); + if (isHotReload()) + { + LOG.warn("Cannot hot reload from packed configuration: {}",configResource); + setHotReload(false); + } return extractedPath; } @@ -162,7 +160,17 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener * Set the Config Path from a {@link File} reference * @param configFile the config file */ + @Deprecated public void setConfigPath(File configFile) + { + setConfigFile(configFile); + } + + /** + * Set the Config Path from a {@link File} reference + * @param configFile the config file + */ + public void setConfigFile(File configFile) { if(configFile == null) { @@ -182,19 +190,15 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener _configPath = configPath; } - /* ------------------------------------------------------------ */ /** * @return the resource associated with the configured properties file, creating it if necessary * @throws IOException if unable to get the resource */ public Resource getConfigResource() throws IOException { - if (_configResource == null) - { - _configResource = new PathResource(_configPath); - } - - return _configResource; + if (_configPath==null) + return null; + return new PathResource(_configPath); } /** @@ -204,7 +208,7 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener */ public boolean isHotReload() { - return hotReload; + return _hotReload; } /** @@ -218,7 +222,7 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener { throw new IllegalStateException("Cannot set hot reload while user store is running"); } - this.hotReload = enable; + this._hotReload = enable; } @@ -247,8 +251,9 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener } Properties properties = new Properties(); - if (getConfigResource().exists()) - properties.load(getConfigResource().getInputStream()); + Resource config = getConfigResource(); + if (config!=null && config.exists()) + properties.load(config.getInputStream()); Set known = new HashSet<>(); @@ -297,7 +302,6 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener } } - /* * set initial load to false as there should be no more initial loads */ @@ -324,11 +328,11 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener loadUsers(); if ( isHotReload() && (_configPath != null) ) { - this.pathWatcher = new PathWatcher(); - this.pathWatcher.watch(_configPath); - this.pathWatcher.addListener(this); - this.pathWatcher.setNotifyExistingOnStart(false); - this.pathWatcher.start(); + this._pathWatcher = new PathWatcher(); + this._pathWatcher.watch(_configPath); + this._pathWatcher.addListener(this); + this._pathWatcher.setNotifyExistingOnStart(false); + this._pathWatcher.start(); } } @@ -357,9 +361,9 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener protected void doStop() throws Exception { super.doStop(); - if (this.pathWatcher != null) - this.pathWatcher.stop(); - this.pathWatcher = null; + if (this._pathWatcher != null) + this._pathWatcher.stop(); + this._pathWatcher = null; } /** diff --git a/jetty-security/src/test/java/org/eclipse/jetty/security/PropertyUserStoreTest.java b/jetty-security/src/test/java/org/eclipse/jetty/security/PropertyUserStoreTest.java index 2f24ebb6d56..eea4fc560e3 100644 --- a/jetty-security/src/test/java/org/eclipse/jetty/security/PropertyUserStoreTest.java +++ b/jetty-security/src/test/java/org/eclipse/jetty/security/PropertyUserStoreTest.java @@ -189,7 +189,7 @@ public class PropertyUserStoreTest final String usersFile = initUsersPackedFileText(); PropertyUserStore store = new PropertyUserStore(); - store.setConfigPath(usersFile); + store.setConfig(usersFile); store.registerUserListener(userCount); diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarFileResource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarFileResource.java index dc95ab451fc..c57cb35476d 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarFileResource.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarFileResource.java @@ -34,7 +34,7 @@ import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; /* ------------------------------------------------------------ */ -class JarFileResource extends JarResource +public class JarFileResource extends JarResource { private static final Logger LOG = Log.getLogger(JarFileResource.class); private JarFile _jarFile; From 5f34e0bce816ac6b865a670c597228c6ea71d305 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 28 Aug 2017 16:03:51 +1000 Subject: [PATCH 11/14] Issue #1520 --- .../org/eclipse/jetty/security/PropertyUserStoreTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jetty-security/src/test/java/org/eclipse/jetty/security/PropertyUserStoreTest.java b/jetty-security/src/test/java/org/eclipse/jetty/security/PropertyUserStoreTest.java index eea4fc560e3..84e8c764b75 100644 --- a/jetty-security/src/test/java/org/eclipse/jetty/security/PropertyUserStoreTest.java +++ b/jetty-security/src/test/java/org/eclipse/jetty/security/PropertyUserStoreTest.java @@ -169,7 +169,7 @@ public class PropertyUserStoreTest final File usersFile = initUsersText(); PropertyUserStore store = new PropertyUserStore(); - store.setConfigPath(usersFile); + store.setConfigFile(usersFile); store.registerUserListener(userCount); @@ -215,7 +215,7 @@ public class PropertyUserStoreTest PropertyUserStore store = new PropertyUserStore(); store.setHotReload(true); - store.setConfigPath(usersFile); + store.setConfigFile(usersFile); store.registerUserListener(userCount); @@ -246,7 +246,7 @@ public class PropertyUserStoreTest PropertyUserStore store = new PropertyUserStore(); store.setHotReload(true); - store.setConfigPath(usersFile); + store.setConfigFile(usersFile); store.registerUserListener(userCount); From ecad4125a431c46dd3718ecff76724eb7f8c0ccf Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 28 Aug 2017 16:17:31 +1000 Subject: [PATCH 12/14] Issue #1520 --- .../eclipse/jetty/util/PathWatcherTest.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/PathWatcherTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/PathWatcherTest.java index 5e05758366c..e9263a20f78 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/PathWatcherTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/PathWatcherTest.java @@ -46,7 +46,7 @@ import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; -@Ignore("Disabled due to behavioral differences in various FileSystems (hard to write a single testcase that works in all scenarios)") +// @Ignore("Disabled due to behavioral differences in various FileSystems (hard to write a single testcase that works in all scenarios)") public class PathWatcherTest { public static class PathWatchEventCapture implements PathWatcher.Listener @@ -81,6 +81,18 @@ public class PathWatcherTest { synchronized (events) { + Path relativePath = this.baseDir.relativize(event.getPath()); + String key = relativePath.toString().replace(File.separatorChar,'/'); + + List types = this.events.get(key); + if (types == null) + { + types = new ArrayList<>(); + } + types.add(event.getType()); + this.events.put(key,types); + LOG.debug("Captured Event: {} | {}",event.getType(),key); + //if triggered by path if (triggerPath != null) { @@ -95,19 +107,6 @@ public class PathWatcherTest { finishedLatch.countDown(); } - - - Path relativePath = this.baseDir.relativize(event.getPath()); - String key = relativePath.toString().replace(File.separatorChar,'/'); - - List types = this.events.get(key); - if (types == null) - { - types = new ArrayList<>(); - } - types.add(event.getType()); - this.events.put(key,types); - LOG.debug("Captured Event: {} | {}",event.getType(),key); } } From d0d9b7f8d7c80a121dea6c8a3404084a44b99368 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 28 Aug 2017 16:26:44 +1000 Subject: [PATCH 13/14] Revert "Issue #1520" This reverts commit ecad4125a431c46dd3718ecff76724eb7f8c0ccf. --- .../eclipse/jetty/util/PathWatcherTest.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/PathWatcherTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/PathWatcherTest.java index e9263a20f78..5e05758366c 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/PathWatcherTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/PathWatcherTest.java @@ -46,7 +46,7 @@ import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; -// @Ignore("Disabled due to behavioral differences in various FileSystems (hard to write a single testcase that works in all scenarios)") +@Ignore("Disabled due to behavioral differences in various FileSystems (hard to write a single testcase that works in all scenarios)") public class PathWatcherTest { public static class PathWatchEventCapture implements PathWatcher.Listener @@ -81,18 +81,6 @@ public class PathWatcherTest { synchronized (events) { - Path relativePath = this.baseDir.relativize(event.getPath()); - String key = relativePath.toString().replace(File.separatorChar,'/'); - - List types = this.events.get(key); - if (types == null) - { - types = new ArrayList<>(); - } - types.add(event.getType()); - this.events.put(key,types); - LOG.debug("Captured Event: {} | {}",event.getType(),key); - //if triggered by path if (triggerPath != null) { @@ -107,6 +95,19 @@ public class PathWatcherTest { finishedLatch.countDown(); } + + + Path relativePath = this.baseDir.relativize(event.getPath()); + String key = relativePath.toString().replace(File.separatorChar,'/'); + + List types = this.events.get(key); + if (types == null) + { + types = new ArrayList<>(); + } + types.add(event.getType()); + this.events.put(key,types); + LOG.debug("Captured Event: {} | {}",event.getType(),key); } } From 08a000b7a7461fe6449b1f55c083700132c5f412 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 28 Aug 2017 16:28:18 +1000 Subject: [PATCH 14/14] Issue #1520 wrong IO --- .../main/java/org/eclipse/jetty/security/PropertyUserStore.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jetty-security/src/main/java/org/eclipse/jetty/security/PropertyUserStore.java b/jetty-security/src/main/java/org/eclipse/jetty/security/PropertyUserStore.java index 4630ae6cfd9..ba795608f44 100644 --- a/jetty-security/src/main/java/org/eclipse/jetty/security/PropertyUserStore.java +++ b/jetty-security/src/main/java/org/eclipse/jetty/security/PropertyUserStore.java @@ -32,7 +32,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; -import org.eclipse.jetty.toolchain.test.IO; +import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.PathWatcher; import org.eclipse.jetty.util.PathWatcher.PathWatchEvent; import org.eclipse.jetty.util.StringUtil;