Review of Resource throwables
This commit is contained in:
parent
e1ebef2ca6
commit
84f6dc7f4c
|
@ -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
|
||||
|
|
|
@ -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<Mount> mountConsumer) throws IOException
|
||||
public static Resource newSystemResource(String resource, Consumer<Mount> 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);
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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-<VERSION>
|
||||
jettyHome = new File(baseDir, "jetty-home-" + version);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<String>
|
|||
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()
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<String>
|
|||
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()
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue