Move Resource.combine() methods to ResourceFactory
This commit is contained in:
parent
28d448aef6
commit
45e706cb67
|
@ -779,7 +779,7 @@ public class HTTPServerDocs
|
|||
ResourceHandler handler = new ResourceHandler();
|
||||
|
||||
// For multiple directories, use ResourceCollection.
|
||||
Resource resource = Resource.combine(
|
||||
Resource resource = ResourceFactory.combine(
|
||||
ResourceFactory.of(handler).newResource("/path/to/static/resources/"),
|
||||
ResourceFactory.of(handler).newResource("/another/path/to/static/resources/")
|
||||
);
|
||||
|
|
|
@ -57,7 +57,6 @@ import org.eclipse.jetty.util.IO;
|
|||
import org.eclipse.jetty.util.QuotedStringTokenizer;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.resource.FileSystemPool;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceFactory;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
@ -1805,7 +1804,7 @@ public class ResourceHandlerTest
|
|||
{
|
||||
copySimpleTestResource(docRoot);
|
||||
_rootResourceHandler.stop();
|
||||
_rootResourceHandler.setBaseResource(Resource.combine(
|
||||
_rootResourceHandler.setBaseResource(ResourceFactory.combine(
|
||||
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePathDir("layer0/")),
|
||||
_rootResourceHandler.getBaseResource()));
|
||||
_rootResourceHandler.start();
|
||||
|
@ -1864,7 +1863,7 @@ public class ResourceHandlerTest
|
|||
{
|
||||
copySimpleTestResource(docRoot);
|
||||
_rootResourceHandler.stop();
|
||||
_rootResourceHandler.setBaseResource(Resource.combine(
|
||||
_rootResourceHandler.setBaseResource(ResourceFactory.combine(
|
||||
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePathDir("layer0/")),
|
||||
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePathDir("layer1/")),
|
||||
_rootResourceHandler.getBaseResource()));
|
||||
|
|
|
@ -52,34 +52,6 @@ public abstract class Resource implements Iterable<Resource>
|
|||
private static final LinkOption[] NO_FOLLOW_LINKS = new LinkOption[]{LinkOption.NOFOLLOW_LINKS};
|
||||
private static final LinkOption[] FOLLOW_LINKS = new LinkOption[]{};
|
||||
|
||||
/**
|
||||
* <p>Make a Resource containing a collection of other resources</p>
|
||||
* @param resources multiple resources to combine as a single resource. Typically, they are directories.
|
||||
* @return A Resource of multiple resources.
|
||||
* @see ResourceCollection
|
||||
*/
|
||||
// TODO this should be moved to ResourceFactory
|
||||
public static ResourceCollection combine(List<Resource> resources)
|
||||
{
|
||||
if (resources == null || resources.isEmpty())
|
||||
throw new IllegalArgumentException("No resources");
|
||||
return new ResourceCollection(resources);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Make a Resource containing a collection of other resources</p>
|
||||
* @param resources multiple resources to combine as a single resource. Typically, they are directories.
|
||||
* @return A Resource of multiple resources.
|
||||
* @see ResourceCollection
|
||||
*/
|
||||
// TODO this should be moved to ResourceFactory
|
||||
public static ResourceCollection combine(Resource... resources)
|
||||
{
|
||||
if (resources == null || resources.length == 0)
|
||||
throw new IllegalArgumentException("No resources");
|
||||
return new ResourceCollection(List.of(resources));
|
||||
}
|
||||
|
||||
public static String dump(Resource resource)
|
||||
{
|
||||
if (resource == null)
|
||||
|
|
|
@ -32,6 +32,32 @@ import org.eclipse.jetty.util.component.Dumpable;
|
|||
*/
|
||||
public interface ResourceFactory
|
||||
{
|
||||
/**
|
||||
* <p>Make a Resource containing a collection of other resources</p>
|
||||
* @param resources multiple resources to combine as a single resource. Typically, they are directories.
|
||||
* @return A Resource of multiple resources.
|
||||
* @see ResourceCollection
|
||||
*/
|
||||
static ResourceCollection combine(List<Resource> resources)
|
||||
{
|
||||
if (resources == null || resources.isEmpty())
|
||||
throw new IllegalArgumentException("No resources");
|
||||
return new ResourceCollection(resources);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Make a Resource containing a collection of other resources</p>
|
||||
* @param resources multiple resources to combine as a single resource. Typically, they are directories.
|
||||
* @return A Resource of multiple resources.
|
||||
* @see ResourceCollection
|
||||
*/
|
||||
static ResourceCollection combine(Resource... resources)
|
||||
{
|
||||
if (resources == null || resources.length == 0)
|
||||
throw new IllegalArgumentException("No resources");
|
||||
return new ResourceCollection(List.of(resources));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a resource from a uri.
|
||||
*
|
||||
|
@ -187,7 +213,7 @@ public interface ResourceFactory
|
|||
if ((uris == null) || (uris.isEmpty()))
|
||||
throw new IllegalArgumentException("List of URIs is invalid");
|
||||
|
||||
return Resource.combine(uris.stream().map(this::newResource).toList());
|
||||
return combine(uris.stream().map(this::newResource).toList());
|
||||
}
|
||||
|
||||
default Resource newResource(URL url)
|
||||
|
|
|
@ -77,7 +77,7 @@ public class ResourceCollectionTest
|
|||
Path two = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/two");
|
||||
Path three = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/three");
|
||||
|
||||
ResourceCollection rc = Resource.combine(
|
||||
ResourceCollection rc = ResourceFactory.combine(
|
||||
resourceFactory.newResource(one),
|
||||
resourceFactory.newResource(two),
|
||||
resourceFactory.newResource(three)
|
||||
|
@ -125,7 +125,7 @@ public class ResourceCollectionTest
|
|||
Path two = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/two");
|
||||
Path three = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/three");
|
||||
|
||||
ResourceCollection rc = Resource.combine(
|
||||
ResourceCollection rc = ResourceFactory.combine(
|
||||
resourceFactory.newResource(one),
|
||||
resourceFactory.newResource(two),
|
||||
resourceFactory.newResource(three)
|
||||
|
@ -147,7 +147,7 @@ public class ResourceCollectionTest
|
|||
Path two = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/two");
|
||||
Path three = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/three");
|
||||
|
||||
ResourceCollection rc = Resource.combine(
|
||||
ResourceCollection rc = ResourceFactory.combine(
|
||||
resourceFactory.newResource(one),
|
||||
resourceFactory.newResource(two),
|
||||
resourceFactory.newResource(three)
|
||||
|
@ -173,7 +173,7 @@ public class ResourceCollectionTest
|
|||
Path three = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/three");
|
||||
Path twoDir = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/two/dir");
|
||||
|
||||
ResourceCollection rc1 = Resource.combine(
|
||||
ResourceCollection rc1 = ResourceFactory.combine(
|
||||
List.of(
|
||||
resourceFactory.newResource(one),
|
||||
resourceFactory.newResource(two),
|
||||
|
@ -181,7 +181,7 @@ public class ResourceCollectionTest
|
|||
)
|
||||
);
|
||||
|
||||
ResourceCollection rc2 = Resource.combine(
|
||||
ResourceCollection rc2 = ResourceFactory.combine(
|
||||
List.of(
|
||||
// the original ResourceCollection
|
||||
rc1,
|
||||
|
@ -215,7 +215,7 @@ public class ResourceCollectionTest
|
|||
Path three = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/three");
|
||||
Path dirFoo = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/two/dir");
|
||||
|
||||
Resource compositeA = Resource.combine(
|
||||
Resource compositeA = ResourceFactory.combine(
|
||||
List.of(
|
||||
resourceFactory.newResource(one),
|
||||
resourceFactory.newResource(two),
|
||||
|
@ -223,7 +223,7 @@ public class ResourceCollectionTest
|
|||
)
|
||||
);
|
||||
|
||||
Resource compositeB = Resource.combine(
|
||||
Resource compositeB = ResourceFactory.combine(
|
||||
List.of(
|
||||
// the original composite Resource
|
||||
compositeA,
|
||||
|
@ -271,7 +271,7 @@ public class ResourceCollectionTest
|
|||
FS.ensureDirExists(dirC);
|
||||
Files.createFile(dirC.resolve("foo"));
|
||||
|
||||
Resource rc = Resource.combine(
|
||||
Resource rc = ResourceFactory.combine(
|
||||
ResourceFactory.root().newResource(dirA),
|
||||
ResourceFactory.root().newResource(dirB),
|
||||
ResourceFactory.root().newResource(dirC)
|
||||
|
|
|
@ -63,7 +63,7 @@ public class OverlayManager
|
|||
resourceBases.add(webApp.getBaseResource());
|
||||
}
|
||||
|
||||
webApp.setBaseResource(Resource.combine(resourceBases));
|
||||
webApp.setBaseResource(ResourceFactory.combine(resourceBases));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -242,6 +242,6 @@ public class QuickStartDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
List<Resource> collection = new ArrayList<>();
|
||||
collection.add(context.getBaseResource());
|
||||
collection.addAll(metaInfResources);
|
||||
context.setBaseResource(Resource.combine(collection));
|
||||
context.setBaseResource(ResourceFactory.combine(collection));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -265,7 +265,7 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
List<Resource> collection = new ArrayList<>();
|
||||
collection.add(context.getBaseResource());
|
||||
collection.addAll(resources);
|
||||
context.setBaseResource(Resource.combine(collection));
|
||||
context.setBaseResource(ResourceFactory.combine(collection));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -448,7 +448,7 @@ public class WebInfConfiguration extends AbstractConfiguration
|
|||
|
||||
webInf = context.getResourceFactory().newResource(extractedWebInfDir.getCanonicalPath());
|
||||
|
||||
Resource rc = Resource.combine(webInf, webApp);
|
||||
Resource rc = ResourceFactory.combine(webInf, webApp);
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("context.baseResource={}", rc);
|
||||
|
|
|
@ -49,7 +49,6 @@ import org.eclipse.jetty.util.FileID;
|
|||
import org.eclipse.jetty.util.URIUtil;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
import org.eclipse.jetty.util.resource.FileSystemPool;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceFactory;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
@ -513,7 +512,7 @@ public class WebAppContextTest
|
|||
|
||||
WebAppContext context = new WebAppContext();
|
||||
context.setContextPath("/");
|
||||
context.setBaseResource(Resource.combine(
|
||||
context.setBaseResource(ResourceFactory.combine(
|
||||
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePath("wars/layer0/")),
|
||||
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePath("wars/layer1/"))));
|
||||
server.setHandler(context);
|
||||
|
@ -531,7 +530,7 @@ public class WebAppContextTest
|
|||
|
||||
WebAppContext context = new WebAppContext();
|
||||
context.setContextPath("/");
|
||||
context.setBaseResource(Resource.combine(
|
||||
context.setBaseResource(ResourceFactory.combine(
|
||||
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePath("wars/layer0/")),
|
||||
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePath("wars/layer1/"))));
|
||||
server.setHandler(context);
|
||||
|
|
|
@ -64,7 +64,7 @@ public class OverlayManager
|
|||
resourceBases.add(webApp.getBaseResource());
|
||||
}
|
||||
|
||||
webApp.setBaseResource(Resource.combine(resourceBases));
|
||||
webApp.setBaseResource(ResourceFactory.combine(resourceBases));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -243,6 +243,6 @@ public class QuickStartDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
List<Resource> collection = new ArrayList<>();
|
||||
collection.add(context.getBaseResource());
|
||||
collection.addAll(metaInfResources);
|
||||
context.setBaseResource(Resource.combine(collection));
|
||||
context.setBaseResource(ResourceFactory.combine(collection));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -265,7 +265,7 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
List<Resource> collection = new ArrayList<>();
|
||||
collection.add(context.getBaseResource());
|
||||
collection.addAll(resources);
|
||||
context.setBaseResource(Resource.combine(collection));
|
||||
context.setBaseResource(ResourceFactory.combine(collection));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -446,7 +446,7 @@ public class WebInfConfiguration extends AbstractConfiguration
|
|||
|
||||
webInf = context.getResourceFactory().newResource(extractedWebInfDir.getCanonicalPath());
|
||||
|
||||
Resource rc = Resource.combine(webInf, webApp);
|
||||
Resource rc = ResourceFactory.combine(webInf, webApp);
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("context.baseResource={}", rc);
|
||||
|
|
Loading…
Reference in New Issue