diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java index 72ec1ceee18..c55a73133e4 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java @@ -189,12 +189,12 @@ public class PathResource extends Resource * @param uri the URI to build this PathResource from. * @throws IOException if unable to construct the PathResource from the URI. */ - PathResource(URI uri) throws IOException + PathResource(URI uri) { this(uri, false); } - PathResource(URI uri, boolean bypassAllowedSchemeCheck) throws IOException + PathResource(URI uri, boolean bypassAllowedSchemeCheck) { if (!uri.isAbsolute()) throw new IllegalArgumentException("not an absolute uri: " + uri); @@ -214,11 +214,6 @@ public class PathResource extends Resource { throw new IllegalStateException("No FileSystem mounted for : " + uri, e); } - catch (Exception e) - { - LOG.trace("IGNORED", e); - throw new IOException("Unable to build Path from: " + uri, e); - } } @Override diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java index 3d8d1d03002..f41f248c33c 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java @@ -272,9 +272,8 @@ public abstract class Resource implements ResourceFactory * * @param resource A URL or filename. * @return A Resource object. - * @throws IOException Problem accessing URI */ - public static Resource newResource(String resource) throws IOException + public static Resource newResource(String resource) { return newResource(toURI(resource)); } @@ -331,9 +330,8 @@ public abstract class Resource implements ResourceFactory * * @param resource Resource as string representation * @return The new Resource - * @throws IOException Problem accessing resource. */ - public static Resource newSystemResource(String resource) throws IOException + public static Resource newSystemResource(String resource) { return newSystemResource(resource, null); } @@ -346,9 +344,8 @@ public abstract class Resource implements ResourceFactory * @param resource Resource as string representation * @param mountConsumer a consumer that receives the mount in case the resource needs mounting * @return The new Resource - * @throws IOException Problem accessing resource. */ - public static Resource newSystemResource(String resource, Consumer mountConsumer) throws IOException + public static Resource newSystemResource(String resource, Consumer mountConsumer) { URL url = null; // Try to format as a URL? @@ -436,9 +433,8 @@ public abstract class Resource implements ResourceFactory * @param r the contained resource * @param containingResource the containing resource * @return true if the Resource is contained, false otherwise - * @throws IOException Problem accessing resource */ - public static boolean isContainedIn(Resource r, Resource containingResource) throws IOException + public static boolean isContainedIn(Resource r, Resource containingResource) { return r.isContainedIn(containingResource); } @@ -456,9 +452,8 @@ public abstract class Resource implements ResourceFactory * * @param r the containing resource * @return true if this Resource is contained, false otherwise - * @throws IOException Problem accessing resource */ - public abstract boolean isContainedIn(Resource r) throws IOException; + public abstract boolean isContainedIn(Resource r); /** * Return true if the passed Resource represents the same resource as the Resource. @@ -742,9 +737,8 @@ public abstract class Resource implements ResourceFactory * @param parent True if the parent directory should be included * @param query query params * @return String of HTML - * @throws IOException on failure to generate a list. */ - public String getListHTML(String base, boolean parent, String query) throws IOException // TODO: move to helper class + public String getListHTML(String base, boolean parent, String query) // TODO: move to helper class { // This method doesn't check aliases, so it is OK to canonicalize here. base = URIUtil.normalizePath(base); diff --git a/jetty-ee10/jetty-ee10-annotations/src/main/java/org/eclipse/jetty/ee10/annotations/AnnotationIntrospector.java b/jetty-ee10/jetty-ee10-annotations/src/main/java/org/eclipse/jetty/ee10/annotations/AnnotationIntrospector.java index a02ad55647f..554226a5e57 100644 --- a/jetty-ee10/jetty-ee10-annotations/src/main/java/org/eclipse/jetty/ee10/annotations/AnnotationIntrospector.java +++ b/jetty-ee10/jetty-ee10-annotations/src/main/java/org/eclipse/jetty/ee10/annotations/AnnotationIntrospector.java @@ -13,7 +13,6 @@ package org.eclipse.jetty.ee10.annotations; -import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -170,15 +169,7 @@ public class AnnotationIntrospector String descriptorLocation = holder.getSource().getResource(); if (descriptorLocation == null) return true; //no descriptor, can't be metadata-complete - try - { - return !WebDescriptor.isMetaDataComplete(_context.getMetaData().getFragmentDescriptor(Resource.newResource(descriptorLocation))); - } - catch (IOException e) - { - LOG.warn("Unable to get Resource for descriptor {}", descriptorLocation, e); - return false; //something wrong with the descriptor - } + return !WebDescriptor.isMetaDataComplete(_context.getMetaData().getFragmentDescriptor(Resource.newResource(descriptorLocation))); } } } diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyHomeForker.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyHomeForker.java index 1dda799b333..b2d059330b8 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyHomeForker.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyHomeForker.java @@ -415,7 +415,7 @@ public class JettyHomeForker extends AbstractForker try (Resource.Mount mount = Resource.mountJar(jettyHomeZip.toPath())) { Resource res = mount.root(); - res.copyTo(baseDir.toPath()); + res.copyTo(baseDir.toPath()); // TODO: Resource.copyTo() cannot copy dir to dir, only file to file } //zip will unpack to target/jetty-home- jettyHome = new File(baseDir, "jetty-home-" + version); diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenWebAppContext.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenWebAppContext.java index 10fdecf4908..1988d719a89 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenWebAppContext.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenWebAppContext.java @@ -14,7 +14,6 @@ package org.eclipse.jetty.ee10.maven.plugin; import java.io.File; -import java.io.IOException; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URI; @@ -322,18 +321,11 @@ public class MavenWebAppContext extends WebAppContext Configurations configurations = super.newConfigurations(); if (getJettyEnvXml() != null) { - try + // inject configurations with config from maven plugin + for (Configuration c : configurations) { - // inject configurations with config from maven plugin - for (Configuration c : configurations) - { - if (c instanceof EnvConfiguration) - ((EnvConfiguration)c).setJettyEnvResource(Resource.newResource(getJettyEnvXml())); - } - } - catch (IOException e) - { - throw new RuntimeException(e); + if (c instanceof EnvConfiguration) + ((EnvConfiguration)c).setJettyEnvResource(Resource.newResource(getJettyEnvXml())); } } @@ -390,62 +382,51 @@ public class MavenWebAppContext extends WebAppContext if (uri == null) return null; - try + // Replace /WEB-INF/classes with candidates for the classpath + if (uri.startsWith(WEB_INF_CLASSES_PREFIX)) { - // Replace /WEB-INF/classes with candidates for the classpath - if (uri.startsWith(WEB_INF_CLASSES_PREFIX)) + if (uri.equalsIgnoreCase(WEB_INF_CLASSES_PREFIX) || uri.equalsIgnoreCase(WEB_INF_CLASSES_PREFIX + "/")) { - if (uri.equalsIgnoreCase(WEB_INF_CLASSES_PREFIX) || uri.equalsIgnoreCase(WEB_INF_CLASSES_PREFIX + "/")) + // exact match for a WEB-INF/classes, so preferentially + // return the resource matching the web-inf classes + // rather than the test classes + if (_classes != null) + return Resource.newResource(_classes.toPath()); + else if (_testClasses != null) + return Resource.newResource(_testClasses.toPath()); + } + else + { + // try matching + Resource res = null; + int i = 0; + while (res == null && (i < _webInfClasses.size())) { - // exact match for a WEB-INF/classes, so preferentially - // return the resource matching the web-inf classes - // rather than the test classes - if (_classes != null) - return Resource.newResource(_classes.toPath()); - else if (_testClasses != null) - return Resource.newResource(_testClasses.toPath()); - } - else - { - // try matching - Resource res = null; - int i = 0; - while (res == null && (i < _webInfClasses.size())) + String newPath = StringUtil.replace(uri, WEB_INF_CLASSES_PREFIX, _webInfClasses.get(i).getPath()); + res = Resource.newResource(newPath); + if (!res.exists()) { - String newPath = StringUtil.replace(uri, WEB_INF_CLASSES_PREFIX, _webInfClasses.get(i).getPath()); - res = Resource.newResource(newPath); - if (!res.exists()) - { - res = null; - i++; - } + res = null; + i++; } - return res; } + return res; } - else if (uri.startsWith(WEB_INF_LIB_PREFIX)) - { - // Return the real jar file for all accesses to - // /WEB-INF/lib/*.jar - String jarName = StringUtil.strip(uri, WEB_INF_LIB_PREFIX); - if (jarName.startsWith("/") || jarName.startsWith("\\")) - jarName = jarName.substring(1); - if (jarName.length() == 0) - return null; - File jarFile = _webInfJarMap.get(jarName); - if (jarFile != null) - return Resource.newResource(jarFile.getPath()); - + } + else if (uri.startsWith(WEB_INF_LIB_PREFIX)) + { + // Return the real jar file for all accesses to + // /WEB-INF/lib/*.jar + String jarName = StringUtil.strip(uri, WEB_INF_LIB_PREFIX); + if (jarName.startsWith("/") || jarName.startsWith("\\")) + jarName = jarName.substring(1); + if (jarName.length() == 0) return null; - } - } - catch (MalformedURLException e) - { - throw e; - } - catch (IOException e) - { - LOG.trace("IGNORED", e); + File jarFile = _webInfJarMap.get(jarName); + if (jarFile != null) + return Resource.newResource(jarFile.getPath()); + + return null; } } return resource; diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/SelectiveJarResource.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/SelectiveJarResource.java index 6021f1918fd..d2da30ca562 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/SelectiveJarResource.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/SelectiveJarResource.java @@ -111,7 +111,7 @@ public class SelectiveJarResource extends Resource } @Override - public boolean isContainedIn(Resource r) throws IOException + public boolean isContainedIn(Resource r) { return _delegate.isContainedIn(r); } diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/ClassMatcher.java b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/ClassMatcher.java index 98f40c042a4..8ac992c9680 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/ClassMatcher.java +++ b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/ClassMatcher.java @@ -13,8 +13,6 @@ package org.eclipse.jetty.ee10.webapp; -import java.io.IOException; -import java.io.UncheckedIOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -135,14 +133,7 @@ public class ClassMatcher extends AbstractSet super(name, inclusive); if (!getName().startsWith("file:")) throw new IllegalArgumentException(name); - try - { - _path = Resource.newResource(getName()).getPath(); - } - catch (IOException e) - { - throw new UncheckedIOException(e); - } + _path = Resource.newResource(getName()).getPath(); } public Path getPath() diff --git a/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/OrderingTest.java b/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/OrderingTest.java index 724231797f7..e194c5859df 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/OrderingTest.java +++ b/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/OrderingTest.java @@ -15,7 +15,6 @@ package org.eclipse.jetty.ee10.webapp; import java.io.IOException; import java.io.InputStream; -import java.net.MalformedURLException; import java.net.URI; import java.nio.channels.ReadableByteChannel; import java.nio.file.Path; @@ -95,7 +94,7 @@ public class OrderingTest } @Override - public boolean isContainedIn(Resource r) throws MalformedURLException + public boolean isContainedIn(Resource r) { return false; } diff --git a/jetty-ee9/jetty-ee9-annotations/src/main/java/org/eclipse/jetty/ee9/annotations/AnnotationIntrospector.java b/jetty-ee9/jetty-ee9-annotations/src/main/java/org/eclipse/jetty/ee9/annotations/AnnotationIntrospector.java index fb6a82cb693..ce611f5c8ea 100644 --- a/jetty-ee9/jetty-ee9-annotations/src/main/java/org/eclipse/jetty/ee9/annotations/AnnotationIntrospector.java +++ b/jetty-ee9/jetty-ee9-annotations/src/main/java/org/eclipse/jetty/ee9/annotations/AnnotationIntrospector.java @@ -13,7 +13,6 @@ package org.eclipse.jetty.ee9.annotations; -import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -170,15 +169,7 @@ public class AnnotationIntrospector String descriptorLocation = holder.getSource().getResource(); if (descriptorLocation == null) return true; //no descriptor, can't be metadata-complete - try - { - return !WebDescriptor.isMetaDataComplete(_context.getMetaData().getFragmentDescriptor(Resource.newResource(descriptorLocation))); - } - catch (IOException e) - { - LOG.warn("Unable to get Resource for descriptor {}", descriptorLocation, e); - return false; //something wrong with the descriptor - } + return !WebDescriptor.isMetaDataComplete(_context.getMetaData().getFragmentDescriptor(Resource.newResource(descriptorLocation))); } } } diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenWebAppContext.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenWebAppContext.java index 06009a6fdb6..8c209f804b4 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenWebAppContext.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenWebAppContext.java @@ -322,18 +322,11 @@ public class MavenWebAppContext extends WebAppContext Configurations configurations = super.newConfigurations(); if (getJettyEnvXml() != null) { - try + // inject configurations with config from maven plugin + for (Configuration c : configurations) { - // inject configurations with config from maven plugin - for (Configuration c : configurations) - { - if (c instanceof EnvConfiguration) - ((EnvConfiguration)c).setJettyEnvResource(Resource.newResource(getJettyEnvXml())); - } - } - catch (IOException e) - { - throw new RuntimeException(e); + if (c instanceof EnvConfiguration) + ((EnvConfiguration)c).setJettyEnvResource(Resource.newResource(getJettyEnvXml())); } } @@ -390,62 +383,51 @@ public class MavenWebAppContext extends WebAppContext if (uri == null) return null; - try + // Replace /WEB-INF/classes with candidates for the classpath + if (uri.startsWith(WEB_INF_CLASSES_PREFIX)) { - // Replace /WEB-INF/classes with candidates for the classpath - if (uri.startsWith(WEB_INF_CLASSES_PREFIX)) + if (uri.equalsIgnoreCase(WEB_INF_CLASSES_PREFIX) || uri.equalsIgnoreCase(WEB_INF_CLASSES_PREFIX + "/")) { - if (uri.equalsIgnoreCase(WEB_INF_CLASSES_PREFIX) || uri.equalsIgnoreCase(WEB_INF_CLASSES_PREFIX + "/")) + // exact match for a WEB-INF/classes, so preferentially + // return the resource matching the web-inf classes + // rather than the test classes + if (_classes != null) + return Resource.newResource(_classes.toPath()); + else if (_testClasses != null) + return Resource.newResource(_testClasses.toPath()); + } + else + { + // try matching + Resource res = null; + int i = 0; + while (res == null && (i < _webInfClasses.size())) { - // exact match for a WEB-INF/classes, so preferentially - // return the resource matching the web-inf classes - // rather than the test classes - if (_classes != null) - return Resource.newResource(_classes.toPath()); - else if (_testClasses != null) - return Resource.newResource(_testClasses.toPath()); - } - else - { - // try matching - Resource res = null; - int i = 0; - while (res == null && (i < _webInfClasses.size())) + String newPath = StringUtil.replace(uri, WEB_INF_CLASSES_PREFIX, _webInfClasses.get(i).getPath()); + res = Resource.newResource(newPath); + if (!res.exists()) { - String newPath = StringUtil.replace(uri, WEB_INF_CLASSES_PREFIX, _webInfClasses.get(i).getPath()); - res = Resource.newResource(newPath); - if (!res.exists()) - { - res = null; - i++; - } + res = null; + i++; } - return res; } + return res; } - else if (uri.startsWith(WEB_INF_LIB_PREFIX)) - { - // Return the real jar file for all accesses to - // /WEB-INF/lib/*.jar - String jarName = StringUtil.strip(uri, WEB_INF_LIB_PREFIX); - if (jarName.startsWith("/") || jarName.startsWith("\\")) - jarName = jarName.substring(1); - if (jarName.length() == 0) - return null; - File jarFile = _webInfJarMap.get(jarName); - if (jarFile != null) - return Resource.newResource(jarFile.getPath()); - + } + else if (uri.startsWith(WEB_INF_LIB_PREFIX)) + { + // Return the real jar file for all accesses to + // /WEB-INF/lib/*.jar + String jarName = StringUtil.strip(uri, WEB_INF_LIB_PREFIX); + if (jarName.startsWith("/") || jarName.startsWith("\\")) + jarName = jarName.substring(1); + if (jarName.length() == 0) return null; - } - } - catch (MalformedURLException e) - { - throw e; - } - catch (IOException e) - { - LOG.trace("IGNORED", e); + File jarFile = _webInfJarMap.get(jarName); + if (jarFile != null) + return Resource.newResource(jarFile.getPath()); + + return null; } } return resource; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/SelectiveJarResource.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/SelectiveJarResource.java index 6126b5d9b5e..2268df0102a 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/SelectiveJarResource.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/SelectiveJarResource.java @@ -111,7 +111,7 @@ public class SelectiveJarResource extends Resource } @Override - public boolean isContainedIn(Resource r) throws IOException + public boolean isContainedIn(Resource r) { return _delegate.isContainedIn(r); } diff --git a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/ClassMatcher.java b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/ClassMatcher.java index 1f8c2bb326c..50dd36071ed 100644 --- a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/ClassMatcher.java +++ b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/ClassMatcher.java @@ -13,8 +13,6 @@ package org.eclipse.jetty.ee9.webapp; -import java.io.IOException; -import java.io.UncheckedIOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -135,14 +133,8 @@ public class ClassMatcher extends AbstractSet super(name, inclusive); if (!getName().startsWith("file:")) throw new IllegalArgumentException(name); - try - { - _path = Resource.newResource(getName()).getPath(); - } - catch (IOException e) - { - throw new UncheckedIOException(e); - } + + _path = Resource.newResource(getName()).getPath(); } public Path getPath() diff --git a/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/OrderingTest.java b/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/OrderingTest.java index e0d2d838526..7a4d3a3c0e1 100644 --- a/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/OrderingTest.java +++ b/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/OrderingTest.java @@ -15,7 +15,6 @@ package org.eclipse.jetty.ee9.webapp; import java.io.IOException; import java.io.InputStream; -import java.net.MalformedURLException; import java.net.URI; import java.nio.channels.ReadableByteChannel; import java.nio.file.Path; @@ -95,7 +94,7 @@ public class OrderingTest } @Override - public boolean isContainedIn(Resource r) throws MalformedURLException + public boolean isContainedIn(Resource r) { return false; }