From 9e65d1ebcb7ae5ac709f9dd2443ad80967a866f0 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 26 Apr 2017 14:54:37 +0200 Subject: [PATCH] Issue #1505 * minor cleanups of ClasspathPattern * defined jetty.home.uri and jetty.base.uri in start.jar and webapp configuration properties * minor cleanup of start.jar property handling (more needed) * updated location classpathpatterns in modules --- .../jetty/deploy/DeploymentManager.java | 19 ++++++++++ .../bindings/GlobalWebappConfigBinding.java | 9 +---- .../deploy/providers/WebAppProvider.java | 7 +--- .../java/org/eclipse/jetty/start/Main.java | 15 +++++++- .../org/eclipse/jetty/start/StartArgs.java | 2 +- .../start/config/CommandLineConfigSource.java | 9 ++++- .../jetty/start/config/ConfigSources.java | 32 ++++++---------- .../jetty/start/ConfigurationAssert.java | 10 +++-- .../org/eclipse/jetty/start/MainTest.java | 14 ++++++- .../src/main/config/modules/log4j-impl.mod | 2 +- .../src/main/config/modules/log4j2-api.mod | 2 +- .../src/main/config/modules/logback-impl.mod | 2 +- .../src/main/config/modules/logging-jul.mod | 3 -- .../src/main/config/modules/logging-log4j.mod | 3 -- .../main/config/modules/logging-log4j2.mod | 3 -- .../main/config/modules/logging-logback.mod | 3 -- .../src/main/config/modules/logging-slf4j.mod | 3 -- .../src/main/config/modules/slf4j-api.mod | 1 + .../java/org/eclipse/jetty/util/TypeUtil.java | 13 ------- .../jetty/webapp/ClasspathPattern.java | 37 ++++++++++++------- .../jetty/webapp/ClasspathPatternTest.java | 35 +++++------------- 21 files changed, 111 insertions(+), 113 deletions(-) diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/DeploymentManager.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/DeploymentManager.java index d7963cef51f..704222cae91 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/DeploymentManager.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/DeploymentManager.java @@ -18,6 +18,7 @@ package org.eclipse.jetty.deploy; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -45,6 +46,8 @@ import org.eclipse.jetty.util.annotation.Name; 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.resource.Resource; +import org.eclipse.jetty.xml.XmlConfiguration; /** * The Deployment Manager. @@ -595,4 +598,20 @@ public class DeploymentManager extends ContainerLifeCycle { return getApps(_lifecycle.getNodeByName(nodeName)); } + + public void scope(XmlConfiguration xmlc, Resource webapp) + throws IOException + { + xmlc.getIdMap().put("Server", getServer()); + Resource home = Resource.newResource(System.getProperty("jetty.home",".")); + xmlc.getProperties().put("jetty.home",home.toString()); + xmlc.getProperties().put("jetty.home.uri",home.getURI().toString()); + + Resource base = Resource.newResource(System.getProperty("jetty.base",home.toString())); + xmlc.getProperties().put("jetty.base",base.toString()); + xmlc.getProperties().put("jetty.base.uri",base.getURI().toString()); + + xmlc.getProperties().put("jetty.webapp",webapp.toString()); + xmlc.getProperties().put("jetty.webapps",webapp.getFile().toPath().getParent().toString()); + } } diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBinding.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBinding.java index 5a50e2719a7..3c9df4df9f0 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBinding.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBinding.java @@ -93,15 +93,8 @@ public class GlobalWebappConfigBinding implements AppLifeCycle.Binding if (globalContextSettings.exists()) { XmlConfiguration jettyXmlConfig = new XmlConfiguration(globalContextSettings.getInputStream()); - Resource resource = Resource.newResource(app.getOriginId()); - File file = resource.getFile(); - jettyXmlConfig.getIdMap().put("Server",app.getDeploymentManager().getServer()); - jettyXmlConfig.getProperties().put("jetty.home",System.getProperty("jetty.home",".")); - jettyXmlConfig.getProperties().put("jetty.base",System.getProperty("jetty.base",".")); - jettyXmlConfig.getProperties().put("jetty.webapp",file.getCanonicalPath()); - jettyXmlConfig.getProperties().put("jetty.webapps",file.getParentFile().getCanonicalPath()); - + app.getDeploymentManager().scope(jettyXmlConfig,resource); jettyXmlConfig.configure(context); } else diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java index b076eff26b7..94e41b2d99a 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java @@ -294,11 +294,7 @@ public class WebAppProvider extends ScanningAppProvider } }; - xmlc.getIdMap().put("Server", getDeploymentManager().getServer()); - xmlc.getProperties().put("jetty.home",System.getProperty("jetty.home",".")); - xmlc.getProperties().put("jetty.base",System.getProperty("jetty.base",".")); - xmlc.getProperties().put("jetty.webapp",file.getCanonicalPath()); - xmlc.getProperties().put("jetty.webapps",file.getParentFile().getCanonicalPath()); + getDeploymentManager().scope(xmlc,resource); if (getConfigurationManager() != null) xmlc.getProperties().putAll(getConfigurationManager().getProperties()); @@ -354,7 +350,6 @@ public class WebAppProvider extends ScanningAppProvider return webAppContext; } - /* ------------------------------------------------------------ */ @Override protected void fileChanged(String filename) throws Exception diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index 863c4486ed2..b0fc5713c13 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -18,7 +18,6 @@ package org.eclipse.jetty.start; -import static org.eclipse.jetty.start.UsageException.ERR_BAD_GRAPH; import static org.eclipse.jetty.start.UsageException.ERR_BAD_STOP_PROPS; import static org.eclipse.jetty.start.UsageException.ERR_INVOKE_MAIN; import static org.eclipse.jetty.start.UsageException.ERR_NOT_STOPPED; @@ -295,6 +294,20 @@ public class Main StartArgs args = new StartArgs(baseHome); args.parse(baseHome.getConfigSources()); + Props props = baseHome.getConfigSources().getProps(); + Props.Prop home = props.getProp(BaseHome.JETTY_HOME); + if (!args.getProperties().containsKey(BaseHome.JETTY_HOME)) + args.getProperties().setProperty(home); + args.getProperties().setProperty(BaseHome.JETTY_HOME+".uri", + baseHome.getHomePath().toUri().toString(), + home.origin); + Props.Prop base = props.getProp(BaseHome.JETTY_BASE); + if (!args.getProperties().containsKey(BaseHome.JETTY_BASE)) + args.getProperties().setProperty(base); + args.getProperties().setProperty(BaseHome.JETTY_BASE+".uri", + baseHome.getBasePath().toUri().toString(), + base.origin); + // ------------------------------------------------------------ // 3) Module Registration Modules modules = new Modules(baseHome,args); diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java index 2073fd30eda..7b7ae07d627 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java @@ -120,7 +120,7 @@ public class StartArgs private Set skipFileValidationModules = new HashSet<>(); /** Map of enabled modules to the source of where that activation occurred */ - private Map> sources = new HashMap<>(); + Map> sources = new HashMap<>(); /** Map of properties to where that property was declared */ private Map propertySource = new HashMap<>(); diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/config/CommandLineConfigSource.java b/jetty-start/src/main/java/org/eclipse/jetty/start/config/CommandLineConfigSource.java index c581c414e43..d1facfe391c 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/config/CommandLineConfigSource.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/config/CommandLineConfigSource.java @@ -41,6 +41,7 @@ public class CommandLineConfigSource implements ConfigSource { public static final String ORIGIN_INTERNAL_FALLBACK = ""; public static final String ORIGIN_CMD_LINE = ""; + public static final String ORIGIN_SYSTEM_PROPERTY = ""; private final RawArgs args; private final Props props; @@ -79,6 +80,7 @@ public class CommandLineConfigSource implements ConfigSource String val = System.getProperty(BaseHome.JETTY_BASE); if (!Utils.isBlank(val)) { + setProperty(BaseHome.JETTY_BASE,val,ORIGIN_SYSTEM_PROPERTY); return FS.toPath(val); } @@ -101,6 +103,7 @@ public class CommandLineConfigSource implements ConfigSource String val = System.getProperty(BaseHome.JETTY_HOME); if (!Utils.isBlank(val)) { + setProperty(BaseHome.JETTY_HOME,val,ORIGIN_SYSTEM_PROPERTY); return FS.toPath(val); } @@ -116,7 +119,9 @@ public class CommandLineConfigSource implements ConfigSource // ${jetty.home} is relative to found BaseHome class try { - return new File(new URI(m.group(1))).getParentFile().toPath(); + Path home = new File(new URI(m.group(1))).getParentFile().toPath(); + setProperty(BaseHome.JETTY_HOME,home.toString(),ORIGIN_INTERNAL_FALLBACK); + return home; } catch (URISyntaxException e) { @@ -127,7 +132,7 @@ public class CommandLineConfigSource implements ConfigSource // Lastly, fall back to ${user.dir} default Path home = FS.toPath(System.getProperty("user.dir",".")); - setProperty(BaseHome.JETTY_HOME,home.toString(),ORIGIN_INTERNAL_FALLBACK); + setProperty(BaseHome.JETTY_HOME,home.toString(),""); return home; } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/config/ConfigSources.java b/jetty-start/src/main/java/org/eclipse/jetty/start/config/ConfigSources.java index 252e9184a93..249f5c97976 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/config/ConfigSources.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/config/ConfigSources.java @@ -50,7 +50,6 @@ public class ConfigSources implements Iterable } private LinkedList sources = new LinkedList<>(); - private Props props = new Props(); private AtomicInteger sourceWeight = new AtomicInteger(1); public void add(ConfigSource source) throws IOException @@ -61,18 +60,15 @@ public class ConfigSources implements Iterable throw new UsageException(ERR_BAD_ARG,"Duplicate Configuration Source Reference: " + source); } sources.add(source); - Collections.sort(sources,new WeightedConfigSourceComparator()); - updateProps(); - // look for --include-jetty-dir entries for (RawArgs.Entry arg : source.getArgs()) { if (arg.startsWith("--include-jetty-dir")) { String ref = getValue(arg.getLine()); - String dirName = props.expand(ref); + String dirName = getProps().expand(ref); Path dir = FS.toPath(dirName).normalize().toAbsolutePath(); DirConfigSource dirsource = new DirConfigSource(ref,dir,sourceWeight.incrementAndGet(),true); add(dirsource); @@ -94,11 +90,20 @@ public class ConfigSources implements Iterable public Prop getProp(String key) { - return props.getProp(key); + return getProps().getProp(key); } - + public Props getProps() { + Props props = new Props(); + + // add all properties from config sources (in reverse order) + ListIterator iter = sources.listIterator(sources.size()); + while (iter.hasPrevious()) + { + ConfigSource source = iter.previous(); + props.addAll(source.getProps()); + } return props; } @@ -147,17 +152,4 @@ public class ConfigSources implements Iterable str.append(']'); return str.toString(); } - - private void updateProps() - { - props.reset(); - - // add all properties from config sources (in reverse order) - ListIterator iter = sources.listIterator(sources.size()); - while (iter.hasPrevious()) - { - ConfigSource source = iter.previous(); - props.addAll(source.getProps()); - } - } } diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java b/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java index 58d9e114f57..70b4da00e95 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java @@ -137,9 +137,13 @@ public class ConfigurationAssert for (Prop prop : args.getProperties()) { String name = prop.key; - if ("jetty.home".equals(name) || "jetty.base".equals(name) || - "user.dir".equals(name) || prop.origin.equals(Props.ORIGIN_SYSPROP) || - name.startsWith("java.")) + if ("jetty.home".equals(name) || + "jetty.base".equals(name) || + "jetty.home.uri".equals(name) || + "jetty.base.uri".equals(name) || + "user.dir".equals(name) || + prop.origin.equals(Props.ORIGIN_SYSPROP) || + name.startsWith("java.")) { // strip these out from assertion, to make assertions easier. continue; diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java index 58c9a091266..3b60f7d4cfe 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java @@ -60,9 +60,19 @@ public class MainTest Main main = new Main(); StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[cmdLineArgs.size()])); BaseHome baseHome = main.getBaseHome(); - System.err.println(args); + // System.err.println(args); ConfigurationAssert.assertConfiguration(baseHome,args,"assert-home.txt"); + + // System.err.println("StartArgs.props:"); + // args.getProperties().forEach(p->System.err.println(p)); + // System.err.println("BaseHome.props:"); + // baseHome.getConfigSources().getProps().forEach(p->System.err.println(p)); + + assertThat(args.getProperties().getString("jetty.home"),is(baseHome.getHome())); + assertThat(args.getProperties().getString("jetty.home.uri"),is(baseHome.getHomePath().toUri().toString())); + assertThat(args.getProperties().getString("jetty.base"),is(baseHome.getBase())); + assertThat(args.getProperties().getString("jetty.base.uri"),is(baseHome.getBasePath().toUri().toString())); } @Test @@ -76,7 +86,7 @@ public class MainTest Main main = new Main(); StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[cmdLineArgs.size()])); - System.err.println(args); + // System.err.println(args); // Assert.assertEquals("--stop should not build module tree", 0, args.getEnabledModules().size()); assertEquals("--stop missing port","10000",args.getProperties().getString("STOP.PORT")); diff --git a/jetty-util/src/main/config/modules/log4j-impl.mod b/jetty-util/src/main/config/modules/log4j-impl.mod index 5aaaa62cc21..dcc8fa52613 100644 --- a/jetty-util/src/main/config/modules/log4j-impl.mod +++ b/jetty-util/src/main/config/modules/log4j-impl.mod @@ -27,4 +27,4 @@ http://www.apache.org/licenses/LICENSE-2.0.html [ini] log4j.version?=1.2.17 - +jetty.webapp.addServerClasses+=,${jetty.base.uri}/lib/log4j/ diff --git a/jetty-util/src/main/config/modules/log4j2-api.mod b/jetty-util/src/main/config/modules/log4j2-api.mod index 123427e7d6c..da7a609b047 100644 --- a/jetty-util/src/main/config/modules/log4j2-api.mod +++ b/jetty-util/src/main/config/modules/log4j2-api.mod @@ -22,4 +22,4 @@ http://www.apache.org/licenses/LICENSE-2.0.html [ini] log4j2.version?=2.6.1 - +jetty.webapp.addServerClasses+=,${jetty.base.uri}/lib/log4j2/ diff --git a/jetty-util/src/main/config/modules/logback-impl.mod b/jetty-util/src/main/config/modules/logback-impl.mod index a9364601720..e001ca0a76e 100644 --- a/jetty-util/src/main/config/modules/logback-impl.mod +++ b/jetty-util/src/main/config/modules/logback-impl.mod @@ -35,4 +35,4 @@ or (per the licensee's choosing) under [ini] logback.version?=1.1.7 - +jetty.webapp.addServerClasses+=,${jetty.base.uri}/lib/logback/ diff --git a/jetty-util/src/main/config/modules/logging-jul.mod b/jetty-util/src/main/config/modules/logging-jul.mod index 17391fd1a02..a2dbe05e804 100644 --- a/jetty-util/src/main/config/modules/logging-jul.mod +++ b/jetty-util/src/main/config/modules/logging-jul.mod @@ -14,6 +14,3 @@ logging [exec] -Dorg.eclipse.jetty.util.log.class?=org.eclipse.jetty.util.log.Slf4jLog - -[ini] -jetty.webapp.addServerClasses+=,${jetty.base.uri}/lib/slf4j/ diff --git a/jetty-util/src/main/config/modules/logging-log4j.mod b/jetty-util/src/main/config/modules/logging-log4j.mod index 55d68bc2243..a19d24aaeab 100644 --- a/jetty-util/src/main/config/modules/logging-log4j.mod +++ b/jetty-util/src/main/config/modules/logging-log4j.mod @@ -14,6 +14,3 @@ logging [exec] -Dorg.eclipse.jetty.util.log.class?=org.eclipse.jetty.util.log.Slf4jLog - -[ini] -jetty.webapp.addServerClasses+=,${jetty.base.uri}/lib/slf4j/,${jetty.base.uri}/lib/log4j/ diff --git a/jetty-util/src/main/config/modules/logging-log4j2.mod b/jetty-util/src/main/config/modules/logging-log4j2.mod index 5c68f013479..f946abef861 100644 --- a/jetty-util/src/main/config/modules/logging-log4j2.mod +++ b/jetty-util/src/main/config/modules/logging-log4j2.mod @@ -14,6 +14,3 @@ logging [exec] -Dorg.eclipse.jetty.util.log.class?=org.eclipse.jetty.util.log.Slf4jLog - -[ini] -jetty.webapp.addServerClasses+=,${jetty.base.uri}/lib/slf4j/,${jetty.base.uri}/lib/log4j2/ diff --git a/jetty-util/src/main/config/modules/logging-logback.mod b/jetty-util/src/main/config/modules/logging-logback.mod index 6fc453669ef..b5c72046981 100644 --- a/jetty-util/src/main/config/modules/logging-logback.mod +++ b/jetty-util/src/main/config/modules/logging-logback.mod @@ -14,6 +14,3 @@ logging [exec] -Dorg.eclipse.jetty.util.log.class?=org.eclipse.jetty.util.log.Slf4jLog - -[ini] -jetty.webapp.addServerClasses+=,${jetty.base.uri}/lib/slf4j/,${jetty.base.uri}/lib/logback/ diff --git a/jetty-util/src/main/config/modules/logging-slf4j.mod b/jetty-util/src/main/config/modules/logging-slf4j.mod index 5dde76f6e37..a9174b86ddc 100644 --- a/jetty-util/src/main/config/modules/logging-slf4j.mod +++ b/jetty-util/src/main/config/modules/logging-slf4j.mod @@ -14,6 +14,3 @@ logging [exec] -Dorg.eclipse.jetty.util.log.class?=org.eclipse.jetty.util.log.Slf4jLog - -[ini] -jetty.webapp.addServerClasses+=,${jetty.base.uri}/lib/slf4j/ diff --git a/jetty-util/src/main/config/modules/slf4j-api.mod b/jetty-util/src/main/config/modules/slf4j-api.mod index 6fb36bd9407..12054fc5e14 100644 --- a/jetty-util/src/main/config/modules/slf4j-api.mod +++ b/jetty-util/src/main/config/modules/slf4j-api.mod @@ -15,6 +15,7 @@ lib/slf4j/slf4j-api-${slf4j.version}.jar [ini] slf4j.version?=1.7.21 +jetty.webapp.addServerClasses+=,${jetty.base.uri}/lib/slf4j/ [license] SLF4J is distributed under the MIT License. diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java index f04f7a92c8f..cbaeef9085c 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java @@ -732,17 +732,4 @@ public class TypeUtil } return null; } - - /* ------------------------------------------------------------ */ - public static File getLocationOfClassAsFile(Class clazz) - { - URI uri = getLocationOfClass(clazz); - - if (uri != null && "file".equalsIgnoreCase(uri.getScheme())) - { - return new File(uri); - } - return null; - } - } 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 cb4bec47e30..9c224ef9ff0 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 @@ -23,6 +23,7 @@ import java.io.File; import java.net.URI; import java.net.URL; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.AbstractSet; import java.util.ArrayList; import java.util.Arrays; @@ -47,12 +48,14 @@ import org.eclipse.jetty.util.resource.Resource; * A class pattern is a string of one of the forms:
    *
  • 'org.package.SomeClass' will match a specific class *
  • 'org.package.' will match a specific package hierarchy - *
  • '-org.package.Classname' excludes a specific class - *
  • '-org.package.' excludes a specific package hierarchy - *
  • Nested classes must be specified with the '$' separator if they - * are to be explicitly included or excluded (eg. org.example.MyClass$NestedClass). - *
  • Nested classes are matched by their containing class. (eg. -org.example.MyClass - * would exclude org.example.MyClass$AnyNestedClass) + *
  • 'org.package.SomeClass$NestedClass ' will match a nested class exactly otherwise. + * Nested classes are matched by their containing class. (eg. org.example.MyClass + * matches org.example.MyClass$AnyNestedClass) + *
  • 'file:///some/location/' - A file system directory from which + * the class was loaded + *
  • 'file:///some/location.jar' - The URI of a jar file from which + * the class was loaded + *
  • Any of the above patterns preceeded by '-' will exclude rather than include the match. *
* When class is initialized from a classpath pattern string, entries * in this string should be separated by ':' (semicolon) or ',' (comma). @@ -76,7 +79,7 @@ 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); + _type = _name.startsWith("file:")?Type.LOCATION:(_name.endsWith(".")?Type.PACKAGE:Type.CLASSNAME); } Entry(String name, boolean include) @@ -84,7 +87,7 @@ 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); + _type = _name.startsWith("file:")?Type.LOCATION:(_name.endsWith(".")?Type.PACKAGE:Type.CLASSNAME); } @@ -315,12 +318,16 @@ public class ClasspathPattern extends AbstractSet if (file.isDirectory()) { if (path.startsWith(file.toPath())) + { return true; - } + } + } else { if (path.equals(file.toPath())) + { return true; + } } } @@ -328,7 +335,6 @@ public class ClasspathPattern extends AbstractSet } } - Map _entries = new HashMap<>(); IncludeExcludeSet _patterns = new IncludeExcludeSet<>(ByPackageOrName.class); IncludeExcludeSet _locations = new IncludeExcludeSet<>(ByLocation.class); @@ -518,10 +524,13 @@ public class ClasspathPattern extends AbstractSet Boolean byName = _patterns.isIncludedAndNotExcluded(clazz.getName()); if (Boolean.FALSE.equals(byName)) return byName; // Already excluded so no need to check location. - File locationFile = TypeUtil.getLocationOfClassAsFile(clazz); - Boolean byLocation = locationFile == null ? null - : _locations.isIncludedAndNotExcluded(locationFile.toPath()); - + URI location = TypeUtil.getLocationOfClass(clazz); + Boolean byLocation = location == null ? null + : _locations.isIncludedAndNotExcluded(Paths.get(location)); + + if (LOG.isDebugEnabled()) + LOG.debug("match {} from {} byName={} byLocation={} in {}",clazz,location,byName,byLocation,this); + // Combine the tri-state match of both IncludeExclude Sets boolean included = byName==Boolean.TRUE || byLocation==Boolean.TRUE || (byName==null && !_patterns.hasIncludes() && byLocation==null && !_locations.hasIncludes()); 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 fa4718e930c..1298a3578d0 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 @@ -18,7 +18,8 @@ package org.eclipse.jetty.webapp; -import java.io.File; +import java.net.URI; +import java.nio.file.Paths; import java.util.Arrays; import org.eclipse.jetty.toolchain.test.JDK; @@ -119,23 +120,15 @@ public class ClasspathPatternTest Assume.assumeFalse(JDK.IS_9); // jar from JVM classloader - File loc_string = TypeUtil.getLocationOfClassAsFile(String.class); + URI loc_string = TypeUtil.getLocationOfClass(String.class); // System.err.println(loc_string); - // another jar from JVM classloader - File loc_jsse = TypeUtil.getLocationOfClassAsFile(Sun.class); - // System.err.println(loc_jsse); - // a jar from maven repo jar - File loc_junit = TypeUtil.getLocationOfClassAsFile(Test.class); + URI loc_junit = TypeUtil.getLocationOfClass(Test.class); // System.err.println(loc_junit); - // a jar from another maven repo jar - File loc_tool = TypeUtil.getLocationOfClassAsFile(JDK.class); - // System.err.println(loc_tool); - // class file - File loc_test = TypeUtil.getLocationOfClassAsFile(ClasspathPatternTest.class); + URI loc_test = TypeUtil.getLocationOfClass(ClasspathPatternTest.class); // System.err.println(loc_test); ClasspathPattern pattern = new ClasspathPattern(); @@ -147,7 +140,7 @@ public class ClasspathPatternTest Assert.assertThat(pattern.match(ClasspathPatternTest.class), Matchers.is(false)); // Add directory for both JVM classes - pattern.include(loc_string.getParentFile().toURI().toString()); + pattern.include(Paths.get(loc_string).getParent().toUri().toString()); // Add jar for individual class and classes directory pattern.include(loc_junit.toString(), loc_test.toString()); @@ -174,23 +167,15 @@ public class ClasspathPatternTest Assume.assumeFalse(JDK.IS_9); // jar from JVM classloader - File loc_string = TypeUtil.getLocationOfClassAsFile(String.class); + URI loc_string = TypeUtil.getLocationOfClass(String.class); // System.err.println(loc_string); - // another jar from JVM classloader - File loc_jsse = TypeUtil.getLocationOfClassAsFile(Sun.class); - // System.err.println(loc_jsse); - // a jar from maven repo jar - File loc_junit = TypeUtil.getLocationOfClassAsFile(Test.class); + URI loc_junit = TypeUtil.getLocationOfClass(Test.class); // System.err.println(loc_junit); - // a jar from another maven repo jar - File loc_tool = TypeUtil.getLocationOfClassAsFile(JDK.class); - // System.err.println(loc_tool); - // class file - File loc_test = TypeUtil.getLocationOfClassAsFile(ClasspathPatternTest.class); + URI loc_test = TypeUtil.getLocationOfClass(ClasspathPatternTest.class); // System.err.println(loc_test); ClasspathPattern pattern = new ClasspathPattern(); @@ -205,7 +190,7 @@ public class ClasspathPatternTest Assert.assertThat(pattern.match(ClasspathPatternTest.class), Matchers.is(true)); // Add directory for both JVM classes - pattern.exclude(loc_string.getParentFile().toURI().toString()); + pattern.exclude(Paths.get(loc_string).getParent().toUri().toString()); // Add jar for individual class and classes directory pattern.exclude(loc_junit.toString(), loc_test.toString());